Linux主机安全检查

查看版本,某些版本可能会包含特定的漏洞。
/etc/debian_version.
/etc/redhat-release
/etc/fedora-release
lsb_release -a #ubuntu
查看内核版本:
uname -a
查看开机时间,开机时间意味着有多长时间没有升级内核了。
uptime #check last kernel upgrade
查看时区:
cat /etc/timezone
时间服务
ps aux|grep ntp
时间服务log
ntpq -p -n
查看安装的软件包,也许会找到有漏洞的版本:
dpkg -l

查找有setuid的可执行文件:
find / -perm -u+s 2>/dev/null
登录日志记录:
/etc/rsyslog.conf

查看网络接口:
ip addr
查看dns是否被更改:
cat /etc/resolv.conf
查看hosts文件:
cat /etc/hosts

todo:导出shell
检查敏感文件的权限:
/etc/shadow
/etc/shadow.backup
/etc/mysql/my.cnf
备份的文件

检查有root权限的应用:
find / -perm -4000 -ls

检查用户:
cat /etc/passwd
检查用户的uid和guid是否是0:0,如果是0:0意味着他们登录后是root
确认无需登录用户bash是/bin/false或/bin/nologin

检查shadowfile
cat /etc/shadow
密码hash以$和$1$开头的分别是DES和MD5 hash,应当修改。
题外话:
在检查shadow文件的时候有这么一行

1
root:$6$BPoThzPl$2FDtPs0iYJfIBWVG1Z1BxuzSD7ZYTN.wdjkqyo7R0NlqgRiY9s0qsyQT1PhN.qfLYwYZglpzK72e4sU5Khr1B.:15664:0:99999:7:::

这个对应的用户名和密码是root:toor

检查chown和chmod的权限,普通用户应该不能访问这两个命令。

检查sudo配置文件
egrep -v ‘^#|^$’ /etc/sudoers

查看打开的端口和对应的进程
# lsof -i TCP -n -P
# lsof -i UDP -n -P

关闭ssh的root远程访问权限
echo ‘PermitRootLogig off’ >> /etc/ssh/sshd_config
强制ssh使用新版本加密:
echo ‘protocol 2′ >> /etc/ssh/sshd_config

如果无需远程访问mysql的话,将mysql端口绑定到127.0.0.1上:
cat /etc/mysql/my.cnf
[mysqld]
bind-address = 127.0.0.1

mysql登录:

1
mysql -u root #会有主机没密码么

mysql查看版本:

1
select @@version;

mysql查看用户和密码:

1
select Host, User, Password from mysql.user;

mysql查看密码hash:

1
select password(‘admin’)

mysql查看写文件权限:

1
SELECT user,file_priv FROM mysql.user WHERE FILE_PRIV=’Y’;

 

检查apache运行的用户:
ps aux|grep apache
在apache的配置文件里也能找到

1
2
3
4
5
#cat /etc/apache2/envvars
export APACHE_RUN_USER=www-data
export APACHE_RUN_GROUP=www-data

确认网站目录下的文件权限:

1
2
3
4
5
#ls -lR /var/www/
/var/www/wordpress/:
total 125
-rwxrwxrwx 1 www-data www-data 395 Jul 11 07:02 index.php
-rwxrwxrwx 1 www-data www-data 19929 Jul 11 07:02 license.txt

这个例子中的文件权限应该被改为 -rwx-r–r–

关闭apache在http头中输出版本,这是Debian的设置位置

1
#echo “ServerTokens   Prod;\nServerSignature  Off” >> /etc/apache2/conf.d/security

关闭文件目录遍历
cat /etc/apache2/sitesenable/000-default

1
2
3
4
5
6
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
deny from all

Php设置
display_errors Off
reviewerror_reporting E_ALL
log_errors On;
safe_mode On;
禁用函数 eval, exec, passthru, shell_exec, system, proc_open,
popen。
allow_url_ Off.

CC BY-NC-SA 4.0 Linux主机安全检查 by 桔子小窝 is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

发表回复

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据