o
    àý°jeF  ã                   @  sl  d dl mZ d dl mZ d dl mZ 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mZmZmZmZmZmZmZmZmZ d dlmZm Z  dZ!dZ"e!e"fZ#dZ$dZ%dZ&dZ'dZ(dZ)dZ*dZ+dZ,dZ-dZ.dZ/dZ0dZ1dZ2dZ3dZ4d Z5d!Z6e	G d"d#„ d#ƒƒZ7d3d*d+„Z8d4d.d/„Z9d0d1„ Z:e;d2kr´e:ƒ  dS dS )5é    )Údivision)Úprint_function)ÚannotationsN)Ú	dataclass)Úlogger)Úparse_target)Úversion)Úsmbconnection)ÚSMB_SESSION_PORT)
ÚSMB_DIALECTÚFILE_READ_ATTRIBUTESÚFILE_WRITE_ATTRIBUTESÚFILE_SHARE_READÚFILE_SHARE_WRITEÚFILE_SHARE_DELETEÚSMB_QUERY_FILE_BASIC_INFOÚSMB_SET_FILE_BASIC_INFOÚSMBQueryFileBasicInfoÚSMBSetFileBasicInfo)ÚSMB2_FILE_BASIC_INFOÚFILE_BASIC_INFORMATIONÚqueryÚseté   é   é   é   é   é    é€   é   i   i   i   i   i    i @  i   i   i   i   i  @ c                   @  s"  e Zd ZU dZded< dZded< dZded< dZded< dZded< dZ	ded< dZ
ded	< dZded
< dZded< dZded< dZded< dZded< dZded< dZded< dZded< dZded< dZded< dZded< dZded< d#dd„Zed$dd„ƒZed%dd„ƒZd&d d!„Zd"S )'ÚFileAttributesFÚboolÚreadonlyÚhiddenÚsystemÚvolumeÚ	directoryÚarchiveÚnormalÚ	temporaryÚsparse_fileÚreparse_pointÚ
compressedÚofflineÚnot_content_indexedÚ	encryptedÚno_scrub_dataÚrecall_on_openÚpinnedÚunpinnedÚrecall_on_data_accessÚreturnÚintc                 C  s  | j rtnd| jrtndB | jrtndB | jrtndB | jr t	ndB | j
r'tndB | jr.tndB | jr5tndB | jr<tndB | jrCtndB | jrJtndB | jrQtndB | jrXtndB | jr_tndB | jrftndB | jrmtndB | j rtt!ndB | j"r{t#ndB | j$rƒt%B S dB S )Nr   )&r#   ÚFILE_ATTRIBUTE_READONLYr$   ÚFILE_ATTRIBUTE_HIDDENr%   ÚFILE_ATTRIBUTE_SYSTEMr&   ÚFILE_ATTRIBUTE_VOLUMEr'   ÚFILE_ATTRIBUTE_DIRECTORYr(   ÚFILE_ATTRIBUTE_ARCHIVEr)   ÚFILE_ATTRIBUTE_NORMALr*   ÚFILE_ATTRIBUTE_TEMPORARYr+   ÚFILE_ATTRIBUTE_SPARSE_FILEr,   ÚFILE_ATTRIBUTE_REPARSE_POINTr-   ÚFILE_ATTRIBUTE_COMPRESSEDr.   ÚFILE_ATTRIBUTE_OFFLINEr/   Ú"FILE_ATTRIBUTE_NOT_CONTENT_INDEXEDr0   ÚFILE_ATTRIBUTE_ENCRYPTEDr1   ÚFILE_ATTRIBUTE_NO_SCRUB_DATAr2   ÚFILE_ATTRIBUTE_RECALL_ON_OPENr3   ÚFILE_ATTRIBUTE_PINNEDr4   ÚFILE_ATTRIBUTE_UNPINNEDr5   Ú$FILE_ATTRIBUTE_RECALL_ON_DATA_ACCESS©Úself© rM   ú†/root/aizidognhua/tmp/workspace/projects/ec89d86c-575f-41c9-af57-ac45cbdbf775/venv/lib/python3.10/site-packages/../../../bin/attrib.pyÚpackc   sR   ÿþýüûúùø	÷
öõôóòñðïîÿîÿzFileAttributes.packÚdatac                 C  s  | di dt |t@ ƒ“dt |t@ ƒ“dt |t@ ƒ“dt |t@ ƒ“dt |t@ ƒ“dt |t@ ƒ“dt |t@ ƒ“dt |t@ ƒ“d	t |t	@ ƒ“d
t |t
@ ƒ“dt |t@ ƒ“dt |t@ ƒ“dt |t@ ƒ“dt |t@ ƒ“dt |t@ ƒ“dt |t@ ƒ“dt |t@ ƒ“dt |t@ ƒ“dt |t@ ƒ“ŽS )Nr#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   r3   r4   r5   rM   )r"   r8   r9   r:   r;   r<   r=   r>   r?   r@   rA   rB   rC   rD   rE   rF   rG   rH   rI   rJ   )ÚclsrP   rM   rM   rN   Úunpacky   sN   ÿþýüûúùø	÷
öõôóòñðïîízFileAttributes.unpackÚstrc                 C  s   t  | ¡ ¡ S )N)r!   rR   Ú__repr__)rP   rM   rM   rN   Úrepr_attribs‘   s   zFileAttributes.repr_attribsc                 C  s¸   | j rdnd| jrdnd | jrdnd | jrdnd | jr dnd | jr'dnd | jr.dnd | jr5d	nd | jr<d
nd | j	rCdnd | j
rJdnd | jrQdnd | jrYd S d S )NÚRú-ÚHÚSÚVÚDÚAÚNÚTÚCÚOÚEÚPÚU)r#   r$   r%   r&   r'   r(   r)   r*   r-   r.   r0   r3   r4   rK   rM   rM   rN   rT   •   s:   ÿþýüûúùø	÷
öõôÿôÿzFileAttributes.__repr__N)r6   r7   )rP   r7   r6   r!   )rP   r7   r6   rS   )r6   rS   )Ú__name__Ú
__module__Ú__qualname__r#   Ú__annotations__r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   r3   r4   r5   rO   ÚclassmethodrR   ÚstaticmethodrU   rT   rM   rM   rM   rN   r!   M   s4   
 
r!   Ú
connectionúsmbconnection.SMBConnectionÚtidr7   Úfidr6   c                 C  s\   |   ¡ tkrt|  ||t¡ƒ}|d }nt|  ||t¡ƒ}|d }t d|›�¡ t	 
|¡S )NÚExtFileAttributesr!   z"Got file / directory attributes = )Ú
getDialectr   r   Ú	queryInfor   r   r   ÚloggingÚdebugr!   rR   )rj   rl   rm   Ú	basicinfoÚ
attributesrM   rM   rN   Úattrib_query¦   s   

ru   ÚattribsÚNonec                 C  s¢   |   ¡ tkr"tƒ }d|d< d|d< d|d< d|d< | ¡ |d< t}ntƒ }d|d< d|d< d|d< d|d< | ¡ |d< t}t d| ¡ › �¡ |  	||||¡ d S )	Nr   ÚCreationTimeÚLastAccessTimeÚLastWriteTimeÚ
ChangeTimern   r!   z&Setting file / directory attributes = )
ro   r   r   rO   r   r   r   rq   rr   ÚsetInfo)rj   rl   rm   rv   Ú	info_dataÚfileInfoClassrM   rM   rN   Ú
attrib_set±   s"   r   c                  C  sf  t  ¡  ttjƒ tjddd�} | jdddd� | jdtd	d
� | jdtdd
� | jdddd� |  	d¡}|jddddd� |jdddd� |jdddd� |jddddd� |  	d¡}|jddt
tdd d!� |jd"dd#d$d� |jd%dd#d&d� |jd'd(d)td*d+d!� | jd,d-�}|jtd.d/�}|jtd0d/�}|jd1d2d3dd4d5� |jd6d7d8dd9d5� |jd:d;d<dd=d5� |jd>d?d@ddAd5� |jdBdCdDddEd5� |jd'dFdGddHd5� |jdIdJdKddLd5� |jdMdNdOddPd5� |jdQdRdSddTd5� |jddUdVddWd5� |jdXdYdZdd[d5� ttjƒd\k�r|  ¡  t d\¡ |  ¡ }|jdu �r1t ¡  tj¡ t t ¡ ¡ nt ¡  tj¡ |jtv�rIt d]j |jd^�¡ t!|j"ƒ\}}}}	|j#d u �r[|	|_#|d u �rbd_}|d_k�rˆ|d_k�rˆ|j$d u �rˆ|j%d`u �rˆ|j&d u �rˆdadbl'm'}
 |
dcƒ}|j&d u�r‘d|_(|j$d u�r |j$ )dd¡\}}nd_}d_}|j*}t+ ,|j-¡}zÙt.j/|	|j#t|j0ƒt|j1ƒde�}|j(du �rÒ| 2||||||j&|j3¡ n	| 4|||||¡ | 5|¡}|jdfk�rét6}n|jdgk�rñt7}|j8||t9t:B t;B da|dh�}zw|jdfk�rtt<|||ƒ||ƒ nS|jdgk�rQt=|j>|j?|j@|jA|jB|jC|jD|jE|jF|jG|jHdi�}tI||||ƒ t|||ƒ W | J||¡ | K|¡ | L¡  W d S W | J||¡ | K|¡ | L¡  W d S W | J||¡ | K|¡ | L¡  W d S | J||¡ | K|¡ | L¡  w  tM�y² } zt ¡ jNtjk�r dad lO}| P¡  t t|ƒ¡ W Y d }~d S d }~ww )jNTz3File Attribute Modification Utility implementation.)Úadd_helpÚdescriptionÚtargetÚstorez6[[domain/]username[:password]@]<targetName or address>)ÚactionÚhelpÚsharez?The share in which the desired file to query or modify resides.)Útyper…   ÚpathzIThe path of the desired file whose attributes we wish to query or modify.z-debugÚ
store_truezTurn DEBUG output ONÚauthenticationz-hasheszLMHASH:NTHASHz$NTLM hashes, format is LMHASH:NTHASH)r„   Úmetavarr…   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)rj   z-pz--portzdestination portz.Destination port to connect to the SMB Server.)Údefaultr‡   r‹   r…   z-dc-ipz
ip addressztIP Address of the domain controller. If omitted it will 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-tz	--timeouté<   Úsecondsz!Set connection timeout (seconds).r„   )Údestz*Query current file / directory attributes.)r…   z#Modify file / directory attributes.z-rz
--readonlyr#   zèA file or directory that is read-only. For a file, applications can read the file but cannot write to it or delete it. For a directory, applications cannot delete it, but applications can create and delete files from that directory.)r�   r„   r…   z-Hz--hiddenr$   z„A file or directory that is hidden. Files and directories marked with this attribute do not appear in an ordinary directory listing.z-sz--systemr%   zQA file or directory that the operating system uses a part of or uses exclusively.z-az	--archiver(   zvA file or directory that requires to be archived. Applications use this attribute to mark files for backup or removal.z-nz--normalr)   z„A file that does not have other attributes set. This flag is used to clear all other flags by specifying it with no other flags set.z--temporaryr*   zìA file that is being used for temporary storage. The operating system can choose to store this file's data in memory rather than on mass storage, writing the data to mass storage only if data remains in the file when the file is closed.z-cz--compressedr-   z¶A file or directory that is compressed. For a file, all of the data in the file is compressed. For a directory, compression is the default for newly created files and subdirectories.z-oz	--offliner.   zäThe data in this file is not available immediately. This attribute indicates that the file data is physically moved to offline storage. This attribute is used by Remote Storage, which is hierarchical storage management software.z-ez--encryptedr0   zµA file or directory that is encrypted. For a file, all data streams in the file are encrypted. For a directory, encryption is the default for newly created files and subdirectories.z--pinnedr3   zÔThis attribute indicates user intent that the file or directory should be kept fully present locally even when not being actively accessed. This attribute is for use with hierarchical storage management software.z-uz
--unpinnedr4   zÊThis attribute indicates that the file or directory should not be kept fully present locally except when being actively accessed. This attribute is for use with hierarchical storage management software.r   zInvalid action '{action}')r„   Ú Fr   )Úgetpassz	Password:ú:)Ú	sess_portÚtimeoutr   r   )Ú	shareModeÚcreationOptionÚdesiredAccess)r#   r$   r%   r(   r)   r*   r-   r.   r0   r3   r4   )Qr   ÚinitÚprintr   ÚBANNERÚargparseÚArgumentParserÚadd_argumentrS   Úadd_argument_groupr
   r7   Úadd_subparsersÚ
add_parserÚATTRIB_QUERY_ACTIONÚATTRIB_SET_ACTIONÚlenÚsysÚargvÚ
print_helpÚexitÚ
parse_argsrr   rq   Ú	getLoggerÚsetLevelÚDEBUGÚgetInstallationPathÚINFOr„   ÚVALID_ATTRIB_ACTIONSÚerrorÚformatr   r‚   Ú	target_ipÚhashesÚno_passÚaesKeyr‘   ÚkÚsplitr†   ÚntpathÚnormpathrˆ   r	   ÚSMBConnectionÚportr”   ÚkerberosLoginÚdc_ipÚloginÚconnectTreer   r   ÚopenFiler   r   r   ru   r!   r#   r$   r%   r(   r)   r*   r-   r.   r0   r3   r4   r   Ú	closeFileÚdisconnectTreeÚcloseÚ	ExceptionÚlevelÚ	tracebackÚ	print_exc)ÚparserÚgroupÚsubcommandsÚquery_parserÚ
set_parserÚoptionsÚdomainÚusernameÚpasswordÚaddressr‘   ÚlmhashÚnthashr†   rˆ   rj   rl   r—   rm   rv   ÚerÅ   rM   rM   rN   ÚmainÈ   sì   



ÿ
ÿ

8 

ûõ
í
ì
þ

€ürÔ   Ú__main__)rj   rk   rl   r7   rm   r7   r6   r!   )
rj   rk   rl   r7   rm   r7   rv   r!   r6   rw   )<Ú
__future__r   r   r   r¤   r›   rq   r·   Údataclassesr   Úimpacket.examplesr   Úimpacket.examples.utilsr   Úimpacketr   r	   Úimpacket.nmbr
   Úimpacket.smbr   r   r   r   r   r   r   r   r   r   Úimpacket.smb3structsr   r   r¡   r¢   r®   r8   r9   r:   r;   r<   r=   r>   r?   r@   rA   rB   rC   rD   rE   rF   rG   rH   rI   rJ   r!   ru   r   rÔ   rd   rM   rM   rM   rN   Ú<module>   s\   0
X
 
ÿ