lecture
in color
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
main() {
struct stat buf;
const char *fname = "/g/150NET/notes/threats/.cshrc";
if (stat(fname,&buf)!=0 || buf.st_mtime+60<time(0)) {
printf("Time's up! I'm going to destroy this!\n");
}
}
/g/150NET/notes/threats/.cshrc
every minute the script fires.
/bin/login or set-user-id command /usr/bin/telnet!
#include <stdio.h>
#define LEN 10
/* here's the function I'll cause to be called */
int foo(const char *q) {
printf("I got you, and captured '%s'\n",q);
}
/* here's the function that should be called */
int normal(const char *p) {
printf("your message is '%s'\n", p);
}
main() {
/* pointer to function: these exist all throughout typical systems */
int (*p)(const char *) = (int (*)(const char *))normal;
char buf[LEN];
size_t size;
/* you can get this info from gdb as well */
printf("buf=%08x\n",buf);
printf("p =%08x\n",&p);
printf("foo=%08x\n",foo);
printf("*p =%08x\n",p);
/* a stupid fread call has a limit three times larger than the buffer */
/* If we read the right thing, we lose */
size=fread(buf,1,LEN*3,stdin);
printf("size=%d\n",size);
printf("*p =%08x\n",p);
/* the trap lies here */
p("hi there");
}
#include <stdio.h>
#define SIZE 20
main() {
int buf[SIZE];
int i;
for (i=0; i<SIZE; i++) buf[i]=0x00010b68; /* address of foo */
fwrite(buf,sizeof(int),SIZE,stdout);
}
foo gets called!
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
main()
{
struct stat buf;
const char *fname = "/tmp/script";
if (stat(fname,&buf)!=0) { /* no file */
FILE *fd = fopen(fname,"w");
fprintf(fd,"echo 'hi there'\n");
fclose(fd);
}
chmod(fname,0755);
system(fname);
unlink(fname);
}
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
main()
{
int i;
struct stat buf;
const char *fname = "/tmp/script";
while (1) {
if (stat(fname,&buf)!=0) { /* no file */
FILE *fd = fopen(fname,"w");
fprintf(fd,"echo 'got you'\n");
fclose(fd);
chmod(fname,0555);
}
for (i=0; i<100; i++) {}
unlink(fname); /* try again */
}
}
fopen actually opened a new file.
victim v check file exists v open file v write file v close file hack v create hack v write hack v close file ----------------------------------------------------------------> time
suexec.c that basically no one can do it. /loc/apache/apache_1.3.9/apache_1.3.9/src/support/suexec.c
$thing .= $tainted; # now $thing is tainted as well.
#! /local/bin/perl -T
system ("ls -l");
reports
Insecure $ENV{PATH} while running with -T switch at taint.pl line 3.
/var/adm/wtmp: login history (command 'last')
/var/adm/wtmpx: extended history for suns
/var/adm/pacct: command accounting (command 'lastcomm')
/usr/sbin/in.telnetd
/usr/sbin/in.ftpd
/usr/local/bin/sshd2
/usr/bin/ps hides user you create.
/usr/bin/ls hides directory you create, e.g., /var/.w, /.x
/usr/sbin/halt, /usr/sbin/shutdown erase all traces of your visit
and restore files to old states.
lecture
in color