pwn 相关环境
asdf
# 使用
# exp模板
使用 lambda 简化一些函数调用, 使用 sys.argv[1] 在运行脚本时快速指定本地/远程,其他一些为一般pwn都会使用的设置。
from pwn import *
import sys
arch =
challenge =
def exp():
# code
local = int(sys.argv[1])
elf = ELF(challenge)
context.os='linux'
context.log_level = 'debug'
context.terminal = ['tmux', 'splitw', '-h']
if local:
cn = process(challenge)
else:
cn = remote( )
if arch==64:
context.arch='amd64'
if arch==32:
context.arch='i386'
p = lambda : pause()
s = lambda x : success(x)
re = lambda m, t : cn.recv(numb=m, timeout=t)
ru = lambda x : cn.recvuntil(x)
rl = lambda : cn.recvline()
sd = lambda x : cn.send(x)
sl = lambda x : cn.sendline(x)
ia = lambda : cn.interactive()
sla = lambda a, b : cn.sendlineafter(a, b)
sa = lambda a, b : cn.sendafter(a, b)
# after a, send b;
exp()
ia()
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
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
借助 pmap 'pid'
和awk
获取当前基地址,并保存在$base中,可以在gdb中访问,
且pie下的调试可以自动下断。
bps = []
pie = 0
def gdba():
if local == 0:
return 0;
cmd ='set follow-fork-mode parent\n'
#cmd=''
if pie:
base =int(os.popen("pmap {}|awk '{{print $1}}'".format(cn.pid)).readlines()[1],16)
cmd +=''.join(['b *{:#x}\n'.format(b+base) for b in bps])
cmd +='set $base={:#x}\n'.format(base)
else:
cmd+=''.join(['b *{:#x}\n'.format(b) for b in bps])
gdb.attach(cn,cmd)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
堆 菜单题常见:
def add(size):
sl('1')
sl(str(size))
def edit(index, con):
sl('2')
sl(str(index))
sl(str(len(con)))
sl(con)
def dele(index):
sl('3')
sl(str(index))
def show(index):
sl('4')
sl(str(index))
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# 环境-docker
这里两个配好的docker:
docker pull skysider/pwndocker:latest # 实现了多个libc版本的docker
docker pull lingze/pwn:1.0 # 多个libc版本, 并已经配好vim tmux等
1
2
2
另外有一个libc2.23版本,可带源码调试malloc部分的docker, 可以配合学习华庭的源码解析
docker pull lingze/gdb:libc23
1
# 使用
docker的两个概念: images, container pull 下来的都是images, 运行中的都是container, images启动使用run, 然后产生对应的一个container, container运行使用start为将一个停止的container启动, contianer关闭使用stop, 运行加入一个-d参数,为在后台启动,然后接入使用exec,这样可以在退出contianer时只是推出链接,而continaer不会停止,方便下次再接入进去, 其中一些常见的在.bashrc/.zshrc中的alias和函数设置:
# docker
alias d='docker'
alias dps='docker ps -a'
dexec(){
docker exec -it $1 /bin/bash;
}
1
2
3
4
5
6
2
3
4
5
6
一些相关链接: docker入门, docker创建镜像, docker文件互传和启动方式, 另外, 如果自己配置docker,可以备份在docker-hub一份,方便以后直接pull下来使用,
上次更新: 3/17/2025, 4:54:54 PM