How to use get_public_key_data method in lisa

Best Python code snippet using lisa_python

vulnerable_default_keys_deep_scan.py

Source:vulnerable_default_keys_deep_scan.py Github

copy

Full Screen

...66 file_path67 ]68 )69 except Exception as e: print(file_path, str(e))70def get_public_key_data(system_path, rsa, dsa, fps, ecs):71 """72 Iterates through every folder, subfolder, and file checking for public key73 data. If found, the data is extracted and added to the dictionaries.74 Args:75 file_path (str): Full system path to the file.76 rsa (dict): Dictionary of all collected RSA moduli.77 dsa (dict): Dictionary of all collected DSA data.78 fps (dict): Dictionary of all collected fingerprints.79 ecs (dict): Dictionary of all collected EC data.80 """81 for root, _, files in os.walk(system_path):82 for name in files:83 file_path = os.path.join(root, name)84 if (file_path.endswith((".crt", ".pem"))):85 extract_fps_ecs(file_path, fps, ecs)86 elif (file_path.endswith((".pub", ".info"))):87 extract_rsa_dsa(file_path, rsa, dsa)88def check_fingerprints(cur, fps):89 """90 Checks a dictionary of fingerprints against the data store in the database.91 Args:92 cur (sqlite3.Cursor): A database cursor created from a connection.93 fps (dict): A dictionary containing all the fingerprints to check.94 """95 fp_count = 096 dog_pound = {}97 for fingerprint, paths in fps.items():98 cur.execute(99 "SELECT * FROM x509info WHERE fingerprint = '%s';" % fingerprint100 )101 for ip, fp, issuer, subject, serial, notB, notA in cur:102 fp_count += 1103 dog_pound.setdefault(" && ".join(paths), 0)104 dog_pound[" && ".join(paths)] += 1105 pprint.pprint(dog_pound)106 print("FINGERPRINT TOTAL:", fp_count)107def check_rsaNumbers(cur, rsa):108 """109 Checks a dictionary of rsa numbers against the data stored in the database.110 Args:111 cur (sqlite3.Cursor): A database cursor created from a connection.112 rsa (dict): A dictionary containing all the rsa numbers to check.113 """114 rsa_count = 0115 dog_pound = {}116 cur.execute("SELECT * FROM rsaNumbers;")117 # debian_weak_keys = 0118 for ip, n, e in cur:119 file_path = rsa.get(n, None)120 if (None != file_path):121 # if ("debian_openssl_weak_keys" in file_path[0]):122 # debian_weak_keys += 1123 rsa_count += 1124 dog_pound.setdefault(" && ".join(file_path), 0)125 dog_pound[" && ".join(file_path)] += 1126 pprint.pprint(dog_pound)127 print("RSA TOTAL:", rsa_count)128 # print("DEBIAN_WEAK_KEY_TOTAL:", debian_weak_keys)129def check_dsaNumbers(cur, dsa):130 """131 Checks a dictionary of dsa numbers against the data stored in the database.132 Args:133 cur (sqlite3.Cursor): A database cursor created from a connection.134 dsa (dict): A dictionary containing all the dsa numbers to check.135 """136 dsa_count = 0137 dog_pound = {}138 cur.execute("SELECT * FROM dsaNumbers;")139 for ip, y, p, q, g in cur:140 params = dsa.get(y, None)141 if params == None: continue142 for i in params:143 if (p == i[0] and q == i[1] and g == i[2]):144 dog_pound.setdefault(i[3], 0)145 dog_pound[i[3]] += 1146 dsa_count += 1147 pprint.pprint(dog_pound)148 print("DSA TOTAL:", dsa_count)149def check_ecNumbers(cur, ecs):150 """151 Checks a dictionary of ec numbers against the data stored in the database.152 Args:153 cur (sqlite3.Cursor): A database cursor created from a connection.154 ecs (dict): A dictionary containing all the ec numbers to check.155 """156 cur.execute("SELECT * FROM ecNumbers;")157 ecs_count = 0158 dog_pound = {}159 for ip, curve, x, y in cur:160 file_path = ecs.get(str(x), None)161 if (None != file_path):162 ecs_count += 1163 dog_pound.setdefault(" && ".join(file_path), 0)164 dog_pound[" && ".join(file_path)] += 1165 pprint.pprint(dog_pound)166 print("EC TOTAL:", ecs_count)167def check_SSH_db(rsa, dsa, ecs):168 """169 Check the SSH public key database for manufacturer default keys where the170 private key is known.171 Args:172 rsa (dict): Contains all the collected rsa data form the default data.173 dsa (dict): Contains all the collected dsa data form the default data.174 ecs (dict): Contains all the collected ec data form the default data.175 """176 conn = connect(SSH_DB_PATH)177 cur = conn.cursor()178 check_rsaNumbers(cur, rsa)179 check_dsaNumbers(cur, dsa)180 check_ecNumbers(cur, ecs)181 cur.close()182 conn.close()183def check_TLS_db(fps):184 """185 Check the TLS public key database for manufacturer default keys where the186 private key is known.187 Args:188 rsa (dict): Contains all the collected rsa data form the default data.189 dsa (dict): Contains all the collected dsa data form the default data.190 ecs (dict): Contains all the collected ec data form the default data.191 """192 conn = connect(TLS_DB_PATH)193 cur = conn.cursor()194 check_fingerprints(cur, fps)195 cur.close()196 conn.close()197if (__name__ == "__main__"):198 """199 Scan each of the Manufacturer Default Key resources for a public in either200 database in which the private key is known.201 """202 rsa = {}203 dsa = {}204 fps = {}205 ecs = {}206 get_public_key_data(207 "default_keys/houseofkeys/private_keys",208 rsa, dsa, fps, ecs209 )210 get_public_key_data(211 "default_keys/houseofkeys/certificates",212 rsa, dsa, fps, ecs213 )214 get_public_key_data(215 "default_keys/ssh-badkeys/authorized",216 rsa, dsa, fps, ecs217 )218 get_public_key_data(219 "default_keys/ssh-badkeys/host",220 rsa, dsa, fps, ecs221 )222 get_public_key_data(223 "default_keys/kompromat/src",224 rsa, dsa, fps, ecs225 )226 #check_TLS_db(fps)...

Full Screen

Full Screen

gpgkey2bc.py

Source:gpgkey2bc.py Github

copy

Full Screen

...16 n += 117 else:18 break19 return ('1'*n) + result20def get_public_key_data(keyid):21 r = check_output(["gpg2", "-k", "--with-colons", "--with-key-data", keyid])22 i = 023 keyid_bytes = bytes(keyid, 'ascii')24 while True:25 i = r.find(b'\nsub:u:256:19:', i)26 if i < 0:27 print("Not found (1)")28 exit(2)29 elif r[i+22:i+30] == keyid_bytes:30 i_pkd = i+3031 while True:32 i_pkd = r.find(b'\npkd', i_pkd)33 if i_pkd < 0:34 print("Not found (2)")35 exit(2)36 elif r[i_pkd+5:i_pkd+6] == b'1':37 i_pub = i_pkd + 1138 break39 else:40 i_pkd += 441 break42 else:43 i += 1444 return r[i_pub:i_pub+130]45def main(keyid):46 pubkey_raw = binascii.unhexlify(get_public_key_data(keyid))47 pubkey_raw_sha256sum = hashlib.sha256(pubkey_raw).digest()48 ripemd160sum = hashlib.new('ripemd160',pubkey_raw_sha256sum).digest()49 pubkey_internal = b'\x00' + ripemd160sum50 pubkey_sha256sum_1st = hashlib.sha256(pubkey_internal).digest()51 pubkey_sha256sum = hashlib.sha256(pubkey_sha256sum_1st).digest()52 address = pubkey_internal + pubkey_sha256sum[0:4]53 b58address = b58encode(address)54 print(b58address)55if __name__ == '__main__':56 keyid=sys.argv[1]...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run lisa automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful