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                   @   sZ   e Zd ZdZdddddZdddd	dZd
ZdZe fddZ	dd Z
dd Zdd Zd
S )sfp_onioncityzOnion.link:Footprint,Investigate:Search Engines:apikey:Search Tor 'Onion City' search engine for mentions of the target domain. z!013611106330597893267:tfgl3wxdtbpT)api_keycse_id
fetchlinks	fullnamesz%Google API Key for Onion.link search.zGoogle Custom Search Engine ID.zQFetch the darknet pages (via TOR, if enabled) to verify they mention your target.zSearch for human names?NFc                 C   s:   || _ |  | _d| _t| D ]}|| | j|< q"d S )NF)sftempStorageresults
errorStatelistkeysopts)selfsfcuserOptsopt r   8/var/www/spiderfoot.crq.systems/modules/sfp_onioncity.pysetup)   s
    
zsfp_onioncity.setupc                 C   s   ddgS )NINTERNET_NAMEDOMAIN_NAMEr   r   r   r   r   watchedEvents2   s    zsfp_onioncity.watchedEventsc                 C   s
   dddgS )NDARKNET_MENTION_URLDARKNET_MENTION_CONTENTRAW_RIR_DATAr   r   r   r   r   producedEvents8   s    zsfp_onioncity.producedEventsc                    s&  |j }|j}|j} jrd S  jd s2|dkr2d S  jd| d |   jd dkrp jdd d	 _d S | jkr jd
| d  d S d	 j|<  jj	d|  jd  jd  jd  jd dd}|d krd S |d }t
t|t j  }|D ]}d	 j|< q|d }	 jj|	 jd  jd d}
|
d dkrjtd|
d  j|} | n jjddd   rd S  fdd|D }|D ]} jd|  |dd} jd  r jj| jd  jd d}|d d kr jd!| d"  qtd#t| d# |d tjd krT 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|} | qd S )+Nr
   
HUMAN_NAMEzReceived event, z, from r   r   z;You enabled sfp_onioncity but did not set a Google API key!FTzAlready did a search for z, skipping.z+site:onion.link _fetchtimeout
_useragentr   )timeout	useragentr   r   )searchStringr   urlswebSearchUrl)r$   r%   code)200201Z202r   contentz%Failed to fetch Google web search URL)	exceptionc                    s"   g | ]} j |d r|qS ).onion.link)r   urlFQDNendswith).0linkr   r   r   
<listcomp>|   s     z-sfp_onioncity.handleEvent.<locals>.<listcomp>zFound a darknet mention: r.   z.onionr	   z	Ignoring z as no data returnedz[^a-zA-Z\-\_0-9]z as no mention of r   x      zString not found in content.r   z...)	eventTypemoduledatar   r   r   debugerrorr   googleIterater   setr   fetchUrlr   __name__notifyListenerscheckForStopreplaceresearchescape
IGNORECASEindexlenBaseException)r   event	eventNamesrcModuleName	eventDataresr'   	new_linkslZgooglesearch_urlresponseevtZdarknet_linksr2   Ztorlink
startIndexendIndexer8   r   r   r   handleEvent<   s    

	   


 
 zsfp_onioncity.handleEvent)r>   
__module____qualname____doc__r   optdescsr   r   dictr   r   r    rU   r   r   r   r   r      s"   		r   )sflibr   r   r   rB   r   r   r   r   r   <module>   s   