Jsp内网简单探测脚本 – JSP Network Simple Detection Script

CracerCracer 2015-12-30 安全工具 1,738 0 5

1

之前是使用的参数模式,现在搞了一个简单的UI。

前言:
某些情况下,内网渗透时,代理出不来,工具传上去被杀,总之就是遇到各种问题。而最过纠结的时,我已经知道内网哪台机器有洞了..(经验多的大神飘过,如果能解决某些内网渗透时遇到的坑的问题,求分享解决方法..)

功能:
代理访问虽然是个简单的功能,但是我觉得够用了。完全可以用来直接扫描内网其他web服务器的目录,尝试内网其其他登陆入口的弱口令,或者直接代理打struts或者其他漏洞。

web扫描:
其实我觉得用web发现更加贴切,其实有了端口扫描为啥还要这个.(因为之前的代码不想动它了。)

端口扫描:
大家都懂。(此功能问题较多,我觉得如果能使用工具或者代理回来就尽量不使用此脚本进行扫描。)

使用方法:
看图就懂了- -懒得写了。
PS:如果没有特别大的问题,我是不想改这个脚本了...

链接: http://pan.baidu.com/s/1o6AbPSe 密码: f3c5

PS:代码写得匆忙有两个小问题。
1.<%@page import="org.apache.commons.io.FileUtils"%> 这行应该删掉,因为之前写代码有人告诉我用这个操作读写文件比较方便。

2.412行改为自己脚本的所在位置。

code:

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
&lt;%@page import="java.io.File"%&gt;
&lt;%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%&gt;
&lt;%@ page isThreadSafe="false"%&gt;
&lt;%@page import="java.net.*"%&gt;
&lt;%@page import="java.io.PrintWriter"%&gt;
&lt;%@page import="java.io.BufferedReader"%&gt;
&lt;%@page import="java.io.FileReader"%&gt;
&lt;%@page import="java.io.FileWriter"%&gt;
&lt;%@page import="java.io.OutputStreamWriter"%&gt;
&lt;%@page import="java.util.regex.Matcher"%&gt;
&lt;%@page import="java.io.IOException"%&gt;
&lt;%@page import="java.net.InetAddress"%&gt;
&lt;%@page import="java.util.regex.Pattern"%&gt;
&lt;%@page import="java.net.HttpURLConnection"%&gt;
&lt;%@page import="java.util.concurrent.LinkedBlockingQueue"%&gt;
&lt;%!final static List list = new ArrayList();
String referer = "";
String cookie = "";
String decode = "utf-8";
int thread = 100;
//final static List scanportlist = new ArrayList();
String cpath="";
//建立一个HTTP连接
HttpURLConnection getHTTPConn(String urlString) {
try {
java.net.URL url = new java.net.URL(urlString);
java.net.HttpURLConnection conn = (java.net.HttpURLConnection) url
.openConnection();
conn.setRequestMethod("GET");
conn.addRequestProperty("User-Agent",
"Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Maxthon;)");
conn.addRequestProperty("Accept-Encoding", "gzip");
conn.addRequestProperty("referer", referer);
conn.addRequestProperty("cookie", cookie);
//conn.setInstanceFollowRedirects(false);
conn.setConnectTimeout(3000);
conn.setReadTimeout(3000);
return conn;
} catch (Exception e) {
return null;
}
}
String PostData(String urlString, String postString) {
HttpURLConnection http = null;
String response = null;
try {
java.net.URL url = new java.net.URL(urlString);
http = (HttpURLConnection) url.openConnection();
http.setDoInput(true);
http.setDoOutput(true);
http.setUseCaches(false);
http.setConnectTimeout(50000);
http.setReadTimeout(50000);
http.setRequestMethod("POST");
http.setRequestProperty("Content-Type",
"application/x-www-form-urlencoded");
http.connect();
OutputStreamWriter osw = new OutputStreamWriter(
http.getOutputStream(), decode);
osw.write(postString);
osw.flush();
osw.close();
response = getHtmlByInputStream(http.getInputStream(), decode);
} catch (Exception e) {
response = getHtmlByInputStream(http.getErrorStream(), decode);
}
return response;
}
HttpURLConnection conn;
//从输入流中读取源码
String getHtmlByInputStream(java.io.InputStream is, String code) {
StringBuffer html = new StringBuffer();
try {
java.io.InputStreamReader isr = new java.io.InputStreamReader(is,
code);
java.io.BufferedReader br = new java.io.BufferedReader(isr);
String temp;
while ((temp = br.readLine()) != null) {
if (!temp.trim().equals("")) {
html.append(temp).append("\n");
}
}
br.close();
isr.close();
} catch (Exception e) {
System.out.print(e.getMessage());
}
return html.toString();
}
//获取HTML源码
String getHtmlContext(HttpURLConnection conn, String decode,boolean isError) {
Map&lt;String, Object&gt; result = new HashMap&lt;String, Object&gt;();
String code = "utf-8";
if (decode != null) {
code = decode;
}
try {
return getHtmlByInputStream(conn.getInputStream(), code);
} catch (Exception e) {
try {
if(isError){
return getHtmlByInputStream(conn.getErrorStream(), code);
}
} catch (Exception e1) {
System.out.println("getHtmlContext2:" + e.getMessage());
}
System.out.println("getHtmlContext:" + e.getMessage());
return "null";
}
}
//获取Server头
String getServerType(HttpURLConnection conn) {
try {
return conn.getHeaderField("Server");
} catch (Exception e) {
return "null";
}
}
//匹配标题
String getTitle(String htmlSource) {
try {
List list = new ArrayList();
String title = "";
Pattern pa = Pattern.compile(".*?");
Matcher ma = pa.matcher(htmlSource);
while (ma.find()) {
list.add(ma.group());
}
for (int i = 0; i &lt; list.size(); i++) {
title = title + list.get(i);
}
return title.replaceAll("&lt;.*?&gt;", "");
} catch (Exception e) {
return null;
}
}
//得到css
List getCss(String html, String url, String decode) {
List cssurl = new ArrayList();
List csscode = new ArrayList();
try {
String title = "";
Pattern pa = Pattern.compile(".*href=\"(.*)[.]css");
Matcher ma = pa.matcher(html.toLowerCase());
while (ma.find()) {
cssurl.add(ma.group(1) + ".css");
}
for (int i = 0; i &lt; cssurl.size(); i++) {
String cssuuu = url + "/" + cssurl.get(i);
String csshtml = "

";
csscode.add(csshtml);
}
} catch (Exception e) {
System.out.println("getCss:" + e.getMessage());
}
return csscode;
}
//域名解析成IP
String getMyIPLocal() throws IOException {
InetAddress ia = InetAddress.getLocalHost();
return ia.getHostAddress();
}
boolean getHostPort(String task){
Socket client = null;
boolean isOpen=false;
try{
String[] s=task.split(":");
client = new Socket(s[0], Integer.parseInt(s[1]));
isOpen=true;
System.out.println("getHostPort:"+task);
//scanportlist.add(task+" &gt;&gt;&gt; Open");
saveScanReslt2(task+" &gt;&gt;&gt; Open\r\n");
}catch(Exception e){
isOpen=false;
}
return isOpen;
}
void getPath(String path){
cpath=path;
}
/* void saveScanReslt(String s){
try{
FileUtils.writeStringToFile(new File(cpath+"/port.txt"), s,"UTF-8",true);
}catch(Exception e){
System.out.print(e.getLocalizedMessage());
}
} */
void saveScanReslt2(String content) {
FileWriter writer = null;
try {
writer = new FileWriter(cpath+"/port.txt", true);
writer.write(content);
} catch (IOException e) {
System.out.print(e.getLocalizedMessage());
} finally {
try {
if(writer != null){
writer.close();
}
} catch (IOException e) {
System.out.print(e.getLocalizedMessage());
}
}
}
String s="Result:
";
String readPortResult(String portfile){
File file = new File(portfile);
BufferedReader reader = null;
try {
System.out.println("");
reader = new BufferedReader(new FileReader(file));
String tempString = null;
while ((tempString = reader.readLine()) != null) {
s+=tempString+"
";
}
reader.close();
} catch (IOException e) {
return null;
} finally {
if (reader != null) {
try {
reader.close();
} catch (IOException e1) {
return null;
}
}
}
return s;
}
%&gt;

内网简单扫描脚本

<script>// <![CDATA[
function showDiv(obj) {
//var statu = document.getElementById("prequest").style.display;
if (obj == "proxy") {
document.getElementById("proxy").style.display = "block";
document.getElementById("web").style.display = "none";
document.getElementById("port").style.display = "none";
} else if (obj == "web") {
document.getElementById("proxy").style.display = "none";
document.getElementById("web").style.display = "block";
document.getElementById("port").style.display = "none";
} else if (obj == "port") {
document.getElementById("proxy").style.display = "none";
document.getElementById("web").style.display = "none";
document.getElementById("port").style.display = "block";
}
}
// ]]></script>

<a style="margin-left: 32px;">代理访问</a> <a style="margin-left: 32px;">Web扫描</a> <a style="margin-left: 32px;">端口扫描</a>
<div id="proxy" style="border: 1px solid #999; padding: 3px; margin-left: 30px; width: 95%; height: 32%; display: block;"><form style="margin-left: 50px;" action="" method="POST">Url:<input style="width: 380px;" name="url" type="text" value="http://127.0.0.1:8080" />

Method:<select name="method">
<option value="GET">GET</option>
<option value="POST">POST</option>
</select>Decode:<select name="decode">
<option value="utf-8">utf-8</option>
<option value="gbk">gbk</option>
</select>

<textarea cols="40" name="post" rows="4">username=admin&amp;password=admin</textarea>
<textarea cols="40" name="post" rows="4">SESSION:d89de9c2b4e2395ee786f1185df21f2c51438059222</textarea>

Referer:<input style="width: 380px;" name="referer" type="text" value="http://www.baidu.com" />

<input type="submit" value="Request" />

</form></div>
<div id="web" style="border: 1px solid #999; padding: 3px; margin-left: 30px; width: 95%; height: 32%; display: none;"><form style="margin-left: 50px;" action="" method="POST">IP:<input name="ip" type="text" value="127.0.0.1" />

Port:<input name="port" type="text" value="80,8080,8081,8088" />

<input type="submit" value="Scan" />

</form></div>
<div id="port" style="border: 1px solid #999; padding: 3px; margin-left: 30px; width: 95%; height: 32%; display: none;"><form style="margin-left: 50px;" action="" method="POST">IP:<input name="scanip" type="text" value="192.168.12.1" />-<input name="scanip2" type="text" value="192.168.12.10" />

Port:<input style="width: 300px;" name="scanport" type="text" value="21,80,135,443,1433,1521,3306,3389,8080,27017" />

Thread:<input style="width: 30px;" name="thread" type="text" value="100" />

<input type="submit" value="Scan" />

</form></div>
&lt;%
final JspWriter pwx = out;
String s = application.getRealPath("/") + "/port.txt";
String result = readPortResult(s);
if (result != null) {
try {
pwx.println(result);
} catch (Exception e) {
System.out.print(e.getMessage());
}
}else{
pwx.println("如果你进行了端口扫描操作,那么这里将会显示扫描结果!
");
}
String div1 = "
<div style="0border: 1px;">";
String div2 = "</div>
";
String u = request.getParameter("url");
String ip = request.getParameter("ip");
String scanip = request.getParameter("scanip");
if (u != null) {
String post = request.getParameter("post");
decode = request.getParameter("decode");
String ref = request.getParameter("referer");
String cook = request.getParameter("cookie");
if (ref != null) {
referer = ref;
}
if (cook != null) {
cookie = cook;
}
String html = null;
if (post != null) {
html = PostData(u, post);
} else {
html = getHtmlContext(getHTTPConn(u), decode, true);
}
String path = request.getContextPath()+"/netspy.jsp";
System.out.println("path:"+path);
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"?url=";
System.out.println("base:"+basePath);
String reaplce = "href=\""+basePath;
//html=html.replaceAll("href=['|\"]?http://(.*)['|\"]?", reaplce+"http://$1\"");
html = html.replaceAll("href=['|\"]?(?!http)(.*)['|\"]?",
reaplce + u + "$1");
List css = getCss(html, u, decode);
String csshtml = "";
if (!html.equals("null")) {
for (int i = 0; i &lt; css.size(); i++) {
csshtml += css.get(i);
}
out.print(div1 + html + csshtml + div2);
} else {
response.setStatus(HttpServletResponse.SC_NOT_FOUND);
out.print("请求失败!");
}
return;
}
else if (ip != null) {
String threadpp = (request.getParameter("thread"));
String[] port = request.getParameter("port").split(",");
if (threadpp != null) {
thread = Integer.parseInt(threadpp);
System.out.println(threadpp);
}
try {
try {
String http = "http://";
String localIP = getMyIPLocal();
if (ip != null) {
localIP = ip;
}
String useIP = localIP.substring(0,
localIP.lastIndexOf(".") + 1);
final Queue queue = new LinkedBlockingQueue();
for (int i = 1; i &lt;= 256; i++) {
for (int j = 0; j &lt; port.length; j++) {
String url = http + useIP + i + ":" + port[j];
queue.offer(url);
System.out.print(url);
}
}
final JspWriter pw = out;
ThreadGroup tg = new ThreadGroup("c");
for (int i = 0; i &lt; thread; i++) { new Thread(tg, new Runnable() { public void run() { while (true) { String addr = queue.poll(); if (addr != null) { System.out.println(addr); HttpURLConnection conn = getHTTPConn(addr); String html = getHtmlContext(conn, decode, false); String title = getTitle(html); String serverType = getServerType(conn); String status = !html .equals("null") ? "Success" : "Fail"; if (html != null &amp;&amp; !status.equals("Fail")) { try { pw.println(addr + " &gt;&gt; "
+ title + "&gt;&gt;"
+ serverType
+ " &gt;&gt;" + status
+ "
");
} catch (Exception e) {
e.printStackTrace();
}
}
} else {
return;
}
}
}
}).start();
}
while (tg.activeCount() != 0) {
}
} catch (Exception e) {
e.printStackTrace();
}
} catch (Exception e) {
out.println(e.toString());
}
} else if (scanip != null) {
getPath(application.getRealPath("/"));
int thread = Integer.parseInt(request.getParameter("thread"));
String[] port = request.getParameter("scanport").split(",");
String ip1 = scanip;
String ip2 = request.getParameter("scanip2");
int start = Integer.parseInt(ip1.substring(
ip1.lastIndexOf(".") + 1, ip1.length()));
int end = Integer.parseInt(ip2.substring(
ip2.lastIndexOf(".") + 1, ip2.length()));
String useIp = scanip.substring(0, scanip.lastIndexOf(".") + 1);
System.out.println("start:" + start);
System.out.println("end:" + end);
final Queue queue = new LinkedBlockingQueue();
for (int i = start; i &lt;= end; i++) {
for (int j = 0; j &lt; port.length; j++) {
String scantarget = useIp + i + ":" + port[j];
queue.offer(scantarget);
}
}
System.out.print("Count1:" + queue.size());
final JspWriter pw = out;
ThreadGroup tg = new ThreadGroup("c");
for (int i = 0; i &lt; thread; i++) { new Thread(tg, new Runnable() { public void run() { while (true) { String scantask = queue.poll(); if (scantask != null) { getHostPort(scantask); /* String result = null; if(isOpen){ result=scantask+ " &gt;&gt;&gt; Open
";
scanportlist.add(result);
System.out.println(result);
} */
/* try {
pw.println(result);
} catch (Exception e) {
System.out.print(e.getMessage());
} */
}
}
}
}).start();
}
/* while (tg.activeCount() != 0) {
} */
try {
pw.println("扫描线程已经开始,请查看" + cpath+"/port.txt文件或者直接刷新本页面!");
} catch (Exception e) {
System.out.print(e.getMessage());
}
}
%&gt;

转载请注明来自Cracer,本文标题:《Jsp内网简单探测脚本 – JSP Network Simple Detection Script》

喜欢 (5) 发布评论
发表评论


Top