socat绑定程序到端口
1.使用socat挂载在服务器端口
sudo apt-get install socat
socat tcp-l:端口号,fork exec:程序位置,reuseaddr
nc绑定程序到特定端口
ncat -ve./[prog] -kl [port]
nohup命令(使得关闭终端也能运行题目程序)
First.编写脚本pwn.sh
#!/bin/sh
#name:pwn.sh
socat tcp-l:端口号,fork exec:程序位置,reuseaddr
Next.运行脚本
sudo chmod u+x ./pwn.sh
nohup ./pwn.sh &
docker搭建
查看汇编代码
objdump -d ./
pwntools 检查保护
checksec [prog]
readelf
readelf --program--headers ${binary} 检查nx保护
gdb-peda
生成垃圾数据,计算偏移
pattern create 100
pattern offset AABA
msf
/usr/share/metasploit-framework/tools/exploit/pattern_create.rb -l 1200
/usr/share/metasploit-framework/tools/exploit/pattern_offset.rb -q 8Bn9
[*] Exact match at offset 1196
gdb-pwn
生成垃圾数据,计算偏移
cyclic 1000
cyclic -l AABA
gdb 反汇编
hook
使用钩子,当在断点处停止时会执行gdb 命令
define hook-stop
Type commands for definition of "hook-stop".
End with a line saying just "end".
>info registers
>x/24wx $esp
>x/2i $eip
>end
(gdb) r
效果
(gdb) del
Delete all breakpoints? (y or n) y
(gdb) break *0x0804840c
Breakpoint 2 at 0x804840c: file stack0/stack0.c, line 11.
(gdb) break *0x8048411
Breakpoint 3 at 0x8048411: file stack0/stack0.c, line 13.
(gdb) define hook-stop
Type commands for definition of "hook-stop".
End with a line saying just "end".
>info registers
>x/24wx $esp
>x/2i $eip
>end
(gdb) r
(gdb) r
The program being debugged has been started already.
Start it from the beginning? (y or n) y
Starting program: /opt/protostar/bin/stack0
eax 0xbffff77c -1073744004
ecx 0x92346446 -1842060218
edx 0x1 1
ebx 0xb7fd7ff4 -1208123404
esp 0xbffff760 0xbffff760
ebp 0xbffff7c8 0xbffff7c8
esi 0x0 0
edi 0x0 0
eip 0x804840c 0x804840c <main+24>
eflags 0x200286 [ PF SF IF ID ]
cs 0x73 115
ss 0x7b 123
ds 0x7b 123
es 0x7b 123
fs 0x0 0
gs 0x33 51
0xbffff760: 0xbffff77c 0x00000001 0xb7fff8f8 0xb7f0186e
0xbffff770: 0xb7fd7ff4 0xb7ec6165 0xbffff788 0xb7eada75
0xbffff780: 0xb7fd7ff4 0x08049620 0xbffff798 0x080482e8
0xbffff790: 0xb7ff1040 0x08049620 0xbffff7c8 0x08048469
0xbffff7a0: 0xb7fd8304 0xb7fd7ff4 0x08048450 0xbffff7c8
0xbffff7b0: 0xb7ec6365 0xb7ff1040 0x0804845b 0x00000000
Error while running hook_stop:
b*main 设置断点
disassembly 反汇编当前函数
disassembly main 反汇编main函数
info proc mappings 查看内存映射情况以及堆栈地址
intel 风格
set disassembly-flavor intel #设置反汇编风格intel或者让att&
set disassembly-flavor att
关闭保护
1.关闭栈保护 -fno-stack-protector
关闭栈可执行(NX,DEP) -zexecstack
gcc -fno-stack-protector -zexecstack bof.c -o bof
gcc -z execstack 开启
或者安装 execstack :apt install execstack
execstack --set-execstack 开启无需编译
execstack --clear-execstack
2.关掉Stack Protector/Canary(栈保护/金丝雀)
gcc -fno-stack-protector -o level level.c
gcc -o test test.c // 默认情况下,不开启Canary保护
gcc -fno-stack-protector -o test test.c //禁用栈保护
gcc -fstack-protector -o test test.c //启用堆栈保护,不过只为局部变量中含有 char 数组的函数插入保护代码
gcc -fstack-protector-all -o test test.c //启用堆栈保护,为所有函数插入保护代码
3.关掉程序ASLR/PIE(程序随机化保护)
gcc -no-pie level level.c
4.关闭整个linux系统的ASLR保护
sudo -s
echo 0 > /proc/sys/kernel/randomize_va_space
exit
5.打开整个linux系统的ASLR保护
sudo -s
echo 2 > /proc/sys/kernel/randomize_va_space
6.RELRO (Relocation Read Only)
- default 是Partial ```bash 开启 full gcc -Wl,-z,relro,-z,now 关闭 gcc -Wol,-z,norelro
全部开启RELRO机制Partial-RELRO:在编译时增加 -z now (GOT 不可写) 部分开启RELRO机制Full-RELRO:在编译时增加 -z lazy(默认配置,GOT可写) 关闭RELRO机制: 在编译时增加 -z norelro ```