注入动态库,穷举。。。
到最后,发现绕了挺远,得有一小天吧;
代码如下:
#include <Windows.h>
#include <stdio.h>
/*
* 结构大致是这样,这里除了清0没别的用,不清可能也可以,但没验证。。。
*/
typedef struct _context
{
unsigned int *func;
int index;
int array_1[1024];
int array_2[1024];
int a;
int b;
}context;
/*
* 回来发现电脑自动重启了...,记得走之前就是 *****4xx 左右,回来改成了 99999411
*/
void input(context *ctx, char *x)
{
char test[] = "123456789";
static int i1 = 8;
static int i2 = 8;
static int i3 = 8;
static int i4 = 8;
static int i5 = 8;
static int i6 = 3;
static int i7 = 0;
static int i8 = 0;
memset(ctx, 0, sizeof(context));
sprintf(x, "%c%c%c%c%c%c%c%c",
test[i1],
test[i2],
test[i3],
test[i4],
test[i5],
test[i6],
test[i7],
test[i8]);
if (i1 < 8)
{
i1++;
}
else
{
i1 = 0;
if (i2 < 8)
{
i2++;
}
else
{
i2 = 0;
if (i3 < 8)
{
i3++;
}
else
{
i3 = 0;
if (i4 < 8)
{
i4++;
}
else
{
i4 = 0;
if (i5 < 8)
{
i5++;
}
else
{
i5 = 0;
if (i6 < 8)
{
i6++;
}
else
{
i6 = 0;
if (i7 < 8)
{
i7++;
}
else
{
i7 = 0;
if (i8 < 8)
{
i8++;
}
else
{
i8 = 0;
printf("---the end---\n");
}
}
}
}
}
}
}
}
}
/*
* 用于修改原程序,执行一次过后调用动态库中代码,重新生成key,重新执行 ,硬编码
*/
unsigned char shell_code1[] = {
0x8d, 0x4c, 0x24, 0x08, // lea ecx, [esp+8]
0x51, // push ecx
0x8d, 0x8c, 0x24, 0x10, 0x01, 0x00, 0x00, // lea ecx, [esp+110]
0x51, // push ecx
0xe8, 0x00, 0x00, 0x00, 0x00, // call input
0x83, 0xc4, 0x08, // add esp,8
0xe9, 0x61, 0xfe, 0xff, 0xff // jmp 4010ac
};
/*
* 动态库入口 调用
*/
void func()
{
DWORD written = 0;
*((DWORD*)&shell_code1[14]) = (DWORD)input - 0x40123e - 5;
BOOL bRet = WriteProcessMemory(INVALID_HANDLE_VALUE, (LPVOID)0x401231, shell_code1,
sizeof(shell_code1), &written);
if (bRet == FALSE)
{
printf("---error:%d---\n", GetLastError());
getchar();
}
执行成功处断点,最终如下:
这个也能穷举出来,,,运气好了点。
[CTF入门培训]顶尖高校博士及硕士团队亲授《30小时教你玩转CTF》,视频+靶场+题目!助力进入CTF世界