pgsqlpot 2.0.0__py2.py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. core/__init__.py +0 -0
  2. core/config.py +50 -0
  3. core/logfile.py +74 -0
  4. core/output.py +39 -0
  5. core/paths.py +53 -0
  6. core/protocol.py +161 -0
  7. core/tools.py +170 -0
  8. output_plugins/__init__.py +0 -0
  9. output_plugins/couch.py +68 -0
  10. output_plugins/datadog.py +74 -0
  11. output_plugins/discord.py +133 -0
  12. output_plugins/elastic.py +137 -0
  13. output_plugins/hpfeed.py +43 -0
  14. output_plugins/influx2.py +66 -0
  15. output_plugins/jsonlog.py +36 -0
  16. output_plugins/kafka.py +57 -0
  17. output_plugins/localsyslog.py +66 -0
  18. output_plugins/mongodb.py +83 -0
  19. output_plugins/mysql.py +210 -0
  20. output_plugins/nlcvapi.py +119 -0
  21. output_plugins/postgres.py +154 -0
  22. output_plugins/redisdb.py +47 -0
  23. output_plugins/rethinkdblog.py +46 -0
  24. output_plugins/slack.py +94 -0
  25. output_plugins/socketlog.py +40 -0
  26. output_plugins/sqlite.py +141 -0
  27. output_plugins/telegram.py +141 -0
  28. output_plugins/textlog.py +46 -0
  29. output_plugins/xmpp.py +193 -0
  30. pgsqlpot/__init__.py +25 -0
  31. pgsqlpot/cli.py +512 -0
  32. pgsqlpot/data/Dockerfile +56 -0
  33. pgsqlpot/data/docs/INSTALL.md +400 -0
  34. pgsqlpot/data/docs/INSTALLWIN.md +411 -0
  35. pgsqlpot/data/docs/PLUGINS.md +21 -0
  36. pgsqlpot/data/docs/TODO.md +8 -0
  37. pgsqlpot/data/docs/datadog/README.md +32 -0
  38. pgsqlpot/data/docs/discord/README.md +58 -0
  39. pgsqlpot/data/docs/geoipupdtask.ps1 +270 -0
  40. pgsqlpot/data/docs/mysql/README.md +176 -0
  41. pgsqlpot/data/docs/mysql/READMEWIN.md +157 -0
  42. pgsqlpot/data/docs/mysql/mysql.sql +85 -0
  43. pgsqlpot/data/docs/postgres/README.md +184 -0
  44. pgsqlpot/data/docs/postgres/READMEWIN.md +196 -0
  45. pgsqlpot/data/docs/postgres/postgres.sql +73 -0
  46. pgsqlpot/data/docs/slack/README.md +68 -0
  47. pgsqlpot/data/docs/sqlite3/README.md +131 -0
  48. pgsqlpot/data/docs/sqlite3/READMEWIN.md +123 -0
  49. pgsqlpot/data/docs/sqlite3/sqlite3.sql +69 -0
  50. pgsqlpot/data/docs/telegram/README.md +103 -0
  51. pgsqlpot/data/etc/honeypot.cfg +415 -0
  52. pgsqlpot/data/etc/honeypot.cfg.base +418 -0
  53. pgsqlpot/data/test/.gitignore +3 -0
  54. pgsqlpot/data/test/test.py +51 -0
  55. pgsqlpot/honeypot.py +117 -0
  56. pgsqlpot-2.0.0.dist-info/METADATA +152 -0
  57. pgsqlpot-2.0.0.dist-info/RECORD +61 -0
  58. pgsqlpot-2.0.0.dist-info/WHEEL +6 -0
  59. pgsqlpot-2.0.0.dist-info/entry_points.txt +2 -0
  60. pgsqlpot-2.0.0.dist-info/licenses/LICENSE +674 -0
  61. pgsqlpot-2.0.0.dist-info/top_level.txt +3 -0
@@ -0,0 +1,184 @@
1
+ # Sending the Output of the Honeypot to an PostgreSQL Database
2
+
3
+ (For installation on Windows, see the corresponding [installation document](READMEWIN.md))
4
+
5
+ - [Sending the Output of the Honeypot to an PostgreSQL Database](#sending-the-output-of-the-honeypot-to-an-postgresql-database)
6
+ - [Prerequisites](#prerequisites)
7
+ - [Installation](#installation)
8
+ - [PostgreSQL Database Creation](#postgresql-database-creation)
9
+ - [Honeypot Configuration](#honeypot-configuration)
10
+ - [Restart the honeypot](#restart-the-honeypot)
11
+
12
+ ## Prerequisites
13
+
14
+ - Working honeypot installation
15
+ - PostgreSQL
16
+
17
+ ## Installation
18
+
19
+ When writing to an PostgreSQL database, the honeypot uses the free databases
20
+ provided by MaxMind for the purpose of geoloacting the IP addresses.
21
+ Start by installing the library necessary to work with these databases
22
+ from an account that can sudo (i.e., not from the user `pgsqlpot`):
23
+
24
+ ```bash
25
+ sudo add-apt-repository ppa:maxmind/ppa
26
+ sudo apt-get update
27
+ sudo apt-get install geoipupdate
28
+ ```
29
+
30
+ Then, make sure that the PostgreSQL database and the `psql` command-line
31
+ utility for managing it are installed:
32
+
33
+ ```bash
34
+ sudo apt-get install postgresql-12 postgresql-client
35
+ ```
36
+
37
+ Log in as the user `postgres` (the super-user in PostgreSQL) and create
38
+ the honeypot-related database users, the database, and grant proper
39
+ privileges to it to the users:
40
+
41
+ ```psql
42
+ $ sudo su - postgres
43
+ $ psql
44
+ postgres=# create user pgsqlpot with password 'PASSWORD HERE';
45
+ postgres=# create database pgsqlpot;
46
+ postgres=# grant all privileges on database pgsqlpot to pgsqlpot;
47
+ ```
48
+
49
+ (Make sure you specify a proper password that you want to use for the user
50
+ `pgsqlpot` instead of 'PASSWORD HERE'.)
51
+
52
+ If you're going to use a third-party tool for accessing the data from the
53
+ database (e.g., [Grafana](https://www.grafana.com) for visualizing the data),
54
+ it is advisable also to create a separate user that has read-only privileges
55
+ to the database and have the third-party tool access the database as that
56
+ user, so that in case the third-party tool contains some kind of vulnerability
57
+ and is breached (and the attacker obtains the database user password from it),
58
+ the attacker cannot modify the database:
59
+
60
+ ```psql
61
+ postgres=# create user pgsqlpotReadOnly with password 'OTHER PASSWORD HERE';
62
+ postgres=# grant select on database pgsqlpot to pgsqlpot;
63
+ ```
64
+
65
+ (Make sure you specify a proper password that you want to use for the user
66
+ `pgsqlpotReadOnly` instead of 'OTHER PASSWORD HERE'.)
67
+
68
+ Finally, exit `psql`:
69
+
70
+ ```psql
71
+ postgres=# \q
72
+ ```
73
+
74
+ Now switch to the `pgsqlpot` user:
75
+
76
+ ```bash
77
+ sudo su - pgsqlpot
78
+ cd pgsqlpot
79
+ ```
80
+
81
+ Go to the directory `data`, where the gelolocation databases will reside:
82
+
83
+ ```bash
84
+ cd data
85
+ ```
86
+
87
+ Create in this directory a file named `geoip.cfg` with the following contents:
88
+
89
+ ```geoip.cfg
90
+ AccountID <ACCOUNT>
91
+ LicenseKey <KEY>
92
+ EditionIDs GeoLite2-City GeoLite2-ASN
93
+ DatabaseDirectory /home/pgsqlpot/pgsqlpot-workdir/data
94
+ LockFile /home/pgsqlpot/pgsqlpot-workdir/data/.geoipupdate.lock
95
+ ```
96
+
97
+ Change the paths in the options `DatabaseDirectory` and `LockFile` if you
98
+ have opted to use paths different from the ones suggested by the
99
+ honeypot installation documentation. Make sure you replace `<ACCOUNT>`
100
+ and `<KEY>` with the account and API key obtained from MaxMind.
101
+
102
+ In order to be able to download the MaxMind geolocation databases (either
103
+ manually or in an automated way), you need a (free) account at their site.
104
+ You can create such an account [there](https://www.maxmind.com/en/geolite2/signup).
105
+ Creating it involves choosing a user name and a password, providing some
106
+ personal data like country of residence, industry in which you're working,
107
+ intended use for their databases, an e-mail address, and also agreeing with
108
+ their terms and conditions. Once the account is created, you can get your
109
+ AccountID and LicenseKey from it.
110
+
111
+ Download the latest version of the Maxmind geolocation databases:
112
+
113
+ ```bash
114
+ geoipupdate -f geoip.cfg
115
+ ```
116
+
117
+ To have the database updated automatically (it is updated on MaxMind's site
118
+ every second Tuesday of each month, so download it every second Wednesday),
119
+ create a crontab job (`crontab -e`) and enter the following:
120
+
121
+ ```crontab
122
+ # Update the geoIP database at midnight on the 2nd Wednesday of each month:
123
+ 0 0 8-14 * * [ $(/bin/date +\%u) -eq 3 ] && /usr/bin/geoipupdate -f /home/pgsqlpot/pgsqlpot-workdir/data/geoip.cfg
124
+ ```
125
+
126
+ Alternatively, if you already have the MaxMind geolocation databases installed
127
+ and updated on your machine in some other place, use their respective paths in
128
+ the `[output_postgres]` section of the file `honeypot.cfg`, as mentioned
129
+ below.
130
+
131
+ Finally, return to the main directory of the project:
132
+
133
+ ```bash
134
+ cd ..
135
+ ```
136
+
137
+ ## PostgreSQL Database Creation
138
+
139
+ The database is already created but it is completely empty. Now we have to
140
+ specify its schema (tables and indexes):
141
+
142
+ ```bash
143
+ psql -f docs/postgres/postgres.sql -W pgsqlpot pgsqlpot
144
+ ```
145
+
146
+ You will be prompted for the password of the database user `pgsqlpot`.
147
+
148
+ If your database does not reside on your local machine but is on some remote
149
+ database server, use the options `-h host` and `-p port` of `psql` to
150
+ specify how to connect to it.
151
+
152
+ ## Honeypot Configuration
153
+
154
+ Add the following entries to the file `~/pgsqlpot-workdir/etc/honeypot.cfg`
155
+
156
+ ```honeypot.cfg
157
+ [output_postgres]
158
+ enabled = true
159
+ debug = false
160
+ host = localhost
161
+ port = 5432
162
+ username = pgsqlpot
163
+ password = secret
164
+ database = pgsqlpot
165
+ # Whether to store geolocation data in the database
166
+ geoip = true
167
+ # Location of the databases used for geolocation
168
+ geoip_citydb = data/GeoLite2-City.mmdb
169
+ geoip_asndb = data/GeoLite2-ASN.mmdb
170
+ ```
171
+
172
+ Make sure that you specify the correct information needed to connect to the
173
+ database (the options `host`, `port`, `username`, and `password`) and that the
174
+ options `geoip_citydb` and `geoip_asndb` point to the correct paths of the two
175
+ MaxMind geolocation databases. Also, if you prefer to keep the PostgreSQL
176
+ database under a different name, make sure that you specify its correct name
177
+ with the `database` option.
178
+
179
+ ## Restart the honeypot
180
+
181
+ ```bash
182
+ source ~/pgsqlpot-env/bin/activate
183
+ pgsqlpot restart
184
+ ```
@@ -0,0 +1,196 @@
1
+ # Sending the Output of the Honeypot to an PostgreSQL Database
2
+
3
+ - [Sending the Output of the Honeypot to an PostgreSQL Database](#sending-the-output-of-the-honeypot-to-an-postgresql-database)
4
+ - [Prerequisites](#prerequisites)
5
+ - [Installation](#installation)
6
+ - [PostgreSQL Database Creation](#postgresql-database-creation)
7
+ - [Honeypot Configuration](#honeypot-configuration)
8
+ - [Restart the honeypot](#restart-the-honeypot)
9
+
10
+ ## Prerequisites
11
+
12
+ - Working honeypot installation
13
+ - PostgreSQL
14
+
15
+ ## Installation
16
+
17
+ When writing to a PostgreSQL database, the honeypot uses the free databases
18
+ provided by MaxMind for the purposes of geoloacting the IP addresses. Start by
19
+ downloading the database update program for your particular kind of Windows from
20
+ [GitHub](https://github.com/maxmind/geoipupdate/releases) and put it in a
21
+ directory listed in the `PATH` variable of the environment.
22
+
23
+ Create an account at the [MaxMind web
24
+ site](https://support.maxmind.com/knowledge-base/articles/create-a-maxmind-account),
25
+ log in, go to "My Account" and then to "Manage license keys". Write down the
26
+ account ID, generate a license key, and copy it.
27
+
28
+ Go to the directory `data`, where the gelolocation databases will reside:
29
+
30
+ ```powershell
31
+ PS C:\> cd \pgsqlpot-workdir\data
32
+ ```
33
+
34
+ Create in this directory a file named `geoip.cfg` with the following contents:
35
+
36
+ ```geoip.cfg
37
+ AccountID <ACCOUNT>
38
+ LicenseKey <KEY>
39
+ EditionIDs GeoLite2-City GeoLite2-ASN
40
+ DatabaseDirectory C:\pgsqlpot-workdir\data
41
+ LockFile C:\pgsqlpot-workdir\data\.geoipupdate.lock
42
+ ```
43
+
44
+ Change the paths in the options `DatabaseDirectory` and `LockFile` if you
45
+ have opted to use paths different from the ones suggested by the
46
+ honeypot installation documentation. Make sure you replace `<ACCOUNT>`
47
+ and `<KEY>` with the account and license key obtained from MaxMind.
48
+
49
+ Download the latest version of the Maxmind geolocation databases:
50
+
51
+ ```powershell
52
+ PS C:\pgsqlpot-workdir\data> geoipupdate -f geoip.cfg
53
+ ```
54
+
55
+ To have the database updated automatically (it is updated on MaxMind's site
56
+ every second Tuesday of each month, so download it every second Wednesday),
57
+ run the script `geoipupdtask.ps1` in the working directory:
58
+
59
+ ```powershell
60
+ PS C:\pgsqlpot-workdir\data> ..\geoipupdtask.ps1
61
+ ```
62
+
63
+ It expects that the program `geoipupdate.exe` resides in one of the directories
64
+ listed in the `PATH` variable of the environment, that the configuration file
65
+ for it is named `geoip.cfg` and resides in the current directory, and that the
66
+ updating task is to be run at 00:00. Also, it creates an updating task named
67
+ `GeoIPUpdate`, which resides in the task folder `\` and has the description
68
+ `GeoIP database updater`. You can change any of these parameters via
69
+ command-line options to the script:
70
+
71
+ ```powershell
72
+ PS C:\pgsqlpot-workdir\data> ..\geoipupdtask.ps1 -TaskName "My GeoIP Database Updater" -TaskPath "\MyTasks" -TaskDescription "Updates the GeoIP database" -RunTime "03:00:00" -geoipupdate "C:\Program File\geoipupdate\geoipupdate.exe" -geoipconfig "C:\pgsqlpot-workdir\data\geoip.cfg"
73
+ ```
74
+
75
+ If you already have the MaxMind geolocation databases installed and updated on
76
+ your machine in some other place, use their respective paths in the
77
+ `[output_postgres]` section of the file `honeypot.cfg`, as mentioned below.
78
+
79
+ Finally, return to the main working directory:
80
+
81
+ ```powershell
82
+ PS C:\pgsqlpot-workdir\data> cd ..
83
+ ```
84
+
85
+ ## PostgreSQL Database Creation
86
+
87
+ In order to access a PostgreSQL database from the command line on Windows, we
88
+ need to install the command-line tools for this platform. Download the full
89
+ package (datbase server, phpMyAdmin, etc.)
90
+ [from here](https://sbp.enterprisedb.com/getfile.jsp?fileid=1259914), start the
91
+ installer wizard and click the `Next` button. Specify the installation directory
92
+ (e.g., `C:\Program Files\PostgreSQL`) and click the `Next` button. On the
93
+ "Select Components" screen, uncheck everything except "Command Line Toos" (you
94
+ can't uncheck them anyway) and click the `Next` button. Finally, on the next
95
+ screen, click the `Next` button again to start the installation process.
96
+
97
+ Once the installation is finished, open the Windows Settings, search for "env"
98
+ and select "Edit environment variables for your account". Select the `Path`
99
+ variable in the upper panel of the dialog that opens (or in the lower panel, if
100
+ you want to make the command-line PostgreSQL client visible to all users), and
101
+ click the `Edit` button. Then press the `New` button and add
102
+ `%ProgramFiles%\PostgreSQL\bin` to the `Path` environmane variable. Finally,
103
+ click `OK` to close all dialogs and exit the Windows Settings. Alternatively,
104
+ you can do it via PowerShell like this:
105
+
106
+ ```powershell
107
+ [System.Environment]::SetEnvironmentVariable("Path", $env:Path + ";%ProgramFiles%\PostgreSQL\bin", [System.EnvironmentVariableTarget]::User)
108
+ ```
109
+
110
+ If you want the tools to be available to all users on the machine, instead of
111
+ only to the current one, use `Machine` instead of `User` in the above command.
112
+ However, you'll have to do this from a PowerShell prompt with `Administrator`
113
+ privileges.
114
+
115
+ Log in as the user `postgres` (the PostgreSQL administrator) and create the
116
+ honeypot-related database users, the database, and grant proper privileges to it
117
+ to the users:
118
+
119
+ ```psql
120
+ PS C:\pgsqlpot-workdir> psql
121
+ postgres=# create user pgsqlpot with password 'PASSWORD HERE';
122
+ postgres=# create database pgsqlpot;
123
+ postgres=# grant all privileges on database pgsqlpot to pgsqlpot;
124
+ ```
125
+
126
+ (Make sure you specify a proper password that you want to use for the user
127
+ `pgsqlpot` instead of 'PASSWORD HERE'.)
128
+
129
+ If you're going to use a third-party tool for accessing the data from the
130
+ database (e.g., [Grafana](https://www.grafana.com) for visualizing the data),
131
+ it is advisable also to create a separate user that has read-only privileges
132
+ to the database and have the third-party tool access the database as that
133
+ user, so that in case the third-party tool contains some kind of vulnerability
134
+ and is breached (and the attacker obtains the database user password from it),
135
+ the attacker cannot modify the database:
136
+
137
+ ```psql
138
+ postgres=# create user pgsqlpotReadOnly with password 'OTHER PASSWORD HERE';
139
+ postgres=# grant select on database pgsqlpot to pgsqlpot;
140
+ ```
141
+
142
+ (Make sure you specify a proper password that you want to use for the user
143
+ `pgsqlpotReadOnly` instead of 'OTHER PASSWORD HERE'.)
144
+
145
+ Finally, exit `psql`:
146
+
147
+ ```psql
148
+ postgres=# \q
149
+ ```
150
+
151
+ The database is already created but it is completely empty. Now we have to
152
+ specify its schema (tables and indexes):
153
+
154
+ ```powershell
155
+ PS C:\pgsqlpot-workdir> psql -f C:\pgsqlpot-workdir\docs\postgres\postgres.sql -W pgsqlpot pgsqlpot
156
+ ```
157
+
158
+ You will be prompted for the password of the database user `pgsqlpot`.
159
+
160
+ If your database does not reside on your local machine but is on some remote
161
+ database server, use the options `-h host` and `-p port` of `psql` to specify
162
+ how to connect to it.
163
+
164
+ ## Honeypot Configuration
165
+
166
+ Add the following entries to the file `C:\pgsqlpot-workdir\etc\honeypot.cfg`
167
+
168
+ ```honeypot.cfg
169
+ [output_postgres]
170
+ enabled = true
171
+ debug = false
172
+ host = localhost
173
+ port = 5432
174
+ username = pgsqlpot
175
+ password = secret
176
+ database = pgsqlpot
177
+ # Whether to store geolocation data in the database
178
+ geoip = true
179
+ # Location of the databases used for geolocation
180
+ geoip_citydb = data/GeoLite2-City.mmdb
181
+ geoip_asndb = data/GeoLite2-ASN.mmdb
182
+ ```
183
+
184
+ Make sure that you specify the correct information needed to connect to the
185
+ database (the options `host`, `port`, `username`, and `password`) and that the
186
+ options `geoip_citydb` and `geoip_asndb` point to the correct paths of the two
187
+ MaxMind geolocation databases. Also, if you prefer to keep the PostgreSQL
188
+ database under a different name, make sure that you specify its correct name
189
+ with the `database` option.
190
+
191
+ ## Restart the honeypot
192
+
193
+ ```powershell
194
+ PS C:\pgsqlpot-workdir> C:\pgsqlpot-env\scripts\activate.ps1
195
+ (pgsqlpot-env) PS C:\pgsqlpot-workdir> pgsqlpot restart
196
+ ```
@@ -0,0 +1,73 @@
1
+ CREATE TABLE IF NOT EXISTS connections (
2
+ id SERIAL PRIMARY KEY,
3
+ sess_no VARCHAR(32) NOT NULL,
4
+ time_stamp TIMESTAMP DEFAULT NULL,
5
+ ip VARCHAR(15) DEFAULT NULL,
6
+ remote_port INTEGER DEFAULT NULL,
7
+ operation SMALLINT DEFAULT NULL,
8
+ local_host VARCHAR(15) DEFAULT NULL,
9
+ local_port INTEGER DEFAULT NULL,
10
+ sensor SMALLINT DEFAULT NULL
11
+ );
12
+
13
+ CREATE INDEX IF NOT EXISTS time_idx ON connections (time_stamp);
14
+ CREATE INDEX IF NOT EXISTS ip_idx ON connections (ip);
15
+ CREATE INDEX IF NOT EXISTS ip2_idx ON connections (time_stamp, ip);
16
+
17
+ CREATE TABLE IF NOT EXISTS operations (
18
+ id SERIAL PRIMARY KEY,
19
+ op_name VARCHAR(63) NOT NULL
20
+ );
21
+
22
+ CREATE TABLE IF NOT EXISTS credentials (
23
+ id SERIAL PRIMARY KEY,
24
+ sess_no VARCHAR(32) NOT NULL,
25
+ username SMALLINT DEFAULT NULL,
26
+ passwd SMALLINT DEFAULT NULL
27
+ );
28
+
29
+ CREATE TABLE IF NOT EXISTS usernames (
30
+ id SERIAL PRIMARY KEY,
31
+ username VARCHAR(255) DEFAULT NULL
32
+ );
33
+
34
+ CREATE TABLE IF NOT EXISTS passwords (
35
+ id SERIAL PRIMARY KEY,
36
+ passwd VARCHAR(255) DEFAULT NULL
37
+ );
38
+
39
+ CREATE TABLE IF NOT EXISTS variables (
40
+ id SERIAL PRIMARY KEY,
41
+ sess_no VARCHAR(32) NOT NULL,
42
+ var SMALLINT DEFAULT NULL,
43
+ val SMALLINT DEFAULT NULL
44
+ );
45
+
46
+ CREATE TABLE IF NOT EXISTS vars (
47
+ id SERIAL PRIMARY KEY,
48
+ var_name VARCHAR(255) DEFAULT NULL
49
+ );
50
+
51
+ CREATE TABLE IF NOT EXISTS var_values (
52
+ id SERIAL PRIMARY KEY,
53
+ var_value VARCHAR(255) DEFAULT NULL
54
+ );
55
+
56
+ CREATE TABLE IF NOT EXISTS sensors (
57
+ id SERIAL PRIMARY KEY,
58
+ sname VARCHAR(255) DEFAULT NULL
59
+ );
60
+
61
+ CREATE UNIQUE INDEX name_idx ON sensors (sname);
62
+
63
+ CREATE TABLE IF NOT EXISTS geolocation (
64
+ id SERIAL PRIMARY KEY,
65
+ ip VARCHAR(15) DEFAULT NULL,
66
+ country_name VARCHAR(45) DEFAULT '',
67
+ country_iso_code VARCHAR(2) DEFAULT '',
68
+ city_name VARCHAR(128) DEFAULT '',
69
+ org VARCHAR(128) DEFAULT '',
70
+ org_asn INTEGER DEFAULT NULL
71
+ );
72
+
73
+ CREATE UNIQUE INDEX ip3_idx ON geolocation (ip);
@@ -0,0 +1,68 @@
1
+ # Sending the output of the honeypot to a Slack channel
2
+
3
+ This guide describes how to send the reports from the honeypot to a Slack
4
+ channel.
5
+
6
+ ## Prerequisites
7
+
8
+ - Working honeypot installation
9
+ - A Slack account (workspace)
10
+
11
+ ## Create a channel for the honeypot's reports
12
+
13
+ - Go to [Slack](https://slack.com) and log into your account (workspace) there.
14
+ - Click the "LAUNCH SLACK" button. Slack will open in a new browser tab.
15
+ - On the vertical planel on the left, click on the *right* side of the word
16
+ `Channels` and select **Create**->**Create channel** from the menu that
17
+ appears.
18
+ - Enter some descriptive name, e.g., `pgsqlpot` in the field `Name` on the
19
+ dialog that appears.
20
+ - Click the **Next** button.
21
+ - Select the kind of channel you want - public or private on the dialog that
22
+ appears.
23
+ - Click the **Create** button.
24
+
25
+ ## Create an app (bot)
26
+
27
+ - Open a new browser tab and go to the URL
28
+ [https://api.slack.com/apps](https://api.slack.com/apps). You
29
+ have to do it manually; there doesn't seem to be a way to go there from
30
+ Slack's user interface.
31
+ - Click on the big green **Create New App** button on the right.
32
+ - Choose to create an app **From scratch** on the dialog that appears.
33
+ - Enter the app name (e.g., `Honeypot Reporter`) and select your workspace,
34
+ then click on the **Create App** button. This will take you to the app
35
+ configuration page.
36
+ - [OPTIONAL] In the dialog at the very bottom of the **Basic Information**
37
+ section, enter a short description for your bot (e.g., "Reports connections
38
+ to our honeypots"), choose a background color (e.g., `#2C2D30`; this field
39
+ cannot be empty), and choose an image (size must be between 512x512 and
40
+ 2000x2000) for your bot's icon, then click the **Save Changes** button at
41
+ the bottom.
42
+ - Go to the **OAuth & Permissions** section in the vertical bar on the right.
43
+ - Near the bottom, in the **Scopes** section, click on the **Add an OAuth Scope**
44
+ button and select **chat:write** from the dialog that appears. Your bot does
45
+ not need any other permission.
46
+ - A bit higher on the page (still on the **OAuth & Permissions** page), go
47
+ to the **OAuth Tokens for Your Workspace** section and click on the
48
+ **Install to Workspace** button. You'll be asked for confirmation; allow it.
49
+ - A new field labeled **Bot User OAuth Token** will appear in the section
50
+ **OAuth Tokens for Your Workspace**. Copy it; you'll have to put it in the
51
+ honeypot's config file.
52
+
53
+ ## Add the bot to the channel
54
+
55
+ - Go back to the browser tab with the Slack application.
56
+ - Select the created channel `#pgsqlpot`.
57
+ - Enter the command to invite your bot (`/invite @honeypot_reporter`) in the
58
+ area where you normally enter messages to be posted to the channel.
59
+
60
+ ## Configure the honeypot to use the bot
61
+
62
+ - Uncomment the `[output_slack]` section in the file `honeypot.cfg`.
63
+ - Set the variable `channel` to the name of the channel you created (e.g.,
64
+ `pgsqlpot`).
65
+ - Set the variable `token` to the bot token you copied when creating the bot.
66
+ - Set the variable `enabled` to `true`.
67
+ - Save the file.
68
+ - Launch the honeypot.
@@ -0,0 +1,131 @@
1
+ # Sending the Output of the Honeypot to an SQLite3 Database
2
+
3
+ (For installation on Windows, see the corresponding [installation document](READMEWIN.md))
4
+
5
+ - [Sending the Output of the Honeypot to an SQLite3 Database](#sending-the-output-of-the-honeypot-to-an-sqlite3-database)
6
+ - [Prerequisites](#prerequisites)
7
+ - [Installation](#installation)
8
+ - [SQLite3 Database Creation](#sqlite3-database-creation)
9
+ - [Honeypot Configuration](#honeypot-configuration)
10
+ - [Restart the honeypot](#restart-the-honeypot)
11
+
12
+ ## Prerequisites
13
+
14
+ - Working honeypot installation
15
+ - SQLite3 (Can be downloaded from the [official site](https://sqlite.org/download.html))
16
+
17
+ ## Installation
18
+
19
+ When writing to an SQLite3 database, the honeypot uses the free databases
20
+ provided by MaxMind for the purposes of geoloacting the IP addresses.
21
+ Start by installing the library necessary to work with these databases
22
+ from an account that can sudo (i.e., not from the user `pgsqlpot`):
23
+
24
+ ```bash
25
+ sudo add-apt-repository ppa:maxmind/ppa
26
+ sudo apt-get update
27
+ sudo apt-get install sqlite3 geoipupdate
28
+ ```
29
+
30
+ Now switch to the `pgsqlpot` user:
31
+
32
+ ```bash
33
+ sudo su - pgsqlpot
34
+ cd pgsqlpot-workdir
35
+ ```
36
+
37
+ Go to the directory `data`, where the gelolocation databases will reside:
38
+
39
+ ```bash
40
+ cd data
41
+ ```
42
+
43
+ Create in this directory a file named `geoip.cfg` with the following contents:
44
+
45
+ ```geoip.cfg
46
+ AccountID <ACCOUNT>
47
+ LicenseKey <KEY>
48
+ EditionIDs GeoLite2-City GeoLite2-ASN
49
+ DatabaseDirectory /home/pgsqlpot/pgsqlpot-workdir/data
50
+ LockFile /home/pgsqlpot/pgsqlpot-workdir/data/.geoipupdate.lock
51
+ ```
52
+
53
+ Change the paths in the options `DatabaseDirectory` and `LockFile` if you
54
+ have opted to use paths different from the ones suggested by the
55
+ honeypot installation documentation. Make sure you replace `<ACCOUNT>`
56
+ and `<KEY>` with the account and API key obtained from MaxMind.
57
+
58
+ In order to be able to download the MaxMind geolocation databases (either
59
+ manually or in an automated way), you need a (free) account at their site.
60
+ You can create such an account [there](https://www.maxmind.com/en/geolite2/signup).
61
+ Creating it involves choosing a user name and a password, providing some
62
+ personal data like country of residence, industry in which you're working,
63
+ intended use for their databases, an e-mail address, and also agreeing with
64
+ their terms and conditions. Once the account is created, you can get your
65
+ AccountID and LicenseKey from it.
66
+
67
+ Download the latest version of the Maxmind geolocation databases:
68
+
69
+ ```bash
70
+ geoipupdate -f geoip.cfg
71
+ ```
72
+
73
+ To have the database updated automatically (it is updated on MaxMind's site
74
+ every second Tuesday of each month, so download it every second Wednesday),
75
+ create a crontab job (`crontab -e`) and enter the following:
76
+
77
+ ```crontab
78
+ # Update the geoIP database at midnight on the 2nd Wednesday of each month:
79
+ 0 0 8-14 * * [ $(/bin/date +\%u) -eq 3 ] && /usr/bin/geoipupdate -f /home/pgsqlpot/pgsqlpot-workdir/data/geoip.cfg
80
+ ```
81
+
82
+ Alternatively, if you already have the MaxMind geolocation databases installed
83
+ and updated on your machine in some other place, use their respective paths in
84
+ the `[output_sqlite]` section of the file `honeypot.cfg`, as mentioned
85
+ below.
86
+
87
+ Finally, return to the main directory of the project:
88
+
89
+ ```bash
90
+ cd ..
91
+ ```
92
+
93
+ ## SQLite3 Database Creation
94
+
95
+ First, create a database named `pgsqlpot.db`, residing in the `data` directory
96
+ and based on the schema `docs/sqlite3/sqlite3.sql`:
97
+
98
+ ```bash
99
+ sqlite3 ~/pgsqlpot-workdir/data/pgsqlpot.db < docs/sqlite3/sqlite3.sql
100
+ ```
101
+
102
+ If you have opted on keeping the database elsewhere, use its proper path
103
+ instead of `~/pgsqlpot-workdir/data/pgsqlpot.db`.
104
+
105
+ ## Honeypot Configuration
106
+
107
+ Add the following entries to the file `~/pgsqlpot-workdir/etc/honeypot.cfg`
108
+
109
+ ```honeypot.cfg
110
+ [output_sqlite]
111
+ enabled = true
112
+ debug = false
113
+ db_file = data/pgsqlpot.db
114
+ # Whether to store geolocation data in the database
115
+ geoip = true
116
+ # Location of the databases used for geolocation
117
+ geoip_citydb = data/GeoLite2-City.mmdb
118
+ geoip_asndb = data/GeoLite2-ASN.mmdb
119
+ ```
120
+
121
+ Make sure the options `geoip_citydb` and `geoip_asndb` point to the correct
122
+ paths of the two MaxMind geolocation databases. Also, if you prefer to keep
123
+ the SQLite3 database elsewhere, make sure that you specify its correct path
124
+ with the `db_file` option.
125
+
126
+ ## Restart the honeypot
127
+
128
+ ```bash
129
+ source ~/pgsqlpot-env/bin/activate
130
+ pgsqlpot restart
131
+ ```