This file contains materials for one instance of the attacklab.

Files:

Linux binary with code-injection vulnerability. To be used for phases 1-3 of the assignment.

Linux binary with return-oriented programming vulnerability. To be used for phases 4-5 of the assignment.

Contains an 8-digit hex code that you will need for level 2 and 3 attacks.

Directory where ctarget and rtarget will keep a record of your successful attacks. Take care not to modify or delete any files in this directory.

Phase 1

Use gdb to check the assembly code of the decode_line() function, or use objdump -d ctarget > ctarget.as

alt text

set break point

beforeInput

0x402a96 is in the field of the test function address.

To let the <decode_line> return to the function, we need to let the stack store the value of 0x40298b

input this:

alt text

Phase 2

break *0x4029ba

 

write assembly code in code_2.s

compile the code, then reconstruct the assembly code phase2compile we get

write the code at rsp, and write the decode_line return at the rsp 0x55642100, which is

phase2success

Phase 3

<touch 3> looks like this:

We can check the $rsp value with breakpoint and input as:

And, we find out:

Write assembly code:

Decompile:

0x55642138 - 0x28 = 0x55642110 string to ascii code: 0x72791e2a -> (48 120) 55 50 55 57 49 101 50 97 (decimal) -> (30 78) 37 32 37 39 31 65 32 61 0a (hex)

Pass!

phase3success

Phase 4

Our goal is to put the value of cookie into %rdi. Therefore, look into the code form <start_farm> to <end_farm>, we can find useful gadgets:

According to the table,

table1 useful segements are (at 0x402aaf+0x2 = 402ab1):

%rax is used in the code, so we also need to put the value into %rax first. Looking at table:

table2 we can find useful gadgets:

The segments we need is (at 0x402aa9+0x3 = 0x402aac):

Therefore, we can input the following string

alt text

Phase 5

Use this to get the %rsp value

Use this to add or substract the offset:

Use this as popq %rax

Use this to move the %rax value to %rdi and %rsi

use this as eax -> ecx

Use thiws as ecx -> edx

Use this as edx -> esi

After all:

break *0x402844

Finally,

alt text