00:00:00.000-->00:00:05.539 >>OK so this afternoon's talk is Sorry for the Lame [grunts] Title and it’s Toma let’s give a 00:00:05.539-->00:00:14.815 big DefCon welcome! [applause] Come on! [applause] Louder! [audience cheers] >> Thanks! Uh, 00:00:14.815-->00:00:22.789 wow it’s an honor to be here at DefCon again. Uh I hope you do enjoy yourselves as well. Uh I 00:00:22.789-->00:00:34.768 am Toma. I have been calling myself a hacker for almost ten years. I am from Hungary and I 00:00:34.768-->00:00:40.574 work for a uh an IT security company in Hungary as a uh pentester and a developer. Uh 00:00:40.574-->00:00:47.314 this is my third time uh at DefCon and I’m mostly a regular speaker at central Europe’s 00:00:47.314-->00:00:55.822 hacker conference activity. That’s enough about me. Uh how did I choose this uh topic? It 00:00:55.822-->00:01:06.300 was not the usual way so I didn’t have any interest in MATLAB and de-sorter, but I was 00:01:06.300-->00:01:14.975 at a friend’s birthday party and at two or three o’clock in the morning uh her sister asked me 00:01:14.975-->00:01:22.583 if I could help her in MATLAB and I had some vague memories of MATLAB back from the university 00:01:22.583-->00:01:31.892 uh but of course I said yes. So the next day I sitting in my room installing MATLAB and uh as 00:01:31.892-->00:01:39.733 a rule of thumb uh what I install on my machine I try to hack. And there was a lot of 00:01:39.733-->00:01:46.340 stuff to hack. This software is uh huge there are some web servers, some cloud 00:01:46.340-->00:01:52.479 integrations, lots of functionalities, lots of surfaces. Uh so hacking is fun 00:01:52.479-->00:01:59.786 so I dived in. What I didn’t want to uh miscommunicate about MATLAB so I also downloaded a 00:01:59.786-->00:02:11.898 trial of uh Mathematica and Maple and together they gave a pretty nice topic to talk about. 00:02:11.898-->00:02:21.174 Um, in this talk probably won’t be the most technical talk you will hear at DefCon. I won’t 00:02:21.174-->00:02:27.347 show you any groundbreaking techniques or technologies but I will show you a bunch of zero 00:02:27.347-->00:02:35.222 days in this software. Let’s start with MATLAB. There are some simple stuff. Uhh, like 00:02:35.222-->00:02:46.033 every, like, every scripting language MATLAB has also facilities to run native codes, 00:02:46.033-->00:02:56.376 native commands. Uh it has a system command which you can use to execute uh OS commands. You 00:02:56.376-->00:03:02.349 can also use the Bang symbol and there are facilities to load native libraries, java, total 00:03:02.349-->00:03:08.121 libraries and command check too. This of course is not a vulnerability in itself but can 00:03:08.121-->00:03:22.769 be used for uh malicious purposes for example spear phishing and that can be uh can 00:03:22.769-->00:03:30.077 be created with a malicious MATLAB script. One other interesting uh aspect of this uh 00:03:30.077-->00:03:38.652 native command execution is that you can download MATLAB mobile and you can create a free 00:03:38.652-->00:03:48.361 registration uh at MathWorks servers and you can actually run MATLAB functions on MathWorks 00:03:48.361-->00:03:54.134 servers and this is not whitelisted or blacklisted and so you can also uh run these 00:03:54.134-->00:04:02.375 system commands on their servers. Uh granted it’s in a docker environment I did not try 00:04:02.375-->00:04:12.486 to escape it but we all know that uh it is just uh privilege escalation by the way. Ok so I 00:04:12.486-->00:04:19.926 am much am using malicious MATLAB uh scripts in uh phishing attack or something like that. 00:04:19.926-->00:04:28.635 But it should be fairly easy uh to protect against these attacks uh because you just have to scan 00:04:28.635-->00:04:36.510 your uh scripts for these dangerous functions. But uh MathWorks uh have a solution 00:04:36.510-->00:04:44.217 against uh IP theft uh which is the function P-code. Uh with P-code you can uh obfuscate your 00:04:44.217-->00:04:56.196 uh MATLAB script so it won’t be a debted with what do they do. Uh MATLAB itself uh uses it uh 00:04:56.196-->00:05:04.571 lot and lots of uh functionalities in uh MATLAB I recommend it as P-files decoded 00:05:04.571-->00:05:14.381 uh MATLAB script uh even though uh MathWorks has a warning that this um obfuscation it’s not uh 00:05:14.381-->00:05:24.824 uh secure enough to trust your sensitive data to it. Uh but because uh lots of MATLABS 00:05:24.824-->00:05:33.099 functionalities implemented as uh P-files I needed to reverse engineer this algorithm uh and 00:05:33.099-->00:05:46.880 uh this was kind of painful because uh throughout a huge number of uh native libraries 00:05:46.880-->00:05:57.123 that goal java jars that in turn uh execute uh MATLAB p-files that sometimes go back to uh 00:05:57.123-->00:06:07.701 java libraries so from an external viewpoint it’s uh it’s uh quite a mess uh and it got me 00:06:07.701-->00:06:20.814 confused a few times uh one of these uh even created a uh nice fail night uh topic I have found 00:06:20.814-->00:06:32.759 a uh FCE by, via study code analyzes but it turned out that uh that code was uh some left 00:06:32.759-->00:06:41.801 over that code that is not uh used anyway uh so uh eventually I have found the p-code uh 00:06:41.801-->00:06:47.707 implementation and I was able to uh create a python script that uh decodes P-files uh back to uh 00:06:47.707-->00:06:59.052 MATLAB script. Uh It was a huge uh internal debate with myself if I should release uh this 00:06:59.052-->00:07:10.964 python script but I have decided against it uh because even uh though MATLAB has that warning, 00:07:10.964-->00:07:21.975 uh lots of people use uh p-codes protect their research and I didn’t want to uh expose it But 00:07:21.975-->00:07:31.751 uh I will uh show you the uh most interesting uh step of the p-code algorithm. P-code is uh 00:07:31.751-->00:07:39.359 P-code consists of three steps. Uh there’s a serialization step, a compression and then an uh 00:07:39.359-->00:07:48.001 encryption step. The letter to implement are M underscore parser library and they are 00:07:48.001-->00:07:53.807 pretty straight forward they are uh really easy to uh reverse engineer and so if you are 00:07:53.807-->00:08:04.284 interested in it you should uh do it you could do it uh without problems. Uh the serialization 00:08:04.284-->00:08:13.560 uh is more interesting because it’s uh it’s uh it’s lots of probably c plus plus code and it 00:08:13.560-->00:08:20.934 would have been uh really painful to reverse engineer even with some decompiler but what 00:08:20.934-->00:08:26.639 was most interesting is that almost the whole algorithm could be understood just uh looking at 00:08:26.639-->00:08:36.182 the p-files, just looking at the data. So here is uh a p-file. Uh it’s already color coded but 00:08:36.182-->00:08:44.624 even without the colors uh it should stick out that uh there are separate blocks that contain 00:08:44.624-->00:08:57.470 uh function names uh and numbers used in the script and uh string literals so uh what remains uh 00:08:57.470-->00:09:05.412 to understood is this first block and uh this last. If you look at the first block it uh 00:09:05.412-->00:09:12.685 really seems to be uh seven DWORDS that have uh really small values and if you look as these 00:09:12.685-->00:09:22.829 values first is uh zero x o C which is twelve uh and if you count the function names uh it’s 00:09:22.829-->00:09:31.905 twelve. Uh the second number is two and uh there are two numbers. Uh so these seven 00:09:31.905-->00:09:45.051 DWORDS uh it seems these are the uh numbers of symbols in the p-file. There are seven of them 00:09:45.051-->00:09:53.359 uh. I was able to identify uh three of them but it turned out that it’s not really important. 00:09:53.359-->00:10:03.470 Uh so this was enough to uh reverse the algorithm. What remains is this last block uh 00:10:03.470-->00:10:11.978 which seems to be uh a combination of uh some random numbers that I invite and some 00:10:11.978-->00:10:22.255 zero x eighty eighty uh pairs uh eighty eighty something uh pairs. Mm, after a while it uh 00:10:22.255-->00:10:29.662 turned out that uh if you subtract zero x eighty eighty from these pairs then the result 00:10:29.662-->00:10:40.406 is an index uh in to this array. So the first one is zero x eighty eighty you subtract zero 00:10:40.406-->00:10:49.249 x eighty eighty you got zero and the zero uh element of the array is x and uh if we go back to the 00:10:49.249-->00:10:57.690 original script you can see that it is indeed start with an x and the next symbol is an equal sign 00:10:57.690-->00:11:09.936 so maybe zero x five F uh represents the equal sign and uh maybe uh all these numbers uh 00:11:09.936-->00:11:18.444 represent some uh symbols or uh reserved words in um MATLAB language. So this was the part 00:11:18.444-->00:11:31.124 when I asked for the help of a disassembler. I looked for uh these uh these numbers in the 00:11:31.124-->00:11:41.000 disassembly of the library and I found uh an array of uh of the reserved words and uh symbols 00:11:41.000-->00:11:50.577 which could be easily extracted from the binary so uh it only needed to uh substitute those 00:11:50.577-->00:12:00.186 numbers with the uh symbols and reserved words uh to get the original uh MATLAB script. So uh 00:12:00.186-->00:12:11.264 it took a few days but it was uh easy enough to uh to reverse engineer the whole algorithm 00:12:11.264-->00:12:27.180 only just by looking at the data. Um ok so I’ve already uh told you about uh MATLAB mobile 00:12:27.180-->00:12:35.488 uh and I’ve told uh that you can connect to MathWorks’ server with it mm but it’s not only 00:12:35.488-->00:12:41.027 Mathwork's’ servers you can connect to but uh you can create your own and you can connect to 00:12:41.027-->00:12:50.103 it too. Uh the communication within the mobile application and the uh server is uh HTTP 00:12:50.103-->00:12:59.979 communication. Uh it’s plain HTTP there is no possibility to uh set up HTTPS but the bodies 00:12:59.979-->00:13:10.189 uh seem to be base sixty-four encoded binary blobs so they may be encrypted. Mm. These are the 00:13:10.189-->00:13:19.766 uh request and uh response bodies I have uh reversed engineered the uh server code 00:13:19.766-->00:13:31.010 and uh it turned out that it is indeed encrypted but it is encrypted uh by XORing the plain 00:13:31.010-->00:13:37.717 text message with the uh MATLAB server’s password so it’s really strong encryption [audience 00:13:37.717-->00:13:46.259 laughter] but it gets better because every single plain text message is uh pre-fixed with a 00:13:46.259-->00:13:57.203 string MATLAB connector uh dash V one. This means that uh if you have one single message you can 00:13:57.203-->00:14:04.744 XO the first eighteen bytes of it uh with the MATLAB connector underscore V one and you get the 00:14:04.744-->00:14:16.656 password. So uh it’s pretty nice but [audience laughter] the maximum password length is 00:14:16.656-->00:14:24.597 thirty-two bytes so what if somebody sets a thirty-two byte password no worries because uh 00:14:24.597-->00:14:33.673 because of the uh structure of the plain text messages uh these are adjacent messages uh there 00:14:33.673-->00:14:39.679 are always uh thirty-two static bytes at the beginning of a message so this is how uh 00:14:39.679-->00:14:49.655 requests starts and uh this is how a response starts so if you got one uh message from uh the 00:14:49.655-->00:14:59.232 mobile MATLAB mobile application to the server you can uh use the password. I have created a word 00:14:59.232-->00:15:07.373 series pro extension that does exactly this. Uh it retrieves the password and creates a uh 00:15:07.373-->00:15:15.748 MATLAB connector tab that shows you the uh plain text message and uh lets you edit it. Uh I 00:15:15.748-->00:15:26.759 didn’t uh try to uh test further the MATLAB- uh MATLAB mobile server but uh this could be a 00:15:26.759-->00:15:37.203 big hub for that for uh fuzzing the server or something like that. Uh this uh extension and 00:15:37.203-->00:15:44.076 uh all of my demos all of my exploits uh will be available on my Github shortly after my 00:15:44.076-->00:15:52.585 talks. You can download it and play with it. Ok I while I was looking for the implementation 00:15:52.585-->00:16:04.630 of the MATLAB mobile. Uh I have found an interesting web dot XML uh in the MATLAB uh server it 00:16:04.630-->00:16:13.940 described some servlets of reach to seem very interesting. The engine servlet and the MATLAB 00:16:13.940-->00:16:22.782 servlet. The MATLAB servlet evaluates functions via a GET request. Uh it is whitelisted 00:16:22.782-->00:16:32.425 there are only a handful of functions that can p-code and it is local host only. But, uh I 00:16:32.425-->00:16:42.201 was looking at uh all these functions that can P-code and it turned out that the 00:16:42.201-->00:16:50.710 pslinkprivate uh function is uh basically a wrapper around feval. Uh feval is the MATLAB 00:16:50.710-->00:16:56.849 function used to evaluate arbitrary MATLAB functions. What this means is uh you can call 00:16:56.849-->00:17:06.492 arbitrary MATLAB functions uh the system function included uh by just one GET request to local 00:17:06.492-->00:17:23.209 host to the MATLAB server. So you can you can have a website uh that mats uh an image uh with 00:17:23.209-->00:17:33.019 such a url if somebody with an open MATLAB uh opens your website it will uh execute 00:17:33.019-->00:17:42.228 whatever uh MATLAB commands you want. So this means basically remote code execution on 00:17:42.228-->00:17:52.271 victim’s machine. As we will shortly see. So yeah you can see the calculator opened. [audience 00:17:52.271-->00:18:05.851 applause] Thanks. Ok, so the other servlet uh is it also evaluates MATLAB functions uh 00:18:05.851-->00:18:14.794 but if this does not work uh on the default configuration so you will have to uh turn on engine 00:18:14.794-->00:18:20.866 servlet. But it can still be used to uh I don’t know back order somebody’s machine. Uh 00:18:20.866-->00:18:27.440 with the engine servlet there is no white or blacklist you can call any MATLAB uh functions. It 00:18:27.440-->00:18:37.883 requires an API key but uh this is uh burnt in to MATLAB it’s MATLAB uh and it’s also local 00:18:37.883-->00:18:48.427 host only at least intended to be because they used the GET request URL java function to get 00:18:48.427-->00:18:55.201 the uh originating URL which uses the host header so it can be very easily be faked. Uh 00:18:55.201-->00:19:10.883 there uh is the key and I also have a demo for this. So I am starting MATLAB and I am going 00:19:10.883-->00:19:19.425 to show you the uh servlet command that can be used to start calculator on victim’s 00:19:19.425-->00:19:35.041 machine by a MATLAB. I am just going to fast-forward a bit. So we can see uh, uh that it is 00:19:35.041-->00:19:42.581 forbidden because uh engine servlet is not running right now. This is the code that can 00:19:42.581-->00:19:55.861 be used to turn it on. Fast-forwarding. Ok it’s on now and if we try again we get the 00:19:55.861-->00:20:08.007 calculator. So it’s again remote code execution but it uh needs engine servlet to be turned on. 00:20:08.007-->00:20:15.581 Ok uh moving on to another uh Mathwork’s product. Uh it’s called MATLAB production server. 00:20:15.581-->00:20:22.788 Uh it can be used to deploy MATLAB functions on the web. It has an express-based management 00:20:22.788-->00:20:31.163 dashboard it uses uh signed cookies to store the session. Uh it uses the cookie session and 00:20:31.163-->00:20:38.571 the key-grip uh and MPM packages uh for this. But it has a huge implementation problem because 00:20:38.571-->00:20:50.649 they have an array of two keys uh it consists of MATLAB and Simulink. But in reality only 00:20:50.649-->00:21:01.627 the first one is ever used. They never uh rotate the keys. Uh we can confirm this by uh creating 00:21:01.627-->00:21:11.737 a signature from for a cookie uh using uh just going to open a cell so you can see is the uh 00:21:11.737-->00:21:22.181 password we get same signature that we uh got from the server. What this means for a tech-er is 00:21:22.181-->00:21:30.923 that we can create a super cookie that grants uh administration rights to any 00:21:30.923-->00:21:41.100 MATLAB production servers always. And this can of course be used to uh run a code on the 00:21:41.100-->00:21:48.908 MATLAB production server because you can uh upload a MATLAB function that uh contains only 00:21:48.908-->00:21:57.116 the system function uh and you can call it uh remotely. So I have a vital script that uh 00:21:57.116-->00:22:10.462 creates new uh MPS instance. It creates a new application and uh deploys and started. Uh and this 00:22:10.462-->00:22:21.907 application uh contains only uh the function MATLAB call. So if we run this uh pattern script. 00:22:21.907-->00:22:39.692 You can see it’s working uh and we have a new MPS uh application. It’s running 00:22:39.692-->00:22:55.674 alright so now we can use the uh MPS shadowed by script to run commands on the MPS server. So 00:22:55.674-->00:23:05.117 as you can see it’s a bit slow but it eventually uh answers with the results so this is uh 00:23:05.117-->00:23:22.368 remote call execution without any authentication to the MPS server. Ok. So I did not do a 00:23:22.368-->00:23:29.375 thorough inspection of uh MPS I did not have the time yet. But I have found some additional flows 00:23:29.375-->00:23:38.884 uh it’s just an example it’s a store express I’m sure there are several others so it’s a nice 00:23:38.884-->00:23:50.162 project I think. Ok so moving on to uh another uh another Math product. Uh it’s Mathematica and 00:23:50.162-->00:23:58.570 it can also execute native commands but uh notebooks, Mathematica notebooks are not uh 00:23:58.570-->00:24:07.046 scripts so they won’t uh evaluate when you open them. Uh but there are uh expression 00:24:07.046-->00:24:16.055 code, expressions code dynamics that can be used to uh evaluate expressions uh automatically but 00:24:16.055-->00:24:24.663 these uh dynamic uh expressions have some protections against uh malicious notebooks there are 00:24:24.663-->00:24:35.974 some uh Mathematica functions, expressions that are uh dangerous and they won’t uh 00:24:35.974-->00:24:44.016 evaluate via a dynamic expression without user interaction. Uh at least they 00:24:44.016-->00:25:06.238 shouldn’t but I found a way uh by trial and error or to bypass this protection. Close. So. So I 00:25:06.238-->00:25:16.048 am going to show the whole trial and error process this uh demo. First thing uh I’ve tried was 00:25:16.048-->00:25:33.565 the a simple run command which can be used to run commands but it opens up the CMD windows and 00:25:33.565-->00:25:41.607 I didn’t like that it turned out the run process does not open up the CMD window so it looks 00:25:41.607-->00:25:56.855 better. Now I am trying to wrap this in to a dynamic and it became quite a disaster because 00:25:56.855-->00:26:08.834 every time the dynamic is displayed uh it evaluates the expression so uh it turns a loop 00:26:08.834-->00:26:20.979 [audience applause & cheer] So eventually I managed to do it and I also found a way to uh get 00:26:20.979-->00:26:29.955 around this uh infinite loop. Uh we can use the track symbols uh dynamic parameter to uh 00:26:29.955-->00:26:39.965 basically make a dynamic uh update only once when it first displayed. So now if we try to 00:26:39.965-->00:27:02.721 save this uh to a file. Ok and uh sorry. So uh trying to open the file and uh there is indeed 00:27:02.721-->00:27:12.331 a warning so it won’t execute pinball without user interaction. I was looking 00:27:12.331-->00:27:21.039 through the documentation and uh I found another expression code oh sorry there’s something other 00:27:21.039-->00:27:32.050 in this video too. There are so called uh safe directories uh and uh documents inside safe 00:27:32.050-->00:27:39.358 directories are not checked for these uh dangerous functions so dynamics will always evaluate 00:27:39.358-->00:27:45.197 from them so if you can get somebody to download your malicious uh notebook to safe 00:27:45.197-->00:27:54.673 location then you are good to go uh no tricks necessary. But if you don’t have that uh luxury, 00:27:54.673-->00:28:06.184 you can use the interpreter uh expression which is used to uh run uh expressions from a string 00:28:06.184-->00:28:13.425 and it should be a dangerous function but it turned out it’s not. So this can be used to 00:28:13.425-->00:28:24.469 auto-execute commands to uh with a uh Mathematica Notebook. So this is how you can bypass the 00:28:24.469-->00:28:40.652 dynamic protection. So, uh really similar to uh Mathematica notebooks are computable 00:28:40.652-->00:28:50.762 document format documents. Uh these are almost the same uh but they are run in uh restricted 00:28:50.762-->00:29:01.840 environment they are run in a sandbox but you can also uh run them from a proxy so it some 00:29:01.840-->00:29:13.051 what widens the tech surface. The biggest restriction of uh the sandbox is that you have no 00:29:13.051-->00:29:20.859 file system access. You can’t uh download files you can’t even uh execute commands but there are 00:29:20.859-->00:29:28.400 still some ways to abuse this CDF’s. When I was looking through the documentation I 00:29:28.400-->00:29:37.876 found out that uh you can do TCP/IP from uh CDFs and my very first thought was uh that I can 00:29:37.876-->00:29:45.984 create uh SOCKS proxy with that. So if I can get someone to open my uh CDF document uh which 00:29:45.984-->00:29:54.693 implements the SOCKS proxy then it will open a proxy in to uh the victim machine in to the 00:29:54.693-->00:30:05.771 victim network so I thought it would be pretty cool so I did implement that proxy and I am 00:30:05.771-->00:30:15.681 going to show you this with a Linux machine that runs X server. This is the victim and 00:30:15.681-->00:30:30.629 it will open the CDF file that implements the SOCKS proxy. And I’m going to use it to create a 00:30:30.629-->00:30:44.242 screen shots of the X desktop remotely through the SOCKS server. So I am using uh circuit 00:30:44.242-->00:31:02.494 uh to redirect the SOCKS communication in to a unique circuit. Ok started the CDF file 00:31:02.494-->00:31:18.577 creating the uh listening circuit for the access server. Just fast-forward a little bit. 00:31:18.577-->00:31:31.957 Ok so now it’s uh everything is uh running I can use uh XWD uh to download uh screenshots from 00:31:31.957-->00:31:43.101 the access server it runs quite a while so fast forwarding again when it’s done uh I am 00:31:43.101-->00:31:52.611 converting it uh to uh png and uh you can see that creating this type of screenshot was 00:31:52.611-->00:32:06.057 indeed successful [audience applause] Thank you! Ok, so another uh Wolfram uh research 00:32:06.057-->00:32:14.599 product is uh Lightweight Grid Manager uh it’s uh clustering solution for from uh from 00:32:14.599-->00:32:21.506 Wolfram Research it’s uh basically a Tom-cat based uh web application to uh manage 00:32:21.506-->00:32:30.816 Mathematica kernels uh it needs authentication to make changes but you can start uh kernels 00:32:30.816-->00:32:36.988 without authentication it has some uh protection though because you can set up an IP 00:32:36.988-->00:32:46.331 whitelists but this protections uh have some very serious implementation flaws first of 00:32:46.331-->00:32:55.240 all the authentication uh this is the uh conflict uh file statement that implements the 00:32:55.240-->00:33:03.715 authentication you can see that it’s only uh for GET and post requests. This is the first flow 00:33:03.715-->00:33:11.590 uh you will see shortly why and uh they also have an AJP listener available this is the 00:33:11.590-->00:33:20.398 second flow. So the first one is a problem because the application will accept uh 00:33:20.398-->00:33:29.441 parameters uh from the credit string and this means you can use a Head uh HTTP request and 00:33:29.441-->00:33:37.916 it uh does not require authentication it does not it’s not uh in the configuration file 00:33:37.916-->00:33:45.357 so you can change uh any configuration without authentication by just using a 00:33:45.357-->00:33:59.704 Head request but you have to uh have to bypass the uh IP filter first uh you can use AJP for 00:33:59.704-->00:34:07.712 this because uh via AJP uh you can lie about the source address, you can say that you 00:34:07.712-->00:34:17.956 are coming from uh local host uh so the application will accept the Oring request because the IP 00:34:17.956-->00:34:23.762 filter is implemented in the application level and not in the application server level. So 00:34:23.762-->00:34:31.803 this can be used to bypass the IP filter. There is one more uh vulnerability uh in this 00:34:31.803-->00:34:42.881 implementation that makes it really easy to uh exploit this uh it has the, you can set the 00:34:42.881-->00:34:54.693 kernels paths uh via a setting and that functionality contains uh an OS command injection uh 00:34:54.693-->00:35:03.101 vulnerability so this means if you combine uh this free vulnerabilities you can have 00:35:03.101-->00:35:11.843 arbitrary uh OS command injections uh on any lightweight grid manager server without any 00:35:11.843-->00:35:26.825 authentication. I have uh created uh python script that uh does this. So you can see it’s 00:35:26.825-->00:35:39.671 the AJM uh application. I am going to start uh listener and I am going to start uh connect by 00:35:39.671-->00:35:52.083 shell by exploiting these vulnerabilities. Fast-forward again. You can see that I have a 00:35:52.083-->00:36:06.097 connection back and uh I can uh execute commands on the uh AJM server. Ok one other thing about 00:36:06.097-->00:36:15.573 AJM its not uh available there is no uh trial or evaluate license but I really wanted to 00:36:15.573-->00:36:24.115 test it and I dig through the internet. And uh I found a university website where there 00:36:24.115-->00:36:36.861 was a Mathematica license number available for public so maybe you don’t do that. [audience 00:36:36.861-->00:36:46.571 laughs] Uh ok, so uh Mathematica and uh in general Wolfram products use the WSTP protocol 00:36:46.571-->00:36:54.446 to communicate uh internally uh between the kernel and the frontend and externally in a 00:36:54.446-->00:37:02.253 clustering situation or with some third party native applications. Uh this protocol 00:37:02.253-->00:37:09.894 uses plain text communications so uh it’s pretty easy to uh launch uh man in the middle 00:37:09.894-->00:37:17.068 attack against it and in this case uh man in the middle attack means remote code execution 00:37:17.068-->00:37:30.348 because you can send a WSTP evaluate packet which will be evaluated on the receiving side. 00:37:30.348-->00:37:48.032 I’m going to show you this uh by connecting Mathematica to a grid. Ok and uh I am running a 00:37:48.032-->00:38:03.815 simple calculation on the grid. Uh so I am going to calculate three times two using the grid 00:38:03.815-->00:38:13.691 and it gives back the result but uh when I start my uh man in the middle attack script which uh 00:38:13.691-->00:38:27.338 uses uh hack C inject to replace any packets with uh one evaluate packet. I am using uh ARP spoof 00:38:27.338-->00:38:34.946 to ARP poison launching uh listener and when I try to compute uh three times two I get 00:38:34.946-->00:38:43.888 uh connect bug shot so I can run voice commands on the server. This shows that uh [coughs] 00:38:43.888-->00:38:58.403 sorry uh this shows that uh the MitM attack is really on remote code execution. Uh, ok. You can 00:38:58.403-->00:39:10.181 also uh offload uh some heavy works from uh Mathematica to uh external programs. Uh so you can 00:39:10.181-->00:39:16.421 call functions uh from Mathematica from uh these external programs but uh there’s 00:39:16.421-->00:39:22.894 dangerous functionality because uh these external programs can also talk to you and they can 00:39:22.894-->00:39:32.437 also send evaluate packets so such uh external program can execute code on your Mathematica 00:39:32.437-->00:39:42.413 server. I’m going to show you this by slightly modifying one of the WSTP uh examples. I am 00:39:42.413-->00:39:54.392 adding to evaluate lines. First one just opens some message and the second one uses the run 00:39:54.392-->00:40:06.471 expressions to uh start the run process expression to start the calculator. So compiling it. 00:40:06.471-->00:40:17.849 Starting the external program and creating a link to this program in Mathematica. When I 00:40:17.849-->00:40:26.257 try to install this external program you can see that calculator runs. So it’s um not 00:40:26.257-->00:40:33.131 an exploit not a vulnerable but just some dangerous functionality in the program. Ok 00:40:33.131-->00:40:40.505 my last target uh it’s Maple. When I installed it and tried it, the first things that uh 00:40:40.505-->00:40:49.614 that that stuck out to me was that Maple documents are XML files. It was not uh not really 00:40:49.614-->00:40:57.288 uh surprise that the software was susceptible to uh XXE attacks. But this of course 00:40:57.288-->00:41:05.997 requires that uh the victim opens a malicious Maple document. But there are two 00:41:05.997-->00:41:15.039 ports uh listening on uh on every IP address on the default Maple install. The first one is 00:41:15.039-->00:41:20.345 not really that interesting it uh just uh accepts a number and uh shuts down the port. But the 00:41:20.345-->00:41:25.316 second one TCP one nine nine nine one uh it’s really interesting because it’s a 00:41:25.316-->00:41:34.959 simple remote control server. Uh here is the protocol you send it a ping it sends it back on ACK 00:41:34.959-->00:41:44.569 and now you can send uh send the server a command which can be uh starting a Maple application 00:41:44.569-->00:41:52.543 Maple applications are defined as uh java uh libraries so they are burned in to the software 00:41:52.543-->00:42:00.885 it’s not uh not an obvious way uh to exploit uh this uh command. But you can also uh 00:42:00.885-->00:42:14.265 open uh Maple documents with the open command and if you have uh if you get a uh file share and 00:42:14.265-->00:42:20.605 put your uh malicious maple document on that file share uh then you can use this uh remote 00:42:20.605-->00:42:27.745 control server to open the malicious document from your file share on the victim’s uh 00:42:27.745-->00:42:36.687 maple machine. Uh there is an auto execute feature in Maple uh which can be used to execute 00:42:36.687-->00:42:47.832 native commands uh with this but it uh requires user interaction so it’s a bit hard to exploit 00:42:47.832-->00:42:55.473 but you can combine this uh remote control server with the fact that the application is 00:42:55.473-->00:43:07.285 susceptible to XXE. Uh does not need user interaction but you can also do SSRF or uh download 00:43:07.285-->00:43:20.398 files from victim’s machine uh using an out of band XXC attack which I am going to show you. So 00:43:20.398-->00:43:32.577 uh, while maple is starting you can see that uh this is just a simple uh XXC pay load. I am 00:43:32.577-->00:43:41.085 starting an FTP server that will receive the file we are going to steal. I am also starting a web 00:43:41.085-->00:44:03.040 server that serves the second stage of the XXC uh pay load. Ok. Fast-forward. And I am also 00:44:03.040-->00:44:11.849 starting an SMB server to uh serve my uh malicious Maple document and now I can use the 00:44:11.849-->00:44:24.328 remote control server to open that document in the victim’s uh Maple. So there’s ping, ACK and 00:44:24.328-->00:44:37.375 I am opening that file from my server and uh this is where you will see the uh result of the uh 00:44:37.375-->00:44:44.482 XXC exploit. Uh you can see it is a director listing uh because uh Maple is in java and you can 00:44:44.482-->00:44:54.825 do director listing uh in Java with XXC but I know you are you all want to see another 00:44:54.825-->00:45:10.174 calculator [audience laughter] so I am going to give you that shortly. So it’s the same attack 00:45:10.174-->00:45:19.517 I’m just yeah there’s a calculator. It’s a pesky calculator. Ok uh this was my uh 00:45:19.517-->00:45:30.061 last uh demo and uh this is the uh end of my talk. There are a lot of stuff to look at uh in 00:45:30.061-->00:45:37.868 these software uh still. These are just a few ideas these are the things I will probably look 00:45:37.868-->00:45:45.243 at in the future. Uh but I encourage you to uh do the same look around at this software. Uh 00:45:45.243-->00:00:00.000 this is the end thank you for listening to my talk [audience claps]