U
    @6^L                     @   sP   d dl mZm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 )    )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_cmseekzvTool - CMSeeK:Footprint,Investigate:Content Analysis:tool:Identify what Content Management System (CMS) might be used.python3 )
pythonpath
cmseekpathz_Path to Python 3 interpreter to use for CMSeeK. If just 'python3' then it must be in your PATH.z8Path to the where the cmseek.py file lives. Must be set.NFc                 C   s@   || _ |  | _d| _d| _t| D ]}|| | j|< q(d S )NFzTarget Website)sftempStorageresults
errorState__dataSource__listkeysopts)selfsfcuserOptsopt r   :/var/www/spiderfoot.crq.systems/modules/sfp_tool_cmseek.pysetup&   s    
zsfp_tool_cmseek.setupc                 C   s   dgS )NINTERNET_NAMEr   r   r   r   r   watchedEvents0   s    zsfp_tool_cmseek.watchedEventsc                 C   s   dgS )NWEBSERVER_TECHNOLOGYr   r   r   r   r   producedEvents6   s    zsfp_tool_cmseek.producedEventsc              
   C   s  |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 }| jd 
d	d
 d }nJ| jd 	dr| jd d	 }| jd d }n| jd d }| jd d }tj|s*| jd| d d| _d S | j|sJ| jdd d S zt| jd |dd|gttd}|jd d\}}	|jd
kr|}
n,| jdd | jd|	 d |  W d S d|
kr| jd|  W d S zJtj|d | d dd}t| }td|d | j|}| | W nB tk
rf } z"| jd t| d W Y W d S d }~X Y nX W n@ tk
r } 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   z?You enabled sfp_tool_cmseek but did not set a path to the tool!Fz	cmseek.pyr   z/Result/Resultz
/cmseek.pyzFile does not exist: zInvalid input, refusing to run.r
   z--follow-redirectz-u)stdoutstderr)inputzUnable to read CMSeeK content.zError running CMSeeK: z, zCMS Detection failedzCouldn't detect the CMS for z	/cms.jsonzutf-8)encodingr   Zcms_namez*Couldn't parse the JSON output of CMSeeK: zUnable to run CMSeeK: )	eventTypemoduledatar   debugr   r   r   errorendswithsplitospathisfilesanitiseInputr   r   communicate
returncodeioopenjsonloadsreadr   __name__notifyListenersBaseExceptionstr)r   event	eventNamesrcModuleName	eventDataexeZ
resultpathpr"   r#   contentfjevter   r   r   handleEvent:   sl    





 zsfp_tool_cmseek.handleEvent)r8   
__module____qualname____doc__r   optdescsr   r   dictr   r   r   rG   r   r   r   r   r      s   
r   )
subprocessr   r   r3   r5   os.pathr-   sflibr   r   r   r   r   r   r   r   <module>   s
   