Download : http://pwnable.kr/bin/leg.c
Download : http://pwnable.kr/bin/leg.asm
友链
https://blog.csdn.net/lee_ham/article/details/78398551
下载之后,看看C的源码
if( (key1()+key2()+key3()) == key ){ printf("Congratz!\n"); int fd = open("flag", O_RDONLY); char buf[100]; int r = read(fd, buf, 100); write(0, buf, r);
(key1()+key2()+key3()) == key就可以获得flag
之后打开另一个文件,是asm汇编语言,一个main函数和三个小部分key
来逐一看看key的数值
key1
(gdb) disass key1 Dump of assembler code for function key1: 0x00008cd4 <+0>: push {r11} ; (str r11, [sp, #-4]!) 0x00008cd8 <+4>: add r11, sp, #0 0x00008cdc <+8>: mov r3, pc 0x00008ce0 <+12>: mov r0, r3 0x00008ce4 <+16>: sub sp, r11, #0 0x00008ce8 <+20>: pop {r11} ; (ldr r11, [sp], #4) 0x00008cec <+24>: bx lr End of assembler dump.
将PC赋值给r3,然后r3在给r0,而r0是函数的返回值,PC(program point)指向的是执行语句地址+8,即0x08cdc+8=0x08ce4,所以key1是0x08ce4
key2
(gdb) disass key2 Dump of assembler code for function key2: 0x00008cf0 <+0>: push {r11} ; (str r11, [sp, #-4]!) 0x00008cf4 <+4>: add r11, sp, #0 0x00008cf8 <+8>: push {r6} ; (str r6, [sp, #-4]!) 0x00008cfc <+12>: add r6, pc, #1 0x00008d00 <+16>: bx r6 0x00008d04 <+20>: mov r3, pc 0x00008d06 <+22>: adds r3, #4 0x00008d08 <+24>: push {r3} 0x00008d0a <+26>: pop {pc} 0x00008d0c <+28>: pop {r6} ; (ldr r6, [sp], #4) 0x00008d10 <+32>: mov r0, r3 0x00008d14 <+36>: sub sp, r11, #0 0x00008d18 <+40>: pop {r11} ; (ldr r11, [sp], #4) 0x00008d1c <+44>: bx lr
先看到pc和r6相加 0x08d04+0x1,然后再bx r6变成thumb状态(根据地址的最低位确定是否状态切换。如果末尾是1则切换到thumb状态,否则保留在asm状态)
之后pc+4赋值给r3(thumb状态,pc+4,asm状态则+8) 再通过adds把r3再加0x4,通过两次相加使得r3=PC+4+4,再赋值给r0 ,
所以r0=PC+4+4=0x8d0c, 即key2=0x8d0c
key3
Dump of assembler code for function key3: 0x00008d20 <+0>: push {r11} ; (str r11, [sp, #-4]!) 0x00008d24 <+4>: add r11, sp, #0 0x00008d28 <+8>: mov r3, lr 0x00008d2c <+12>: mov r0, r3 0x00008d30 <+16>: sub sp, r11, #0 0x00008d34 <+20>: pop {r11} ; (ldr r11, [sp], #4) 0x00008d38 <+24>: bx lr
lr(link register)寄存器存储的是函数的返回地址,指向main函数,看看main函数
0x00008d7c <+64>: bl 0x8d20 <key3> 0x00008d80 <+68>: mov r3, r0
key3=0x8d80
之后相加即可
执行获取flag
My daddy has a lot of ARMv5te muscle!