3
@6^M                 @   sH   d dl Z d dlZd dlZd dlZd dlmZmZmZ G dd deZ	dS )    N)
SpiderFootSpiderFootPluginSpiderFootEventc               @   sV   e Zd ZdZdddZdddZdZe fdd	Zd
d Z	dd Z
dd Zdd ZdS )sfp_citadelz~Citadel Engine:Footprint,Investigate,Passive:Leaks, Dumps and Breaches:apikey:Searches Leak-Lookup.com's database of breaches. <   )api_keytimeoutzCLeak-Lookup API key. Without this you're limited to the public API.z-Custom timeout due to heavy traffic at times.Nc             C   s>   || _ | j | _d| _x"t|j D ]}|| | j|< q$W d S )NzLeak-Lookup.com)sftempStorageresults__dataSource__listkeysopts)selfsfcuserOptsopt r   6/var/www/spiderfoot.crq.systems/modules/sfp_citadel.pysetup    s
    
zsfp_citadel.setupc             C   s   dgS )N	EMAILADDRr   )r   r   r   r   watchedEvents)   s    zsfp_citadel.watchedEventsc             C   s   dgS )NEMAILADDR_COMPROMISEDr   )r   r   r   r   producedEvents/   s    zsfp_citadel.producedEventsc             C   s   | j d }|sd}|jdjdddd|d}| jjd	tjj|| j d
 | j d d}|d d krr| jjd d S yt	j
|d }W n4 tk
r } z| jjdt|  d S d }~X nX |S )Nr   Z 3edfb5603418f101926c64ca5dd0e409raw_unicode_escapeasciireplace)errorsZemail_address)querytypekeyz"https://leak-lookup.com/api/searchr	   
_useragent)postDatar	   	useragentcontentz No response from Leak-Lookup.comz Error processing JSON response: )r   encodedecoder
   fetchUrlurllibparse	urlencodedebugjsonloadsBaseExceptionstr)r   emailZapikeyparamsresdataer   r   r   
queryEmail4   s&    

zsfp_citadel.queryEmailc       
      C   s  |j }|j}|j}| jjd| d |  | jr4d S || jkrV| jjd| d  d S d| j|< | j|}|d krvd S |jd}|jd}|dkr| jj	d	j
||d
 d|krd| _d S d S |sd S xB|D ]:}| jjdj
|| tddj
||| j|}	| j|	 qW d S )NzReceived event, z, from z	Skipping z as already searched.Terrormessagetruez#Error encountered processing {}: {}FzMISSING APIz"Found Leak-Lookup entry for {}: {}r   z{} [{}])	eventTypemoduler5   r
   r-   
errorStater   r7   getr8   formatinfor   __name__notifyListeners)
r   event	eventNamesrcModuleName	eventDatar5   r8   r9   siteevtr   r   r   handleEventS   s6    





zsfp_citadel.handleEvent)rA   
__module____qualname____doc__r   optdescsr   dictr   r   r   r7   rI   r   r   r   r   r      s   	r   )
r.   urllib.requestr*   urllib.parseurllib.errorsflibr   r   r   r   r   r   r   r   <module>   s   