gpt4 book ai didi

Linux bash 迭代 apache access_log 文件并发送邮件

转载 作者:太空宇宙 更新时间:2023-11-04 05:48:38 26 4
gpt4 key购买 nike

我需要一个 Linux bash 脚本,如果 apache 日志中的搜索中出现任何结果,该脚本会向我发送电子邮件。

我有一个非常简单的方法(句子)来研究SQL注入(inject)攻击,它只需搜索SQLi中使用的一些关键字即可。这是:

#tail -50000 /var/vhosts/site.com/logs/access_log | egrep -i "select%20|union%20|'|1=1"

所以现在我希望能够在多个 access_log 中启动它(对于每个网站 - 我拥有的虚拟主机),并在找到结果时向我发送电子邮件。

示意性地表示:

我有 apache access_log 文件,每个虚拟主机一个:

/var/vhosts/website_1/access_log
/var/vhosts/website_2/access_log
etc...

以及我所说的 bash 进程的方案:

for each access_log file (one by virtual host)
result = tail -50000 /var/www/vhosts/site.com/logs/access_log | egrep -i "select%20|union%20|'|1=1"
if any line appear in the result then
send mail(myemail@site.com, 'Warning!: Possible attack in virtual_host_i')
end;

有人知道如何实现这个脚本吗?

提前致谢

最佳答案

您有一个很好的计划,只需编写代码即可。试试这个:

#!/bin/bash
for file in $(ls /var/vhosts/*/access_log); do
result="" #reset the result variable
result=$(tail -50000 "${file}" | egrep -i "(select )|(union )|'|(1=1)")
if [[ ! -z $result ]]; then
echo "file ${file} contains suspicious lines:"
echo $result
# or enter your command for mailing the result
# for example:
# echo ${result} | mail -s ${file} youremail@site.com
# check man page for your mail command!
fi
done

关于Linux bash 迭代 apache access_log 文件并发送邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49180232/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com