I like to play active-defense. Every day, I extract attackers IP addresses from my SSH honeypots and performa quick Nmap scan against them. The goal is to gain more knowledge about the compromised hosts. Most of the time, hosts are located behind a residential broadband connection. But sometimes, you find more interesting stuff. When valid credentials are found, the classic scenario is the installation of a botnet client that will be controlled via IRC to launchmultiple attacks or scans. Malicious binaries are pre-compiled for many architectures but, this time, I feltlucky and got access to the source code! I found a compromised host (located in the Seychelles) that was hosting pre-compiled binaries and the source code of the botnet client itself. I had a quick look of course...
Honestly, the client is not very complex and only basic features are implemented but it helps to understand how to code malicious software. First of all, only one CC server was hardcoded in the source code (also located in the Seychelles) but the client can handle multiple servers. I presume that binaries are compiled with a new CC every time a new campaign is started. The connection occurred on an unusual port: 9271 (the default one being 6667 - IRC).
Once started, the client forks itself, tries to connect to its C">
if (pid1 = fork()) { waitpid(pid1, } else if (!pid1) { if (pid2 = fork()) { } else if (!pid2) { } else {}} else {}while(1){ } ....}
Once successfully connected, it enters the mainloop waiting for commands. The following ones were implemented:
PING (expecting a classic PONG reply)
GETLOCALIP (returns the local IP address of the bot)
SCANNER [ON|OFF] (starts or stops the Telnet scanner - see below)
The email feature looked experimental because some part of the code was commented out and the From">
if(send(fd, HELO rastrent.com\r\n } }if(strstr(buffer, 250 }if(send(fd, MAIL FROM: \r\n } }if(strstr(buffer, 250 }
The domain rastrent.com is registered butnot used at the moment. Here are passive DNS records found:
About the flood commands, the UDP and TCP ones are classic. The JUNK">
//nonblocking swegif(send(fds[i].fd, watwat, 1024, MSG_NOSIGNAL) == -1 errno != EAGAIN){}
This is not a very complex example but it shows how a badly protected Linux box can be infected and integrated into a botnet to generate malicious activity. The fact that the main feature is a Telnet scanner and the presence of binaries for multiple architectures tend to think for the botnet targets residential routers or small embedded Linux like storage devices. In the mean time, the server hosting the source code and binaries is offline for 24 hours. The hardcoded CC server is still alive.