thunk示例代码

了解了一下thunk,怎么感觉好像写shellcode,但觉得比较好玩,自己也写了一个示例程序,跟实际的thunk有点区别,供自己参考


#include <windows.h>
#include <TCHAR.h>
#include <iostream>
#pragma pack(push,1) 

struct Thunk
{
	BYTE    m_nop;

	BYTE	m_push; DWORD   m_fun;

	BYTE	m_push4; DWORD   m_arg4;
	BYTE	m_push3; DWORD   m_arg3;
	BYTE	m_push2; DWORD   m_arg2;
	BYTE	m_push1; DWORD   m_arg1;   

    DWORD    m_call;
	DWORD	 m_ret;

    BOOL Init(HWND hWnd , LPCTSTR lpText, LPCTSTR lpCaption, UINT uType)  
    { 
		m_nop = 0x90; // nop;

		m_push = 0x68; m_fun = PtrToUlong(::MessageBox);// push m_fun;

		m_push1 = 0x68; m_arg1 = HandleToUlong(hWnd);// push m_arg1;
		m_push2 = 0x68; m_arg2 = PtrToUlong(lpText);// push m_arg2;
		m_push3 = 0x68; m_arg3 = PtrToUlong(lpCaption);// push m_arg3;
		m_push4 = 0x68; m_arg4 = uType;// push m_arg4;
		
		m_call = 0x102454ff;// call [esp+10h];
		
		m_ret =  0xc304c483;// add esp,4; ret;

		::FlushInstructionCache(::GetCurrentProcess(), this, sizeof(Thunk)); 
        return TRUE;   
    }   
}; 

#pragma pack(pop)
 


void main()
{
    Thunk thunk;
	void (*MsgBox)() = (void(*)())(&thunk);
    thunk.Init(NULL, _T("hello world"), _T("YSHE"), MB_OK);
    MsgBox(); //((void(*)())(&thunk))();
	std::cout<< "this is thunk test" <<std::endl;
}


  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值