-
Notifications
You must be signed in to change notification settings - Fork 3
/
torScannerExec.py
174 lines (134 loc) · 3.91 KB
/
torScannerExec.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
#!/usr/bin/pyton
# coding=<utf-8>
import pprint
import sys
import random
import Queue
import time
import socket
from math import floor,ceil
from TorCtl import TorCtl
import findexit
import datetime
import sys
import ConfigParser
import decoClass
import pickle
import os
from shutil import move
import glob
import db2
from torHelper import *
from logic import *
configFile = "/opt/config.ini"
configPar = ConfigParser.ConfigParser()
configDic={}
scanDate='' # Quella che mi dice la giornata di scan, non il timestamp vero e proprio
####################################
####################################
####################################
####################################
class Unbuffered:
def __init__(self, stream):
self.stream = stream
def write(self, data):
self.stream.write(data)
self.stream.flush()
def __getattr__(self, attr):
return getattr(self.stream, attr)
@timeMeasure
def getAndSetConfig():
""" Reading config from file"""
print "-> Reading conf from file",
configDic={}
global torPortSockList
global torPortCtlList
configPar.read(configFile)
options = configPar.options("Scanner")
for option in options:
try:
configDic[option] = configPar.get("Scanner", option)
if configDic[option] == -1:
DebugPrint("skip: %s" % option)
except Exception as e:
print e
print("exception on %s!" % option)
configDic[option] = None
options = configPar.options("Tor")
for option in options:
try:
configDic[option] = configPar.get("Tor", option)
if configDic[option] == -1:
DebugPrint("skip: %s" % option)
except Exception as e:
print e
print("exception on %s!" % option)
configDic[option] = None
options = configPar.options("DB")
for option in options:
try:
configDic[option] = configPar.get("DB", option)
if configDic[option] == -1:
DebugPrint("skip: %s" % option)
except Exception as e:
print e
print("exception on %s!" % option)
configDic[option] = None
configDic["torportsock"]=int(configDic["torportsock"])
configDic["torportctl"]=int(configDic["torportctl"])
return configDic
@timeMeasure
def chooseFile():
print "-> Seleziono un file con le info da scannare",
path = '/mnt/ramfs'
for infile in glob.glob( os.path.join(path, '*.todo') ):
return infile
#lol return
@timeMeasure
def moveFile(filez):
print "-> Moving file to /var/log/torscanner",
strName=time.strftime("%Y-%m-%d %H:%M:%S",time.gmtime())
move(filez, '/var/log/torscanner/'+strName)
return
@timeMeasure
def deleteIfLastRound():
print "-> Cancello il file di ip da scannare",
path = '/mnt/ramfs'
files = glob.glob( os.path.join(path, '*.todo') )
print "(ancora", len(files), "to delete)",
def getExitRoutesFromPickle():
f=open("/mnt/ramfs/my.exits", "rb")
exitList = pickle.load(f)
f.close()
return exitList
#######################################
#######################################
sys.stdout=Unbuffered(sys.stdout)
scanDate = datetime.datetime.fromtimestamp(time.time())
timestart =time.time()
print "-> Start at ", scanDate, " [K]"
# Questa cosa server per leggere la configurazione da file e metterla in
# un dictionary apposito.
configDic = getAndSetConfig() #k
# creiamo un'istanza al db per le porcate iniziali
conn = db2.dbConnectz(configDic["db_host"],configDic["db_user"],configDic["db_pass"],configDic["db_name"]) #ok
readMe=chooseFile()
print "-> Working with ", readMe
f=open(readMe, "rb")
iplist = pickle.load(f)
f.close()
exitRoutes=getExitRoutesFromPickle()
print "- Number of exit routes", len(exitRoutes)
print "- Number of ip to scan", len(iplist)
filename1="/mnt/ramfs/lookupdict"
f=open(filename1, 'rb')
dictionarylookup = pickle.load(f)
print "..:: Starting scan ::.."
run(iplist, scanDate, exitRoutes, configDic, dictionarylookup)
print "..:: Scan Finished ::.."
print "-> Moving files to log"
moveFile(readMe)
print "-> Deleting .todo file"
deleteIfLastRound()
print "Exiting: [K]"
sys.exit()