Government Security
Network Security Resources

Jump to content

Photo

Irc Bot In Perl


  • Please log in to reply
52 replies to this topic

#31 NapAiM

NapAiM

    Private

  • Members
  • 12 posts

Posted 19 December 2006 - 02:44 PM

I think i shall use that version instead of the script,
I edit it quite heavily, you might take some ideas from it, its not all working yet, was going through each module at a time and revamping some of the main parts, I was going to make it use strict but haven't got round to that yet.
Here it is anyway:

Edit: Its all working now

#!/usr/bin/perl

	$server	=	'squareownz.homeip.net';
	$port	=	6667;
	$nick	=	'Sara';
	$ident	=	'Sara';
	$realname =	'Sara';
	$chan	=	'#so';
	$pass	=	'password';
	$su		=	'Napalm';
	$owners	=	'Napalm';
	$owner_m=	'Napalm!Snake@G-232588F4';
	$p		=	'!';

use IO::Socket;

$irc=IO::Socket::INET->new(
		PeerAddr=>$server,
		PeerPort=>$port,
		Proto=>'tcp') || die "Could not connect!";
		
		print "PerlBot by netcomm\n";
		print "$nick has connected to $server on $chan\n";
		print $irc "USER $ident $ident $ident $ident :$realname\r\n";
		print $irc "NICK $nick\r\n";
		print $irc "PRIVMSG :NickServ :identify $pass\n";
		print $irc "JOIN $chan\n";
		print $irc "PRIVMSG $owners :$nick is online\n";

		while(defined($in=<$irc>)){

if ($in =~ /^PING\s:(.+)/) { print $irc "PONG :$1\r\n"; }
if ($in =~ /^:(.+)\!.+ JOIN\b/)
{
	print $irc "PRIVMSG $1 :hello $1 welcome to $chan\n";
}
$in =~ s/^\s://;
@splin = split(/:/, $in);
print @splin;

	karma($splin[2]) if $splin[2] =~ /^!karma/;
	info() if $splin[2] =~ /^!info/;
	pcrypt($splin[2], $splin[3]) if $splin[2] =~ /^!crypt/;

next unless $in =~ /^:$owners\b/;
next unless $in =~ /^:$owner_m\b/;

	rehash() if $splin[2] =~ /^!rehash/;
	raw($splin[2]) if $splin[2] =~ /^!raw/;
	say($splin[2]) if $splin[2] =~ /^!say/;
	op($splin[2]) if $splin[2] =~ /^!op/;
	deop($splin[2]) if $splin[2] =~ /^!deop/;
	quit() if $splin[2] =~ /^!quit/;
	packet($splin[2]) if $splin[2] =~ /^!packet/;
	#pastebot();

sub rehash {
	print $irc "PRIVMSG $chan :Rehashing...\n";
	print $irc "QUIT\n";
	system("bot.pl");
	print $irc "join $chan";
}

sub info 
{	
	print $irc "PRIVMSG $chan :Napalm's Pet\n";
}

sub op
{
	$_ = substr $_[0], 3;
	$_ =~ s/\s//;
	print $irc "MODE $chan +o $_\n";
}

sub deop
{
	$_ = substr $_[0], 5;
	$_ =~ s/\s//;
	print $irc "MODE $chan -o $_\n";
}
			  
sub raw 
{
	$_ = substr $_[0], 4;
	$_ =~ s/\s//;
	print $irc "$_\r\n";
}


sub say 
{ 
	$_ = substr $_[0], 4;
	$_ =~ s/\s//;
	print $irc "PRIVMSG $chan :$_\r\n";
}

sub quit 
{
	print $irc "PRIVMSG $chan :Love ya!\r\n";
	print $irc "QUIT\r\n";
}

sub pcrypt 
{
	$_[0] =~ s/\s//g;
	$_[0] = substr $_[0], 6, 8;
	$_[1] =~ s/\s//g;
	$_[1] = substr $_[1], 0, 2;
	my $cryptstr = crypt($_[0], $_[1]);
	print $irc "PRIVMSG $chan :Perl crypted string: $cryptstr = $_[0] and $_[1]\r\n";
}

my %karma = ();
sub karma 
{	
	$in =~ s/\s//g;
	$_ = split(/:/,$in);
	$_[2] = substr $_[2], 6;

	if ($_[3] eq "")
	{
		print $irc "PRIVMSG $chan :Karma with $_[2] is $karma->{$_[2]}. \r\n";
	} elsif ($_[2] eq "")
	{
		print $irc "PRIVMSG $chan :Karma with $_ is $karma->{$_[2]}. \r\n";
	}
	else
	{
		if ($in =~ /$owner_m/)
		{
			$karma->{$_[2]} = $_[3];
			print $irc "PRIVMSG $chan :Upgraded Karma with $_[2]. Is now: $karma->{$_[2]} \r\n";
		} else {print $irc "PRIVMSG $chan :NO\r\n";}
	}
}

sub packet
{
	$_ = substr $_[0], 7;
	$_ =~ s/\s//g;
	print $irc "PRIVMSG $chan :Sending... $_\r\n";
	system ("ping -l 65500 -n 5 $_");
	print $irc "PRIVMSG $chan :Complete.\r\n";
}

}
close($irc);
1;


#32 netcomm

netcomm

    Specialist

  • Members
  • 121 posts

Posted 19 January 2007 - 07:22 PM

Hmm not much different there.
It is much better now with the plug-in's
saves having to rehash and reconnect when wirinting new stuff in.


where are your sub calls?

#33 NapAiM

NapAiM

    Private

  • Members
  • 12 posts

Posted 24 January 2007 - 09:50 AM

yeah, heh its pretty much the same only the Module one was down, theese is the sub calls:
rehash() if $splin[2] =~ /^!rehash/;
	raw($splin[2]) if $splin[2] =~ /^!raw/;
	say($splin[2]) if $splin[2] =~ /^!say/;
	op($splin[2]) if $splin[2] =~ /^!op/;
	deop($splin[2]) if $splin[2] =~ /^!deop/;
	quit() if $splin[2] =~ /^!quit/;
	packet($splin[2]) if $splin[2] =~ /^!packet/;

quite a mess ^^

#34 Curse

Curse

    Private

  • Members
  • 1 posts

Posted 17 March 2007 - 02:02 PM

this thing dont work on a freebsd system and its a nice tool, could this be fixed so i can use it?

#35 Ryan M

Ryan M

    First Sergeant

  • Second Lieutenant
  • 1,740 posts

Posted 17 March 2007 - 10:03 PM

this thing dont work on a freebsd system and its a nice tool, could this be fixed so i can use it?


Sure it can, just grab yourself a PERL manual, or google for some PERL refrences :) The best thing to do when it comes to bots is..if you don't know how to use it, then don't. Bots can have some good uses, but a lot of times they're used for DDoS attacks. That's the best help I can offer. As far as use on your freebsd system, make sure the path to your PERL directory is acurate.
There is no security on this earth. Only opportunity.
-Douglas MacArthur

GSO Compiled Exploit Database
----------------------------------------
[b]Mod at GovernmentSecurity

#36 KSURi

KSURi

    Private

  • Members
  • 12 posts

Posted 29 March 2007 - 05:22 AM

There are some functions, i think, which should be added to this bot.
I'll PM you my source, look through it, i hope it'll be helpfull.
# perl -MHuman -e "my $self=new Human||die"
Died at -e line 1
#

#37 netcomm

netcomm

    Specialist

  • Members
  • 121 posts

Posted 19 November 2007 - 07:59 PM

Just thought i would spark up this post to see if anyone is hosting the bot as i don't have a current copy and would like to start dev again.

#38 ADX

ADX

    Private

  • Members
  • 7 posts

Posted 09 December 2007 - 01:19 AM

is there any reason y i get this error ?


NOTICE AUTH :*** Looking up your hostname...

NOTICE AUTH :*** Checking Ident

NOTICE AUTH :*** Found your hostname

NOTICE AUTH :*** No Ident response

PING :82D9AF38

:irc.servercentral.net 451 * :You have not registered


I have the same problem and i fownd this

Format: 513 If you can't connect, type /QUOTE PONG <code> or /PONG <code>
Example: 513 If you can't connect, type /QUOTE PONG 1706545232 or /PONG 1706545232
Network: OzOrg Parameters:
<code> The PING code that you are to reply with. Info:
This is sent on connect on some servers. Notes:
Most clients (including mIRC) automatically handle the PING PONG required to signon to servers. If a client does not support this, this message is intended to help the user connect. Variations:
This (or a similar raw or notice) may be used on other networks as well.

if u have some line for this pls give it

#39 netcomm

netcomm

    Specialist

  • Members
  • 121 posts

Posted 09 December 2007 - 08:53 PM

Before
print $irc "USER $ident $ident $ident $ident :$realname\n"; in bot.pl
try somthing like

[codebox]if($irc=~/^ping : (.+)$/)
{
$1 = $pong;
print $irc "PONG :$pong\n";
}[/codebox]

I must have only tested in on servers that don't require a pong at the start... let me know if it works.

#40 ADX

ADX

    Private

  • Members
  • 7 posts

Posted 10 December 2007 - 06:22 AM

Before
print $irc "USER $ident $ident $ident $ident :$realname\n"; in bot.pl
try somthing like

if($irc=~/^ping : (.+)$/){$1 = $pong;print $irc "PONG :$pong\n";}

I must have only tested in on servers that don't require a pong at the start... let me know if it works.


Nope...
and at the end...
PING :1353105991

:server.org 451 SPK SPK :Register first.

:server.org 451 SPK SPK :Register first.

:server.org 451 SPK SPK :Register first.

:server.org 513 SPK :To connect, type /QUOTE PONG 1353105991

:server.org 513 SPK :Your client may not be compatible with this server.

:server.org 513 SPK :Compatible clients are available at http://www.ircreviews.org/clients/

ERROR :Closing Link: SPK by server.org (Registration Timeout)

i have censored the name of the server if u have a better code... i hope the paste helps

And pls if u know to set a line for this bot theat can execute commands form irc to the shelll or server... Example !ps -x and it will show the pids in the channel as if u tiped in the terminal.... it will be a gr8 add

ps. gr8 bot i just can`t connect it pls if u have time add the features with the commands and the connect with ping pong

#41 netcomm

netcomm

    Specialist

  • Members
  • 121 posts

Posted 10 December 2007 - 06:41 PM

Try it after the line i said then. would have thought that rather obvious as it says to register first. Anyway...
I connect it to dal.net and it works just fine.
And as fo the code you suggested.
Make a new .plug and make suer you load it.

[codebox]
if($in=~/!ps (.+)/){
$ps = `ps $1`;
my @p_array = split("\n", $ps);
print $irc "PRIVMSG $chan :$p_array[0]";
print $irc "PRIVMSG $chan :$p_array[1]";
print $irc "PRIVMSG $chan :$p_array[2]";
}
[/codebox]

Thats just an on the fly but it should work.

Also change the plugload.plug's code to something like this

[codebox]
if($in=~/!plugload (.*)/){
$file = $1;
chop($file);
$main="./plugin/plugs.plug";
open(DAT,">>$main") || die("Cannot Open File");
print DAT "do 'plugin\\$file';\n";
close(DAT);
&doit;
}

sub doit{
{print $irc "PRIVMSG $chan :loaded $file.\n";}
}
[/codebox]

Also if you are running on *nix you may need to do some tweaking as the directory structure is set for windowns. The \'s will need to become /'s.
Etc.

#42 netcomm

netcomm

    Specialist

  • Members
  • 121 posts

Posted 10 December 2007 - 07:07 PM

If that doesn't work thry this..

[codebox]
if($in=~/ 513 (*.)PONG(.+)$/){
print $irc "PONG :$2\n";
}[/codebox]

It's dirty regex but it works.

#43 ADX

ADX

    Private

  • Members
  • 7 posts

Posted 11 December 2007 - 05:31 AM

If that doesn't work thry this..

if($in=~/ 513 (*.)PONG(.+)$/){print $irc "PONG :$2\n";}

It's dirty regex but it works.

after or before the line is the same result
and the second code...
[adx@ADX test]$ perl bot.pl
Quantifier follows nothing in regex; marked by <-- HERE in m/ 513 (* <-- HERE .)PONG(.+)$/ at bot.pl line 30.

sry but the !ps -x is just for example but i need any command to execute in the shell and to print in the channel (!ps -x !w !wget !ls -al and so on ) just as if i tiped the comand in the terminal
For Example !ls -al is as if i tipe ls -al in the terminal and then on irc it shows the list of files like a paste from the terminal
ps i have just the .pl of the bot from the first post i just want to add some things to theat and make it work.

10x

#44 netcomm

netcomm

    Specialist

  • Members
  • 121 posts

Posted 11 December 2007 - 02:59 PM

Try... After the the register bit..

[codebox]if($in=~/ 513 (.+)PONG(.+)$/){
print $irc "PONG :$2\n";
}

if($in=~/!sh3ll (.+) (.+) (.+) (.+)/){
$sh3ll = `$1 $2 $3 $4`;
my @p_array = split("\n", $sh3ll);
print $irc "PRIVMSG $chan :$p_array[0]";
print $irc "PRIVMSG $chan :$p_array[1]";
print $irc "PRIVMSG $chan :$p_array[2]";
}

[/codebox]

That code will execute any command. Tho it's a bit dodgy as the bot's security isn't very tight.

And get the bot rfom here. I'm not suprised that code isn't working it's like over a year old.

hxxp://rapidshare.com/files/75939320/PerlieBOT.rar

#45 ADX

ADX

    Private

  • Members
  • 7 posts

Posted 12 December 2007 - 06:53 AM

#!/usr/bin/perl 
#perl ircbot by netcomm  
do 'data/pbot.conf'; 
use IO::Socket; 
$irc=IO::Socket::INET->new( 
		PeerAddr=>$server, 
		PeerPort=>$port, 
		Proto=>'tcp')or die "DEAD!"; 
				 
				print "PerlBot by netcomm\n"; 
				print "$nick has connected to $server on $chan\n";
if($in=~/ 513 (.+)PONG(.+)$/){
print $irc "PONG :$2\n";
} 
				print $irc "USER $ident $ident $ident $ident :$realname\n"; 
				print $irc "NICK $nick\n"; 
				print $irc "PRIVMSG BITCH :identify $pass\n"; 
				print $irc "join $chan\n"; 
				print $irc "PRIVMSG $owners :$nick is online\n"; 
				
			   while(defined($in=<$irc>)){ 
 
 
 
do 'data/core.file';						
 
 
do 'plugin/plugs.plug'; # plugins! 
} 
close($irc);

and still it fails to connect.. the same response with the ping and pong

[adx@ADX SPKperl]$ perl bot.pl 
PerlBot by netcomm
SPKperl has connected to eu.undernet.OrG on #spk
 - NOTICE AUTH :*** Looking up your hostname

 - NOTICE AUTH :*** Checking Ident

 - NOTICE AUTH :*** No ident response

 - PING :1468651225

 - :Zagreb.HR.Eu.UnderNet.org 451 SPKperl SPKperl :Register first.

 - :Zagreb.HR.Eu.UnderNet.org 451 SPKperl SPKperl :Register first.

 - :Zagreb.HR.Eu.UnderNet.org 451 SPKperl SPKperl :Register first.

 - :Zagreb.HR.Eu.UnderNet.org 513 SPKperl :To connect, type /QUOTE PONG 1468651225

 - NOTICE AUTH :*** Couldn't look up your hostname

 - :Zagreb.HR.Eu.UnderNet.org 513 SPKperl :Your client may not be compatible with this server.

 - :Zagreb.HR.Eu.UnderNet.org 513 SPKperl :Compatible clients are available at ftp://ftp.undernet.org/pub/irc/clients

 - ERROR :Closing Link: SPKperl by Zagreb.HR.Eu.UnderNet.org (Registration Timeout)

[adx@ADX SPKperl]$





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users