-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathconsole.py
315 lines (251 loc) · 8.63 KB
/
console.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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
#! /usr/bin/env python
#! -*-coding:utf-8 -*-
import subprocess
import sys
import sqlite3
import re
from cmd import Cmd
from lib.aspxshell import *
from lib.aspshell import *
from lib.phpshell import *
from lib.tools import *
class MainConsole(Cmd):
prompt = "pyshell> "
Object = None
def __init__(self):
Cmd.__init__(self)
#在cmdloop之前执行,打印装逼信息
def preloop(self):
string = '''
_ _ _
| | | | | V1.0
_ __ _ _ ___| |__ ___| | |
| '_ \| | | / __| '_ \ / _ \ | |
| |_) | |_| \__ \ | | | __/ | |
| .__/ \__, |___/_| |_|\___|_|_|
| | __/ |
|_| |___/
If You Want Fuck Me,Please Do It Now!
'''
print string
#打印帮助信息
def do_help(self, argv):
print 'help'
#增
def do_add(self, argv):
list = {}
array = argv.split(' ')
if len(array) < 3:
print ("length Not standard")
return 0
if array[0].startswith("http://") or array[0].startswith("https://"):
list['shell'] = array[0]
else:
self.Error("url address is not vaild!")
return 0
if len(array[1]) < 40:
list['pass'] = array[1]
else :
self.Error("pass is too long!")
return 0
if array[2] in ['asp', 'aspx', 'php'] :
list['type'] = array[2]
else :
self.Error("Script type error!")
return 0
list['code'] = "utf-8" if len(array) < 4 else array[3]
sql = '''insert into shell values (NULL, "{0}", "{1}", "{2}", "{3}", {4})'''.format(list['shell'], list['pass'], list['type'], list['code'], Tools.GetUnixDate())
db = DBSEStorage()
if db.execute(sql):
print "add ok"
else:
print "fuck %s " % result
del db
#self.Error("url address is not vaild")
#查
def do_show(self, argv):
db = DBSEStorage()
result = db.execute("select * from shell").fetchall()
format = "id\tshell\tpass\ttype\tencode\tdate\n"
print format
for line in result:
print "{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t".format(line[0],line[1],line[2],line[3],line[4], Tools.timestamp_datetime(line[5]))
del db
#改
def do_modify(self, argv):
array = argv.split(' ')
result = None
sql= "update shell set "
for line in array:
# print line
key = line[:line.find('=')]
value = line[line.find('=')+1:]
if key == 'id':
id = value
continue
elif key=='date':
print "Can't modify date field"
return False
sql += "%s=%s," % (key, value)
sql = "{0} where id={1}".format(sql[:-1],id)
db = DBSEStorage()
result = db.execute(sql)
if result:
print "Modify ok"
del db
#删
def do_remove(self, argv):
condition = argv.split(' ')[0]
sql = "delete from shell where "
if condition.find('id=')>=0 :
ids= condition[condition.find('=')+1:]
sql += "id in (%s)" % ids
elif condition.find('shell=')>=0:
shell = condition[condition.find('=')+1:]
sql += "shell like %s" % shell
elif re.match(r"\d+,", condition) !=None:
sql += "id in (%s) " % condition
elif re.match(r"%(.*?)%", condition) != None:
sql += '''shell like "%s" ''' % condition
else:
print "sorry , We don't Konw what you want delete"
return 0
db = DBSEStorage()
result = db.execute(sql)
if result:
print "del ok"
else:
print "del error"
del db
def do_search(self, argv):
condition = argv.split(' ')
sql = "select * from shell where "
if condition.find('shell=')>=0:
shell = condition[condition.find('=')+1:]
sql += '''shell like "%s"''' % shell
if condition.find('pass=')>=0:
ps = condition[condition.find('=')+1:]
sql += '''pass like "%s"''' % shell
if condition.find('date')>=0:
sql += '''date like "%s" ''' % condition
else:
print "sorry , We Don't suppost you syntax"
return 0
#执行系统命令
def do_shell(self, argv):
code = subprocess.call(argv,shell=True)
#指定shell,进入高级模式
def do_get(self, argv):
id = argv.split(' ')[0]
if re.match(r"\d+", id) ==None:
print "sorry, it is just support id"
return 0
sql = "select * from shell where id=%s " % id
db = DBSEStorage()
result = db.execute(sql).fetchone()
if result == None:
printf("No this Id")
return None
if result[3] == "php":
self.object = phpshell(result[1], result[2])
elif result[3] == 'asp':
self.object = aspshell(result[1], result[2])
else:
self.object = aspxshell(result[1], result[2])
self.prompt = "pyshell|%s > " % result[3]
del db
# 高级
# 显示文件
def do_ls(self, argv):
if argv.split(' ')[0] != '':
self.object.GetFilePath(argv.split(' ')[0])
self.object.GetFilePath()
#删除文件
def do_del(self, argv):
filelist = argv.split(' ')[0]
if "," in filelist:
files = filelist.split(',')
for line in files:
self.object.DeleteFile(line)
return 0
else:
files = filelist
self.object.DeleteFile(files)
return 0
# self.object.DeleteFile( )
def do_upload(self, argv):
list = argv.split(' ')
if "," in list[0]:
files = filelist.split(',')
for line in files:
if len(list) == 2:
self.object.UploadFile(line, list[1]) #上传到远程文件夹
self.object.UploadFile(line, None) # 上传到网站根目录
return 0
else:
files = list[0]
if len(list) == 2:
self.object.UploadFile(files, list[1]) #上传到远程文件夹
self.object.UploadFile(files, None) # 上传到网站根目录
return 0
def do_rename(self, argv):
oldname = argv.split(' ')[0]
newname = argv.split(' ')[1]
self.object.RenameFile(oldname, newname)
def do_read(self, argv):
file = argv.split(' ')[0]
self.object.ReadFile(file)
def do_down(self, argv):
file = argv.split(' ')[0]
self.object.DownloadFile(file)
def do_copy(self, argv):
source = argv.split(' ')[0]
desc = argv.split(' ')[1]
self.object.CopyFile(source, desc)
#更新数据库
def do_updatedb(self, argv):
pass
def do_q(self, argv):
print "Bye"
try:
del self.object
except:
pass
return True
def do_exit(self, argv):
print "Bye"
del self.object
return True
def Error(self, info):
print info
return 0
class DBSEStorage:
cursor = None
def __init__(self):
self.cursor = sqlite3.connect("pyshell.db")
self.cursor.execute('''
create table if not exists shell (
id INTEGER PRIMARY KEY,
shell varchar(100) not null,
pass varchar(50) not null,
type varchar(10) not null,
code varchar(20) default 'utf-8',
date int(11) not null
)
''')
self.cursor.commit()
def execute(self, sql):
try:
result = self.cursor.execute(sql)
self.cursor.commit()
return result
except :
print "error %s not exceute success" % sql
def __del__(self):
self.cursor.close()
def debug(info):
print info
sys.exit()
if __name__ == '__main__':
a = MainConsole()
a.cmdloop()