Sample Analysis: Salary-Lure JS Loader to a JPEG Carrying Remcos

Tags: remcos c2 javascript powershell wmi xor cyberchef config-extraction deobfuscation

Cover image for the salary-lure JS loader to Remcos analysis post
TL;DR:
A JavaScript file posing as a Japanese "Spreadsheet about salary increases from December" decodes two XOR layers, drops a PowerShell script, and launches it hidden through WMI. That script loads a .NET loader straight into memory, which pulls a JPEG from ii-sen[.]ir with Remcos appended after the image's end-of-image marker. I unpacked every stage statically except the in-memory .NET loader, matched the dropped PowerShell to Triage's copy byte for byte, carved Remcos out of the JPEG, and decrypted its config. C2: winne[.]mynetav[.]net:2734.

Summary

The sample is a JavaScript file tagged Remcos on MalwareBazaar. Only 1 of 61 engines flagged it on VirusTotal during the time of this writing.

VirusTotal results showing 1 of 61 detections
Only 1 of 61 engines flagged the sample.
  1. Outer JS (WSH) a hex blob padded with Unicode junk, XOR-decoded with the plaintext key j3eevZqDRSH5I1.
  2. Stage 2 dropper: a second XOR blob (key GsNSDQHMEC1ccZ) written to %TEMP%\rad*.tmp.ps1 and launched through WMI
  3. Stage 3 PowerShell: downloads a .NET loader from a Cloudflare Workers URL and loads it in memory
  4. Stage 4 .NET loader: never touches disk, and the one stage I didn't recover
  5. JPEG with a passenger: a real photo with Remcos appended after the FF D9 end-of-image marker
  6. Remcos: native x64 RAT, injected into CasPol.exe per Joe Sandbox

I ran it through ANY.RUN and Triage first so I knew what normal looked like, then worked the JS layers statically with grep, CyberChef, and a few Python decoders. My own sandbox runs stopped at the .NET download, so I picked up the rest of the chain from Joe Sandbox and a sister sample on ANY.RUN, carved Remcos out of the JPEG, and decrypted its config. Every key step got checked against an independent source.

View the Joe Sandbox report 2005119 (opens in a new tab) View the Triage report 261116-m49nfsss8r (opens in a new tab) View the ANY.RUN sister sample 50561774-7bd9-4819-b537-9a10ea4c9307 (opens in a new tab)
Diagram of the chain from the .js lure through two XOR layers, the WMI-launched PowerShell, the .NET loader, and the JPEG to Remcos
From a fake salary "spreadsheet" to Remcos, a few layers deep.

Sample identifiers

Field Value
SHA256 38fef8dc1fab96cb08a27bebc4e85a022308371e15c7a131e27b491cd679dc90
File type JavaScript (.js), UTF-16LE, Windows Script Host
Size 28,431,838 bytes, 28.4 MB (inflated by padding)
Original name 12月からの昇給に関するスプレッドシート.js
Source MalwareBazaar, tagged as Remcos
Family Remcos RAT
VT detections 1 / 61 at time of analysis
C2 winne[.]mynetav[.]net:2734

1. The lure

Joe Sandbox shows the original filename in an escaped format:

12#U6708#U304b#U3089#U306e#U6607#U7d66#U306b#U95a2#U3059#U308b#U30b9#U30d7#U30ec#U30c3#U30c9#U30b7#U30fc#U30c8.js

Each #UXXXX is a Unicode code point written in hex. Joe swaps non-ASCII characters out for that notation. Two CyberChef operations turn it back into text:

  1. Find / Replace: #U → \u
  2. Unescape string

That gives you 12月からの昇給に関するスプレッドシート.js, a JavaScript file pretending to be a salary spreadsheet.

Joe Sandbox showing the escaped Japanese filename
Translation of the Japanese filename to English
Translation

2. Sandbox runs first

Before going static, I ran it in ANY.RUN and Triage so I'd know what normal looks like for this thing. That way, when I'm buried in code later, I can match what I'm reading to behavior I've actually seen.

ANY.RUN said nope

Initially, I attempted to upload the unzipped file, but the free tier caps uploads at 16 MB, and this file is 28.4 MB.
I had to upload it zipped. The zip came in way under the limit, ANY.RUN extracted it inside the VM, and I double-clicked the .js from there.

ANY.RUN upload error: unable to load file larger than 16 Mb
The padding beat ANY.RUN's free upload limit.

Process tree

  • wscript.exe runs the JS (Windows' default handler for .js files)
  • powershell.exe shows up, but its parent is wmiprvse.exe, not wscript.exe. Section 4 shows exactly why.
powershell.exe -WindowStyle Hidden -ExecutionPolicy Bypass -Command "& 'C:\Users\admin\AppData\Local\Temp\rad8E7D9.tmp.ps1'; Remove-Item -LiteralPath 'C:\Users\admin\AppData\Local\Temp\rad8E7D9.tmp.ps1' -Force -ErrorAction SilentlyContinue"

It runs a .ps1 out of %TEMP% with a hidden window, then deletes that file right after.

ANY.RUN process tree showing wmiprvse.exe as the parent of powershell.exe
PowerShell's parent is wmiprvse.exe, not wscript.exe.

Triage

Triage scored it 10/10 and pulled a deobfuscated PowerShell snippet into its config section. Network-wise, it only shows a DNS lookup and a GET to hxxps://royal-wood-3c0d[.]julianosilvasantospiresrosa[.]workers[.]dev/prxyb from powershell.exe, plus requests to c[.]pki[.]goog for certificate revocation lists (Windows checking certs during TLS).

Triage overview showing 10 out of 10 and the extracted PowerShell Triage network requests showing the workers.dev request and CRL lookups
Network requests showing the workers.dev request and CRL lookups.

It also captured the dropped script:
SHA256 b94b3efa333e41c846b01a0a65a0c72a5e756e3b44bed78179ae2a577f1ec47d.

Triage downloads list showing radD50AF.tmp.ps1 and the PowerShell policy test file
The dropped PowerShell, captured by Triage.

ANY.RUN's TLS details show the cert for that workers[.]dev domain was issued by Let's Encrypt on 2026-11-06.

ANY.RUN TLS certificate details for the workers[.]dev domain
TLS

What neither sandbox showed: a Remcos process. Both runs stop after the /prxyb request, and without HTTPS interception I couldn't see what that response contained.


3. Stage 1: the outer JS

All static work from here on happened in REMnux on an isolated network. First, the basic "what am I looking at" commands:

sha256sum 38fef8dc1fab96cb08a27bebc4e85a022308371e15c7a131e27b491cd679dc90.js
file 38fef8dc1fab96cb08a27bebc4e85a022308371e15c7a131e27b491cd679dc90.js
wc -c -l 38fef8dc1fab96cb08a27bebc4e85a022308371e15c7a131e27b491cd679dc90.js
head -c 1500 38fef8dc1fab96cb08a27bebc4e85a022308371e15c7a131e27b491cd679dc90.js; echo
tail -c 1500 38fef8dc1fab96cb08a27bebc4e85a022308371e15c7a131e27b491cd679dc90.js; echo
REMnux output of sha256sum, file, wc, head, and tail
First look at the file.
  • file says UTF-16, little-endian, CRLF line endings. Most characters take 2 bytes, so the 28,431,838-byte file is roughly 14 million characters of text.
  • A whopping 2,999 lines for 28.4 MB. The lines in head and tail were short, so some lines had to be massive.
  • Head and tail are junk code. Random variable names, pointless math, and .length > 0 checks whose results are never used.
Junk code at the top of the file Junk code at the bottom of the file
Junk code at both ends.

Converting it and hunting for the real code

iconv -f UTF-16 -t UTF-8 38fef8dc*.js > s.js
wc -c -l s.js

# Top 10 longest lines (length, line number)
awk '{print length($0), NR}' s.js | sort -rn | head -10

# Look for the interesting goopy stuff
grep -n -E 'eval|Function\(|ActiveXObject|WScript|GetObject|winmgmts|Win32_Process|GetTempName|fromCharCode|\.Run|Create\(|ps1|powershell' s.js | cut -c1-250

Using -f UTF-16 instead of UTF-16LE lets iconv read the Byte Order Mark (BOM) and drop it. Always pipe through cut -c1-250 or head on a sample like this. Some lines are over 230,000 characters, and dumping one to your terminal will lock it up. Ask me how I know.

The output laid out the whole structure:

  • Lines 1261 to 1310: 50 enormous lines, each around 237,000 characters. That's the encoded payload.
  • Line 1315: abiturient += String.fromCharCode(emplotments ^ cupules); decodes it one byte at a time with XOR.
  • Line 1319: eval(abiturient); runs whatever got decoded.
  • Line 1323: WScript.Quit(); exits right after. Nothing below line 1323 ever runs.
awk and grep output showing the giant lines and the eval sink
The giant lines, the XOR.
WScript.Quit call ending execution of the outer JS
The eval.

Below the quit there's code that queries printers over WMI and echoes things like DeviceID, ShareName, and PrintProcessor, with every identifier renamed to a random English word (costella, hieland, locomutation). It never executes.

Dead code echoing printer DeviceID and ShareName
Dead code querying printers over WMI
Printer queries.

Reading the decoder without running it

sed -n '1250,1260p;1301,1323p' s.js | cut -c1-300
The outmaneuver decoder function with the pyrolater key and the XOR loop

Things I was looking for

  1. What the blob is: a number array, a string, or something else
  2. Where pyrolater (the XOR key variable) comes from: a single byte, a key string, or computed
  3. How the loop walks the blob

While I'm sure everything was "randomized," these authors literally kept the decoder function named outmaneuver like it wasn't going to raise a red flag lol. Oh, the irony.

What I found

  1. falanga is a hex string with a 15-character junk separator stuck after every single hex character. The separator mixes characters from all over Unicode, which is why it renders as garbage.
  2. falanga.split("<separator>").join("") cuts the string apart at every separator and glues it back with nothing in between. That's the classic JS way to say "delete every copy of X". What's left is pure hex.
  3. The loop walks the hex 2 characters at a time. emplotments is the current byte, cupules is the matching character of the key pyrolater = "j3eevZqDRSH5I1", and % pyrolater.length wraps back to the start after 14 bytes. That makes it a repeating-key XOR.
  4. eval(abiturient) runs the result, then WScript.Quit().
The falanga loop with the XOR key

Cooking it in CyberChef

First, pull every falanga line into its own txt file.

grep -E 'falanga \+?= "' s.js > falanga.txt

Load the txt file into CyberChef with the open file button, then:

  1. Find / Replace (regex): ^(var )?falanga \+?= "|" → nothing
  2. Find / Replace (regex): [^0-9A-Fa-f] → nothing
  3. From Hex
  4. XOR: key j3eevZqDRSH5I1, key format UTF8, scheme Standard
CyberChef recipe decoding the falanga blob into stage 2
Layer 1, decoded.

Gotchas I hit, so you don't have to:

  • The first chunk is a var falanga = "...", not a +=. Miss it and the XOR key is out of line from byte 0, so everything turns to garbage.
  • Step 1 strips var on purpose. The a in var and the f/a in falanga are valid hex.
  • CyberChef's XOR key defaults to HEX. Switch it to UTF8.
  • Don't run "Escape Unicode Characters" recipe before the regex. It turns the separator into escapes full of hex digits that the regex keeps.

4. Stage 2: the dropper

wc -c -l stage2.js
awk '{print length($0), NR}' stage2.js | sort -rn | head -10
grep -n -E 'eval|Function\(|ActiveXObject|GetObject|winmgmts|Win32_Process|GetTempName|fromCharCode|\.Run|Create\(|ps1|powershell|Write|SaveToFile|split\(' stage2.js | cut -c1-250

Stage 2 is the saved output of the first decoded stage. Stage 2 is 370,195 bytes across 2,827 lines, padded with more junk code.

Junk code padding in stage 2

This time the APIs observed from the sandboxes show up in plain text, bunched together from around line 979. The real logic lives in a function called main(), which gets called at line 969 before it's even defined at 974. That works because JavaScript hoists function declarations.

main() called before its declaration, relying on JavaScript hoisting Stage 2 main function: main() with the fruendal key and the intaker blob Continuation of main() in stage 2 Decoder loop, temp path, PowerShell path pieces, and WMI setup ShowWindow, CreateTextFile, ExecMethod_, and WScript.Quit WScript.Quit
The dropper, top to bottom.
  1. Second XOR key: fruendal = "GsNSDQHMEC1ccZ" (line 977)
  2. Second blob: intaker, same separator, same split().join(""), same XOR loop, decoded into alternations (lines 979 to 998)
  3. Drop path: %TEMP%\ + GetTempName() + .ps1. That's where the radXXXXX.tmp.ps1 names in the sandboxes come from.
  4. PowerShell path in pieces: "C:", "\\", "Windows", "System32", "WindowsPowerShell\\v1.0", "powershell.exe", glued together at runtime
  5. Command line: separator-padded character by character, stripped into kingdom
  6. WMI: SWbemLocator → ConnectServer(".", "root\\cimv2") → Win32_Process and its Create method, plus Win32_ProcessStartup
  7. Hidden window: ShowWindow = 0, then CommandLine = kingdom
  8. Write: CreateTextFile(path, true) → Write(alternations) → Close()
  9. Launch: ExecMethod_("Create", ...)
  10. Quit

Step 9 is why PowerShell's parent was wmiprvse.exe in both sandboxes. The JS asks WMI to start the process, so WMI's own process becomes the parent.

The builder left its comments in, in Portuguese

  • //naomodificar ("não modificar" = "do not modify") on lines 975 and 1036, wrapping the malicious block
  • Right after WScript.Quit(): "O restante do script original só é executado se a flag continuar True" = "The rest of the original script only runs if the flag stays True," above an if (executarResto === true) check
  • Line 962: "Le valor do dicionario; retorna "" se a chave nao existir" = "Reads the dictionary value; returns "" if the key doesn't exist"
Portuguese builder comments naomodificar and executarResto Additional Portuguese builder comments in stage 2
Comments the author potentially forgot to strip.

5. Stage 3: the PowerShell

Decoding it

Same recipe, new key: GsNSDQHMEC1ccZ.

sed -n '977p' stage2.js | cat -A
sed -n '979,990p' stage2.js > intaker.txt

The first attempt decoded a few clean characters, then garbage. Instead of guessing, I counted every printable ASCII character in the blob lines:

First stage 3 decode attempt turning to garbage
Initial Stage 3, recipe.
sed -n '979,990p' stage2.js | grep -o '[ -~]' | sort | uniq -c | sort -rn

After the hex digits, the leftovers were 20 quotes, 8 commas, the letters for var intaker, and c, c, o, n, t, a plus ., (, ), ;. That spells .concat(:

var intaker = "chunk1".concat("chunk2", "chunk3", ..., "chunk10");

c, c, and a are valid hex. My "delete everything that isn't hex" regex kept them, injected 3 fake hex characters, and shifted every byte after them. Fix: strip .concat( first. The first Find / Replace becomes var intaker =|\.concat\(. Lesson: when you're cleaning hex out of code, the code's own keywords can pass as hex.

Proving the decode is right

Triage captured the file the dropper actually wrote, so I had something to check against. This decoder mirrors the JS exactly and writes raw bytes:

#!/usr/bin/env python3
# Decode a separator-padded hex blob with repeating-key XOR. Writes raw bytes.
# usage: decode_blob.py <file> <start_line> <end_line> <split_line> <key> <out>
import re
import sys

src, start, end, split_ln, key, out = sys.argv[1:7]
start, end, split_ln = int(start), int(end), int(split_ln)
key = key.encode()

with open(src, encoding="utf-8") as f:
    lines = f.read().split("\n")

sep = re.search(r'\.split\("(.*?)"\)', lines[split_ln - 1]).group(1)
block = "\n".join(lines[start - 1:end])
blob = "".join(re.findall(r'"(.*?)"', block)).replace(sep, "")

bad = sorted(set(c for c in blob if c not in "0123456789abcdefABCDEF"))
print(f"[*] separator: {len(sep)} chars, hex digits: {len(blob)}")
if bad:
    sys.exit(f"[!] non-hex characters remain: {bad[:20]}")

data = bytes(int(blob[i:i + 2], 16) ^ key[(i // 2) % len(key)]
             for i in range(0, len(blob) - 1, 2))
with open(out, "wb") as f:
    f.write(data)
print(f"[+] wrote {len(data)} bytes to {out}")
python3 -I ~/scripts/decode_blob.py stage2.js 979 990 992 GsNSDQHMEC1ccZ stage3.ps1
sha256sum stage3.ps1 radD50AF.tmp.ps1
Running decode_blob.py on stage 2 to produce stage3.ps1
Decoder
sha256sum showing stage3.ps1 matching radD50AF.tmp.ps1 from Triage
Carved by hand, the hashes match.

4,510 hex digits → 2,255 bytes, SHA256 b94b3efa333e41c846b01a0a65a0c72a5e756e3b44bed78179ae2a577f1ec47d. Byte for byte the same as Triage's radD50AF.tmp.ps1.

Building iex without typing it

. ( $ENv:comspec[4,26,25]-JoIN'') ( '<script>'.Replace(...) )

$env:comspec normally holds C:\Windows\system32\cmd.exe. Counting from 0, positions 4, 26, and 25 are i, e, and x: iex, short for Invoke-Expression. The script runs its own body without the word ever appearing in the file.

Placeholders

Placeholder Becomes How it's built
7Od $ .rePLACe('7Od','$')
SLH | [CHAr]83+[CHAr]76+[CHAr]72 = "SLH"
Dh4 ' [CHAr]68+[CHAr]104+[CHAr]52 = "Dh4" → [CHAr]39

On top of that, strings are chopped into concatenated pieces like '7Odeluvia'+'tions'.

The loader logic

  1. Sets the URL hxxps://royal-wood-3c0d[.]julianosilvasantospiresrosa[.]workers[.]dev/prxyb
  2. Creates a WebClient with [activator]::createInstance([net.webclient]) and sets a Chrome 120 User-Agent
  3. Downloads the response with DownloadString()
  4. If it contains -INICIO-(.*?)-FIM-, keeps only what's between the markers ("início" and "fim" are Portuguese for "start" and "end")
  5. Reverses the string, replaces every * with A, and base64-decodes it
  6. Loads the bytes as a .NET assembly with [System.AppDomain]::CurrentDomain.Load(), straight from memory
  7. Finds a method named vt and calls it with 19 arguments: 12 base64 strings and 7 empty strings
Decoded stage 3 PowerShell with placeholders
The stage 3 loader, decoded.

I couldn't decode those encrypted base64 arguments, so I'm not going to guess what they hold.


6. Picking up the trail

My sandbox runs stopped at /prxyb, so I went back to Joe Sandbox, which ran this hash on 2026-11-13 while the infrastructure was still serving.

What Joe saw after stage 3

  • powershell.exe spawns CasPol.exe (a legit .NET Framework binary) and injects a PE into it at 0x140000000
  • Remcos YARA hits in PowerShell's memory and on the unpacked image inside CasPol.exe
  • A second download: hxxps://ii-sen[.]ir/nv/payload_113212[.]png → 103.215.222[.]13:443, matched by Joe's "Remcos - Steganography payload download" rule
  • CasPol.exe injects into chrome.exe and launches headless msedge.exe with --remote-debugging-port=9222
  • Joe's dropped PowerShell was radEAD54.tmp.ps1, the same pattern again
Joe Sandbox process tree showing powershell.exe spawning CasPol.exe Joe Sandbox relationships view for the sample
Joe got all the way to Remcos in CasPol.exe.

Rookie trap I almost fell into: the only file in Joe's dropped files is %TEMP%\THB768.tmp, a 108,144-byte .NET file. Its MD5 (C91C5994E9C0F1690C296B57DFCD2EDF) is identical to CasPol.exe's MD5 in the process tree, and CasPol.exe is what wrote it. It's a copy of CasPol, not the missing loader. Always compare hashes before you chase a dropped file.

Joe Sandbox dropped file THB768.tmp with the same MD5 as CasPol.exe

A sister sample on ANY.RUN

Searching ANY.RUN's public submissions turned up another task from 2026-11-13 01:32: "Таблица с информацией о повышении заработной платы с декабря .pdf.zip", Russian for "Table with information about salary increases from December".
SHA256 906b78d823d1dc2b3283672e86ba5eb68e1b9c8c75dfe2a0b9d14579f9e52302.

  • The same /prxyb and ii-sen[.]ir URLs, and a connection to 103.215.222[.]13
  • DNS for winne[.]mynetav[.]net
  • wmiprvse.exe → hidden PowerShell running radC61FA.tmp.ps1, then deleting it
  • caspol.exe tagged #REMCOS
ANY.RUN public submission for the Russian-language salary lure ANY.RUN process tree with REVERSELOADER and REMCOS tags
Same salary lure, different language.

That task saved the file from ii-sen[.]ir in its Files tab. I briefly switched REMnux to the internet-connected network, downloaded it, checked the hash, and went straight back to isolated:

7z x <download>.zip -o./png_payload    # password: infected
sha256sum ./png_payload/*

SHA256 9912ca6dce79a65c49eb55f751759d426ded522f93d33358f2228f2c6270b321. VT: 6/61, 3.12 MB, and VT calls it a JPEG despite the .png name.

ANY.RUN Files tab with payload_113212.png VirusTotal showing 6 of 61 for payload_113212.png
The "PNG" is a JPEG.

ii-sen[.]ir is an Iranian domain, and Joe geolocates 103.215.222[.]13 to Iran (AS48551). That's where the file was hosted, not indicative of who's actually running the campaign.

ANY.RUN connection to 103.215.222[.]13 for the JPEG download

7. The JPEG with a passenger

file ii-sen.ir
exiftool ii-sen.ir
xxd ii-sen.ir | head -5
xxd ii-sen.ir | tail -5
strings -n 8 ii-sen.ir | grep -i -E 'INICIO|FIM|MZ|TVqQ'
file and exiftool output for the JPEG More exiftool metadata for the JPEG
A real Photoshop JPEG.

The image itself is real: a valid JPEG, 3840x2160, made in Photoshop CC 2019, with metadata dates from 2021 and 2022. It even has a text layer that reads "RULE THEM ALL, ONE BOARD TO." However, the end of the file is not an image:

xxd tail of the JPEG showing the appended data ending in FIM
0031f750: 2323 2323 2323 2323 2323 2323 2323 2323  ################
0031f760: 2323 2323 2323 674c 2323 2323 2323 382f  ######gL######8/
0031f770: 2f23 2323 2323 2323 2323 2323 2345 2323  /############E##
0031f780: 2323 2323 2323 2323 2323 4d23 2323 2323  ##########M#####
0031f790: 2351 7156 5446 494d                      #QqVTFIM
grep -obUa 'INICIO' ii-sen.ir
xxd -s $((2074229 - 16)) -l 32 ii-sen.ir
001fa665: dd7b dfba f75e f7ee bdd7 bdfb af75 ffd9  .{...^.......u..
001fa675: 494e 4943 494f 3d3d 2323 2323 2323 2323  INICIO==########

FF D9 is the JPEG end-of-image marker, and INICIO starts right after it. Image viewers stop reading at FF D9, so the picture opens like any normal photo while about 1.2 million characters ride along behind it. Joe calls it "steganography," but strictly speaking it's data appended after the end of the image.

The last characters before FIM are QqVT. Reversed, that's TVqQ, which is how a base64-encoded MZ header starts. Reversed base64 of a Windows executable.

xxd output showing FF D9 immediately followed by INICIO QqVT before FIM, reversed base64 for TVqQ (MZ)
The image ends, the payload begins.

First try: close, but wrong

Stage 3 swapped * for A, so I guessed # → A. That gave 900,306 bytes starting with MZ, and the DOS stub text was even there. But file only said "MS-DOS executable," and the header was mangled:

Normal PE My first decode
Byte 0x04 03 03 shows up at 0x07
Byte 0x08 04 04 shows up at 0x11
e_lfanew (0x3C) offset to PE\0\0 00 00 00 00
DOS stub starts at 0x40 starts at 0xAC
xxd of the first decode showing a mangled MS-DOS header
xxd

The right bytes were there, spread apart by extra zeros. In base64, every A is 6 zero bits, so too many As means too many zeros. Lesson: an MZ at the start doesn't mean you decoded a PE correctly. Check for PE\0\0 at the offset stored at 0x3C.

Letting the PE header decide

Instead of guessing again, I used Claude to write a small script that tries every likely substitution for # and keeps whichever one produces a real PE header. A correct decode has to have PE\0\0 at the offset stored at 0x3C, so the header settles it.

#!/usr/bin/env python3
# Try candidate decodings of the INICIO...FIM blob; report which one yields a valid PE.
# usage: test_jpg_decode.py <image>
import base64
import collections
import re
import struct
import sys

raw = open(sys.argv[1], "rb").read()
s, e = raw.find(b"INICIO"), raw.rfind(b"FIM")
blob = raw[s + len(b"INICIO"):e].strip()[::-1]   # reversed

cnt = collections.Counter(blob)
print(f"[*] chars: {len(blob)}, '#': {cnt[ord('#')]}, 'A': {cnt[ord('A')]}")
runs = collections.Counter(len(m) for m in re.findall(rb"#+", blob))
print(f"[*] '#' run lengths (length: count), top 10: {runs.most_common(10)}")

def check(name, b64):
    try:
        data = base64.b64decode(b64, validate=True)
    except Exception as ex:
        print(f"[-] {name}: base64 failed ({ex})")
        return
    valid = "no"
    if data[:2] == b"MZ" and len(data) > 0x40:
        off = struct.unpack_from("<I", data, 0x3C)[0]
        if off + 4 <= len(data) and data[off:off + 4] == b"PE\0\0":
            valid = f"yes, PE header at 0x{off:x}"
            with open("stage5.bin", "wb") as f:
                f.write(data)
    print(f"[+] {name}: {len(data)} bytes, MZ={data[:2] == b'MZ'}, valid PE: {valid}")

cands = {"hash_to_A": blob.replace(b"#", b"A"),
         "hash_removed": blob.replace(b"#", b"")}
for n in (2, 3, 4):
    cands[f"{n}hash_to_A"] = blob.replace(b"#" * n, b"A")
for name, b in cands.items():
    check(name, b)
[*] chars: 1200410, '#': 480675, 'A': 0
[*] '#' run lengths (length: count), top 10: [(3, 39804), (6, 11556), (9, 6002), (12, 5500), (18, 1278), (27, 1099), (24, 664), (15, 660), (21, 350), (30, 172)]
[+] hash_to_A: 900306 bytes, MZ=True, valid PE: no
[-] hash_removed: base64 failed (Invalid base64-encoded string: number of data characters (719733) cannot be 1 more than a multiple of 4)
[-] 2hash_to_A: base64 failed (Only base64 data is allowed)
[+] 3hash_to_A: 659968 bytes, MZ=True, valid PE: yes, PE header at 0x108
[-] 4hash_to_A: base64 failed (Only base64 data is allowed)
  • Zero literal A's in the blob
  • 480,675 # characters, which divides evenly by 3
  • Every common run length is a multiple of 3 (3, 6, 9, ... 30)
  • Only ### → A produces a valid PE: 659,968 bytes, PE\0\0 at 0x108

The encoding: reverse the string, and write every A as ###.


8. Finally: Remcos

file stage5.bin
sha256sum stage5.bin
diec stage5.bin
strings -n 8 stage5.bin | grep -i -E 'remcos|rmc-|watchdog|keylog|settings' | head -20
stage5.bin: PE32+ executable (GUI) x86-64, for MS Windows, 6 sections
2afde2e56560a21ce3f4646081e638b55cd43aa3189cbd8ea515a9e13d8b0dca  stage5.bin
PE64
    Linker: Microsoft Linker(14.16.27054)
    Compiler: Microsoft Visual C/C++(19.16.27054)[LTCG/C++]
    Tool: Microsoft Visual Studio(2017, 15.9)

Offline Keylogger Started
Online Keylogger Started
Remcos Agent initialized (
Remcos restarted by watchdog!
Watchdog module activated
SETTINGS
	Remcos v
  • 64-bit Windows GUI executable, built with Visual Studio 2017. Native C++, not .NET.
  • Remcos strings everywhere, including Remcos restarted by watchdog!, the exact string Joe's YARA rule matched on the PE injected into CasPol.exe
  • SHA256 2afde2e56560a21ce3f4646081e638b55cd43aa3189cbd8ea515a9e13d8b0dca had no detections or public submissions on VirusTotal or ANY.RUN at the time of writing. Only the JPEG travels over the network, and the PE only exists once it's decoded.
VirusTotal search for the Remcos hash showing no detections or submissions ANY.RUN search for the Remcos hash showing no submissions
No detections or submissions observed

Side note: in the broken first decode, strings showed lines like WATAUAVAWH and A_A^A]A\_. Those are x64 machine code: 57 41 54 41 55 41 56 41 57 is push rdi; push r12; push r13; push r14; push r15, a function prologue, and the A_A^... lines are the matching pops. That was the first hint of native code before diec confirmed it.

Pulling the config

SETTINGS is the name of a resource inside the binary. Public Remcos research describes it as RC4-encrypted, with the first byte giving the key length and the key right after. REMnux didn't have pefile, and I wasn't reconnecting the box to install it, so I parsed the resource table by hand (and by I, I mean Claude made the python script):

#!/usr/bin/env python3
# Dependency-free: find the SETTINGS resource in a PE, then try RC4 with a key-length-prefixed key.
# usage: remcos_cfg.py <pe>
import struct
import sys

data = open(sys.argv[1], "rb").read()

def u16(o):
    return struct.unpack_from("<H", data, o)[0]

def u32(o):
    return struct.unpack_from("<I", data, o)[0]

# PE headers
pe = u32(0x3C)
if data[pe:pe + 4] != b"PE\0\0":
    sys.exit("[!] no PE header")
nsec = u16(pe + 6)
opt_size = u16(pe + 20)
opt = pe + 24
magic = u16(opt)
dd = opt + (112 if magic == 0x20B else 96)   # data directories (PE32+ vs PE32)
res_rva = u32(dd + 2 * 8)                    # directory index 2 = resources

# Section table, for RVA -> file offset
secs = []
for i in range(nsec):
    s = opt + opt_size + i * 40
    vsize, va, rsize, rptr = u32(s + 8), u32(s + 12), u32(s + 16), u32(s + 20)
    secs.append((va, max(vsize, rsize), rptr))

def rva2off(rva):
    for va, size, rptr in secs:
        if va <= rva < va + size:
            return rva - va + rptr
    sys.exit(f"[!] RVA 0x{rva:x} not in any section")

base = rva2off(res_rva)

def entries(off):
    n = u16(off + 12) + u16(off + 14)        # named + ID entries
    for i in range(n):
        e = off + 16 + i * 8
        yield u32(e), u32(e + 4)

def name_of(nid):
    if nid & 0x80000000:                     # high bit set = name string
        o = base + (nid & 0x7FFFFFFF)
        ln = u16(o)
        return data[o + 2:o + 2 + ln * 2].decode("utf-16-le")
    return nid

# Walk type -> name -> language
found = None
for t_id, t_off in entries(base):
    if not t_off & 0x80000000:
        continue
    for n_id, n_off in entries(base + (t_off & 0x7FFFFFFF)):
        if name_of(n_id) != "SETTINGS" or not n_off & 0x80000000:
            continue
        for l_id, l_off in entries(base + (n_off & 0x7FFFFFFF)):
            d = base + (l_off & 0x7FFFFFFF)
            rva, size = u32(d), u32(d + 4)
            off = rva2off(rva)
            found = data[off:off + size]
            print(f"[*] SETTINGS: resource type {name_of(t_id)}, lang {l_id}, {size} bytes")

if found is None:
    sys.exit("[!] SETTINGS resource not found")

def rc4(key, buf):
    s = list(range(256))
    j = 0
    for i in range(256):
        j = (j + s[i] + key[i % len(key)]) % 256
        s[i], s[j] = s[j], s[i]
    i = j = 0
    out = bytearray()
    for b in buf:
        i = (i + 1) % 256
        j = (j + s[i]) % 256
        s[i], s[j] = s[j], s[i]
        out.append(b ^ s[(s[i] + s[j]) % 256])
    return bytes(out)

klen = found[0]
key = found[1:1 + klen]
print(f"[*] key length byte: {klen}, key (hex): {key.hex()}")
cfg = rc4(key, found[1 + klen:])
print(f"[*] decrypted (first 400 bytes, repr):\n{cfg[:400]!r}")
with open("remcos_config.bin", "wb") as f:
    f.write(cfg)
print("[+] full output written to remcos_config.bin")
python3 -I ~/scripts/remcos_cfg.py stage5.bin
[*] SETTINGS: resource type 10, lang 0, 570 bytes
[*] key length byte: 71, key (hex): 821c16ad1f55eae02106e49e0d5c8b37...
[*] decrypted (first 400 bytes, repr):
b'winne[.]mynetav[.]net:2734:0\x1e|\x1e\x1e\x1f|winto|\x1e\x1e\x1f|1|...|Rmc-SUNBKC|...'
Output of remcos_cfg.py showing the decrypted config with the C2
The config, decrypted without running anything.

Resource type 10 is RT_RCDATA, the standard Windows type for raw data. The key is 71 bytes, and the fields are separated by |\x1e\x1e\x1f|. Rather than trust the method blindly, I checked the output against the config Joe pulled from memory during its live run:

Joe Sandbox Remcos config extracted from memory
The config, decrypted without running anything.
Joe field Value In my decrypt
Host:Port:Password winne[.]mynetav[.]net:2734:0 Yes, first field
Assigned name winto Yes
Copy file remcos.exe Yes (UTF-16)
Mutex Rmc-SUNBKC Yes
Keylog file logs.dat Yes (UTF-16)
Screenshot file Screenshots Yes
Audio folder MicRecords Yes

I only mapped fields that match Joe's strings one to one.


What's still open

  • The .NET loader from /prxyb. It only ever exists in memory, and unfortunately none of the reports I had included it.
  • The 12 base64 vt arguments. Without the loader, anything I said about them would be a guess.

IOCs

Type Value Note
C2 winne[.]mynetav[.]net:2734 From the decrypted config
Mutex Rmc-SUNBKC From the decrypted config
SHA256 (JS lure) 38fef8dc1fab96cb08a27bebc4e85a022308371e15c7a131e27b491cd679dc90 Japanese salary lure
SHA256 (sister sample) 906b78d823d1dc2b3283672e86ba5eb68e1b9c8c75dfe2a0b9d14579f9e52302 Russian salary lure, .pdf.zip
SHA256 (dropped PowerShell) b94b3efa333e41c846b01a0a65a0c72a5e756e3b44bed78179ae2a577f1ec47d Stage 3, verified against Triage
SHA256 (JPEG) 9912ca6dce79a65c49eb55f751759d426ded522f93d33358f2228f2c6270b321 Remcos appended after FF D9
SHA256 (Remcos, carved) 2afde2e56560a21ce3f4646081e638b55cd43aa3189cbd8ea515a9e13d8b0dca Memory only in the wild
URL hxxps://royal-wood-3c0d[.]julianosilvasantospiresrosa[.]workers[.]dev/prxyb .NET loader download
URL hxxps://ii-sen[.]ir/nv/payload_113212[.]png JPEG download
IP 103.215.222[.]13 Hosts ii-sen[.]ir (AS48551)
Drop path %TEMP%\rad*.tmp.ps1 Written by stage 2, deleted after launch
Behavior powershell.exe -WindowStyle Hidden -ExecutionPolicy Bypass with parent wmiprvse.exe WMI launch from stage 2
String j3eevZqDRSH5I1 Layer 1 XOR key
String GsNSDQHMEC1ccZ Stage 2 XOR key
String -INICIO- / -FIM- Markers in the /prxyb response
String INICIO / FIM Markers in the JPEG
String vt .NET method invoked by stage 3

Detection ideas

  • wscript.exe creating %TEMP%\rad*.tmp.ps1
  • wmiprvse.exe spawning powershell.exe with -WindowStyle Hidden -ExecutionPolicy Bypass
  • A PowerShell command line that runs a script and then Remove-Items that same script
  • powershell.exe making requests to *.workers[.]dev, or downloading an image from ii-sen[.]ir
  • powershell.exe spawning CasPol.exe (per Joe's process tree)
  • DNS lookups for winne[.]mynetav[.]net
  • The mutex Rmc-SUNBKC
  • A JPEG with INICIO right after its FF D9 end-of-image marker (easy YARA territory)

Overall purpose

This is a multi-stage Remcos delivery chain behind a salary-themed lure, seen in Japanese and Russian versions on the same infrastructure. A padded JavaScript file XOR-decodes a dropper, which writes a PowerShell loader to %TEMP% and launches it hidden through WMI. The loader pulls a .NET assembly from a Cloudflare Workers URL into memory, and per Joe Sandbox, that stage fetches a JPEG from ii-sen[.]ir and injects the Remcos binary appended to it into CasPol.exe. Remcos then reports to winne[.]mynetav[.]net:2734.

Key takeaways

  • Static work recovered every stage except the in-memory .NET loader, and each one was checked against an independent source or a structural check: Triage's dropped file, a PE structure check, and Joe's config.
  • When your own sandbox run stalls, other people's runs of the same infrastructure can fill the gap. The JPEG came from someone else's ANY.RUN task.
  • An MZ at the start doesn't mean a correct decode. Check the PE header.
  • When cleaning hex out of code, the code's own keywords (var, concat) can pass as hex.
  • Hosting location isn't attribution. The payload sat on an Iranian domain, and the builder comments are in Portuguese.