3
@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   sD   || _ | j | _d| _d| _x"t|j D ]}|| | j|< q*W 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          7   C   sp  |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 j	d	r|d
 }t
jj|s| jjd| d d| _d S | jj|s| jjdd d S y.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}y"t|ttd}|jd d\}	}
W n8 tk
r } z| jjdt| d d S d }~X nX |jdkr| jjdd | jjd|
 d |	  d S |	s| jjd|  d S ytj|	}W n8 tk
r> } z| jjdt| d d S d }~X nX tdt|| j|}| j| d d!d"d#d$d%d&d'd(d)d*d+d,d-d.d/d0d1d2d3d4g}x|D ]}|jd5}|sq|jd$rx4|jd$jd6D ] }td7|| j|}| j| qW |jd1r.x4|jd1jd6D ] }td8|| j|}| j| q
W x6|D ].}||krFq4td9|| j|}| j| q4W qW d 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IPZ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!   rN   r   r   r   r   r      s   	r   )
subprocessr   r   ior<   os.pathr3   sflibr   r   r   r   r   r   r   r   <module>   s
   