• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

Python实现E-Mail收集插件实例教程

python 搞代码 4年前 (2022-01-07) 27次浏览 已收录 0个评论

这篇文章主要给大家介绍了关于Python实现E-Mail收集插件的相关资料,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面来一起看看吧

__import__函数

我们都知道import是导入模块的,但是其实import实际上是使用builtin函数import来工作的。在一些程序中,我们可以动态去调用函数,如果我们知道模块的名称(字符串)的时候,我们可以很方便的使用动态调用

 def getfunctionbyname(module_name, function_name): module = __import__(module_name) return getattr(module, function_name)

通过这段代码,我们就可以简单调用一个模块的函数了

插件系统开发流程

一个插件系统运转工作,主要进行以下几个方面的操作

  • 获取插件,通过对一个目录里的.py文件扫描得到
  • 将插件目录加入到环境变量sys.path
  • 爬虫将扫描好的 URL 和网页源码传递给插件
  • 插件工作,工作完毕后将主动权还给扫描器

插件系统代码

在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 = (" A<a style="color:transparent">来源gao*daima.com搞@代#码网</a>ND %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

可以看到网页中的邮箱都被采集到了

总结

以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,如果有疑问大家可以留言交流,谢谢大家对gaodaima搞代码网的支持。

以上就是Python实现E-Mail收集插件实例教程的详细内容,更多请关注gaodaima搞代码网其它相关文章!


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:Python实现E-Mail收集插件实例教程

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址