Computer and Network Security

Table of Contents

Lecture 5: application security - simple attacks

Buffer overflow

Example program:

#include <stdio.h>
#include <string.h>
void hello(char *name) {
    char buf[16];           # limited space
    strcpy(buf, name);      # no limit on copied data => buffer overflow
    printf("hello %s\n", buf);
}
int main(int argc, char **argv) {
    hello(argv[1]);
    return 0;
}

Three types of memory:

In the example, buf is on the stack.

Stack frames:

The buffer overflow in the example overwrites the return address, so the program fails when jumping to an invalid address.

Terminology:

Local privilege escalation

Local attacks: attacker can already execute code, privileges are restricted – you want to impersonate another user with higher privileges

UNIX permissions:

Files are owned by a user and group. Three sets of permission bits for user, group, and others.

Process:

Impersonation:

Setuid process has multiple UIDs:

For local attacks, you usually target setuid root binaries, or operating system kernel.

Simple attacks

Program behavior depends on

Performing an attack:

environment attacks:

file system attacks:

race conditions: time-of-check to time-of-use attack (what if permission at time of use differs from time of check? e.g. symlink changes)

principle of least privilege:

Every program and every privileged user of the system should operate using the least amount of privilege necessary to complete the job.