forked from sebdraven/OSINT
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathactions.py
175 lines (153 loc) · 5.78 KB
/
actions.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
'''
Created on Feb 1, 2013
@author: slarinier
'''
from harvesting import search
from harvesting.crawler import Record, CrawlerThread
from network import make_networks, networks
from processing import metadataextract
from processing.clean_db import Cleandb
from processing.create_result import Create_Result
from processing.dnstree import DNSTree
from pymongo.connection import Connection
from screenshots.screenshots import Screenshots
import mongodb
import pymongo
import threading
class Actions(object):
'''
classdocs
'''
def __init__(self,db_value):
self.db_value=db_value
connection=Connection('localhost',27017)
self.db=connection[db_value]
def create_network(self):
network=make_networks.make_networks('localhost', self.db_value)
network.createNetworks('new_domaines')
network.exportFile(self.db_value+'_network.log')
def create_result(self,collection,criteria):
createResult=Create_Result(self.db_value,criteria)
if collection=='scanners':
createResult.processScanners(collection)
return
createResult.process(collection)
def metasearch(self,criteria,scriptsJS,geoloc):
print "########### Meta Search ###########"
main_thread = threading.currentThread()
thread_pool=[]
for criterius in criteria:
for script in scriptsJS:
gs=search.search(100,criterius,script,self.db_value)
gs.start()
thread_pool.append(gs)
for t in threading.enumerate():
if t is not main_thread:
t.join()
for t in thread_pool:
t.record()
print "########### Search terminated ###########"
print "########### Resolve IP ############"
networks.resolve(geoloc,self.db_value)
def search_ip(self,geoloc,scriptsJS):
main_thread = threading.currentThread()
print "########### Search by IP ###########"
ips=[]
domaines=self.db.new_domaines.find()
thread_pool=[]
for domaine in domaines:
try:
ips.append(domaine['ip'])
except KeyError:
print domaine
i=0
print 'les IPS sont: '+ str(ips)
for ip in set(ips):
if ip != '0.0.0.0':
i+=1
gs=search.search(20,'ip:'+str(ip),scriptsJS[1],self.db_value)
gs.start()
thread_pool.append(gs)
if i % 10 ==0:
for t in threading.enumerate():
if t is not main_thread:
t.join()
for t in thread_pool:
t.record()
print "########### Search terminated ###########"
print "########### Search by network ###########"
print "########### Resolve IP ############"
networks.resolve(geoloc,self.db_value)
def screenshots(self,db_value,threadpool):
connection=Connection('localhost',27017)
db=connection[db_value]
domaines=db.new_domaines.distinct('domaine')
i=0
main_thread = threading.currentThread()
print "print "+ str(len(domaines))+ " screenshots"
for domaine in domaines:
i+=1
screen=Screenshots(domaines, 'screenshots/screenshots.js', 'screenshots/screenshots/'+db_value, domaine)
screen.start()
if i % int(threadpool)==0:
for t in threading.enumerate():
if t is not main_thread:
t.join()
def metadata_exctract(self,db):
main_thread = threading.currentThread()
print "########## Meta Data IP ##########"
mdb=mongodb.mongodb('localhost',27017,db)
i=0
for domaine in mdb.selectall('new_domaines'):
i+=1
url=domaine['url']
domaine_value=domaine['domaine']
print url
if not 'meta' in domaine:
domaine['meta']='ok'
mtd=metadataextract.metadataextract('harvesting/metaextract.js',db,domaine_value,url)
mtd.start()
if i % 30==0:
for t in threading.enumerate():
if t is not main_thread:
t.join(2)
def dnstree(self,db_value):
dnst=DNSTree(db_value)
dnst.process()
def crawl(self):
main_thread = threading.currentThread()
domaines=self.db.new_domaines.distinct('domaine')
threadpool=[]
rec=Record(self.db_value)
rec.start()
i=0
for domaine in domaines:
i=i+1
cw=CrawlerThread(domaine,self.db_client)
cw.start()
if i % 30==0:
for t in threading.enumerate():
if t is not main_thread:
t.join(2)
stop=True
while(stop):
for t in threadpool:
if not t.IsActive():
threadpool.remove(t)
if len(threadpool)==0:
stop=False
def clean_db(self,pathfilters):
directory = "screenshots/screenshots/"+self.db_value
filters=[]
with open(pathfilters,'r') as fw:
for ligne in fw:
filters.append(ligne.strip())
cl=Cleandb(self.db_value, directory, filters)
cl.clean()
def reset(self):
for domaine in self.db.new_domaines.find():
domaine['meta']=None
self.db.update(domaine,'new_domaines')
def init(self,db,coll,attrib):
self.db.create_collection(coll)
self.db[coll].ensure_index([(attrib,pymongo.ASCENDING)],unique=True)