新兴开源扫描器Golismero插件编写-UI插件编写
Golismero是一款开源的Web扫描器,它不但自带不少的安全测试工具,而且还可导入分析市面流行的扫描工具的结果,比如Openvas,Wfuzz, SQLMap, DNS recon等,并自动分析。Golismero采用插件形式的框架结构,由纯python编写,并集成了许多开源的安全工具,可以运行在Windows,Linux, BSD,OS X等系统上,几乎没有系统依赖性,唯一的要求就是python的版本不低于2.7,其官网是:https://golismero-project.com。
Golismero采用了插件式的框架结构,提供了一系列的接口,用户只要继承并且实现这些接口,就可以自定义自己的插件。根据插件的功能,可分为四类,每个类别的插件的接口都不同,所以在编写自定义插件的时候,注意选择好相应的插件类型。
a. ImportPlugin(导入插件)
导入插件主要是用来加载其他安全工具的扫描结果
b. TestingPlugin(测试插件)
测试插件主要是用来测试或者渗透入侵的插件
c. ReportPlugin(报表插件)
报表插件主要是对测试结果生成报表。
d. UIPlugin(界面插件)
界面插件主要是用于和用户交互的,显示当前系统的运行情况。
插件编写
UIPlugin编写
这是Golismero的界面插件,主要用于展示当前系统的运行详细状态信息,其接口类如下:
接口类
golismero.api.plugin.UIPlugin
基类
+ golismero.api.plugin._InformationPlugin + golismero.api.plugin.Plugin +Object
接口基类:
_init_
x.__init__(...) initializes x; see help(type(x)) for signature
check_params(options, *audits)
Parameters:
options (OrchestratorConfig) – Orchestrator settings. audits (AuditConfig) – Audit settings. Raises: AttributeError – A critical configuration option is missing. ValueError – A configuration option has an incorrect value. TypeError – A configuration option has a value of a wrong type. Exception – An error occurred while validating the settings.
recv_info(info)
Callback method to receive data to be processed. This is the most important method of a plugin. Here’s where most of the logic resides. [Parameters]: info (Data) – Data to be processed.
recv_msg(message)
Callback method to receive control messages to be processed. Parameters: message (Message) – incoming message to process Returns: Shared plugin state variables.
state
Return type: PluginState
update_status(progress=None)
Plugins can call this method to tell the user of the current progress of whatever the plugin is doing. Warning Do not override this method! Note This method may not be supported in future versions of GoLismero. Parameters: progress (float | None) – Progress percentage [0, 100] as a float, or None to indicate progress can’t be measured.
下面就以编写一个显示各个插件运行时间logtime插件为例,UI控件必须放置在\plugins\ui目录下,每个插件都需要一个后缀名为.golismero的说明文档,以及相应python脚本文件。定义logtime的配置说明文件plugins\ui\logtime.golismero,代码如下:
[Core] Name = Logtime UI [Documentation] Description = Show time plugin runs in console. Author = GoLismero project team Version = 0.1 Website = https://www.freebuf.com Copyright = Copyright (C) 2011-2013 GoLismero Project License = GNU Public License
Python脚本文件plugins\ui\logtime.py,内容如下:
#!/usr/bin/env python # -*- coding: utf-8 -*- __license__ = """ """ from golismero.api.audit import get_audit_count from golismero.api.config import Config from golismero.api.data import Data from golismero.api.plugin import UIPlugin, get_plugin_info from golismero.main.console import Console, colorize from golismero.messaging.codes import MessageType, MessageCode, MessagePriority import time class LogTimePlugin(UIPlugin): """ This demo shows how to write a UI plugin to melismero, it will show how long each plugin runs, more infos plz refer to the following links. https://www.freebuf.com """ #---------------------------------------------------------------------- def __init__(self): """ we init a dictionary to record the time when plugins start and stop {"pluginname1":{'start':12123123,'stop':999999}, "pluginname2":{'start':12123123,'stop':999999},} """ self._logplugindic={} #-------------------------------------------------------------------------- def check_params(self, options, *audits): """ Usually, we just judge the audits whether 'audit' is empty. But you have check the input arguments if your plugin requires them. """ if not audits: raise ValueError("No targets selected!") #-------------------------------------------------------------------------- def recv_info(self, info): """ Process the data if you wanna handle them. As we just wanna log the time when plugin start/stop, so we don't care about the detailed info about the data 'info' """ pass #-------------------------------------------------------------------------- def recv_msg(self, message): # Process status messages if message.message_type == MessageType.MSG_TYPE_STATUS: plugin_name = message.plugin_name if not plugin_name: return if message.message_code == MessageCode.MSG_STATUS_PLUGIN_BEGIN: nowtimesec=time.time() self._logplugindic[plugin_name]=dict(start=nowtimesec) elif message.message_code == MessageCode.MSG_STATUS_PLUGIN_END: nowtimesec=time.time() try: self._logplugindic[plugin_name]['stop']=nowtimesec # we do something about 'self._logplugindic' # .... # now , i just print how long plugin runs showplugname = get_plugin_info(plugin_name).display_name if not showplugname: showplugname = plugin_name if not self._logplugindic[plugin_name] or not self._logplugindic[plugin_name]['start']: text = "[#] Plugin '%s' runs for ... i don't know " % (showplugname) else: runtime = self._logplugindic[plugin_name]['stop']-self._logplugindic[plugin_name]['start'] text = "[#] Plugin '%s' runned for %d seconds" % (showplugname, runtime) except: text = "[#] Error occurs" Console.display(text)
上面每个函数都给出了注释(因为是我这个编辑器不支持中文,所以只好用中式英文来说明了,大家将就看吧),功能很简单,就是记录在扫描过程中,统计每个插件的运行时间,并显示出来。
执行python golismero.py –plugin-list,看看我们的插件是否被识别出来,执行结果如下:
/----------------------------------------------\ | GoLismero 2.0.0b1 - The Web Knife | | Contact: golismero.project<@>gmail.com | | | | Daniel Garcia Garcia a.k.a cr0hn (@ggdaniel) | | Mario Vilas (@Mario_Vilas) | \----------------------------------------------/ ------------- Plugin list ------------- -= Import plugins =- …………………………………………………….<此处省略N多> -= UI plugins =- console: Console user interface. disabled: Empty user interface. logtime: Show time plugin runs in console
可以看到我们的插件可以被正确识别,接下来执行时,将UI界面切换到我们刚写的UI界面插件上,执行
python golismero –ui-mode logtime ww.jike521.com -o result.html
其结果如下:
/----------------------------------------------\ | GoLismero 2.0.0b1 - The Web Knife | | Contact: golismero.project<@>gmail.com | | | | Daniel Garcia Garcia a.k.a cr0hn (@ggdaniel) | | Mario Vilas (@Mario_Vilas) | \----------------------------------------------/ GoLismero started at 2013-09-16 16:41:21.146000 [#] Plugin 'Suspicious URL' runned for 4 seconds [#] Plugin 'OS fingerprinting plugin' runned for 58 seconds [#] Plugin 'theHarvester' runned for 61 seconds [#] Plugin 'Web Spider' runned for 65 seconds [#] Plugin 'OS fingerprinting plugin' runned for 65 seconds [#] Plugin 'Robots.txt Analyzer' runned for 65 seconds [#] Plugin 'Web Server fingerprinting plugin' runned for 67 seconds [#] Plugin 'DNS zone transfer' runned for 82 seconds [#] Plugin 'DNS zone transfer' runned for 83 seconds [#] Plugin 'DNS analyzer' runned for 84 seconds [#] Plugin 'theHarvester' runned for 85 seconds [#] Plugin 'DNS analyzer' runned for 85 seconds [#] Plugin 'DNS subdomain bruteforcer' runned for 473 seconds [#] Plugin 'DNS subdomain bruteforcer' runned for 503 seconds [#] Plugin 'Default Error page finder' runned for 2 seconds [#] Plugin 'Bruteforce permutations discovery' runned for 0 seconds [#] Plugin 'Bruteforce file extensions discovery' runned for 0 seconds [#] Plugin 'Bruteforce suffixes discovery' runned for 1 seconds [#] Plugin 'Bruteforce prefixes discovery' runned for 1 seconds [#] Plugin 'Bruteforce directories discovery' runned for 2 seconds [#] Plugin 'Nikto' runned for 2 seconds [#] Plugin 'OpenVAS' runned for 2 seconds [#] Plugin 'Bruteforce predictables discovery' runned for 5 seconds
显然,Golismero只能支持单个UI插件,无法同时支持多个UI插件,导致无法支持多路UI输出。最典型的缺陷就是如果将其改造成分布式的部署结构,我们开发一个向统计服务器推送当前状态显示的UIPlugin,又有个和用户交互的UIPlugin时,那么这两个UI Plugin是无法同时启动的
上一篇: 笔记本电脑设置网络连接优先级方法步骤介绍