Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

start remote registry as unprivileged user in reg.py #1638

Merged
merged 2 commits into from
Nov 3, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions examples/reg.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
from impacket.examples.utils import parse_target
from impacket.system_errors import ERROR_NO_MORE_ITEMS
from impacket.structure import hexdump
from impacket.smbconnection import SMBConnection
from impacket.smbconnection import SMBConnection, SessionError
from impacket.dcerpc.v5.dtypes import READ_CONTROL


Expand Down Expand Up @@ -173,7 +173,8 @@ def run(self, remoteName, remoteHost):
self.__remoteOps.enableRegistry()
except Exception as e:
logging.debug(str(e))
logging.warning('Cannot check RemoteRegistry status. Hoping it is started...')
logging.warning('Cannot check RemoteRegistry status. Triggering start trough named pipe...')
self.triggerWinReg()
self.__remoteOps.connectWinReg()

try:
Expand All @@ -200,6 +201,17 @@ def run(self, remoteName, remoteHost):
if self.__remoteOps:
self.__remoteOps.finish()

def triggerWinReg(self):
# original idea from https://twitter.com/splinter_code/status/1715876413474025704
tid = self.__smbConnection.connectTree('IPC$')
try:
self.__smbConnection.openFile(tid, r'\winreg', 0x12019f, creationOption=0x40, fileAttributes=0x80)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

No clue what the hex values do, just copied them over from psexec.py.

except SessionError:
# STATUS_PIPE_NOT_AVAILABLE error is expected
pass
# give remote registry time to start
time.sleep(1)

def save(self, dce, keyName):
hRootKey, subKey = self.__strip_root_key(dce, keyName)
outputFileName = "%s\%s.save" % (self.__options.outputPath, subKey)
Expand Down