U
    @6^                     @   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                   @   sV   e Zd ZdZddddZ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_tool_whatwebzuTool - WhatWeb:Footprint,Investigate:Content Analysis:tool:Identify what software is in use on the specified website.   Zruby )
aggression	ruby_pathwhatweb_pathz"Set WhatWeb aggression level (1-4)zZPath to Ruby interpreter to use for WhatWeb. If just 'ruby' then it must be in your $PATH.z1Path to the whatweb executable file. 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_whatweb.pysetup(   s    
zsfp_tool_whatweb.setupc                 C   s   dgS )NINTERNET_NAMEr   r   r   r   r   watchedEvents1   s    zsfp_tool_whatweb.watchedEventsc                 C   s
   dddgS )NRAW_RIR_DATAWEBSERVER_BANNERWEBSERVER_TECHNOLOGYr   r   r   r   r   producedEvents4   s    zsfp_tool_whatweb.producedEventsc                 C   sp  |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 }| jd 	d	r|d
 }t
j|s| jd| d d| _d S | j|s| jdd d S z.t| jd }|dkrd}|dk rd}W n   d}Y nX | jd |ddt| ddd|g}z"t|ttd}|jd d\}	}
W n@ tk
r } z | jdt| d W Y d S d }~X Y nX |jdkr| jdd | jd|
 d |	  d S |	s | jd|  d S zt|	}W n@ tk
rN } z | jdt| d W Y d S d }~X Y nX tdt|| j|}| | d d!d"d#d$d%d&d'd(d)d*d+d,d-d.d/d0d1d2d3d4g}|D ]}|d5}|sq|d$r|d$d6D ] }td7|| j|}| | q|d1r4|d1d6D ] }td8|| j|}| | q|D ].}||krJq8td9|| j|}| | q8qd S ):NzReceived event, z, from z	Skipping z as already scanned.Tr   z@You enabled sfp_tool_whatweb but did not set a path to the tool!F/ZwhatwebzFile does not exist: zInvalid input, refusing to run.r
      r   r   z--quietz--aggression=z--log-json=/dev/stdoutz--user-agent=Mozilla/5.0z--follow-redirect=never)stdoutstderr)inputzUnable to run WhatWeb: r   zUnable to read WhatWeb output.zError running WhatWeb: z, zWhatWeb returned no output for z+Couldn't parse the JSON output of WhatWeb: r   ZCountryZIPScriptTitle
HTTPServerZRedirectLocationZUncommonHeadersz	Via-ProxyZCookiesHttpOnlyzStrict-Transport-Securityzx-hackerz	x-machinez
x-pingbackz	X-BackendzX-CachezX-UA-CompatiblezX-Powered-ByzX-Forwarded-ForzX-Frame-OptionszX-XSS-Protectionpluginsstringr    r!   SOFTWARE_USED)	eventTypemoduledatar   debugr   r   r   errorendswithospathisfilesanitiseInputintstrr   r   communicateBaseException
returncodejsonloadsr   __name__notifyListenersget)r   event	eventNamesrcModuleName	eventDataexer
   argspr%   r&   eZresult_jsonevt	blacklistresultZplugin_matcheswpluginr   r   r   handleEvent7   s    









                

zsfp_tool_whatweb.handleEvent)r@   
__module____qualname____doc__r   optdescsr   r   dictr   r   r"   rP   r   r   r   r   r      s   	r   )
subprocessr   r   ior>   os.pathr5   sflibr   r   r   r   r   r   r   r   <module>   s
   