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 d dlmZ d dlmZ d d	lmZ d
d Zdd ZedkrQe  dS dS )    N)logger)
__banner__)SMBConnectionFactory)ICPRRPC)DCERPC5Connection)
DCERPCAuth)EPM)SAMRRPCc              
      s>  zt d t| }|  }t d tj|t j| j	| j
dI d H \}}|d ur2|t d t| }t||}tj|ddI d H \}}|d urT|td | 2 zH3 d H W \}}|dkrjq]||I d H \}	}|d urz|t |	 ||	I d H \}
}|d ur|||
d	I d H \}}|d ur|t |  q]6 | 2 z3 d H W \}}|d ur|t | ||I d H \}	}|d ur|t |	 ||	I d H \}
}|d ur|||
I d H \}}|d ur|t |  ||
2 z}3 d H W \}}}|d ur|t | ||
|I d H \}}|d ur"|||2 zP3 d H W \}}|d ur6|t | |d
d }t d|  ||
t|I d H \}}|d ur[q't d ||I d H \}}|d urp|t |  q'6 q6 q6 t d W dS  ty } zt !  d|fW  Y d }~S d }~ww )Nz$[+] Parsing connection parameters...z[+] Connecting to EPM...)dc_ipdomainz![+] Connecting to WKST service...T)perform_dummyzService DCE Connected!TESTAdministrator-zUser RID: %szOK!z[+] Finished!)TNF)"printr   from_url
get_targetget_hostname_or_ipr   create_targetr	   service_uuidr
   r   r   from_smb_gssapiget_credentialr   from_rpcconnectionr   debuglist_domainsget_domain_sidopen_domainget_user_by_namedumpget_infolist_aliases
open_aliaslist_alias_memberssplit	open_userintget_user_info	Exception	traceback	print_exc)urlsuiptargeterrauth
connectionrpcr   dsidhdomainuserinfodinfognamegsidhaliasmsidusidhuseruinfoe r?   /root/aizidognhua/tmp/workspace/projects/ec89d86c-575f-41c9-af57-ac45cbdbf775/venv/lib/python3.10/site-packages/aiosmb/examples/dcesam.pyamain   s   
,

	




6rA   c                  C   sn   dd l } | jdd}|jddddd |jdd	d
 | }tt |jdkr-tt	j
 tt|j d S )Nr   z*Remore Registry Service client via DCE/RPC)descriptionz-vz	--verbosecount)actiondefaultsmb_urlzConnection string that describes the authentication and target. Example: smb+ntlm-password://TEST\Administrator:password@10.10.10.2)help   )argparseArgumentParseradd_argument
parse_argsr   r   verboser   setLevelloggingDEBUGasynciorunrA   rF   )rI   parserargsr?   r?   r@   main{   s   
rU   __main__)rQ   r)   rO   osaiosmbr   aiosmb._versionr   !aiosmb.commons.connection.factoryr   #aiosmb.dcerpc.v5.interfaces.icprmgrr   aiosmb.dcerpc.v5.connectionr   1aiosmb.dcerpc.v5.common.connection.authenticationr   'aiosmb.dcerpc.v5.interfaces.endpointmgrr   #aiosmb.dcerpc.v5.interfaces.samrmgrr	   rA   rU   __name__r?   r?   r?   r@   <module>   s"   j
