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,400 @@
1
+ # Installation guide (on Ubuntu)
2
+
3
+ (For installation on Windows, see the corresponding [installation document](INSTALLWIN.md))
4
+
5
+ - [Installation guide (on Ubuntu)](#installation-guide-on-ubuntu)
6
+ - [Step 1: Install the dependencies](#step-1-install-the-dependencies)
7
+ - [Step 2: Open port 5432 for TCP traffic](#step-2-open-port-5432-for-tcp-traffic)
8
+ - [Step 3: Create a user account](#step-3-create-a-user-account)
9
+ - [Step 4: Install the honeypot](#step-4-install-the-honeypot)
10
+ - [Installing from PyPI (recommended)](#installing-from-pypi-recommended)
11
+ - [Installing from the repo](#installing-from-the-repo)
12
+ - [Step 5: Initialize the working directory](#step-5-initialize-the-working-directory)
13
+ - [Step 6: Create a configuration file](#step-6-create-a-configuration-file)
14
+ - [Step 7: Start the honeypot](#step-7-start-the-honeypot)
15
+ - [Step 8: Make the honeypot start at boot time](#step-8-make-the-honeypot-start-at-boot-time)
16
+ - [Configure additional output plugins (OPTIONAL)](#configure-additional-output-plugins-optional)
17
+ - [Docker usage (OPTIONAL)](#docker-usage-optional)
18
+ - [Command-line options](#command-line-options)
19
+ - [Upgrading the honeypot](#upgrading-the-honeypot)
20
+
21
+ ## Step 1: Install the dependencies
22
+
23
+ Install system-wide support for Python and pip:
24
+
25
+ ```bash
26
+ sudo apt-get update
27
+ sudo apt-get install python3 python3-pip
28
+ ```
29
+
30
+ If you plan to use the MySQL output plugin, also install the MySQL client
31
+ development library:
32
+
33
+ ```bash
34
+ sudo apt-get install libmysqlclient-dev
35
+ ```
36
+
37
+ ## Step 2: Open port 5432 for TCP traffic
38
+
39
+ If TCP port 5432 is not already opened for incoming connections on your
40
+ firewall and router, you must open it now. How exactly to do this from a NAT
41
+ router depends on the router model; please consult the instruction manual of
42
+ the router.
43
+
44
+ To open the port on the firewall, use:
45
+
46
+ ```bash
47
+ sudo ufw allow 5432/tcp
48
+ ```
49
+
50
+ ## Step 3: Create a user account
51
+
52
+ It is strongly recommended to run the honeypot as a dedicated non-root user
53
+ (named `pgsqlpot` in our example), who cannot `sudo`:
54
+
55
+ ```bash
56
+ $ sudo adduser --disabled-password pgsqlpot
57
+ Adding user `pgsqlpot' ...
58
+ Adding new group `pgsqlpot' (1019) ...
59
+ Adding new user `pgsqlpot' (1019) with group `pgsqlpot' ...
60
+ Creating home directory `/home/pgsqlpot' ...
61
+ Copying files from `/etc/skel' ...
62
+ Changing the user information for pgsqlpot
63
+ Enter the new value, or press ENTER for the default
64
+ Full Name []:
65
+ Room Number []:
66
+ Work Phone []:
67
+ Home Phone []:
68
+ Other []:
69
+ Is the information correct? [Y/n]
70
+ ```
71
+
72
+ Switch to that user's account:
73
+
74
+ ```bash
75
+ sudo su - pgsqlpot
76
+ ```
77
+
78
+ ## Step 4: Install the honeypot
79
+
80
+ Create a virtual environment. For modern versions of Python (i.e., 3.x), use
81
+ just
82
+
83
+ ```bash
84
+ python -m venv pgsqlpot-env
85
+ ```
86
+
87
+ For the obsolete Python 2.7, use
88
+
89
+ ```bash
90
+ pip install "virtualenv==20.15.1"
91
+ virtualenv pgsqlpot-env
92
+ ```
93
+
94
+ Then activate the virtual environment with
95
+
96
+ ```bash
97
+ source pgsqlpot-env/bin/activate
98
+ ```
99
+
100
+ and update `pip`
101
+
102
+ ```bash
103
+ (pgsqlpot-env) $ python -m pip install pip --upgrade
104
+ ```
105
+
106
+ How you should proceed further depends on whether you want to install the
107
+ honeypot from the repo (usually done for testing purposes) or from PyPI
108
+ (the recommended approach).
109
+
110
+ ### Installing from PyPI (recommended)
111
+
112
+ Installing from PyPI is very simple. Just use
113
+
114
+ ```bash
115
+ (pgsqlpot-env) $ pip install --prefer-binary pgsqlpot[plugin_list]
116
+ ```
117
+
118
+ Here, `plugin_list` is a comma-separated list of output plugin names whose
119
+ dependencies you want to install. You do not need to install the dependencies
120
+ for all existing plugins. For instance, if you plan to use only the `mysql`
121
+ and `redisdb` plugins, use `[mysql,redisdb]`. If you want to install the
122
+ dependencies for all plugins, use `[all]`.
123
+
124
+ The output plugins `discord`, `jsonlog`, `localsyslog`, `socketlog`, `sqlite`,
125
+ `telegram`, and `textlog` have no dependencies of their own. If you plan to use
126
+ only one or more of those, omit the `[plugin_list]` part entirely. It won't hurt
127
+ to specify such a plugin (e.g., `[mysql,jsonlog]`) but this is essentially
128
+ equivalent to omitting it.
129
+
130
+ If, after installation, you decide that you're going to use yet another plugin,
131
+ simply run the installation command again with the new plugin included in the
132
+ `plugin_list`
133
+
134
+ ### Installing from the repo
135
+
136
+ Ensure that the `build` module is installed, clone the repo, build the
137
+ distribution wheel, and install from it:
138
+
139
+ ```bash
140
+ (pgsqlpot-env) $ pip install build --upgrade
141
+ (pgsqlpot-env) $ git clone https://gitlab.com/bontchev/pgsqlpot.git
142
+ (pgsqlpot-env) $ cd pgsqlpot
143
+ (pgsqlpot-env) $ python -m build
144
+ (pgsqlpot-env) $ pip install --prefer-binary "dist/pgsqlpot-*-py2.py3-none-any.whl[plugin_list]"
145
+ ```
146
+
147
+ where `plugin_list` is as described in the previous section.
148
+
149
+ ## Step 5: Initialize the working directory
150
+
151
+ Create a directory where the honeypot will store its configuration, data,
152
+ documentation, and logs, then initialize it:
153
+
154
+ ```bash
155
+ (pgsqlpot-env) $ mkdir ~/pgsqlpot-workdir
156
+ (pgsqlpot-env) $ cd ~/pgsqlpot-workdir
157
+ (pgsqlpot-env) $ pgsqlpot init
158
+ ```
159
+
160
+ This creates the `data/`, `docs/`, `etc/`, and `log/` subdirectories. It
161
+ also copies the files `test.py` (for verifying the honeypot is working)
162
+ and `Dockerfile` into the working directory.
163
+
164
+ ## Step 6: Create a configuration file
165
+
166
+ The configuration for the honeypot is stored in `etc/honeypot.cfg.base` and
167
+ `etc/honeypot.cfg`. Both files are read on startup but entries from
168
+ `etc/honeypot.cfg` take precedence. The `.base` file contains the default
169
+ settings and should not be edited — it may be overwritten by upgrades. All
170
+ your customisations should go into `etc/honeypot.cfg`.
171
+
172
+ To run with a standard configuration there is no need to change anything.
173
+
174
+ For instance, in order to enable JSON logging, create `etc/honeypot.cfg` and
175
+ put in it only the following:
176
+
177
+ ```ini
178
+ [output_jsonlog]
179
+ enabled = true
180
+ logfile = log/pgsqlpot.json
181
+ epoch_timestamp = true
182
+ ```
183
+
184
+ For more information about how to configure additional output plugins, please
185
+ consult the appropriate `README.md` file in the subdirectory corresponding to
186
+ the plugin inside the `docs/` directory.
187
+
188
+ **Note on testing:** The default blacklist excludes connections from
189
+ `127.0.0.1` and `192.168.0.0/16`. If you run `test.py` from the same machine
190
+ as the honeypot, you will not see any log output because the connection will
191
+ not be logged. Either run `test.py` with `-H <your-external-IP>`, or
192
+ temporarily clear the blacklist in `etc/honeypot.cfg`:
193
+
194
+ ```ini
195
+ [honeypot]
196
+ blacklist =
197
+ ```
198
+
199
+ ## Step 7: Start the honeypot
200
+
201
+ From the working directory, with the virtual environment active:
202
+
203
+ ```bash
204
+ (pgsqlpot-env) $ cd ~/pgsqlpot-workdir
205
+ (pgsqlpot-env) $ pgsqlpot start
206
+ ```
207
+
208
+ To check that the honeypot is running, use
209
+
210
+ ```bash
211
+ (pgsqlpot-env) $ pgsqlpot status
212
+ The honeypot is running (PID: 12345).
213
+ ```
214
+
215
+ To run in the foreground (useful for debugging):
216
+
217
+ ```bash
218
+ (pgsqlpot-env) $ pgsqlpot run
219
+ ```
220
+
221
+ Stop it by pressing Ctrl-C.
222
+
223
+ To stop the honeypot when it is running in the background, use
224
+
225
+ ```bash
226
+ (pgsqlpot-env) $ pgsqlpot stop
227
+ Stopping the honeypot (PID 12345)... Stopped.
228
+ ```
229
+
230
+ To verify that the honeypot is working correctly, run the test script (see
231
+ the note about the blacklist above):
232
+
233
+ ```bash
234
+ (pgsqlpot-env) $ python test.py -u Foo -p Bar -H $(curl -s "http://api.ipify.org")
235
+ ```
236
+
237
+ It should print a message like this:
238
+
239
+ ```test.py
240
+ Error: connection to server at "123.123.123.123", port 5432 failed: FATAL: password authentication failed for user "Foo"
241
+ ```
242
+
243
+ where instead of `123.123.123.123` you'll see your external IP address.
244
+
245
+ ## Step 8: Make the honeypot start at boot time
246
+
247
+ Edit the `crontab` jobs with your favourite editor:
248
+
249
+ ```bash
250
+ crontab -e
251
+ ```
252
+
253
+ and add the line:
254
+
255
+ ```bash
256
+ @reboot cd ${HOME}/pgsqlpot-workdir && ${HOME}/pgsqlpot-env/bin/pgsqlpot start >/dev/null 2>&1
257
+ ```
258
+
259
+ This starts the honeypot automatically whenever the computer boots.
260
+
261
+ ## Configure additional output plugins (OPTIONAL)
262
+
263
+ The honeypot automatically outputs event data as text to stdout (or to a log
264
+ file, if configured). Additional output plugins can be configured to record
265
+ the data in other ways. Supported output plugins currently include:
266
+
267
+ Destination|Plugin Name
268
+ ---|---
269
+ CouchDB|couch
270
+ [Datadog](datadog/README.md)|datadog
271
+ [Discord](discord/README.md)|discord
272
+ Elasticsearch|elastic
273
+ HPFeeds|hpfeed
274
+ InfluxDB 2.0|influx2
275
+ JSON|jsonlog
276
+ Kafka|kafka
277
+ MongoDB|mongodb
278
+ [MySQL](mysql/README.md)|mysql
279
+ NLCV API|nlcvapi
280
+ [PostgreSQL](postgres/README.md)|postgres
281
+ Redis|redisdb
282
+ RethinkDB|rethinkdblog
283
+ [Slack](slack/README.md)|slack
284
+ Socket|socketlog
285
+ [SQLite3](sqlite3/README.md)|sqlite
286
+ Syslog|localsyslog
287
+ [Telegram](telegram/README.md)|telegram
288
+ Text|textlog
289
+ XMPP|xmpp
290
+
291
+ More plugins are likely to be added in the future.
292
+
293
+ See `docs\[plugin]\README.md` for details on each plugin or click on the
294
+ names in the above table that are clickable.
295
+
296
+ **Note:** The `influx2` plugin requires Python 3.x and cannot be used with
297
+ Python 2.7. The `localsyslog` plugin works only on Linux.
298
+
299
+ ## Docker usage (OPTIONAL)
300
+
301
+ **WARNING!** A user who belongs to the `docker` group has effective root
302
+ privileges on the host, which negates the advantages of creating the `pgsqlpot`
303
+ user as a restricted user in the first place. Since this significantly increases
304
+ the [attack surface](https://docs.docker.com/engine/security/security/#docker-daemon-attack-surface),
305
+ we strongly advise against using the honeypot with Docker. One alternative is
306
+ to use [Podman](https://podman.io/), which does not require privileged user
307
+ access in order to operate.
308
+
309
+ If you nevertheless wish to use Docker, first make sure it is installed and
310
+ that the user `pgsqlpot` is a member of the `docker` group (from a user who
311
+ can `sudo`):
312
+
313
+ ```bash
314
+ sudo apt-get install docker.io
315
+ sudo usermod -a -G docker pgsqlpot
316
+ ```
317
+
318
+ Then switch to the `pgsqlpot` user and build the image from the working
319
+ directory (the `Dockerfile` was placed there by `pgsqlpot init`):
320
+
321
+ ```bash
322
+ sudo su - pgsqlpot
323
+ cd ~/pgsqlpot-workdir
324
+ source ~/pgsqlpot-env/bin/activate
325
+ VERSION=$(pgsqlpot --version)
326
+ deactivate
327
+
328
+ # Build with all plugins (default)
329
+ docker build --build-arg VERSION=$VERSION -t pgsqlpot .
330
+
331
+ # Or build with specific plugins only, e.g., mysql and kafka:
332
+ docker build --build-arg VERSION=$VERSION --build-arg PLUGINS=mysql,kafka -t pgsqlpot .
333
+
334
+ # Run, mounting your config and data directories
335
+ docker run -d -p 5432:5432 \
336
+ -v ${HOME}/pgsqlpot-workdir/etc/honeypot.cfg:/pgsqlpot/etc/honeypot.cfg \
337
+ -v ${HOME}/pgsqlpot-workdir/data:/pgsqlpot/data \
338
+ pgsqlpot
339
+ ```
340
+
341
+ ## Command-line options
342
+
343
+ The honeypot supports the following command-line options:
344
+
345
+ ```bash
346
+ -h, --help show this help message and exit
347
+ -v, --version show program's version number and exit
348
+ -w WORKDIR, --workdir WORKDIR
349
+ Working directory (overrides PGSLQPOT_WORKDIR and cwd)
350
+ ```
351
+
352
+ It also supports the following subcommands:
353
+
354
+ ```bash
355
+ init Scaffold a working directory
356
+ run Start the honeypot in the foreground
357
+ start Start the honeypot in the background
358
+ stop Stop the backgrounded honeypot
359
+ restart Restart (stop and start) the honeypot in the background
360
+ status Show running status
361
+ ```
362
+
363
+ All subcommands accept `-w / --workdir DIR` to specify the working directory
364
+ explicitly, overriding the `PGSLQPOT_WORKDIR` environment variable and the
365
+ current directory.
366
+
367
+ The `run`, `start`, and `restart` subcommands also accept the options
368
+
369
+ ```bash
370
+ -h, --help show this help message and exit
371
+ -p PORT, --port PORT Port to listen on (default: 5432)
372
+ -l LOGFILE, --logfile LOGFILE
373
+ Log file (default: stdout)
374
+ -s SENSOR, --sensor SENSOR
375
+ Sensor name (default: hostname)
376
+ ```
377
+
378
+ Settings specified via command-line options take precedence over the
379
+ corresponding settings in the configuration files.
380
+
381
+ ## Upgrading the honeypot
382
+
383
+ Stop the honeypot, upgrade the package, re-initialize (to pick up any new
384
+ default config or response files), and restart:
385
+
386
+ ```bash
387
+ $ cd ~/pgsqlpot-workdir
388
+ $ source ~/pgsqlpot-env/bin/activate
389
+ (pgsqlpot-env) $ pgsqlpot stop
390
+ (pgsqlpot-env) $ pip install --prefer-binary --upgrade pgsqlpot[plugin_list]
391
+ (pgsqlpot-env) $ pgsqlpot init
392
+ (pgsqlpot-env) $ pgsqlpot start
393
+ ```
394
+
395
+ where `[plugin_list]` is as explained above.
396
+
397
+ Note that `pgsqlpot init` is safe to re-run — it never overwrites files that
398
+ you have already edited or created (such as `etc/honeypot.cfg`). It only
399
+ copies files that are missing, so any new defaults added by an upgrade are
400
+ picked up automatically.