1

我正在使用 grep 在攻击后分析我的日志文件。通常是这样

grep -F "POST /xxxxx.php" ./access-log

现在有人攻击了我的一些网站,但我不知道漏洞在哪里,也不知道攻击者的 IP 地址是什么。现在我想找到一个向我的多个网站发送请求的 IP 地址,如下所示:

abcde.com-log:123.123.123.123 - - [12/Jan/2013:08:41:08 +0100] "POST /xxxxx.php HTTP/1.1" 200 1234 "-" "-"

wxyz.com-log:123.123.123.123 - - [12/Jan/2013:08:41:08 +0100] "POST /xxxxx.php HTTP/1.1" 200 1234 "-" "-"

但我不知道如何让 grep 或其他 unix 工具只给我那个匹配项,匹配的对象不止一个日志文件。

4

1 回答 1

0

假设您想要的 IP 地址是每个日志文件中的第一个字段,请尝试以下操作:

awk '
   /POST \/xxxxx\.php/ {
      ip=$1
      if ( !(ipFilePairs[ip,FILENAME]++) ) {
         ipFileCnt[ip]++
         ipFileList[ip] = ipFileList[ip] " " FILENAME
      }
   }
   END {
      for (ip in ipFileCnt)
         if (ipFileCnt[ip] > 1)
            print ip ":" ipFileList[ip]
   }
' *.log
于 2013-01-18T01:30:50.657 回答