mysql有漏洞的版本_乌云漏洞爬虫的数据库版本(mysql)

importmysql.connectorimportsys, osimporturllib.requestimportreimportitertools

user= 'root'pwd= ''host= '127.0.0.1'db= 'test'data_file= 'wooyun.dat'create_table_sql= "CREATE TABLE IF NOT EXISTS mytable (id int(10) AUTO_INCREMENT PRIMARY KEY, type varchar(300) , info varchar(1000) , detail varchar(5000) , repair varchar(1000) )CHARACTER SET utf8"insert_sql= "INSERT INTO mytable (type, info, detail, repair) VALUES ( %s, %s, %s, %s)"select_sql= "SELECT id, type, info, detail, repair FROM mytable"cnx= mysql.connector.connect(user=user, password=pwd, host=host, database=db)

cursor=cnx.cursor()defcreate_table_sql_api(a):try:

cursor.execute(a)exceptmysql.connector.Error as err:print("create table 'mytable' failed.")print("Error: {}".format(err.msg))

sys.exit()definsert_sql_api(a,b):try:

cursor.execute(a,b)exceptmysql.connector.Error as err:print("insert table 'mytable' failed.")print("Error: {}".format(err.msg))

sys.exit()defselect_sql_api(a):try:

cursor.execute(a)for (id, type, info, detail, repair) incursor:print("ID:{} type:{} info:{} repair:{}".format(id, type, info, detail, repair))exceptmysql.connector.Error as err:print("query table 'mytable' failed.")print("Error: {}".format(err.msg))

sys.exit()defget_html_response(url):

html_response= urllib.request.urlopen(url).read().decode('utf-8')returnhtml_responsedefgeturl(starturl):

a=get_html_response(starturl)

childurl=(re.findall(r'/bugs/wooyun-\w*-\w*\b',a))returnchildurldefget_nextpage(starturl):

d=get_html_response(starturl)

nextpage=(re.findall(r'searchbug.php\?q=6YeR6J6N&pNO=\w',d))returnnextpage

starturl="http://www.wooyun.org/searchbug.php?q=6YeR6J6N"result=[]

final=[]

type_wooyun_n=[]

info_n=[]

detail_n=[]

repair_n=[]#output=open("D:\\wooyun.csv","w+")

create_table_sql_api(create_table_sql)for i inget_nextpage(starturl):

result+=geturl('http://wooyun.org/'+re.sub('金融','6YeR6J6N',i))#扫描各种漏洞的url地址放入result中

result=set(result)#去除result中重复的地址

for i inresult:

k=get_html_response('http://wooyun.org/'+re.sub('金融','%E9%87%91%E8%9E%8D',i))#下载页面到k

type_wooyun=re.findall(r'漏洞类型:.*.',k)

info=re.findall(r'

\w*:.*.

',k)#空白字符用/s,寻找所有适用于

标签的文字

detail=re.findall(r'

.*.

',k)

repair=re.findall(r'修复方案:\s*

.*.\s*

',k)for j in type_wooyun:#漏洞类型,为之后进行数据库分类做准备

j=re.sub(r':\s',':',j)

j=re.sub(r'\t','',j)

j=re.sub(r'','',j)

type_wooyun_n+=jfor j in info:#处理概要

j=re.sub(r':\s',':',j)

j=re.sub(r'

','',j)

j=re.sub(r'','',j)

j=re.sub(r'','',j)

j=re.sub(r'','',j)

j=re.sub(r'','',j)

j=j.split()

info_n+=jfor j in detail:#处理详情

j=re.sub(r':\s',':',j)

j=re.sub(r'

','',j)

j=re.sub(r'

','',j)

j=re.sub(r'"\starget="_blank">',',',j)

j=re.sub(r'','',j)

j=re.sub(r':',':',j)

j=j.split()

repair_n+=j

type_wooyun_str="".join(itertools.chain(*type_wooyun_n))

info_str="".join(itertools.chain(*info_n))

detail_str="".join(itertools.chain(*detail_n))

repair_str="".join(itertools.chain(*repair_n))

final.append(type_wooyun_str)

final.append(info_str)

final.append(detail_str)

final.append(repair_str)

insert_sql_api(insert_sql,tuple(final))

select_sql_api(select_sql)#output.writelines(final)

#output.writelines('\n\n')

final.clear()

repair_n.clear()

info_n.clear()

type_wooyun_n.clear()

detail_n.clear()

cnx.commit()

cursor.close()

cnx.close()#output.close()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值