Skip to content

Feature/postgres protocol - #1507

Open
luth3n wants to merge 36 commits into
Pennyw0rth:mainfrom
luth3n:feature/postgres-protocol
Open

luth3n wants to merge 36 commits into
Pennyw0rth:mainfrom
luth3n:feature/postgres-protocol

Conversation

@luth3n

@luth3n luth3n commented Nov 5, 2026 •

Copy link
Copy Markdown

Description

This PR introduces PostgreSQL protocol support to NetExec, extending its capabilities to interact with PostgreSQL database servers.

Core features:

  • Credential validation and password spraying
  • Admin detection (Pwn3d!) for users with rolsuper role
  • Put a local file into remote target: --put-file
  • Get a remote file: --get-file

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Deprecation of feature or functionality
  • This change requires a documentation update
  • This requires a third party update (such as Impacket, Dploot, lsassy, etc)
  • This PR was created with the assistance of AI (list what type of assistance, tool(s)/model(s) in the description)

Setup guide for the review

Test with Docker:
docker run --name pg-test -e POSTGRES_PASSWORD=test1234 -p 5432:5432 -d postgres:16

Commands

#Searching for PostgreSQL servers
nxc psql 192.168.1.0/24

#Password spraying
nxc psql 192.168.1.83 -u postgres -p wordlist

#Put a local file into remote target
nxc psql 192.168.1.83 -u postgres -p admin --put-file /tmp/local_file /tmp/remote_file

#Get a remote file
nxc psql 192.168.1.83 -u postgres -p admin --get-file /etc/passwd /tmp/passwd


Screenshots:

Screenshot From 2026-11-23 17-12-31 Screenshot From 2026-11-23 17-12-42 Screenshot From 2026-11-23 17-14-27 Screenshot From 2026-11-23 17-15-16

Checklist:

  • I have ran Ruff against my changes (poetry: poetry run ruff check ., use --fix to automatically fix what it can)
  • I have added or updated the tests/e2e_commands.txt file if necessary (new modules or features are required to be added to the e2e tests)
  • If reliant on changes of third party dependencies, such as Impacket, dploot, lsassy, etc, I have linked the relevant PRs in those projects
  • I have linked relevant sources that describes the added technique (blog posts, documentation, etc)
  • I have performed a self-review of my own code (not an AI review)
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation (PR here: https://github.com/Pennyw0rth/NetExec-Wiki)

@NeffIsBack

Copy link
Copy Markdown
Member

Hi and thanks for the PR!

Please strip out the modules for now tho and open a separate PR for them. This makes reviewing much easier and therefore faster.

@NeffIsBack NeffIsBack added the enhancement New feature or request label Nov 5, 2026
@luth3n

luth3n commented Nov 5, 2026

Copy link
Copy Markdown
Author

Hi and thanks for the PR!

Please strip out the modules for now tho and open a separate PR for them. This makes reviewing much easier and therefore faster.

done

@NeffIsBack

Copy link
Copy Markdown
Member

@luth3n can you merge in main? The diff looks like it is outdated and it seems like I do not have permissions to push to your fork. If possible enabling that would be great as well otherwise I can't push changes that are required for a merge.

Comment thread nxc/protocols/postgres/proto_args.py Resolved
Comment thread nxc/protocols/postgres/proto_args.py Resolved
Comment thread nxc/protocols/postgres/proto_args.py Resolved
Comment thread .dockerignore Resolved
Comment thread pyproject.toml Resolved
Comment thread nxc/protocols/postgres.py Resolved
Comment thread nxc/protocols/postgres.py Resolved
Comment thread nxc/protocols/postgres.py Resolved
Comment thread nxc/protocols/postgres.py Resolved
Comment thread nxc/protocols/postgres.py Resolved
@luth3n

luth3n commented Nov 19, 2026

Copy link
Copy Markdown
Author

Thanks for the feedback provided — I've fixed everything mentioned above.

@luth3n
luth3n requested a review from NeffIsBack November 19, 2026 16:42
@luth3n
luth3n requested a review from mpgn November 24, 2026 12:16

@mpgn mpgn left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fixes!

Comment thread nxc/protocols/psql.py Resolved
Comment thread nxc/protocols/psql/database.py Resolved
Comment thread tests/e2e_commands.txt Resolved
Comment thread nxc/protocols/psql.py Resolved
Comment thread nxc/protocols/psql.py Resolved

@mpgn mpgn left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Retested on PostgreSQL 16 and 18, LGTM 👍

retest

@luth3n

luth3n commented Nov 24, 2026

Copy link
Copy Markdown
Author

Retested on PostgreSQL 16 and 18, LGTM 👍

retest

Glad to hear!

Comment thread nxc/protocols/psql.py Resolved
Comment thread nxc/protocols/psql.py Resolved
@NeffIsBack

Copy link
Copy Markdown
Member

@luth3n the check for SSL still tells us if SSL is even supported right? So if the server responds with "N" we know that no connection ever will be encrypted. If that assumption holds I would push the following banner:
image

@luth3n

luth3n commented Nov 25, 2026

Copy link
Copy Markdown
Author

If that assumption holds I would push the following banner:

Yep, exactly. SSLRequest makes it possible to determine whether a server supports SSL at all, so it makes sense to reflect this in the banner

@NeffIsBack

Copy link
Copy Markdown
Member

Fyi, also added a --query arg for raw SQL queries:
image

@mpgn could you give my code a quick review?

NeffIsBack
NeffIsBack previously approved these changes Nov 25, 2026

@NeffIsBack NeffIsBack left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM form my side:

posgresql-proto

NeffIsBack
NeffIsBack previously approved these changes Nov 25, 2026
@NeffIsBack

NeffIsBack commented Nov 25, 2026 •

Copy link
Copy Markdown
Member

@luth3n Could you open up a PR to the wiki and add documentation for the new proto?

Do you also have social media (twitter, linkedin, bluesky)?

@luth3n

luth3n commented Nov 25, 2026

Copy link
Copy Markdown
Author

@NeffIsBack Sure, I'll add the documentation

https://x.com/luth3n

@mpgn mpgn left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rest looks good 👍

Comment thread nxc/protocols/psql.py Resolved
Co-authored-by: mpgn <5891788+mpgn@users.noreply.github.com>
Signed-off-by: Alex <61382599+NeffIsBack@users.noreply.github.com>
@luth3n

luth3n commented Nov 26, 2026

Copy link
Copy Markdown
Author

Created a PR on the wiki and added documentation for PSQL

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants