话说,这第二颗确实比第一颗难度大很多,我按照上面的思路,被炸得体无完肤~~!
后来发现这个并不是像上面一样的固定的密码
这里是main函数反汇编得到的

程序代码:
0x08048a8b <+199>: call 0x8049363 <read_line>
0x08048a90 <+204>: mov %eax,(%esp)
0x08048a93 <+207>: call 0x8048d1c <phase_2>
0x08048a98 <+212>: call 0x80491c1 <phase_defused>
0x08048a9d <+217>: movl $0x8049783,(%esp)
即将断点设在phase_2上
重新运行
发现要先输入才能运行到断点处
随便输入什么比如1 2 3 4 5 6吧
所以这个 0x08048a8b <+199>:call 0x8049363 <read_line>
一定是得到密码的函数,并且 他这么急着保存,很有可能刚输入的就在eax里

程序代码:
(gdb) info reg
eax 0x804a870
……
(gdb) x/1sb 0x804a870
0x804a870 <input_strings+80>: "1 2 3 4 5 6"
果然就在这里,所以,就先不看read_line了
然后disas phase_2

程序代码:
(gdb) disas phase_2
Dump of assembler code for function phase_2:
0x08048d1c <+0>: push %ebp
0x08048d1d <+1>: mov %esp,%ebp
0x08048d1f <+3>: push %esi
0x08048d20 <+4>: push %ebx
0x08048d21 <+5>: sub $0x30,%esp
0x08048d24 <+8>: lea -0x20(%ebp),%eax
0x08048d27 <+11>: mov %eax,0x4(%esp)
0x08048d2b <+15>: mov 0x8(%ebp),%eax
0x08048d2e <+18>: mov %eax,(%esp)
0x08048d31 <+21>: call 0x8049295 <read_six_numbers>
0x08048d36 <+26>: cmpl $0x1,-0x20(%ebp)
0x08048d3a <+30>: je 0x8048d41 <phase_2+37>
0x08048d3c <+32>: call 0x8049253 <explode_bomb>
0x08048d41 <+37>: mov $0x2,%ebx
0x08048d46 <+42>: lea -0x20(%ebp),%esi
0x08048d49 <+45>: mov %ebx,%eax
0x08048d4b <+47>: imul -0x8(%esi,%ebx,4),%eax
0x08048d50 <+52>: cmp %eax,-0x4(%esi,%ebx,4)
0x08048d54 <+56>: je 0x8048d5b <phase_2+63>
0x08048d56 <+58>: call 0x8049253 <explode_bomb>
0x08048d5b <+63>: add $0x1,%ebx
0x08048d5e <+66>: cmp $0x7,%ebx
0x08048d61 <+69>: jne 0x8048d49 <phase_2+45>
0x08048d63 <+71>: add $0x30,%esp
0x08048d66 <+74>: pop %ebx
0x08048d67 <+75>: pop %esi
0x08048d68 <+76>: pop %ebp
0x08048d69 <+77>: ret
这段代码
eax给了esp后就调用函数read_six_numbers
所以再disas read_six_numbers
得

程序代码:
gdb) disas read_six_numbers
Dump of assembler code for function read_six_numbers:
0x08049295 <+0>: push %ebp
0x08049296 <+1>: mov %esp,%ebp
0x08049298 <+3>: sub $0x28,%esp
0x0804929b <+6>: mov 0xc(%ebp),%edx
0x0804929e <+9>: lea 0x14(%edx),%eax
0x080492a1 <+12>: mov %eax,0x1c(%esp)
0x080492a5 <+16>: lea 0x10(%edx),%eax
0x080492a8 <+19>: mov %eax,0x18(%esp)
0x080492ac <+23>: lea 0xc(%edx),%eax
0x080492af <+26>: mov %eax,0x14(%esp)
0x080492b3 <+30>: lea 0x8(%edx),%eax
0x080492b6 <+33>: mov %eax,0x10(%esp)
0x080492ba <+37>: lea 0x4(%edx),%eax
0x080492bd <+40>: mov %eax,0xc(%esp)
0x080492c1 <+44>: mov %edx,0x8(%esp)
0x080492c5 <+48>: movl $0x8049aca,0x4(%esp)
0x080492cd <+56>: mov 0x8(%ebp),%eax
0x080492d0 <+59>: mov %eax,(%esp)
0x080492d3 <+62>: call 0x80488b4 <sscanf@plt>
0x080492d8 <+67>: cmp $0x5,%eax
0x080492db <+70>: jg 0x80492e2 <read_six_numbers+77>
0x080492dd <+72>: call 0x8049253 <explode_bomb>
0x080492e2 <+77>: leave
0x080492e3 <+78>: ret
End of assembler dump.
在这里

程序代码:
0x0804929b <+6>: mov 0xc(%ebp),%edx
0x0804929e <+9>: lea 0x14(%edx),%eax
0x080492a1 <+12>: mov %eax,0x1c(%esp)
0x080492a5 <+16>: lea 0x10(%edx),%eax
0x080492a8 <+19>: mov %eax,0x18(%esp)
0x080492ac <+23>: lea 0xc(%edx),%eax
0x080492af <+26>: mov %eax,0x14(%esp)
0x080492b3 <+30>: lea 0x8(%edx),%eax
0x080492b6 <+33>: mov %eax,0x10(%esp)
0x080492ba <+37>: lea 0x4(%edx),%eax
0x080492bd <+40>: mov %eax,0xc(%esp)
0x080492c1 <+44>: mov %edx,0x8(%esp)
这一段,我觉得不光是复制,还有一个作用就是把字符串转换成了数字恩,
然后对齐了数据以便后面使用,
ps:光着一段数据的对齐,我算了1个小时~~!
这第二颗炸弹的关键就是后面了
0x08048d36 <+26>: cmpl $0x1,-0x20(%ebp)
0x08048d3a <+30>: je 0x8048d41 <phase_2+37>[\code]
说明第一个密码是1,不解释

程序代码:
0x08048d41 <+37>: mov $0x2,%ebx
0x08048d46 <+42>: lea -0x20(%ebp),%esi
0x08048d49 <+45>: mov %ebx,%eax
0x08048d4b <+47>: imul -0x8(%esi,%ebx,4),%eax
0x08048d50 <+52>: cmp %eax,-0x4(%esi,%ebx,4)
0x08048d54 <+56>: je 0x8048d5b <phase_2+63>
伪代码表示:
(ebx)=2
esi=ebp-20
(eax)=(ebx)
(eax)=(eax)*((ebx)*4+esi-8)=2
if(-0x4(%esi,%ebx,4)!=2)
exit
计算-0x4(%esi,%ebx,4)实际是esi+4
也就是ebp-0x1c
就是刚对齐的第二个数据
所以第二个密码是2
再往下ebx当计数器,在exb<7时循环
自己算咯
所以第二个炸弹的密码分别是
1 2 2*3 6*4 24*5 120*6 也就是
1 2 6 24 120 720
---------------------------------

程序代码:
Welcome to my fiendish little bomb. You have 6 phases with
which to blow yourself up. Have a nice day!
I am not part of the problem. I am a Republican.
Phase 1 defused. How about the next one?
1 2 6 24 120 720
That's number 2. Keep going!
[
本帖最后由 wog 于 2011-4-12 23:13 编辑 ]