|
1 | 1 | # -*- coding: binary -*-
|
2 |
| -## |
3 |
| -# $Id$ |
4 |
| -## |
5 | 2 |
|
6 |
| -### |
7 |
| -# |
8 |
| -# framework-util-exe |
9 |
| -# -------------- |
| 3 | +module Msf |
| 4 | +module Util |
| 5 | + |
10 | 6 | #
|
11 | 7 | # The class provides methods for creating and encoding executable file
|
12 | 8 | # formats for various platforms. It is a replacement for the previous
|
13 | 9 | # code in Rex::Text
|
14 | 10 | #
|
15 |
| -### |
16 |
| - |
17 |
| -module Msf |
18 |
| -module Util |
19 | 11 | class EXE
|
20 | 12 |
|
21 | 13 | require 'rex'
|
@@ -74,7 +66,7 @@ def self.to_executable(framework, arch, plat, code='', opts={})
|
74 | 66 | if (arch.index(ARCH_X86))
|
75 | 67 |
|
76 | 68 | if (plat.index(Msf::Module::Platform::Windows))
|
77 |
| - return to_win32pe_only(framework, code, opts) |
| 69 | + return to_win32pe(framework, code, opts) |
78 | 70 | end
|
79 | 71 |
|
80 | 72 | if (plat.index(Msf::Module::Platform::Linux))
|
@@ -368,19 +360,19 @@ def self.to_win32pe_only(framework, code, opts={})
|
368 | 360 |
|
369 | 361 | sections_header = []
|
370 | 362 | pe._file_header.v['NumberOfSections'].times { |i| sections_header << [(i*0x28)+pe.rva_to_file_offset(pe._dos_header.v['e_lfanew']+pe._file_header.v['SizeOfOptionalHeader']+0x18+0x24),exe[(i*0x28)+pe.rva_to_file_offset(pe._dos_header.v['e_lfanew']+pe._file_header.v['SizeOfOptionalHeader']+0x18),0x28]] }
|
371 |
| - |
| 363 | + |
372 | 364 |
|
373 | 365 | #look for section with entry point
|
374 | 366 | sections_header.each do |sec|
|
375 | 367 | virtualAddress = sec[1][0xc,0x4].unpack('L')[0]
|
376 | 368 | sizeOfRawData = sec[1][0x10,0x4].unpack('L')[0]
|
377 | 369 | characteristics = sec[1][0x24,0x4].unpack('L')[0]
|
378 | 370 | if pe.hdr.opt.AddressOfEntryPoint >= virtualAddress && pe.hdr.opt.AddressOfEntryPoint < virtualAddress+sizeOfRawData
|
379 |
| - #put this section writable |
380 |
| - characteristics|=0x80000000 |
381 |
| - newcharacteristics = [characteristics].pack('L') |
382 |
| - exe[sec[0],newcharacteristics.length]=newcharacteristics |
383 |
| - end |
| 371 | + #put this section writable |
| 372 | + characteristics|=0x80000000 |
| 373 | + newcharacteristics = [characteristics].pack('L') |
| 374 | + exe[sec[0],newcharacteristics.length]=newcharacteristics |
| 375 | + end |
384 | 376 | end
|
385 | 377 |
|
386 | 378 | #put the shellcode at the entry point, overwriting template
|
@@ -936,7 +928,7 @@ def self.to_vba(framework,code,opts={})
|
936 | 928 | end
|
937 | 929 |
|
938 | 930 | def self.to_win32pe_vba(framework, code, opts={})
|
939 |
| - to_exe_vba(to_win32pe_only(framework, code, opts)) |
| 931 | + to_exe_vba(to_win32pe(framework, code, opts)) |
940 | 932 | end
|
941 | 933 |
|
942 | 934 | def self.to_exe_vbs(exes = '', opts={})
|
@@ -1204,15 +1196,15 @@ def self.to_win32pe_psh(framework, code, opts={})
|
1204 | 1196 | end
|
1205 | 1197 |
|
1206 | 1198 | def self.to_win32pe_vbs(framework, code, opts={})
|
1207 |
| - to_exe_vbs(to_win32pe_only(framework, code, opts), opts) |
| 1199 | + to_exe_vbs(to_win32pe(framework, code, opts), opts) |
1208 | 1200 | end
|
1209 | 1201 |
|
1210 | 1202 | def self.to_win32pe_asp(framework, code, opts={})
|
1211 |
| - to_exe_asp(to_win32pe_only(framework, code, opts), opts) |
| 1203 | + to_exe_asp(to_win32pe(framework, code, opts), opts) |
1212 | 1204 | end
|
1213 | 1205 |
|
1214 | 1206 | def self.to_win32pe_aspx(framework, code, opts={})
|
1215 |
| - to_exe_aspx(to_win32pe_only(framework, code, opts), opts) |
| 1207 | + to_exe_aspx(to_win32pe(framework, code, opts), opts) |
1216 | 1208 | end
|
1217 | 1209 |
|
1218 | 1210 | # Creates a jar file that drops the provided +exe+ into a random file name
|
@@ -1940,7 +1932,7 @@ def self.to_executable_fmt(framework, arch, plat, code, fmt, exeopts)
|
1940 | 1932 | output = Msf::Util::EXE.to_vba(framework, code, exeopts)
|
1941 | 1933 |
|
1942 | 1934 | when 'vba-exe'
|
1943 |
| - exe = Msf::Util::EXE.to_win32pe_only(framework, code, exeopts) |
| 1935 | + exe = Msf::Util::EXE.to_win32pe(framework, code, exeopts) |
1944 | 1936 | output = Msf::Util::EXE.to_exe_vba(exe)
|
1945 | 1937 |
|
1946 | 1938 | when 'vbs'
|
|
0 commit comments