-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinject_ca_certificate.js
76 lines (66 loc) · 2.63 KB
/
inject_ca_certificate.js
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
const fs = require('fs');
// Certificate file path
const CERT_FILE_PATH = 'ca.crt'; // Replace with your certificate file path
// Read certificate content
let certContent;
try {
certContent = fs.readFileSync(CERT_FILE_PATH);
} catch (error) {
console.error('[-] Unable to read certificate file:', error.message);
Java.use('java.lang.System').exit(1);
}
// Determine certificate format and parse
let cert;
try {
const CertFactory = Java.use('java.security.cert.CertificateFactory');
const ByteArrayInputStream = Java.use('java.io.ByteArrayInputStream');
const certFactory = CertFactory.getInstance("X.509");
// Attempt to parse PEM format
try {
const certPem = Java.use("java.lang.String").$new(certContent.toString());
const certBytes = certPem.getBytes();
cert = certFactory.generateCertificate(ByteArrayInputStream.$new(certBytes));
} catch (pemError) {
// If PEM parsing fails, try DER format
try {
cert = certFactory.generateCertificate(ByteArrayInputStream.$new(certContent));
} catch (derError) {
throw new Error('[-] Unsupported certificate format! Please provide a valid PEM or DER certificate.');
}
}
} catch (error) {
console.error('[-] Error parsing certificate:', error.message);
Java.use('java.lang.System').exit(1);
}
// Inject the certificate
Java.perform(() => {
const trustedClasses = [
'com.android.org.conscrypt.TrustedCertificateIndex',
'org.conscrypt.TrustedCertificateIndex',
'org.apache.harmony.xnet.provider.jsse.TrustedCertificateIndex'
];
trustedClasses.forEach((TrustedCertificateIndexClassname) => {
let TrustedCertificateIndex;
try {
TrustedCertificateIndex = Java.use(TrustedCertificateIndexClassname);
} catch (error) {
console.warn(`[*] Skipping certificate injection: ${TrustedCertificateIndexClassname} not found.`);
return;
}
TrustedCertificateIndex.$init.overloads.forEach((overload) => {
overload.implementation = function () {
this.$init(...arguments);
this.index(cert);
};
});
TrustedCertificateIndex.reset.overloads.forEach((overload) => {
overload.implementation = function () {
const result = this.reset(...arguments);
this.index(cert);
return result;
};
});
console.log(`[+] Successfully injected certificate into: ${TrustedCertificateIndexClassname}`);
});
console.log('== System certificate trust injection complete ==');
});