Home键(小房子键)

2014-11-24 01:07:57 · 作者: · 浏览: 3

核心思想:objdump -d 找到关键汇编代码,然后用ghex2 打开可执行程序,修改和汇编对应的机器码,当然前提是对汇编足够了解。

下面讲一个简单在linux上的例子:

1. 先建立一个简单的程序,


[cpp]
#include
using namespace std;

bool abc(){
return false;
}

int main(int argc, char *argv[])
{
if(abc()){
cout << "hacked" << endl;
}else{
cout << "not hacked" << endl;
}
return 0;
}

#include
using namespace std;

bool abc(){
return false;
}

int main(int argc, char *argv[])
{
if(abc()){
cout << "hacked" << endl;
}else{
cout << "not hacked" << endl;
}
return 0;
}
2. 用g++ main.cpp编译成可执行程序a.out,

3. 运行./a.out 输出:

not hacked

4. 调用 objdump -d a.out > simple.txt

5. 在simple.txt中搜索abc,找到如下代码


[cpp]
080486f4 <_Z3abcv>:
80486f4: 55 push %ebp
80486f5: 89 e5 mov %esp,%ebp
80486f7: b8 00 00 00 00 mov $0x0,%eax
80486fc: 5d pop %ebp
80486fd: c3 ret

080486f4 <_Z3abcv>:
80486f4: 55 push %ebp
80486f5: 89 e5 mov %esp,%ebp
80486f7: b8 00 00 00 00 mov $0x0,%eax
80486fc: 5d pop %ebp
80486fd: c3 ret 6. 然后用ghex2打开a.out, 搜 55 89 e5 b8 00 00 00 00, 找到这段汇编对应的机器码的位置,

7. 最后到了关键一步, 把上面的一段机器码改成 55 89 e5 b8 01 00 00 00, 其实只改了一个字,意思是把返回false改成返回true。

8. 再次运行./a.out 输出: hacked。大功告成。