Skip to content

Commit 199bf8e

Browse files
committed
cleanups and update to require 4.0 CLR by default
1 parent 44c5fc3 commit 199bf8e

File tree

1 file changed

+12
-32
lines changed

1 file changed

+12
-32
lines changed

modules/post/windows/manage/powershell/build_net_code.rb

Lines changed: 12 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ def initialize(info={})
2020
'Description' => %q{
2121
This module will build a .NET source file using powershell. The compiler builds
2222
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.
2626
},
2727
'License' => MSF_LICENSE,
2828
'Author' => 'RageLtMan <rageltman[at]sempervictus>',
@@ -31,7 +31,6 @@ def initialize(info={})
3131
'Targets' => [ [ 'Universal', {} ] ],
3232
'DefaultTarget' => 0,
3333
'DisclosureDate' => 'Aug 14 2012'
34-
3534
))
3635

3736
register_options(
@@ -50,7 +49,7 @@ def initialize(info={})
5049
], self.class)
5150
register_advanced_options(
5251
[
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']),
5453
], self.class)
5554

5655
end
@@ -62,19 +61,19 @@ def run
6261
print_error("Incompatible Environment")
6362
return 0
6463
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
6666
if client.sys.config.getuid == 'NT AUTHORITY\SYSTEM'
6767
print_error("Cannot run as system")
6868
return 0
6969
end
7070

71-
72-
7371
# End of file marker
7472
eof = Rex::Text.rand_text_alpha(8)
7573
env_suffix = Rex::Text.rand_text_alpha(8)
7674
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"
7877
net_com_opts[:com_opts] = datastore['COMPILER_OPTS']
7978
net_com_opts[:provider] = datastore['CODE_PROVIDER']
8079
net_com_opts[:assemblies] = datastore['ASSEMBLIES']
@@ -94,29 +93,11 @@ def run
9493
end
9594

9695
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+
11597
# Execute the powershell script
116-
print_status('Executing the script.')
117-
#psh_exec(script,false,true)
98+
print_status('Building remote code.')
11899
cmd_out, running_pids, open_channels = execute_script(script, true)
119-
get_ps_output(cmd_out,eof)
100+
get_ps_output(cmd_out, eof)
120101
vprint_good( "Cleaning up #{running_pids.join(', ')}" )
121102

122103
clean_up(nil, eof, running_pids, open_channels, env_suffix, false)
@@ -126,7 +107,7 @@ def run
126107
size = session.fs.file.stat(net_com_opts[:target].gsub('\\','\\\\')).size
127108
print_good("File #{net_com_opts[:target].gsub('\\','\\\\')} found, #{size}kb")
128109
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")
130111
return
131112
end
132113

@@ -135,7 +116,6 @@ def run
135116
session.sys.process.execute(net_com_opts[:target].gsub('\\','\\\\'), nil, {'Hidden' => true, 'Channelized' => true})
136117
end
137118

138-
139119
print_good('Finished!')
140120
end
141121

0 commit comments

Comments
 (0)