arm pwn 入门
arm 汇编基础
寄存器

------ctf wiki
调用约定
- 在函数调用的时候寄存器
R0 R1 R2 R3
分别存放函数的四个参数,如果有4个以上的参数则会从右向左入栈
跳转指令
常见跳转指令有B,BL,BX,BLX
- B == jmp
- L 把下一条指令地址放到 LR 寄存器里面
- X arm指令集切换到thumb指令集
ARM 与 Thumb
- Thumb指令可以看作是ARM指令压缩形式的子集
- cpsr 状态寄存器中标志了当前指令的指令集

- 在函数跳转过程中如果是
BX addr+1
这种形式,即跳转地址的最后一位为1,说明要跳转到的地方是Thumb
指令
POP
- pop{r0,r4,pc}
This instruction causes a branch to the address popped off the stack into the PC. This is usually a return from a subroutine, where the LR was pushed onto the stack at the start of the subroutine. -----arm developer doc
相当于 pop r0,pop r4,ret
jarvisoj_typo
分析
- 程序是静态编译的所以对函数先做个简单的识别
- 可以看到程序存在栈溢出

- 布置的栈的结构如下
padding |
---|
pop{r0,r4,pc} |
/bin/sh\x00 |
aaaa |
system |
- 关于 padding 的大小可以看 ida 的 stack 确定,这里的 s 应该是之前入栈的 LR(返回地址)?或者可以按照 wiki 上的方法确定

exp
1 | from pwn import * |