mirror of https://gitee.com/openkylin/genmai.git
commit
26cd076510
|
@ -0,0 +1,88 @@
|
|||
# [OK] 为验证通过
|
||||
# [WARNING] 为风险提示
|
||||
|
||||
import redis
|
||||
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 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);
|
||||
|
||||
################################
|
||||
# 功能函数
|
||||
|
||||
# Redis未授权检查
|
||||
def check_redis_unauthorized(ip, port):
|
||||
try:
|
||||
r = redis.StrictRedis(host=ip, port=int(port), db=0)
|
||||
r.ping()
|
||||
l_print(f"[WARNING] 检测到Redis未授权: {ip}:{port}",
|
||||
f"[WARNING] Redis unauthorized detected for {ip}:{port}")
|
||||
except redis.exceptions.ResponseError as e:
|
||||
if str(e) == "NOAUTH Authentication required.":
|
||||
l_print(f"[OK] Redis未授权检查已通过: {ip}:{port}",
|
||||
f"[OK] Redis authorized check passed for {ip}:{port}")
|
||||
else:
|
||||
l_print(f"[OK] Redis 错误: {ip}:{port}",
|
||||
f"[OK] Redis error for {ip}:{port}")
|
||||
except redis.exceptions.ConnectionError:
|
||||
l_print(f"[OK] Redis 链接错误 {ip}.{port}",
|
||||
f"[OK] Redis connection error for {ip}:{port}")
|
||||
|
||||
if __name__ == '__main__':
|
||||
arg_lang = sys.argv[1]
|
||||
|
||||
check_redis_unauthorized("localhost", 6379)
|
Loading…
Reference in New Issue