Iris CTF 2023 - babyseek (offset)
Info
86 Solves (8.4% of users)
167 Points (500 Points)
description
I’ll let you seek around my file as far as you want, but you can’t go anywhere since it’s /dev/null.nc ret2libm.chal.irisc.tf 10004
To figure out where things are, you can use the gdb debugger. I recommend using a Docker instance, such as with the Dockerfile provided, to ensure you have an environment that matches the remote server you are attacking.
Hint!
You can find the location of functions in the Global Offset Table by using their name followed by @got.plt - for example, print &‘fwrite@got.plt‘.
By: sera
for player
1 | . |
1 | chal: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=25a1bb094d7ba8684d70c7686826e67352ceaf0b, for GNU/Linux 3.2.0, with debug_info, not stripped |
Analysis
Mitigation
1 | Arch: amd64-64-little |
Source Code
This challenge have a source code, So we can view the original source code ! :)
1 |
|
Nice win()
function which prints the flag. I like it.
Let’s see the [*]
and [**]
marking in code. First [*]
, The null
pointer is points to the _IO_write_ptr
member of a FILE
object. It points to the location where the file is being written to in memory. Before [**]
, We can write the value to pos
. It is add to the null->_IO_write_ptr
at [**]
, So pos
is mean the offset.
The frwite()
function attempt to write address of the win()
to that offset, and then exit()
.
Vulnerability
We can move the pointer that the file is being written to in memory.
Exploit
Exploit Scenario
Let’s overwrite the GOT
of exit()
which is called write after. We calculate the offset of win()
to exit@got.plt
.
Exploit Code
1 | from pwn import * |
In this CTF, Perhaps to prevent brute force, the following process is added when connecting to the server.
1 | == proof-of-work: enabled == |
Flag
1 | irisctf{not_quite_fseek} |