【4】Golismero报表编写-ReportPlugin插件编写
来源:互联网 发布:小米盒子 知乎 编辑:程序博客网 时间:2024/05/22 04:41
地址: http://blog.csdn.net/hujkay
作者:Jekkay Hu(34538980@qq.com)
关键词:golismero, web扫描器, 插件编写
时间: 2013/10/29
4. 报表插件
报表插件(ReportPlugin)是用于在扫描完成后,将扫描结果输出为特定格式的的插件,它的接口类是:
接口
class golismero.api.plugin.ReportPlugin
基类
+ golismero.api.plugin.Plugin
+ Object
该类的接口方法如下:
接口方法
说明
_init_
x.__init__(...) initializes x; see help(type(x)) for signature
generate_report(output_file)
Run plugin and generate the report.
This is the entry point for Report plugins, where most of the logic resides.
Parameters:
output_file (str) – Output file to generate.
is_supported(output_file)
Determine if this plugin supports the requested file format.
Tipically, here is where Report plugins examine the file extension.
Parameters:
output_file (str) – Output file to generate.
Returns:
True if this plugin supports the format, False otherwise.
Return type:
bool
state
Returns:
Shared plugin state variables.
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.
下面我就以写一个报表插件vul,用输出XML格式的漏洞列表。
1. 新建配置文件plugins/report/vul.golismero,定义插件的相关描述信息,其内容如下:
[Documentation]
Name = vul Report
Description = Writes XML text reports about Vulnerabilities.
Author = Jekkay Hu
Version = 0.1
Website = http://blog.csdn.net/hujkay
Copyright = Copyright (C) 2011-2013
License = GNU Public License
2. 新建插件vul实现文件plugins/report/vul.py,其代码内容如下:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from golismero.api.data import Data
from golismero.api.data.db import Database
from golismero.api.plugin import ReportPlugin, get_plugin_name
class VulReport(ReportPlugin):
def __init__(self):
super(VulReport,self).__init__()
self._fd = None
def is_supported(self, output_file):
"""
judge if support output file
"""
return (
output_file
and output_file.lower().endswith(".vul")
)
def generate_report(self, output_file):
with open(output_file, mode='w') as self.__fd:
self.__write_report()
def __iterate(self, data_type = None, data_subtype = None):
if Database.count(data_type, data_type) < 100:
return Database.get_many(
Database.keys(data_type=data_type, data_subtype=data_subtype)
)
return Database.iterate(data_type=data_type, data_subtype=data_subtype)
def __write_report(self):
count = Database.count(Data.TYPE_VULNERABILITY)
print >> self._fd, r"<vulroot version='1.0' amount='%d' >" % count
if count <= 0:
print >> self._fd, r"</vulroot>"
return
vuln_types = { v.display_name: v.vulnerability_type for v in self.__iterate(Data.TYPE_VULNERABILITY) }
titles = vuln_types.keys()
titles.sort()
if "Uncategorized Vulnerability" in titles:
titles.remove("Uncategorized Vulnerability")
titles.append("Uncategorized Vulnerability")
for title in titles:
data_subtype = vuln_types[title]
print >> self.__fd, r" <vuls title='%s' data_subtype='%s'>" % (title, data_subtype)
for vuln in self.__iterate(Data.TYPE_VULNERABILITY, data_subtype):
print >> self.__fd, r" <vul>"
print >> self.__fd, r" <Occurrence ID='%s'/>" % (vuln.identity)
print >> self.__fd, r" <Title>%s</Title>" % (vuln.title)
print >> self.__fd, r" <Foundby>%s</Foundby>" % get_plugin_name(vuln.plugin_id)
print >> self.__fd, r" <Level>%s</Level>" % str(vuln.level)
print >> self.__fd, r" <Impact>%s</Impact>" % str(vuln.impact)
print >> self.__fd, r" <Severity>%s</Severity>" % str(vuln.severity)
print >> self.__fd, r" <Risk>%s</Risk>" % str(vuln.risk)
print >> self.__fd, r" <Description>%s</Description>" % str(vuln.description)
print >> self.__fd, r" <Solution>%s</Solution>" % str(vuln.solution)
print >> self.__fd, r" </vul>"
print >> self.__fd, r" </vuls>"
print >> self._fd, r"</vulroot>"
3. 启动命令
python golismero.py -nd -e spider -e findadminpage -o result.vul 127.0.0.1 -r 3
4. 执行完之后,查看文件result.vul内容:
<vuls title='Suspicious URL' data_subtype='suspicious/url'>
<vul>
<Occurrence ID='9f17c727f5367b0f91d1dbcb59b8ec8e'/>
<Title>User attention required by: testing/scan/findadminpage</Title>
<Foundby>testing/scan/findadminpage</Foundby>
<Level>informational</Level>
<Impact>0</Impact>
<Severity>0</Severity>
<Risk>0</Risk>
<Description>Find the admin webpage [http://127.0.0.1/admin.html] </Description>
<Solution>No additional details are available.</Solution>
</vul>
</vuls>
BTW,爬虫一直是非常耗时的,而Golismero从版本2.0.0开始已经可以支持自定爬虫深度和插件处理资源的深度(事实上,爬虫也是一种插件),比如使用参数 -r 2,那么所有的插件都只会处理深度为2以内的url等资源,而‘-r inf’表示无限,但是目前版本2.0.0b2中仍然存在一个小问题,就是不管设置深度为多少,爬虫插件都会抓取所有的页面,期待下个版本会加以优化。
Jekkay Hu,胡杨
2013/10/29
- 【4】Golismero报表编写-ReportPlugin插件编写
- 【1】Golismero插件编写-UI插件编写
- 【2】Golismero插件编写-TestingPlugin插件编写
- 【3】Golismero插件编写-ImportPlugin插件编写
- 插件编写
- 插件编写
- 编写报表SQL语句
- vba 编写自动报表
- golismero
- ABAP报表程序编写规范
- 用DELPHI编写特殊报表
- 编写QQ外挂插件的提示[4]
- Maven学习4:编写maven插件补充
- 编写Qtopia插件
- Writing Plugins编写插件
- 编写.net插件初试
- 求助: 编写VC插件
- 如何编写lighttpd插件
- Linux操作系统下编译支持NTFS的内核模块
- 第一个opencv程序
- <mx:states>使用实例
- Yii 框架里数据库操作详解-增加、查询、更新、删除的方法
- const的使用(C++编程规范)
- 【4】Golismero报表编写-ReportPlugin插件编写
- YARN/MRv2 Resource Manager深入剖析—AM管理
- 如何通过IIS浏览.log文件
- Python2.7.3移除字符串中重复字符(一)
- 我们一起来游戏 (三)——(AS3零基础做AIR卡牌网游)
- 提升模拟器
- hibernate 源码研究
- 实时数据采集传输软件LDM配置
- 我们一起来游戏 (四)——(AS3零基础做AIR卡牌网游)