高级语言程序转换SHELLCODE时编码注意

使用VC写的DLL通过内存加载类,转成SHELLCODE,发现一个诡异的问题,程序直接运行操作与下载无任何问题,下载10G数据也不会出错。

但转成SHELLCODE后,诡异的问题,就出现了,不确定时间地点,出错。

经过3个多小时,每句代码排查,找出问题原因,使用了如下代码:

UINT ProcFileEnumWillDown(TCHAR * str_path)//枚举要下载的文件夹
{
	CListDirectoryFile list;
	list.SearchFileAll(str_path);

	CMySocket sock;
	sock.m_socket=m_socket;

	for (int i=0;i<list.MyVectorFileName.size();i++)
	{
		WIN32_FIND_DATA fd={0};
		HANDLE hFind = FindFirstFile(list.MyVectorFileName[i].c_str(), &fd);

		if (hFind==INVALID_HANDLE_VALUE){
			lstrcpy(fd.cFileName,_T("Failed to access files"));//获取文件信息失败时把错误信息返给用户
		}else{
			lstrcpy(fd.cFileName,list.MyVectorFileName[i].c_str());//因为是枚举所有文件,把文件全路径复制到WIN32_FIND_DATA结构中
			FindClose(hFind);
		}

		PACKET pkt={0};//注意这里!
		CopyMemory((void*)pkt.buf,(char*)&fd,sizeof(fd));
		SendPacket(&pkt);
	}

        PACKET pkt={0};//注意这里!
	SendPacket(&pkt);

	return 1;
}

看出猫腻吗?如果是编译的EXE,板钉的没任何问题,决对靠普,但在SHELLCODE中,就出问题了,SHELLCODE中要求,禁止引用任何全局变量常量,这里编译后就会出问题了,解决方法,直接合并成一个 PACKET pkt={0}问题得到解决。

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:
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值