内容简介:我们都知道通过这段代码,我们就可以简单调用一个模块的函数了一个插件系统运转工作,主要进行以下几个方面的操作
__import__ 函数
我们都知道 import 是导入模块的,但是其实 import 实际上是使用 builtin 函数 import 来工作的。在一些程序中,我们可以动态去调用函数,如果我们知道模块的名称(字符串)的时候,我们可以很方便的使用动态调用
def getfunctionbyname(module_name, function_name):
module = __import__(module_name)
return getattr(module, function_name)
通过这段代码,我们就可以简单调用一个模块的函数了
插件系统开发流程
一个插件系统运转工作,主要进行以下几个方面的操作
.py sys.path
插件系统代码
在 lib/core/plugin.py 中创建一个 spiderplus 类,实现满足我们要求的代码
# __author__ = 'mathor'
import os
import sys
class spiderplus(object):
def __init__(self, plugin, disallow = []):
self.dir_exploit = []
self.disallow = ['__init__']
self.disallow.extend(disallow)
self.plugin = os.getcwd() + '/' + plugin
sys.path.append(plugin)
def list_plusg(self):
def filter_func(file):
if not file.endswith('.py'):
return False
for disfile in self.disallow:
if disfile in file:
return False
return True
dir_exploit = filter(filter_func, os.listdir(self.plugin)
return list(dir_exploit)
def work(self, url, html):
for _plugin in self.list_plusg():
try:
m = __import__(_plugin.split('.')[0])
spider = getattr(m, 'spider')
p = spider()
s = p.run(url, html)
except Exception as e:
print (e)
work 函数中需要传递url,html,这个就是我们扫描器传给插件系统的,通过代码
spider = getattr(m, 'spider') p = spider() s = p.run(url, html)
我们定义插件必须使用 class spider 中的 run 方法调用
扫描器中调用插件
我们主要用爬虫调用插件,因为插件需要传递url和网页源码这两个参数,所以我们在爬虫获取到这两个的地方加入插件系统代码即可
首先打开 Spider.py ,在 Spider.py 文件开头加上
from lib.core import plugin
然后在文件的末尾加上
disallow = ['sqlcheck']
_plugin = plugin.spiderplus('script', disallow)
_plugin.work(_str['url'], _str['html'])
disallow 是不允许的插件列表,为了方便测试,我们可以把sqlcheck填上
SQL注入融入插件系统
其实非常简单,只需要修改 script/sqlcheck.py 为下面即可
关于 Download 模块,其实就是 Downloader 模块,把 Downloader.py 复制一份命名为 Download.py 就行
import re, random
from lib.core import Download
class spider:
def run(self, url, html):
if (not url.find("?")): # Pseudo-static page
return false;
Downloader = Download.Downloader()
BOOLEAN_TESTS = (" AND %d=%d", " OR NOT (%d=%d)")
DBMS_ERRORS = {
# regular expressions used for DBMS recognition based on error message response
"MySQL": (r"SQL syntax.*MySQL", r"Warning.*mysql_.*", r"valid MySQL result", r"MySqlClient\."),
"PostgreSQL": (r"PostgreSQL.*ERROR", r"Warning.*\Wpg_.*", r"valid PostgreSQL result", r"Npgsql\."),
"Microsoft SQL Server": (r"Driver.* SQL[\-\_\ ]*Server", r"OLE DB.* SQL Server", r"(\W|\A)SQL Server.*Driver", r"Warning.*mssql_.*", r"(\W|\A)SQL Server.*[0-9a-fA-F]{8}", r"(?s)Exception.*\WSystem\.Data\.SqlClient\.", r"(?s)Exception.*\WRoadhouse\.Cms\."),
"Microsoft Access": (r"Microsoft Access Driver", r"JET Database Engine", r"Access Database Engine"),
"Oracle": (r"\bORA-[0-9][0-9][0-9][0-9]", r"Oracle error", r"Oracle.*Driver", r"Warning.*\Woci_.*", r"Warning.*\Wora_.*"),
"IBM DB2": (r"CLI Driver.*DB2", r"DB2 SQL error", r"\bdb2_\w+\("),
"SQLite": (r"SQLite/JDBCDriver", r"SQLite.Exception", r"System.Data.SQLite.SQLiteException", r"Warning.*sqlite_.*", r"Warning.*SQLite3::", r"\[SQLITE_ERROR\]"),
"Sybase": (r"(?i)Warning.*sybase.*", r"Sybase message", r"Sybase.*Server message.*"),
}
_url = url + "%29%28%22%27"
_content = Downloader.get(_url)
for (dbms, regex) in ((dbms, regex) for dbms in DBMS_ERRORS for regex in DBMS_ERRORS[dbms]):
if (re.search(regex,_content)):
return True
content = {}
content['origin'] = Downloader.get(_url)
for test_payload in BOOLEAN_TESTS:
# Right Page
RANDINT = random.randint(1, 255)
_url = url + test_payload % (RANDINT, RANDINT)
content["true"] = Downloader.get(_url)
_url = url + test_payload % (RANDINT, RANDINT + 1)
content["false"] = Downloader.get(_url)
if content["origin"] == content["true"] != content["false"]:
return "sql found: %" % url
E-Mail搜索插件
最后一个简单的例子,搜索网页中的E-Mail,因为插件系统会传递网页源码,我们用一个正则表达式 ([\w-]+@[\w-]+\.[\w-]+)+ 搜索出所有的邮件。创建 script/email_check.py 文件
# __author__ = 'mathor'
import re
class spider():
def run(self, url, html):
#print(html)
pattern = re.compile(r'([\w-]+@[\w-]+\.[\w-]+)+')
email_list = re.findall(pattern, html)
if (email_list):
print(email_list)
return True
return False
运行 python w8ay.py
可以看到网页中的邮箱都被采集到了
以上所述就是小编给大家介绍的《Python实现E-Mail收集插件》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!
猜你喜欢:- 配置ELK系统(ElasticSearch+Logstash+Kibana)收集nginx系统日志(三): Logstash的Grok过滤器插件原理
- JVM 笔记:垃圾收集算法与垃圾收集器
- JVM 笔记:垃圾收集算法与垃圾收集器
- Java 垃圾收集技术
- 日志收集的 “DNA”
- 信息收集很重要
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Chinese Authoritarianism in the Information Age
Routledge / 2018-2-13 / GBP 115.00
This book examines information and public opinion control by the authoritarian state in response to popular access to information and upgraded political communication channels among the citizens in co......一起来看看 《Chinese Authoritarianism in the Information Age》 这本书的介绍吧!