Hello fellow Nullbytiens, I'm Washu, a long time commenter but first time poster. Today we'll be making an IRC bot, if you haven't seen OTW's post about the new IRC channel I would encourage you to go check it out. He does a good job at explaining what IRC is and how to get set up.
So what is a IRC bot? A IRC bot is essentially a user on an IRC channel that monitors the channel and responds to certain events. For example, if the bot is triggered by the word "command" when a user enters ".command" it will trigger a command that can do anything you wish.
For this project we will be using the Sopel framework, this will allows us to quickly make a powerful and useful python bot. Since this bot is written in python I recommend The Defalt's guide on How to Train your Python. A great guide that will help you with any python problem.
So first we have to download and install Sopel. If we look on their main page it links us to the install instruction. Its simple, we just have to do sudo pip install sopel. So lets try it:
Alright looks good.
Great, everything seemingly works! As you may have noticed I'm running Kali 2.0 so you may have different errors depending on your OS. The next step is to run the initial install. To do that simple run sopel
Oops, a friendly reminder from the developers that you shouldn't run anything that doesn't need it with root privilege ;) Lets try again with a user account.
Warning When I did this for the on Kali 2.0 it gave me a bunch of errors about creating the config file during setup, the same issue as this. I don't have a screenshot but to fix it I had to do a couple of things.
- Uninstall the current Sopel with sudo pip uninstall sopel
- Once that is done we need to download the git from git hub with git clone git://github.com/sopel-irc/sopel.git
Note: sopel requires Python 2.7.x or Python 3.3+ to run
- If you using python 2.7 you must install an additional dependency with pip install backports.ssl_match_hostname
- Then, from within the directory of the download, run python setup.py install
Now your installation should work correctly and you can continue on with the setup.
So lets try it again with a non-root account
Great! It works and allows us to configure our bot. When it ask you about the server to connect to put in chat.freenode.net, when it ask you about the channel enter #nullbyte. Everything else can be left as the default and it will work. If at any time you want to change anything the config file is located at /home/user/.sopel/default.cfg
Your bot should automatically connect and if everything goes as plan its name should appear in the user list at #nullbyte.
Now that your bot is working it can accept command. The first command to try is .help. This will give you a list of all command that can be used out of the box, a full list is also available here.
Some fun command to try out at first:
- .g - Query Google for a word
- .wiki - Search Wikipedia for an article
- .calc - Calculate an equation
- .tr - Translate a language to English
There are many more built in commands and modules and I leave it up to discover them all.
Now I know that we didn't really make anything ourselves yet but that's for the next tutorial. We will learn how to make our own modules and custom command, but if your are very keen to get your bot customized right away I encourage you to head over to the Sopel tutorials to start learning. Its very easy and extendable and maybe you can even submit your modules to the project :)
Last thing I want to say is don't spam! If you put your bot on the channel, please test it from within a private chat, so that there is not to much spam on the IRC.
Hope everyone has fun and hopefully we'll be seeing lots of bots around the IRC channel.
Want to start making money as a white hat hacker? Jump-start your white-hat hacking career with our 2020 Premium Ethical Hacking Certification Training Bundle from the new Null Byte Shop and get over 60 hours of training from ethical hacking professionals.