1
1
#!/usr/bin/env python3
2
2
3
- # Name: exe2hex v1.4 (2016-04-14)
3
+ # Name: exe2hex v1.4.1 (2016-06-30) ~ Codename: hEXE
4
4
# Author: g0tmilk ~ https://blog.g0tmi1k.com/
5
5
# Licence: MIT License ~ http://opensource.org/licenses/MIT
6
6
# Credit to: exe2bat.exe & https://github.com/acjsec/exe2bam
16
16
17
17
import urllib.parse
18
18
19
- version = '1.4'
19
+ version = '1.4.1 '
20
20
21
21
22
22
###################
@@ -328,7 +328,7 @@ def finish_bat(self, loop=0):
328
328
# The final few things
329
329
output += '%sdel /F /Q %s%s\r\n' % (prefix, parts, suffix)
330
330
if self.telnet_file == None:
331
- output += '%sstart /wait /b %s%s\r\n' % (prefix, self.exe_filename, suffix)
331
+ output += '%sstart /wait /b %s%s\r\n\r\n ' % (prefix, self.exe_filename, suffix)
332
332
333
333
# Write the file out
334
334
self.write_file(self.bat_file, output, "BATch", False)
@@ -338,11 +338,15 @@ def bin_to_posh(self):
338
338
# Feedback for the user, to know where they are
339
339
verbose_msg('Converting to PoSH')
340
340
341
+ # Null any previous files
342
+ #self.posh_hex += '%secho|set /p="">%s.hex%s\r\n' % (prefix, self.short_file, suffix)
343
+ self.posh_hex += '%secho|set /p="">%s.hex%s\r\n' % (prefix, self.short_file, suffix)
344
+
341
345
# Loop through binary bytes
342
346
for i in range(0, len(self.exe_bin), hex_len):
343
- self.posh_hex += '%sset /p "= ' % (prefix)
347
+ self.posh_hex += '%secho|set /p=" ' % (prefix)
344
348
self.posh_hex += ''.join('%02x' % i for i in self.exe_bin[i:i + hex_len])
345
- self.posh_hex += '"<NUL >>%s.hex%s\r\n' % (self.short_file, suffix)
349
+ self.posh_hex += '">>%s.hex%s\r\n' % (self.short_file, suffix)
346
350
347
351
# Write resulting bat file
348
352
def save_bat(self, loop=0):
@@ -365,16 +369,16 @@ def save_bat(self, loop=0):
365
369
def save_posh(self):
366
370
# Create PoSh file!
367
371
output = self.posh_hex
368
- output += "%spowershell -Command \"$hex =Get-Content -readcount 0 -path './%s.hex';" % (prefix, self.short_file)
369
- output += "$len=$hex [0].length;"
370
- output += "$bin =New-Object byte[] ($len /2);"
372
+ output += "%spowershell -Command \"$h =Get-Content -readcount 0 -path './%s.hex';" % (prefix, self.short_file)
373
+ output += "$l=$h [0].length;"
374
+ output += "$b =New-Object byte[] ($l /2);"
371
375
output += "$x=0;"
372
- output += "for ($i=0;$i -le $len -1;$i+=2)"
373
- output += "{$bin [$x]=[byte]::Parse($hex .Substring($i,2),[System.Globalization.NumberStyles]::HexNumber);"
376
+ output += "for ($i=0;$i -le $l -1;$i+=2)"
377
+ output += "{$b [$x]=[byte]::Parse($h[0] .Substring($i,2),[System.Globalization.NumberStyles]::HexNumber);"
374
378
output += "$x+=1};"
375
- output += "set-content -encoding byte '%s' -value $bin ;\"%s\r\n" % (self.exe_filename, suffix)
379
+ output += "set-content -encoding byte '%s' -value $b ;\"%s\r\n" % (self.exe_filename, suffix)
376
380
output += "%sdel /F /Q %s.hex%s\r\n" % (prefix, self.short_file, suffix)
377
- output += "%sstart /b %s%s\r\n" % (prefix, self.exe_filename, suffix)
381
+ output += "%sstart /b %s%s\r\n\r\n " % (prefix, self.exe_filename, suffix)
378
382
379
383
# Write file out
380
384
self.write_file(self.posh_file, output, "PoSh", True)
@@ -628,7 +632,7 @@ def run(self):
628
632
error_exit('Cannot use the same input as output')
629
633
630
634
# Are we missing .bat when doing telnet?
631
- if bat == None and telnet != None :
635
+ if bat == None and telnet != False :
632
636
error_exit("Need a BATch file (-b) to use Telnet (-t)")
633
637
634
638
# Read in file information
0 commit comments