烏雲漏洞爬蟲的資料庫版本(mysql)

2022-05-23 20:30:11 字數 4705 閱讀 4581

特別鳴謝阮思綺同學!雖然感覺這個冷冷的部落格也沒人看23333

import

mysql.connector

import

sys, os

import

urllib.request

import

reimport

itertools

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)

except

mysql.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)

except

mysql.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) in

cursor:

print("

id:{} type:{} info:{} repair:{}

".format(id, type, info, detail, repair))

except

mysql.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')

return

html_response

defgeturl(starturl):

a=get_html_response(starturl)

childurl=(re.findall(r'

/bugs/wooyun-\w*-\w*\b

',a))

return

childurl

defget_nextpage(starturl):

d=get_html_response(starturl)

nextpage=(re.findall(r'

searchbug.php\?q=6yer6j6n&pno=\w

',d))

return

nextpage

starturl="

"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 in

get_nextpage(starturl):

result+=geturl('

'+re.sub('

金融','

6yer6j6n

',i))

#掃瞄各種漏洞的url位址放入result中

result=set(result)#

去除result中重複的位址

for i in

result:

k=get_html_response('

'+re.sub('

金融','

%e9%87%91%e8%9e%8d

',i))#

type_wooyun=re.findall(r'

漏洞型別:.*.

',k)

info=re.findall(r'

',k)#

空白字元用/s,尋找所有適用於\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+=j

for 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=j.split()

info_n+=j

for 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) detail_n+=j

for j in repair:#

處理回覆方法

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()

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))

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()

資料庫mysql軟體安裝 資料庫軟體mysql安裝

2.解壓至欲安裝的目錄下 3.開啟cmd,進入軟體目錄下d qmdownload mysql 5.7.24 winx64 bin,執行mysqld 4.初始化使用者 cmd d qmdownload mysql 5.7.24 winx64 bin,執行mysqld initialize insecu...

python 資料庫 爬蟲

python3 和 pip3 安裝 安裝 selenium 配置驅動的環境變數,或者將驅動放到已經配置好的資料夾中,類似 window 的 cmd的目錄 window c windows system32 linux usr bin usr local bin 安裝 pyquery 安裝pymysq...

mysql資料庫之python鏈結mysql

使用之前請在命令列pip install pymysql import pymysql 1.建立鏈結 conn pymysql.connect host 127.0.0.1 ip位址 port 3306,埠號 database database name 資料庫名稱 user mysql usern...