背景
一般机器如果做扫描agent端,其实配置方面是有很多可优化的点,此处以centos7为例,另外一般不推荐agent装在docker中运行,进行大量扫描,坑较多。
配置
- 关闭selinux:
vi /etc/selinux/config
,第6行改成SELINUX=disabled
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of three two values:
# targeted - Targeted processes are protected,
# minimum - Modification of targeted policy. Only selected processes are protected.
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
改完后,必须重启机器才能生效,如下,则SELINUX已关闭
2. 增大文件打开数限制,一般centos默认为1024或65536,对于大并发扫描完全不够
(1)vi /etc/security/limits.conf
,文件末尾添加:
* soft nofile 204800
* hard nofile 204800
* soft nproc 204800
* hard nproc 204800
* 代表针对所有用户
noproc 是代表最大进程数
nofile 是代表最大文件打开数
(2)vi /etc/security/limits.d/20-nproc.conf
,文件末尾添加:
* soft nproc 204800
* hard nproc 204800
(3) 如果是ssh连接目标机,重新开个窗口,输入ulimit -n,即可看到成功修改
3. 关闭firewalld和iptables:
systemctl stop firewalld
systemctl stop iptables
4. 卸载nf_conntrack模块,如果开着这个模块,且nf_conntrack_max数值不高的话(cat /proc/sys/net/netfilter/nf_conntrack_max
查看),会导致扫描严重掉包,系统日志中会有大量记录:
(1)最佳解决方法:modprobe -r nf_conntrack
,直接卸载该模块,如果有其它依赖模块导致卸载失败,需要手动把其它模块一一卸载:
(2)临时方法:调大nf_conntrack_max限制值,vi /etc/sysctl.conf
,末尾增加:net.nf_conntrack_max = 100000
,sysctl -p
保存,不建议永久使用这种方法
5. 时间同步
分布式扫描中一般会有多个agent,需要保持时间同步,可通过ntp来实现
(1)设置时区:timedatectl set-timezone Asia/Shanghai
(2)安装ntp服务:yum install ntp
(3)开启ntp同步timedatectl set-ntp true