-
Notifications
You must be signed in to change notification settings - Fork 1
/
distributer.py
148 lines (113 loc) · 4.55 KB
/
distributer.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
#!/usr/bin/python
# -*- coding: UTF-8 -*-
import time
from celery import Celery
from config import conf_redis_backend,conf_redis_broker,conf_redis_db_storage
import urllib
import socket
import urllib2
import hashlib
from fingerprints import *
import re
import random
import json
import time
import redis
from gevent import monkey
agents=json.loads(open('user_agent.json').read())
distributer=Celery('distributer',broker=conf_redis_backend,backend=conf_redis_backend)
@distributer.task
def scan(url,cmsname,user_agent="random",timeout=10,proxy_settings=None,interval=None,confirm=False):
"TODO"
global agents
if(proxy_settings is not None):
proxy=urllib2.ProxyHandler(proxy_settings)
opener=urllib2.build_opener(proxy)
urllib2.install_opener(opener)
res=[]
errorcount=0
jobs=0
session=redis.StrictRedis.from_url(conf_redis_db_storage)
cmslist=[]
#for cmsname in cmsjobs:
while True:
try:
cms = json.loads(session.hget('cmslist',cmsname))#session.query(FingerPrints).filter(FingerPrints.cms==cmsname).all()
break
except Exception,e:
print "[-]ERR:",e
continue
#cms={'name':cmsname,'urls':[],'content':[]}
#for fingerprint in fingerprints:
# if(fingerprint.type=="hash"):
# cms['urls'].append({'fullMark':fingerprint.full_mark,'existMark':fingerprint.exist_mark,'md5':fingerprint.pattern,'addr':fingerprint.addr,'id':fingerprint.id})
# elif (fingerprint.type=='content'):
# cms['content'].append({'addr':fingerprint.addr,'data':fingerprint.pattern,'Mark':fingerprint.full_mark/3,'id':fingerprint.id})
#cmslist.append(cms)
#cms={'name':cmsnames,'urls':[],'content':[]}
confirmed=False
currentMark={"type":cms["name"],"credential":0,'fids':[]}
visited_url=[]
for u in cms["urls"]:
if interval is not None:
time.sleep(interval)
currentu=url+'/'+u["addr"]
try:
req=urllib2.Request(currentu)
if user_agent!="random":
req.add_header('User-Agent',user_agent)
else:
randpos=random.randint(0,len(agents)-1)
req.add_header('User-Agent',agents[randpos].encode('utf-8'))
response=urllib2.urlopen(req,timeout=timeout).read()
m=hashlib.md5()
m.update(response)
if m.hexdigest()==u["md5"].lower():
currentMark["credential"]+=u["fullMark"]
currentMark['fids'].append({'id':u['id'],'level':2})
if(confirm):
currentMark['cid']=u['id']
currentMark['confirm']=True
confirmed=True
break
elif u['addr'] not in visited_url:
currentMark["credential"]+=u["existMark"]
visited_url.append(u["addr"])
currentMark['fids'].append({'id':u['id'],'level':1})
except socket.error,sockerr:
print sockerr
continue
except urllib2.URLError,e:
print e.message
#print e.reason
continue
if confirm and confirmed:
print 'confirmed'
return currentMark
for c in cms["content"]:
currentu = url + '/' + c["addr"]
try:
req = urllib2.Request(currentu)
if user_agent != "random":
req.add_header('User-Agent', user_agent)
else:
randpos = random.randint(0, len(agents) - 1)
req.add_header('User-Agent', agents[randpos])
response = urllib2.urlopen(req, timeout=timeout).read()
if re.search(c['data'],response):
currentMark["credential"] += c["Mark"]*3
currentMark['fids'].append({'id':c['id'],'level':2})
except socket.error, sockerr:
print sockerr
continue
except urllib2.URLError,e:
print e.message
#print e.reason
continue
#res.append(currentMark)
currentMark['confirm']=confirmed
return currentMark
#if __name__=='__main__':
# from fingerprints import cmstypes
# import sys
# print scan(sys.argv[1],cmstypes[:10])