{"id":8501,"date":"2023-05-12T21:35:49","date_gmt":"2023-05-12T21:35:49","guid":{"rendered":"https:\/\/www.hexacorn.com\/blog\/?p=8501"},"modified":"2023-05-12T21:36:06","modified_gmt":"2023-05-12T21:36:06","slug":"matlab-persistent-lolbin-2-years-too-late-but-always","status":"publish","type":"post","link":"https:\/\/www.hexacorn.com\/blog\/2023\/05\/12\/matlab-persistent-lolbin-2-years-too-late-but-always\/","title":{"rendered":"Matlab persistent lolbin &#8211; 2 years too late, but always&#8230;"},"content":{"rendered":"\n<p>I just realized I have never published a post about lolbinish\/persistencish Matlab feature that I referred to in this <a href=\"https:\/\/twitter.com\/Hexacorn\/status\/1410374511103516676?s=20\">twit<\/a>. The Tl;dr; is that Matlab can load a DLL of our choice when we use its feature that is both Matlab-user friendly, and &#8230; unbelievable.<\/p>\n\n\n\n<p>Using the following command line invocation:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">MATLAB.exe -nosplash -nodesktop -r \"run('c:\\test\\test.m'); exit;\"<\/pre>\n\n\n\n<p>we can instruct matlab to load the matlab file named &#8216;test.m&#8217; in a batch-like fashion.<\/p>\n\n\n\n<p>The &#8216;test.m&#8217; in this example include a short piece of code shown below:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">x = foo();<\/pre>\n\n\n\n<p>When matlab loads the &#8216;test.m&#8217;, it tries to resolve the function &#8216;foo&#8217; that it will eventually recognize as unknown; as a result, it will look for locally present Matlab executable files (*.mex32 on 32-, and *.mexw64 on 64-bit Windows), and will try to find that function there. In our case (on 64-bit version of OS\/matlab) it will look for a &#8216;foo.mexw64&#8217; file, load it (it is a DLL), and then call a function <em>mexFunctio<\/em>n acting as an interface between matlab and the matlab executable.<\/p>\n\n\n\n<p>The example session is shown in this animation:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><a href=\"https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2023\/05\/matlab.gif\"><img decoding=\"async\" src=\"https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2023\/05\/matlab.gif\" alt=\"\" class=\"wp-image-8503\" width=\"500\"\/><\/a><\/figure>\n\n\n\n<p>It&#8217;s obvious there are at least two scenarios where this &#8216;feature&#8217; can be used for offensive purposes:<\/p>\n\n\n\n<ul><li>niche Lolbin &#8211; having a library of your choice loaded by matlab may help to evade security software<\/li><li>niche and stealthy persistence &#8211; matlab files can be modified in a viral way to force the loading our our library of choice at some random moment in the future<\/li><\/ul>\n","protected":false},"excerpt":{"rendered":"<p>I just realized I have never published a post about lolbinish\/persistencish Matlab feature that I referred to in this twit. The Tl;dr; is that Matlab can load a DLL of our choice when we use its feature that is both &hellip; <a href=\"https:\/\/www.hexacorn.com\/blog\/2023\/05\/12\/matlab-persistent-lolbin-2-years-too-late-but-always\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[35,64],"tags":[],"_links":{"self":[{"href":"https:\/\/www.hexacorn.com\/blog\/wp-json\/wp\/v2\/posts\/8501"}],"collection":[{"href":"https:\/\/www.hexacorn.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hexacorn.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hexacorn.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hexacorn.com\/blog\/wp-json\/wp\/v2\/comments?post=8501"}],"version-history":[{"count":4,"href":"https:\/\/www.hexacorn.com\/blog\/wp-json\/wp\/v2\/posts\/8501\/revisions"}],"predecessor-version":[{"id":8506,"href":"https:\/\/www.hexacorn.com\/blog\/wp-json\/wp\/v2\/posts\/8501\/revisions\/8506"}],"wp:attachment":[{"href":"https:\/\/www.hexacorn.com\/blog\/wp-json\/wp\/v2\/media?parent=8501"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hexacorn.com\/blog\/wp-json\/wp\/v2\/categories?post=8501"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hexacorn.com\/blog\/wp-json\/wp\/v2\/tags?post=8501"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}