@@ -20,9 +20,9 @@ def initialize(info={})
20
20
'Description' => %q{
21
21
This module will build a .NET source file using powershell. The compiler builds
22
22
the executable or library in memory and produces a binary. After compilation the
23
- PoweShell session can also sign the executable if provided a path the a .pfx formatted
24
- certificate. Compiler options and a list of assemblies required can be configured
25
- in the datastore.
23
+ PowerShell session can also sign the executable if provided a path the
24
+ a .pfx formatted certificate. Compiler options and a list of assemblies
25
+ required can be configured in the datastore.
26
26
} ,
27
27
'License' => MSF_LICENSE ,
28
28
'Author' => 'RageLtMan <rageltman[at]sempervictus>' ,
@@ -31,7 +31,6 @@ def initialize(info={})
31
31
'Targets' => [ [ 'Universal' , { } ] ] ,
32
32
'DefaultTarget' => 0 ,
33
33
'DisclosureDate' => 'Aug 14 2012'
34
-
35
34
) )
36
35
37
36
register_options (
@@ -50,7 +49,7 @@ def initialize(info={})
50
49
] , self . class )
51
50
register_advanced_options (
52
51
[
53
- OptString . new ( 'NET_CLR_VER' , [ false , 'Minimun NET CLR version required to compile' , '3.5 ' ] ) ,
52
+ OptString . new ( 'NET_CLR_VER' , [ false , 'Minimum NET CLR version required to compile' , '4.0 ' ] ) ,
54
53
] , self . class )
55
54
56
55
end
@@ -62,19 +61,19 @@ def run
62
61
print_error ( "Incompatible Environment" )
63
62
return 0
64
63
end
65
- # Havent figured this one out yet, but we need a PID owned by a user, cant steal tokens either
64
+
65
+ # Havent figured this one out yet, but we need a PID owned by a user, can't steal tokens either
66
66
if client . sys . config . getuid == 'NT AUTHORITY\SYSTEM'
67
67
print_error ( "Cannot run as system" )
68
68
return 0
69
69
end
70
70
71
-
72
-
73
71
# End of file marker
74
72
eof = Rex ::Text . rand_text_alpha ( 8 )
75
73
env_suffix = Rex ::Text . rand_text_alpha ( 8 )
76
74
net_com_opts = { }
77
- net_com_opts [ :target ] = datastore [ 'OUTPUT_TARGET' ] || session . fs . file . expand_path ( '%TEMP%' ) + "\\ #{ Rex ::Text . rand_text_alpha ( rand ( 8 ) +8 ) } .exe"
75
+ net_com_opts [ :target ] = datastore [ 'OUTPUT_TARGET' ] ||
76
+ session . fs . file . expand_path ( '%TEMP%' ) + "\\ #{ Rex ::Text . rand_text_alpha ( rand ( 8 ) +8 ) } .exe"
78
77
net_com_opts [ :com_opts ] = datastore [ 'COMPILER_OPTS' ]
79
78
net_com_opts [ :provider ] = datastore [ 'CODE_PROVIDER' ]
80
79
net_com_opts [ :assemblies ] = datastore [ 'ASSEMBLIES' ]
@@ -94,29 +93,11 @@ def run
94
93
end
95
94
96
95
vprint_good ( "Writing to #{ net_com_opts [ :target ] } " )
97
- # Compress
98
- print_status ( 'Compressing script contents:' )
99
- compressed_script = compress_script ( script , eof )
100
- =begin
101
- # If the compressed size is > 8100 bytes, launch stager
102
- if (compressed_script.size > 8100)
103
- print_error(" - Compressed size: #{compressed_script.size}")
104
- error_msg = "Compressed size may cause command to exceed "
105
- error_msg += "cmd.exe's 8kB character limit."
106
- print_error(error_msg)
107
- print_status('Launching stager:')
108
- script = stage_cmd_env(compressed_script, env_suffix)
109
- print_good("Payload successfully staged.")
110
- else
111
- print_good(" - Compressed size: #{compressed_script.size}")
112
- script = compressed_script
113
- end
114
- =end
96
+
115
97
# Execute the powershell script
116
- print_status ( 'Executing the script.' )
117
- #psh_exec(script,false,true)
98
+ print_status ( 'Building remote code.' )
118
99
cmd_out , running_pids , open_channels = execute_script ( script , true )
119
- get_ps_output ( cmd_out , eof )
100
+ get_ps_output ( cmd_out , eof )
120
101
vprint_good ( "Cleaning up #{ running_pids . join ( ', ' ) } " )
121
102
122
103
clean_up ( nil , eof , running_pids , open_channels , env_suffix , false )
@@ -126,7 +107,7 @@ def run
126
107
size = session . fs . file . stat ( net_com_opts [ :target ] . gsub ( '\\' , '\\\\' ) ) . size
127
108
print_good ( "File #{ net_com_opts [ :target ] . gsub ( '\\' , '\\\\' ) } found, #{ size } kb" )
128
109
rescue
129
- print_error ( "File #{ net_com_opts [ :target ] . gsub ( '\\' , '\\\\' ) } not found" )
110
+ print_error ( "File #{ net_com_opts [ :target ] . gsub ( '\\' , '\\\\' ) } not found, NET CLR version #{ datastore [ 'NET_CLR_VER' ] } possibly not available " )
130
111
return
131
112
end
132
113
@@ -135,7 +116,6 @@ def run
135
116
session . sys . process . execute ( net_com_opts [ :target ] . gsub ( '\\' , '\\\\' ) , nil , { 'Hidden' => true , 'Channelized' => true } )
136
117
end
137
118
138
-
139
119
print_good ( 'Finished!' )
140
120
end
141
121
0 commit comments