U
    @6^'                     @   s0   d dl mZmZmZ d dlZG dd deZdS )    )
SpiderFootSpiderFootPluginSpiderFootEventNc                   @   sR   e Zd ZdZddddZddddZdZe fd	d
Zdd Z	dd Z
dd ZdS )	sfp_torchzyTORCH:Footprint,Investigate:Search Engines:errorprone:Search Tor 'TORCH' search engine for mentions of the target domain.T   )
fetchlinkspages	fullnameszQFetch the darknet pages (via TOR, if enabled) to verify they mention your target.z+Number of results pages to iterate through.zSearch for human names?Nc                 C   s4   || _ |  | _t| D ]}|| | j|< qd S )N)sftempStorageresultslistkeysopts)selfsfcuserOptsopt r   4/var/www/spiderfoot.crq.systems/modules/sfp_torch.pysetup&   s    
zsfp_torch.setupc                 C   s
   dddgS )NDOMAIN_NAME
HUMAN_NAME	EMAILADDRr   r   r   r   r   watchedEvents.   s    zsfp_torch.watchedEventsc                 C   s
   dddgS )NDARKNET_MENTION_URLDARKNET_MENTION_CONTENTSEARCH_ENGINE_WEB_CONTENTr   r   r   r   r   producedEvents4   s    zsfp_torch.producedEventsc                 C   s^  |j }|j}|j}| jd s(|dkr(d S || jkrJ| jd| d  d S d| j|< | jjd| jd | jd d	}|d
 s| jd d S t	
d|d
 t	jt	jB }|sd S |d }d}d}	d}
d| krZ|	| jd k rZ|  rd S |	dkr dt|	 }
|	d7 }	| jjd| d |dd d |
 | jd | jd d	}|d ksX|d
sh| jd d S |d
 }d|d
 krtd|d
 | j|}| | t	
d|d
 t	jt	jB }|D ]}|| jkrҐqqd| j|< | jd|  | j|dr|  r d S | jd r:| jj|| jd | jd d}|d
 d kr`| jd | d!  q||d
 kr| jd | d" |  qtd#|| j|}| | z&|d
 |d$ }|t| d% }W n: tk
r } z| jd& W Y qW 5 d }~X Y nX |d
 || }td'd(| d( | j|}| | ntd#|| j|}| | qqd S ))Nr	   r   zAlready did a search for z, skipping.Tzhttp://xmh57jrzrnw6insl.onion
_useragent_fetchtimeout)	useragenttimeoutcontentz;Couldn't connect to TORCH, check that you have TOR enabled.z0\<form method="get" action="/(\S+)/search.cgi"\>r    zcolor=gray>next &gt;&gt;r   z&np=   zhttp://xmh57jrzrnw6insl.onion/z/search.cgi?q= z%20z&cmd=Search!zNo results returned from TORCH.zNo documents were foundr   z0\<DT\>\d+.\s+<a href="(.*?)"\s+TARGET="_blank"\>zFound a darknet mention: z.onionr   )r#   r"   z	Ignoring z as no data returnedz as no mention of r   x      zString not found in content.r   z...)	eventTypemoduledatar   r   r
   debugfetchUrlinforefindall
IGNORECASEDOTALLlowercheckForStopstrreplacegetr   __name__notifyListenersurlFQDNendswithindexlenBaseException)r   event	eventNamesrcModuleName	eventDataZformpagemZformidZpagecontentZ	pagecountpr,   evtlinkslinkres
startIndexendIndexer   r   r   handleEvent7   s    

 



 
 




 zsfp_torch.handleEvent)r9   
__module____qualname____doc__r   optdescsr   dictr   r   r   rM   r   r   r   r   r      s   r   )sflibr   r   r   r0   r   r   r   r   r   <module>   s   