Skip to content

Commit caf4c02

Browse files
daniruizX0RW3LL
authored andcommitted
Use relative paths
1 parent 932079e commit caf4c02

2 files changed

Lines changed: 21 additions & 17 deletions

File tree

SharpShooter.py

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import string
1818
import sys
1919
import argparse
20+
import os
2021
import traceback
2122
from jsmin import jsmin
2223
from modules import *
@@ -204,6 +205,7 @@ def run(self, args):
204205

205206
template_body = b""
206207
template_base = "templates/sharpshooter."
208+
source_path = os.path.dirname(os.path.realpath(__file__)) + "/"
207209
shellcode_delivery = False
208210
shellcode_gzip = ""
209211
payload_type = 0
@@ -261,6 +263,7 @@ def run(self, args):
261263
template_base = "templates/sharpshooterv4."
262264

263265
#print(template_base)
266+
template_base = source_path + template_base
264267

265268
if(args.payload == "hta"):
266269
payload_type = 1
@@ -427,7 +430,7 @@ def run(self, args):
427430
shellcode_payload = shellcode_payload.lower()
428431
if (shellcode_payload == "y" or shellcode_payload == "yes"):
429432
shellcode_delivery = True
430-
shellcode_template = self.read_file("templates/shellcode.cs")
433+
shellcode_template = self.read_file(source_path + "templates/shellcode.cs")
431434

432435
shellcode = []
433436

@@ -523,30 +526,30 @@ def run(self, args):
523526
awl_payload_simple = ""
524527

525528
if("js" in file_type or args.comtechnique):
526-
harness = self.read_file("templates/harness.js").decode(encoding='UTF-8')
529+
harness = self.read_file(source_path + "templates/harness.js").decode(encoding='UTF-8')
527530
payload = harness.replace("%B64PAYLOAD%", payload_encoded.decode(encoding='utf-8'))
528531
payload = payload.replace("%KEY%", "'%s'" % (key))
529532
payload_minified = jsmin(payload)
530533
awl_payload_simple = template_code
531534
elif("wsf" in file_type):
532-
harness = self.read_file("templates/harness.wsf").decode(encoding='utf-8')
535+
harness = self.read_file(source_path + "templates/harness.wsf").decode(encoding='utf-8')
533536
payload = harness.replace("%B64PAYLOAD%", payload_encoded.decode(encoding='utf-8'))
534537
payload = payload.replace("%KEY%", "'%s'" % (key))
535538
payload_minified = jsmin(payload)
536539
elif("hta" in file_type):
537-
harness = self.read_file("templates/harness.hta").decode(encoding='utf-8')
540+
harness = self.read_file(source_path + "templates/harness.hta").decode(encoding='utf-8')
538541
payload = harness.replace("%B64PAYLOAD%", payload_encoded.decode(encoding='utf-8'))
539542
payload = payload.replace("%KEY%", "'%s'" % (key))
540543
payload_minified = jsmin(payload)
541544
elif("vba" in file_type):
542-
harness = self.read_file("templates/harness.vba").decode(encoding='utf-8')
545+
harness = self.read_file(source_path + "templates/harness.vba").decode(encoding='utf-8')
543546
payload = harness.replace("%B64PAYLOAD%", payload_encoded.decode(encoding='utf-8'))
544547
payload = payload.replace("%KEY%", "\"%s\"" % (key))
545548
payload_minified = jsmin(payload)
546549
elif("slk" in file_type):
547550
pass
548551
else:
549-
harness = self.read_file("templates/harness.vbs").decode(encoding='utf-8')
552+
harness = self.read_file(source_path + "templates/harness.vbs").decode(encoding='utf-8')
550553
payload = harness.replace("%B64PAYLOAD%", payload_encoded.decode(encoding='utf-8'))
551554
payload = payload.replace("%KEY%", "\"%s\"" % (key))
552555

@@ -555,7 +558,7 @@ def run(self, args):
555558
elif (payload_type == 5):
556559
file_type = "vbe"
557560

558-
f = open("output/" + outputfile_payload, 'w')
561+
f = open(outputfile_payload, 'w')
559562
#print(payload)
560563
if(payload_type == 8):
561564
f.write(macro_stager)
@@ -565,9 +568,9 @@ def run(self, args):
565568

566569
if(args.comtechnique):
567570
if not args.awltechnique or args.awltechnique == "wmic":
568-
payload_file = "output/" + outputfile + ".xsl"
571+
payload_file = outputfile + ".xsl"
569572
else:
570-
payload_file = "output/" + outputfile + ".sct"
573+
payload_file = outputfile + ".sct"
571574

572575
#if("js" in file_type or "hta" in file_type or "wsf" in file_type):
573576
awl_payload = awl.create_com_stager(args.comtechnique, file_type, args.awlurl, payload_file, awl_payload_simple, args.amsi)
@@ -580,22 +583,22 @@ def run(self, args):
580583
f.write(payload)
581584
f.close()
582585

583-
print("\033[1;34m[*]\033[0;0m Written delivery payload to output/%s" % outputfile_payload)
586+
print("\033[1;34m[*]\033[0;0m Written delivery payload to %s" % outputfile_payload)
584587
if shellcode_delivery:
585588
outputfile_shellcode = outputfile + ".payload"
586-
with open("output/" + outputfile_shellcode, 'w') as f:
589+
with open(outputfile_shellcode, 'w') as f:
587590
gzip_encoded = base64.b64encode(shellcode_gzip.getvalue())
588591
f.write(gzip_encoded.decode(encoding='utf-8'))
589592
f.close()
590-
print("\033[1;34m[*]\033[0;0m Written shellcode payload to output/%s" % outputfile_shellcode)
593+
print("\033[1;34m[*]\033[0;0m Written shellcode payload to %s" % outputfile_shellcode)
591594

592595
if "vba" not in file_type:
593596
if (args.smuggle):
594597
key = self.rand_key(10)
595598
template = ""
596599
template = args.template
597-
embedinhtml.run_embedInHtml(key, "./output/" + outputfile_payload, "./output/" + outputfile + ".html", template)
600+
embedinhtml.run_embedInHtml(key, outputfile_payload, outputfile + ".html", template)
598601
if __name__ == "__main__":
599602
ss = SharpShooter()
600603
args = ss.validate_args()
601-
ss.run(args)
604+
ss.run(args)

modules/embedinhtml.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,18 +188,19 @@ def run_embedInHtml(key, fileName, outFileName, template_name):
188188
if (template_choice < 1 or template_choice > 6):
189189
raise Exception
190190
if(template_choice == 1):
191-
templatesource = "./templates/sharepoint.tpl"
191+
templatesource = "templates/sharepoint.tpl"
192192
elif(template_choice == 2):
193-
templatesource = "./templates/mcafee.tpl"
193+
templatesource = "templates/mcafee.tpl"
194194
break
195195
except:
196196
print("\033[1;31m[!]\033[0;0m Incorrect choice")
197197
else:
198198
templatesource = input("\033[1;34m[*]\033[0;0m Provide full path to custom template\n")
199199

200200
else:
201-
templatesource = "./templates/%s.tpl" % template_name
201+
templatesource = "templates/%s.tpl" % template_name
202202

203+
templatesource = os.path.dirname(os.path.realpath(__file__)) + '/../' + templatesource
203204
resultHTML = convertFromTemplate(params, templatesource)
204205

205206
if resultHTML is not None:

0 commit comments

Comments
 (0)