#!/usr/bin/perl ################################################################ # Rootsecure.net # # ----------------------- # # Chatbot coded from a tutorial at # # http://b0iler.eyeonsecurity.org/tutorials/ircperlbot.htm # # # # Note: To use this script you also need a phrase list, a demo # # file is available from: # # http://www.rootsecure.net/content/downloads/perl_scripts/irc_chat_bot_text.txt # # # Please also note that the opinions of this bot may not # # necessarily represent those of Rootsecure.net # ################################################################ $irc_server='irc.esper.net'; $irc_channel='#cooldude'; $irc_name='cooldude'; $bot_text_file='irc_chat_bot_text.txt'; ## Open bot speech file &open_bot_speech; sub open_bot_speech { open(DAT, $bot_text_file) || die("Could not open $bot_text_file file!"); @bot_speech_data_file=; close(DAT); } # end sub open_bot_speech ## Clear screen system ('clear'); # clear screen on windows system ('cls'); # clear screen on *nix $last_message_time = '0'; ##Begin communications use IO::Socket; $sock = IO::Socket::INET->new( PeerAddr => "$irc_server", PeerPort => 7000, Proto => 'tcp' ) or die "could not make the connection"; while($line = <$sock>){ print $line; if(($line =~ /(NOTICE AUTH).*(checking ident)/i) || ($line =~ /Found your hostname/i)){ print $sock "NICK $irc_name\nUSER bot 0 0 :just a bot\n"; last; } } while($line = <$sock>){ print $line; #use next line if the server asks for a ping if($line =~ /^PING/){ print $sock "PONG :" . (split(/ :/, $line))[1]; } if($line =~ /(376|422)/i){ print $sock "NICKSERV :identify nick_password\n"; last; } } sleep 3; print $sock "JOIN $irc_channel\n"; sleep(2); print $sock "PRIVMSG $irc_channel :hey\n"; while ($line = <$sock>) { ($command, $text) = split(/ :/, $line); #$text is the stuff from the ping or the text from the server if ($command eq 'PING'){ #while there is a line break - many different ways to do this while ( (index($text,"\r") >= 0) || (index($text,"\n") >= 0) ){ chop($text); } print $sock "PONG $text\n"; next; } #done with ping handling ($nick,$type,$channel) = split(/ /, $line); #split by spaces ($nick,$hostname) = split(/!/, $nick); #split by ! to get nick and hostname seperate $nick =~ s/://; #remove :'s $text =~ s/://; #get rid of all line breaks. Again, many different way of doing this. $/ = "\r\n"; while($text =~ m#$/$#){ chomp($text); } if ($type =~ /JOIN/gi){ unless ($nick =~ /$irc_name/gi) { sleep (3); print $sock "PRIVMSG $irc_channel :yo yo, greetz to $nick\n"; print "<$irc_name> yo yo, greetz to $nick\n"; $bot_responce = "<$irc_name> yo yo, greetz to $nick\n"; } } if (($type =~ /PART/gi) || ($type =~ /QUIT/gi)){ sleep (3); print $sock "PRIVMSG $irc_channel :$nick has left the building\n"; print "<$irc_name> $nick has left the building\n"; $bot_responce = "<$irc_name> $nick has left the building\n"; } if($channel eq $irc_channel){ print "<$nick> $text\n"; &bot_speech; if ($text =~ /hello/gi){ sleep (2); print $sock "PRIVMSG $irc_channel :hi there $nick\n"; print "<$irc_name> hi there $nick\n"; $bot_responce = "<$irc_name> hi there $nick\n"; } if ($text =~ /say/gi){ $text =~ s/say //g; print $sock "PRIVMSG $irc_channel :$text\n"; print "<$irc_name> $text\n"; $bot_responce = "<$irc_name> $text\n"; } } if($channel eq $irc_name){ print "<$nick> $text\n"; if($text =~ /hello/gi){ print $sock "PRIVMSG $nick :hi there _EOF\n"; print " PRIVMSG $nick :sorry, i dont do private chats _EOF\n"; } if($text =~ /admin/gi){ print $sock "mode $irc_channel +o $nick\n"; print " Make $nick channel op\n"; } if($text =~ /change_nick/gi){ ($command,$command_var) = split(/ /, $text); #split by spaces print $sock "nick $command_var\n"; print " Change nick to $command_var\n"; $irc_name = $command_var; } if($text =~ /say/gi){ ($command,$command_var) = split(/=/, $text); #split by spaces print $sock "PRIVMSG $irc_channel :$command_var\n"; print "<$irc_name> $command_var\n"; $bot_responce = "<$irc_name> $command_var\n"; } if ($text =~ /admin kill $irc_name/gi){ print $sock "quit :killed by $nick\n"; print " quit :killed by $nick\n"; $bot_responce = "<$irc_name> quit :killed by $nick\n"; } } open(DAT,">>irc_log-$irc_server.txt") || die("Could not open irc_log-$irc_server.txt file!"); print DAT "$line"; print DAT "\n$bot_responce"; close(DAT); } sub bot_speech { foreach $split_line (@bot_speech_data_file) { &date_time; $split_line =~ s/\$DATE/$date1/g; $split_line =~ s/\$TIME/$time/g; $split_line =~ s/\n//g; $split_line =~ s/\r//g; ($hear,$say)=split(/\|/,$split_line); @count=split(//,$say); $count = @count; &if_have_responce; } } # end sub bot_speech sub if_have_responce { if ($text =~ /$hear/gi) { unless ($last_message_time eq localtime(time)) { $count = $count / 3; if ($count <= 1) {$count++;} sleep ($count); print $sock "PRIVMSG $irc_channel :$say\n"; print "<$irc_name> $say\n"; $bot_responce = "<$irc_name> $say\n"; $last_message_time = localtime(time); } } } # end sub if_have_responce sub date_time { @Days = ( 'Sunday','Monday','Tuesday','Wednesday', 'Thursday','Friday','Saturday' ); @days = ( 'Sun','Mon','Tue','Wed','Thu','Fri','Sat' ); @MONTHS = ( 'January','February','March','April', 'May','June','July','August', 'September','October','November','December' ); @Months = ( 'Jan','Feb','Mar','Apr','May','June', 'July','Aug','Sep','Oct','Nov','Dec' ); @months = ( '01','02','03','04','05','06', '07','08','09','10','11','12' ); ( $s,$m,$h,$mday,$mon,$year,$wday,$yday,$isdst ) = localtime( time ); if( $hour < 10 ) { $hour = "0$hour" } if( $min < 10 ) { $min = "0$min" } if( $sec < 10 ) { $sec = "0$sec" } if( $mday < 10 ) { $mday = "0$mday" } $year = substr( $year,1,2 ); $Year = "20$year"; $date1 = "$Days[ $wday ], $MONTHS[ $mon ] $mday, $Year"; $date2 = "$Months[ $mon ] $mday, $Year"; $date3 = "$months[ $mon ]/$mday/$year"; $local = localtime( time ); ($null,$null,$null,$time) = split(/ /, $local); #split by spaces # $date1 [Monday, September 06, 1999] # $date2 [Sep 06, 1999] # $date3 [09/06/99] # $local [Wed Sep 15 13:51:49 1999] } # end sub date_time