2015-05-12 15:17:42 +00:00
|
|
|
|
2016-09-04 17:23:49 +00:00
|
|
|
# Installing Cowrie in seven steps.
|
2015-05-12 15:22:15 +00:00
|
|
|
|
2016-10-25 18:43:49 +00:00
|
|
|
* [Step 1: Install dependencies](#step-1-install-dependencies)
|
|
|
|
* [Step 2: Create a user account](#step-2-create-a-user-account)
|
|
|
|
* [Step 3: Checkout the code](#step-3-checkout-the-code)
|
2017-06-02 06:08:37 +00:00
|
|
|
* [Step 4: Setup Virtual Environment](#step-4-setup-virtual-environment)
|
|
|
|
* [Step 5: Install configuration file](#step-5-install-configuration-file)
|
|
|
|
* [Step 6: Generate a DSA key](#step-6-generate-a-dsa-key)
|
|
|
|
* [Step 7: Turning on cowrie](#step-7-turning-on-cowrie)
|
|
|
|
* [Step 8: Port redirection (optional)](#step-8-port-redirection-optional)
|
2016-12-20 07:15:28 +00:00
|
|
|
* [Running within supervisord(optional)](#running-using-supervisord)
|
2016-10-25 18:43:49 +00:00
|
|
|
* [Troubleshooting](#troubleshooting)
|
2016-02-04 05:40:28 +00:00
|
|
|
|
2016-09-04 21:00:00 +00:00
|
|
|
## Step 1: Install dependencies
|
2016-06-01 18:09:44 +00:00
|
|
|
|
2016-12-11 11:40:00 +00:00
|
|
|
First we install support for Python virtual environments and other dependencies.
|
|
|
|
The actual Python packages are installed later.
|
2016-09-04 21:00:00 +00:00
|
|
|
|
2017-07-25 06:33:24 +00:00
|
|
|
On Debian based systems (last verified on Debian 9, 2017-07-25):
|
2016-06-19 13:39:09 +00:00
|
|
|
```
|
2017-07-25 06:33:24 +00:00
|
|
|
$ sudo apt-get install git python-virtualenv libssl-dev libffi-dev build-essential libpython-dev python2.7-minimal authbind
|
2016-06-19 13:39:09 +00:00
|
|
|
```
|
|
|
|
|
2016-08-31 18:31:12 +00:00
|
|
|
## Step 2: Create a user account
|
2016-06-01 18:09:44 +00:00
|
|
|
|
2016-01-17 06:32:35 +00:00
|
|
|
It's strongly recommended to install under a dedicated non-root user id:
|
2015-05-12 15:17:42 +00:00
|
|
|
|
|
|
|
```
|
|
|
|
$ sudo adduser --disabled-password cowrie
|
|
|
|
Adding user `cowrie' ...
|
|
|
|
Adding new group `cowrie' (1002) ...
|
|
|
|
Adding new user `cowrie' (1002) with group `cowrie' ...
|
|
|
|
Changing the user information for cowrie
|
|
|
|
Enter the new value, or press ENTER for the default
|
|
|
|
Full Name []:
|
|
|
|
Room Number []:
|
|
|
|
Work Phone []:
|
|
|
|
Home Phone []:
|
|
|
|
Other []:
|
|
|
|
Is the information correct? [Y/n]
|
|
|
|
|
|
|
|
$ sudo su - cowrie
|
2016-08-31 18:31:12 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
## Step 3: Checkout the code
|
2015-05-12 15:17:42 +00:00
|
|
|
|
2016-08-31 18:31:12 +00:00
|
|
|
```
|
2015-05-12 15:17:42 +00:00
|
|
|
$ git clone http://github.com/micheloosterhof/cowrie
|
|
|
|
Cloning into 'cowrie'...
|
|
|
|
remote: Counting objects: 2965, done.
|
|
|
|
remote: Compressing objects: 100% (1025/1025), done.
|
|
|
|
remote: Total 2965 (delta 1908), reused 2962 (delta 1905), pack-reused 0
|
|
|
|
Receiving objects: 100% (2965/2965), 3.41 MiB | 2.57 MiB/s, done.
|
|
|
|
Resolving deltas: 100% (1908/1908), done.
|
|
|
|
Checking connectivity... done.
|
|
|
|
|
|
|
|
$ cd cowrie
|
2016-08-31 18:31:12 +00:00
|
|
|
```
|
|
|
|
|
2017-03-05 20:21:32 +00:00
|
|
|
## Step 4: Setup Virtual Environment
|
2016-08-31 18:31:12 +00:00
|
|
|
|
2016-12-11 11:40:00 +00:00
|
|
|
Next you need to create your virtual environment:
|
2015-05-12 15:17:42 +00:00
|
|
|
|
2016-08-31 18:31:12 +00:00
|
|
|
```
|
|
|
|
$ pwd
|
|
|
|
/home/cowrie/cowrie
|
|
|
|
$ virtualenv cowrie-env
|
|
|
|
New python executable in ./cowrie/cowrie-env/bin/python
|
|
|
|
Installing setuptools, pip, wheel...done.
|
|
|
|
```
|
|
|
|
|
|
|
|
Activate the virtual environment and install packages
|
|
|
|
|
|
|
|
```
|
|
|
|
$ source cowrie-env/bin/activate
|
|
|
|
(cowrie-env) $ pip install -r requirements.txt
|
|
|
|
```
|
|
|
|
|
2017-03-05 20:21:32 +00:00
|
|
|
## Step 5: Install configuration file
|
2016-08-31 18:31:12 +00:00
|
|
|
|
2017-05-17 12:28:13 +00:00
|
|
|
The configuration for Cowrie is stored in cowrie.cfg.dist and
|
|
|
|
cowrie.cfg. Both files are read, where entries from cowrie.cfg take
|
|
|
|
precedence. The .dist file can be overwritten on upgrades, cowrie.cfg
|
|
|
|
will not be changed. To run with a standard configuration, there
|
|
|
|
is no need to change anything. To enable telnet, for example, create
|
|
|
|
cowrie.cfg and input only the following:
|
|
|
|
|
2016-08-31 18:31:12 +00:00
|
|
|
```
|
2017-05-17 12:28:13 +00:00
|
|
|
[telnet]
|
|
|
|
enabled = true
|
2016-08-31 18:31:12 +00:00
|
|
|
```
|
|
|
|
|
2017-03-05 20:21:32 +00:00
|
|
|
## Step 6: Generate a DSA key
|
2016-08-31 18:31:12 +00:00
|
|
|
|
2016-09-04 17:23:49 +00:00
|
|
|
This step should not be necessary, however some versions of twisted
|
2017-05-17 12:28:13 +00:00
|
|
|
are not compatible. To avoid problems in advance, run:
|
2015-05-12 15:17:42 +00:00
|
|
|
|
2016-08-31 18:31:12 +00:00
|
|
|
```
|
|
|
|
$ cd data
|
|
|
|
$ ssh-keygen -t dsa -b 1024 -f ssh_host_dsa_key
|
|
|
|
$ cd ..
|
|
|
|
```
|
|
|
|
|
2017-03-05 20:21:32 +00:00
|
|
|
## Step 7: Turning on cowrie
|
2016-08-31 18:31:12 +00:00
|
|
|
|
2017-03-07 19:12:02 +00:00
|
|
|
Cowrie is implemented as a module for Twisted, but to properly
|
2016-09-04 17:23:49 +00:00
|
|
|
import everything the top-level source directory needs to be in
|
2017-05-17 12:28:13 +00:00
|
|
|
python's os.path. This sometimes won't happen correctly, so make
|
2016-09-04 17:23:49 +00:00
|
|
|
it explicit:
|
2016-08-31 18:31:12 +00:00
|
|
|
|
|
|
|
```
|
2017-03-07 19:12:02 +00:00
|
|
|
# or another path to the top-level cowrie folder
|
2016-08-31 18:31:12 +00:00
|
|
|
$ export PYTHONPATH=/home/cowrie/cowrie
|
|
|
|
```
|
|
|
|
|
2017-03-07 19:12:02 +00:00
|
|
|
Start Cowrie with the cowrie command. You can add the cowrie/bin directory
|
|
|
|
to your path if desired. If the virtual environment is called "cowrie-env"
|
|
|
|
it will be automatically activated. Otherwise you will need to activate it
|
|
|
|
manually
|
2016-08-31 18:31:12 +00:00
|
|
|
|
|
|
|
```
|
2017-03-07 19:12:02 +00:00
|
|
|
$ bin/cowrie start
|
|
|
|
Activating virtualenv "cowrie-env"
|
|
|
|
Starting cowrie with extra arguments [] ...
|
2015-05-12 15:17:42 +00:00
|
|
|
```
|
|
|
|
|
2017-03-05 20:21:32 +00:00
|
|
|
## Step 8: Port redirection (optional)
|
2016-08-31 18:31:12 +00:00
|
|
|
|
2016-06-16 12:21:59 +00:00
|
|
|
Cowrie runs by default on port 2222. This can be modified in the configuration file.
|
2015-05-12 15:20:51 +00:00
|
|
|
The following firewall rule will forward incoming traffic on port 22 to port 2222.
|
|
|
|
|
|
|
|
```
|
2015-06-23 08:20:12 +00:00
|
|
|
$ sudo iptables -t nat -A PREROUTING -p tcp --dport 22 -j REDIRECT --to-port 2222
|
2015-05-12 15:20:51 +00:00
|
|
|
```
|
2015-05-12 15:17:42 +00:00
|
|
|
|
2016-09-04 17:23:49 +00:00
|
|
|
Note that you should test this rule only from another host; it
|
2017-05-17 12:28:13 +00:00
|
|
|
doesn't apply to loopback connections. Alternatively you can run
|
2016-09-04 17:23:49 +00:00
|
|
|
authbind to listen as non-root on port 22 directly:
|
2016-01-17 06:32:35 +00:00
|
|
|
|
|
|
|
```
|
|
|
|
$ apt-get install authbind
|
|
|
|
$ touch /etc/authbind/byport/22
|
|
|
|
$ chown cowrie:cowrie /etc/authbind/byport/22
|
2016-02-04 05:45:17 +00:00
|
|
|
$ chmod 770 /etc/authbind/byport/22
|
2016-01-17 06:32:35 +00:00
|
|
|
```
|
|
|
|
|
2016-10-28 05:38:43 +00:00
|
|
|
Or for telnet:
|
|
|
|
|
|
|
|
```
|
|
|
|
$ apt-get install authbind
|
|
|
|
$ sudo touch /etc/authbind/byport/23
|
|
|
|
$ sudo chown cowrie:cowrie /etc/authbind/byport/23
|
|
|
|
$ sudo chmod 770 /etc/authbind/byport/23
|
|
|
|
```
|
|
|
|
|
2017-03-07 19:17:30 +00:00
|
|
|
* Edit bin/cowrie and modify the AUTHBIND_ENABLED setting
|
2016-01-17 06:32:35 +00:00
|
|
|
* Change listen_port to 22 in cowrie.cfg
|
2015-09-12 09:47:21 +00:00
|
|
|
|
2016-12-20 07:15:28 +00:00
|
|
|
## Running using Supervisord
|
|
|
|
On Debian, put the below in /etc/supervisor/conf.d/cowrie.conf
|
|
|
|
```
|
|
|
|
[program:cowrie]
|
2017-03-07 19:17:30 +00:00
|
|
|
command=/home/cowrie/cowrie/bin/cowrie start
|
2016-12-20 07:15:28 +00:00
|
|
|
directory=/home/cowrie/cowrie/
|
|
|
|
user=cowrie
|
|
|
|
autorestart=true
|
|
|
|
redirect_stderr=true
|
|
|
|
```
|
2017-03-07 19:17:30 +00:00
|
|
|
Update the bin/cowrie script, change:
|
2016-12-20 07:15:28 +00:00
|
|
|
```
|
|
|
|
DAEMONIZE=""
|
|
|
|
```
|
|
|
|
to:
|
|
|
|
```
|
|
|
|
DAEMONIZE="-n"
|
|
|
|
```
|
|
|
|
|
2016-08-31 18:31:12 +00:00
|
|
|
## Troubleshooting
|
2015-09-12 09:47:21 +00:00
|
|
|
|
2016-09-04 17:23:49 +00:00
|
|
|
* If you see `twistd: Unknown command: cowrie` there are two
|
2017-05-17 12:28:13 +00:00
|
|
|
possibilities. If there's a python stack trace, it probably means
|
|
|
|
there's a missing or broken dependency. If there's no stack trace,
|
2016-09-04 17:23:49 +00:00
|
|
|
double check that your PYTHONPATH is set to the source code directory.
|
2016-04-26 15:16:49 +00:00
|
|
|
* Default file permissions
|
2016-04-27 08:38:05 +00:00
|
|
|
|
2016-04-26 15:16:49 +00:00
|
|
|
To make Cowrie logfiles public readable, change the ```--umask 0077``` option in start.sh into ```--umask 0022```
|
2016-04-27 08:38:05 +00:00
|
|
|
|