一聚教程网:一个值得你收藏的教程网站

最新下载

热门教程

内网探测脚本&简单代理访问 jsp/php 源码分享

时间:2015-10-30 编辑:简简单单 来源:一聚教程网

php内网探测脚本&简单代理访问



jsp.jpg
 


jsp2.jpg
 


jsp4.jpg
 


jsp5.jpg

..

1.直接访问默认扫描当前IP的C段,获取标题、web容器.

2.可以自定义传入需要扫描的段,传入参数ip即可

3.代理访问参数为url,可简单的访问内网的web,对了,我还加载了网站里的css,做到尽量看上去和直接访问的效果一样

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> 
<%@ page isThreadSafe="false"%> 
<%@page import="java.io.PrintWriter"%> 
<%@page import="java.io.OutputStreamWriter"%> 
<%@page import="java.util.regex.Matcher"%> 
<%@page import="java.io.IOException"%> 
<%@page import="java.net.InetAddress"%> 
<%@page import="java.util.regex.Pattern"%> 
<%@page import="java.net.HttpURLConnection"%> 
<%@page import="java.util.concurrent.LinkedBlockingQueue"%> 
<%!final static List list = new ArrayList(); 
  String referer = ""; 
  String cookie = ""; 
  String decode = "utf-8"; 
  int thread = 100; 
  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; 
    } 
  } 
  HttpURLConnection conn; 
  String getHtmlContext(HttpURLConnection conn, String decode) { 
    Map result = new HashMap(); 
    try { 
      String code = "utf-8"; 
      if (decode != null) { 
        code = decode; 
      } 
      StringBuffer html = new StringBuffer(); 
      java.io.InputStreamReader isr = new java.io.InputStreamReader( 
          conn.getInputStream(), 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(); 
      return html.toString(); 
    } catch (Exception e) { 
      System.out.println("getHtmlContext:"+e.getMessage()); 
      return "null"; 
    } 
  } 
  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 < list.size(); i++) { 
        title = title + list.get(i); 
      } 
      return title.replaceAll("<.*?>", ""); 
    } catch (Exception e) { 
      return null; 
    } 
  } 
  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 < 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; 
  } 
  String getMyIPLocal() throws IOException { 
    InetAddress ia = InetAddress.getLocalHost(); 
    return ia.getHostAddress(); 
  }%> 
<% 
  String u = request.getParameter("url"); 
  String ip = request.getParameter("ip"); 
  if (u != null) { 
    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 = getHtmlContext(getHTTPConn(u), decode); 
    List css = getCss(html, u, decode); 
    String csshtml = ""; 
    if (!html.equals("null")) { 
      for (int i = 0; i < css.size(); i++) { 
        csshtml += css.get(i); 
      } 
      out.print(html + csshtml); 
    } else { 
      response.setStatus(HttpServletResponse.SC_NOT_FOUND); 
      out.print("请求失败!"); 
    } 
    return; 
  } 
  else if (ip != null || u == null) { 
    String threadpp = (request.getParameter("thread")); 
    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 <= 256; i++) { 
          String url = http + useIP + i; 
          queue.offer(url); 
        } 
        final JspWriter pw = out; 
        ThreadGroup tg = new ThreadGroup("c"); 
        for (int i = 0; i < 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); 
                  String title = getTitle(html); 
                  String serverType = getServerType(conn); 
                  String status = !html 
                      .equals("null") ? "Success" 
                      : "Fail"; 
                  if (html != null 
                      && !status.equals("Fail")) { 
                    try { 
                      pw.println(addr + "  >>  "+ title + ">>"+ serverType+ " >>" + 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());      }    }  %>


参数:

ip [需要探测的ip段]

url [需要请求的地址]

其他参数:

thread [指定线程数]

decode [指定编码]

referer [伪造referer]

cookie [伪造cookie]

待完善:

1.一个C段,可能有多种编码格式,所以指定一个参数是有问题的。

2.端口可以修改传入一个数组,支持探测多个端口80,8080..

3.代理访问功能并不完善,例如加载js、加载图片、超链接替换成代理访问的链接、表单替换支持真实请求..


php内网探测脚本&简单代理访问

>  “.$title.”>>”.$serverType.” >>”.$status.”
”; } @ob_flush(); flush(); } ob_end_clean(); } function getHtmlContext($url){ $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HEADER, TRUE);    //表示需要response header curl_setopt($ch, CURLOPT_NOBODY, FALSE); //表示需要response body curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($ch, CURLOPT_TIMEOUT, 120); $result = curl_exec($ch); global $header; if($result){ $headerSize = curl_getinfo($ch, CURLINFO_HEADER_SIZE); $header = explode(“\r\n”,substr($result, 0, $headerSize)); $body = substr($result, $headerSize); } if (curl_getinfo($ch, CURLINFO_HTTP_CODE) == ‘200’) { return $body; } if (curl_getinfo($ch, CURLINFO_HTTP_CODE) == ‘302’) { $location = getHeader(“Location”); if(strpos(getHeader(“Location”),’http://’) == false){ $location = getHost($url).$location; } return getHtmlContext($location); } return NULL; } function getHeader($name){ global $header; foreach ($header as $loop) { if(strpos($loop,$name) !== false){ return trim(substr($loop,strlen($name)+2)); } } } function getTitle($html){ preg_match(“/(.*?)<\/title>/i”,$html, $matches); return $matches[1]; } function getHost($url){ preg_match(“/^(http:\/\/)?([^\/]+)/i”,$url, $matches); return $matches[0]; } function getCss($host,$html){ preg_match_all(“/<link[\s\S]*?href=[‘\”](.*?[.]css.*?)[\”‘][\s\S]*?>/i”,$html, $matches); //print_r($matches); foreach($matches[1] as $v){ $cssurl = $v; if(strpos($v,’http://’) == false){ $cssurl = $host.”/”.$v; } $csshtml = “<style>”.file_get_contents($cssurl).”</style>”; $html .= $csshtml; } return $html; } ?></pre><p><br/></p> </div> <div class="pages art-detail"> </div> <ul class="TurnPage"> <li class="TurnPage-left"> <p> <span>上一个:</span> <a href="https://www.111com.net/jsp/Jsp-Servlet/95949.htm" class="maxWidth">myeclipse git插件安装使用教程</a> </p> </li> <li class="TurnPage-right"> <p> <span>下一个:</span> <a href="https://www.111com.net/jsp/Java/96119.htm" class="maxWidth">Java分层 service/action/DAO 总结</a> </p> </li> </ul> <div class="articles"> <div class="tit02"> <h4>相关文章</h4> </div> <ul> <li> <a target="_blank" href="https://www.111com.net/jsp/226257.htm">SpringBoot测试配置属性与web启动环境解析</a> <span>10-24</span> </li> <li> <a target="_blank" href="https://www.111com.net/jsp/226244.htm">vue中将el-switch值true、false改为number类型的1和0解析</a> <span>10-24</span> </li> <li> <a target="_blank" href="https://www.111com.net/jsp/226236.htm">Vue中的路由配置项meta使用解读</a> <span>10-24</span> </li> <li> <a target="_blank" href="https://www.111com.net/jsp/226229.htm">SpringBoot自定义bean绑定解析</a> <span>10-24</span> </li> <li> <a target="_blank" href="https://www.111com.net/jsp/226214.htm">SpringBoot常用计量与bean属性校验和进制数据转换规则解析</a> <span>10-24</span> </li> <li> <a target="_blank" href="https://www.111com.net/jsp/226213.htm">工厂方法在Spring框架中的运用介绍</a> <span>10-24</span> </li> </ul> </div> </div> </div> </div> </div> <div class="hot-column"> <div class="cont"> <div class="tit"> <h4>热门栏目</h4> </div> <ul class="clearfix"> <li> <h6><a href="https://www.111com.net/phper/php.html" target="_blank">php教程</a></h6> <a href="https://www.111com.net/list-45/" target="_blank">php入门</a> <a href="https://www.111com.net/list-46/" target="_blank">php安全</a> <a href="https://www.111com.net/list-47/" target="_blank">php安装</a> <a href="https://www.111com.net/list-48/" target="_blank">php常用代码</a> <a href="https://www.111com.net/list-49/" target="_blank">php高级应用</a> </li> <li> <h6><a href="https://www.111com.net/net/net.html" target="_blank">asp.net教程</a></h6> <a href="https://www.111com.net/list-78/" target="_blank">基础入门</a> <a href="https://www.111com.net/list-79/" target="_blank">.Net开发</a> <a href="https://www.111com.net/list-80/" target="_blank">C语言</a> <a href="https://www.111com.net/list-81/" target="_blank">VB.Net语言</a> <a href="https://www.111com.net/list-82/" target="_blank">WebService</a> </li> <li> <h6><a href="https://www.111com.net/sj/index.html" target="_blank">手机开发</a></h6> <a href="https://www.111com.net/list-208/" target="_blank">安卓教程</a> <a href="https://www.111com.net/list-209/" target="_blank">ios7教程</a> <a href="https://www.111com.net/list-210/" target="_blank">Windows Phone</a> <a href="https://www.111com.net/list-211/" target="_blank">Windows Mobile</a> <a href="https://www.111com.net/list-212/" target="_blank">手机常见问题</a> </li> <li> <h6><a href="https://www.111com.net/cssdiv/css.html" target="_blank">css教程</a></h6> <a href="https://www.111com.net/list-99/" target="_blank">CSS入门</a> <a href="https://www.111com.net/list-100/" target="_blank">常用代码</a> <a href="https://www.111com.net/list-101/" target="_blank">经典案例</a> <a href="https://www.111com.net/list-102/" target="_blank">样式布局</a> <a href="https://www.111com.net/list-103/" target="_blank">高级应用</a> </li> <li> <h6><a href="https://www.111com.net/wy/yw.html" target="_blank">网页制作</a></h6> <a href="https://www.111com.net/list-136/" target="_blank">设计基础</a> <a href="https://www.111com.net/list-137/" target="_blank">Dreamweaver</a> <a href="https://www.111com.net/list-138/" target="_blank">Frontpage</a> <a href="https://www.111com.net/list-139/" target="_blank">js教程</a> <a href="https://www.111com.net/list-140/" target="_blank">XNL/XSLT</a> </li> <li> <h6><a href="https://www.111com.net/office/index.html" target="_blank">办公数码</a></h6> <a href="https://www.111com.net/list-236/" target="_blank">word</a> <a href="https://www.111com.net/list-237/" target="_blank">excel</a> <a href="https://www.111com.net/list-238/" target="_blank">powerpoint</a> <a href="https://www.111com.net/list-239/" target="_blank">金山WPS</a> <a href="https://www.111com.net/list-240/" target="_blank">电脑新手</a> </li> <li> <h6><a href="https://www.111com.net/jsp/jsp.html" target="_blank">jsp教程</a></h6> <a href="https://www.111com.net/list-68/" target="_blank">Application与Applet</a> <a href="https://www.111com.net/list-69/" target="_blank">J2EE/EJB/服务器</a> <a href="https://www.111com.net/list-70/" target="_blank">J2ME开发</a> <a href="https://www.111com.net/list-71/" target="_blank">Java基础</a> <a href="https://www.111com.net/list-72/" target="_blank">Java技巧及代码</a> </li> </ul> </div> </div> <div class="footer"> <div class="cont"> <p> <a href="https://www.111com.net/" target="_self">一聚教程网</a>| <a href="https://www.111com.net/us/us.html" class="about" target="_self">关于我们</a>| <a href="https://www.111com.net/us/me.html" class="contact" target="_self">联系我们</a>| <a href="https://www.111com.net/us/ads.html" class="gg_contact" target="_self">广告合作</a>| <a href="https://www.111com.net/us/link.html" class="friend_link" target="_self">友情链接</a>| <a href="https://www.111com.net/us/bcinfo.html" class="copyright_notice" target="_self">版权声明</a> </p> <p> <span>copyRight@2007-2024 www.111COM.NET AII Right Reserved <a href="https://beian.miit.gov.cn/" target="_blank" class="beian">苏ICP备17065847号-2</a> </span> </p> <p> <span> 网站内容来自网络整理或网友投稿如有侵权行为请邮件:yijucomnet@163.com 我们24小时内处理 </span> </p> </div> </div> <script src="https://assets.111com.net/js/stat.js?v=2024022101"></script> <script src="https://api.111com.net/api/stat/hits?type=article&id=96052"></script> </body> </html>