16.05.2015 Views

Working with the Unix OS

Working with the Unix OS

Working with the Unix OS

SHOW MORE
SHOW LESS

Create successful ePaper yourself

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

<strong>Unix</strong> Security<br />

system(cmdstr);<br />

$ echo "/bin/cat /etc/private" > ed<br />

$ chmod +x ed<br />

$ PATH=":"; export PATH<br />

$ smart idiot<br />

/* always specify full pathname */<br />

system("/bin/ed"):<br />

/* or specify path */<br />

system("PATH=/bin:/usr/bin:/etc ed");<br />

$ cp ed bin<br />

$ PATH=: IFS=/ smarter idiot<br />

/* solution */<br />

system("IFS=' \t\n'; export IFS: /bin/ed");<br />

system("IFS=' \t\n'; export IFS; PATH=/bin:/usr/bin:/etc ed");<br />

$ smarter "idiot; cat /etc/private"<br />

/* check argv[l] for special shell characters */<br />

if (strpbrk(argv[l], "|^;&'*?[]$/\\'\"\n") != (char *) NULL)<br />

{<br />

fprintf(stderr, "smartest: bad character in argument\n"):<br />

exit(2);<br />

}<br />

! Shell Escapes<br />

saveeuid = geteuid();<br />

setuid(getuid());<br />

system("/bin/ed") ;<br />

setuid(saveeuid):<br />

! Executing SUID programs from inside SUID programs<br />

When you run a SUID program from inside a SUID program <strong>the</strong> new program runs <strong>with</strong> <strong>the</strong> effective UID of its<br />

owner. "mkdir" & "rmdir" commands are SUID and owned by root.<br />

$ cat mkrmdir. c<br />

main ()<br />

{<br />

system("/bin/mkdir foo");<br />

system("/bin/rmdir foo");<br />

}<br />

$ ls -l mkrmdir<br />

-rwsr-xr-x 1 pat ITB100 2048 May 26 17:01 mkrmdir<br />

$ ls -ld<br />

drwxr-xr-x 2 pat ITB100 320 May 26 17:02 .<br />

$ who am i<br />

greg tty08 May 26 17:05<br />

$ mkrmdir<br />

mkdir: cannot access.<br />

rmdir: foo non-existent<br />

$ su pat<br />

Password: XXXX<br />

$ id<br />

207

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

Saved successfully!

Ooh no, something went wrong!