|
| 1 | +<?php |
| 2 | + |
| 3 | +set_time_limit(0);//设置程序执行时间 |
| 4 | +ob_implicit_flush(True); |
| 5 | +ob_end_flush(); |
| 6 | +$url = isset($_REQUEST['url'])?$_REQUEST['url']:null; |
| 7 | + |
| 8 | +/*端口扫描代码*/ |
| 9 | +function check_port($ip,$port,$timeout=0.1) { |
| 10 | + $conn = @fsockopen($ip, $port, $errno, $errstr, $timeout); |
| 11 | + if ($conn) { |
| 12 | + fclose($conn); |
| 13 | + return true; |
| 14 | + } |
| 15 | +} |
| 16 | + |
| 17 | + |
| 18 | +function scanip($ip,$timeout,$portarr){ |
| 19 | +foreach($portarr as $port){ |
| 20 | +if(check_port($ip,$port,$timeout=0.1)==True){ |
| 21 | +echo 'Port: '.$port.' is open<br/>'; |
| 22 | +@ob_flush(); |
| 23 | +@flush(); |
| 24 | + |
| 25 | +} |
| 26 | + |
| 27 | +} |
| 28 | +} |
| 29 | + |
| 30 | +echo '<html> |
| 31 | +<form action="" method="post"> |
| 32 | +<input type="text" name="startip" value="Start IP" /> |
| 33 | +<input type="text" name="endip" value="End IP" /> |
| 34 | +<input type="text" name="port" value="80,8080,8888,1433,3306" /> |
| 35 | +Timeout<input type="text" name="timeout" value="10" /><br/> |
| 36 | +<button type="submit" name="submit">Scan</button> |
| 37 | +</form> |
| 38 | +</html> |
| 39 | +'; |
| 40 | + |
| 41 | +if(isset($_POST['startip'])&&isset($_POST['endip'])&&isset($_POST['port'])&&isset($_POST['timeout'])){ |
| 42 | + |
| 43 | +$startip=$_POST['startip']; |
| 44 | +$endip=$_POST['endip']; |
| 45 | +$timeout=$_POST['timeout']; |
| 46 | +$port=$_POST['port']; |
| 47 | +$portarr=explode(',',$port); |
| 48 | +$siparr=explode('.',$startip); |
| 49 | +$eiparr=explode('.',$endip); |
| 50 | +$ciparr=$siparr; |
| 51 | +if(count($ciparr)!=4||$siparr[0]!=$eiparr[0]||$siparr[1]!=$eiparr[1]){ |
| 52 | +exit('IP error: Wrong IP address or Trying to scan class A address'); |
| 53 | +} |
| 54 | +if($startip==$endip){ |
| 55 | +echo 'Scanning IP '.$startip.'<br/>'; |
| 56 | +@ob_flush(); |
| 57 | +@flush(); |
| 58 | +scanip($startip,$timeout,$portarr); |
| 59 | +@ob_flush(); |
| 60 | +@flush(); |
| 61 | +exit(); |
| 62 | +} |
| 63 | + |
| 64 | +if($eiparr[3]!=255){ |
| 65 | +$eiparr[3]+=1; |
| 66 | +} |
| 67 | +while($ciparr!=$eiparr){ |
| 68 | +$ip=$ciparr[0].'.'.$ciparr[1].'.'.$ciparr[2].'.'.$ciparr[3]; |
| 69 | +echo '<br/>Scanning IP '.$ip.'<br/>'; |
| 70 | +@ob_flush(); |
| 71 | +@flush(); |
| 72 | +scanip($ip,$timeout,$portarr); |
| 73 | +$ciparr[3]+=1; |
| 74 | + |
| 75 | +if($ciparr[3]>255){ |
| 76 | +$ciparr[2]+=1; |
| 77 | +$ciparr[3]=0; |
| 78 | +} |
| 79 | +if($ciparr[2]>255){ |
| 80 | +$ciparr[1]+=1; |
| 81 | +$ciparr[2]=0; |
| 82 | +} |
| 83 | +} |
| 84 | +} |
| 85 | + |
| 86 | +/*内网代理代码*/ |
| 87 | + |
| 88 | +function getHtmlContext($url){ |
| 89 | + $ch = curl_init(); |
| 90 | + curl_setopt($ch, CURLOPT_URL, $url); |
| 91 | + curl_setopt($ch, CURLOPT_HEADER, TRUE); //表示需要response header |
| 92 | + curl_setopt($ch, CURLOPT_NOBODY, FALSE); //表示需要response body |
| 93 | + curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); |
| 94 | + curl_setopt($ch, CURLOPT_TIMEOUT, 120); |
| 95 | + $result = curl_exec($ch); |
| 96 | + global $header; |
| 97 | + if($result){ |
| 98 | + $headerSize = curl_getinfo($ch, CURLINFO_HEADER_SIZE); |
| 99 | + $header = explode("\r\n",substr($result, 0, $headerSize)); |
| 100 | + $body = substr($result, $headerSize); |
| 101 | + } |
| 102 | + if (curl_getinfo($ch, CURLINFO_HTTP_CODE) == '200') { |
| 103 | + return $body; |
| 104 | + } |
| 105 | + if (curl_getinfo($ch, CURLINFO_HTTP_CODE) == '302') { |
| 106 | + $location = getHeader("Location"); |
| 107 | + if(strpos(getHeader("Location"),'http://') == false){ |
| 108 | + $location = getHost($url).$location; |
| 109 | + } |
| 110 | + return getHtmlContext($location); |
| 111 | + } |
| 112 | + return NULL; |
| 113 | +} |
| 114 | + |
| 115 | +function getHost($url){ |
| 116 | + preg_match("/^(http:\/\/)?([^\/]+)/i",$url, $matches); |
| 117 | + return $matches[0]; |
| 118 | +} |
| 119 | +function getCss($host,$html){ |
| 120 | + preg_match_all("/<link[\s\S]*?href=['\"](.*?[.]css.*?)[\"'][\s\S]*?>/i",$html, $matches); |
| 121 | + foreach($matches[1] as $v){ |
| 122 | + $cssurl = $v; |
| 123 | + if(strpos($v,'http://') == false){ |
| 124 | + $cssurl = $host."/".$v; |
| 125 | + } |
| 126 | + $csshtml = "<style>".file_get_contents($cssurl)."</style>"; |
| 127 | + $html .= $csshtml; |
| 128 | + } |
| 129 | + return $html; |
| 130 | +} |
| 131 | + |
| 132 | +if($url != null){ |
| 133 | + |
| 134 | + $host = getHost($url); |
| 135 | + echo getCss($host,getHtmlContext($url)); |
| 136 | +} |
| 137 | +?> |
0 commit comments