<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>Coder Legion - Recent posts tagged reverse</title>
<link>https://coderlegion.com/tag/reverse</link>
<description>Powered by Question2Answer</description>
<item>
<title>WannaCry, Reopened</title>
<link>https://coderlegion.com/28267/wannacry-reopened</link>
<description>&lt;h3 id=&quot;what-a-modern-triage-of-a-2017-ransomware-sample-teaches-about-killswitch-logic-and-staging-behaviour&quot;&gt;What a modern triage of a 2017 ransomware sample teaches about killswitch logic and staging behaviour&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Vasilis Mantas&lt;/strong&gt; — Threat Detection Engineer&lt;/p&gt;
&lt;hr&gt;
&lt;blockquote&gt;&lt;p&gt;&lt;strong&gt;Verdict:&lt;/strong&gt; WannaCry checks a hardcoded URL before doing anything destructive. If the URL &lt;em&gt;responds&lt;/em&gt;, the sample exits without encrypting. If it cannot be reached, encryption proceeds. This inverted logic is the single most instructive thing in the binary, and it is easy to get backwards — including in a lab, where a network simulator that answers every request will silently prevent the malware from detonating at all.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;WannaCry has been analysed exhaustively since May 2017. This walkthrough is not an attempt to say something new about the campaign. It is a demonstration of triage method on a sample whose ground truth is already known, which makes it a useful benchmark: every conclusion below can be checked against the public record.&lt;/p&gt;
&lt;p&gt;The analysis was performed in an isolated lab with no route to the internet.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;surface-behaviour&quot;&gt;Surface behaviour&lt;/h3&gt;
&lt;p&gt;Detonating the sample produces the outcome the sample is famous for. Files across the system are renamed with a &lt;code&gt;.WNCRY&lt;/code&gt; extension, a ransom interface titled &lt;em&gt;Wana Decrypt0r 2.0&lt;/em&gt; appears demanding $600 in Bitcoin, and the desktop wallpaper is replaced with a plaintext version of the same message.&lt;/p&gt;
&lt;p&gt;A practical note for anyone running this in a lab: several FlareVM analysis tools become unusable after detonation, because their own files are encrypted along with everything else. Snapshot before, not after.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;basic-static-analysis&quot;&gt;Basic static analysis&lt;/h3&gt;
&lt;p&gt;Extracting strings with FLOSS, filtering short noise:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-shell&quot;&gt;FLOSS.exe -n 7 Ransomware.wannacry.exe.malz &amp;gt; outputstrings.txt
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The DOS header string &lt;code&gt;!This program cannot be run in DOS mode.&lt;/code&gt; appears multiple times. A PE header appearing more than once inside a single file means embedded executables, and each occurrence is followed by a distinct set of DLL imports — a different API surface per embedded binary. PEStudio confirmed three packed binaries in total.&lt;/p&gt;
&lt;p&gt;The remaining strings are unusually generous:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-plaintext&quot;&gt;cmd.exe /c &quot;%s&quot;
115p7UMMngoj1pMvkpHijcRdfJNXj6LrLn
12t9YDPgwueZ9NyMgw519p7AA8isjr6SMw
13AM4VW2dhxYgXeQepoHkHSQuy6NgaEb94
Global\MsWinZonesCacheCounterMutexA
tasksche.exe
TaskStart
icacls . /grant Everyone:F /T /C /Q
attrib +h .
C:\%s\qeriuwjhrf
C:\%s\%s
http://www.iuqerfsodp9ifjaposdfjhgosurijfaewrwergwea.com
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Three Bitcoin wallets, a named mutex, a dropped executable name, two format-string paths, and one conspicuously random-looking domain. The &lt;code&gt;icacls&lt;/code&gt; and &lt;code&gt;attrib&lt;/code&gt; commands grant everyone full control over a directory tree and hide it — staging behaviour, visible before a single instruction is executed.&lt;/p&gt;
&lt;p&gt;The import table reinforces the picture. &lt;code&gt;CryptGenRandom&lt;/code&gt; and &lt;code&gt;CryptAcquireContextA&lt;/code&gt; for key generation. A dense block of &lt;code&gt;ws2_32.dll&lt;/code&gt; socket functions — &lt;code&gt;socket&lt;/code&gt;, &lt;code&gt;connect&lt;/code&gt;, &lt;code&gt;send&lt;/code&gt;, &lt;code&gt;recv&lt;/code&gt;, &lt;code&gt;WSAStartup&lt;/code&gt; — alongside &lt;code&gt;GetAdaptersInfo&lt;/code&gt;, indicating network enumeration and self-propagation. &lt;code&gt;InternetOpenA&lt;/code&gt; and &lt;code&gt;InternetOpenUrlA&lt;/code&gt; from &lt;code&gt;wininet.dll&lt;/code&gt;, which turn out to matter more than anything else in the list.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;dynamic-analysis-and-a-lab-trap&quot;&gt;Dynamic analysis, and a lab trap&lt;/h3&gt;
&lt;p&gt;The second detonation was run with REMnux providing inetsim as a fake DNS resolver and HTTP responder. The sample did nothing. No encryption, no ransom note, no filesystem activity of consequence.&lt;/p&gt;
&lt;p&gt;That is not a broken sample. It is the killswitch working.&lt;/p&gt;
&lt;p&gt;When inetsim answers the request to &lt;code&gt;iuqerfsodp9ifjaposdfjhgosurijfaewrwergwea.com&lt;/code&gt; with a 200 OK, WannaCry concludes the domain is live and exits. In the first detonation, with no simulator running, the request failed, the sample concluded the domain was unregistered, and it encrypted the filesystem.&lt;/p&gt;
&lt;p&gt;The consequence for analysts is worth stating directly. A generic network simulator that returns success for every request will suppress this sample's entire payload. An analyst who only ever detonates with full simulation would conclude the binary is inert.&lt;/p&gt;
&lt;p&gt;With the payload allowed to run, TCPView showed the propagation attempt: a large volume of TCP SYN packets to sequential and apparently random addresses on &lt;strong&gt;port 445&lt;/strong&gt;, the SMB service port — the sample scanning for further hosts to infect. A second listener appeared, &lt;code&gt;taskhsvc.exe&lt;/code&gt; bound to &lt;code&gt;127.0.0.1:9050&lt;/code&gt;, the Tor SOCKS port, providing the anonymised channel back to the operators.&lt;/p&gt;
&lt;p&gt;Procmon, filtered on the sample's process name and &lt;code&gt;CreateFile&lt;/code&gt;, showed the drop:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-plaintext&quot;&gt;Ransomware.wan... → C:\Windows\tasksche.exe   SUCCESS
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;followed in the process tree by &lt;code&gt;tasksche.exe&lt;/code&gt; executing with the argument &lt;code&gt;/i&lt;/code&gt;. Filtering again on the new PID revealed the staging directory:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-plaintext&quot;&gt;C:\ProgramData\dveqybpwqzws072\
    msg\                      TaskData\
    @Please_Read_Me@.txt      @WanaDecryptor@.exe
    00000000.eky              00000000.pky        00000000.res
    b.wnry  c.wnry  f.wnry  r.wnry  s.wnry  t.wnry  u.wnry
    taskdl.exe                taskse.exe
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The &lt;code&gt;C:\%s\%s&lt;/code&gt; format string from the strings output is now explained: the directory name is generated at runtime, which is why the folder is &lt;code&gt;dveqybpwqzws072&lt;/code&gt; here and something else elsewhere. A service is created bearing the same random name — the persistence mechanism.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;advanced-static-analysis&quot;&gt;Advanced static analysis&lt;/h3&gt;
&lt;p&gt;Loading the binary into Cutter and navigating to &lt;code&gt;main&lt;/code&gt; puts the killswitch logic on screen in a dozen instructions:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-plaintext&quot;&gt;0x0040814a   mov  esi, str.http:__www.iuqerfsodp9ifjaposdfjhgosurijfaewrwergwea.com
0x0040817b   call dword [InternetOpenA]
0x00408194   call dword [InternetOpenUrlA]
0x0040819a   mov  edi, eax
0x004081a3   test edi, edi
0x004081a5   jne  0x4081bc
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The decompiler view is clearer still:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-c&quot;&gt;eax = InternetOpenUrlA(esi, ecx, 0, 0, 0x84000000, 0);
edi = eax;
esi = *(InternetCloseHandle);
if (edi == 0) {
    (*esi)();
    (*esi)(0);
    eax = fcn_00408090();
    eax = 0;
    return eax;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;code&gt;InternetOpenUrlA&lt;/code&gt; returns a handle, or NULL on failure. The handle lands in &lt;code&gt;edi&lt;/code&gt;, and &lt;code&gt;test edi, edi&lt;/code&gt; sets the zero flag only when the call failed.&lt;/p&gt;
&lt;p&gt;The branch is therefore: &lt;strong&gt;handle is NULL — the domain did not resolve — call &lt;code&gt;fcn_00408090&lt;/code&gt;, the encryption routine.&lt;/strong&gt; Handle is valid — the domain responded — close the handles, clean up the stack, return.&lt;/p&gt;
&lt;p&gt;The graph view makes the asymmetry obvious. One path is labelled normal execution and leads into the encryption function. The other is a short exit stub. The condition separating them is a single &lt;code&gt;test&lt;/code&gt; on the result of a web request.&lt;/p&gt;
&lt;p&gt;Registering that domain is what stopped the campaign in 2017. The disassembly above is the mechanism, in six instructions.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;indicators-of-compromise&quot;&gt;Indicators of compromise&lt;/h3&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Type &lt;/th&gt;&lt;th&gt;Indicator&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;Killswitch domain &lt;/td&gt;&lt;td&gt;&lt;code&gt;iuqerfsodp9ifjaposdfjhgosurijfaewrwergwea.com&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Mutex &lt;/td&gt;&lt;td&gt;&lt;code&gt;Global\MsWinZonesCacheCounterMutexA&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Dropped file &lt;/td&gt;&lt;td&gt;&lt;code&gt;C:\Windows\tasksche.exe&lt;/code&gt; (executed with &lt;code&gt;/i&lt;/code&gt;)&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Staging path &lt;/td&gt;&lt;td&gt;&lt;code&gt;C:\ProgramData\&amp;lt;random&amp;gt;\&lt;/code&gt; containing &lt;code&gt;.wnry&lt;/code&gt; files&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Dropped tools &lt;/td&gt;&lt;td&gt;&lt;code&gt;taskdl.exe&lt;/code&gt;, &lt;code&gt;taskse.exe&lt;/code&gt;, &lt;code&gt;@WanaDecryptor@.exe&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Ransom note &lt;/td&gt;&lt;td&gt;&lt;code&gt;@Please_Read_Me@.txt&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Extension &lt;/td&gt;&lt;td&gt;&lt;code&gt;.WNCRY&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Network &lt;/td&gt;&lt;td&gt;Mass outbound SYN to TCP/445&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Network &lt;/td&gt;&lt;td&gt;Local listener on &lt;code&gt;127.0.0.1:9050&lt;/code&gt; (Tor)&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;BTC &lt;/td&gt;&lt;td&gt;&lt;code&gt;115p7UMMngoj1pMvkpHijcRdfJNXj6LrLn&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;BTC &lt;/td&gt;&lt;td&gt;&lt;code&gt;12t9YDPgwueZ9NyMgw519p7AA8isjr6SMw&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;BTC &lt;/td&gt;&lt;td&gt;&lt;code&gt;13AM4VW2dhxYgXeQepoHkHSQuy6NgaEb94&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;hr&gt;
&lt;h3 id=&quot;mitre-att-amp-ck-mapping&quot;&gt;MITRE ATT&amp;amp;CK mapping&lt;/h3&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Tactic &lt;/th&gt;&lt;th&gt;Technique&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;Execution &lt;/td&gt;&lt;td&gt;T1106 — Native API&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Persistence &lt;/td&gt;&lt;td&gt;T1543.003 — Create or Modify System Process: Windows Service&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Defense Evasion &lt;/td&gt;&lt;td&gt;T1564.001 — Hide Artifacts: Hidden Files and Directories&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Defense Evasion &lt;/td&gt;&lt;td&gt;T1222.001 — File and Directory Permissions Modification&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Discovery &lt;/td&gt;&lt;td&gt;T1046 — Network Service Discovery&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Lateral Movement &lt;/td&gt;&lt;td&gt;T1210 — Exploitation of Remote Services&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Command and Control &lt;/td&gt;&lt;td&gt;T1090.003 — Proxy: Multi-hop Proxy (Tor)&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Impact &lt;/td&gt;&lt;td&gt;T1486 — Data Encrypted for Impact&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Impact &lt;/td&gt;&lt;td&gt;T1490 — Inhibit System Recovery&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;hr&gt;
&lt;h3 id=&quot;detection-guidance&quot;&gt;Detection guidance&lt;/h3&gt;
&lt;p&gt;The hashes and the killswitch domain have limited value now. The behavioural sequence does not.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;1. Permission-widening plus attribute-hiding on a freshly created directory.&lt;/strong&gt; The &lt;code&gt;icacls . /grant Everyone:F /T /C /Q&lt;/code&gt; and &lt;code&gt;attrib +h .&lt;/code&gt; pair is staging behaviour that predates encryption. Catching it means catching the sample before impact, which is the only detection that actually matters for ransomware.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-yaml&quot;&gt;title: Mass Permission Grant Followed by Directory Hiding
status: experimental
logsource:
  category: process_creation
  product: windows
detection:
  icacls:
    Image|endswith: '\icacls.exe'
    CommandLine|contains|all:
      - '/grant'
      - 'Everyone:F'
      - '/T'
  attrib:
    Image|endswith: '\attrib.exe'
    CommandLine|contains: '+h'
  condition: icacls or attrib
falsepositives:
  - Some software installers and backup agents
level: high
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Correlate the two within a short window on one host rather than alerting on either alone — that is what separates a real staging sequence from routine installer noise.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;2. Executable written to &lt;code&gt;C:\Windows\&lt;/code&gt; by a non-system process, then executed.&lt;/strong&gt; A user-context process dropping a binary directly into the Windows directory and launching it is a narrow, high-value pattern.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;3. Outbound SMB scanning from a workstation.&lt;/strong&gt; A single host opening connections to TCP/445 across many destinations in a short window is almost never legitimate on an endpoint. Threshold on distinct destination count per source per minute.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;4. Local Tor SOCKS listener.&lt;/strong&gt; A process binding &lt;code&gt;127.0.0.1:9050&lt;/code&gt; is worth an alert in any enterprise that has not deliberately deployed Tor.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;5. Suspicious process spawning &lt;code&gt;cmd.exe /c&lt;/code&gt;.&lt;/strong&gt; Present here, and generic enough to earn its place in any ruleset — with the tuning that implies.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;analyst-takeaways&quot;&gt;Analyst takeaways&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Environment shapes behaviour, so vary the environment.&lt;/strong&gt; The single most important finding in this analysis only appeared because the sample was detonated both with and without network simulation. One configuration produced a functioning ransomware; the other produced an inert file. Detonating once tells you what a sample does under one set of conditions, not what it does.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Strings foreshadow structure.&lt;/strong&gt; &lt;code&gt;icacls&lt;/code&gt;, &lt;code&gt;attrib&lt;/code&gt;, &lt;code&gt;C:\%s\%s&lt;/code&gt; and &lt;code&gt;tasksche.exe&lt;/code&gt; were all visible before execution, and each was confirmed by dynamic analysis. Reading strings carefully turns dynamic analysis into confirmation rather than exploration.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;The decisive logic is often tiny.&lt;/strong&gt; The behaviour that defined a global incident reduces to one API call, one &lt;code&gt;test&lt;/code&gt;, and one conditional jump. Finding that block took longer than understanding it — which is usually how reverse engineering goes.&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;&lt;em&gt;Written by Vasilis Mantas, Senior Threat Detection Engineer. Analysis performed in an isolated lab using FlareVM, REMnux, FLOSS, PEStudio, PEview, Wireshark, Procmon, TCPView and Cutter.&lt;/em&gt;&lt;/p&gt;
</description>
<category>Articles</category>
<guid isPermaLink="true">https://coderlegion.com/28267/wannacry-reopened</guid>
<pubDate>Wed, 23 Sep 2026 05:44:57 +0000</pubDate>
</item>
</channel>
</rss>