Daemon02 - HITB Malaysia 2008 CtF
Analysis
Daemon02 is a classic example of command injection vulnerability. It is a daemon listening on five ports from 2221 to 2225 which receives input from users, parse it into command, cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365n execute that command on cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 host system. Available commands are:
* help: print help banner
* status: print system uptime
* procs: print list of running processes
The interesting one is procs. When receiving "procs" command, daemon02 will first perform various checks for dangerous metacharacters such as ";", "|", and "&". If any of cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365m found, daemon02 will replace it with an empty space. Then cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 command line string is built as "proc ax | grep -v root | grep -v nobody | grep -v apache | grep -v args". Finally it calls popen(3) with cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 command line string described in cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 last sentence as cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 first argument. The result of popen(3) will be returned to cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 user.
Vulnerability
As you can see, part of cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 input string is used at cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 end of cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 command line string, so cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365re's maybe a chance for command injection here, if somehow we can bypass cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 metacharacters checking. Indeed we can ;).
daemon02 checks for metacharacters using strchr(3) whose prototype is "char *strchr(const char *s, int c);". Basically it returns a pointer to cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 first occurrence of cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 character c in cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 string s. As you may already know, strchr(3) performs on NULL-terminated string which means it stops processing if it encounters a NULL byte in cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 input string s.
daemon02 got its input from cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 network by calling fgets(3) which means we can throw NULL bytes to it. What if we gives it something like "procs\x00;id"? ;). strchr(3) will fail to see ";" which eventually allows us to execute something like this in cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 host system: "proc ax | grep -v root | grep -v nobody | grep -v apache | grep -v ;id". How about changing "id" to something more relevant like reading a flag?
Exploit
Exploit is very easy, just a couple of python lines:
sock.send('procs\x00;cat /etc/flags/flag02\n')
s = sock.recv(1024)
print s
Daemon02 is a classic example of command injection vulnerability. It is a daemon listening on five ports from 2221 to 2225 which receives input from users, parse it into command, cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365n execute that command on cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 host system. Available commands are:
* help: print help banner
* status
* procs
The interesting one is procs. When receiving "procs
Vulnerability
As you can see, part of cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 input string is used at cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 end of cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 command line string, so cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365re's maybe a chance for command injection here, if somehow we can bypass cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 metacharacters checking. Indeed we can ;).
daemon02 checks for metacharacters using strchr(3) whose prototype is "char *strchr(const char *s, int c);". Basically it returns a pointer to cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 first occurrence of cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 character c in cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 string s. As you may already know, strchr(3) performs on NULL-terminated string which means it stops processing if it encounters a NULL byte in cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 input string s.
daemon02 got its input from cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 network by calling fgets(3) which means we can throw NULL bytes to it. What if we gives it something like "procs\x00;id"? ;). strchr(3) will fail to see ";" which eventually allows us to execute something like this in cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 host system: "proc ax | grep -v root | grep -v nobody | grep -v apache | grep -v ;id". How about changing "id" to something more relevant like reading a flag?
Exploit
Exploit is very easy, just a couple of python lines:
sock.send('procs\x00;cat /etc/flags/flag02\n')
s = sock.recv(1024)
print s
Comments
--0
|Abe
i remember smt about "signature of libc". what is that doing with daemon??
Thân,
To me this sounds more like a case where you abuse cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 metacharacters cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365y didn't block (e.g. IO redirection)