Add rpcclient.py to examples - #2240
Open
PN-Tester wants to merge 2 commits into
Open
Conversation
Fixed argument parsing for addgroupmem and delgroupmem commands. Previous version did not understand double quotes for group names like "Domin Admins", etc.
Author
|
Fixed a bug in the argument parser for addgroupmem and delgroupmem that would fail on group names with spaces and not understand double quotes. Working now in last commit. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Added impacket / python port of samba's rpcclient as rpcclient.py
Original is at github.com/pn-tester/rpcclient.py
Readme from that page is shown below :
rpcclient.py
A Python implementation of Samba's
rpcclientinteractive shell, built with impacket.This version was specifically designed for compatibility with other impacket components including
ntlmrelayx.Additional features have been added to facilitate local account creation and subsequent usage for exploitation.
Usage
Above screenshot shows basic usage of rpcclient shell over SOCKS tunnel to perform reconnaissance
Rationale
The tool exists to offer more granular control of RPC interaction to penetration testers during internal network engagements. When operators relay NTLM authentication over SMB and create a SOCKS tunnel, a common method
of solidifying this foothold is through creation of a local account on the target computer. Subsequently escalating this account to local administrator of the victim machine is trivial, but actually using the account is not!
Specifically, a common issue arises when using net.py through an ntlmrelay SOCKS to create users or reset passwords. The RPC method call used to set the password requires a session key to encrypt the value, but because we are in a SOCKS tunnel, there is no session key we can access. Thus, the password of the created account is always blank.
While a blank password is perfectly fine from an authentication standpoint (we can provide '' or the NT hash
31D6CFE0D16AE931B73C59D7E0C089C0for credentials), it presents all sorts of problems in windows land.Whats worse, you cannot reset or change the blank password with :
rpcclient.py does not have this issue, because we have modified the account creation process to clear the "password must change at next logon" flag.
Even so, the account will remain unuseable by default due to restrictions on network logons using accounts with blank password (default policy).
The fix is to enable remote registry on the target, and change the value of the key in HKLM to allow us to authenticate with the blank password having user.
This can be done with
fixblankpasswordpolicy. Now the user can authenticate but only to IPC$, not C$ or ADMIN$, or do anything spicy. The reason, despite being a local admin, is that there is another default policy thatlimits the token privileges a local admin gets over the network. If we want an admin session, we need to change this registry value as well with
fixuactokenfilter.When combined with the
fixblankpasswordpolicyandfixuactokenfiltercommands, the created account is ready for usage out of the box.Demo
In the above example, we use rpcclient.py through a SOCKS tunnel to create and escalate the local user "hacker", before dumping SAM and LSA secrets from the target with the new account
NOTE : the usage of the fixblankpasswordpolicy and fixuactokenfilter commands for remote registry modifications
The same operation fails when using impacket-net through the SOCKS tunnel for the reasons mentioned in the rationale section

Connection flags
-hashes LMHASH:NTHASH-no-pass-k-aesKey <hex key>-dc-ip <ip>-port {139,445}-timeout <seconds>-socks-proxy host:portproxychains(requires PySocks)-dialect {1,2.02,2.1,3.0,3.0.2,3.1.1}smbinfobelow) —-dialect 1only helps if the target still has legacy SMB1 enabled, which most current Windows builds do not-c "cmd1;cmd2"-debugCommand reference
SAMR — users
enumdomusersqueryuser <rid|username>createdomuser <username> [password] [--enable] [--must-change]--must-changeis explicitly passed — see Beyond stock rpcclientdeletedomuser <username>enableuser <rid|username>disableuser <rid|username>setuserpass <username> [newpassword] [--must-change]chgpasswd <username> [old_nthash]SAMR — groups & aliases (local groups)
enumdomgroupsquerygroup <rid>querygroupmem <rid>createdomgroup <name>deletedomgroup <rid|name>addgroupmem <group rid|name> <user rid|name>delgroupmem <group rid|name> <user rid|name>enumalsgroups [builtin|domain]createdomalias <name> [--builtin]deletedomalias <rid|name> [--builtin]addaliasmem [--builtin] <alias rid|name> <member: sid|rid|username>delaliasmem [--builtin] <alias rid|name> <member: sid|rid|username>listaliasmem [--builtin] <alias rid|name>SAMR — misc
querydominfogetdompwinfolookupnames <name> [name...]lookupsids <sid> [sid...]LSA
lsaquerylsaenumsidenumprivsSRVSVC / WKSSVC
srvinfonetshareenumnetsharegetinfo <share>netserverdiskenumwkstainfoRemote Registry (WINREG/SVCCTL)
regsetdword <HKLM\key\path> <ValueName> <dword>REG_DWORDvalue underHKEY_LOCAL_MACHINE. Automatically starts the Remote Registry service if it's stopped or disabledfixblankpasswordpolicy [on|off]off(default) lets a blank-password local account authenticate over the network;onrestores the secure defaultfixuactokenfilter [on|off]LocalAccountTokenFilterPolicy).off(default) makes a local admin account get a full admin token over the network instead of a UAC-filtered one;onrestores the secure defaultBoth
fix*commands track whether this session had to auto-enable the Remote Registry service to reach the registry at all, and theiron(undo) form puts the service back toDisabledif so — they won't touch it if it was already enabled/running beforehand.Diagnostics
smbinfosetuserpass/createdomuser <user> <pass>failsGeneric / arbitrary RPC
bind <\pipe\name> <interface-uuid> [major.minor]rawcall <opnum> [hex-payload]bind, and print the raw hex responseLicense
No license specified — treat as source-available for personal/internal use unless you know otherwise.