o
    j                     @   sJ   d dl Z d dlmZ d dlmZ d dlmZ d dlmZ G dd dZ	dS )    N)logger)NTLMClientNative)ISC_REQ)WSNETDirectAuthc                   @   s   e Zd Zdd Zdd Zedd Zdd Zd,d
dZd,ddZ	dd Z
d-ddZd.ddZdd Zdd Zdd Zdd Zdd  Zd!d" Zd#d$ Zd%d& Zd'd Z
d-d(dZd/d)efd*d+ZdS )0NTLMClientWSNETDirectc                 C   s8   t d | _|| _d | _d| _d | _t| j| _	d S )N   r   )
osurandomhex_authid
credentialsspi
iterationssession_keyr   ntlm_ctx)selfr    r   /root/aizidognhua/tmp/workspace/projects/ec89d86c-575f-41c9-af57-ac45cbdbf775/venv/lib/python3.10/site-packages/asyauth/protocols/ntlm/client/wsnetdirect.py__init__   s   zNTLMClientWSNETDirect.__init__c                 C   s   d S Nr   r   r   r   r   setup   s   zNTLMClientWSNETDirect.setupc                 C      | j jS r   )r   ntlmChallenger   r   r   r   r      s   z#NTLMClientWSNETDirect.ntlmChallengec                 C   r   r   )r   
seq_numberr   r   r   r   get_seq_number   s   z$NTLMClientWSNETDirect.get_seq_numberClientc                 C      | j j|dS N)mode)r   get_sealkeyr   r   r   r   r   r          z!NTLMClientWSNETDirect.get_sealkeyc                 C   r   r   )r   get_signkeyr!   r   r   r   r#   !   r"   z!NTLMClientWSNETDirect.get_signkeyc                    s   | j |||I d H S r   r   encrypt)r   datasequence_nor   r   r   r%   $   s   zNTLMClientWSNETDirect.encryptinitNc                       | j j||||dI d H S N)	direction	auth_datar   decryptr   r&   r'   r+   r,   r   r   r   r.   '      zNTLMClientWSNETDirect.decryptFc                    r)   )N)r+   reset_cipher)r   sign)r   r&   
message_nor+   r1   r   r   r   r2   *   r0   zNTLMClientWSNETDirect.signc                       | j ||I d H S r   )r   verify)r   r&   	signaturer   r   r   r5   -      zNTLMClientWSNETDirect.verifyc                 C   s   | j ||||||S r   )r   SEAL)r   
signingKey
sealingKeymessageToSignmessageToEncryptseqNumcipher_encryptr   r   r   r8   0   s   zNTLMClientWSNETDirect.SEALc                 C   s   | j ||||S r   )r   SIGN)r   r9   messager=   r>   r   r   r   r?   3   s   zNTLMClientWSNETDirect.SIGNc                 C   s   | j S r   )r   r   r   r   r   get_session_key6   s   z%NTLMClientWSNETDirect.get_session_keyc                 C   
   | j  S r   )r   get_extra_infor   r   r   r   rC   9      
z$NTLMClientWSNETDirect.get_extra_infoc                 C   rB   r   )r   is_extended_securityr   r   r   r   rE   <   rD   z*NTLMClientWSNETDirect.is_extended_securityc                 C   rB   r   )r   signing_neededr   r   r   r   rF   ?   rD   z$NTLMClientWSNETDirect.signing_neededc                 C   rB   r   )r   encryption_neededr   r   r   r   rG   B   rD   z'NTLMClientWSNETDirect.encryption_neededc                    r4   r   r$   )r   r&   r3   r   r   r   r%   E   r7   c                    r)   r*   r-   r/   r   r   r   r.   H   r0   flagsc              
      s  z:|d u r
t j}td| j|f  td| j|f  td| j|f  | jd u rFt| jj	 | _| j
 I d H \}}|d urF||d u rtd| j  | jjdddd|jdd	I d H \}}	}
}|d url|td
| j|f  td| j|	f  td| j|
f  |  jd7  _| j|
 |
dd fW S td| j|f  | j| td| j  | jjdddd|j|d	I d H \}}	}}|d ur|| j| td
| j|f  td| j|	f  td| j|f  td| j  | j I d H \| _}|d ur|td| j| j f  | j|   td| j| j f  | j I d H  |dd fW S  tyT } zd d |fW  Y d }~S d }~ww )Nz[WSNETDirect][NTLM][%s] spn: %sz![WSNETDirect][NTLM][%s] flags: %sz#[WSNETDirect][NTLM][%s] cb_data: %szE[WSNETDirect][NTLM][%s] Initializing auth context, fetching NegotaiteNTLM        )authdataz,[WSNETDirect][NTLM][%s][Response] Status: %sz4[WSNETDirect][NTLM][%s][Response] Response flags: %sz/[WSNETDirect][NTLM][%s][Response] Negotiate: %s   Tz%[WSNETDirect][NTLM][%s] Challenge: %szB[WSNETDirect][NTLM][%s] Sending Challenge, getting Authenticate...z2[WSNETDirect][NTLM][%s][Response] Authenticate: %sz.[WSNETDirect][NTLM][%s] Fetching SessionKey...z0[WSNETDirect][NTLM][%s][Response] SessionKey: %sz$[WSNETDirect][NTLM][%s][NTLMINFO] %sF)r   
CONNECTIONr   debugr   r   r   r   subprotocolget_urlconnectauthenticatevaluer   r   load_negotiateload_challengeload_authenticateget_sessionkeyr   r
   load_sessionkeyrA   rC   
disconnect	Exception)r   authDatarH   cb_dataspnkwargs_errstatusctxattrnegotiate_rawauthenticate_rawer   r   r   rT   K   s\   
((
z"NTLMClientWSNETDirect.authenticate)r   )r(   N)NF)NNN)__name__
__module____qualname__r   r   propertyr   r   r    r#   r%   r.   r2   r5   r8   r?   rA   rC   rE   rF   rG   r   rT   r   r   r   r   r   
   s,    	





r   )
r   asyauth.protocols.ntlmr   $asyauth.protocols.ntlm.client.nativer   asyauth.common.winapi.constantsr   wsnet.agent.direct.authr   r   r   r   r   r   <module>   s    