-
Notifications
You must be signed in to change notification settings - Fork 5
/
update.py
178 lines (140 loc) · 4.2 KB
/
update.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
#!/usr/bin/env python
#coding=utf-8
import urllib
import urllib2
import os
import sys
import socket
from utils.BeautifulSoup import BeautifulSoup
import re
import time
import platform
g_cookie = 'csrftoken=jLySq58kvH7DW23sxIUwkVPpsOMStUdX; sessionid=8g49ri43mn8fgmic41gd1nt9x1ati6v1; CNZZDATA1253290531=1433061732-1414286034-%7C1414824533'
g_readme_head = ''' <html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css">
<!--
body { FONT-FAMILY: verdana; font-size: 10pt; color: #000000}
-->
</style>
<title>POC LIST</title>
</head>
<body bgcolor="#FFFFFF">
'''
def isWindow():
return "Window" in platform.platform()
def format_dos(info):
if not isWindow():
return info
else:
return str(info).decode("utf8").encode("gbk")
def strip_tags(html):
html = html.replace(' ', ' ')
html = html.replace('>', '>')
html = html.replace('<', '<')
html = html.replace('"', '"')
html = html.replace(''', "'")
html = html.replace('&', "&")
html = ''.join(html)
html = html[html.find('#!/'):]
return format_dos(html)
def getHtml(url):
info= ''
for i in range(3):
try:
req = urllib2.Request(url)
req.add_header('Cookie', g_cookie)
info = urllib2.urlopen(req).read()
break
except Exception,e:
time.sleep(i+1)
continue
return info
def getPoc(poc):
info = getHtml("http://beebeeto.com/pdb/" + poc + "/")
if '' == info:
return ''
if '<img src="/static/img/test.jpg"' in info:
return ''
bt = BeautifulSoup(info)
ret = bt.find('pre', {'class' : "brush: python;"})
ret = ret.renderContents()
if ret:
return strip_tags(ret)
else:
return ''
def makeReadme(name, info):
ret = re.findall("'name'.*", info)
if ret == '':
return
info = ret[0].replace("'name'", "")
info = info.replace(":", "")
info = info.replace("'", "")
info = info.replace(",", "")
info = info.strip()
if not os.path.exists("./poc/readme.html"):
with open("./poc/readme.html", 'w') as fp:
fp.write(g_readme_head)
info = "[<a href=%s>%s<a>]%s\r\n<br>" % ("http://beebeeto.com/pdb/"+name, name, info)
with open("./poc/readme.html", 'a') as fp: fp.write(info)
def savePoc(name, info):
if '' == info:
return
if not os.path.exists('./poc'):
os.mkdir('./poc')
sname = "./poc/" + name + ".py"
if os.path.exists(sname):
return
with open(sname, "wb") as fp:
fp.write(str(info))
makeReadme(name, info)
def get_onepage_poclist(page):
info = getHtml("http://beebeeto.com/pdb" + '/?page=' + str(page))
if '' == info:
return ''
bt = BeautifulSoup(info)
end = bt.find('a', {'style' : "font-size: 20px;font-weight: bold; border-bottom: 3px solid #777777;"})
if '1' == end.renderContents() and page != 1:
return ''
ret = bt.find('div', {'class' : 'mainlist'})
ret = ret.renderContents()
if ret == "":
return ""
retlist = []
rets = re.findall('<a href=.*?>', ret)
for one in rets:
if "poc-" in one:
one = one.replace('<a href="', "")
one = one.replace('">', "")
one = one.strip()
retlist.append(one)
return retlist
def main():
sum = 0
socket.setdefaulttimeout(10)
info = getHtml("http://beebeeto.com/")
if "注册" in info and "登录" in info:
print "[ERR] The cookie is error!"
return
for i in range(1,1000):
pocs = get_onepage_poclist(i)
if "" == pocs:
break
for t in pocs:
print "[*] Get Poc -> %s " % t
info = getPoc(t)
if info == "": continue
savePoc(t, info)
sum = sum + 1
print "[*] The total number of POC is %d " % sum
if __name__ == "__main__":
if len(sys.argv) < 2:
print "usage: update.py cookie"
sys.exit()
else:
g_cookie = sys.argv[1]
main()
#info = getPoc("poc-2014-0115")
#savePoc('poc-2014-0115', info)
#open('txt.html', 'w').write(str(info))