|
|
发表于 2006-3-3 23:48:07
|
显示全部楼层
首先下载一个QQ IP数据库,然后把所有的IP地址导到一个TXT文本中。
如下59.75.0.0 59.75.0.255 陕西省西安市 延安大学西安学院
59.75.1.0 59.75.255.255 陕西省 教育网
59.76.0.0 59.76.31.255 甘肃省庆阳市 陇东学院
59.76.32.0 59.76.191.255 甘肃省 教育网
59.76.192.0 59.76.207.255 宁夏银川市 银川大学
59.76.208.0 59.76.255.255 甘肃省 教育网
59.77.0.0 59.77.3.255 厦门大学 漳州校区
59.77.4.0 59.77.6.255 厦门大学 海韵园
59.77.7.0 59.77.14.255 厦门大学 漳州校区
59.77.15.0 59.77.16.255 厦门大学 海韵校区
59.77.17.0 59.77.61.255 厦门大学 漳州校区
59.77.62.0 59.77.62.255 厦门大学 嘉庚学院南光9
59.77.63.0 59.77.63.255 厦门大学 漳州校区
然后,把所有的网通地址先弄出来,不过很多是重复的。 cat ipdata.txt | grep "网通" > cnciprangelist.txt
我们需要的是0.0.0.0/0的标准数据,不能无端推测,要以APNIC为标准
上APNIC看了以后,发现了一个不大不小的漏洞,做了一个 php shell#!/usr/bin/php -q
<?php
function binnmtowm($binin){
$binin=rtrim($binin, "0");
if (!ereg("0",$binin) ){
return str_pad(str_replace("1","0",$binin), 32, "1");
} else return "1010101010101010101010101010101010101010";
}
function bintocdr ($binin){
return strlen(rtrim($binin,"0"));
}
function bintodq ($binin) {
if ($binin=="N/A") return $binin;
$binin=explode(".", chunk_split($binin,8,"."));
for ($i=0; $i<4 ; $i++) {
$dq[$i]=bindec($binin[$i]);
}
return implode(".",$dq) ;
}
function bintoint ($binin){
return bindec($binin);
}
function binwmtonm($binin){
$binin=rtrim($binin, "1");
if (!ereg("1",$binin)){
return str_pad(str_replace("0","1",$binin), 32, "0");
} else return "1010101010101010101010101010101010101010";
}
function cdrtobin ($cdrin){
return str_pad(str_pad("", $cdrin, "1"), 32, "0");
}
function dotbin($binin,$cdr_nmask){
// splits 32 bit bin into dotted bin octets
if ($binin=="N/A") return $binin;
$oct=rtrim(chunk_split($binin,8,"."),".");
if ($cdr_nmask > 0){
$offset=sprintf("%u",$cdr_nmask/8) + $cdr_nmask ;
return substr($oct,0,$offset ) . substr($oct,$offset) ;
} else {
return $oct;
}
}
function dqtobin($dqin) {
$dq = explode(".",$dqin);
for ($i=0; $i<4 ; $i++) {
$bin[$i]=str_pad(decbin($dq[$i]), 8, "0", STR_PAD_LEFT);
}
return implode("",$bin);
}
function inttobin ($intin) {
return str_pad(decbin($intin), 32, "0", STR_PAD_LEFT);
}
$csvpath="/var/tmp/cnciprangelist.txt";
$handle = fopen ("$csvpath","r");
$lastnet = "192.168.0.0/24";
while ($data = fgetcsv ($handle,10000, " ")) {
$arr=$data[0];
$my_net_info=$lastnet;
$check_ipadd=$arr;
include 'sc.php';
if ($doit==true){
$command="wget http://www.apnic.net/apnic-bin/whois.pl?searchtext=".$data[0]." -O /var/tmp/index".$data[0].".html -U IE".$data[0]."";
$lastline=system ($command,$return_code);
if ($return_code == 0){
$result=exec("cat /var/tmp/index".$data[0].".html |grep \"</pre><pre><b><u>route</u></b>:\"", $$arr);
$array=$$arr;
if (is_array($array)){
$netstring=ereg_replace("</pre><pre><b><u>route</u></b>: ","",$array[0]);
if ($netstring==""){
$nonetarr=explode(".",$check_ipadd);
$netstring=$nonetarr[0].".".$nonetarr[1].".0.0/16";
}
//echo "route add -net ".$netstring." gw 222.137.217.251"."<br>";
@ exec ("echo \"route add -net ".$netstring." gw 222.137.217.251"."\" >> /var/tmp/routecnc.table",$s,$offset);
@ exec ("rm /var/tmp/index".$data[0].".html",$a,$off);
$lastip=$data[0];
}else{exec ("echo \"no cat route info\" >> /var/tmp/routecnc.table",$c_error,$d_error);}
}else{exec ("echo \"wget error\" >> /var/tmp/routecnc.table",$a_error,$b_error);}
}
$lastnet=$netstring;
}
?>
sc.php 文件如下:<?php
$bin_ip=dqtobin($check_ipadd);
$my_net_info=rtrim("$my_net_info");
if (ereg("/",$my_net_info)){ //if cidr type mask
$dq_host = strtok("$my_net_info", "/");
$cdr_nmask = strtok("/");
$bin_nmask=cdrtobin($cdr_nmask);
$bin_wmask=binnmtowm($bin_nmask);
}
$bin_host=dqtobin($dq_host);
$bin_bcast=(str_pad(substr($bin_host,0,$cdr_nmask),32,1));
$bin_net=(str_pad(substr($bin_host,0,$cdr_nmask),32,0));
$bin_first=(str_pad(substr($bin_net,0,31),32,1));
$bin_last=(str_pad(substr($bin_bcast,0,31),32,0));
$host_total=(bindec(str_pad("",(32-$cdr_nmask),1)) - 1);
if ($host_total <= 0){ //Takes care of 31 and 32 bit masks.
$bin_first="N/A" ; $bin_last="N/A" ; $host_total="N/A";
if ($bin_net === $bin_bcast) $bin_bcast="N/A";
}
if (($bin_ip >= $bin_first) and ($bin_ip <= $bin_last)){
$doit=false;
}else{
$doit=true;
}
?>
最后就得到一个相对其他比较完整的网通路由段。
同样的道理,获得其他运营商段也是非常简单的。 |
|