U
    @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   s@   || _ |  | _d| _d| _t| D ]}|| | j|< q(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   sH  |j }|j}|j}| jd| d |  | jr4d S || jkrV| jd| d  d S d| j|< | jd s| jdd d| _d S | jd 	d	r| jd }n.| jd 	d
r| jd d	 }n| jd d }t
j|s| jd| d d| _d S | j|s| jdd d S zt| jd |ddd|gttd}|jd d\}}|jdkrX|}	n,| jdd | jd| d |  W d S z8t|	}
|
D ]$}td|d | j|}| | qW nB tk
r } z"| jdt| d W Y W d S d }~X Y nX W n@ tk
rB } z | jdt| d W Y d S d }~X Y 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)r3   
__module____qualname____doc__r   optdescsr   r   dictr   r   r    rB   r   r   r   r   r      s   
r   )
subprocessr   r   r"   os.pathr,   sflibr   r   r   r   r   r   r   r   <module>   s   