国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > PHP > 正文

php中fsockopen模仿post與get詳解

2024-05-04 21:48:31
字體:
來源:轉載
供稿:網友

在php中fsockopen函數可以模仿用戶去訪問一些網站并且還可以帶一些常用的信息,如果瀏覽器,IP,post,get 等等數據,下面我分別一來給大家介紹介紹.

如果你要使用fsockopen函數我們必須在php.ini中把allow_url_fopen = On 設置為開啟狀態.

例,fsockopen() Example,代碼如下:

  1. <?php 
  2. $fp = fsockopen("m.survivalescaperooms.com", 80, $errno$errstr, 30); 
  3. if (!$fp) { 
  4.     echo "$errstr ($errno)<br />n"
  5. else { 
  6.     $out = "GET / HTTP/1.1rn"
  7.     $out .= "Host: www.example.comrn"
  8.     $out .= "Connection: Closernrn"
  9.     fwrite($fp$out); 
  10.     while (!feof($fp)) { 
  11.         echo fgets($fp, 128); 
  12.     } 
  13.     fclose($fp); 
  14. ?> 

偽造post,POST HTTP請求(URL)并獲取返回值,代碼如下:

  1. <?php  
  2.  
  3.   $srv_ip = '192.168.1.5';//你的目標服務地址.  
  4.  
  5.   $srv_port = 80;//端口  
  6.  
  7.   $url = 'http://localhost/fsock.php'; //接收你post的URL具體地址   
  8.  
  9.   $fp = '';  
  10.  
  11.   $errno = 0;//錯誤處理  
  12.  
  13.   $errstr = '';//錯誤處理  
  14.  
  15.   $timeout = 10;//多久沒有連上就中斷  
  16.  
  17.   $post_str = "username=demo&password=hahaha";//要提交的內容.  
  18.  
  19.   //打開網絡的 Socket 鏈接。  
  20.  
  21.   $fp = fsockopen($srv_ip,$srv_port,$errno,$errstr,$timeout);  
  22.  
  23.   if (!$fp){  
  24.  
  25.    echo('fp fail');  
  26.  
  27.   }  
  28.  
  29.   $content_length = strlen($post_str);  
  30.  
  31.   $post_header = "POST $url HTTP/1.1rn";  
  32.  
  33.   $post_header .= "Content-Type: application/x-www-form-urlencodedrn";  
  34.  
  35.   $post_header .= "User-Agent: MSIErn";  
  36.  
  37.   $post_header .= "Host: ".$srv_ip."rn";  
  38.  
  39.   $post_header .= "Content-Length: ".$content_length."rn";  
  40.  
  41.   $post_header .= "Connection: closernrn";  
  42.  
  43.   $post_header .= $post_str."rnrn";  
  44.  
  45.   fwrite($fp,$post_header); 
  46.  
  47.   $inheader = 1;  
  48.  
  49.   while(!feof($fp)){//測試文件指針是否到了文件結束的位置  
  50.  
  51.    $line = fgets($fp,1024);  
  52.  
  53.    //去掉請求包的頭信息  
  54.  
  55.    if ($inheader && ($line == "n" || $line == "rn")) {  
  56.  
  57.          $inheader = 0;  
  58.  
  59.     }  
  60.  
  61.     if ($inheader == 0) {  
  62.  
  63.       echo $line;  
  64.  
  65.     }  
  66.  
  67.   }  
  68.  
  69.   fclose($fp);  
  70.  
  71.   unset ($line);  
  72.  
  73. ?>  

簡要說明:代碼第二行是你的IP地址或域名,第四行是你要POST的頁面的具體地址,本例用的是fsock.php,fsock.php內容如下:

  1. <?php  
  2.  
  3.     echo "username:".$_POST['username']."<br/>";  
  4.  
  5.     echo "password:".$_POST['password'];  
  6.  
  7. ?> 
  8.  
  9. //結果為: 
  10.  
  11. username:demo 
  12.  
  13. password:hahaha 

偽造get,同時偽造post,get方法,代碼如下:

  1. <?php 
  2. //fsocket模擬post提交 
  3. $purl = "http://localhost/netphp/test2.php?uu=rrrrrrrrrrrr"
  4. print_r(parse_url($url)); 
  5. sock_post($purl,"uu=55555555555555555"); 
  6. //fsocket模擬get提交 
  7. function sock_get($url$query
  8.    $info = parse_url($url); 
  9.    $fp = fsockopen($info["host"], 80, $errno$errstr, 3); 
  10.    $head = "GET ".$info['path']."?".$info["query"]." HTTP/1.0rn"
  11.    $head .= "Host: ".$info['host']."rn"
  12.    $head .= "rn"
  13.    $write = fputs($fp$head); 
  14.    while (!feof($fp)) 
  15.    { 
  16.     $line = fread($fp,4096); 
  17.     echo $line
  18.    } 
  19. sock_post($purl,"uu=rrrrrrrrrrrrrrrr"); 
  20. function sock_post($url$query
  21.    $info = parse_url($url); 
  22.    $fp = fsockopen($info["host"], 80, $errno$errstr, 3); 
  23.    $head = "POST ".$info['path']."?".$info["query"]." HTTP/1.0rn"
  24.    $head .= "Host: ".$info['host']."rn"
  25.    $head .= "Referer: http://".$info['host'].$info['path']."rn"
  26.    $head .= "Content-type: application/x-www-form-urlencodedrn"
  27.    $head .= "Content-Length: ".strlen(trim($query))."rn"
  28.    $head .= "rn"
  29.    $head .= trim($query); 
  30.    $write = fputs($fp$head); 
  31.    while (!feof($fp)) 
  32.    { 
  33.     $line = fread($fp,4096); 
  34.     echo $line
  35.    } 
  36. ?> 

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 六盘水市| 安庆市| 定远县| 临沭县| 大余县| 廉江市| 海城市| 康马县| 深水埗区| 津市市| 沿河| 北宁市| 绥滨县| 黄冈市| 庆城县| 江城| 岫岩| 城固县| 田阳县| 修文县| 黄冈市| 额尔古纳市| 克拉玛依市| 达拉特旗| 浮山县| 自贡市| 长春市| 本溪| 锡林郭勒盟| 绍兴县| 海原县| 台州市| 巴东县| 龙江县| 明光市| 双鸭山市| 龙口市| 搜索| 那坡县| 巴马| 天等县|