一.常用安全工具:rootkit检测工具,aide文件监控,TCPdump抓包工具

1.rootkit

a.了解rootkit

针对多个系统,如win、sunos、linux

rootkit由几个独立程序组成:

1)网络嗅探程序,用于获取用户名密码,并且上传。

2)特洛伊***,inetd、login为***者提供后门。

3)隐藏***者目录、进程:ps、netstat、ls替换。

4)清理工具,zap、z2***者使用这些工具可删除wtmp、utmp、lastlog等用户记录有关的日志。

b.检测rootkit

防止rootkit:做好系统及时更新,权限管理准确,开启selinux及时检测rootkit

chkrootkit:检测linux系统是否被rootkit***

RKHunter:检测rootkit

1)安装和使用chkrootkit

yum --enablerepo=epel -y install chkrootkit (必须先配置好epel的源)

clip_image002

chkrootkit ##执行检测

clip_image004

chkrootkit |grep INFECTED ##如果显示有结果证明中招,没结果即没问题

clip_image006

2)RKHunter安装及使用

rpm -qa |grep rkhunter

rpm -e rkhunter

yum --enablerepo=epel -y install rkhunter (必须先配置好epel的yum源)

clip_image008

vi /etc/sysconfig/rkhunter

MAILTO=root@localhost ##检测通知邮箱,可以自定义

DIAG_SCAN=no ##快速扫描,如果yes,详细扫描。

:wq

clip_image010

rkhunter --update ##更新rkhunter数据库(病毒库)

clip_image012

rkhunter --propupd ##更新系统文件的优先级

clip_image014

rkhunter --check --sk ##检测rootkit病毒,DIAG_SCAN=no

clip_image016

rkhunter --check --rwo ##详细检测,DIAG_SCAN=yes

System checks summary

=====================

File properties checks...

Files checked: 133

Suspect files: 2

Rootkit checks...

Rootkits checked : 376

Possible rootkits: 0 ##0个rootkits

Applications checks...

All checks skipped

The system checks took: 1 minute and 22 seconds

All results have been written to the log file: /var/log/rkhunter/rkhunter.log

One or more warnings have been found while checking the system.

Please check the log file (/var/log/rkhunter/rkhunter.log)

clip_image018

2.AIDE文件、目录监测工具

aide:可以实现监测文件:权限变化,文件大小,重命名,移动等。

yum -y install aide

clip_image020

vi /etc/aide.conf

:87,$s/^/#/g ##注释掉默认监测规则

clip_image022

clip_image024

在87行后添加:

MYAT = p+u+g+acl ##定义监控事件,p权限、u用户、g组、acl文件的facl

/etc/linuxfan MYAT ##对目录的MYAT的事件进行监控

:wq

clip_image026

mkdir /etc/linuxfan

clip_image028

aide --init ##初始化数据库

clip_image030

mv /var/lib/aide/aide.db.new.gz /var/lib/aide/aide.db.gz ##对比模板数据库

clip_image032

aide --check ##监测目录是否有变化,无变化

clip_image034

chmod 777 /etc/linuxfan

clip_image036

aide --check ##监测目录的变化

clip_image038

aide --update ##更新变化,确认变化是合法

clip_image040

cp /var/lib/aide/aide.db.new.gz /var/lib/aide/aide.db.gz ##去掉new保证前面设置的权限合法化

clip_image042

echo '0 1 * * * /usr/sbin/aide --update |mail -s 'Daily check by aide' linuxfan360@163.com' >>/var/spool/cron/root

clip_image044

3.TCPdump抓包工具

截取网络部分流量数据,并且输出。常见的排错和网络分析工具。

案例:

tcpdump arp ##当怀疑arp***时使用

clip_image046

tcpdump icmp ##当怀疑ddos***时使用

clip_image048

tcpdump ip host 192.168.3.200 and port 22 and tcp ##只抓ssh包

clip_image050

tcpdump -vv ##显示抓包的详细信息

二:回顾常用工具,分析工具lsof,sar,ss,iperf3网络测速,双网卡bonding

1.常用工具:磁盘、内存、cpu

磁盘:

df -hT ##硬盘的使用情况

clip_image052

du -sh /* ##统计目录的每个文件及目录大小

clip_image054

mount ##查看已经挂载的内容

clip_image056

内存:

free

clip_image058

cat /proc/meminfo

clip_image060

cpu查看:

cat /proc/cpuinfo

clip_image062

echo "scale=4; 100/3" |bc ##用于计算相关显示信息,scale指定小数的位数

clip_image064

wc -l /etc/hosts ##统计文件的行数

clip_image066

[root@www ~]# sync ##将有效数据从内存中写入硬盘

[root@www ~]# echo 3 >/proc/sys/vm/drop_caches ##清楚内存中的数据

[root@www ~]# free

clip_image068

2.分析工具

1)lsof:列出系统打开的文件

clip_image070

案例:

lsof #列出所有的打开的文件

clip_image072

COMMAND PID(进程) USER(用户) TYPE NODE(节点) NAME

a.递归查找某个目录所有被打开的文件

lsof +D /opt/data

clip_image074

b.列出某个用户打开所有文件

lsof -u root

clip_image076

lsof -u ^root ##-u用户,^取反

clip_image078

c.查找某个进程所打开文件

lsof -c nginx

clip_image080

d.列出某个进程打开文件

lsof -p 1

clip_image082

lsof -p ^1

clip_image084

e.列出网络连接打开的文件

lsof -i ##列出所有包括ipv4、ipv6;lsof -i 4 (只列出ipv4)

clip_image086

lsof -a -u hacker -i ##找到hacker用户的所有网络连接

lsof -i udp:53 ##查看udp53端口网络连接

lsof -i tcp:53

clip_image088

f.输出某类资源的pid

lsof -t -i ##将所有的网络的进程输出

clip_image090

kill -9 $(lsof -t -i)

clip_image092

2.sar,资源监控

clip_image094

sar是有sysstat软件提供,需要单独安装。

sar支持监控内存、cpu、硬盘

案例:

[root@ns ~]# yum -y install sysstat

sar -r 2 3 ##监控内存,每隔2秒一次共3次

clip_image096

sar -u 2 3 ##监控cpu的使用情况

clip_image098

sar -b 2 3 ##监控硬盘使用情况

clip_image100

支持文件的操作:

sar -b -f /var/log/sa/sa18

clip_image102

LC_ALL=C sar -u 2 3 ##指定时间的显示方式为19:10:12的格式

clip_image104

3.ss查看网络连接情况

ss -a ##查看所有的网络连接

clip_image106

ss -o state established ##过滤出established状态的连接

clip_image108

4.iperf3:网络测速工具

c/s模式,通过给客户端传输数据测速网络情况

同时在c端和s端安装iperf3

yum -y install epel-release

yum -y install iperf3

s端:

iperf3 -s ##监听

c端:

iperf3 -c 192.168.10.113 ##测速

5.双网卡绑定:

eth0和eth1同时接到同一个网络中,

modprobe bonding ##加载bonding内核模块

lsmod |grep bond ##确认是否成功

clip_image110

cd /etc/sysconfig/network-scripts/

[root@localhost network-scripts]# cat ifcfg-eth0

DEVICE=eth0

TYPE=Ethernet

ONBOOT=yes

NM_CONTROLLED=no

BOOTPROTO=none

MASTER=bond0

IPV6INIT=no

SLAVE=yes

cd /etc/sysconfig/network-scripts/

[root@localhost network-scripts]# cat ifcfg-eth1

DEVICE=eth1

TYPE=Ethernet

ONBOOT=yes

NM_CONTROLLED=no

BOOTPROTO=none

MASTER=bond0

IPV6INIT=no

SLAVE=yes

[root@localhost network-scripts]# cat ifcfg-bond0

DEVICE=bond0

BOOTPROTO=none

ONBOOT=yes

IPV6INIT=no

IPADDR=192.168.10.21

NETMASK=255.255.255.0

GATEWAY=192.168.10.1

DNS1=192.168.3.5

BOND_OPTS="mode=1 primary=eth0 miimon" ##mode=1表示容错,0表示负载均衡,虚拟机只支持1,0-6真机支持。

/etc/init.d/network restart

cat <<END >>/etc/rc.local

modprobe bonding

/etc/init.d/network restart

6.iftop+ntop网络监控流量

注意安全前必须配置好rpmforge和epel源:

[root@ns bin]# yum -y install --enablerepo=rpmforge iftop ##安装iftop

clip_image112

[root@ns bin]# iftop ##使用iftop

clip_image114

[root@ns ~]# yum -y install --enablerepo=epel ntop ##安装ntop

clip_image116

[root@ns ~]# ntop -i eth0 -u ntop ##在内网卡上启动ntop

clip_image118

http://192.168.100.100:3000/ ##浏览器中访问查看,最好配置×××软件,ntop调用google地图

clip_image120