Skip to content

Instantly share code, notes, and snippets.

@azet
Last active July 28, 2018 13:03
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save azet/a68ff158fe6a742de96b to your computer and use it in GitHub Desktop.
Save azet/a68ff158fe6a742de96b to your computer and use it in GitHub Desktop.
Extracts RSA moduli for Fast-GCD (factorable.net) from masscan collected X.509 Certificates. Input needs to be stripped of non-X.509 entries first [use the power of grep(1)!].
#!/usr/bin/env python
#
# Parsing of `masscan` collected X.509 certificates
# to extract RSA moduli for Fast-GCD (factorable.net).
# ..threaded Python version.
#
# Authors: Aaron Zauner <azet@azet.org>
# License: CC0 1.0 (https://creativecommons.org/publicdomain/zero/1.0)
#
from __future__ import print_function
import sys, base64, threading, Queue
import ujson as json # best performing JSON lib. for Python
from M2Crypto import X509, RSA
obj = object()
def read_file(name, queue):
with open(name) as file:
for line in file:
queue.put(line)
queue.put(obj)
def worker(runqueue, printqueue):
for line in iter(runqueue.get, obj):
try:
data = json.loads(str(line))
der = data['ports'][0]['service']['banner']
cert = X509.load_cert_der_string(base64.b64decode(der))
pub = cert.get_pubkey()
printqueue.put(pub.get_modulus())
except:
# do nothing on broken certificate
pass
printqueue.put(obj)
if __name__ == '__main__':
filename = sys.argv[1]
runqueue = Queue.Queue()
printqueue = Queue.Queue()
threading.Thread(target = read_file, args = (filename, runqueue)).start()
threading.Thread(target = worker, args = (runqueue, printqueue)).start()
for line in iter(printqueue.get, obj):
print(line)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment