- 一、基本安全实施
- 二、系统引导和登录控制
- 三、弱口令检测,端口扫描
1、锁定用户及锁定文件
1)锁定账户
[root@test-t1 ~]# usermod -L list //锁定账户 -L, --lock [root@test-t1 ~]# passwd -S list //查看账户状态 -S, --status list LK 2021-10-08 0 99999 7 -1 (Password locked.) [root@test-t1 ~]# usermod -U list //解锁账户 -U, --unlock [root@test-t1 ~]# passwd -S list list PS 2021-10-08 0 99999 7 -1 (Password set, SHA512 crypt.)
扩展: passwd参数 也可以实现锁定、解锁账户
passwd -l list -l, --lock
passwd -u list -u, --unlock
2)锁定文件
锁定/etc/passwd,/etc/passwd文件后 就相当于禁止创建用户。
[root@test-t1 ~]# chattr +i /etc/passwd //锁定文件 [root@test-t1 ~]# lsattr /etc/passwd //查看文件状态 ----i----------- /etc/passwd [root@test-t1 ~]# useradd zhangsan-t1 //创建用户测试 useradd: cannot open /etc/passwd [root@test-t1 ~]# chattr -i /etc/passwd //解锁文件 [root@test-t1 ~]# lsattr /etc/passwd ---------------- /etc/passwd
2、安全密码控制
1)设置密码有效期
# 1、针对新用户 [root@localhost ~]# vim /etc/login.defs PASS_MAX_DAYS 7 //设置密码有效期为7天 // # 2、针对已有用户 [root@test-t1 ~]# chage -M 77 lisi //设置密码有效期为7天 [root@test-t1 ~]# tail /etc/shadow //验证
2)设置下次登录时重新更改密码否则将拒绝登录
[root@test-t1 ~]# chage -d 0 lisi
3、历史命令、自动注销
1) 修改历史命令条数
bash终端环境中,历史命令的记录由变量HISTSIZE控制,默认为1000条,可以更改/etc/profile文件内容设置历史命令条数。
[root@test-t1 ~]# vim /etc/profile HISTSIZE=500 //修改为500条历史命令 [root@test-t1 ~]# source /etc/profile
2)历史命令清空
[root@test-t1 ~]# vim ~/.bash_logout history -c clear [root@test-t1 ~]# source ~/.bash_logout [root@test-t1 ~]# >~/.bash_history
3)设置超时时间
闲置超时由变量TMOUT来控制,默认单位为秒(s),更改/etc/profile文件设置
[root@test-t1 ~]# vim /etc/profile //针对新用户 export TMOUT=600 //600秒无人操作自动注销终端
4、用户切换
设置个别用户使用su命令
借助pam—wheel认证模块,只允许个别用户使用su命令,修改/etc/pam.d/su启用pam—wheel即可! 开启后只有wheel组中用户可以使用su命令
[root@test-t1 ~]# vim /etc/pam.d/su auth required pam_wheel.so use_uid //去掉前面#号 # 测试zhangsan用户是否可以使用su命令 [root@test-t1 ~]# su zhangsan [zhangsan@test-t1 root]$ su root Password: su: Permission denied //权限拒绝 没有su权限 #将zhangsan加入到wheel组中 再进行测试 [root@test-t1 ~]# usermod -g wheel zhangsan [root@test-t1 ~]# id zhangsan uid=1001(zhangsan) gid=10(wheel) groups=10(wheel)
5、提权sudo命令
使用sudo命令前需要加上sudo
sudo命令允许使用通配符"*",取反符"!"
配置文件在/etc/sudoers中,或者使用visudo命令打开 建议使用后者 授权格式为:
user MACHINE COMMANDS
授权主要包括用户,主机,命令三个部分 用户(user):直接授权指定用户名,或采用"%组名"的形式(授权组里所有用户) 主机(MACHINE):使用此配置文件的主机名称,主要方便多个主机共用一份sudoers文件,一般设置localhost或者实际主机名即可 命令(COMMANDS):填写命令程序的完整路径,多个以","逗号隔开
[root@test-t1 ~]# visudo ..... zhangsan ALL=(ALL) ALL //赋予所有权限 %wheel ALL=NOPASSWD:ALL //赋予wheel组所有权限,且不需要密码验证 lisi ALL=NOPASSWD:/bin/echo,/bin/ls //赋予lisi账户使用echo,ls命令权限
启用sudo日志记录
root@test-t1 etc]# echo "Defaults logfile=/var/log/sudo" >> /etc/sudoers
如果启用日志可以从/var/log/sudo/文件中看到sudo的操作记录
[root@test-t1 ~]# tail /var/log/sudo二、系统引导和登录控制
1、禁止快捷键重庆
[root@test-t1 etc]# ll /usr/lib/systemd/system/ctrl-alt-del.target //查看是链接文件 lrwxrwxrwx. 1 root root 13 Sep 26 18:32 /usr/lib/systemd/system/ctrl-alt-del.target -> reboot.target [root@test-t1 etc]# systemctl mask ctrl-alt-del.target //注销ctrl-alt-del.target Created symlink from /etc/systemd/system/ctrl-alt-del.target to /dev/null. [root@test-t1 etc]# systemctl daemon-reload //重新加载system配置
2、设置GRUB菜单密码
设置密码使用,grub2-mkpasswd-pbkdf2命令生成,生成密码后存放在/etc/grub.d/00_header配置文件中。
[root@test-t1 ~]# grub2-mkpasswd-pbkdf2 输入口令: //设置密码 Reenter password: PBKDF2 hash of your password is grub.pbkdf2.sha512.10000.37B241BE7B9B7AA1FE3631633F2B9FACF0C68133C8D53DF1BCDFA029A5E75B6031D99736281F45EDE65737D4145719C4A18D4F26948C9B85F1C3EE1F6DDECA5C.21F50377A7E3D5BD8C60C5FD580C48A3518AEF747E21A7D0449C9F0B5EC589FB50B8EA0D531279B7C78A15C1867D70F68E1A7BA1B8E59BACDE77CDC1F96B465A [root@test-t1 ~]# cp /boot/grub2/grub.cfg /boot/grub2/grub.cfg.bak //备份 [root@test-t1 ~]# cp /etc/grub.d/00_header /etc/grub.d/00_header.bak //备份 [root@test-t1 ~]# vim /etc/grub.d/00_header //把经加密后的字符串添加至文件末尾 cat << EOF set superusers="root" //用户设置为root password_pbkdf2 root grub.pbkdf2.sha512.10000.C93C6375BA50060DB5D5906ECDBFC79A13DC90A78A049DD792CEA7B6666B1A1418330809DD9FA89B06A5AA21C8B5259D7DB10EC993CF5F97AEE6E4D04CAA6396.C9E9900D29F7705087F2AEDF0F7F4E192000ADB9FD2569DC13A80B3ACB9F60644D283ECA6EE1A99AC994A2B039956D130CE7E5893A9D69FCCD398C8DEBDA12A0 EOF [root@test-t1 ~]# grub2-mkconfig -o /boot/grub2/grub.cfg //生成新grub.cf的文件
验证:-e 需要输入密码才可以进入GRUB菜单。
3、终端控制登入
1)禁止root远程登入
[root@test-t1 ~]# vim /etc/securetty #tty5 //禁止root在5,6终端登录 #tty6
2)禁止普通用户登录 (有些版本可能无效)
禁止新的用户登录到系统,login程序会检查/etc/noloin文件是否存,如果存在将禁止新的用户登录到系统。
[root@test-t1 ~]# touch /etc/noloin三、弱口令检测,端口扫描
1、弱口令检测
源码包下载 提取码:6666
john the ripper是一款开源软件的密码破解工具,能够在已知密文中分析出明文密码字串,支持多种加密算法。
1)编译安装john
解压后可以看到三个文件分别为doc(手册文档),run(运行程序),src(源码文件)
[root@test-t1 local]# tar zxf john-1.8.0.tar.gz [root@test-t1 local]# cd john-1.8.0/ [root@test-t1 john-1.8.0]# cd src/ [root@test-t1 src]# make clean linux-x86-64
2)弱口令检测
[root@test-t1 ~]# cp /etc/shadow /root/shadow.txt //zhe [root@test-t1 ~]# cd /usr/local/john-1.8.0/run/ [root@test-t1 run]# ./john /root/shadow.txt Loaded 3 password hashes with 3 different salts (crypt, generic crypt(3) [?/64]) Press 'q' or Ctrl-C to abort, almost any other key for stat 123456 (root) //结果 这里故意设置弱口令,复杂点的密码几乎是不会备检测出来的。 123 (lisi) //结果 # 查看已破解账户列表 [root@localhost run]# ./john --show /root/shadow.txt root:123456::0:99999:7::: lisi:123::0:99999:7::: 2 password hashes cracked, 1 left
3)使用密码字典文件
对于暴力密码破解来说密码词典很关键,john the ripper默认提供的字典文件为password.lst,其中列出3000个常见的弱口令,用户可在字典里文件中加上更多密码组合(生日,等)更容易破解密码,当然也可以自己编写字典,下面演示就是自己编写字典为dict1.txt
[root@test-t1 run]# >john.pot [root@test-t1 run]# vim dict1.txt [root@test-t1 run]# ./john --wordlist=aaa.txt /root/shadow.txt Loaded 4 password hashes with 4 different salts (crypt, generic crypt(3) [?/64]) fopen: aaa.txt: No such file or directory [root@test-t1 run]# ./john --wordlist=dict1.txt /root/shadow.txt Loaded 4 password hashes with 4 different salts (crypt, generic crypt(3) [?/64]) Press 'q' or Ctrl-C to abort, almost any other key for status 111 (zhangsan) 111 (lisi) 111 (test) 123.com (root) 4g 0:00:00:00 100% 66.66g/s 100.0p/s 400.0c/s 400.0C/s 123.com Use the "--show" option to display all of the cracked passwords reliably Session completed
注意: --wordlist=后面跟词典名称,可以使用自带字典,也可以自己编写字典
2、端口扫描
1)安装nmap
[root@test-t1 ~]# yum -y install nmap
2)语法参数选项
nmap [扫描类型] [选项] <扫描目标> 常有选项: -p:指定端口 -n:不解析DNS -sS,TCP SYN 扫描(半开扫描):只想目标发出SYN数据包,如果收到SYN/ACK响应包就认为目录端口正在监听,并立即断开;否则认为目标端口未开放。 -sT,TCP连接扫描:这是完整的TCP扫描方式,用来建立一个TCP连接,如果成功则认为目标端口正在监听服务,否则认为目录端口未开放。 -sF,TCP FIN扫描:开放端口会忽略这种数据包,关闭的端口会回应RST数据包。许多防火墙只对SYN数据包进行简单过滤,而忽略了其他形式的TCP攻击包。这种类型的扫描可间接检测防火墙的健壮性。 -sU,UDP扫描:探测目标主机提供哪些UDP服务,UDP扫描的速度会比较慢。 -sP,ICMP扫描:类似于ping检测,快速判断目标主机是否存活,不做其他扫描。 -pO,跳过ping检测:这种方式认为所有的目标主句是存活的,当对方不响应ICMP请求时,使用这种方式可用避免因无法ping通而放弃扫描。
# 1、扫描tcp端口 [root@test-t1 ~]# nmap 127.0.0.1 Starting Nmap 6.40 ( http://nmap.org ) at 2021-10-09 22:31 CST Nmap scan report for localhost (127.0.0.1) Host is up (0.000016s latency). Not shown: 998 closed ports PORT STATE SERVICE 22/tcp open ssh 25/tcp open smtp Nmap done: 1 IP address (1 host up) scanned in 1.84 seconds
# 2、扫描UDP端口 [root@test-t1 ~]# nmap -sU 127.0.0.1 Starting Nmap 6.40 ( http://nmap.org ) at 2021-10-09 22:32 CST
# 3、检查192.168.1.0/24段中那些提供ftp服务 -p 指定端口 [root@test-t1 ~]# nmap -p 21 192.168.1.0/24 Starting Nmap 6.40 ( http://nmap.org ) at 2021-10-09 22:39 CST Nmap scan report for 192.168.1.77 Host is up (0.00085s latency). PORT STATE SERVICE 21/tcp filtered ftp MAC Address: 00:50:56:C0:00:08 (VMware) Nmap scan report for 192.168.1.254 Host is up (-0.10s latency). PORT STATE SERVICE 21/tcp filtered ftp MAC Address: 00:50:56:E5:40:0F (VMware) Nmap scan report for 192.168.1.66 Host is up (-13s latency). PORT STATE SERVICE 21/tcp open ftp //open 这个是开启状态!
# 4、检查192.168.1.0/24段哪些存活主机 [root@test-t1 ~]# nmap -n -sP 192.168.1.0/24 Starting Nmap 6.40 ( http://nmap.org ) at 2021-10-09 22:37 CST Nmap scan report for 192.168.1.77 Host is up (0.0010s latency). MAC Address: 00:50:56:C0:00:08 (VMware) Nmap scan report for 192.168.1.254 Host is up (-0.10s latency). MAC Address: 00:50:56:ED:1B:87 (VMware) Nmap scan report for 192.168.1.66 Host is up.
# 5、检查192.168.1.100-200有哪些开启文件共享服务 [root@test-t1 ~]# nmap -p 139,445 192.168.1.100-200 Starting Nmap 6.40 ( http://nmap.org ) at 2021-10-09 22:47 CST



