3
@6^                 @   sH   d dl mZm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 )    )PopenPIPEN)
SpiderFootSpiderFootPluginSpiderFootEventc               @   sR   e Zd ZdZdddZ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_tool_dnstwistzTool - DNSTwist:Footprint,Investigate:DNS:tool:Identify bit-squatting, typo and other similar domains to the target using a local DNSTwist installation.python )
pythonpathdnstwistpathz^Path to Python interpreter to use for DNSTwist. If just 'python' then it must be in your PATH.z:Path to the where the dnstwist.py file lives. Must be set.NFc             C   sD   || _ | j | _d| _d| _x"t|j D ]}|| | j|< q*W d S )NFDNS)sftempStorageresults
errorState__dataSource__listkeysopts)selfsfcuserOptsopt r   </var/www/spiderfoot.crq.systems/modules/sfp_tool_dnstwist.pysetup%   s    
zsfp_tool_dnstwist.setupc             C   s   dgS )NDOMAIN_NAMEr   )r   r   r   r   watchedEvents/   s    zsfp_tool_dnstwist.watchedEventsc             C   s   dgS )NSIMILARDOMAINr   )r   r   r   r   producedEvents5   s    z sfp_tool_dnstwist.producedEventsc             C   s8  |j }|j}|j}| jjd| d |  | jr4d S || jkrV| jjd| d  d S d| j|< | jd s| jjdd d| _d S | jd j	d	r| jd }n.| jd j	d
r| jd d	 }n| jd d }t
jj|s| jjd| d d| _d S | jj|s| jjdd d S yt| jd |ddd|gttd}|jd d\}}|jdkrX|}	n*| jjdd | jjd| d |  d S y<tj|	}
x,|
D ]$}td|d | j|}| j| qW W n8 tk
r } z| jjdt| d d S d }~X nX W n8 tk
r2 } z| jjdt| d d S d }~X nX d S )NzReceived event, z, from z	Skipping z as already scanned.Tr   zAYou enabled sfp_tool_dnstwist but did not set a path to the tool!Fzdnstwist.py/z/dnstwist.pyzFile does not exist: zInvalid input, refusing to run.r
   z-fjsonz-r)stdoutstderr)inputr   z Unable to read DNSTwist content.zError running DNSTwist: z, r   zdomain-namez,Couldn't parse the JSON output of DNSTwist: zUnable to run DNSTwist: )	eventTypemoduledatar   debugr   r   r   errorendswithospathisfilesanitiseInputr   r   communicate
returncoder!   loadsr   __name__notifyListenersBaseExceptionstr)r   event	eventNamesrcModuleName	eventDataexepr"   r#   contentjrevter   r   r   handleEvent9   s\    


 



zsfp_tool_dnstwist.handleEvent)r2   
__module____qualname____doc__r   optdescsr   r   dictr   r   r   rA   r   r   r   r   r      s   
r   )
subprocessr   r   r!   os.pathr+   sflibr   r   r   r   r   r   r   r   <module>   s   