!412 完成SessionBus检测脚本

Merge pull request !412 from a-alpha/alpha-dev
This commit is contained in:
a-alpha 2024-06-18 03:04:22 +00:00 committed by Gitee
commit cc11419b66
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
2 changed files with 103 additions and 0 deletions

View File

@ -0,0 +1,79 @@
# [OK] 为验证通过
# [WARNING] 为风险提示
import subprocess
import os
import sys
arg_lang = ""
################################
# 常量
# for get_env_lang()
STR_GET_ENV_LANG_ZH = "语言环境为中文"
STR_GET_ENV_LANG_EN = "语言环境为英文"
STR_GET_ENV_LANG_UNKNOW = "语言环境未知"
# for is_root()
STR_IS_ROOT_TRUE = "当前用户为root权限"
STR_IS_ROOT_FALSE = "当前用户没有root权限"
################################
# 环境检查函数
def get_env_lang():
# lang = os.getenv("LANG")
# if lang.startswith("zh"):
# return STR_GET_ENV_LANG_ZH
# elif lang.startswith("en"):
# return STR_GET_ENV_LANG_EN
# else:
# return STR_GET_ENV_LANG_UNKNOW
#
if arg_lang == "zh":
return STR_GET_ENV_LANG_ZH
elif arg_lang == "en":
return STR_GET_ENV_LANG_EN
else:
return STR_GET_ENV_LANG_UNKNOW
def is_root():
if os.geteuid() == 0:
print(STR_IS_ROOT_TRUE)
return True
else:
print(STR_IS_ROOT_FALSE)
return False
################################
# 辅助函数
def l_print(zh_str, en_str) :
if STR_GET_ENV_LANG_ZH == get_env_lang() :
print(zh_str);
else :
print(en_str);
################################
# 功能函数
# MySQL空口令检查
def check_mysql_empty_password(ip, port, username):
try:
output = subprocess.run(['mysql', '-uroot'], input="exit\n", text=True,capture_output=True)
# output = output.decode('utf-8').strip()
# output = subprocess.Popen('ls',shell=True,close_fds=True)
# output.kill()
if output.returncode == 0:
l_print(f"[WARNING] 检测到MySQL空密码: {ip}:{port}",
f"[WARNING] MySQL empty password detected for {ip}:{port}")
else:
l_print(f"[OK] MySQL空密码检查已通过: {ip}:{port}",
f"[OK] MySQL empty password check passed for {ip}:{port}")
except Exception as e:
l_print(f"[OK] MySQL空密码检查已通过: {ip}:{port}",
f"[OK] MySQL empty password check passed for {ip}:{port}")
if __name__ == '__main__':
arg_lang = sys.argv[1]
check_mysql_empty_password("localhost", 3306, "song")

View File

@ -0,0 +1,24 @@
FormatVer: 20230518
Id: check_mysql_empty_password
Belong: baseline
Power :
SiteInfo:
Severity: medium
Name: 本地服务检测 -- 检测mysql空口令
SiteRequests:
Implement:
ImArray:
- Inter : python3
InterArgs :
Exec : check_mysql_empty_password.py
Args :
- zh
Inter:
- "[WARNING]"
Condition: None
RepairArgs:
- Inter :
InterArgs :
Exec : ''
Args:
RepairPower: # root权限或者普通用户权限