-
-
Save martbhell/96d13990d18bb26319cf9bb935057dfa to your computer and use it in GitHub Desktop.
gpg_scan.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import os | |
import subprocess | |
import re | |
import glob | |
def main(dumps): | |
for f in dumps: | |
pubring = "/home/ubuntu/keydump/%s" % f | |
output1 = subprocess.Popen(["gpg", "--list-packets", pubring], stdout=subprocess.PIPE, stderr=subprocess.PIPE) | |
output, outerr = output1.communicate() | |
# some non-utf8 stuff in an sks dump | |
output = output.decode("utf8", errors='replace') | |
items = output.split("\n#") | |
current_keyid = "??" | |
counts = {} | |
for item in items: | |
if ":public key packet:" in item: | |
m = re.search(r'keyid: ([0-9a-fA-F]+)', item) | |
try: | |
current_keyid = m.group(1) | |
except AttributeError: | |
# 'NoneType' object has no attribute 'group' | |
continue | |
if ":signature packet:" in item: | |
counts[current_keyid] = counts.get(current_keyid, 0) + 1 | |
for key in counts.keys(): | |
if counts[key] > 10000: | |
print("######### %s" % f) | |
print(key, counts[key]) | |
if __name__ == "__main__": | |
os.chdir("/home/ubuntu/keydump") | |
filez = sorted(glob.glob("*.pgp")) | |
os.chdir(os.path.realpath(os.curdir)) | |
main(filez) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment