Skip to content
Memory corruption Write-up Intermediate

Exploiting A Windows Based Buffer Overflow

The TRUN command of the Vulnserver test program copies attacker-supplied input into a fixed-size buffer without bounds checking, so a long string overwrites the saved return address. An attacker who can reach the service can redirect execution to their own shellcode and obtain a reverse shell on the Windows host.

Ravishanka Silva Follow

Published on infosecwriteups.com

This article is based on exploiting a simple buffer overflow in Windows using Vulnserver. If you don’t have an idea about buffer overflows, read my previous article about exploiting a Linux buffer overflow here, https://ravi5hanka.medium.com/privilege-escalation-in-linux-via-a-local-buffer-overflow-dcee4f9b4a49

Ravishanka Silva, on infosecwriteups.com

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.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely the TRUN command handler copies the received data into a fixed-length stack buffer using an unchecked copy, allowing the saved return address to be overwritten.

Impact

An attacker who can reach the service could run arbitrary code on the Windows host and obtain a reverse shell, though the author had to disable the Windows Defender firewall for the listener to work.

What the attacker needed

Network access to port 9999; vulnserver running as administrator; Windows Defender firewall disabled for the listener

How it was found

  1. Run Vulnserver as administrator and attach it to the debugger, then let it run.
  2. Connect to port 9999 and send a spike script to each command to see which one crashes the service.
  3. Fuzz the TRUN command with increasing input to find roughly where the crash occurs.
  4. Send a unique cyclic pattern and read the overwritten instruction pointer value to calculate the exact offset.
  5. Confirm control of the instruction pointer by overwriting it with a recognisable value.
  6. Find a module without memory protections and a jump-to-stack-pointer instruction, then place shellcode after it and catch the reverse shell.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

A buffer overflow happens when a program copies more data into a fixed-size memory space than it can hold, so the extra data spills over into neighbouring memory. Here the spilled data reaches the saved return address, a value that tells the processor where to continue after the current function, letting the attacker choose the next instruction. The result is that the attacker's own code runs on the victim machine.

What is Memory corruption?

Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.

More by Ravishanka Silva

View all

1 more disclosed report, best first.

Similar reports

View all

Same bug class and techniques, clearest first.

Memory corruption

The lesson behind this report.

Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.