Systems and Internet Infrastructure Security Laboratory (SIIS) Page 1
CMPSC 497: Midterm Review
Trent Jaeger Systems and Internet Infrastructure Security (SIIS) Lab Computer Science and Engineering Department Pennsylvania State University
CMPSC 497: Midterm Review Trent Jaeger Systems and Internet - - PowerPoint PPT Presentation
CMPSC 497: Midterm Review Trent Jaeger Systems and Internet Infrastructure Security (SIIS) Lab Computer Science and Engineering Department Pennsylvania State University Systems and Internet Infrastructure Security Laboratory (SIIS) Page 1
Systems and Internet Infrastructure Security Laboratory (SIIS) Page 1
Trent Jaeger Systems and Internet Infrastructure Security (SIIS) Lab Computer Science and Engineering Department Pennsylvania State University
Systems and Internet Infrastructure Security Laboratory (SIIS) Page
2
Systems and Internet Infrastructure Security Laboratory (SIIS) Page
3
Systems and Internet Infrastructure Security Laboratory (SIIS) Page
4
Systems and Internet Infrastructure Security Laboratory (SIIS) Page 5
printf ("This class is %s\n", string);
Systems and Internet Infrastructure Security Laboratory (SIIS) Page 6
printf(“%s%s%s%s”);
Systems and Internet Infrastructure Security Laboratory (SIIS) Page 7
printf(arg);
Systems and Internet Infrastructure Security Laboratory (SIIS) Page 8
an adversary-controlled number
Arg1-Arg3 on stack
string with Arg1 and Arg2
write that number (of bytes) using %n with address at Arg3
Systems and Internet Infrastructure Security Laboratory (SIIS) Page
9
Systems and Internet Infrastructure Security Laboratory (SIIS) Page 10
void function (int a, int b) { char buffer[12]; gets(buffer); return; } void main() { int x; x = 0; function(1,2); x = 1; printf("%d\n",x); }
Systems and Internet Infrastructure Security Laboratory (SIIS) Page 11
Systems and Internet Infrastructure Security Laboratory (SIIS) Page 12
Systems and Internet Infrastructure Security Laboratory (SIIS) Page
13
Systems and Internet Infrastructure Security Laboratory (SIIS) Page
Systems and Internet Infrastructure Security Laboratory (SIIS) Page
char packet[10]; … // suppose len is adversary controlled strncpy(buf, packet, len); send(fd, buf, len);
15
Systems and Internet Infrastructure Security Laboratory (SIIS) Page
16
Systems and Internet Infrastructure Security Laboratory (SIIS) Page
17
Systems and Internet Infrastructure Security Laboratory (SIIS) Page
18
Systems and Internet Infrastructure Security Laboratory (SIIS) Page
19
writable memory
Systems and Internet Infrastructure Security Laboratory (SIIS) Page
20
writable memory
Systems and Internet Infrastructure Security Laboratory (SIIS) Page
21
writable memory
Systems and Internet Infrastructure Security Laboratory (SIIS) Page
22
Systems and Internet Infrastructure Security Laboratory (SIIS) Page
23
Systems and Internet Infrastructure Security Laboratory (SIIS) Page
24
Systems and Internet Infrastructure Security Laboratory (SIIS) Page
25
Systems and Internet Infrastructure Security Laboratory (SIIS) Page
26
Systems and Internet Infrastructure Security Laboratory (SIIS) Page
27
Systems and Internet Infrastructure Security Laboratory (SIIS) Page
28
Systems and Internet Infrastructure Security Laboratory (SIIS) Page
29
Systems and Internet Infrastructure Security Laboratory (SIIS) Page
30
Systems and Internet Infrastructure Security Laboratory (SIIS) Page
2: int connect limit = MAXCONN; int *size, *type; 3: char buf[MAXLEN]; 4: size = &buf[8]; type = &buf[12]; 5: ... /* code in that function */ 6: while(connect limit--) { 7: readData(sockfd, buf); 8: if(*type == NONE ) break; 9: if(*type == STREAM) 10: *size = *(srv->cur max); 11: else { 12: srv->typ = *type; 13: srv->total += *size; 14: } 15: err = processData(buf, &result); 16: if (!err) sendData(sockfd, result);
31
Systems and Internet Infrastructure Security Laboratory (SIIS) Page
2: int connect limit = MAXCONN; int *size, *type; 3: char buf[MAXLEN]; 4: size = &buf[8]; type = &buf[12]; 5: ... /* code in that function */ 6: while(connect limit--) { 7: readData(sockfd, buf); 8: if(*type == NONE ) break; 9: if(*type == STREAM) 10: *size = *(srv->cur max); 11: else { 12: srv->typ = *type; 13: srv->total += *size; 14: } 15: err = processData(buf, &result); 16: if (!err) sendData(sockfd, result);
32
Systems and Internet Infrastructure Security Laboratory (SIIS) Page
2: int connect limit = MAXCONN; int *size, *type; 3: char buf[MAXLEN]; 4: size = &buf[8]; type = &buf[12]; 5: ... /* code in that function */ 6: while(connect limit--) { 7: readData(sockfd, buf); 8: if(*type == NONE ) break; 9: if(*type == STREAM) 10: *size = *(srv->cur max); 11: else { 12: srv->typ = *type; 13: srv->total += *size; 14: } 15: err = processData(buf, &result); 16: if (!err) sendData(sockfd, result);
33
Systems and Internet Infrastructure Security Laboratory (SIIS) Page
2: int connect limit = MAXCONN; int *size, *type; 3: char buf[MAXLEN]; 4: size = &buf[8]; type = &buf[12]; 5: ... /* code in that function */ 6: while(connect limit--) { 7: readData(sockfd, buf); 8: if(*type == NONE ) break; 9: if(*type == STREAM) 10: *size = *(srv->cur max); 11: else { 12: srv->typ = *type; 13: srv->total += *size; 14: } 15: err = processData(buf, &result); 16: if (!err) sendData(sockfd, result);
34
Systems and Internet Infrastructure Security Laboratory (SIIS) Page
2: int connect limit = MAXCONN; int *size, *type; 3: char buf[MAXLEN]; 4: size = &buf[8]; type = &buf[12]; 5: ... /* code in that function */ 6: while(connect limit--) { 7: readData(sockfd, buf); 8: if(*type == NONE ) break; 9: if(*type == STREAM) 10: *size = *(srv->cur max); 11: else { 12: srv->typ = *type; 13: srv->total += *size; 14: } 15: err = processData(buf, &result); 16: if (!err) sendData(sockfd, result);
35
Systems and Internet Infrastructure Security Laboratory (SIIS) Page
2: int connect limit = MAXCONN; int *size, *type; 3: char buf[MAXLEN]; 4: size = &buf[8]; type = &buf[12]; 5: ... /* code in that function */ 6: while(connect limit--) { 7: readData(sockfd, buf); 8: if(*type == NONE ) break; 9: if(*type == STREAM) 10: *size = *(srv->cur max); 11: else { 12: srv->typ = *type; 13: srv->total += *size; 14: } 15: err = processData(buf, &result); 16: if (!err) sendData(sockfd, result);
36
Systems and Internet Infrastructure Security Laboratory (SIIS) Page
2: int connect limit = MAXCONN; int *size, *type; 3: char buf[MAXLEN]; 4: size = &buf[8]; type = &buf[12]; 5: ... /* code in that function */ 6: while(connect limit--) { 7: readData(sockfd, buf); 8: if(*type == NONE ) break; 9: if(*type == STREAM) 10: *size = *(srv->cur max); 11: else { 12: srv->typ = *type; 13: srv->total += *size; 14: } 15: err = processData(buf, &result); 16: if (!err) sendData(sockfd, result);
37
Systems and Internet Infrastructure Security Laboratory (SIIS) Page
38
Gadgets
G1: push %eax; ret G2: pop %eax; ret G3: push %ebx; ret G4: pop %ebx; ret G5: mov %eax, (%ebx); ret // store value in %eax to memory location (%ebx) G6: pop %esp; ret G7: jmp %ebx; ret G8: add (%ebx), %eax; ret // add value at memory location (%ebx) to %eax G9: ret G10: pop %esp; ret
Systems and Internet Infrastructure Security Laboratory (SIIS) Page
39
Gadgets
G1: push %eax; ret G2: pop %eax; ret G3: push %ebx; ret G4: pop %ebx; ret G5: mov %eax, (%ebx); ret // store value in %eax to memory location (%ebx) G6: pop %esp; ret G7: jmp %ebx; ret G8: add (%ebx), %eax; ret // add value at memory location (%ebx) to %eax G9: ret G10: pop %esp; ret
Systems and Internet Infrastructure Security Laboratory (SIIS) Page
40
Gadgets
G1: push %eax; ret G2: pop %eax; ret G3: push %ebx; ret G4: pop %ebx; ret G5: mov %eax, (%ebx); ret // store value in %eax to memory location (%ebx) G6: pop %esp; ret G7: jmp %ebx; ret G8: add (%ebx), %eax; ret // add value at memory location (%ebx) to %eax G9: ret G10: pop %esp; ret
Systems and Internet Infrastructure Security Laboratory (SIIS) Page
41
Gadgets
G1: push %eax; ret G2: pop %eax; ret G3: push %ebx; ret G4: pop %ebx; ret G5: mov %eax, (%ebx); ret // store value in %eax to memory location (%ebx) G6: pop %esp; ret G7: jmp %ebx; ret G8: add (%ebx), %eax; ret // add value at memory location (%ebx) to %eax G9: ret G10: pop %esp; ret
Systems and Internet Infrastructure Security Laboratory (SIIS) Page
42
Gadgets
G1: push %eax; ret G2: pop %eax; ret G3: push %ebx; ret G4: pop %ebx; ret G5: mov %eax, (%ebx); ret // store value in %eax to memory location (%ebx) G6: pop %esp; ret G7: jmp %ebx; ret G8: add (%ebx), %eax; ret // add value at memory location (%ebx) to %eax G9: ret G10: pop %esp; ret
Systems and Internet Infrastructure Security Laboratory (SIIS) Page
43
Gadgets
G1: push %eax; ret G2: pop %eax; ret G3: push %ebx; ret G4: pop %ebx; ret G5: mov %eax, (%ebx); ret // store value in %eax to memory location (%ebx) G6: pop %esp; ret G7: jmp %ebx; ret G8: add (%ebx), %eax; ret // add value at memory location (%ebx) to %eax G9: ret G10: pop %esp; ret
Systems and Internet Infrastructure Security Laboratory (SIIS) Page
44
Systems and Internet Infrastructure Security Laboratory (SIIS) Page
45
Systems and Internet Infrastructure Security Laboratory (SIIS) Page
46
// file path is "/home/" at this point 1: bytes = recv(socket, html page, LIMIT, FLAGS); 2: strncat(file path, html page, LIMIT); 3: check stat(html page, NOT SYMLINK); 4: fd = open(html page, RDONLY); 5: bytes = read(fd, outbuf, LIMIT); 6: send(socket, outbuf, LIMIT, FLAGS);
Systems and Internet Infrastructure Security Laboratory (SIIS) Page
47
// file path is "/home/" at this point 1: bytes = recv(socket, html page, LIMIT, FLAGS); 2: strncat(file path, html page, LIMIT); 3: check stat(html page, NOT SYMLINK); 4: fd = open(html page, RDONLY); 5: bytes = read(fd, outbuf, LIMIT); 6: send(socket, outbuf, LIMIT, FLAGS);
Systems and Internet Infrastructure Security Laboratory (SIIS) Page
48
// file path is "/home/" at this point 1: bytes = recv(socket, html page, LIMIT, FLAGS); 2: strncat(file path, html page, LIMIT); 3: check stat(html page, NOT SYMLINK); 4: fd = open(html page, RDONLY); 5: bytes = read(fd, outbuf, LIMIT); 6: send(socket, outbuf, LIMIT, FLAGS);
Systems and Internet Infrastructure Security Laboratory (SIIS) Page
49
// file path is "/home/" at this point 1: bytes = recv(socket, html page, LIMIT, FLAGS); 2: strncat(file path, html page, LIMIT); 3: check stat(html page, NOT SYMLINK); 4: fd = open(html page, RDONLY); 5: bytes = read(fd, outbuf, LIMIT); 6: send(socket, outbuf, LIMIT, FLAGS);
Systems and Internet Infrastructure Security Laboratory (SIIS) Page
50
// file path is "/home/" at this point 1: bytes = recv(socket, html page, LIMIT, FLAGS); 2: strncat(file path, html page, LIMIT); 3: check stat(html page, NOT SYMLINK); 4: fd = open(html page, RDONLY); 5: bytes = read(fd, outbuf, LIMIT); 6: send(socket, outbuf, LIMIT, FLAGS);
Systems and Internet Infrastructure Security Laboratory (SIIS) Page
51