为什么用PHP';s$\u服务器变量?

为什么用PHP';s$\u服务器变量?,php,apache,ip,lamp,Php,Apache,Ip,Lamp,我用php记录我的网站访问者的IP地址以及一些其他信息($content),这样我就可以计算访问者的数量 我正在使用以下代码: <?php public static function logContent(array $content = null){ try { $myFile = fopen("visitors.txt", "a"); $txt = "IP: &quo

我用php记录我的网站访问者的IP地址以及一些其他信息($content),这样我就可以计算访问者的数量

我正在使用以下代码:

<?php
public static function logContent(array $content = null){
        try {

            $myFile = fopen("visitors.txt", "a");

            $txt = "IP: ";

            if (isset($_SERVER['HTTP_CLIENT_IP']))
                $ipAddress = $_SERVER['HTTP_CLIENT_IP'];
            else if (isset($_SERVER['HTTP_X_FORWARDED_FOR']))
                $ipAddress = $_SERVER['HTTP_X_FORWARDED_FOR'];
            else if (isset($_SERVER['HTTP_X_FORWARDED']))
                $ipAddress = $_SERVER['HTTP_X_FORWARDED'];
            else if (isset($_SERVER['HTTP_FORWARDED_FOR']))
                $ipAddress = $_SERVER['HTTP_FORWARDED_FOR'];
            else if (isset($_SERVER['HTTP_FORWARDED']))
                $ipAddress = $_SERVER['HTTP_FORWARDED'];
            else if (isset($_SERVER['REMOTE_ADDR']))
                $ipAddress = $_SERVER['REMOTE_ADDR'];
            else
                $ipAddress = 'UNKNOWN';

            $txt .= $ipAddress;
            $txt .= " Time: " . date("Y-m-d h:i:s", time());
            $txt .= "\n";

            if (!empty($content) && is_array($content)) {
                foreach ($content as $k => $v) {
                    $txt .= "$k : ";
                    $txt .= $v;
                    $txt .= "\n";
                }
                $txt .= "\n";
            }

            fwrite($myFile, $txt);
            fclose($myFile);
        } catch (\Exception $e) {

        }
    }
?>
但是,我最近在我的日志中得到了以下条目

知识产权: }__测试O:21:“JDatabaseDriverMysqli”:3:{s:2:“fc”;O:17:“JSImplePrefactory”:0:{s:21:\0\0\0disconnectHandlers”;a:1:{i:0;a:2:{i:0;O:9:“SimplePie”:5:{s:8:“清理”;O:20:“JDatabaseDriverMysql”:0:{s:8:“feed\uURL”;s:56:“die(md5(目录分隔符));JFactory::getConfig();退出;s:19:“断言缓存函数名”;断言U:11:“缓存类:缓存名”O:20:JDatabaseDriverMysql:0:{}i:1;s:4:init;}s:13:\0\0\0连接;b:1;}���� 时间:2020-06-1911:27:37

这是一种类似于针对Java的MySQL注入的恶意注入攻击吗


我是否需要留意任何可疑之处并修补Apache服务器以提高安全性?

据我所知,HTTP_X_FORWARDED_for Header是由客户端/代理发送的(),您不需要对$u服务器的内容进行任何控制['HTTP_X_FORWARDED_for']

是的,有人尝试过SQL注入,但在本例中,它并不敏感(只是输出到文本文件中)。 在输出到文件之前,必须先检查$ipAddress的内容(例如,使用正则表达式或)

编辑:您可以通过以下方式重现此行为:

  curl -H 'X-Forwarded-For: 1.1.1.1' https://www.example.com/mypage
  curl -H 'X-Forwarded-For: <SOME RANDOM INPUT>' https://www.example.com/mypage
curl-H'X-Forwarded-For:1.1.1'https://www.example.com/mypage
curl-H'X-For:'https://www.example.com/mypage

希望这有帮助

这闻起来像是可能的注射攻击。您可能需要参考以进行更仔细的查看。虽然这是关于joomla的设置,涉及2015年,但签名值得一看

我建议你检查一下日志,看看有没有可疑的活动

  curl -H 'X-Forwarded-For: 1.1.1.1' https://www.example.com/mypage
  curl -H 'X-Forwarded-For: <SOME RANDOM INPUT>' https://www.example.com/mypage