{"id":49,"date":"2023-07-22T10:24:00","date_gmt":"2023-07-22T17:24:00","guid":{"rendered":"https:\/\/francisco.x10.bz\/blog\/?p=49"},"modified":"2025-01-13T09:43:01","modified_gmt":"2025-01-13T17:43:01","slug":"installing-and-configuring-a-honeypot","status":"publish","type":"post","link":"https:\/\/defrancisco.us\/blog\/index.php\/2023\/07\/22\/installing-and-configuring-a-honeypot\/","title":{"rendered":"Laying Out the Honey: Installing and Configuring a Honeypot"},"content":{"rendered":"<p>Cybersecurity \u2014 the body of knowledge and practices to defend internet-connected devices and products from malicious attacks by hackers, spammers, and cybercriminals \u2014 is very important to me. I conduct research into patterns of behavior, tactics, techniques, and procedures used in attacks.<\/p>\n<p>I run honeypots to understand how hackers evolve their attack practices. A honeypot is a controlled and safe network-connected system \u2014 typically, but not always, a computer \u2014 that is set up as a decoy to lure cyberattackers. In other words, a honeypot is a deception device designed to look like a targetable system for the purpose of attracting attackers. Attack activity against the honeypot is recorded and later analyzed by researchers.<\/p>\n<p>I use <a href=\"https:\/\/github.com\/cowrie\/cowrie\" target=\"_blank\" rel=\"noopener\">Cowrie<\/a>, a fantastic open-source honeypot capable of collecting attack information over the SSH and Telnet protocols. Cowrie provides an emulation of a Debian-like Linux system. It excels at logging brute-force attacks and interactions performed by attackers on the remote shell.<\/p>\n<p>As, unfortunately, attacks on connected devices are all but ubiquitous, Cowrie generates large amounts of data. I use <a href=\"https:\/\/docs.splunk.com\/Documentation\/Splunk\/9.1.1\/Admin\/MoreaboutSplunkFree\" target=\"_blank\" rel=\"noopener\">Splunk Free<\/a>, the free (albeit limited) version of Splunk Enterprise to host a local copy of the data. I process and analyze the collected data using homegrown tools developed in Go, Python and the Bash scripting language. As part of the data crunching, I augment the attack data collected by Cowrie with malware information from <a href=\"https:\/\/www.virustotal.com\" target=\"_blank\" rel=\"noopener\">VirusTotal<\/a> and IP address information from <a href=\"https:\/\/dev.maxmind.com\/geoip\/geolite2-free-geolocation-data\" target=\"_blank\" rel=\"noopener\">MaxMind GeoLite2<\/a>. Both services offer free tiers with reasonable limits on API consumption, so the whole analysis can be performed very cost-effectively.<\/p>\n<p>Once a day, I report\u2009the IP addresses from where unwanted traffic originated to AbusePIDB, a project that aims to make the internet safer by helping systems administrators and webmasters check and report IP addresses involved in malicious activities. My AbuseIPDB contributions can be found <a href=\"https:\/\/www.abuseipdb.com\/user\/103277\" target=\"_blank\" rel=\"noopener\">here<\/a>.<\/p>\n<p>This is a simplified diagram of my setup:<\/p>\n<p><a href=\"\/images\/blog\/hpsetup-old_e.webp\" title=\"Simplified Honeypot Environment Diagram\"><img decoding=\"async\" src=\"\/images\/blog\/hpsetup-old_e.webp\" alt=\"Simplified Honeypot Environment Diagram\" title=\"Simplified Honeypot Environment Diagram\" \/><\/a><\/p>\n<p>Installing and configuring a Cowrie and Splunk-based honeypot environment is pretty straightforward. Below you can find the steps I took, in case you find the information useful:<\/p>\n<p>[<a href=\"#1\">Skip table of contents<\/a>]<\/p>\n<ol>\n<li><a href=\"#1\">The Honeypot<\/a>\n<ol>\n<li><a href=\"#1.1\">Choose the honeypot host<\/a><\/li>\n<li><a href=\"#1.2\">Install the system dependencies<\/a><\/li>\n<li><a href=\"#1.3\">Create a user account<\/a><\/li>\n<li><a href=\"#1.4\">Get the Cowrie code<\/a><\/li>\n<li><a href=\"#1.5\">Set up a Python virtual environment<\/a><\/li>\n<li><a href=\"#1.6\">Configure Cowrie<\/a><\/li>\n<li><a href=\"#1.7\">Customize Cowrie<\/a><\/li>\n<li><a href=\"#1.8\">Forward listening ports<\/a><\/li>\n<li><a href=\"#1.9\">Start Cowrie<\/a><\/li>\n<\/ol>\n<\/li>\n<li><a href=\"#2\">The Data Repository<\/a>\n<ol>\n<li><a href=\"#2.1\">Install Splunk<\/a><\/li>\n<li><a href=\"#2.2\">Switch from Splunk Enterprise to Splunk Free<\/a><\/li>\n<li><a href=\"#2.3\">Create a Splunk HTTP event collector (HEC)<\/a><\/li>\n<li><a href=\"#2.4\">Create a Splunk event collector token<\/a><\/li>\n<li><a href=\"#2.5\">Configure Cowrie to use the Splunk event collector<\/a><\/li>\n<li><a href=\"#2.6\">Verify that everything works<\/a><\/li>\n<\/ol>\n<\/li>\n<\/ol>\n<h2>Part 1: The Honeypot<a name=1><\/a><\/h2>\n<p>I chose Cowrie as the key component of my unwanted traffic detection infrastructure. Cowrie is a superb medium\/high interaction honeypot designed to log brute-force attempts and shell interactions launched by attackers over both SSH and Telnet. Cowrie is very popular among both researchers and enthusiasts due to an optimal combination of rich capabilities and ease of use. It is open-source and is backed by an active community led by <a href=\"https:\/\/www.patreon.com\/micheloosterhof\" target=\"_blank\" rel=\"noopener\">Michel Oosterhof<\/a>, the project\u2019s maintainer, creator, and main developer.<\/p>\n<h3>1. Choose the honeypot host<a name=1.1><\/a><\/h3>\n<p>You need to start by choosing a Linux system where to install the honeypot. Since Cowrie is very efficient in its resource consumption, I opted for a tiny <a href=\"https:\/\/www.raspberrypi.com\/products\/raspberry-pi-400\/specifications\/\" target=\"_blank\" rel=\"noopener\">Raspberry Pi 400<\/a> computer as the Cowrie host.<\/p>\n<h3>2. Install the system dependencies<a name=1.2><\/a><\/h3>\n<p>Install the system dependencies on the Cowrie host:<\/p>\n<pre><code> $ sudo apt-get install git python3-virtualenv libssl-dev libffi-dev build-essential libpython3-dev python3-minimal authbind virtualenv \n<\/code><\/pre>\n<h3>3. Create a user account<a name=1.3><\/a><\/h3>\n<p>Installing a user without a password is not an absolute requirement, but it is recommended by the Cowrie authors:<\/p>\n<pre><code>$ sudo adduser --disabled-password cowrie\nAdding user &#039;cowrie&#039; ...\nAdding new group &#039;cowrie&#039; (1002) ...\nAdding new user &#039;cowrie&#039; (1002) with group &#039;cowrie&#039; ... \nChanging the user information for cowrie\nEnter the new value, or press ENTER for the default\nFull Name []:\nRoom Number []:\nWork Phone []:\nHome Phone []:\nOther []:\nIs the information correct? [Y\/n]\n\n$ sudo su - cowrie\n<\/code><\/pre>\n<h3>4. Get the Cowrie code<a name=1.4><\/a><\/h3>\n<p>Clone the <code>cowrie<\/code> project from GitHub:<\/p>\n<pre><code>$ git clone http:\/\/github.com\/cowrie\/cowrie\nCloning into &#039;cowrie&#039;...\nremote: Counting objects: 2965, done.\nremote: Compressing objects: 100% (1025\/1025), done.\nremote: Total 2965 (delta 1908), reused 2962 (delta 1905), pack-reused 0 \nReceiving objects: 100% (2965\/2965), 3.41 MiB | 2.57 MiB\/s, done.\nResolving deltas: 100% (1908\/1908), done.\nChecking connectivity... done.\n\n$ cd cowrie\n<\/code><\/pre>\n<h3>5. Set up a Python virtual environment<a name=1.5><\/a><\/h3>\n<p>Technically speaking, this step is not needed, but it is highly recommended to ensure that package updates on the Cowrie host system will not cause incompatibilities with the honeypot operation:<\/p>\n<pre><code>$ pwd\n\/home\/cowrie\/cowrie\n\n$ python -m venv cowrie-env\nNew python executable in .\/cowrie\/cowrie-env\/bin\/python \nInstalling setuptools, pip, wheel...done.\n<\/code><\/pre>\n<p>After you install the virtual environment, activate it and install required packages:<\/p>\n<pre><code>$ source cowrie-env\/bin\/activate\n(cowrie-env) $ python -m pip install --upgrade pip\n(cowrie-env) $ python -m pip install --upgrade -r requirements.txt \n<\/code><\/pre>\n<h3>6. Configure Cowrie<a name=1.6><\/a><\/h3>\n<p>The Cowrie configuration is stored in the <code>cowrie\/etc\/cowrie.cfg file<\/code>. To run the honeypot with a standard configuration, there is no need to change anything. By default, Cowrie accepts traffic over SSH. I wanted the honeypot to also accept traffic over Telnet, send the data to Splunk (more on this later), and change the default ports 22 and 23, so I modified the configuration file as follows:<\/p>\n<pre><code>[telnet]\nenabled = true\n...\n[output_splunk]\nenabled = true\n...\n[proxy]\nbackend_ssh_port = 2022\nbackend_telnet_port = 2023 \n<\/code><\/pre>\n<p>I also wanted to change the default user configurations and the list of credentials accepted to login to the remote shell. These changes are made by modifing the cowrie\/etc\/userdb.txt file. Each line in the file consists of three fields separated by the : character, where:<\/p>\n<ul>\n<li>Field #1 is the username.<\/li>\n<li>Field #2 is currently unused and set to <code>x<\/code>.<\/li>\n<li>Field #3 is the regular expression that specifies the list of passwords accepted by the user.<\/li>\n<\/ul>\n<p>As an example, the following settings configure a username <code>admin<\/code> that accepts all passwords except 1) only numeric characters, 2) the case-sensitive string <code>admin<\/code>, and 3) the case-insensitive string <code>honeypot<\/code>:<\/p>\n<pre><code>admin:x:!admin\nadmin:x:!\/^[0-9]+$\/\nadmin:x:!\/honeypot\/i \nadmin:x:*\n<\/code><\/pre>\n<h3>7. Customize Cowrie<a name=1.7><\/a><\/h3>\n<p>Optionally, you can change the look-and-feel of the Cowrie interface to make it look more realistic. A number of files allow you to do that:<\/p>\n<ul>\n<li>In <code>cowrie\/etc\/cowrie.cfg<\/code>, you can change, for example, the hostname displayed by the shell prompt, the user prompt, the Telnet username and password prompts, the response from the <code>uname<\/code> command, the SSH version printed by <code>ssh -V<\/code>, etc.<\/li>\n<\/ul>\n<pre><code>hostname = appsrv02\n...\nprompt = root&gt;\n...\ntelnet_username_prompt_regex = (\\n|^)ubuntu login: .* \ntelnet_password_prompt_regex = .*Password: .*\n...\nkernel_version = 3.2.0-4-amd64\nkernel_build_string = #1 SMP Debian 3.2.68-1+deb7u1\nhardware_platform = x86_64\noperating_system = GNU\/Linux\n...\nssh_version = OpenSSH_7.9p1, OpenSSL 1.1.1a  20 Nov 2018 \n<\/code><\/pre>\n<ul>\n<li>In <code>cowrie\/honeyfs\/etc\/issue<\/code>, you can change the pre-login banner.<\/li>\n<li>In <code>cowrie\/honeyfs\/etc\/motd<\/code>, you can change the post-login message.<\/li>\n<li>In <code>cowrie\/honeyfs\/proc\/cpuinfo<\/code>, you can change the simulated CPU make-up of the system (e.g., number and type of processors).<\/li>\n<li>In <code>cowrie\/honeyfs\/proc\/meminfo<\/code>, you can change the simulated system\u2019s memory allocation and usage.<\/li>\n<li>In <code>cowrie\/honeyfs\/proc\/version<\/code>, you can change the Linux kernel and <code>gcc<\/code> versions.<\/li>\n<\/ul>\n<h3>8. Forward listening ports<a name=1.8><\/a><\/h3>\n<p>As we saw above, I configured Cowrie to accept SSH traffic over port 2022 and Telnet traffic over port 2023. In order to preserve the fidelity of the decoy, I opened ports 22 and 23 on the router and forward their traffic to ports 2022 and 2023, respectively, on the system hosting Cowrie.<\/p>\n<h3>9. Start Cowrie<a name=1.9><\/a><\/h3>\n<p>Start the honeypot by calling the <code>cowrie\/bin\/cowrie<\/code> executable that is part of the Cowrie distribution. An existing virtual environment is preserved if activated, otherwise Cowrie will attempt to load the environment called <code>cowrie-env<\/code> that we created earlier:<\/p>\n<pre><code>bin\/cowrie start\nActivating virtualenv &quot;cowrie-env&quot;\nStarting cowrie with extra arguments [] ... \n<\/code><\/pre>\n<h2>Part 2: The Data Repository<a name=2><\/a><\/h2>\n<p>I opted for Splunk Enterprise as the warehouse of my Cowrie-generated data because it is very powerful, offers superb API-based data querying and manipulation functionality, can be installed locally, and \u2014 best of all \u2014 is free if you keep your data volume under 500MB per day. I found it easier to set up and operate than alternatives such as Elasticsearch\/OpenSearch and Graylog.<\/p>\n<h3>1. Install Splunk<a name=2.1><\/a><\/h3>\n<p>Splunk Free is a free (as in no-cost) version of Splunk Enterprise with limited capabilities. When you first install Splunk Enterpise, it will automatically install an Enterprise Trial license that comes enabled by default. The Splunk Enterprise Trial license is valid for 60 days. The best part is that you can switch to the free license at any time during the trial period. The steps are as follows:<\/p>\n<ul>\n<li>Navigate to the <a href=\"https:\/\/www.splunk.com\/en_us\/products\/splunk-enterprise.html\" target=\"_blank\" rel=\"noopener\">Splunk Enterprise<\/a> page.<\/li>\n<li>If you do not have a Splunk account, create one.<\/li>\n<li>Log into your Splunk account.<\/li>\n<li>Under <em>Products<\/em>, select <em>Free Trials and Downloads<\/em>, scroll down to <em>Splunk Enterprise<\/em>, and click the <em>Get My Free Trial button<\/em>.<\/li>\n<li>Select the operating system of the machine where you want to install Splunk (I chose Windows), then download the latest version of Splunk Enterprise by clicking on the <em>Download Now<\/em> button.<\/li>\n<li>Agree to the Splunk General Terms and click <em>Access Program<\/em> to start the download.<\/li>\n<li>Open the downloaded package and follow the installation instructions on your operating system of choice.<\/li>\n<\/ul>\n<h3>2. Switch from Splunk Enterprise to Splunk Free<a name=2.2><\/a><\/h3>\n<p>At any time during your Splunk Enterprise trial, you can switch to the Free license. This is how:<\/p>\n<ul>\n<li>Login to your administrator account on the web interface of Splunk Enterprise. The default URL is <code>http:\/\/127.0.0.1:8000<\/code>.<\/li>\n<li>In the upper right-hand corner, navigate to <em>Settings<\/em>.<\/li>\n<li>Under <em>System<\/em>, select <em>Licensing<\/em>.<\/li>\n<li>Select <em>Change License Group<\/em>.<\/li>\n<li>Select <em>Free license<\/em> and then click <em>Save<\/em>.<\/li>\n<li>On the next screen, select <em>Restart Now<\/em> for the changes to take effect.<\/li>\n<\/ul>\n<h3>3. Create a Splunk HTTP event collector (HEC)<a name=2.3><\/a><\/h3>\n<ul>\n<li>Navigate to the web interface of your Splunk instance at <code>http:\/\/127.0.0.1:8000<\/code>.<\/li>\n<li>In the upper right-hand corner, select <em>Settings<\/em>.<\/li>\n<li>Under <em>Data<\/em>, select <em>Data Inputs<\/em>.<\/li>\n<li>Under <em>Local Inputs<\/em>, click the <em>HTTP Event Collector<\/em> link.<\/li>\n<li>Under <em>HTTP Event Collector<\/em>, click the <em>Global Settings<\/em> button at the top right of the page.<\/li>\n<li>Under <em>Edit Global Settings<\/em>, click <em>Enabled<\/em>, then click the <em>Save<\/em> button.<\/li>\n<li>Go back to <em>Data &gt; Data Inputs<\/em>.<\/li>\n<li>Under <em>Local Inputs<\/em>, click <em>+Add new<\/em> to the right of <em>HTTP Event Collector<\/em>.<\/li>\n<li>Under <em>Add Data<\/em>, enter a name for your new HEC, then click <em>Next<\/em>.<\/li>\n<li>Under <em>Input Settings<\/em>, click the <em>Create a new index<\/em> link in the <em>Index<\/em> section.<\/li>\n<li>Under <em>New Index<\/em>, enter <code>cowrie<\/code> as the name of your new index, then click <em>Save<\/em>.<\/li>\n<li>Back under <em>Input Settings<\/em>, select your newly-created index under <em>Select Allowed Indexes<\/em>, then click the <em>Review<\/em> button at the top right of the page.<\/li>\n<li>Under <em>Review<\/em>, click the <em>Submit<\/em> button at the top right of the page.<\/li>\n<\/ul>\n<h3>4. Create a Splunk event collector token<a name=2.4><\/a><\/h3>\n<ul>\n<li>Navigate to the web interface your Splunk instance at <a href=\"http:\/\/127.0.0.1:8000\">http:\/\/127.0.0.1:8000<\/a>.<\/li>\n<li>In the upper right-hand corner, select Settings.<\/li>\n<li>Click the Add Data icon.<\/li>\n<li>Under Or get data in with the following methods, click Monitor.<\/li>\n<li>Click HTTP Event Collector.<\/li>\n<li>Enter a name for the token.<\/li>\n<li>Click the Next button at the top right of the page.<\/li>\n<li>Click the Review button at the top right of the page.<\/li>\n<li>Under Review, click the Submit button at the top right of the page.<\/li>\n<li>Copy the token value; you will need it in the next step.<\/li>\n<\/ul>\n<h3>5. Configure Cowrie to use the Splunk event collector<a name=2.5><\/a><\/h3>\n<p>We now need to go to back the Cowrie configuration file <code>cowrie\/etc\/cowrie.cfg<\/code> and make edits to ensure that Cowrie sends the events it collects to Splunk through the HEC we created earlier. Look for the <code>[output-splunk]<\/code> section and ensure that it looks like this:<\/p>\n<pre><code>[output-splunk]\nenabled = true\nurl = http:\/\/XXX.XXX.XXX.XXX:8088\/services\/collector\/event \ntoken = your_splunk_token\nindex = cowrie\nsourcetype = cowrie\nsource = cowrie\n<\/code><\/pre>\n<p>Replace the <code>XXX.XXX.XXX.XXX<\/code> part of the <code>url<\/code> setting with the local IP address on your home network of the system hosting your Splunk instance. Replace <code>your_splunk_token<\/code> in the <code>token<\/code> setting with your Splunk token. Leave the <code>index<\/code>, <code>sourcetype<\/code>, and <code>source<\/code> settings set to their <code>cowrie<\/code> default.<\/p>\n<h3>6. Verify that everything works<a name=2.6><\/a><\/h3>\n<p>If all the above configuration steps went well, you should now have Cowrie connected to Splunk. Start Cowrie on the system where it was installed (Raspberry Pi in my case) and make sure that your Splunk service is running on the system where you installed it; mine runs on Windows 11. Assuming that your honeypot is being attacked \u2014 a very safe bet \u2014 you should see nicely formatted events on your Splunk instance. To view them, select <em>Apps &gt; Search &amp; Reporting<\/em> from your Splunk web interface and enter the following in the <em>New Search<\/em> text field:<\/p>\n<pre><code> index=cowrie\n<\/code><\/pre>\n<p>That\u2019s all. Happy threat hunting!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Cybersecurity \u2014 the body of knowledge and practices to defend internet-connected devices and products from malicious attacks by hackers, spammers, and cybercriminals \u2014 is very important to me. I conduct research into patterns of behavior, tactics, techniques, and procedures used in attacks. I run honeypots to understand how hackers evolve their attack practices. A honeypot [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-49","post","type-post","status-publish","format-standard","hentry","category-cyber"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/defrancisco.us\/blog\/index.php\/wp-json\/wp\/v2\/posts\/49","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/defrancisco.us\/blog\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/defrancisco.us\/blog\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/defrancisco.us\/blog\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/defrancisco.us\/blog\/index.php\/wp-json\/wp\/v2\/comments?post=49"}],"version-history":[{"count":21,"href":"https:\/\/defrancisco.us\/blog\/index.php\/wp-json\/wp\/v2\/posts\/49\/revisions"}],"predecessor-version":[{"id":208,"href":"https:\/\/defrancisco.us\/blog\/index.php\/wp-json\/wp\/v2\/posts\/49\/revisions\/208"}],"wp:attachment":[{"href":"https:\/\/defrancisco.us\/blog\/index.php\/wp-json\/wp\/v2\/media?parent=49"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/defrancisco.us\/blog\/index.php\/wp-json\/wp\/v2\/categories?post=49"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/defrancisco.us\/blog\/index.php\/wp-json\/wp\/v2\/tags?post=49"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}