我试图通过改变它的EIP来破解另一个程序.有两个程序正在运行,一个是目标,它告诉作为"核心功能"的函数(例如,接收密码字符串作为参数并返回true或false的函数)在内存中.然后现在我知道核心功能在哪里我想用另一个程序修改EIP,这样目标程序就可以调用我的函数,只需从中获取一个真实的并打印出一个漂亮的"访问权限".
我的代码现在是这样的:
目标计划:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int checkPwd(char *pwd)
{
printf("\nstill in the function\n");
if(strcmp(pwd, "patrick") == 0) return true;
else return false;
}
int main()
{
char pwd[16];
printf("%d", checkPwd);
scanf("%s", &pwd);
system("pause");
if(checkPwd(pwd)) printf("Granted!\n");
else printf("Not granted\n");
system("pause");
}
Run Code Online (Sandbox Code Playgroud)
攻击者计划:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
int returnTrue()
{
return true;
}
int main()
{
int hex;
scanf("%d", &hex);
memcpy((void*)hex, (void*)returnTrue, sizeof(char)*8);
system("pause");
}
Run Code Online (Sandbox Code Playgroud)
我想补充一点,我试图直接将十六进制代码(没有scanf部分)放入攻击者程序中并且不起作用,它崩溃了.
所以我觉得我在这里错过了理论的某些部分.我很高兴知道它是什么.
提前致谢.
这不起作用 - 进程占用不同的内存空间!
现代操作系统旨在保护用户程序免受此类攻击.一个进程无法访问另一个进程的内存 - 实际上,数据地址仅在该进程内有效.
程序运行时,它有自己的内存视图,只能"看到"内核指示内存管理单元(MMU)为其映射的内存.
一些参考: