Skip to content

Commit cf8ae54

Browse files
committed
code optimization
1 parent 1a3075c commit cf8ae54

File tree

2 files changed

+41
-41
lines changed

2 files changed

+41
-41
lines changed

lib/cli/colors.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/python3
22

33
'''
4-
some frequently used colors
4+
some frequently-used colors
55
'''
66

77
PURPLE = '\033[95m'

lib/cli/main.py

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,10 @@
1010
import sys
1111
import time
1212

13-
import lib.cli.colors as colors
14-
import lib.cli.console as console
15-
import lib.tools.baidu as baidu
16-
import lib.tools.exploits as ExecExp
13+
import lib.tools.exploits as exploit_exec
14+
from lib.cli import colors, console
15+
from lib.tools import zoomeye, baidu
1716
from lib.cli.console import debug_except, input_check, check_kill_process
18-
from lib.tools import zoomeye
1917

2018

2119
class SessionParameters:
@@ -24,17 +22,22 @@ class SessionParameters:
2422
define some global parameters
2523
'''
2624

27-
INIT_DIR = os.getcwd()
28-
OUT_DIR = INIT_DIR + '/output'
29-
PROXY_CONF = INIT_DIR + \
30-
'/data/proxy.conf'
31-
USE_PROXY = True
32-
IP_LIST = INIT_DIR + \
33-
'/data/ip_list.txt'
34-
PROXY_BIN = INIT_DIR + \
35-
'/tools/ss-proxy'
36-
SS_CONFIG = INIT_DIR + \
37-
'/data/ss.json'
25+
def __init__(self):
26+
self.init_dir = os.getcwd()
27+
self.out_dir = self.init_dir + '/output'
28+
self.proxy_conf = self.init_dir + \
29+
'/data/proxy.conf'
30+
self.use_proxy = True
31+
self.ip_list = self.init_dir + \
32+
'/data/ip_list.txt'
33+
self.proxy_bin = self.init_dir + \
34+
'/tools/ss-proxy'
35+
self.ss_config = self.init_dir + \
36+
'/data/ss.json'
37+
38+
39+
# Needed for scanner session later
40+
SESSION = SessionParameters()
3841

3942

4043
def list_exp():
@@ -78,40 +81,40 @@ def execute(cmd):
7881
\n[*] Target: {}\
7982
\n[*] Proxy config: {}'.format(
8083
os.getcwd(),
81-
SessionParameters.INIT_DIR,
82-
SessionParameters.IP_LIST,
83-
SessionParameters.PROXY_CONF) +
84+
SESSION.init_dir,
85+
SESSION.ip_list,
86+
SESSION.proxy_conf) +
8487
colors.END)
8588
elif cmd.startswith('target'):
8689
target = ''.join(cmd.split()[1:])
87-
if not target in os.listdir(SessionParameters.INIT_DIR + '/data'):
90+
if not target in os.listdir(SESSION.init_dir + '/data'):
8891
return
8992
print(colors.BLUE + '[i] Target changed to {}'.format(target))
90-
SessionParameters.IP_LIST = SessionParameters.INIT_DIR + \
93+
SESSION.ip_list = SESSION.init_dir + \
9194
'/data/' + target
9295
elif cmd == 'init' or cmd == 'i':
9396
print(colors.CYAN +
9497
'[*] Going back to init_dir...' + colors.END)
95-
os.chdir(SessionParameters.INIT_DIR)
98+
os.chdir(SESSION.init_dir)
9699
elif cmd.startswith('baidu'):
97100
try:
98101
command = cmd.strip().split()
99102
dork = command[1]
100103
count = int(command[2])
101-
os.chdir(SessionParameters.OUT_DIR)
104+
os.chdir(SESSION.out_dir)
102105
print(colors.PURPLE + '[*] Searching on Baidu...' + colors.END)
103106
baidu.spider(dork, count)
104107
except (IndexError, EOFError, KeyboardInterrupt, SystemExit):
105108
return
106109
elif cmd == 'proxy':
107-
if not os.path.exists(SessionParameters.SS_CONFIG):
110+
if not os.path.exists(SESSION.ss_config):
108111
console.print_error(
109-
'[-] Please make sure {} exists'.format(SessionParameters.SS_CONFIG))
112+
'[-] Please make sure {} exists'.format(SESSION.ss_config))
110113
try:
111114
subprocess.Popen(
112-
[SessionParameters.PROXY_BIN,
115+
[SESSION.proxy_bin,
113116
'-c',
114-
SessionParameters.SS_CONFIG],
117+
SESSION.ss_config],
115118
stderr=subprocess.PIPE, stdout=subprocess.PIPE, shell=False)
116119
except BaseException as err:
117120
console.print_error(
@@ -171,11 +174,8 @@ def attack():
171174
'''
172175
handles attack command
173176
'''
174-
175-
if input_check('[?] Do you wish to use proxychains? [y/n] ', choices=['y', 'n']) == 'y':
176-
SessionParameters.USE_PROXY = True
177-
else:
178-
SessionParameters.USE_PROXY = False
177+
SESSION.use_proxy = input_check(
178+
'[?] Do you wish to use proxychains? [y/n] ', choices=['y', 'n']) == 'y'
179179
answ = input_check(
180180
'\n[?] Do you wish to use\
181181
\n\n [a] built-in exploits\
@@ -204,11 +204,11 @@ def attack():
204204
elif answ == '1':
205205
console.print_error('\n[-] Under development')
206206
elif answ == '0':
207-
scanner(ExecExp.weblogic())
207+
scanner(exploit_exec.weblogic())
208208
elif answ == '3':
209-
scanner(ExecExp.s2_045())
209+
scanner(exploit_exec.s2_045())
210210
elif answ == '4':
211-
scanner(ExecExp.witbe())
211+
scanner(exploit_exec.witbe())
212212
except BaseException:
213213
console.print_error("[-] We have an error executing exploit")
214214
debug_except()
@@ -296,19 +296,19 @@ def scanner(scanner_args):
296296
# looks ugly, but since it works well, im not planning a rewrite
297297
_, work_path, exec_path, custom_args, jobs = scanner_args[0], \
298298
scanner_args[1], scanner_args[2], scanner_args[3], scanner_args[4]
299-
if SessionParameters.USE_PROXY:
299+
if SESSION.use_proxy:
300300
e_args = [
301301
'proxychains4',
302302
'-q',
303303
'-f',
304-
SessionParameters.PROXY_CONF,
304+
SESSION.proxy_conf,
305305
'./' + exec_path]
306306
else:
307307
e_args = ['./' + exec_path]
308308
e_args += custom_args
309309
e_args += ['-t']
310310
try:
311-
target_list = open(SessionParameters.IP_LIST)
311+
target_list = open(SESSION.ip_list)
312312
except BaseException as exc:
313313
console.print_error('[-] Error occured: {}\n'.format(exc))
314314
debug_except()
@@ -359,7 +359,7 @@ def scanner(scanner_args):
359359
console.print_error('[-] Error when running scanner')
360360
debug_except()
361361
os.system('clear')
362-
os.chdir(SessionParameters.INIT_DIR)
362+
os.chdir(SESSION.init_dir)
363363
console.print_success('\n[+] All done!\n')
364364
print(console.INTRO)
365365

@@ -376,7 +376,7 @@ def main():
376376
colors.END)).strip()
377377
if answ.lower() == 'n':
378378
os.system("ls data")
379-
SessionParameters.IP_LIST = SessionParameters.INIT_DIR + '/data/' + \
379+
SESSION.ip_list = SESSION.init_dir + '/data/' + \
380380
input_check(
381381
'[=] Choose your target IP list, eg. ip_list.txt ',
382382
choices=os.listdir('data'))

0 commit comments

Comments
 (0)