Last active
September 28, 2016 08:04
-
-
Save sonickun/6f9d6bc2c55d0cec9d051f82ce0d39ae to your computer and use it in GitHub Desktop.
CSAW CTF 2016 | Regexpire (misc100)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import socket | |
| import rstr | |
| remoteip = "misc.chal.csaw.io" | |
| remoteport = 8001 | |
| def sock(remoteip, remoteport): | |
| s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
| s.connect((remoteip, remoteport)) | |
| return s, s.makefile('rw', bufsize=0) | |
| def read_until(f, delim='\n'): | |
| data = '' | |
| while not data.endswith(delim): | |
| data += f.read(1) | |
| return data | |
| s, f = sock(remoteip, remoteport) | |
| print read_until(f, "regexes?\n") | |
| count = 0 | |
| while True: | |
| print "[+] Iter:", count | |
| target = read_until(f, "\n").strip() | |
| print "[+] Target:", target | |
| ans = rstr.xeger(target) | |
| while '\n' in ans: | |
| ans = rstr.xeger(target) | |
| print "[+] Answer:", ans | |
| s.send(ans+"\n") | |
| count += 1 | |
| s.close() | |
| #flag: flag{^regularly_express_yourself$} |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
指定された正規表現を満たす文字列を返す問題×1000問。pythonのrstrが便利。答えの文字列に改行コードが含まれているとそこで区切られてしまうので、改行コードを含まなくなるまで答えを再生成する。