{"id":1047,"date":"2015-02-14T00:07:27","date_gmt":"2015-02-14T00:07:27","guid":{"rendered":"http:\/\/www.gironsec.com\/blog\/?p=1047"},"modified":"2015-02-20T16:47:24","modified_gmt":"2015-02-20T16:47:24","slug":"ctb-locker-and-dropper","status":"publish","type":"post","link":"https:\/\/www.gironsec.com\/blog\/2015\/02\/ctb-locker-and-dropper\/","title":{"rendered":"CTB-Locker and Dropper"},"content":{"rendered":"<p>Users of the net dread this screen. They feel when they see it all hope is lost.<br \/>\n<a href=\"http:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/zomg-no2.png\" target=\"_blank\"><img decoding=\"async\" loading=\"lazy\" src=\"http:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/zomg-no2-300x197.png\" alt=\"zomg no2\" width=\"300\" height=\"197\" class=\"alignnone size-medium wp-image-1048\" srcset=\"https:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/zomg-no2-300x197.png 300w, https:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/zomg-no2.png 825w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><br \/>\nIn the case of this ransomware dropper, the same holds true.<br \/>\n<a href=\"http:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/ZOMG-NOOO.png\" target=\"_blank\"><img decoding=\"async\" loading=\"lazy\" src=\"http:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/ZOMG-NOOO-300x159.png\" alt=\"ZOMG NOOO\" width=\"300\" height=\"159\" class=\"alignnone size-medium wp-image-1051\" srcset=\"https:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/ZOMG-NOOO-300x159.png 300w, https:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/ZOMG-NOOO-1024x543.png 1024w, https:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/ZOMG-NOOO.png 1920w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><br \/>\nIn fact, in running this, I lost my downloads folder >:(<br \/>\n<a href=\"http:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/damnit.png\" target=\"_blank\"><img decoding=\"async\" loading=\"lazy\" src=\"http:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/damnit-300x115.png\" alt=\"damnit\" width=\"300\" height=\"115\" class=\"alignnone size-medium wp-image-1054\" srcset=\"https:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/damnit-300x115.png 300w, https:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/damnit-1024x394.png 1024w, https:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/damnit.png 1157w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><br \/>\nIndeed, a risk all malware reverse engineers take. Live and learn right? Anywho, let&#8217;s dive into this bastard already.<\/p>\n<p>First things first, here&#8217;s what the thing looks like on VirusTotal:<br \/>\n<a href=\"http:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/virus_total.png\" target=\"_blank\"><img decoding=\"async\" loading=\"lazy\" src=\"http:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/virus_total-300x211.png\" alt=\"virus_total\" width=\"300\" height=\"211\" class=\"alignnone size-medium wp-image-1055\" srcset=\"https:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/virus_total-300x211.png 300w, https:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/virus_total.png 969w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><br \/>\nA pretty dinky file to be honest, barely scratching 40 KB.<br \/>\n<a href=\"http:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/dinkyfile.png\" target=\"_blank\"><img decoding=\"async\" loading=\"lazy\" src=\"http:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/dinkyfile.png\" alt=\"dinkyfile\" width=\"523\" height=\"121\" class=\"alignnone size-full wp-image-1056\" srcset=\"https:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/dinkyfile.png 523w, https:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/dinkyfile-300x69.png 300w\" sizes=\"(max-width: 523px) 100vw, 523px\" \/><\/a><\/p>\n<p>A quick peek in IDA shows us what its like under the hood:<br \/>\n<a href=\"http:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/quickidapeek.png\" target=\"_blank\"><img decoding=\"async\" loading=\"lazy\" src=\"http:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/quickidapeek-300x169.png\" alt=\"quickidapeek\" width=\"300\" height=\"169\" class=\"alignnone size-medium wp-image-1059\" srcset=\"https:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/quickidapeek-300x169.png 300w, https:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/quickidapeek-1024x576.png 1024w, https:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/quickidapeek.png 1920w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><br \/>\nMemory packed. How the hell do I know that just peeking real quick? Whenever there&#8217;s a bunch of uninitialized data (yellow) that looks like garbage, its most likely its memory packed. This most likely means they&#8217;re gonna try the either the RunPE method, or some sort of code injection. Looking through the thing in IDA, I&#8217;m not seeing the prerequisites for RunPE, but I do however see one function that stands out for code injection:<br \/>\n<a href=\"http:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/code_injection_point.png\" target=\"_blank\"><img decoding=\"async\" loading=\"lazy\" src=\"http:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/code_injection_point-290x300.png\" alt=\"code_injection_point\" width=\"290\" height=\"300\" class=\"alignnone size-medium wp-image-1062\" srcset=\"https:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/code_injection_point-290x300.png 290w, https:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/code_injection_point.png 786w\" sizes=\"(max-width: 290px) 100vw, 290px\" \/><\/a><br \/>\nSee the &#8216;jmp dword ptr[esi]&#8217; sequence? This is where the malware will make its process leap to another section after preparing the loader. Also note the <a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/windows\/desktop\/aa366890%28v=vs.85%29.aspx\" target=\"_blank\">VirtualAllocEx<\/a> call for used for allocating some space in another region. The code sequence appears to loop through code and inject it into the region returned by the VirtualAlloc call, then when its done, jumps to it.<br \/>\nThat said, let&#8217;s load this thing into the debugger and get to work. I start by setting my breakpoints on the usual malware fare (Process creations, file, memory, thread manipulation, etc), and start, breaking at the code space mentioned in IDA:<br \/>\n<a href=\"http:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/start1_2.png\" target=\"_blank\"><img decoding=\"async\" loading=\"lazy\" src=\"http:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/start1_2-300x159.png\" alt=\"start1_2\" width=\"300\" height=\"159\" class=\"alignnone size-medium wp-image-1063\" srcset=\"https:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/start1_2-300x159.png 300w, https:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/start1_2-1024x542.png 1024w, https:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/start1_2.png 1920w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><br \/>\nAs I suspected, the malware is injecting the code in ECX into the space pointed to by ESI or in this case 003E0000. We see our jump and more (new) instructions. Let&#8217;s hit F9 and continue on through.<br \/>\n<a href=\"http:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/start2.png\" target=\"_blank\"><img decoding=\"async\" loading=\"lazy\" src=\"http:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/start2-300x159.png\" alt=\"start2\" width=\"300\" height=\"159\" class=\"alignnone size-medium wp-image-1061\" srcset=\"https:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/start2-300x159.png 300w, https:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/start2-1024x542.png 1024w, https:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/start2.png 1920w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><br \/>\nThere&#8217;s a lot going on in this picture. As I said in red, we got a hit, a VirtualProtect call that&#8217;s modifying the address space of the original byte space 00400000 from outside (003F00FB). Casual observation shows us an exe header in our registers pointing us to another address space at 008f0000. What does this mean? It means the malware dumped its loader into 008f0000 and is attempting to write the contents into itself in 00400000 (original address space). A form of self modifying code. This also means I was wrong with my RunPE guess. Oh well, can&#8217;t win em all right?<\/p>\n<p>Let&#8217;s dump the exe in 008f0000 (right click dump, choose save file) and peek in IDA.<\/p>\n<p><a href=\"http:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/quickidapeek_2.png\" target=\"_blank\"><img decoding=\"async\" loading=\"lazy\" src=\"http:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/quickidapeek_2-300x163.png\" alt=\"quickidapeek_2\" width=\"300\" height=\"163\" class=\"alignnone size-medium wp-image-1064\" srcset=\"https:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/quickidapeek_2-300x163.png 300w, https:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/quickidapeek_2-1024x555.png 1024w, https:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/quickidapeek_2.png 1920w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><br \/>\nThat&#8217;s a bit more like it. Note the URL&#8217;s hard coded inside. This seems to be our stage 2. There are few functions (thank GOD) which makes reversing this much easier. <\/p>\n<p>Further down from main, we see a function that attempts to grab something from the resources section (FindResource).<br \/>\n<a href=\"http:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/resource_section.png\"  target=\"_blank\"><img decoding=\"async\" loading=\"lazy\" src=\"http:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/resource_section.png\" alt=\"resource_section\" width=\"652\" height=\"404\" class=\"alignnone size-full wp-image-1067\" srcset=\"https:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/resource_section.png 652w, https:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/resource_section-300x186.png 300w\" sizes=\"(max-width: 652px) 100vw, 652px\" \/><\/a><br \/>\nThere&#8217;s something there when we load the thing up with CFF Explorer:<br \/>\n<a href=\"http:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/findresource2.png\" target=\"_blank\"><img decoding=\"async\" loading=\"lazy\" src=\"http:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/findresource2-300x259.png\" alt=\"findresource2\" width=\"300\" height=\"259\" class=\"alignnone size-medium wp-image-1068\" srcset=\"https:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/findresource2-300x259.png 300w, https:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/findresource2-1024x883.png 1024w, https:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/findresource2.png 1041w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><br \/>\nA cab file? Sure ok, whatever. What&#8217;s in the cab file?<br \/>\n<a href=\"http:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/findresource3.png\" target=\"_blank\"><img decoding=\"async\" loading=\"lazy\" src=\"http:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/findresource3-300x156.png\" alt=\"findresource3\" width=\"300\" height=\"156\" class=\"alignnone size-medium wp-image-1069\" srcset=\"https:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/findresource3-300x156.png 300w, https:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/findresource3-1024x534.png 1024w, https:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/findresource3.png 1919w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><br \/>\nRTF document. My guess is file is shown to the user so they don&#8217;t think anything is up \/ wrong. <\/p>\n<p>The other functions are responsible for downloading the stage2, and decrypting \/ running it. For that, let&#8217;s step through. In this case, I used ollydump after the process changed its original bytes with the newly loaded sequence. Skipping past the part where it launches the RTF doc we just dissected with ShellExecute, we see a number of functions and a sleep.<br \/>\n<a href=\"http:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/making_rounds.png\" target=\"_blank\"><img decoding=\"async\" loading=\"lazy\" src=\"http:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/making_rounds-300x107.png\" alt=\"making_rounds\" width=\"300\" height=\"107\" class=\"alignnone size-medium wp-image-1070\" srcset=\"https:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/making_rounds-300x107.png 300w, https:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/making_rounds-1024x367.png 1024w, https:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/making_rounds.png 1083w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><br \/>\nThe sub routine at 00401a8a just downloads a file. In this case, the malware is downloading the index page from Windows update I guess in an attempt to fool heuristics? After the long sleep, the malware goes through its stage2 loop and attempts to download the encrypted file.<br \/>\n<a href=\"http:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/download_stage2.png\" target=\"_blank\"><img decoding=\"async\" loading=\"lazy\" src=\"http:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/download_stage2-300x88.png\" alt=\"download_stage2\" width=\"300\" height=\"88\" class=\"alignnone size-medium wp-image-1071\" srcset=\"https:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/download_stage2-300x88.png 300w, https:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/download_stage2-1024x300.png 1024w, https:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/download_stage2.png 1593w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><br \/>\nRecall that 00401A8A is for downloading files and takes 1 argument. The value pushed is &#8216;evalero.com\/img\/cario.tar.gz&#8217;.<\/p>\n<p>If the file is non existent \/ no good, then the malware continues after sleeping for 5 seconds with the next address in the list.<br \/>\n<a href=\"http:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/sleep5seconds_tryagain.png\" target=\"_blank\"><img decoding=\"async\" loading=\"lazy\" src=\"http:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/sleep5seconds_tryagain-300x98.png\" alt=\"sleep5seconds_tryagain\" width=\"300\" height=\"98\" class=\"alignnone size-medium wp-image-1072\" srcset=\"https:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/sleep5seconds_tryagain-300x98.png 300w, https:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/sleep5seconds_tryagain.png 799w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>Since the first few links are dead ends, it takes a few iterations before finding a payload:<br \/>\n<a href=\"http:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/hardcoded_next.png\" target=\"_blank\"><img decoding=\"async\" loading=\"lazy\" src=\"http:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/hardcoded_next-300x170.png\" alt=\"hardcoded_next\" width=\"300\" height=\"170\" class=\"alignnone size-medium wp-image-1073\" srcset=\"https:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/hardcoded_next-300x170.png 300w, https:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/hardcoded_next.png 928w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>This link actually worked.<br \/>\nHere&#8217;s what it looks like:<br \/>\n<a href=\"http:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/cairo_tar_gz.png\" target=\"_blank\"><img decoding=\"async\" loading=\"lazy\" src=\"http:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/cairo_tar_gz-300x265.png\" alt=\"cairo_tar_gz\" width=\"300\" height=\"265\" class=\"alignnone size-medium wp-image-1065\" srcset=\"https:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/cairo_tar_gz-300x265.png 300w, https:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/cairo_tar_gz.png 689w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><br \/>\nEncrypted of course&#8230;.<\/p>\n<p>After downloading the file, the malware stores the contents in EDI and decrypts via the function 0040179E.<br \/>\n<a href=\"http:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/cryptedfile1.png\" target=\"_blank\"><img decoding=\"async\" loading=\"lazy\" src=\"http:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/cryptedfile1-300x77.png\" alt=\"cryptedfile1\" width=\"300\" height=\"77\" class=\"alignnone size-medium wp-image-1074\" srcset=\"https:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/cryptedfile1-300x77.png 300w, https:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/cryptedfile1.png 991w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><br \/>\nLet&#8217;s step on through<br \/>\n<a href=\"http:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/cryptedfile2.png\" target=\"_blank\"><img decoding=\"async\" loading=\"lazy\" src=\"http:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/cryptedfile2-253x300.png\" alt=\"cryptedfile2\" width=\"253\" height=\"300\" class=\"alignnone size-medium wp-image-1075\" srcset=\"https:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/cryptedfile2-253x300.png 253w, https:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/cryptedfile2.png 599w\" sizes=\"(max-width: 253px) 100vw, 253px\" \/><\/a><\/p>\n<p>Looking at the code, it looks like it looks like simple XOR, but with a few extra steps. It also appears to write the contents after decryption into EAX. Let&#8217;s be lazy and run until return:<br \/>\n<a href=\"http:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/cryptedfile4.png\" target=\"_blank\"><img decoding=\"async\" loading=\"lazy\" src=\"http:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/cryptedfile4-300x197.png\" alt=\"cryptedfile4\" width=\"300\" height=\"197\" class=\"alignnone size-medium wp-image-1076\" srcset=\"https:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/cryptedfile4-300x197.png 300w, https:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/cryptedfile4-1024x672.png 1024w, https:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/cryptedfile4.png 1160w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>Sure enough, at address 01760000 we have our decrypted file complete with exe header. After returning, the code then writes the file, runs it with ShellExecute, sleeps for 10 seconds and deletes the file, exiting.<br \/>\n<a href=\"http:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/write_it_run_it_delete_it.png\" target=\"_blank\"><img decoding=\"async\" loading=\"lazy\" src=\"http:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/write_it_run_it_delete_it-300x134.png\" alt=\"write_it_run_it_delete_it\" width=\"300\" height=\"134\" class=\"alignnone size-medium wp-image-1077\" srcset=\"https:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/write_it_run_it_delete_it-300x134.png 300w, https:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/write_it_run_it_delete_it.png 1010w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>So what&#8217;s in this new file we just decrypted? It&#8217;s slightly larger than the original file and has a generic looking icon too:<br \/>\n<a href=\"http:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/17.png\" target=\"_blank\"><img decoding=\"async\" loading=\"lazy\" src=\"http:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/17-300x83.png\" alt=\"_17\" width=\"300\" height=\"83\" class=\"alignnone size-medium wp-image-1078\" srcset=\"https:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/17-300x83.png 300w, https:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/17.png 810w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>Peeking in IDA shows us its packed (OF COURSE IT IS).<br \/>\n<a href=\"http:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/quickidapeek_3.png\" target=\"_blank\"><img decoding=\"async\" loading=\"lazy\" src=\"http:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/quickidapeek_3-300x163.png\" alt=\"quickidapeek_3\" width=\"300\" height=\"163\" class=\"alignnone size-medium wp-image-1079\" srcset=\"https:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/quickidapeek_3-300x163.png 300w, https:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/quickidapeek_3-1024x555.png 1024w, https:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/quickidapeek_3.png 1920w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>Note the FindResource call, and the long red section. This is actually garbage. Most of this binary is like this just to anger me. The only code I&#8217;m interested in is at 00402A80 with &#8216;jmp     dword ptr [edx]&#8217;.<br \/>\n<a href=\"http:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/code_injection_point2.png\" target=\"_blank><img decoding=\"async\" loading=\"lazy\" src=\"http:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/code_injection_point2-294x300.png\" alt=\"code_injection_point2\" width=\"294\" height=\"300\" class=\"alignnone size-medium wp-image-1080\" srcset=\"https:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/code_injection_point2-294x300.png 294w, https:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/code_injection_point2.png 733w\" sizes=\"(max-width: 294px) 100vw, 294px\" \/><\/a><br \/>\nLook familiar? it should, it&#8217;s the same code injection jump from the previous binary. How does the thing inject the code after decrypting it? Beats the heck outta me, but there&#8217;s a lot of jumping around involved:<br \/>\n<!-- HTML generated using hilite.me --><\/p>\n<div style=\"background: #ffffff; overflow:auto;width:auto;border:solid gray;border-width:.1em .1em .1em .8em;padding:.2em .6em;\">\n<pre style=\"margin: 0; line-height: 125%\">.text:<span style=\"color: #a61717; background-color: #e3d2d2\">0040294<\/span>B                 cmp     ebx, <span style=\"color: #0000FF\">0<\/span>\r\n.text:<span style=\"color: #a61717; background-color: #e3d2d2\">0040294<\/span>E                 jz      loc_402A57\r\n.text:<span style=\"color: #a61717; background-color: #e3d2d2\">00402954<\/span>                 sbb     ecx, <span style=\"color: #0000FF\">0FFFFFF86h<\/span>\r\n.text:<span style=\"color: #a61717; background-color: #e3d2d2\">00402957<\/span>                 sub     ecx, <span style=\"color: #0000FF\">0FFFFFFDFh<\/span>\r\n.text:<span style=\"color: #a61717; background-color: #e3d2d2\">0040295<\/span>A                 sub     eax, eax\r\n.text:<span style=\"color: #a61717; background-color: #e3d2d2\">0040295<\/span>C                 dec     eax\r\n.text:<span style=\"color: #a61717; background-color: #e3d2d2\">0040295<\/span>D                 and     eax, [esi]\r\n.text:<span style=\"color: #a61717; background-color: #e3d2d2\">0040295<\/span>F                 mov     cl, <span style=\"color: #000080; font-weight: bold\">byte<\/span> ptr unk_4070F1\r\n.text:<span style=\"color: #a61717; background-color: #e3d2d2\">00402965<\/span>                 sub     <span style=\"color: #000080; font-weight: bold\">dword<\/span>_4071BE+<span style=\"color: #0000FF\">2<\/span>, ecx\r\n.text:<span style=\"color: #a61717; background-color: #e3d2d2\">0040296<\/span>B                 add     <span style=\"color: #000080; font-weight: bold\">dword<\/span>_4070EC+<span style=\"color: #0000FF\">1<\/span>, ecx\r\n.text:<span style=\"color: #a61717; background-color: #e3d2d2\">00402971<\/span>                 sub     <span style=\"color: #000080; font-weight: bold\">dword<\/span>_407030, ecx\r\n.text:<span style=\"color: #a61717; background-color: #e3d2d2\">00402977<\/span>                 sbb     ecx, <span style=\"color: #0000FF\">0FFFFFFA5h<\/span>\r\n.text:<span style=\"color: #a61717; background-color: #e3d2d2\">0040297<\/span>A                 add     esi, <span style=\"color: #0000FF\">4<\/span>\r\n.text:<span style=\"color: #a61717; background-color: #e3d2d2\">0040297<\/span>D                 add     ecx, ecx\r\n.text:<span style=\"color: #a61717; background-color: #e3d2d2\">0040297<\/span>F                 add     <span style=\"color: #000080; font-weight: bold\">dword<\/span>_407030+<span style=\"color: #0000FF\">3<\/span>, ecx\r\n.text:<span style=\"color: #a61717; background-color: #e3d2d2\">00402985<\/span>                 not     eax\r\n.text:<span style=\"color: #a61717; background-color: #e3d2d2\">00402987<\/span>                 sub     ch, cl\r\n.text:<span style=\"color: #a61717; background-color: #e3d2d2\">00402989<\/span>                 sbb     ecx, ecx\r\n.text:<span style=\"color: #a61717; background-color: #e3d2d2\">0040298<\/span>B                 or      ecx, <span style=\"color: #0000FF\">0FFFFFFA7h<\/span>\r\n.text:<span style=\"color: #a61717; background-color: #e3d2d2\">0040298<\/span>E                 mov     <span style=\"color: #000080; font-weight: bold\">byte<\/span> ptr <span style=\"color: #000080; font-weight: bold\">dword<\/span>_407116+<span style=\"color: #0000FF\">2<\/span>, <span style=\"color: #0000FF\">0D5h<\/span>\r\n.text:<span style=\"color: #a61717; background-color: #e3d2d2\">00402995<\/span>                 sbb     <span style=\"color: #000080; font-weight: bold\">dword<\/span> ptr unk_4070AC, ecx\r\n.text:<span style=\"color: #a61717; background-color: #e3d2d2\">0040299<\/span>B                 lea     eax, [eax-<span style=\"color: #0000FF\">11h<\/span>]\r\n.text:<span style=\"color: #a61717; background-color: #e3d2d2\">0040299<\/span>E                 xor     ecx, <span style=\"color: #0000FF\">10h<\/span>\r\n.text:<span style=\"color: #a61717; background-color: #e3d2d2\">004029<\/span>A1                 mov     ecx, <span style=\"color: #000080; font-weight: bold\">dword<\/span>_4070BA\r\n.text:<span style=\"color: #a61717; background-color: #e3d2d2\">004029<\/span>A7                 mov     <span style=\"color: #000080; font-weight: bold\">dword<\/span>_407017, ecx\r\n.text:<span style=\"color: #a61717; background-color: #e3d2d2\">004029<\/span>AD                 mov     <span style=\"color: #000080; font-weight: bold\">byte<\/span> ptr <span style=\"color: #000080; font-weight: bold\">dword<\/span>_40710D, <span style=\"color: #0000FF\">8Dh<\/span>\r\n.text:<span style=\"color: #a61717; background-color: #e3d2d2\">004029<\/span>B4                 xor     eax, edi\r\n.text:<span style=\"color: #a61717; background-color: #e3d2d2\">004029<\/span>B6                 sub     ecx, <span style=\"color: #0000FF\">0FFFFFFDBh<\/span>\r\n.text:<span style=\"color: #a61717; background-color: #e3d2d2\">004029<\/span>B9                 mov     <span style=\"color: #000080; font-weight: bold\">byte<\/span> ptr <span style=\"color: #000080; font-weight: bold\">dword<\/span>_407012+<span style=\"color: #0000FF\">2<\/span>, <span style=\"color: #0000FF\">4<\/span>\r\n.text:<span style=\"color: #a61717; background-color: #e3d2d2\">004029<\/span>C0                 adc     ecx, ecx\r\n.text:<span style=\"color: #a61717; background-color: #e3d2d2\">004029<\/span>C2                 clc\r\n.text:<span style=\"color: #a61717; background-color: #e3d2d2\">004029<\/span>C3                 sbb     eax, <span style=\"color: #0000FF\">0FFFFFFFFh<\/span>\r\n.text:<span style=\"color: #a61717; background-color: #e3d2d2\">004029<\/span>C6                 mov     <span style=\"color: #000080; font-weight: bold\">byte<\/span>_407029, <span style=\"color: #0000FF\">37h<\/span>\r\n.text:<span style=\"color: #a61717; background-color: #e3d2d2\">004029<\/span>CD                 sbb     ecx, <span style=\"color: #0000FF\">57h<\/span>\r\n.text:<span style=\"color: #a61717; background-color: #e3d2d2\">004029<\/span>D0                 xor     <span style=\"color: #000080; font-weight: bold\">dword<\/span>_4071FA+<span style=\"color: #0000FF\">1<\/span>, ecx\r\n.text:<span style=\"color: #a61717; background-color: #e3d2d2\">004029<\/span>D6                 add     ecx, ecx\r\n.text:<span style=\"color: #a61717; background-color: #e3d2d2\">004029<\/span>D8                 xor     edi, edi\r\n.text:<span style=\"color: #a61717; background-color: #e3d2d2\">004029<\/span>DA                 sub     edi, eax\r\n.text:<span style=\"color: #a61717; background-color: #e3d2d2\">004029<\/span>DC                 neg     edi\r\n.text:<span style=\"color: #a61717; background-color: #e3d2d2\">004029<\/span>DE                 mov     <span style=\"color: #000080; font-weight: bold\">byte<\/span> ptr <span style=\"color: #000080; font-weight: bold\">dword<\/span>_40706F+<span style=\"color: #0000FF\">2<\/span>, <span style=\"color: #0000FF\">42h<\/span>\r\n.text:<span style=\"color: #a61717; background-color: #e3d2d2\">004029<\/span>E5                 sbb     ecx, ecx\r\n.text:<span style=\"color: #a61717; background-color: #e3d2d2\">004029<\/span>E7                 mov     <span style=\"color: #000080; font-weight: bold\">byte<\/span> ptr <span style=\"color: #000080; font-weight: bold\">dword<\/span>_4070C1, <span style=\"color: #0000FF\">0C4h<\/span>\r\n.text:<span style=\"color: #a61717; background-color: #e3d2d2\">004029<\/span>EE                 or      ecx, <span style=\"color: #0000FF\">52h<\/span>\r\n.text:<span style=\"color: #a61717; background-color: #e3d2d2\">004029<\/span>F1                 rol     edi, <span style=\"color: #0000FF\">2<\/span>\r\n.text:<span style=\"color: #a61717; background-color: #e3d2d2\">004029<\/span>F4                 mov     <span style=\"color: #000080; font-weight: bold\">byte<\/span> ptr <span style=\"color: #000080; font-weight: bold\">dword<\/span>_407121+<span style=\"color: #0000FF\">1<\/span>, <span style=\"color: #0000FF\">0FFh<\/span>\r\n.text:<span style=\"color: #a61717; background-color: #e3d2d2\">004029<\/span>FB                 mov     ecx, <span style=\"color: #000080; font-weight: bold\">dword<\/span>_407162+<span style=\"color: #0000FF\">2<\/span>\r\n.text:<span style=\"color: #a61717; background-color: #e3d2d2\">00402<\/span>A01                 add     cl, ch\r\n.text:<span style=\"color: #a61717; background-color: #e3d2d2\">00402<\/span>A03                 mov     <span style=\"color: #000080; font-weight: bold\">byte<\/span> ptr <span style=\"color: #000080; font-weight: bold\">dword<\/span>_4070C7+<span style=\"color: #0000FF\">2<\/span>, <span style=\"color: #0000FF\">77h<\/span>\r\n.text:<span style=\"color: #a61717; background-color: #e3d2d2\">00402<\/span>A0A                 rol     edi, <span style=\"color: #0000FF\">6<\/span>\r\n.text:<span style=\"color: #a61717; background-color: #e3d2d2\">00402<\/span>A0D                 adc     ecx, <span style=\"color: #0000FF\">0FFFFFF9Fh<\/span>\r\n.text:<span style=\"color: #a61717; background-color: #e3d2d2\">00402<\/span>A10                 sbb     ecx, ecx\r\n.text:<span style=\"color: #a61717; background-color: #e3d2d2\">00402<\/span>A12                 push    eax\r\n.text:<span style=\"color: #a61717; background-color: #e3d2d2\">00402<\/span>A13                 pop     <span style=\"color: #000080; font-weight: bold\">dword<\/span> ptr [edx]\r\n.text:<span style=\"color: #a61717; background-color: #e3d2d2\">00402<\/span>A15                 mov     <span style=\"color: #000080; font-weight: bold\">byte<\/span> ptr <span style=\"color: #000080; font-weight: bold\">dword<\/span>_40706F, <span style=\"color: #0000FF\">0CEh<\/span>\r\n.text:<span style=\"color: #a61717; background-color: #e3d2d2\">00402<\/span>A1C                 xor     <span style=\"color: #000080; font-weight: bold\">dword<\/span>_4070F6+<span style=\"color: #0000FF\">1<\/span>, ecx\r\n.text:<span style=\"color: #a61717; background-color: #e3d2d2\">00402<\/span>A22                 sub     edx, <span style=\"color: #0000FF\">0FFFFFFFCh<\/span>\r\n.text:<span style=\"color: #a61717; background-color: #e3d2d2\">00402<\/span>A25                 mov     ecx, <span style=\"color: #000080; font-weight: bold\">dword<\/span>_4071FA\r\n.text:<span style=\"color: #a61717; background-color: #e3d2d2\">00402<\/span>A2B                 sub     <span style=\"color: #000080; font-weight: bold\">dword<\/span>_40711D+<span style=\"color: #0000FF\">1<\/span>, ecx\r\n.text:<span style=\"color: #a61717; background-color: #e3d2d2\">00402<\/span>A31                 and     ecx, <span style=\"color: #0000FF\">55h<\/span>\r\n.text:<span style=\"color: #a61717; background-color: #e3d2d2\">00402<\/span>A34                 or      <span style=\"color: #000080; font-weight: bold\">dword<\/span>_407135, ecx\r\n.text:<span style=\"color: #a61717; background-color: #e3d2d2\">00402<\/span>A3A                 mov     <span style=\"color: #000080; font-weight: bold\">byte<\/span> ptr <span style=\"color: #000080; font-weight: bold\">dword<\/span>_40701B+<span style=\"color: #0000FF\">2<\/span>, <span style=\"color: #0000FF\">7Bh<\/span>\r\n.text:<span style=\"color: #a61717; background-color: #e3d2d2\">00402<\/span>A41                 lea     ebx, [ebx-<span style=\"color: #0000FF\">4<\/span>]\r\n.text:<span style=\"color: #a61717; background-color: #e3d2d2\">00402<\/span>A44                 mov     <span style=\"color: #000080; font-weight: bold\">byte<\/span>_407069, <span style=\"color: #0000FF\">0EDh<\/span>\r\n.text:<span style=\"color: #a61717; background-color: #e3d2d2\">00402<\/span>A4B                 sbb     <span style=\"color: #000080; font-weight: bold\">dword<\/span>_407104, ecx\r\n.text:<span style=\"color: #a61717; background-color: #e3d2d2\">00402<\/span>A51                 push    offset loc_40294B\r\n.text:<span style=\"color: #a61717; background-color: #e3d2d2\">00402<\/span>A56                 retn\r\n.text:<span style=\"color: #a61717; background-color: #e3d2d2\">00402<\/span>A57 <span style=\"color: #008800; font-style: italic\">; ---------------------------------------------------------------------------<\/span>\r\n.text:<span style=\"color: #a61717; background-color: #e3d2d2\">00402<\/span>A57\r\n.text:<span style=\"color: #a61717; background-color: #e3d2d2\">00402<\/span>A57 loc_402A57:                             <span style=\"color: #008800; font-style: italic\">; CODE XREF: .text:0040294E\u0018j<\/span>\r\n.text:<span style=\"color: #a61717; background-color: #e3d2d2\">00402<\/span>A57                 mov     edx, esp\r\n.text:<span style=\"color: #a61717; background-color: #e3d2d2\">00402<\/span>A59                 mov     esi, ds:GetModuleHandleA\r\n.text:<span style=\"color: #a61717; background-color: #e3d2d2\">00402<\/span>A5F                 push    esi\r\n.text:<span style=\"color: #a61717; background-color: #e3d2d2\">00402<\/span>A60                 mov     <span style=\"color: #000080; font-weight: bold\">dword<\/span> ptr <span style=\"color: #000080; font-weight: bold\">byte<\/span>_40707D, edi\r\n.text:<span style=\"color: #a61717; background-color: #e3d2d2\">00402<\/span>A66                 sub     <span style=\"color: #000080; font-weight: bold\">dword<\/span>_4071F5, ebx\r\n.text:<span style=\"color: #a61717; background-color: #e3d2d2\">00402<\/span>A6C                 push    offset loc_4028F0\r\n.text:<span style=\"color: #a61717; background-color: #e3d2d2\">00402<\/span>A71                 mov     ah, <span style=\"color: #000080; font-weight: bold\">byte<\/span> ptr <span style=\"color: #000080; font-weight: bold\">dword<\/span>_40710D+<span style=\"color: #0000FF\">2<\/span>\r\n.text:<span style=\"color: #a61717; background-color: #e3d2d2\">00402<\/span>A77                 mov     <span style=\"color: #000080; font-weight: bold\">byte<\/span>_407195, <span style=\"color: #0000FF\">0DCh<\/span>\r\n.text:<span style=\"color: #a61717; background-color: #e3d2d2\">00402<\/span>A7E                 xor     al, <span style=\"color: #0000FF\">46h<\/span>\r\n.text:<span style=\"color: #a61717; background-color: #e3d2d2\">00402<\/span>A80                 jmp     <span style=\"color: #000080; font-weight: bold\">dword<\/span> ptr [edx]\r\n<\/pre>\n<\/div>\n<p>Let&#8217;s dive right in and break on this jump like last time shall we?  Stepping into the function brings me into the area of 00A90000:<br \/>\n<a href=\"http:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/crypto_unpacked1.png\" target=\"_blank\"><img decoding=\"async\" loading=\"lazy\" src=\"http:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/crypto_unpacked1-300x159.png\" alt=\"crypto_unpacked1\" width=\"300\" height=\"159\" class=\"alignnone size-medium wp-image-1082\" srcset=\"https:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/crypto_unpacked1-300x159.png 300w, https:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/crypto_unpacked1-1024x542.png 1024w, https:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/crypto_unpacked1.png 1920w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><br \/>\nPeeking through shows a lot of dynamic address resolution and unpacking. Instead of simply just calling functions, the malware dynamically builds a string of a function and then calls it. Weird right?<br \/>\n<a href=\"http:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/function_unpacking.png\" target=\"_blank\"><img decoding=\"async\" loading=\"lazy\" src=\"http:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/function_unpacking-300x189.png\" alt=\"function_unpacking\" width=\"300\" height=\"189\" class=\"alignnone size-medium wp-image-1083\" srcset=\"https:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/function_unpacking-300x189.png 300w, https:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/function_unpacking.png 528w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>Like before in stage1, it also replaces the bytes in itself before running. It took some time to find the decryption sequence, but here it is and yes its XOR:<br \/>\n<a href=\"http:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/decryption_sequence_again.png\" target=\"_blank\"><img decoding=\"async\" loading=\"lazy\" src=\"http:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/decryption_sequence_again-300x195.png\" alt=\"decryption_sequence_again\" width=\"300\" height=\"195\" class=\"alignnone size-medium wp-image-1084\" srcset=\"https:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/decryption_sequence_again-300x195.png 300w, https:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/decryption_sequence_again.png 532w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>See the STOS instruction? That instruction copies the value of EAX and places it in the location ES:[EDI] or 00AB0010. This is basic self modifying code with encryption. The LOOPD instruction tells it to loop and jump X number of times (657910 or so). Executing until return and checking in the dump the address 00AB0000 shows us what we want:<br \/>\n<a href=\"http:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/crypto_unpacked3.png\" target=\"_blank\"><img decoding=\"async\" loading=\"lazy\" src=\"http:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/crypto_unpacked3-300x159.png\" alt=\"crypto_unpacked3\" width=\"300\" height=\"159\" class=\"alignnone size-medium wp-image-1085\" srcset=\"https:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/crypto_unpacked3-300x159.png 300w, https:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/crypto_unpacked3-1024x542.png 1024w, https:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/crypto_unpacked3.png 1920w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>Dumping the file and loading it into IDA shows us its packed. Of course. Why wouldn&#8217;t it be packed?<br \/>\n<a href=\"http:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/packedagain.png\" target=\"_blank\"><img decoding=\"async\" loading=\"lazy\" src=\"http:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/packedagain-300x181.png\" alt=\"packedagain\" width=\"300\" height=\"181\" class=\"alignnone size-medium wp-image-1086\" srcset=\"https:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/packedagain-300x181.png 300w, https:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/packedagain-1024x618.png 1024w, https:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/packedagain.png 1202w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>Which means once again I have to dive in to see what it does. I mean I could continue the program, but this is a good stopping point. Immunity complains that its packed (DUH). The first thing I encounter is a call to VirtualAlloc, most likely to free up some space and mark it RWE.<br \/>\n0012FF8C   00495D50  P]I.  \/CALL to VirtualAlloc from _00AB000.00495D4D<br \/>\n0012FF90   00000000  &#8230;.  |Address = NULL<br \/>\n0012FF94   001FC000  .\u00c0\u001f.  |Size = 1FC000 (2080768.)<br \/>\n0012FF98   00001000  .\u0010..  |AllocationType = MEM_COMMIT<br \/>\n0012FF9C   00000004  \u0004&#8230;  \\Protect = PAGE_READWRITE<\/p>\n<p>In an effort to save time, I need to wrap this up. The thing calls VirtualProtect next to set the range, it jumps around a lot before eventually unpacking fully and calling its main function in another address 00690000. <\/p>\n<p>Eventually in the unpacked portion, the malware starts looking for files via the FindFirstFile api with a *.* wildcard. It loops through every file in the user&#8217;s working directory and base directory (nice enough to skip the system directory and program files folder), inspecting each file extension for MDF, XLS, DOC, PDF, ZIP, 7Zip, etc, but it doesn&#8217;t encrypt them yet. Only on the second run.<br \/>\n<a href=\"http:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/findfile.png\"><img decoding=\"async\" loading=\"lazy\" src=\"http:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/findfile.png\" alt=\"findfile\" width=\"575\" height=\"147\" class=\"alignnone size-full wp-image-1091\" srcset=\"https:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/findfile.png 575w, https:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/findfile-300x77.png 300w\" sizes=\"(max-width: 575px) 100vw, 575px\" \/><\/a><br \/>\n0012C5B8   00743D5D  ]=t.  \/CALL to CreateFileW from 00743D57<br \/>\n0012C5BC   00869418  \u0018\u201d\u2020.  |FileName = &#8220;C:\\Documents and Settings\\All Users\\Application Data\\Adobe\\usnpcde&#8221;<br \/>\n0012C5C0   80000000  &#8230;\u20ac  |Access = GENERIC_READ<br \/>\n0012C5C4   00000000  &#8230;.  |ShareMode = 0<br \/>\n0012C5C8   00000000  &#8230;.  |pSecurity = NULL<br \/>\n0012C5CC   00000003  \u0003&#8230;  |Mode = OPEN_EXISTING<br \/>\n0012C5D0   00000002  \u0002&#8230;  |Attributes = HIDDEN<br \/>\n0012C5D4   00000000  &#8230;.  \\hTemplateFile = NULL<\/p>\n<p>It then checks for AV&#8217;s ekrn.exe and avp.exe (Kaspersky and Eset). Why now and not at the beginning? Who knows?<br \/>\n<a href=\"http:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/av_check.png\" target=\"_blank\"><img decoding=\"async\" loading=\"lazy\" src=\"http:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/av_check.png\" alt=\"av_check\" width=\"811\" height=\"497\" class=\"alignnone size-full wp-image-1092\" srcset=\"https:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/av_check.png 811w, https:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/av_check-300x184.png 300w\" sizes=\"(max-width: 811px) 100vw, 811px\" \/><\/a><\/p>\n<p>After this it copies itself to the temp folder:<br \/>\nCopies itself to temp<br \/>\n0012C850   0074309C  \u01530t.  \/CALL to CreateFileW from 0074309A<br \/>\n0012C854   0012D2A0  \u00a0\u00d2\u0012.  |FileName = &#8220;C:\\DOCUME~1\\Joe\\LOCALS~1\\Temp\\ityksxm.exe&#8221;<br \/>\n0012C858   40000000  &#8230;@  |Access = GENERIC_WRITE<br \/>\n0012C85C   00000003  \u0003&#8230;  |ShareMode = FILE_SHARE_READ|FILE_SHARE_WRITE<br \/>\n0012C860   00000000  &#8230;.  |pSecurity = NULL<br \/>\n0012C864   00000002  \u0002&#8230;  |Mode = CREATE_ALWAYS<br \/>\n0012C868   00000000  &#8230;.  |Attributes = 0<br \/>\n0012C86C   00000000  &#8230;.  \\hTemplateFile = NULL<\/p>\n<p>Creates a task for persistence:<\/p>\n<p>0012CB30   7583B76D  m\u00b7\u0192u  \/CALL to CreateFileW from mstask.7583B767<br \/>\n0012CB34   00D173A0  \u00a0s\u00d1.  |FileName = &#8220;C:\\WINDOWS\\Tasks\\ilhorge.job&#8221;<br \/>\n0012CB38   00000000  &#8230;.  |Access = 0<br \/>\n0012CB3C   00000003  \u0003&#8230;  |ShareMode = FILE_SHARE_READ|FILE_SHARE_WRITE<br \/>\n0012CB40   00000000  &#8230;.  |pSecurity = NULL<br \/>\n0012CB44   00000003  \u0003&#8230;  |Mode = OPEN_EXISTING<br \/>\n0012CB48   00000000  &#8230;.  |Attributes = 0<br \/>\n0012CB4C   00000000  &#8230;.  \\hTemplateFile = NULL<\/p>\n<p>Then it sleeps for a little while, before finally exiting:<br \/>\n<a href=\"http:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/final_sleep.png\"  target=\"_blank\"><img decoding=\"async\" loading=\"lazy\" src=\"http:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/final_sleep-300x127.png\" alt=\"final_sleep\" width=\"300\" height=\"127\" class=\"alignnone size-medium wp-image-1089\" srcset=\"https:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/final_sleep-300x127.png 300w, https:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/final_sleep.png 865w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>When it runs again from the scheduled task, that&#8217;s when it changes your background and asks you to read its nice little message, informing you how to get your files back:<br \/>\n<a href=\"http:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/kek.png\" target=\"_blank\"><img decoding=\"async\" loading=\"lazy\" src=\"http:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/kek-300x188.png\" alt=\"kek\" width=\"300\" height=\"188\" class=\"alignnone size-medium wp-image-1093\" srcset=\"https:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/kek-300x188.png 300w, https:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/kek.png 734w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>Never once does the malware&#8217;s second stage write its unencrypted contents to disk, its all contained in RAM making scraping more difficult. I was able to pull the asm contents of the main unpacked function into an IDB file and a text file. There are over 405 THOUSAND lines of assembly code in this bitch. Sure, some of it is data, and most of it is statically linked crap like crypto algorithms, but still, lots of shit to go through.<br \/>\n<a href=\"http:\/\/gironsec.com\/code\/Cryptolocker_Asm_Listing.txt\">Have a peek<\/a>. If you want the IDB file, <a href=\"http:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/cryptolocker_memrange_and_idb.7z\">have at it<\/a>.<\/p>\n<p>When I have time to revisit (Workshop in 1 month!!!!) I will go into more detail about the encryption used, but its pretty tight stuff &#8211; RSA Public key encryption. Block ciphers for large files.<br \/>\nFor now though, it seems someone else <a href=\"https:\/\/zairon.wordpress.com\/2015\/02\/17\/ctb-locker-encryptiondecryption-scheme-in-details\/\" target=\"_blank\">beat me to the punch<\/a>.<\/p>\n<p>Until then, stay safe and don&#8217;t trust anyone \/ anything from email.<br \/>\n<a href=\"http:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/1247938871381.jpg\"><img decoding=\"async\" loading=\"lazy\" src=\"http:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/1247938871381.jpg\" alt=\"1247938871381\" width=\"679\" height=\"516\" class=\"alignnone size-full wp-image-1094\" srcset=\"https:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/1247938871381.jpg 679w, https:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2015\/02\/1247938871381-300x228.jpg 300w\" sizes=\"(max-width: 679px) 100vw, 679px\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Users of the net dread this screen. They feel when they see it all hope is lost. In the case of this ransomware dropper, the same holds true. In fact, in running this, I lost my downloads folder >:( Indeed, a risk all malware reverse engineers take. Live and learn right? Anywho, let&#8217;s dive into [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[7],"tags":[102,106],"_links":{"self":[{"href":"https:\/\/www.gironsec.com\/blog\/wp-json\/wp\/v2\/posts\/1047"}],"collection":[{"href":"https:\/\/www.gironsec.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.gironsec.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.gironsec.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.gironsec.com\/blog\/wp-json\/wp\/v2\/comments?post=1047"}],"version-history":[{"count":10,"href":"https:\/\/www.gironsec.com\/blog\/wp-json\/wp\/v2\/posts\/1047\/revisions"}],"predecessor-version":[{"id":1106,"href":"https:\/\/www.gironsec.com\/blog\/wp-json\/wp\/v2\/posts\/1047\/revisions\/1106"}],"wp:attachment":[{"href":"https:\/\/www.gironsec.com\/blog\/wp-json\/wp\/v2\/media?parent=1047"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gironsec.com\/blog\/wp-json\/wp\/v2\/categories?post=1047"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gironsec.com\/blog\/wp-json\/wp\/v2\/tags?post=1047"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}