Files
cowrie/doc/sql
Michel Oosterhof b861cebef3 Arch handling by @oliveriandrea
commit 916b5bf7fa8cff0eee9623bdd188fa902ea49699
Author: Michel Oosterhof <michel@oosterhof.net>
Date:   Mon Apr 2 00:39:28 2018 +0400

    string handling

commit 1d52bb7a85cace371717e7db1f88cd1eff608e1c
Author: Michel Oosterhof <michel@oosterhof.net>
Date:   Sun Apr 1 22:03:13 2018 +0400

    arch already logged in server.py

commit 2f4fee8bdf3b9f129cf4315bd6c20ef38e44d582
Author: Michel Oosterhof <michel@oosterhof.net>
Date:   Sun Apr 1 22:02:06 2018 +0400

    get binary contents from file system

commit 1043bde0328de9d54c72cdb00a20b5ccd6c3f4cc
Author: Michel Oosterhof <michel@oosterhof.net>
Date:   Sun Apr 1 21:42:34 2018 +0400

    use 'arch' as multi value architecture.

commit 6d86d20acb7e4affa8cc690d45995c40d5f0542f
Merge: 201a923 c9e5a44
Author: Michel Oosterhof <michel@oosterhof.net>
Date:   Sun Apr 1 15:50:57 2018 +0400

    Merge remote-tracking branch 'oliveriandrea/multi_arch' into multi-arch-michel

commit c9e5a44a6a
Author: oliveriandrea <oliveriandrea@gmail.com>
Date:   Wed Mar 28 17:57:52 2018 +0200

    Introduction of self.arch = 'linux-x64-lsb'

commit f54f9ae67d
Author: oliveriandrea <oliveriandrea@gmail.com>
Date:   Wed Mar 28 17:56:59 2018 +0200

    moved to server

commit a22bf01855
Author: oliveriandrea <oliveriandrea@gmail.com>
Date:   Wed Mar 28 17:56:09 2018 +0200

    fake_arch to arch, self.arch -> self.server.arch

commit 1c7ca09449
Author: oliveriandrea <oliveriandrea@gmail.com>
Date:   Wed Mar 28 17:52:51 2018 +0200

    fake_arch to arch

commit f706f6568e
Author: oliveriandrea <oliveriandrea@gmail.com>
Date:   Wed Mar 28 17:51:37 2018 +0200

    fake_arch to arch

commit af95806ceb
Author: oliveriandrea <oliveriandrea@gmail.com>
Date:   Wed Mar 28 12:04:41 2018 +0200

    move fake_arch and archs_emulated under [shell]

commit be72123228
Author: oliveriandrea <oliveriandrea@gmail.com>
Date:   Wed Mar 28 11:55:49 2018 +0200

    fake_arch now is under [shell]

commit 32609bf7ce
Author: oliveriandrea <oliveriandrea@gmail.com>
Date:   Wed Mar 28 11:48:58 2018 +0200

    Move fake arch configuration under [shell]

commit 952e87d0b9
Author: oliveriandrea <oliveriandrea@gmail.com>
Date:   Thu Mar 22 10:48:52 2018 +0100

    Update README

commit 8adde62f33
Author: oliveriandrea <oliveriandrea@gmail.com>
Date:   Thu Mar 22 10:47:17 2018 +0100

    Collection of dummy executables

commit e79c2d77c1
Author: oliveriandrea <oliveriandrea@gmail.com>
Date:   Thu Mar 22 10:45:35 2018 +0100

    Source code of the dummy executables

commit db2ccf5297
Author: oliveriandrea <oliveriandrea@gmail.com>
Date:   Thu Mar 22 10:44:52 2018 +0100

    README for the sources

commit 97d5dc2b3d
Author: oliveriandrea <oliveriandrea@gmail.com>
Date:   Thu Mar 22 10:37:47 2018 +0100

    Patch to cat,head,tail and dd in order to report fake arch

commit 05543a1490
Author: oliveriandrea <oliveriandrea@gmail.com>
Date:   Thu Mar 22 10:36:31 2018 +0100

    Update the configuration in order to support multiarch emulation

commit 81b29f2dd2
Author: oliveriandrea <oliveriandrea@gmail.com>
Date:   Thu Mar 22 10:35:36 2018 +0100

    Added param table in SQL schemas

commit 827c47ff71
Author: oliveriandrea <oliveriandrea@gmail.com>
Date:   Thu Mar 22 10:34:47 2018 +0100

    Added params table

commit fa7b467950
Author: oliveriandrea <oliveriandrea@gmail.com>
Date:   Thu Mar 22 10:27:15 2018 +0100

    Generate random choice for the architecture
2018-04-02 00:44:20 +04:00
..
2018-04-02 00:44:20 +04:00
2018-01-03 04:49:57 +00:00
2018-04-02 00:44:20 +04:00
2015-02-10 12:04:20 +00:00
2015-12-30 12:18:00 +00:00
2015-12-30 13:00:39 +00:00
2018-04-02 00:44:20 +04:00

How to Send Cowrie Output to a MySQL Database

Prerequisites

  • Working Cowrie installation
  • MySQL Server installation

Installation

$ sudo apt-get install mysql-server libmysqlclient-dev python-mysqldb
$ su - cowrie
$ source cowrie/cowrie-env/bin/activate
$ pip install mysqlclient

Previously MySQL-python was used. Only if you run into isses with mysqlclient, try this instead:

$ pip install MySQL-python

MySQL Configuration

First create an empty database named 'cowrie'.

$ mysql -u root -p
CREATE DATABASE cowrie;

Create a cowrie user account for the database and grant access privileges:

All Privileges:

GRANT ALL ON cowrie.* TO 'cowrie'@'localhost' IDENTIFIED BY 'PASSWORD HERE';

Restricted Privileges:

Alternatively you can grant the cowrie account with less privileges. The following command grants the account with the bare minimum required for the output logging to function:

GRANT INSERT, SELECT, UPDATE ON cowrie.* TO 'cowrie'@'localhost' IDENTIFIED BY 'PASSWORD HERE';

Apply the privilege settings and exit mysql.

FLUSH PRIVILEGES;
exit

Next, log into the MySQL database using the cowrie account to verify proper access privileges and load the database schema provided in the doc/sql/ directory:

$ cd ~/cowrie/doc/sql/
$ mysql -u cowrie -p
USE cowrie;
source mysql.sql;
exit

Cowrie Configuration

Uncomment and update the following entries to ~/cowrie/cowrie.cfg under the Output Plugins section:

[output_mysql]
host = localhost
database = cowrie
username = cowrie
password = PASSWORD HERE
port = 3306
debug = false

Restart Cowrie

$ cd ~/cowrie/bin/
$ ./cowrie restart

Verify That the MySQL Output Engine Has Been Loaded

Check the end of the ~/cowrie/log/cowrie.log to make sure that the MySQL output engine has loaded successfully.

$ cd ~/cowrie/log/
$ tail cowrie.log

Example expected output:

2017-11-27T22:19:44-0600 [-] Loaded output engine: jsonlog
2017-11-27T22:19:44-0600 [-] Loaded output engine: mysql
...
2017-11-27T22:19:58-0600 [-] Ready to accept SSH connections

Confirm That Events are Logged to the MySQL Database

Wait patiently for a new login attempt to occur. Use tail like before to quickly check if any activity has been recorded in the cowrie.log file.

Once a login event has occurred, log back into the MySQL database and verify that the event was recorded:

$ mysql -u cowrie -p
USE cowrie;
SELECT * FROM auth;

Example output:

+----+--------------+---------+----------+-------------+---------------------+
| id | session      | success | username | password    | timestamp           |
+----+--------------+---------+----------+-------------+---------------------+
|  1 | a551c0a74e06 |       0 | root     | 12345       | 2017-11-27 23:15:56 |
|  2 | a551c0a74e06 |       0 | root     | seiko2005   | 2017-11-27 23:15:58 |
|  3 | a551c0a74e06 |       0 | root     | anko        | 2017-11-27 23:15:59 |
|  4 | a551c0a74e06 |       0 | root     | 123456      | 2017-11-27 23:16:00 |
|  5 | a551c0a74e06 |       0 | root     | dreambox    | 2017-11-27 23:16:01 |
...