You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
90 lines
3.3 KiB
90 lines
3.3 KiB
#结果合并功能函数模块
|
|
import re
|
|
|
|
def my_merge(fun_name,result):
|
|
if fun_name == "enum4linux":
|
|
result = enum4linux_merge(result)
|
|
else:
|
|
pass
|
|
return result
|
|
|
|
|
|
#--------------------enum4linux--------------------
|
|
def enum4linux_merge(result):
|
|
print("enum4linux")
|
|
# 1.用户列表(用于密码爆破)
|
|
users = extract_users(result)
|
|
# 2. 共享目录(用于未授权访问/文件泄露)
|
|
shares = extract_shares(result)
|
|
# 3. 密码策略(指导爆破规则)
|
|
policy = extract_password_policy(result)
|
|
# 4. 操作系统信息(用于漏洞匹配)
|
|
os_info = extract_os_info(result)
|
|
# 整合输出
|
|
result = f"Users:{users}\nShares:{shares}\nPolicy:{policy}\nOS Info:{os_info}\n"
|
|
print(result)
|
|
return result
|
|
|
|
def extract_users(data):
|
|
"""提取所有用户列表(含 RID)"""
|
|
users = {}
|
|
pattern = re.compile(r"user:\[(.*?)\] rid:\[(0x[a-fA-F0-9]+)\]")
|
|
matches = pattern.findall(data)
|
|
for user, rid in matches:
|
|
users[user] = rid
|
|
return users
|
|
|
|
def extract_shares(data):
|
|
"""提取共享目录并清理 ANSI 转义码"""
|
|
shares = []
|
|
share_block = re.search(r"Share Enumeration.*?=\n(.*?)\n\n", data, re.DOTALL)
|
|
if share_block:
|
|
lines = share_block.group(1).split('\n')
|
|
for line in lines:
|
|
# 清理 ANSI 转义码(如 \x1b[35m)
|
|
line_clean = re.sub(r'\x1b\[[0-9;]*m', '', line)
|
|
if 'Disk' in line_clean or 'IPC' in line_clean:
|
|
parts = list(filter(None, line_clean.split()))
|
|
if len(parts) >= 3:
|
|
share = {
|
|
"name": parts[0],
|
|
"type": parts[1],
|
|
"access": "Unknown"
|
|
}
|
|
# 提取清理后的访问权限
|
|
access_line = re.search(rf"//.*{re.escape(parts[0])}.*Mapping: (.*?) ", data)
|
|
if access_line:
|
|
access_clean = re.sub(r'\x1b\[[0-9;]*m', '', access_line.group(1))
|
|
share["access"] = access_clean
|
|
shares.append(share)
|
|
return shares
|
|
|
|
def extract_password_policy(data):
|
|
"""提取密码策略"""
|
|
policy = {}
|
|
policy_block = re.search(r"Password Policy Information.*?=\n(.*?)\n\n", data, re.DOTALL)
|
|
if not policy_block:
|
|
return policy
|
|
|
|
policy_text = policy_block.group(1)
|
|
# 提取最小密码长度(处理未匹配情况)
|
|
min_length_match = re.search(r"Minimum password length: (\d+)", policy_text)
|
|
policy["min_length"] = min_length_match.group(1) if min_length_match else "未知"
|
|
|
|
# 提取密码复杂性要求
|
|
complexity_match = re.search(r"Password Complexity: (Enabled|Disabled)", policy_text)
|
|
policy["complexity"] = complexity_match.group(1) if complexity_match else "未知"
|
|
|
|
# 提取账户锁定阈值
|
|
lockout_match = re.search(r"Account Lockout Threshold: (\d+|None)", policy_text)
|
|
policy["lockout_threshold"] = lockout_match.group(1) if lockout_match else "未知"
|
|
return policy
|
|
|
|
def extract_os_info(data):
|
|
"""提取操作系统信息"""
|
|
os_info = {}
|
|
match = re.search(r"server \(([^)]+)\)", data)
|
|
if match:
|
|
os_info["samba_version"] = match.group(1)
|
|
return os_info
|
|
#------------------------------------------------
|
|
|