长度:
字符 | 长度(byte) | 使用 |
---|---|---|
hh | 1 | char |
h | 2 | short int |
l | 4 | long int |
Ll | 8 | long long int |
转换符:
字符 | 长度 (byte) | 使用 |
---|---|---|
d | 4 | integer |
u | 4 | Unsigned integer |
x | 4 | hex |
s | 4 | String |
c | 1 | Character |
32位:
读:
1 | '%{}$x'.format(index) // 读4个字节 |
写:1
2
3
4'%{}$n'.format(index) // 解引用,写入四个字节
'%{}$hn'.format(index) // 解引用,写入两个字节
'%{}$hhn'.format(index) // 解引用,写入一个字节
'%{}$lln'.format(index) // 解引用,写入八个字节
64位:
读:1
2
3
4'%{}$x'.format(index, num) // 读4个字节
'%{}$lx'.format(index, num) // 读8个字节
'%{}$p'.format(index) // 读8个字节
'${}$s'.format(index)
写:1
2
3
4
5
6
7
8
9
10'%{}$n'.format(index) // 解引用,写入四个字节
'%{}$hn'.format(index) // 解引用,写入两个字节
'%{}$hhn'.format(index) // 解引用,写入一个字节
'%{}$lln'.format(index) // 解引用,写入八个字节
%1$lx: RSI
%2$lx: RDX
%3$lx: RCX
%4$lx: R8
%5$lx: R9
%6$lx: 栈上的第一个QWORD
附加:
fmtstr_payload是pwntools提供的函数,用于自动生成格式化字符串。
fmtstr_payload有两个参数
第一个参数是int,用于表示取参数的偏移个数
第二个参数是字典,字典的意义是往key的地址,写入value的值
1 | fmtstr_payload(7, {printf_got: system_add}) |
这个函数调用会往printf_got中写入system_add