本基线脚本为自己所写,仅适用于Centos7,SUSE,TencentOS2.4系统
基线脚本主要包含以下内容
- 密码复杂度:8-32位,同时包含大小写字母,特殊字符
- 密码有效期:不超过90天
- 登录限制:密码输入错误连续5次账号临时锁定
- 连接超时:系统登录10-30分钟不活动,自动断开连接
- 分配三个用户:系统管理员,审计管理员,安全管理员
- 锁定或删除shutdown、halt帐户
- 启用安全审计功能:开启auditd,rsyslog服务
- 禁用telnet.socket服务
- 系统日志保留时间:不小于180天
自动检测/配置脚本
#! /bin/bash
#检查系统版本
function CheckSystem() {
system_version=‘’
if [[ -e /etc/os-release ]]; then
source /etc/os-release
system_version=${system_version}"PRETTY_NAME:
P
R
E
T
T
Y
_
N
A
M
E
,
"
e
l
s
e
s
y
s
t
e
m
_
v
e
r
s
i
o
n
=
PRETTY\_NAME, " else system\_version=
PRETTY_NAME,"elsesystem_version={system_version}“PRETTY_NAME: cat /etc/issue|head -n 1
, "
fi
var=KaTeX parse error: Expected '}', got 'EOF' at end of input: …?} echo "......{var}…”
}
#检查密码有效期
function CheckPassMaxDays() {
PASS_MAX_DAYS=cat /etc/login.defs | grep PASS\_MAX\_DAYS | grep -v ^# | awk '{print $2}'
if [ -z $PASS_MAX_DAYS ];then
sed -i ‘s/#PASS_MAX_DAYS/PASS_MAX_DAYS/’ /etc/login.defs
PASS_MAX_DAYS=cat /etc/login.defs | grep PASS\_MAX\_DAYS | grep -v ^# | awk '{print $2}'
fi
if [ -z $PASS_MAX_DAYS ];then
echo “…[N] Password Validity Period: Reset failed”
elif [ $PASS_MAX_DAYS -le 90 -a $PASS_MAX_DAYS -ge 30 ];then
echo “…[Y] Password Validity Period:
P
A
S
S
_
M
A
X
_
D
A
Y
S
d
a
y
s
"
e
l
s
e
s
e
d
−
i
′
/
P
A
S
S
_
M
A
X
_
D
A
Y
S
/
s
/
′
"
PASS\_MAX\_DAYS days" else sed -i '/PASS\_MAX\_DAYS/s/'"
PASS_MAX_DAYSdays"elsesed−i′/PASS_MAX_DAYS/s/′"{PASS_MAX_DAYS}”‘/90/g’ /etc/login.defs
PASS_MAX_DAYS=cat /etc/login.defs | grep PASS\_MAX\_DAYS | grep -v ^# | awk '{print $2}'
if [ $PASS_MAX_DAYS -le 90 -a $PASS_MAX_DAYS -ge 30 ];then
echo “…[Y] Password Validity Period: $PASS_MAX_DAYS days”
else
echo “…[N] Password Validity Period: Reset failed”
fi
fi
}
#检查日志保留时间
function CheckLogBackupTime() {
Log_Backup_Time=cat /etc/logrotate.conf |head -n 10|grep "rotate "| grep -v ^# | head -n 1|awk '{print $2}'
if [ -z $Log_Backup_Time ];then
sed -i ‘s/#rotate/rotate/’ /etc/logrotate.conf
Log_Backup_Time=cat /etc/logrotate.conf |head -n 10|grep "rotate "| grep -v ^# | head -n 1|awk '{print $2}'
fi
if [ -z $Log_Backup_Time ];then
echo “…[N] Log backup Time,Configuration does not exist”
elif [ $Log_Backup_Time -ge 26 ];then
echo “…[Y] Log backup Time:
L
o
g
_
B
a
c
k
u
p
_
T
i
m
e
w
e
e
k
s
"
e
l
s
e
s
e
d
−
i
′
/
r
o
t
a
t
e
/
s
/
′
"
Log\_Backup\_Time weeks" else sed -i '/rotate/s/'"
Log_Backup_Timeweeks"elsesed−i′/rotate/s/′"{Log_Backup_Time}”‘/26/g’ /etc/logrotate.conf
Log_Backup_Time=cat /etc/logrotate.conf |head -n 10|grep "rotate "| grep -v ^# | head -n 1|awk '{print $2}'
if [ $Log_Backup_Time -ge 26 ];then
echo “…[Y] Log backup Time: $Log_Backup_Time weeks”
else
echo “…[N] Log backup Time,Reset failed”
fi
fi
}
#检查会话超时时间
function CheckConnectionTimeout() {
Connection_Timeout=cat /etc/profile | grep 'export TMOUT' | grep -v ^# | cut -d= -f2
if [ -z
C
o
n
n
e
c
t
i
o
n
_
T
i
m
e
o
u
t
]
;
t
h
e
n
s
e
d
−
i
′
Connection\_Timeout ];then sed -i '
Connection_Timeout];thensed−i′a export TMOUT=1800’ /etc/profile
elif [ $Connection_Timeout -gt 1800 -o
C
o
n
n
e
c
t
i
o
n
_
T
i
m
e
o
u
t
−
l
t
600
]
;
t
h
e
n
s
e
d
−
i
′
/
T
M
O
U
T
/
s
/
′
"
Connection\_Timeout -lt 600 ];then sed -i '/TMOUT/s/'"
Connection_Timeout−lt600];thensed−i′/TMOUT/s/′"{Connection_Timeout}"‘/1800/g’ /etc/profile
fi
source /etc/profile
Connection_Timeout=cat /etc/profile | grep 'export TMOUT' | grep -v ^# | cut -d= -f2
if [ $Connection_Timeout -le 1800 -a $Connection_Timeout -ge 600 ];then
echo “…[Y] Connection timeout: $Connection_Timeout seconds”
else
echo “…[N] Connection timeout: Reset failed”
fi
}
#检查共享账户
function CheckSharedUser() {
usermod -L shutdown 2>/dev/null
usermod -L halt 2>/dev/null
echo “…[Y] Shared user: Locked”
}
#检查审计策略
function CheckAuditLogs() {
Audit_Logs=auditctl -s | grep enabled | awk '{print $2}'
if [ $Audit_Logs -ne 1 ];then
systemctl start auditd
systemctl enable auditd
fi
Audit_Logs=auditctl -s | grep enabled | awk '{print $2}'
if [ $Audit_Logs -eq 1 ];then
echo “…[Y] Audit Policy: $Audit_Logs Enable”
else
echo “…[N] Audit Policy: $Audit_Logs Disabled”
fi
}
#检查分权账户
function CheckAuthorizedUser() {
shenji=cat /etc/passwd |grep shenji | grep -v ^# | cut -d: -f 1
anquan=cat /etc/passwd |grep anquan | grep -v ^# | cut -d: -f 1
sysadmin=cat /etc/passwd |grep sysadmin | grep -v ^# | cut -d: -f 1
if [ -z KaTeX parse error: Expected 'EOF', got '#' at position 49: … shenji:In123!@#̲123|chpasswd se…a shenji ALL = (root) NOPASSWD: /usr/bin/cat , /usr/bin/less , /usr/bin/more , /usr/bin/tail , /usr/bin/head’ /etc/sudoers
fi
if [ -z $anquan ];then
useradd anquan
echo anquan:In123!@#123|chpasswd
fi
if [ -z $sysadmin ];then
useradd sysadmin
echo sysadmin:In123!@#123|chpasswd
fi
shenji=cat /etc/passwd |grep shenji | grep -v ^# | cut -d: -f 1
anquan=cat /etc/passwd |grep anquan | grep -v ^# | cut -d: -f 1
sysadmin=cat /etc/passwd |grep sysadmin | grep -v ^# | cut -d: -f 1
if [ -z $shenji -o -z $anquan -o -z $sysadmin ];then
echo “…[N] Authorized user: $shenji, $anquan, $sysadmin”
else
echo “…[Y] Authorized user: $shenji, $anquan, $sysadmin”
fi
}
#检查登录失败锁定配置CentOS
function CheckLoginFailureLock_CentOS() {
Login_Failure_Lock=grep "pam\_tally2.so" /etc/pam.d/system-auth| grep -v ^#|head -n 1|awk '{print $7}'
if [ -z $Login_Failure_Lock ];then
sed -i ‘/pam_tally2.so/s/#auth/auth/g’ /etc/pam.d/system-auth
Login_Failure_Lock=grep "pam\_tally2.so" /etc/pam.d/system-auth| grep -v ^#|head -n 1|awk '{print $7}'
fi
if [ -z
L
o
g
i
n
_
F
a
i
l
u
r
e
_
L
o
c
k
]
;
t
h
e
n
s
e
d
−
i
′
Login\_Failure\_Lock ];then sed -i '
Login_Failure_Lock];thensed−i′a auth required pam_tally2.so onerr=fail audit silent dent=5 unlock_time=600 even_deny_root root_unlock_time=600’ /etc/pam.d/system-auth
else
Login_Failure_Lock=grep "pam\_tally2.so onerr=fail audit silent dent=5 unlock\_time=600" /etc/pam.d/system-auth| grep -v ^#|awk '{print $7}'
if [ -z KaTeX parse error: Expected 'EOF', got '#' at position 60: …lly2.so/s/auth/#̲auth/g' /etc/pa…a auth required pam_tally2.so onerr=fail audit silent dent=5 unlock_time=600 even_deny_root root_unlock_time=600’ /etc/pam.d/system-auth
fi
fi
Login_Failure_Lock=grep "pam\_tally2.so onerr=fail audit silent dent=5 unlock\_time=600" /etc/pam.d/system-auth| grep -v ^#|awk '{print $7","$8","$10}'
if [ -z $Login_Failure_Lock ];then
echo “…[N] Login Failure Lock: Reset failed”
else
echo “…[Y] Login Failure Lock: $Login_Failure_Lock”
fi
}
#检查登录失败锁定配置SUSE
function CheckLoginFailureLock_SUSE() {
Login_Failure_Number=cat /etc/login.defs | grep LOGIN\_RETRIES | grep -v ^# | awk '{print $2}'
if [ -z $Login_Failure_Number ];then
sed -i ‘s/#LOGIN_RETRIES/LOGIN_RETRIES/’ /etc/login.defs
Login_Failure_Number=cat /etc/login.defs | grep LOGIN\_RETRIES | grep -v ^# | awk '{print $2}'
fi
if [ -z $Login_Failure_Number ];then
echo “…[N] Number of login failures: No configuration”
elif [ $Login_Failure_Number -le 8 -a $Login_Failure_Number -ge 3 ];then
echo “…[Y] Number of login failures:
L
o
g
i
n
_
F
a
i
l
u
r
e
_
N
u
m
b
e
r
"
e
l
s
e
s
e
d
−
i
′
/
L
O
G
I
N
_
R
E
T
R
I
E
S
/
s
/
′
"
Login\_Failure\_Number" else sed -i '/LOGIN\_RETRIES/s/'"
Login_Failure_Number"elsesed−i′/LOGIN_RETRIES/s/′"{Login_Failure_Number}”‘/5/g’ /etc/login.defs
Login_Failure_Number=cat /etc/login.defs | grep LOGIN\_RETRIES | grep -v ^# | awk '{print $2}'
if [ $Login_Failure_Number -le 8 -a $Login_Failure_Number -ge 3 ];then
自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。
深知大多数网络安全工程师,想要提升技能,往往是自己摸索成长,但自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!
因此收集整理了一份《2024年网络安全全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友。
既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上网络安全知识点,真正体系化!
由于文件比较大,这里只是将部分目录大纲截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且后续会持续更新
如果你觉得这些内容对你有帮助,可以添加VX:vip204888 (备注网络安全获取)
学习路线:
这个方向初期比较容易入门一些,掌握一些基本技术,拿起各种现成的工具就可以开黑了。不过,要想从脚本小子变成黑客大神,这个方向越往后,需要学习和掌握的东西就会越来越多以下是网络渗透需要学习的内容:
一个人可以走的很快,但一群人才能走的更远。不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎扫码加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!
img-blog.csdnimg.cn/7a04c5d629f1415a9e35662316578e07.png#pic_center)
一个人可以走的很快,但一群人才能走的更远。不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎扫码加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!
[外链图片转存中…(img-ji5ca3ZE-1712649509327)]