DEV Community

Hyunseung Ha
Hyunseung Ha

Posted on

3

[PWN.03] Exploitation with pwntools

pwntools is a python tool used for exploitation.
We can use it and exploit easier than in the past.

#!/usr/bin/python
from pwn import *

# remote connection
r = remote("{IP}", PORT)

# Write payload to exploit
payload = ...

# Send data to {IP}
r.send(payload)
r.sendline(payload)
r.sendafter("{STRING FROM REMOTE}", payload)
r.sendlineafter("{STRING FROM REMOTE}", payload)

# Receive data from Remote
r.recv(int)
r.recvline()
r.recvuntil("{STRING}")
... and more

# Change to Little endian or Big Endian
# Little endian
hex(u32(VALUE))
hex(u64(VALUE))

# Big Endian
hex(p32(VALUE))
hex(p64(VALUE))

# for PLT(Procedure Linkage Table) and GOT(Global Offset 
Table)
e = ELF('{FILE}')
puts_plt = e.plt['puts']
read_got = e.got['read']

# Set architecture
context.arch = "amd64" # or i386, arm

# SHELL making AUTOMATICALLY
s = shellcraft.sh()
Enter fullscreen mode Exit fullscreen mode

We can easily perform exploits using the above.

Speedy emails, satisfied customers

Postmark Image

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay