1 | 1 | | #!/usr/bin/python |
2 | | - | ####################################################### |
3 | | - | # Author: Nasir khan (r0ot h3x49) # |
4 | | - | ####################################################### |
5 | | - | |
6 | | - | import os,sys,time |
7 | | - | import socks |
| 2 | + | import os |
| 3 | + | import re |
| 4 | + | import sys |
| 5 | + | import time |
8 | 6 | | import socket |
9 | 7 | | import subprocess |
10 | | - | from tor_paths import check_path |
| 8 | + | |
| 9 | + | from . import socks |
| 10 | + | from .Color import * |
| 11 | + | from .tor_paths import check_path |
11 | 12 | | if os.name == "nt": |
12 | | - | import inet_pton |
| 13 | + | from . import inet_pton |
13 | 14 | | else: |
14 | 15 | | pass |
15 | 16 | | |
| 17 | + | def clean(value): |
| 18 | + | if sys.version_info[:2] >= (3, 0): |
| 19 | + | return value.decode('utf-8') |
| 20 | + | else: |
| 21 | + | return value |
| 22 | + | |
16 | 23 | | class Proxy: |
17 | 24 | | |
18 | 25 | | def __init__(self): |
| skipped 4 lines |
23 | 30 | | |
24 | 31 | | @property |
25 | 32 | | def ConfigureTor(self): |
26 | | - | if sys.platform == 'win32': |
27 | | - | |
28 | | - | search_torrc = os.getcwd()+'\\proxy\\tor_configs\\win\\*torrc' |
29 | | - | search_torexe = os.getcwd()+'\\proxy\\tor_configs\\win\\*tor.exe' |
30 | | - | search_geoip = os.getcwd()+'\\proxy\\tor_configs\\win\\*geoip' |
31 | | - | search_geoip6 = os.getcwd()+'\\proxy\\tor_configs\\win\\*geoip6' |
32 | | - | |
33 | | - | torexe = check_path(search_torexe) |
34 | | - | torrc = check_path(search_torrc) |
35 | | - | geoip = check_path(search_geoip) |
36 | | - | geoip6 = check_path(search_geoip6) |
37 | | - | write_dd = 'DataDirectory %s\n' % (geoip.replace('\geoip','')) |
38 | | - | write_geoip = 'GeoIPFile %s\n' % (geoip) |
39 | | - | write_geoip6 = 'GeoIPv6File %s\n' % (geoip6) |
40 | | - | |
41 | | - | fd = open(torrc) |
42 | | - | torrc_read = fd.readlines() |
43 | | - | fd.close() |
44 | | - | |
45 | | - | torrc_file = open(torrc, 'w') |
46 | | - | torrc_read[4] = write_geoip |
47 | | - | torrc_read[5] = write_geoip6 |
48 | | - | torrc_read[6] = write_dd |
49 | | - | torrc_file.writelines(torrc_read) |
50 | | - | torrc_file.close() |
51 | | - | |
52 | | - | cmd = subprocess.Popen([torexe, '-f', torrc], stdout=subprocess.PIPE) |
53 | | - | while True: |
54 | | - | try: |
55 | | - | line = cmd.stdout.readline() |
56 | | - | if line != '': |
57 | | - | print line.strip() |
58 | | - | except KeyboardInterrupt: |
59 | | - | print '[-] -- User interrupted closing the services..' |
60 | | - | time.sleep(3) |
61 | | - | break |
62 | | - | |
63 | | - | elif sys.platform == 'darwin': |
64 | | - | |
65 | | - | search_torexe = os.getcwd()+'/proxy/tor_configs/mac/*tor' |
66 | | - | search_torrc = os.getcwd()+'/proxy/tor_configs/mac/*torrc' |
67 | | - | search_geoip = os.getcwd()+'/proxy/tor_configs/mac/*geoip' |
68 | | - | search_geoip6 = os.getcwd()+'/proxy/tor_configs/mac/*geoip6' |
69 | | - | |
70 | | - | torexe = check_path(search_torexe) |
71 | | - | torrc = check_path(search_torrc) |
72 | | - | geoip = check_path(search_geoip) |
73 | | - | geoip6 = check_path(search_geoip6) |
74 | | - | |
75 | | - | write_dd = 'DataDirectory %s\n' % (geoip.replace('/geoip','')) |
76 | | - | write_geoip = 'GeoIPFile %s\n' % (geoip) |
77 | | - | write_geoip6 = 'GeoIPv6File %s\n' % (geoip6) |
78 | | - | |
79 | | - | fd = open(torrc) |
80 | | - | torrc_read = fd.readlines() |
81 | | - | fd.close() |
82 | | - | |
83 | | - | torrc_file = open(torrc, 'w') |
84 | | - | torrc_read[4] = write_geoip |
85 | | - | torrc_read[5] = write_geoip6 |
86 | | - | torrc_read[6] = write_dd |
87 | | - | torrc_file.writelines(torrc_read) |
88 | | - | torrc_file.close() |
89 | 33 | | |
90 | | - | cmd = subprocess.Popen([torexe, '-f', torrc], stdout=subprocess.PIPE) |
91 | | - | while True: |
92 | | - | try: |
93 | | - | line = cmd.stdout.readline() |
94 | | - | if line != '': |
95 | | - | print line.strip() |
96 | | - | except KeyboardInterrupt: |
97 | | - | print '[-] -- User interrupted closing the services..' |
98 | | - | time.sleep(3) |
99 | | - | break |
| 34 | + | search_torrc = os.getcwd()+'\\proxy\\tor_configs\\win\\*torrc' |
| 35 | + | search_torexe = os.getcwd()+'\\proxy\\tor_configs\\win\\*tor.exe' |
| 36 | + | search_geoip = os.getcwd()+'\\proxy\\tor_configs\\win\\*geoip' |
| 37 | + | search_geoip6 = os.getcwd()+'\\proxy\\tor_configs\\win\\*geoip6' |
100 | 38 | | |
101 | | - | else: |
| 39 | + | torexe = check_path(search_torexe) |
| 40 | + | torrc = check_path(search_torrc) |
| 41 | + | geoip = check_path(search_geoip) |
| 42 | + | geoip6 = check_path(search_geoip6) |
| 43 | + | write_dd = 'DataDirectory %s\n' % (geoip.replace('\geoip','')) |
| 44 | + | write_geoip = 'GeoIPFile %s\n' % (geoip) |
| 45 | + | write_geoip6 = 'GeoIPv6File %s\n' % (geoip6) |
102 | 46 | | |
103 | | - | search_torexe = os.getcwd()+'/proxy/tor_configs/linux/*tor' |
104 | | - | search_torrc = os.getcwd()+'/proxy/tor_configs/linux/*torrc' |
105 | | - | search_geoip = os.getcwd()+'/proxy/tor_configs/linux/*geoip' |
106 | | - | search_geoip6 = os.getcwd()+'/proxy/tor_configs/linux/*geoip6' |
| 47 | + | fd = open(torrc) |
| 48 | + | torrc_read = fd.readlines() |
| 49 | + | fd.close() |
107 | 50 | | |
108 | | - | torexe = check_path(search_torexe) |
109 | | - | torrc = check_path(search_torrc) |
110 | | - | geoip = check_path(search_geoip) |
111 | | - | geoip6 = check_path(search_geoip6) |
112 | | - | |
113 | | - | write_dd = 'DataDirectory %s\n' % (geoip.replace('/geoip','')) |
114 | | - | write_geoip = 'GeoIPFile %s\n' % (geoip) |
115 | | - | write_geoip6 = 'GeoIPv6File %s\n' % (geoip6) |
116 | | - | |
117 | | - | fd = open(torrc) |
118 | | - | torrc_read = fd.readlines() |
119 | | - | fd.close() |
120 | | - | |
121 | | - | torrc_file = open(torrc, 'w') |
122 | | - | torrc_read[4] = write_geoip |
123 | | - | torrc_read[5] = write_geoip6 |
124 | | - | torrc_read[6] = write_dd |
125 | | - | torrc_file.writelines(torrc_read) |
126 | | - | torrc_file.close() |
| 51 | + | torrc_file = open(torrc, 'w') |
| 52 | + | torrc_read[4] = write_geoip |
| 53 | + | torrc_read[5] = write_geoip6 |
| 54 | + | torrc_read[6] = write_dd |
| 55 | + | torrc_file.writelines(torrc_read) |
| 56 | + | torrc_file.close() |
127 | 57 | | |
128 | | - | cmd = subprocess.Popen([torexe, '-f', torrc], stdout=subprocess.PIPE) |
129 | | - | while True: |
130 | | - | try: |
131 | | - | line = cmd.stdout.readline() |
132 | | - | if line != '': |
133 | | - | print line.strip() |
134 | | - | except KeyboardInterrupt: |
135 | | - | print '[-] -- User interrupted closing the services..' |
136 | | - | time.sleep(3) |
137 | | - | break |
| 58 | + | cmd = subprocess.Popen([torexe, '-f', torrc], stdout=subprocess.PIPE) |
| 59 | + | req, umsg = 1, "User requested new identity.." |
| 60 | + | while True: |
| 61 | + | try: |
| 62 | + | line = cmd.stdout.readline() |
| 63 | + | if line != '': |
| 64 | + | line = clean(line) |
| 65 | + | if '0.3.2.10' in line: |
| 66 | + | t, v = (line.strip().split('running')[0].split('[notice]')[1]).split() |
| 67 | + | print ('{}{}[{}{}*{}{}] {:<4} : {}'.format(fg, sd, fm, sb, fg, sd, t, v)) |
| 68 | + | if 'Bootstrapped' in line: |
| 69 | + | per, msg = ((line.strip())[42:]).split(":") |
| 70 | + | print ('{}{}[{}{}*{}{}] {:<4} : {}'.format(fg, sd, fm, sb, fg, sd, per, msg)) |
| 71 | + | if 'Done' in msg: |
| 72 | + | print (fg + sb + '\n----------------------------------------------------------------------------\n') |
| 73 | + | if 'opened from 127.0.0.1' in line: |
| 74 | + | print ('{}{}[{}{}*{}{}] {req:02d} : {umsg!s}'.format(fg, sd, fm, sb, fg, sd, req=req, umsg=umsg)) |
| 75 | + | req += 1 |
| 76 | + | except KeyboardInterrupt: |
| 77 | + | print ('\n{}{}[{}{}-{}{}] -- User interrupted closing the services..'.format(fg, sd, fr, sb, fg, sd)) |
| 78 | + | time.sleep(1) |
| 79 | + | break |
138 | 80 | | |
139 | 81 | | |
140 | 82 | | |
| skipped 32 lines |