Changeset 66 for trunk/lib/bletchley/blobtools.py
- Timestamp:
- 11/04/13 11:54:59 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/bletchley/blobtools.py
r65 r66 2 2 A collection of tools to assist in analyzing encrypted blobs of data 3 3 4 Copyright (C) 2011-201 2Virtual Security Research, LLC4 Copyright (C) 2011-2013 Virtual Security Research, LLC 5 5 Author: Timothy D. Morgan, Jason A. Donenfeld 6 6 … … 165 165 blob = blob.replace(bytes([c]), b'') 166 166 167 nopad = blob.rstrip(self.pad) 167 if self.dialect.endswith('intpad'): 168 if blob[-1] not in b'012': 169 return False 170 nopad = blob[:-1] 171 padlen = blob[-1] - 48 # see the ascii table 172 else: 173 nopad = blob.rstrip(self.pad) 174 padlen = len(blob) - len(nopad) 175 176 # what the pad length ought to be 168 177 padlen_guess = self._guessPadLength(len(nopad)) 169 178 if padlen_guess == None: … … 176 185 # pad must not appear in the middle of the 177 186 # string and must be the correct length at the end 178 return (self.pad not in nopad) and ( len(blob) == len(nopad)+padlen_guess)187 return (self.pad not in nopad) and (padlen == padlen_guess) 179 188 180 189 def decode(self, blob): … … 182 191 blob = blob.replace(bytes(c), b'') 183 192 193 if self.dialect.endswith('intpad'): 194 padlen = blob[-1] - 48 # see the ascii table 195 padlen_guess = self._guessPadLength(len(blob[:-1])) 196 if padlen != padlen_guess: 197 raise Exception("Invalid length for int-padded base64 string. (%d != %d)" 198 % (padlen, padlen_guess)) 199 200 blob = blob[:-1] + (self.pad*padlen) 201 184 202 if self.dialect.endswith('nopad'): 185 203 if self.pad in blob: … … 208 226 if ret_val != None and self.dialect.endswith('nopad'): 209 227 ret_val = ret_val.rstrip(self.pad) 228 229 if ret_val != None and self.dialect.endswith('intpad'): 230 stripped = ret_val.rstrip(self.pad) 231 ret_val = stripped + ("%d" % (len(ret_val) - len(stripped))).encode('utf-8') 210 232 211 233 return ret_val … … 337 359 return _percentEncode(blob, plus=plus, upper=upper) 338 360 339 361 # XXX: need a better way to organize these with the possible combinations of dialects, padding, etc 362 # for instance, can we have rfc3548-newline-nopad ? 340 363 priorities = [ 341 364 (hexEncoding, 'upper', 100), … … 349 372 (base64Encoding, 'rfc3548-nopad', 201), 350 373 (base64Encoding, 'rfc3548-newline', 202), 374 (base64Encoding, 'rfc3548-intpad', 203), 351 375 (base64Encoding, 'filename', 210), 352 376 (base64Encoding, 'filename-nopad', 211), 377 (base64Encoding, 'filename-intpad', 212), 353 378 (base64Encoding, 'url1', 230), 354 379 (base64Encoding, 'url1-nopad', 231), 380 (base64Encoding, 'url1-intpad', 232), 355 381 (base64Encoding, 'otkurl', 235), 356 382 (base64Encoding, 'otkurl-nopad', 236), 383 (base64Encoding, 'otkurl-intpad', 237), 357 384 (base64Encoding, 'url2', 240), 358 385 (base64Encoding, 'url2-nopad', 241), 386 (base64Encoding, 'url2-intpad', 242), 359 387 (base64Encoding, 'url3', 250), 360 388 (base64Encoding, 'url3-nopad', 251), 389 (base64Encoding, 'url3-intpad', 252), 361 390 (base64Encoding, 'url4', 260), 362 391 (base64Encoding, 'url4-nopad', 261), 392 (base64Encoding, 'url4-intpad', 262), 363 393 (base64Encoding, 'url5', 265), 364 394 (base64Encoding, 'url5-nopad', 266), 395 (base64Encoding, 'url5-intpad', 267), 365 396 (base64Encoding, 'url6', 267), 366 397 (base64Encoding, 'url6-nopad', 268), 398 (base64Encoding, 'url6-intpad', 269), 367 399 (base64Encoding, 'xmlnmtoken', 270), 368 400 (base64Encoding, 'xmlnmtoken-nopad', 271), 401 (base64Encoding, 'xmlnmtoken-intpad', 272), 369 402 (base64Encoding, 'xmlname', 280), 370 403 (base64Encoding, 'xmlname-nopad', 281), 404 (base64Encoding, 'xmlname-intpad', 282), 371 405 (percentEncoding, 'upper-plus', 400), 372 406 (percentEncoding, 'upper', 401),
Note: See TracChangeset
for help on using the changeset viewer.