@@ -39,21 +39,22 @@ def initialize(info = {})
39
39
[
40
40
OptPath . new ( 'SOURCE_FILE' , [ true , 'Path to source code' ] ) ,
41
41
OptBool . new ( 'RUN_BINARY' , [ false , 'Execute the generated binary' , false ] ) ,
42
- OptString . new ( 'ASSEMBLIES' , [ false , 'Any assemblies outside the defaults' ,
43
- "mscorlib.dll, System.dll, System.Xml.dll, System.Data.dll" ] ) ,
42
+ OptString . new ( 'ASSEMBLIES' , [ false , 'Any assemblies outside the defaults' , "mscorlib.dll, System.dll, System.Xml.dll, System.Data.dll" ] ) ,
44
43
OptString . new ( 'OUTPUT_TARGET' , [ false , 'Name and path of the generated binary, default random, omit extension' ] ) ,
45
44
OptString . new ( 'COMPILER_OPTS' , [ false , 'Options to pass to compiler' , '/optimize' ] ) ,
46
45
OptString . new ( 'CODE_PROVIDER' , [ true , 'Code provider to use' , 'Microsoft.CSharp.CSharpCodeProvider' ] )
47
- ] , self . class )
46
+ ] , self . class
47
+ )
48
48
register_advanced_options (
49
49
[
50
50
OptString . new ( 'NET_CLR_VER' , [ false , 'Minimum NET CLR version required to compile' , '4.0' ] )
51
- ] , self . class )
51
+ ] , self . class
52
+ )
52
53
end
53
54
54
55
def run
55
56
# Make sure we meet the requirements before running the script
56
- if ! ( session . type == "meterpreter" || have_powershell? )
57
+ unless session . type == "meterpreter" || have_powershell?
57
58
print_error "Incompatible Environment"
58
59
return 0
59
60
end
@@ -68,8 +69,9 @@ def run
68
69
eof = Rex ::Text . rand_text_alpha ( 8 )
69
70
env_suffix = Rex ::Text . rand_text_alpha ( 8 )
70
71
net_com_opts = { }
71
- net_com_opts [ :target ] = datastore [ 'OUTPUT_TARGET' ] ||
72
- session . fs . file . expand_path ( '%TEMP%' ) + "\\ #{ Rex ::Text . rand_text_alpha ( rand ( 8 ) + 8 ) } .exe"
72
+ net_com_opts [ :target ] =
73
+ datastore [ 'OUTPUT_TARGET' ] ||
74
+ "#{ session . fs . file . expand_path ( '%TEMP%' ) } \\ #{ Rex ::Text . rand_text_alpha ( rand ( 8 ) + 8 ) } .exe"
73
75
net_com_opts [ :com_opts ] = datastore [ 'COMPILER_OPTS' ]
74
76
net_com_opts [ :provider ] = datastore [ 'CODE_PROVIDER' ]
75
77
net_com_opts [ :assemblies ] = datastore [ 'ASSEMBLIES' ]
@@ -110,8 +112,11 @@ def run
110
112
111
113
# Run the result
112
114
if datastore [ 'RUN_BINARY' ]
113
- session . sys . process . execute ( net_com_opts [ :target ] . gsub ( '\\' , '\\\\' ) ,
114
- nil , { 'Hidden' => true , 'Channelized' => true } )
115
+ cmd_out = session . sys . process . execute ( net_com_opts [ :target ] . gsub ( '\\' , '\\\\' ) ,
116
+ nil , 'Hidden' => true , 'Channelized' => true )
117
+ while ( out = cmd_out . channel . read )
118
+ print_good out
119
+ end
115
120
end
116
121
117
122
print_good 'Finished!'
0 commit comments