首页
社区
课程
招聘
[求助]一个seh问题
发表于: 2016-6-3 11:01 6392

[求助]一个seh问题

2016-6-3 11:01
6392
问题的代码在注释的地方:
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>

typedef struct _EXCEPTION_REGISTRATION_RECORD
{
	_EXCEPTION_REGISTRATION_RECORD *next;
	PVOID  handle;

}EXCEPTION_REGISTRATION_RECORD, *PEXCEPTION_REGISTRATION_RECORD;

int  *a = NULL;
int b;

EXCEPTION_DISPOSITION  __cdecl ExceptionHandle(EXCEPTION_RECORD *pRecord,
	EXCEPTION_REGISTRATION_RECORD *pFram,
	CONTEXT *pContext,
	PVOID pValue)
{
	DWORD dwThreadID = GetCurrentThreadId();
	printf("except:%X\n", dwThreadID);
	printf("exception code:%X, exception addr:%X, eip:%X\n", pRecord->ExceptionCode, pRecord->ExceptionAddress, pContext->Eip);
	pContext->Eax = (DWORD)&b;
	return ExceptionContinueExecution;
}

int _tmain(int argc, _TCHAR* argv[])
{
	__asm
	{
		push ExceptionHandle
		push  fs:[0]
		mov  fs:[0], esp
	}
	DWORD dwThreadID = GetCurrentThreadId();
	printf("normal:%X\n", dwThreadID);
	__asm
	{
		push eax
		mov eax, a
		mov [eax], 10
		pop eax
	}
	__asm
	{
		/*
		mov eax, [esp]
		mov fs:[0], eax
		add esp, 4
		add esp, 4
		*/
		pop fs:[0]
		add esp,4
		
	}
	
	printf("after, b:%d\n", b);
	EXCEPTION_ILLEGAL_INSTRUCTION;
	MessageBox(NULL, _T("end"), _T("alert"), 0);
	return 0;
}


问题描述:
1. 如果使用
    pop fs:[0]
    add esp,4
   就会出现无限次跳入ExceptionHandle中
2. 如果使用
     mov eax, [esp]
     mov fs:[0], eax
     add esp, 4
     add esp, 4
  只进入ExceptionHandle中一次,然后正常返回
3. 我研究了下两端代码是等效的啊
ps:
1. 我的编译环境是vs2010 运行环境xpsp3
2. 在vs2010链接选项中增加 /SAFESEH:NO

[课程]Linux pwn 探索篇!

收藏
免费 0
支持
分享
最新回复 (4)
雪    币: 878
活跃值: (496)
能力值: ( LV3,RANK:20 )
在线值:
发帖
回帖
粉丝
2
两段代码并不等效, 后者eax也改变了
2016-6-3 12:59
0
雪    币: 96
活跃值: (36)
能力值: ( LV4,RANK:50 )
在线值:
发帖
回帖
粉丝
3
这段代码主要任务是恢复seh链,从这个角度上了?
2016-6-3 14:24
0
雪    币: 24
活跃值: (102)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
4
pop fs:[0]
add esp, 2
add esp, 4
2016-6-3 15:27
0
雪    币: 96
活跃值: (36)
能力值: ( LV4,RANK:50 )
在线值:
发帖
回帖
粉丝
5
[QUOTE=wulumuqi;1432253]pop fs:[0]
add esp, 2
add esp, 4[/QUOTE]
谢谢哥们,此贴终结!
刚才用od调试了一下,pop fs:[0],实际上esp是加2而不是加4
2016-6-4 00:14
0
游客
登录 | 注册 方可回帖
返回
//