3
@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   s8   || _ | j | _x"t|j D ]}|| | j|< qW 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   sd  |j }|j}|j}| jd  r*|dkr*d S || jkrL| jjd| d  d S d| j|< | jjd| jd | jd d	}|d
 s| jjd d S t	j
d|d
 t	jt	jB }|sd S |d }d}d}	d}
xd|j ko|	| jd k r^| j rd S |	dkrdt|	 }
|	d7 }	| jjd| d |jdd d |
 | jd | jd d	}|d ks^|jd
 rn| jjd d S |d
 }d|d
 krtd|d
 | j|}| j| t	j
d|d
 t	jt	jB }x|D ]}|| jkrܐqqd| j|< | jjd|  | jj|jdr| j rd S | jd r<| jj|| jd | jd d}|d
 d krh| jjd | d!  q||d
 kr| jjd | d" |  qtd#|| j|}| j| y&|d
 j|d$ }|t| d% }W n4 tk
r } z| jjd& wW Y d d }~X nX |d
 || }td'd(| d( | j|}| j| ntd#|| j|}| j| qW qW d 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)r8   
__module____qualname____doc__r   optdescsr   dictr   r   r   rL   r   r   r   r   r      s   r   )sflibr   r   r   r/   r   r   r   r   r   <module>   s   