@@ -42,9 +42,7 @@ def get_custom_exe(path=nil)
42
42
path ||= datastore [ 'EXE::Custom' ]
43
43
print_status ( "Using custom payload #{ path } , RHOST and RPORT settings will be ignored!" )
44
44
datastore [ 'DisablePayloadHandler' ] = true
45
- file = ::File . open ( path , 'rb' )
46
- exe = file . read ( file . stat . size )
47
- file . close
45
+ ::File . open ( path , 'rb' ) { |f | exe = f . read ( f . stat . size ) }
48
46
exe
49
47
end
50
48
@@ -58,16 +56,13 @@ def generate_payload_exe(opts = {})
58
56
pl ||= payload . encoded
59
57
60
58
# Fall back to x86...
61
- if not opts [ :arch ] or opts [ :arch ] . length < 1
62
- opts [ :arch ] = [ ARCH_X86 ]
63
- end
59
+ opts [ :arch ] = [ ARCH_X86 ] if !opts [ :arch ] || opts [ :arch ] . length < 1
60
+
64
61
# Ensure we have an array
65
- if not opts [ :arch ] . kind_of? Array
66
- opts [ :arch ] = [ opts [ :arch ] ]
67
- end
62
+ opts [ :arch ] = [ opts [ :arch ] ] unless opts [ :arch ] . kind_of? Array
68
63
69
64
# Transform the PlatformList
70
- if ( opts [ :platform ] . kind_of? Msf ::Module ::PlatformList )
65
+ if opts [ :platform ] . kind_of? Msf ::Module ::PlatformList
71
66
opts [ :platform ] = opts [ :platform ] . platforms
72
67
end
73
68
@@ -89,7 +84,7 @@ def generate_payload_exe_service(opts = {})
89
84
#Ensure opts[:arch] is an array
90
85
opts [ :arch ] = [ opts [ :arch ] ] unless opts [ :arch ] . kind_of? Array
91
86
92
- if opts [ :arch ] and ( opts [ :arch ] . index ( ARCH_X64 ) or opts [ :arch ] . index ( ARCH_X86_64 ) )
87
+ if opts [ :arch ] && ( opts [ :arch ] . index ( ARCH_X64 ) or opts [ :arch ] . index ( ARCH_X86_64 ) )
93
88
exe = Msf ::Util ::EXE . to_win64pe_service ( framework , pl , opts )
94
89
else
95
90
exe = Msf ::Util ::EXE . to_win32pe_service ( framework , pl , opts )
@@ -112,12 +107,12 @@ def generate_payload_dll(opts = {})
112
107
opts [ :arch ] = [ opts [ :arch ] ] unless opts [ :arch ] . kind_of? Array
113
108
114
109
# NOTE: Only x86_64 linux is supported here.
115
- if ( plat . index ( Msf ::Module ::Platform ::Linux ) )
116
- if opts [ :arch ] and ( opts [ :arch ] . index ( ARCH_X64 ) or opts [ :arch ] . index ( ARCH_X86_64 ) )
110
+ if plat . index ( Msf ::Module ::Platform ::Linux )
111
+ if opts [ :arch ] && ( opts [ :arch ] . index ( ARCH_X64 ) || opts [ :arch ] . index ( ARCH_X86_64 ) )
117
112
dll = Msf ::Util ::EXE . to_linux_x64_elf_dll ( framework , pl , opts )
118
113
end
119
- elsif ( plat . index ( Msf ::Module ::Platform ::Windows ) )
120
- if opts [ :arch ] and ( opts [ :arch ] . index ( ARCH_X64 ) or opts [ :arch ] . index ( ARCH_X86_64 ) )
114
+ elsif plat . index ( Msf ::Module ::Platform ::Windows )
115
+ if opts [ :arch ] && ( opts [ :arch ] . index ( ARCH_X64 ) || opts [ :arch ] . index ( ARCH_X86_64 ) )
121
116
dll = Msf ::Util ::EXE . to_win64pe_dll ( framework , pl , opts )
122
117
else
123
118
dll = Msf ::Util ::EXE . to_win32pe_dll ( framework , pl , opts )
@@ -140,9 +135,7 @@ def generate_payload_msi(opts = {})
140
135
:uac => datastore [ 'MSI::UAC' ]
141
136
} )
142
137
143
- msi = Msf ::Util ::EXE . to_exe_msi ( framework , exe , opts )
144
-
145
- return msi
138
+ Msf ::Util ::EXE . to_exe_msi ( framework , exe , opts )
146
139
end
147
140
148
141
protected
0 commit comments