Skip to content

Commit 2bcf32d

Browse files
committed
Use correct byte codecs
* UTF-8 codecs are used for reading files, encoding and decoding operations. The correct codecs to use should be Latin-1. Reason being that UTF-8 does not include 0xFE and 0xFF. . This poses a significant issue that goes unnoticed during testing, but affects core functionality. Since raw shellcode, which is essentially read from a file, may contain those characters, subsequent encoding/decoding is going to be incorrect, thus affecting the final payload which breaks at runtime. . For more information, please refer to the following links: https://en.wikipedia.org/wiki/UTF-8 https://en.wikipedia.org/wiki/ISO/IEC_8859-1 https://docs.python.org/3/howto/unicode.html#id2 https://datatracker.ietf.org/doc/html/rfc3629#section-3 * Closes mdsecactivebreach#29 * Closes mdsecactivebreach#34 * Closes mdsecactivebreach#37 * Fixes mdsecactivebreach#42
1 parent d25c936 commit 2bcf32d

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

SharpShooter.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ def run(self, args):
405405
except Exception as e:
406406
print("\n\033[1;31m[!]\033[0;0m Incorrect choice")
407407

408-
template_body = template_body.decode(encoding='utf-8')
408+
template_body = template_body.decode(encoding='latin-1')
409409
template_code = template_body.replace("%SANDBOX_ESCAPES%", sandbox_techniques)
410410

411411
delivery_method = "1"
@@ -449,7 +449,7 @@ def run(self, args):
449449
# sc_split = [encoded_sc[i:i+100] for i in range(0, len(encoded_sc), 100)]
450450
# for i in sc_split:
451451
#else:
452-
template_code = template_code.replace("%SHELLCODE64%", encoded_sc.decode(encoding='utf-8'))
452+
template_code = template_code.replace("%SHELLCODE64%", encoded_sc.decode(encoding='latin-1'))
453453

454454
else:
455455
refs = args.refs
@@ -521,36 +521,36 @@ def run(self, args):
521521

522522
key = self.rand_key(10)
523523
payload_encrypted = self.rc4(key, template_code)
524-
payload_encoded = base64.b64encode(payload_encrypted.encode(encoding='utf-8'))
524+
payload_encoded = base64.b64encode(payload_encrypted.encode(encoding='latin-1'))
525525

526526
awl_payload_simple = ""
527527

528528
if("js" in file_type or args.comtechnique):
529-
harness = self.read_file(source_path + "templates/harness.js").decode(encoding='UTF-8')
530-
payload = harness.replace("%B64PAYLOAD%", payload_encoded.decode(encoding='utf-8'))
529+
harness = self.read_file(source_path + "templates/harness.js").decode(encoding='latin-1')
530+
payload = harness.replace("%B64PAYLOAD%", payload_encoded.decode(encoding='latin-1'))
531531
payload = payload.replace("%KEY%", "'%s'" % (key))
532532
payload_minified = jsmin(payload)
533533
awl_payload_simple = template_code
534534
elif("wsf" in file_type):
535-
harness = self.read_file(source_path + "templates/harness.wsf").decode(encoding='utf-8')
536-
payload = harness.replace("%B64PAYLOAD%", payload_encoded.decode(encoding='utf-8'))
535+
harness = self.read_file(source_path + "templates/harness.wsf").decode(encoding='latin-1')
536+
payload = harness.replace("%B64PAYLOAD%", payload_encoded.decode(encoding='latin-1'))
537537
payload = payload.replace("%KEY%", "'%s'" % (key))
538538
payload_minified = jsmin(payload)
539539
elif("hta" in file_type):
540-
harness = self.read_file(source_path + "templates/harness.hta").decode(encoding='utf-8')
541-
payload = harness.replace("%B64PAYLOAD%", payload_encoded.decode(encoding='utf-8'))
540+
harness = self.read_file(source_path + "templates/harness.hta").decode(encoding='latin-1')
541+
payload = harness.replace("%B64PAYLOAD%", payload_encoded.decode(encoding='latin-1'))
542542
payload = payload.replace("%KEY%", "'%s'" % (key))
543543
payload_minified = jsmin(payload)
544544
elif("vba" in file_type):
545-
harness = self.read_file(source_path + "templates/harness.vba").decode(encoding='utf-8')
546-
payload = harness.replace("%B64PAYLOAD%", payload_encoded.decode(encoding='utf-8'))
545+
harness = self.read_file(source_path + "templates/harness.vba").decode(encoding='latin-1')
546+
payload = harness.replace("%B64PAYLOAD%", payload_encoded.decode(encoding='latin-1'))
547547
payload = payload.replace("%KEY%", "\"%s\"" % (key))
548548
payload_minified = jsmin(payload)
549549
elif("slk" in file_type):
550550
pass
551551
else:
552-
harness = self.read_file(source_path + "templates/harness.vbs").decode(encoding='utf-8')
553-
payload = harness.replace("%B64PAYLOAD%", payload_encoded.decode(encoding='utf-8'))
552+
harness = self.read_file(source_path + "templates/harness.vbs").decode(encoding='latin-1')
553+
payload = harness.replace("%B64PAYLOAD%", payload_encoded.decode(encoding='latin-1'))
554554
payload = payload.replace("%KEY%", "\"%s\"" % (key))
555555

556556
if (payload_type == 3):
@@ -588,7 +588,7 @@ def run(self, args):
588588
outputfile_shellcode = outputfile + ".payload"
589589
with open(outputfile_shellcode, 'w') as f:
590590
gzip_encoded = base64.b64encode(shellcode_gzip.getvalue())
591-
f.write(gzip_encoded.decode(encoding='utf-8'))
591+
f.write(gzip_encoded.decode(encoding='latin-1'))
592592
f.close()
593593
print("\033[1;34m[*]\033[0;0m Written shellcode payload to %s" % outputfile_shellcode)
594594

modules/embedinhtml.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ def run_embedInHtml(key, fileName, outFileName, template_name):
134134
print("\033[93m[!]\033[0;0m Could not determine the mime type for the input file. Force it using the -m switch.")
135135
quit()
136136

137-
payload = base64.b64encode(rc4Encryptor.binaryEncrypt(fileBytes.decode(encoding='utf-8')).encode())
137+
payload = base64.b64encode(rc4Encryptor.binaryEncrypt(fileBytes.decode(encoding='latin-1')).encode())
138138
print("\033[1;34m[*]\033[0;0m Encrypted input file with key [{}]".format(key))
139139

140140
# blobShim borrowed from https://github.com/mholt/PapaParse/issues/175#issuecomment-75597039

0 commit comments

Comments
 (0)