write4

write4 32bit

Solution

The string "/bin/cat flag.txt" is not present in the binary, so the method used in "split" won't work here.

We are given a function print_file and our task is to call print_file("flag.txt"). There is no "flag.txt" string in the binary either, so we have to input this string and store it somewhere, for example, the .bss segment.

As the instruction suggests, we should look for a gadget mov [reg], reg:

ROPgadget

The idea is:

  1. Store the string "flag" in ebp.

  2. Store the address of bss in edi.

  3. Use the gadget mov dword ptr [edi], ebp ; ret to pass the string flag to the .bss segment.

  4. Repeat step 1 to 3 to pass the string ".txt" to bss + 4.

  5. Call print_file(bss)

Exploit

write4 64bit

Solution

Again, the 64-bit case is even simpler. The idea is the same, except we can pass the string "flag.txt" in one round because we are dealing with 64-bit registers.

Exploit

Last updated