Software+Security
Software+Security
Lesson Introduction
●Software vulnerabilities and how attackers exploit them.
● Defenses against attacks that try to exploit buffer
overflows.
#include <stdio.h>
#include <strings.h>
if (allow_login == 0)
printf("Login request rejected");
else
printf("Login request allowed");
}
Stack Access Quiz
Check the lines of code, when executed, accesses addresses in
the stack frame for main():
int main(int argc, char *argv[]) {
int allow_login = 0;
char pwdstr[12];
char targetpwd[12] = "MyPwd123";
gets(pwdstr);
if (strncmp(pwdstr,targetpwd, 12) == 0)
allow_login = 1;
if (allow_login == 0)
printf("Login request rejected");
else
printf("Login request allowed");
}
Understanding the Stack
High Address
Low Address
Attacker Bad Input Quiz
What type of password string could defeat the
password check code? (Check all that apply)
#include <stdio.h> Any password of length
#include <strings.h>
greater than 12 bytes
int main(int argc, char *argv[]) {
int allow_login = 0;
that ends in ‘123’
char pwdstr[12];
char targetpwd[12] = "MyPwd123";
gets(pwdstr); Any password of length
if (strncmp(pwdstr,targetpwd, 12) == greater than 16 bytes
0)
allow_login = 1; that begins with
if (allow_login == 0)
‘MyPwd123’
printf("Login request
rejected");
else Any password of length
printf("Login request
greater than 8 bytes
Attacker Code Execution
We type a correct password (MyPwd123) of less
than 12 characters:
If we type a really
long string, we
will overflow into
the return address
space.
Attacker Code Execution
We can carefully
overflow the
return address
so it contains the
value of an
address where we
put some code we
want executed.
Buffer Overflow Quiz
Which of these vulnerabilities applies to
the code:
The target password was too short, this made it easy
to overflow the buffer.
The code did not check the input and reject password
strings longer than 12 bytes.
Higher Address
Stack
char* p = malloc (256);
memset (p, ‘A’, 1024);
Heap
Lower Address
●Heap Overflow – Example
Higher Address
Chunk 2
Chunk 1
The language...
●Should be strongly typed
●Should do automatic bounds checks
●Should do automatic memory
management