socat绑定程序到端口
1.使用socat挂载在服务器端口
sudo apt-get install socatsocat tcp-l:端口号,fork exec:程序位置,reuseaddr
nc绑定程序到特定端口
ncat -ve./[prog] -kl [port]
nohup命令(使得关闭终端也能运行题目程序)
First.编写脚本pwn.sh#!/bin/sh#name:pwn.shsocat tcp-l:端口号,fork exec:程序位置,reuseaddrNext.运行脚本sudo chmod u+x ./pwn.shnohup ./pwn.sh &
docker搭建
查看汇编代码
objdump -d ./
pwntools 检查保护
checksec [prog]
readelf
readelf --program--headers ${binary} 检查nx保护
gdb-peda
生成垃圾数据,计算偏移
pattern create 100pattern 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 1000cyclic -l AABA
gdb 反汇编
hook
使用钩子,当在断点处停止时会执行gdb 命令define hook-stopType 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) delDelete all breakpoints? (y or n) y(gdb) break *0x0804840cBreakpoint 2 at 0x804840c: file stack0/stack0.c, line 11.(gdb) break *0x8048411Breakpoint 3 at 0x8048411: file stack0/stack0.c, line 13.(gdb) define hook-stopType 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) rThe program being debugged has been started already.Start it from the beginning? (y or n) yStarting program: /opt/protostar/bin/stack0eax 0xbffff77c -1073744004ecx 0x92346446 -1842060218edx 0x1 1ebx 0xb7fd7ff4 -1208123404esp 0xbffff760 0xbffff760ebp 0xbffff7c8 0xbffff7c8esi 0x0 0edi 0x0 0eip 0x804840c 0x804840c <main+24>eflags 0x200286 [ PF SF IF ID ]cs 0x73 115ss 0x7b 123ds 0x7b 123es 0x7b 123fs 0x0 0gs 0x33 510xbffff760: 0xbffff77c 0x00000001 0xb7fff8f8 0xb7f0186e0xbffff770: 0xb7fd7ff4 0xb7ec6165 0xbffff788 0xb7eada750xbffff780: 0xb7fd7ff4 0x08049620 0xbffff798 0x080482e80xbffff790: 0xb7ff1040 0x08049620 0xbffff7c8 0x080484690xbffff7a0: 0xb7fd8304 0xb7fd7ff4 0x08048450 0xbffff7c80xbffff7b0: 0xb7ec6365 0xb7ff1040 0x0804845b 0x00000000Error 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 execstackexecstack --set-execstack 开启无需编译execstack --clear-execstack
2.关掉Stack Protector/Canary(栈保护/金丝雀)
gcc -fno-stack-protector -o level level.cgcc -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 -secho 0 > /proc/sys/kernel/randomize_va_spaceexit
5.打开整个linux系统的ASLR保护
sudo -secho 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 ```
