-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathLicenseGenerator.swift
175 lines (143 loc) · 6.55 KB
/
LicenseGenerator.swift
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
//
// LicenseGenerator.swift
// CLCracker
//
// Created by Maksim on 06.01.2024.
//
import Foundation
import CommonCrypto
typealias MGCopyAnswer = (@convention(c) (CFString) -> CFString)
class LicenseGenerator {
static var randomChar: String = ""
static func GenerateLicense() -> String? {
let handle = dlopen("/usr/lib/libMobileGestalt.dylib", RTLD_NOW)
let copyAnswerSymbol = dlsym(handle, "MGCopyAnswer")
let copyAnswerFunction = unsafeBitCast(copyAnswerSymbol, to: MGCopyAnswer.self)
let UDID = copyAnswerFunction("UniqueDeviceID" as CFString) as String // UDID
// Console.shared.log("[+] UDID: " + UDID)
let EthernetAddressV1 = copyAnswerFunction("EthernetMacAddress" as CFString) as String // MACv1
var EthernetAddressV2 = "" // MACv2
let components = EthernetAddressV1.components(separatedBy: ":")
if components.count >= 1 {
if var firstOctet = UInt8(components[0], radix: 16) {
firstOctet += 2
let modifiedString = String(format: "%02X%@", firstOctet, components[1...].joined(separator: ""))
let finalString = modifiedString.lowercased().replacingOccurrences(of: ":", with: "")
EthernetAddressV2 = finalString
}
}
// Console.shared.log("[+] MACv2: " + UDID)
return GenerateLicenseWrapper(UDID: UDID, model: getDeviceModel(), MACv2: EthernetAddressV2)
}
static func GenerateLicenseWrapper(UDID: String, model: String, MACv2: String) -> String? {
randomChar = generateRandomChars()
let LicenseV2field = generateLicenseV2String(UDID: UDID, Model: model)
let Request256field = generateRequest256(key: generateRequest256Key(MACv2: MACv2)!)
let Request256fieldBase64 = encodeRequest256field(Request256field!)
return generateXMLString(LicenseV2field: LicenseV2field!, Request256fieldBase64: Request256fieldBase64!)
}
static func MD5(_ string: String) -> String? {
let length = Int(CC_MD5_DIGEST_LENGTH)
var digest = [UInt8](repeating: 0, count: length)
if let d = string.data(using: String.Encoding.utf8) {
_ = d.withUnsafeBytes { (body: UnsafePointer<UInt8>) in
CC_MD5(body, CC_LONG(d.count), &digest)
}
}
return (0..<length).reduce("") {
$0 + String(format: "%02x", digest[$1])
}
}
static func generateRandomChars() -> String {
let letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
let digits = "0123456789"
let randomLetter = letters.randomElement() ?? "a"
let randomDigit = digits.randomElement() ?? "0"
return String(randomLetter) + String(randomDigit)
}
static func getDeviceModel() -> String {
var systemInfo = utsname()
uname(&systemInfo)
let machineMirror = Mirror(reflecting: systemInfo.machine)
let identifier = machineMirror.children.reduce("") { identifier, element in
guard let value = element.value as? Int8, value != 0 else { return identifier }
return identifier + String(UnicodeScalar(UInt8(value)))
}
return identifier
}
static func generateLicenseV2String(UDID: String, Model: String) -> String? {
let originalString = "947066a0b35b3bf2ecd4d697cc6e6700" + UDID + randomChar + Model
var md5String = MD5(originalString)
let indexToRemove5 = md5String!.index(md5String!.endIndex, offsetBy: -5)
let indexToRemove6 = md5String!.index(md5String!.endIndex, offsetBy: -6)
md5String!.remove(at: indexToRemove5)
md5String!.remove(at: indexToRemove6)
let insertionIndex = md5String!.index(md5String!.endIndex, offsetBy: -16)
let substringToInsert = randomChar
md5String!.insert(contentsOf: substringToInsert, at: insertionIndex)
return md5String
}
static func generateRequest256Key(MACv2: String) -> String? {
let result = MACv2 + randomChar + MACv2 + "14" + randomChar + randomChar
return result
}
static func generateRequest256(key: String) -> String? {
let text = "CL_IIllIllllIlIllllIIIIlIIlIlllIlIIlIlIIIlI:;CL_IIllIllIIllIIllllllIIIIIllIlllIIllIllIII:;CL_lIllIllIIlIlIIlIIIlIIlIIlllllllIIIIIIlIl"
guard let plaintextData = text.data(using: .utf8),
let keyData = key.data(using: .utf8) else {
return nil
}
let bufferSize = plaintextData.count + kCCBlockSizeAES128
var buffer = [UInt8](repeating: 0, count: bufferSize)
var numBytesEncrypted: size_t = 0
let status = keyData.withUnsafeBytes { keyBytes in
plaintextData.withUnsafeBytes { dataBytes in
CCCrypt(CCOperation(kCCEncrypt),
CCAlgorithm(kCCAlgorithmAES),
CCOptions(kCCOptionPKCS7Padding),
keyBytes.baseAddress,
keyData.count,
nil,
dataBytes.baseAddress,
plaintextData.count,
&buffer,
bufferSize,
&numBytesEncrypted)
}
}
if status == kCCSuccess {
let encryptedData = Data(bytes: buffer, count: numBytesEncrypted)
return encryptedData.base64EncodedString()
}
return nil
}
static func encodeRequest256field(_ request256field: String) -> String? {
guard let requestData = request256field.data(using: .utf8) else {
return nil
}
let base64String = requestData.base64EncodedString()
return base64String
}
static func generateXMLString(LicenseV2field: String, Request256fieldBase64: String) -> String {
let xmlString =
"""
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>DidShowSetup</key>
<integer>1</integer>
<key>LicenseV2</key>
<string>\(LicenseV2field)</string>
<key>Request256</key>
<data>
\(Request256fieldBase64)
</data>
<key>Version</key>
<string>144BC3</string>
</dict>
</plist>
"""
return xmlString
}
}