shellcode——1、采用硬编码弹出计算器

一、shellcode的介绍

    用一句话给的shellcode的下个定义,那就是“一段可以执行特定功能的机器码”。

二、实验环境及工具介绍

实验环境:Windows XP SP3

实验工具:OllyDbg、WinHex、LordPE

三、编程思路

     用c语言来描述其实就是两句:

WinExec("calc.exe", 5);
ExitProcess(0);
    看到有些文章会在开头还加一句:
LoadLibrary(“kernel32.dll”);
    看不懂为啥要加这一句,因为大部分软件都会加载kernel32.dll这个的DLL,更何况LoadLibrary()本来就是在kernel32.dll中的。。。


四、确定被调用函数的虚拟地址

    因为这次是用的是硬编码的方式,所以需要通过查找kernel32.dll的导出表,来确定的的WinExec()和ExitProcess()的虚拟地址。使用LordPE加载kernel32.dll,在导出表中查找这两个函数得出两个函数的RVA(相对虚拟地址)为别为:0x000623AD和0x0001CAFA。

    当然,光有RVA是不够的,还需要知道基址,即0x7C800000。


    所以计算得出了ExitProcess()的地址为0x7C81CAFA,WinExec()的地址为0x7C8623AD。

五、编写汇编代码

int main()
{
	__asm
	{
		push ebp
		mov ebp,esp
		//WinExec("calc.exe", 5)
		xor eax,eax						//eax清0
		push eax						//“0x00”,用于分割字符串
		mov eax,0x6578652e				        //".exe"
		push eax
		mov eax,0x636c6163				        //"calc"
		push eax
		mov eax,esp
		push 5							//arg2=SW_SHOW
		push eax						//arg1="calc.exe"
		mov eax,0x7c8623ad				        //WinExec的地址
		call eax
		//ExitProcess(0)
		xor eax,eax
		push eax						//arg1=0
		mov eax,0x7c81cafa				        //ExitProcess的地址
		call eax			

		mov esp,ebp
		pop ebp
	}
	return 0;
}

测试结果:



六、提取机器码

    用OD加载程序,二进制复制,再粘贴到的的WinHex中。


提取机器码,并测试:

unsigned char shellcode[]=
"/x55/x8B/xEC/x33"
"/xC0/x50/xB8/x2E"
"/x65/x78/x65/x50"
"/xB8/x63/x61/x6C"
"/x63/x50/x8B/xC4"
"/x6A/x05/x50/xB8"
"/xAD/x23/x86/x7C"
"/xFF/xD0/x33/xC0"
"/x50/xB8/xFA/xCA"
"/x81/x7C/xFF/xD0"
"/x8B/xE5/x5D/x33";

int main()
{
	__asm
	{
		lea eax,shellcode
		call eax
	}
	return 0;
}


至此,一段用硬编码的shellcode的就完成了(@ _ @)!

参考链接:https://www.cnblogs.com/toorist/p/4428340.html



Shellcode Helper v1.62 Coded by TeLeMan (c) 2008-2013 Usage: schelper.exe [options] Options: -i [input file] input file (Default: stdin) -o [output file] output file (Default: stdout) -s input file format (Default: Auto-Detection) -sb input file format is Binary -sp the input file format's parameters -d output file format (Default: C format) -db output file format is Binary -dp the output file format's parameters -search get the start offset by the pattern: e.g. PK\x03\x04 -soff fix the match offset after searching (Default: 0) -off convert the input file from the offset (Default: 0) -len convert the input file with the length (Default: 0 - MAX) -en [encoder] encode shellcode (Default: XorDword) -de [encoder] decode shellcode (Default: Auto-Detection) -ex exclude characters: e.g. 0x00,0x01-0x1F,0xFF (Default: 0x00) -in incude characters only -ep the encoder's parameters -t [pid] execute or inject shellcode into process for testing -td [pid] execute or inject shellcode into process for debugging -stack put shellcode into stack and execute it (ESP is the shellcode start) -noinfo display no normal messages except error messages Available formats: 0 - C 1 - C(HexArray) 2 - Perl 3 - Python 4 - Ruby 5 - JavaScript(Escape) 6 - VBScript(Escape) 7 - Pascal 8 - MASM(Data) 9 - HexDump 10 - BitString 11 - HexString 12 - HexArray(C like) 13 - Base64 14 - Binary 15 - HexString(C like) 16 - HexString(Escape) 17 - HexString(JavaScript,UNICODE) 18 - URI(ISO-8859-1) 19 - XML(PCDATA) 20 - BigNumber 21 - BigNumber(Hex) 22 - BigNumber(BaseX) 23 - FloatPoint 24 - UnixTimestamp 25 - GUID 26 - MASM(ASM) 27 - NASM 28 - YASM(ASM) 29 - FASM(ASM) 30 - JWASM(ASM) 31 - POASM(ASM) 32 - GOASM(ASM) 33 - GNU ASM Available encoders:
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值