MCPcopy
hub / github.com/jtesta/ssh-audit / build_struct

Function build_struct

src/ssh_audit/ssh_audit.py:1018–1189  ·  view source on GitHub ↗
(target_host: str, banner: Optional['Banner'], kex: Optional['SSH2_Kex'] = None, pkm: Optional['SSH1_PublicKeyMessage'] = None, client_host: Optional[str] = None, software: Optional[Software] = None, algorithms: Optional[Algorithms] = None, algorithm_recommendation_suppress_list: Optional[List[str]] = None, additional_notes: List[str] = [])

Source from the content-addressed store, hash-verified

1016
1017
1018def build_struct(target_host: str, banner: Optional['Banner'], kex: Optional['SSH2_Kex'] = None, pkm: Optional['SSH1_PublicKeyMessage'] = None, client_host: Optional[str] = None, software: Optional[Software] = None, algorithms: Optional[Algorithms] = None, algorithm_recommendation_suppress_list: Optional[List[str]] = None, additional_notes: List[str] = []) -> Any: # pylint: disable=dangerous-default-value
1019
1020 def fetch_notes(algorithm: str, alg_type: str) -> Dict[str, List[Optional[str]]]:
1021 '''Returns a dictionary containing the messages in the "fail", "warn", and "info" levels for this algorithm.'''
1022 alg_db = SSH2_KexDB.get_db()
1023 alg_info = {}
1024 if algorithm in alg_db[alg_type]:
1025 alg_desc = alg_db[alg_type][algorithm]
1026 alg_desc_len = len(alg_desc)
1027
1028 # If a list for the failure notes exists, add it to the return value. Similarly, add the related lists for the warnings and informational notes.
1029 if (alg_desc_len >= 2) and (len(alg_desc[1]) > 0):
1030 alg_info["fail"] = alg_desc[1]
1031 if (alg_desc_len >= 3) and (len(alg_desc[2]) > 0):
1032 alg_info["warn"] = alg_desc[2]
1033 if (alg_desc_len >= 4) and (len(alg_desc[3]) > 0):
1034 alg_info["info"] = alg_desc[3]
1035
1036 # Add information about when this algorithm was implemented in OpenSSH/Dropbear.
1037 since_text = Algorithm.get_since_text(alg_desc[0])
1038 if (since_text is not None) and (len(since_text) > 0):
1039 # Add the "info" key with an empty list if the if-block above didn't create it already.
1040 if "info" not in alg_info:
1041 alg_info["info"] = []
1042 alg_info["info"].append(since_text)
1043 else:
1044 alg_info["fail"] = [SSH2_KexDB.FAIL_UNKNOWN]
1045
1046 return alg_info
1047
1048 banner_str = ''
1049 banner_protocol = None
1050 banner_software = None
1051 banner_comments = None
1052 if banner is not None:
1053 banner_str = str(banner)
1054 banner_protocol = '.'.join(str(x) for x in banner.protocol)
1055 banner_software = banner.software
1056 banner_comments = banner.comments
1057
1058 res: Any = {
1059 "banner": {
1060 "raw": banner_str,
1061 "protocol": banner_protocol,
1062 "software": banner_software,
1063 "comments": banner_comments,
1064 },
1065 }
1066
1067 # If we're scanning a client host, put the client's IP into the results. Otherwise, include the target host.
1068 if client_host is not None:
1069 res['client_ip'] = client_host
1070 else:
1071 res['target'] = target_host
1072
1073 if kex is not None:
1074 res['compression'] = kex.server.compression
1075

Callers 1

outputFunction · 0.85

Calls 5

FingerprintClass · 0.90
fetch_notesFunction · 0.85
dh_modulus_sizesMethod · 0.80
host_keysMethod · 0.80

Tested by

no test coverage detected