Enumeración
Además de un host se nos proporciona un zip
que al descomprimirlo nos deja varios archivos, entre ellos una flag
falsa, un script
en python y un binario
compilado
❯ ls
glibc flag.txt gs wrapper.py
Al conectarnos con netcat
de como esta estructurada la pila
e instrucciones
❯ netcat 188.166.152.84 32451
Stack frame layout
| . | <- Higher addresses
| . |
|_____________|
| | <- 64 bytes
| Return addr |
|_____________|
| | <- 56 bytes
| RBP |
|_____________|
| | <- 48 bytes
| target |
|_____________|
| | <- 40 bytes
| alignment |
|_____________|
| | <- 32 bytes
| Buffer[31] |
|_____________|
| . |
| . |
|_____________|
| |
| Buffer[0] |
|_____________| <- Lower addresses
[Addr] | [Value]
-------------------+-------------------
0x00007ffc3a53fe50 | 0x0000000000000000 <- Start of buffer
0x00007ffc3a53fe58 | 0x0000000000000000
0x00007ffc3a53fe60 | 0x0000000000000000
0x00007ffc3a53fe68 | 0x0000000000000000
0x00007ffc3a53fe70 | 0x6969696969696969 <- Dummy value for alignment
0x00007ffc3a53fe78 | 0x00000000deadbeef <- Target to change
0x00007ffc3a53fe80 | 0x0000563333f7a800 <- Saved rbp
0x00007ffc3a53fe88 | 0x00007fb950c21c87 <- Saved return address
0x00007ffc3a53fe90 | 0x0000002000000000
0x00007ffc3a53fe98 | 0x00007ffc3a53ff68
After we insert 4 "A"s, (the hex representation of A is 0x41), the stack layout like this:
[Addr] | [Value]
-------------------+-------------------
0x00007ffc3a53fe50 | 0x0000000041414141 <- Start of buffer
0x00007ffc3a53fe58 | 0x0000000000000000
0x00007ffc3a53fe60 | 0x0000000000000000
0x00007ffc3a53fe68 | 0x0000000000000000
0x00007ffc3a53fe70 | 0x6969696969696969 <- Dummy value for alignment
0x00007ffc3a53fe78 | 0x00000000deadbeef <- Target to change
0x00007ffc3a53fe80 | 0x0000563333f7a800 <- Saved rbp
0x00007ffc3a53fe88 | 0x00007fb950c21c87 <- Saved return address
0x00007ffc3a53fe90 | 0x0000002000000000
0x00007ffc3a53fe98 | 0x00007ffc3a53ff68
After we insert 4 "B"s, (the hex representation of B is 0x42), the stack layout looks like this:
[Addr] | [Value]
-------------------+-------------------
0x00007ffc3a53fe50 | 0x4242424241414141 <- Start of buffer
0x00007ffc3a53fe58 | 0x0000000000000000
0x00007ffc3a53fe60 | 0x0000000000000000
0x00007ffc3a53fe68 | 0x0000000000000000
0x00007ffc3a53fe70 | 0x6969696969696969 <- Dummy value for alignment
0x00007ffc3a53fe78 | 0x00000000deadbeef <- Target to change
0x00007ffc3a53fe80 | 0x0000563333f7a800 <- Saved rbp
0x00007ffc3a53fe88 | 0x00007fb950c21c87 <- Saved return address
0x00007ffc3a53fe90 | 0x0000002000000000
0x00007ffc3a53fe98 | 0x00007ffc3a53ff68
◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉
◉ ◉
◉ Fill the 32-byte buffer, overwrite the alginment address and the "target's" 0xdeadbeef value. ◉
◉ ◉
◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉
>>
Analizemos poco a poco, al inicio se nos muestra como esta conformada la pila y que son necesarios 40
bytes para llegar al inicio del target, este finaliza a los 48
bytes
Stack frame layout
| . | <- Higher addresses
| . |
|_____________|
| | <- 64 bytes
| Return addr |
|_____________|
| | <- 56 bytes
| RBP |
|_____________|
| | <- 48 bytes
| target |
|_____________|
| | <- 40 bytes
| alignment |
|_____________|
| | <- 32 bytes
| Buffer[31] |
|_____________|
| . |
| . |
|_____________|
| |
| Buffer[0] |
|_____________| <- Lower addresses
Asi que con 48
bytes sobreescribimos el valor completo del target
sin embargo nos piden que cambiemos la cadena deadbeef
que tiene 4
bytes en lugar de 8
asi que solo necesitamos 44
de esta manera nos quedaria 0x00000000
y los 4
bytes
0x00007ffc3a53fe78 | 0x00000000deadbeef <- Target to change