Posted onEdited onInpwn
,
逆向Views: Word count in article: 785Reading time ≈3 mins.
详细过程及exp
1. Basic checks:
1 2 3 4 5 6 7 8 9 10 11 12
┌──(root💀kali)-[~/hackthebox/challenge/pwn/space] └─# file space space: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux.so.2, for GNU/Linux 3.2.0, BuildID[sha1]=90e5767272e16e26e1980cb78be61437b3d63e12, not stripped ┌──(root💀kali)-[~/hackthebox/challenge/pwn/space] └─# checksec space [*] '/root/hackthebox/challenge/pwn/space/space' Arch: i386-32-little RELRO: No RELRO Stack: No canary found NX: NX disabled PIE: No PIE (0x8048000) RWX: Has RWX segments
2. Debug binary with buffer overflow string as input:
3. Check the EIP offset:
4. Control EIP with custom bytes:
5. Check the space for the custom payload:
There is 18B + 9B space split by 4 Bytes for the EIP register.
So payload could look like great post https://www.abatchy.com/2017/05/jumping-to-shellcode.html:
EAX stores (18B + 4B + 9B) data provided as input during overflow.
Without the “mov esp, eax” step, second_stage_shellcode would break the execution flow, because pushed “0x6e69622f” would be treated as data to execute, while it should be stored for further executed syscall and treated as an argument for execve() stored in EBX register. https://security.stackexchange.com/questions/98311/problems-executing-shellcode-via-nop-sled
Then set up EAX and ECX registers to 0. A short jump to the first 18B on the stack. Great article which explains, why we jump 0xe2 — available https://thestarman.pcministry.com/asm/2bytejumps.htm
Secondly, we just set up arguments for the execve(). (Check this article, if you don’t know CDQ instruction)