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,270 @@
1
+ <#
2
+
3
+ .SYNOPSIS
4
+
5
+ Create the task for automatic updating of the GeoIP database
6
+
7
+ .DESCRIPTION
8
+
9
+ This PowerShell script creates (or removes) the Windows task that
10
+ automatically updates MaxMind's GeoIP database every second Wednesday
11
+ of the month. If the task with the specified name and in the specified
12
+ folder already exists, it's properties will be modified as specified
13
+ by the other options.
14
+
15
+ .PARAMETER taskName
16
+
17
+ Name of the updating task (default: "GeoIPUpdate").
18
+
19
+ .PARAMETER taskDescription
20
+
21
+ Description of the task (default: "GeoIP database updater")
22
+
23
+ .PARAMETER taskPath
24
+
25
+ Path of the updater task (default: "\")
26
+
27
+ .PARAMETER runTime
28
+
29
+ Time of the day when the task should be run (default: "00:00:00").
30
+
31
+ .PARAMETER geoipupdate
32
+
33
+ Path to the program "geoipupdate.exe" (default: "geoipupdate.exe")
34
+
35
+ .PARAMETER geoipconfig
36
+
37
+ Path to the config for for the program "geoipupdate.exe" (default: "geoip.cfg")
38
+
39
+ .PARAMETER remove
40
+
41
+ Delete the task with the specified name instead of creating it.
42
+
43
+ .PARAMETER silent
44
+
45
+ Do not display any information messages.
46
+
47
+ .PARAMETER help
48
+
49
+ Show short usage help and exit.
50
+
51
+ .EXAMPLE
52
+
53
+ .\geoipupdtask.ps1
54
+
55
+ Creates a task named "GeoIPUpdate" that runs at 00:00 every second
56
+ Wednesday of the month and updates the GeoIP database.
57
+
58
+ .EXAMPLE
59
+
60
+ .\geoipupdtask.ps1 -taskname "GeoIP Updater" -runtime 03:15
61
+
62
+ Creates a task named "GeoIP Updater" that runs at 03:15:00 every second
63
+ Wednesday of the month and updates the GeoIP database.
64
+
65
+ .EXAMPLE
66
+
67
+ .\geoipupdtask.ps1 -remove
68
+
69
+ Removes the task named "GeoIPUpdate".
70
+
71
+ #>
72
+
73
+ [CmdletBinding()]
74
+ Param (
75
+ [string] $taskName = "GeoIPUpdate", # Task name
76
+ [string] $taskDescription = "GeoIP database updater", # Task description
77
+ [string] $taskPath = "\", # Task path
78
+ [string] $runTime = "00:00:00", # Time of the day at which the task will run
79
+ [string] $geoipupdate = "geoipupdate.exe", # Path to the program geoipupdate.exe
80
+ [string] $geoipconfig = "geoip.cfg", # Path to the config file of the program geoipupdate.exe
81
+ [switch] $remove, # Remove the task instead of creating it
82
+ [switch] $silent, # If specified, the information messages are suppressed
83
+ [switch] $help # Show usage help and exit
84
+ )
85
+
86
+ $ErrorActionPreference = "Stop"
87
+
88
+ function removeTask {
89
+ Param (
90
+ [string] $taskName = "GeoIPUpdate",
91
+ [string] $taskPath = "\",
92
+ [bool] $silent = $false
93
+ )
94
+ $task = Get-ScheduledTask -TaskName $taskName -TaskPath $taskPath -ErrorAction SilentlyContinue
95
+ if (-not $task) {
96
+ Write-Host "The task '$taskName' does not exist." -ForegroundColor Red
97
+ return 1
98
+ }
99
+ if (-not $silent) {
100
+ Write-Output "Removing the task named '$taskPath$taskName'."
101
+ }
102
+ Unregister-ScheduledTask -TaskPath $taskPath -TaskName $taskName -Confirm: $false
103
+ return 0
104
+ }
105
+
106
+ Function ConvertTo-BitFlag {
107
+ [OutputType([int])]
108
+ param (
109
+ [Parameter(Mandatory, ValueFromPipeline)]
110
+ [int[]]
111
+ $InputObject
112
+ )
113
+
114
+ begin {
115
+ $val = 0
116
+ }
117
+ process {
118
+ foreach ($i in $InputObject) {
119
+ $val = $val -bor (1 -shl ($i - 1))
120
+ }
121
+ }
122
+ end {
123
+ $val
124
+ }
125
+ }
126
+
127
+ function createTask {
128
+ Param (
129
+ [string] $taskName = "GeoIPUpdate",
130
+ [string] $taskDescription = "GeoIP database updater",
131
+ [string] $taskPath = "\",
132
+ [string] $runTime = "00:00:00",
133
+ [string] $geoipupdate,
134
+ [string] $geoipconfig,
135
+ [bool] $silent = $false
136
+ )
137
+ try {
138
+ $parsedTime = [TimeSpan]::Parse($runTime)
139
+ }
140
+ catch {
141
+ Write-Host "'$runTime' is not a valid time." -ForegroundColor Red
142
+ return 1
143
+ }
144
+
145
+ if (-not $taskPath.StartsWith("\")) {
146
+ $taskPath = "\" + $taskPath
147
+ }
148
+ if (-not $taskPath.EndsWith("\")) {
149
+ $taskPath = $taskPath + "\"
150
+ }
151
+
152
+ $task = Get-ScheduledTask -TaskName $taskName -TaskPath $taskPath -ErrorAction SilentlyContinue
153
+
154
+ if (-not $silent) {
155
+ if ($task) {
156
+ Write-Host "The task '$taskPath$taskName' already exists."
157
+ Write-Host "Its properties will be modified accordingly."
158
+ Write-Host "Task description set to '$taskDescription'."
159
+ }
160
+ else {
161
+ Write-Host "Creating task named '$taskPath$taskName', described as '$taskDescription'."
162
+ }
163
+ Write-Host "The task will be run at $parsedTime every 2nd Wednesday of the month."
164
+ Write-Host "It will execute the program '`"$geoipupdate`"' with the arguments '-f `"$geoipconfig`"'."
165
+ }
166
+
167
+ $TASK_ACTION_EXEC = 0
168
+ $TASK_LOGON_S4U = 2
169
+ $TASK_TRIGGER_MONTHLYDOW = 5
170
+ $TASK_CREATE_OR_UPDATE = 6
171
+ $TASK_COMPATIBILITY_V2_4 = 6
172
+
173
+ $start = (Get-Date).ToString("yyyy-MM-dd") + "T" + $runTime
174
+ $daysOfWeek = @([DayOfWeek]::Wednesday)
175
+ $weeksOfMonth = @(2)
176
+ $monthsOfYear = @(1..12)
177
+
178
+ $service = New-Object -ComObject Schedule.Service
179
+ $service.Connect()
180
+
181
+ try {
182
+ $folder = $service.GetFolder($taskPath)
183
+ }
184
+ catch {
185
+ if (-not $silent) {
186
+ Write-Host "Task folder '$taskPath' does not exist. Creating it."
187
+ }
188
+ $folderName = $taskPath.Trim('\')
189
+
190
+ if ($folderName -eq "") {
191
+ $folder = $service.GetFolder("\")
192
+ }
193
+ else {
194
+ $pathParts = $folderName -split '\\'
195
+ $currentFolder = $service.GetFolder("\")
196
+
197
+ foreach ($part in $pathParts) {
198
+ if ($part -ne "") {
199
+ try {
200
+ $currentFolder = $currentFolder.GetFolder($part)
201
+ }
202
+ catch {
203
+ $currentFolder = $currentFolder.CreateFolder($part)
204
+ }
205
+ }
206
+ }
207
+
208
+ $folder = $currentFolder
209
+ }
210
+ }
211
+
212
+ $task = $service.NewTask(0)
213
+ $task.RegistrationInfo.Description = $taskDescription
214
+ $action = $task.Actions.Create($TASK_ACTION_EXEC)
215
+ $trigger = $task.Triggers.Create($TASK_TRIGGER_MONTHLYDOW)
216
+ $settings = $task.Settings
217
+
218
+ $action.Path = "`"$geoipupdate`""
219
+ $action.Arguments = "-f `"$geoipconfig`""
220
+
221
+ $trigger.StartBoundary = $start
222
+ $trigger.DaysOfWeek = $daysOfWeek | ForEach-Object { $_ + 1 } | ConvertTo-BitFlag
223
+ $trigger.WeeksOfMonth = $weeksOfMonth | ConvertTo-BitFlag
224
+ $trigger.MonthsOfYear = $monthsOfYear | ConvertTo-BitFlag
225
+
226
+ $settings.Compatibility = $TASK_COMPATIBILITY_V2_4
227
+ $settings.StartWhenAvailable = $true
228
+ $settings.Hidden = $true
229
+ $settings.RunOnlyIfNetworkAvailable = $true
230
+ $settings.DisallowStartIfOnBatteries = $false
231
+
232
+ $null = $folder.RegisterTaskDefinition($taskName, $task, $TASK_CREATE_OR_UPDATE, $null, $null, $TASK_LOGON_S4U)
233
+
234
+ return 0
235
+ }
236
+
237
+ if ($help) {
238
+ $scriptName = $MyInvocation.MyCommand.Name
239
+ Write-Host "Usage: $scriptName [[-taskname] TaskName] [[-taskdescription] TaskDescription] [[-taskpath] TaskPath]"
240
+ Write-Host "`t`t`t[[-geoipupdate] GeoIPUpdateProg] [[-geoipconfig] GeoIPUpdateConf]"
241
+ Write-Host "`t`t`t[[-runtime] RunTime] [-remove] [-silent] [-help]"
242
+ Write-Host "`tTaskName`tTask name (default: 'GeoIPUpdate')"
243
+ Write-Host "`tTaskDescription`tTask description (default: 'GeoIP database updater')"
244
+ Write-Host "`tTaskPath`tTask path; specify both leading and trailing '\' (default: '\')"
245
+ Write-Host "`tRunTime`t`tTime of the day at which the task should run (default: '00:00:00')"
246
+ Write-Host "`tGeoIPUpdateProg`tPath to the program 'geoipupdate.exe' (default: 'geoipupdate.exe')"
247
+ Write-Host "`tGeoIPUpdateConf`tPath to the config file of the program 'geoipupdate.exe' (default: 'geoip.cfg')"
248
+ Write-Host "`tremove`t`tRemove the task (if it exists) instead of creating it"
249
+ Write-Host "`tsilent`t`tSuppress information messages"
250
+ Write-Host "`thelp`t`tShow this help and exit"
251
+ Exit
252
+ }
253
+
254
+ if (-not(Test-Path -path $geoipconfig)) {
255
+ Write-Host "Cannot find the file '$geoipconfig'." -ForegroundColor Red
256
+ Exit 1
257
+ }
258
+
259
+ if ($null -eq (Get-Command $geoipupdate -ErrorAction SilentlyContinue)) {
260
+ Write-Host "Cannot find the program '$geoipupdate'." -ForegroundColor Red
261
+ Exit 1
262
+ }
263
+
264
+ if ($remove) {
265
+ $errorcode = removeTask $taskName $taskPath $silent
266
+ } else {
267
+ $errorcode = createTask $taskName $taskDescription $taskPath $runTime $geoipupdate $geoipconfig $silent
268
+ }
269
+
270
+ Exit $errorcode
@@ -0,0 +1,176 @@
1
+ # Sending the Output of the Honeypot to a MySQL Database
2
+
3
+ (For installation on Windows, see the corresponding [installation document](READMEWIN.md))
4
+
5
+ - [Sending the Output of the Honeypot to a MySQL Database](#sending-the-output-of-the-honeypot-to-a-mysql-database)
6
+ - [Prerequisites](#prerequisites)
7
+ - [Installation](#installation)
8
+ - [MySQL Configuration](#mysql-configuration)
9
+ - [Honeypot Configuration](#honeypot-configuration)
10
+ - [Restart the honeypot](#restart-the-honeypot)
11
+
12
+ ## Prerequisites
13
+
14
+ - Working honeypot installation
15
+ - MySQL Server installation
16
+
17
+ **Note on Python 2.7:** Prebuilt `mysqlclient` wheels are not available for
18
+ Python 2.7. You will need `libmysqlclient-dev` installed system-wide and a C
19
+ compiler available to build it from source. On Python 3.x this is not an
20
+ issue as prebuilt wheels are available via PyPI.
21
+
22
+ ## Installation
23
+
24
+ When writing to a MySQL database, the honeypot uses the free databases
25
+ provided by MaxMind for the purposes of geoloacting the IP addresses.
26
+ Start by installing the library necessary to work with these databases
27
+ from an account that can sudo (i.e., not from the user `pgsqlpot`):
28
+
29
+ ```bash
30
+ sudo add-apt-repository ppa:maxmind/ppa
31
+ sudo apt-get update
32
+ sudo apt-get install libmysqlclient-dev geoipupdate
33
+ ```
34
+
35
+ Now switch to the `pgsqlpot` user:
36
+
37
+ ```bash
38
+ sudo su - pgsqlpot
39
+ cd ~/pgsqlpot-workdir
40
+ ```
41
+
42
+ Go to the directory `data`, where the geolocation databases will reside:
43
+
44
+ ```bash
45
+ cd data
46
+ ```
47
+
48
+ Create in this directory a file named `geoip.cfg` with the following contents:
49
+
50
+ ```geoip.cfg
51
+ AccountID <ACCOUNT>
52
+ LicenseKey <KEY>
53
+ EditionIDs GeoLite2-City GeoLite2-ASN
54
+ DatabaseDirectory /home/pgsqlpot/pgsqlpot-workdir/data
55
+ LockFile /home/pgsqlpot/pgsqlpot-workdir/data/.geoipupdate.lock
56
+ ```
57
+
58
+ Change the paths in the options `DatabaseDirectory` and `LockFile` if you
59
+ have opted to use paths different from the ones suggested by the
60
+ honeypot installation documentation. Make sure you replace `<ACCOUNT>`
61
+ and `<KEY>` with the account and API key obtained from MaxMind.
62
+
63
+ In order to be able to download the MaxMind geolocation databases (either
64
+ manually or in an automated way), you need a (free) account at their site.
65
+ You can create such an account [there](https://www.maxmind.com/en/geolite2/signup).
66
+ Creating it involves choosing a user name and a password, providing some
67
+ personal data like country of residence, industry in which you're working,
68
+ intended use for their databases, an e-mail address, and also agreeing with
69
+ their terms and conditions. Once the account is created, you can get your
70
+ AccountID and LicenseKey from it.
71
+
72
+ Download the latest version of the Maxmind geolocation databases:
73
+
74
+ ```bash
75
+ geoipupdate -f geoip.cfg
76
+ ```
77
+
78
+ To have the database updated automatically (it is updated on MaxMind's site
79
+ every second Tuesday of each month, so download it every second Wednesday),
80
+ create a crontab job (`crontab -e`) and enter the following:
81
+
82
+ ```crontab
83
+ # Update the geoIP database at midnight on the 2nd Wednesday of each month:
84
+ 0 0 8-14 * * [ $(/bin/date +\%u) -eq 3 ] && /usr/bin/geoipupdate -f /home/pgsqlpot/pgsqlpot-workdir/data/geoip.cfg
85
+ ```
86
+
87
+ Alternatively, if you already have the MaxMind geolocation databases installed
88
+ and updated on your machine in some other place, use their respective paths in
89
+ the `[output_mysql]` section of the file `honeypot.cfg`, as mentioned
90
+ below.
91
+
92
+ ## MySQL Configuration
93
+
94
+ First create a database named `pgsqlpot` and grant access to it to a user
95
+ named `pgsqlpot`:
96
+
97
+ ```bash
98
+ $ mysql -p -u root
99
+ MySQL> CREATE DATABASE IF NOT EXISTS pgsqlpot;
100
+ MySQL> CREATE USER IF NOT EXISTS 'pgsqlpot'@'localhost' IDENTIFIED WITH mysql_native_password BY 'PASSWORD HERE' PASSWORD EXPIRE NEVER;
101
+ MySQL> GRANT ALTER, ALTER ROUTINE, CREATE, CREATE ROUTINE, CREATE TEMPORARY TABLES, CREATE VIEW, DELETE, DROP, EXECUTE, INDEX, INSERT, LOCK TABLES, SELECT, SHOW VIEW, TRIGGER, UPDATE ON pgsqlpot.* TO 'pgsqlpot'@'localhost';
102
+ ```
103
+
104
+ (Make sure you specify a proper password that you want to use for the user
105
+ `pgsqlpot` instead of 'PASSWORD HERE'.)
106
+
107
+ If you're going to use a third-party tool for accessing the data from the
108
+ database (e.g., [Grafana](https://www.grafana.com) for visualizing the data),
109
+ it is advisable also to create a separate user that has read-only privileges
110
+ to the database and have the third-party tool access the database as that
111
+ user, so that in case the third-party tool contains some kind of vulnerability
112
+ and is breached (and the attacker obtains the database user password from it),
113
+ the attacker cannot modify the database:
114
+
115
+ ```bash
116
+ MySQL> CREATE USER IF NOT EXISTS 'pgsqlpotReadOnly'@'localhost' IDENTIFIED WITH mysql_native_password BY 'OTHER PASSWORD HERE' PASSWORD EXPIRE NEVER;
117
+ MySQL> GRANT SELECT ON pgsqlpot.* TO 'pgsqlpotReadOnly'@'localhost';
118
+ ```
119
+
120
+ (Make sure you specify a proper password that you want to use for the user
121
+ `pgsqlpotReadOnly` instead of 'OTHER PASSWORD HERE'.)
122
+
123
+ Finally, make sure that the user-related changes are committed to the database:
124
+
125
+ ```mysql
126
+ MySQL> FLUSH PRIVILEGES;
127
+ MySQL> exit
128
+ ```
129
+
130
+ Next, load the database schema:
131
+
132
+ ```bash
133
+ $ cd ~/pgsqlpot-workdir
134
+ $ mysql -p -u pgsqlpot pgsqlpot
135
+ MySQL> source ./docs/mysql/mysql.sql;
136
+ MySQL> exit
137
+ ```
138
+
139
+ ## Honeypot Configuration
140
+
141
+ Add the following entries to the file `~/pgsqlpot-workdir/etc/honeypot.cfg`
142
+
143
+ ```honeypot.cfg
144
+ [output_mysql]
145
+ enabled = true
146
+ host = localhost
147
+ database = pgsqlpot
148
+ username = pgsqlpot
149
+ password = PASSWORD HERE
150
+ port = 3306
151
+ # Whether to store geolocation data in the database
152
+ geoip = true
153
+ # Location of the databases used for geolocation
154
+ geoip_citydb = data/GeoLite2-City.mmdb
155
+ geoip_asndb = data/GeoLite2-ASN.mmdb
156
+ ```
157
+
158
+ Make sure you use the password you specified for the MySQL user `pgsqlpot`
159
+ instead of 'PASSWORD HERE'. Make sure the options `geoip_citydb` and
160
+ `geoip_asndb` point to the correct paths of the two MaxMind geolocation
161
+ databases.
162
+
163
+ Since the file `honeypot.cfg` contains in cleartext the password for
164
+ the database, it would be a good idea to change its permissions so that only
165
+ the user `pgsqlpot` can access it:
166
+
167
+ ```bash
168
+ chmod g-r,g-w,o-r,o-w ~/pgsqlpot-workdir/etc/honeypot.cfg
169
+ ```
170
+
171
+ ## Restart the honeypot
172
+
173
+ ```bash
174
+ source ~/pgsqlpot-env/bin/activate
175
+ pgsqlpot restart
176
+ ```
@@ -0,0 +1,157 @@
1
+ # Sending the Output of the Honeypot to a MySQL Database
2
+
3
+ - [Sending the Output of the Honeypot to a MySQL Database](#sending-the-output-of-the-honeypot-to-a-mysql-database)
4
+ - [Prerequisites](#prerequisites)
5
+ - [Installation](#installation)
6
+ - [MySQL Configuration](#mysql-configuration)
7
+ - [Honeypot Configuration](#honeypot-configuration)
8
+ - [Restart the honeypot](#restart-the-honeypot)
9
+
10
+ ## Prerequisites
11
+
12
+ - Working honeypot installation
13
+ - MySQL Server installation
14
+
15
+ ## Installation
16
+
17
+ When writing to a MySQL database, the honeypot uses the free databases provided
18
+ 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), log
57
+ in as Administrator (or launch an elevated PowerShell window, if the user
58
+ `HoneyPotter` is allowed to do it) and run the script `geoipupdtask.ps1` in the
59
+ working subdirectory:
60
+
61
+ ```powershell
62
+ PS C:\pgsqlpot-workdir\data> ..\geoipupdtask.ps1
63
+ ```
64
+
65
+ It expects that the program `geoipupdate.exe` resides in one of the directories
66
+ listed in the `PATH` variable of the environment, that the configuration file
67
+ for it is named `geoip.cfg` and resides in the current directory, and that the
68
+ updating task is to be run at 00:00. Also, it creates an updating task named
69
+ `GeoIPUpdate`, which resides in the task folder `\` and has the description
70
+ `GeoIP database updater`. You can change any of these parameters via
71
+ command-line options to the script:
72
+
73
+ ```powershell
74
+ 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"
75
+ ```
76
+
77
+ If you already have the MaxMind geolocation databases installed and updated on
78
+ your machine in some other place, use their respective paths in the
79
+ `[output_mysql]` section of the file `honeypot.cfg`, as mentioned below.
80
+
81
+ ## MySQL Configuration
82
+
83
+ First create a database named `pgsqlpot` and grant access to it to a user
84
+ named `pgsqlpot`:
85
+
86
+ ```powershell
87
+ PS C:\> mysql -p -u root
88
+ MySQL> CREATE DATABASE IF NOT EXISTS pgsqlpot;
89
+ MySQL> CREATE USER IF NOT EXISTS 'pgsqlpot'@'localhost' IDENTIFIED WITH mysql_native_password BY 'PASSWORD HERE' PASSWORD EXPIRE NEVER;
90
+ MySQL> GRANT ALTER, ALTER ROUTINE, CREATE, CREATE ROUTINE, CREATE TEMPORARY TABLES, CREATE VIEW, DELETE, DROP, EXECUTE, INDEX, INSERT, LOCK TABLES, SELECT, SHOW VIEW, TRIGGER, UPDATE ON pgsqlpot.* TO 'pgsqlpot'@'localhost';
91
+ ```
92
+
93
+ (Make sure you specify a proper password that you want to use for the user
94
+ `pgsqlpot` instead of 'PASSWORD HERE'.)
95
+
96
+ If you're going to use a third-party tool for accessing the data from the
97
+ database (e.g., [Grafana](https://www.grafana.com) for visualizing the data),
98
+ it is advisable also to create a separate user that has read-only privileges
99
+ to the database and have the third-party tool access the database as that
100
+ user, so that in case the third-party tool contains some kind of vulnerability
101
+ and is breached (and the attacker obtains the database user password from it),
102
+ the attacker cannot modify the database:
103
+
104
+ ```mysql
105
+ MySQL> CREATE USER IF NOT EXISTS 'pgsqlpotReadOnly'@'localhost' IDENTIFIED WITH mysql_native_password BY 'OTHER PASSWORD HERE' PASSWORD EXPIRE NEVER;
106
+ MySQL> GRANT SELECT ON pgsqlpot.* TO 'pgsqlpotReadOnly'@'localhost';
107
+ ```
108
+
109
+ (Make sure you specify a proper password that you want to use for the user
110
+ `pgsqlpotReadOnly` instead of 'OTHER PASSWORD HERE'.)
111
+
112
+ Finally, make sure that the user-related changes are committed to the database:
113
+
114
+ ```mysql
115
+ MySQL> FLUSH PRIVILEGES;
116
+ MySQL> exit
117
+ ```
118
+
119
+ Next, load the database schema:
120
+
121
+ ```powershell
122
+ PS C:\> cd \pgsqlpot-workdir
123
+ PS C:\pgsqlpot-workdir> mysql -p -u pgsqlpot pgsqlpot
124
+ MySQL> source ./docs/mysql/mysql.sql;
125
+ MySQL> exit
126
+ ```
127
+
128
+ ## Honeypot Configuration
129
+
130
+ Add the following entries to the file `C:\pgsqlpot\etc\honeypot.cfg`
131
+
132
+ ```honeypot.cfg
133
+ [output_mysql]
134
+ enabled = true
135
+ host = localhost
136
+ database = pgsqlpot
137
+ username = pgsqlpot
138
+ password = PASSWORD HERE
139
+ port = 3306
140
+ # Whether to store geolocation data in the database
141
+ geoip = true
142
+ # Location of the databases used for geolocation
143
+ geoip_citydb = data/GeoLite2-City.mmdb
144
+ geoip_asndb = data/GeoLite2-ASN.mmdb
145
+ ```
146
+
147
+ Make sure you use the password you specified for the MySQL user `pgsqlpot`
148
+ instead of 'PASSWORD HERE'. Make sure the options `geoip_citydb` and
149
+ `geoip_asndb` point to the correct paths of the two MaxMind geolocation
150
+ databases.
151
+
152
+ ## Restart the honeypot
153
+
154
+ ```powershell
155
+ PS C:\pgsqlpot-workdir> C:\pgsqlpot-env\scripts\activate.ps1
156
+ (pgsqlpot-env) PS C:\pgsqlpot-workdir> pgsqlpot restart
157
+ ```
@@ -0,0 +1,85 @@
1
+ CREATE TABLE IF NOT EXISTS `connections` (
2
+ `id` INT NOT NULL AUTO_INCREMENT,
3
+ `session` CHAR(32) NOT NULL,
4
+ `timestamp` DATETIME DEFAULT NULL,
5
+ `operation` INT DEFAULT NULL,
6
+ `ip` VARCHAR(15) DEFAULT NULL,
7
+ `remote_port` INT DEFAULT NULL,
8
+ `local_host` VARCHAR(15) DEFAULT NULL,
9
+ `local_port` INT DEFAULT NULL,
10
+ `sensor` INT DEFAULT NULL,
11
+ PRIMARY KEY (`id`),
12
+ KEY `time_idx` (`timestamp`),
13
+ KEY `ip_idx` (`ip`),
14
+ KEY `ip2_idx` (`timestamp`, `ip`)
15
+ );
16
+
17
+ CREATE TABLE IF NOT EXISTS `operations` (
18
+ `id` INT NOT NULL AUTO_INCREMENT,
19
+ `op_name` VARCHAR(20) NOT NULL,
20
+ PRIMARY KEY (`id`),
21
+ UNIQUE (`op_name`)
22
+ );
23
+
24
+ CREATE TABLE IF NOT EXISTS `credentials` (
25
+ `id` INT NOT NULL AUTO_INCREMENT,
26
+ `session` CHAR(32) NOT NULL,
27
+ `username` INT DEFAULT NULL,
28
+ `password` INT DEFAULT NULL,
29
+ PRIMARY KEY (`id`)
30
+ );
31
+
32
+ CREATE TABLE IF NOT EXISTS `usernames` (
33
+ `id` INT NOT NULL AUTO_INCREMENT,
34
+ `username` VARCHAR(255) DEFAULT NULL,
35
+ PRIMARY KEY (`id`),
36
+ UNIQUE (`username`)
37
+ );
38
+
39
+ CREATE TABLE IF NOT EXISTS `passwords` (
40
+ `id` INT NOT NULL AUTO_INCREMENT,
41
+ `password` VARCHAR(255) DEFAULT NULL,
42
+ PRIMARY KEY (`id`),
43
+ UNIQUE (`password`)
44
+ );
45
+
46
+ CREATE TABLE IF NOT EXISTS `variables` (
47
+ `id` INT NOT NULL AUTO_INCREMENT,
48
+ `session` VARCHAR(32) NOT NULL,
49
+ `var` INT DEFAULT NULL,
50
+ `val` INT DEFAULT NULL,
51
+ PRIMARY KEY (`id`)
52
+ );
53
+
54
+ CREATE TABLE IF NOT EXISTS `vars` (
55
+ `id` INT NOT NULL AUTO_INCREMENT,
56
+ `var_name` VARCHAR(20) NOT NULL,
57
+ PRIMARY KEY (`id`),
58
+ UNIQUE(`var_name`)
59
+ );
60
+
61
+ CREATE TABLE IF NOT EXISTS `var_values` (
62
+ `id` INT NOT NULL AUTO_INCREMENT,
63
+ `var_value` VARCHAR(255),
64
+ PRIMARY KEY (`id`),
65
+ UNIQUE(`var_value`)
66
+ );
67
+
68
+ CREATE TABLE IF NOT EXISTS `sensors` (
69
+ `id` INT NOT NULL AUTO_INCREMENT,
70
+ `name` VARCHAR(255) DEFAULT NULL,
71
+ PRIMARY KEY (`id`),
72
+ UNIQUE (`name`)
73
+ );
74
+
75
+ CREATE TABLE IF NOT EXISTS `geolocation` (
76
+ `id` INT NOT NULL AUTO_INCREMENT,
77
+ `ip` VARCHAR(15) DEFAULT NULL,
78
+ `country_name` VARCHAR(45) DEFAULT '',
79
+ `country_iso_code` VARCHAR(2) DEFAULT '',
80
+ `city_name` VARCHAR(128) DEFAULT '',
81
+ `org` VARCHAR(128) DEFAULT '',
82
+ `org_asn` INT DEFAULT NULL,
83
+ PRIMARY KEY (`id`),
84
+ UNIQUE(`ip`)
85
+ );