Watching the Bad Guys with Cowrie
Portholes
I can launch my shiny cowrie container with the following command, which exposes TCP port 2222 for my (non-public) SSH server, to query it locally:
$ docker run -d --restart=always -p 2222:2222 cowrie c52f9570af958069dba5ff5b13cf29751e7f71a689413a972b7a460b7a2f4516
The command above (with the -d switch) will keep the container running even if you log out.
I can then access the running container with the following command, which will offer a Bash prompt (abbreviate the hash if you like, which is c52f9570af95 in my case or any unique first few containers relative to other containers on the system):
$ docker exec -it c52f9570af95 bash
You can then log into and rummage around the container's filesystem. Note that you’ll connect as the cowrie user and not the superuser, root.
The next thing to do is ascertain the cowrie container’s IP Address with the output shown near the end having run the following command:
$ docker inspect c52f9570af95
As suspected (the first container often adopts this address by default), I can see this IP address (172.17.0.2) for my container as shown in Listing 3.
Listing 3: Honeypot IP Address
"Gateway": "172.17.0.1", "IPAddress": "172.17.0.2", "IPPrefixLen": 16, "IPv6Gateway": "", "GlobalIPv6Address": "", "GlobalIPv6PrefixLen": 0, "MacAddress": "02:42:ac:11:00:02", "DriverOpts": null
Onwards now to see what’s being presented in terms of attack surface by Cowrie.
I’ll install the mighty nmap for a quick port scan (on my localhost) as follows:
$ apt install -y nmap
Next, I’ll run the port scan with this command:
$ nmap 172.17.0.2
In Figure 2, I can confirm firstly that I am connecting to the correct IP address for the container and secondly that I am only exposing TCP port 2222 from the container.
Rummaging Deeper
Now I need to try and get into the SSH daemon that is listening inside my container following the same approach (brute forcing passwords) that an attacker would if the container was publicly accessible.
Running local commands is easy as pie with the following command:
$ ssh root@172.17.0.2 -p2222
Figure 3 shows what to expect if I use root as the username and 123456 as the password. Success!
The default root user password, which I’ve just mentioned, would take a bot or attacker a few attempts to guess, but not long at all (root:root or admin:admin being more common probably).
If you edit the file cowrie.cfg inside the container, then you can affect a few config-related things, such as enabling the Telnet server, which can be found inside the etc volume in Docker. Switching on Telnet, for example, looks like this:
[telnet] enabled = yes
Now that I’ve got access to our honeypot SSH server, I'll analyze the logs that an attacker might leave behind.
Having run a few arbitrary commands inside the container, I then log back into the container through Docker. Cowrie provides the magical command, playlog, to look through what commands an attacker has run. You’ll find that running it offers an animated display of what was typed. I can choose between SSH sessions and view the animation as follows:
$ playlog /cowrie/cowrie-git/var/lib/cowrie/tty/f43b369f158dc632e06
When I was rummaging in the container over SSH, I typed the command hello, which I knew would fail as a marker. Next, having run playlog pointed at the path for the SSH session above, it’s clearly the correct SSH session that I’m watching as I’m greeted with a hello again.
Whaddaya Hear, Whaddaya Say?
You might be pleasantly surprised to hear that you can generate some pretty amazing graphs from your honeypot’s logs with Kippo-Graph. According to an online article, “The switch went real smooth as Cowrie is basically a drop in replacement for Kippo and scripts like Kippo-Graph work with it.” Cowrie will run with Kippo-Graph thanks for its Kippo provenance, so it’s worth having a look at the GitHub page. Figure 4 and Figure 5 show some examples from a website that focuses on Kippo-Graph.
As the sophisticated graphing software shows, there’s much more to Kippo and Cowrie than simply replaying commands when it comes to analysis of attacker trends.
« Previous 1 2 3 Next »
Buy Linux Magazine
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Support Our Work
Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.
News
-
TUXEDO Computers Unveils Linux Laptop Featuring AMD Ryzen CPU
This latest release is the first laptop to include the new CPU from Ryzen and Linux preinstalled.
-
XZ Gets the All-Clear
The back door xz vulnerability has been officially reverted for Fedora 40 and versions 38 and 39 were never affected.
-
Canonical Collaborates with Qualcomm on New Venture
This new joint effort is geared toward bringing Ubuntu and Ubuntu Core to Qualcomm-powered devices.
-
Kodi 21.0 Open-Source Entertainment Hub Released
After a year of development, the award-winning Kodi cross-platform, media center software is now available with many new additions and improvements.
-
Linux Usage Increases in Two Key Areas
If market share is your thing, you'll be happy to know that Linux is on the rise in two areas that, if they keep climbing, could have serious meaning for Linux's future.
-
Vulnerability Discovered in xz Libraries
An urgent alert for Fedora 40 has been posted and users should pay attention.
-
Canonical Bumps LTS Support to 12 years
If you're worried that your Ubuntu LTS release won't be supported long enough to last, Canonical has a surprise for you in the form of 12 years of security coverage.
-
Fedora 40 Beta Released Soon
With the official release of Fedora 40 coming in April, it's almost time to download the beta and see what's new.
-
New Pentesting Distribution to Compete with Kali Linux
SnoopGod is now available for your testing needs
-
Juno Computers Launches Another Linux Laptop
If you're looking for a powerhouse laptop that runs Ubuntu, the Juno Computers Neptune 17 v6 should be on your radar.