Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/264.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/security/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 这个片段中CURL的用法是什么?这是恶意的吗?_Php_Security - Fatal编程技术网

Php 这个片段中CURL的用法是什么?这是恶意的吗?

Php 这个片段中CURL的用法是什么?这是恶意的吗?,php,security,Php,Security,我在从网站下载的代码中找到了这个函数。有人能解释一下这个代码片段的CURL部分吗?谢谢:) function cache\u url($url,$skip\u cache=true,$proxy='') { //背景 $cachetime=604800;//一周 $where=“缓存”; 如果(!is_dir($where)){ mkdir($where); } $hash=md5($url); $file=“$where/$hash.cache”; //查一下该死的档案。 $mtime=0;

我在从网站下载的代码中找到了这个函数。有人能解释一下这个代码片段的CURL部分吗?谢谢:)

function cache\u url($url,$skip\u cache=true,$proxy='')
{
//背景
$cachetime=604800;//一周
$where=“缓存”;
如果(!is_dir($where)){
mkdir($where);
}
$hash=md5($url);
$file=“$where/$hash.cache”;
//查一下该死的档案。
$mtime=0;
如果(文件_存在($file)){
$mtime=filemtime($file);
}
$filetimemod=$mtime+$cachetime;
//如果续订日期小于现在,则返回true;否则返回false(无需更新)
如果($filetimemod

注意:example.com被替换为我在代码中找到的恶意网站URL。

CURL代码只是将
$URL
内容下载到本地文件;唯一的“恶意”方面似乎是作者不希望目标服务器轻易阻止下载。为此,尝试了两种方法,注释如下:

curl_setopt($ch,CURLOPT_USERAGENT),“Mozilla/5.0(兼容;Googlebot/2.1+http://www.google.com/bot.html)");

将用户代理设置为Googlebot,这可能是为了避免 服务器端的用户代理阻塞(例如,站点不太可能 想要阻止谷歌爬虫)或从分析中删除的方法 这将引起服务器管理员的注意

curl\u setopt($ch,CURLOPT\u HTTPHEADER,数组(“远程地址:$ip”,“HTTP\u转发:$ip”)

设置主机上的
X-Forwarded-For
Remote Addr
标题 请求一个随机IP地址。服务器可能会尝试使用这些 用于确定客户端原始源IP和此随机 地址可能最终被记录在访问日志中,从而掩盖了 请求的来源,并降低请求被拒绝的可能性 封锁


这两种方法都可能愚弄对日志文件的随意审查,但是很容易被任何称职的管理员发现。

声明推荐人不会引起恶意,但是如果你的目标跟踪推荐人并且他们认为你的请求是恶意的,那么我猜你可能会被阻止。根据评论
//检查血腥的文件。
我会想象作者试图通过添加您所说的“恶意”网站。在本例中,
$url
是什么?$url是页面url我不理解使用CURL和放置Google Bot的IP范围以及指定Google Bot用户代理的目的
function cache_url($url, $skip_cache = true,$proxy = '')
{
  // settings
  $cachetime = 604800; //one week
  $where     = "cache";
  if (!is_dir($where)) {
    mkdir($where);
  }

  $hash = md5($url);
  $file = "$where/$hash.cache";

  // check the bloody file.
  $mtime= 0;
  if (file_exists($file)) {
    $mtime = filemtime($file);
  }
  $filetimemod = $mtime + $cachetime;

  // if the renewal date is smaller than now, return true; else false (no need for update)
  if ($filetimemod < time() OR $skip_cache) {
    // $data = file_get_contents($url);
    $ip = "" . mt_rand(0, 255) . "." . mt_rand(0, 255) . "." . mt_rand(0, 255) . "." . mt_rand(0, 255);
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array("REMOTE_ADDR: $ip","HTTP_X_FORWARDED_FOR: $ip"));
    curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)");
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($ch, CURLOPT_REFERER, "https://example.com/");

    if (isset($proxy) && $proxy != '') {
      curl_setopt($ch, CURLOPT_PROXY, $proxy);
    }

    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_TIMEOUT, 10);

    $data = curl_exec($ch);
    curl_close($ch);

    // save the file if there's data
    if ($data AND !$skip_cache) {
      file_put_contents($file, $data);
    }
  }
  else {
    $data = file_get_contents($file);
  }

  return $data;
}