first commit

This commit is contained in:
iProbe 2022-10-18 16:59:37 +08:00
commit ba848e218d
1001 changed files with 152333 additions and 0 deletions

15
shell/safe/00-backup.sh Normal file
View file

@ -0,0 +1,15 @@
#!/bin/bash
# 备份
cp /etc/pam.d/su $backupdir
cp /etc/pam.d/sshd $backupdir
cp /etc/pam.d/login $backupdir
cp /etc/ssh/sshd_config $backupdir
cp /etc/profile $backupdir
cp /etc/sysctl.conf $backupdir
cp /etc/hosts.allow $backupdir
cp /etc/hosts.deny $backupdir
cp /etc/selinux/config $backupdir

View file

@ -0,0 +1,6 @@
#!/bin/bash
# 密码长度
sed -i 's/^PASS_MIN_LEN 5/PASS_MIN_LEN $lenth/g' /etc/login.defs
# 密码过期
sed -i 's/^PASS_MAX_DAYS 99999/PASS_MAX_DAYS $days/g' /etc/login.defs

6
shell/safe/02-host.sh Normal file
View file

@ -0,0 +1,6 @@
#!/bin/bash
sed -i '$a\ALL:ALL:deny' /etc/hosts.deny
for ip in $ip_h;do
sed -i '$a\sshd:$ssh_port:allow' /etc/hosts.allow
done

3
shell/safe/03-selinux.sh Normal file
View file

@ -0,0 +1,3 @@
#!/bin/bash
sed -i 's@^SELINUX=enforcing@SELINUX=permissive@' /etc/selinux/config

10
shell/safe/04-firewall.sh Normal file
View file

@ -0,0 +1,10 @@
#!/bin/bash
# 添加端口访问
for ip in $ip_f;do
firewall-cmd --zone=work --add-source=$ip/24 --permanent
done
firewall-cmd --zone=work --add-port=$ssh_port/tcp --permanent
firewall-cmd --zone=work --add-port=$http_port/tcp --permanent
firewall-cmd --zone=work --add-port=$https_port/tcp --permanent
firewall-cmd --reload

10
shell/safe/05-sshd.sh Normal file
View file

@ -0,0 +1,10 @@
#!/bin/bash
# sshd端口
sed -i "/^#Port 22/a\Port $ssh_port" /etc/ssh/sshd_config
# 限制root用户远程
sed -i '/#PermitRootLogin yes/a\PermitRootLogin no' /etc/ssh/sshd_config
# 限制管理用户与应用用户登录。允许manager登录允许appl_user通过ip_ssh登录
sed -i "\$a\AllowUsers $manager $appl_user@$ip_ssh" /etc/ssh/sshd_config
/bin/systemctl restart sshd

6
shell/safe/06-limit.sh Normal file
View file

@ -0,0 +1,6 @@
#!/bin/bash
# 禁止非whell组用户使用su切换用户
sed -i '/pam_wheel.so use_uid$/a\auth\t\trequired\tpam_wheel.so use_uid' /etc/pam.d/su
# 只允许wheel组中的用户使用su
sed -i '$a\SU_WHEEL_ONLY yes' /etc/login.defs

5
shell/safe/07-lock.sh Normal file
View file

@ -0,0 +1,5 @@
#!/bin/bash
# 登录失败3次就锁用户300s
sed -i '/^#%PAM-1.0/a\auth\t required\tpam_tally2.so deny=3 unlock_time=300 even_deny_root root_unlock_time=300' /etc/pam.d/sshd
sed -i '/^#%PAM-1.0/a\auth\trequired\tpam_tally2.so deny=3 unlock_time=300 even_deny_root root_unlock_time=300' /etc/pam.d/login

20
shell/safe/08-sysctl.sh Normal file
View file

@ -0,0 +1,20 @@
#!/bin/bash
# 开启SYN Cookies预防Flood
sed -i '$a\net.ipv4.tcp_syncookies = 1' /etc/sysctl.conf
# 开启重用允许将TIME-WAIT套接字重新用于新的TCP连接
sed -i '$a\net.ipv4.tcp_tw_reuse = 1' /etc/sysctl.conf
# 开启TCP连接中TIME-WAIT套接字的快速回收
sed -i '$a\net.ipv4.tcp_tw_recycle = 1' /etc/sysctl.conf
# 如果套接字由本端要求关闭这个参数决定了它保持在FIN-WAIT-2状态的时间单位s
sed -i '$a\net.ipv4.tcp_fin_timeout = 30' /etc/sysctl.conf
# 当keepalive启用时TCP发送keepalive消息的频度单位s
sed -i '$a\net.ipv4.tcp_keepalive_time = 1200' /etc/sysctl.conf
# 向外连接的端口范围
sed -i '$a\net.ipv4.ip_local_port_range = 1024 65000' /etc/sysctl.conf
# SYN队列的长度
sed -i '$a\net.ipv4.tcp_max_syn_backlog = 8192' /etc/sysctl.conf
# 系统同时保持TIME_WAIT套接字的最大数量
sed -i '$a\net.ipv4.tcp_max_tw_buckets = 5000' /etc/sysctl.conf
/usr/sbin/sysctl -p

6
shell/safe/09-timeout.sh Normal file
View file

@ -0,0 +1,6 @@
#!/bin/bash
# 3分钟未操作断掉连接
sed -i 's/^#ClientAliveInterval 0/ClientAliveInterval 60/' /etc/ssh/sshd_config
sed -i 's/^#ClientAliveCountMax/ClientAliveCountMax/' /etc/ssh/sshd_config
sed -i '$a\TMOUT=300\nexport TMOUT' /etc/profile

7
shell/safe/10-umask.sh Normal file
View file

@ -0,0 +1,7 @@
#!/bin/bash
# umask
sed -i 's/umask 022/umask $umask_/' /etc/profile
sed -i 's/umask 002/umask $umask_/' /etc/profile
sed -i 's/umask 022/umask $umask_/' /etc/bashrc
sed -i 's/umask 002/umask $umask_/' /etc/bashrc

33
shell/safe/11-user.sh Normal file
View file

@ -0,0 +1,33 @@
#!/bin/bash
## 创建管理用户
echo $root_password | passwd --stdin root
# 管理组
/usr/sbin/groupadd -g $manager_group_id $manager_group
# 应用管理组
/usr/sbin/groupadd -g $appl_group_id $appl_group
# 数据库管理组
/usr/sbin/groupadd -g $db_group_id $db_group
# 查看日志组
/usr/sbin/groupadd -g $logs_group_id $logs_group
# 管理用户
/usr/sbin/useradd -u $manager_id -g $manager_group_id -G 0,10 $manager
echo $manager_password | passwd --stdin $manager
# 应用管理用户
/usr/sbin/useradd -u $appl_user_id -g $appl_group_id $appl_user
echo $appl_user_password | passwd --stdin $appl_user
# 数据库管理用户
/usr/sbin/useradd -u $db_user_id -g $db_group_id $db_user
echo $db_user_password | passwd --stdin $db_user
# 查看日志用户
/usr/sbin/useradd -u $logs_user_id -g $logs_group_id -G $appl_group_id $logs_user
echo $logs_user_password | passwd --stdin $logs_user

28
shell/safe/12-chattr.sh Normal file
View file

@ -0,0 +1,28 @@
#/bin/bash
# 锁定文件
chattr +i /etc/passwd
chattr +i /etc/group
chattr +i /etc/sudoers
chattr +i /etc/profile
chattr +i /etc/bashrc
chattr +i /etc/ssh/sshd_config
chattr +i /etc/init.d/
chattr +i /etc/rc.d/
chattr +i /etc/crontab
chattr +i /etc/cron.d/
chattr +i /etc/hosts.allow
chattr +i /etc/hosts.deny
chattr +i /usr/bin
chattr +i /usr/sbin
chattr +i /usr/local/sbin
chattr +i /usr/local/bin
chattr +i /usr/libexec
chattr +i /sbin/
chattr +i /bin/
chattr +i /etc/yum.repos.d/
chattr +i /var/spool/cron/

64
shell/safe/config.sh Normal file
View file

@ -0,0 +1,64 @@
#!/bin/bash
# 备份目录
backupdir=/opt
# root密码
root_password="Op@2019"
# 管理组
manager_group="ops"
# 管理组id
manager_group_id=500
# 管理用户
manager="opm"
# 管理用户id
manager_id=501
# 管理用户密码
manager_password="Opm#Qhiex&19"
# 应用组
appl_group="appgroup"
# 应用组id
appl_group_id=1000
# 应用用户
appl_user="appuser"
# 应用用户id
appl_user_id=1001
# 应用用户密码
appl_user_password="appuser@2019"
# 数据库管理组
db_group="dbgroup"
# 数据库管理组id
db_group_id=1500
# 数据库管理用户
db_user="dbuser"
# 数据库管理用户id
db_user_id=1501
# 数据库管理用户密码
db_user_password="database@2019"
# 查看日志组
logs_group="devgroup"
# 查看日志组id
logs_group=2000
# 查看日志用户
logs_user="dev"
# 查看日志用户id
logs_user_id=2001
# 查看日志用户密码
logs_user_password="dev@2019"
# ssh端口
ssh_port=16512
# http端口
http_port=80
# https端口
https_port=443
# 密码最短长度
lenth=8
# 密码过期时间
days=180
# umask
umask_=027
# 访问ip(firewall),以空格为分隔符
ip_f="192.168.1.0"
# 访问ip(hosts),以空格为分隔符
ip_h="192.168.1.*"
# 限制登录ip
ip_ssh="172.18.104.*"

17
shell/safe/jiagu.sh Normal file
View file

@ -0,0 +1,17 @@
#!/bin/bash
. ./config.sh
./00-backup.sh
./01-password.sh
./02-host.sh
./03-selinux.sh
./04-firewall.sh
./05-sshd.sh
./06-limit.shi
./07-lock.sh
./08-sysctl.sh
./09-timeout.s
./10-umask.sh
./11-user.sh
./12-chattr.sh