-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdetexploit_server.py
190 lines (167 loc) · 4.94 KB
/
detexploit_server.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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
#
# DetExploit Server
# Description: Server side program for detexploit/DetExploit
# Author: moppoi5168
#
from colorama import init as cinit
from flask import *
from flask import request as rq
from termcolor import cprint
from pyfiglet import figlet_format
from getpass import getpass
import codecs
import random
import string
import sys
sip = ''
sport = ''
passcode = ''
spass = ''
rid = {}
app = Flask(__name__)
def setup():
global sip
global sport
global passcode
global spass
print('\n Starting the DetExploit server configuration.\n')
print(' Server IP: IP Address used to serve DetExploit Server.')
print(' In most case, 0.0.0.0 should be used.')
sip = input(' >> ')
print(' Server port: Port number used to serve DetExploit Server.')
print(' You may need to check firewall settings of your server.')
sport = input(' >> ')
print(' Connection Passcode: This passcode is used to verify client connecting to the server.')
print(" Please write same value at DetExploit Client's config.ini.")
passcode = input(' >> ')
print(""" Management Password: This password is used for the authenciation
in management console of this server.""")
spass = input(' >> ')
return sip, sport, spass
def main():
global spass
ret = setup()
sip = ret[0]
sport = ret[1]
spass = ret[2]
app.run(host=sip, port=int(sport), debug=False)
#app.run(host=HOST, port=PORT)
@app.route('/', methods=['GET'])
def ipage():
return '''
<h2>DetExploit Server</h2>
<p>
Welcome to DetExploit Server!!
Server is alive right now.
If you are an administrator, please check README.md for usage of this server.
</p>
'''
### Pages for client ###
@app.route('/reg', methods=['POST'])
def register():
global passcode
code = rq.get_data().decode()
if code != passcode:
return 'Error :('
ldi = string.ascii_letters + string.digits
uid = ''.join(random.choice(ldi) for i in range(30))
rid[uid] = 'Wait'
return uid
@app.route('/call', methods=['POST'])
def call():
uid = rq.get_data().decode()
for muid in rid:
if uid == muid:
if rid[uid] == 'Scan':
return 'Scan'
elif rid[uid] == 'Wait':
return 'Wait'
elif rid[uid] == 'Disconnect':
return 'Disconnect'
return 'Error :('
@app.route('/report', methods=['POST'])
def report():
# ret = rq.get_data().decode('cp932', 'ignore').replace('\u7e32','').replace('\u7528', '').replace('\uff83', '')
# ret = rq.get_data().decode('cp932', 'ignore').encode('utf-8', 'ignore').decode('utf-8', 'ignore')
ret = rq.get_data().decode()
print(ret)
uid = ret.split('|||')[0]
rpdata = ret.split('|||')[1]
for muid in rid:
if uid == muid:
if rid[uid] == 'Scan':
rid[uid] = 'Wait'
with codecs.open(uid + '_scanresult.txt', 'w', 'utf-8') as wh:
wh.write(rpdata)
return 'Success'
return 'Error :('
### Pages for client ###
### Pages for server console ###
@app.route('/atest', methods=['POST'])
def auth_test():
nopass = rq.get_data().decode()
if nopass == spass:
return 'Success'
else:
return 'Error :('
@app.route('/ohist', methods=['POST'])
def ohist():
ret = rq.get_data().decode()
fn = ret.split('|||')[0]
nopass = ret.split('|||')[1]
if nopass != spass:
return'Error :('
with codecs.open(fn, 'r', 'utf-8') as histf:
return histf.read()
return 'Error :('
@app.route('/rhist', methods=['POST'])
def rhist():
nopass = rq.get_data().decode()
if nopass != spass:
return 'Error :('
import os
files = []
texts = ''
for x in os.listdir('./'):
if os.path.isfile('./' + x):
files.append(x)
for file in files:
if '.txt' in file:
texts = texts + file + '\n'
return texts
@app.route('/push', methods=['POST'])
def push():
ret = rq.get_data().decode()
uid = ret.split('|||')[0]
nopass = ret.split('|||')[1]
if nopass != spass:
return 'Error :('
for muid in rid:
if uid == muid:
rid[uid] = 'Scan'
return 'Success'
return 'Error :('
@app.route('/pushall', methods=['POST'])
def push_all():
nopass = rq.get_data().decode()
if nopass != spass:
return 'Error :('
for muid in rid:
rid[muid] = 'Scan'
return 'Success'
@app.route('/pcli', methods=['POST'])
def print_clients():
tmp = []
nopass = rq.get_data().decode()
if nopass != spass:
return 'Error :('
for muid in rid:
tmp.append(muid)
print('|||'.join(tmp))
return '|||'.join(tmp)
### Pages for server console ###
if __name__ == '__main__':
cinit(strip=not sys.stdout.isatty())
print('')
cprint(figlet_format(' DetExploit'), 'red', attrs=['bold'], end='')
main()