Reverse Lookup IP Addresses - Metasploit
This page contains detailed information about how to use the post/multi/recon/reverse_lookup metasploit module. For list of all metasploit modules, visit the Metasploit Module Library.
Module Overview
Name: Reverse Lookup IP Addresses
Module: post/multi/recon/reverse_lookup
Source code: modules/post/multi/recon/reverse_lookup.rb
Disclosure date: -
Last modification time: 2022-11-05 13:18:35 +0000
Supported architecture(s): -
Supported platform(s): BSD, Linux, OSX, Solaris, Unix, Windows
Target service / protocol: -
Target network port(s): -
List of CVEs: -
This module reverse resolves an IP address or IP address range to hostnames.
Module Ranking and Traits
Module Ranking:
- normal: The exploit is otherwise reliable, but depends on a specific version and can't (or doesn't) reliably autodetect. More information about ranking can be found here.
Stability:
- crash-safe: Module should not crash the service.
Basic Usage
There are two ways to execute this post module.
From the Meterpreter prompt
The first is by using the "run" command at the Meterpreter prompt. It allows you to run the post module against that specific session:
meterpreter > run post/multi/recon/reverse_lookup
From the msf prompt
The second is by using the "use" command at the msf prompt. You will have to figure out which session ID to set manually. To list all session IDs, you can use the "sessions" command.
msf > use post/multi/recon/reverse_lookup
msf post(reverse_lookup) > show options
... show and set options ...
msf post(reverse_lookup) > set SESSION session-id
msf post(reverse_lookup) > exploit
If you wish to run the post against all sessions from framework, here is how:
1 - Create the following resource script:
framework.sessions.each_pair do |sid, session|
run_single("use post/multi/recon/reverse_lookup")
run_single("set SESSION #{sid}")
run_single("run")
end
2 - At the msf prompt, execute the above resource script:
msf > resource path-to-resource-script
Required Options
- SESSION: The session to run this module on
Knowledge Base
Vulnerable Application
This module reverse resolves an IP address or IP address range to hostnames.
Verification Steps
- Start msfconsole
- Get a session
- Do:
use post/multi/recon/reverse_lookup
- Do:
set SESSION <session id>
- Do:
set ADDRESS <IP address>
orset RANGE <IP address range>
- Do:
run
Options
ADDRESS
IP address to resolve.
RANGE
IP address range to resolve.
Scenarios
Windows Server 2016 (x86_64)
msf6 > use post/multi/recon/reverse_lookup
msf6 post(multi/recon/reverse_lookup) > set address 1.1.1.1
address => 1.1.1.1
msf6 post(multi/recon/reverse_lookup) > set session 1
session => 1
msf6 post(multi/recon/reverse_lookup) > run
[*] Resolving 1.1.1.1
[+] 1.1.1.1 resolves to one.one.one.one
[*] Post module execution completed
Solaris 11.3 (x86_64)
msf6 > use post/multi/recon/reverse_lookup
msf6 post(multi/recon/reverse_lookup) > set address 1.1.1.1
address => 1.1.1.1
msf6 post(multi/recon/reverse_lookup) > set session 1
session => 1
msf6 post(multi/recon/reverse_lookup) > run
[*] Resolving 1.1.1.1
[+] 1.1.1.1 resolves to one.one.one.one
[*] Post module execution completed
Ubuntu Linux 22.04.1 (x86_64)
msf6 > use post/multi/recon/reverse_lookup
msf6 post(multi/recon/reverse_lookup) > set address 1.1.1.1
address => 1.1.1.1
msf6 post(multi/recon/reverse_lookup) > set session 1
session => 1
msf6 post(multi/recon/reverse_lookup) > run
[!] SESSION may not be compatible with this module:
[!] * missing Meterpreter features: stdapi_railgun_memread, stdapi_railgun_api
[*] Resolving 1.1.1.1
[+] 1.1.1.1 resolves to one.one.one.one
[*] Post module execution completed
Go back to menu.
Msfconsole Usage
Here is how the multi/recon/reverse_lookup post exploitation module looks in the msfconsole:
msf6 > use post/multi/recon/reverse_lookup
msf6 post(multi/recon/reverse_lookup) > show info
Name: Reverse Lookup IP Addresses
Module: post/multi/recon/reverse_lookup
Platform: Windows, Unix, Linux, OSX, Solaris, BSD
Arch:
Rank: Normal
Provided by:
mubix <[email protected]>
Module stability:
crash-safe
Compatible session types:
Meterpreter
Powershell
Shell
Basic options:
Name Current Setting Required Description
---- --------------- -------- -----------
ADDRESS no IP address to resolve
RANGE no IP address range to resolve
SESSION yes The session to run this module on
Description:
This module reverse resolves an IP address or IP address range to
hostnames.
View the full module info with the info -d command.
Module Options
This is a complete list of options available in the multi/recon/reverse_lookup post exploitation module:
msf6 post(multi/recon/reverse_lookup) > show options
Module options (post/multi/recon/reverse_lookup):
Name Current Setting Required Description
---- --------------- -------- -----------
ADDRESS no IP address to resolve
RANGE no IP address range to resolve
SESSION yes The session to run this module on
View the full module info with the info, or info -d command.
Advanced Options
Here is a complete list of advanced options supported by the multi/recon/reverse_lookup post exploitation module:
msf6 post(multi/recon/reverse_lookup) > show advanced
Module advanced options (post/multi/recon/reverse_lookup):
Name Current Setting Required Description
---- --------------- -------- -----------
VERBOSE false no Enable detailed status messages
WORKSPACE no Specify the workspace for this module
View the full module info with the info, or info -d command.
Post Actions
This is a list of all post exploitation actions which the multi/recon/reverse_lookup module can do:
msf6 post(multi/recon/reverse_lookup) > show actions
Post actions:
Name Description
---- -----------
Evasion Options
Here is the full list of possible evasion options supported by the multi/recon/reverse_lookup post exploitation module in order to evade defenses (e.g. Antivirus, EDR, Firewall, NIDS etc.):
msf6 post(multi/recon/reverse_lookup) > show evasion
Module evasion options:
Name Current Setting Required Description
---- --------------- -------- -----------
Go back to menu.
Error Messages
This module may fail with the following error messages:
- Failed to resolve <IP>
- Failed to resolve <IP>
- Failed to resolve <IP>
- Failed to resolve <IP>
- Failed to resolve <IP>
- Unsupported sesssion type <SESSION.TYPE>
- Failed to resolve <IP>
- ADDRESS or RANGE option must be set.
- WS2_32 is not available at this time, exiting
- WS2_32 was loaded but does not have the gethostbyaddr function, exiting
- `host' command not found
Check for the possible causes from the code snippets below found in the module source code. This can often times help in identifying the root cause of the problem.
Failed to resolve <IP>
Here is a relevant code snippet related to the "Failed to resolve <IP>" error message:
56: return if res.blank?
57:
58: hostname = res.split("\n").first.split(' ').last
59:
60: if hostname.blank? || !hostname.ends_with?('.')
61: print_error("Failed to resolve #{ip}")
62: return
63: end
64:
65: hostname.chomp('.')
66: end
Failed to resolve <IP>
Here is a relevant code snippet related to the "Failed to resolve <IP>" error message:
71: case session.type
72: when 'powershell'
73: host = cmd_exec("[System.Net.Dns]::GetHostEntry('#{ip}').HostName").to_s
74:
75: if host.blank?
76: print_error("Failed to resolve #{ip}")
77: return
78: end
79:
80: return host
81: when 'meterpreter'
Failed to resolve <IP>
Here is a relevant code snippet related to the "Failed to resolve <IP>" error message:
82: ip_ino = Rex::Socket.addr_aton(ip)
83:
84: result = client.railgun.ws2_32.gethostbyaddr(ip_ino, ip_ino.size, 2)
85:
86: if result.blank? || result['return'] == 0
87: print_error("Failed to resolve #{ip}")
88: return
89: end
90:
91: memtext = client.railgun.memread(result['return'], 255)
92:
Failed to resolve <IP>
Here is a relevant code snippet related to the "Failed to resolve <IP>" error message:
89: end
90:
91: memtext = client.railgun.memread(result['return'], 255)
92:
93: unless memtext.include?(ip_ino)
94: print_error("Failed to resolve #{ip}")
95: return
96: end
97:
98: host = memtext.split(ip_ino)[1].split("\00")[0]
99:
Failed to resolve <IP>
Here is a relevant code snippet related to the "Failed to resolve <IP>" error message:
96: end
97:
98: host = memtext.split(ip_ino)[1].split("\00")[0]
99:
100: if host.blank?
101: print_error("Failed to resolve #{ip}")
102: return
103: end
104:
105: return host
106: else
Unsupported sesssion type <SESSION.TYPE>
Here is a relevant code snippet related to the "Unsupported sesssion type <SESSION.TYPE>" error message:
102: return
103: end
104:
105: return host
106: else
107: fail_with(Failure::BadConfig, "Unsupported sesssion type #{session.type}")
108: end
109: rescue Rex::Post::Meterpreter::RequestError, Errno::ETIMEDOUT
110: print_error("Failed to resolve #{ip}")
111: nil
112: end
Failed to resolve <IP>
Here is a relevant code snippet related to the "Failed to resolve <IP>" error message:
105: return host
106: else
107: fail_with(Failure::BadConfig, "Unsupported sesssion type #{session.type}")
108: end
109: rescue Rex::Post::Meterpreter::RequestError, Errno::ETIMEDOUT
110: print_error("Failed to resolve #{ip}")
111: nil
112: end
113:
114: def run
115: address = datastore['ADDRESS']
ADDRESS or RANGE option must be set.
Here is a relevant code snippet related to the "ADDRESS or RANGE option must be set." error message:
113:
114: def run
115: address = datastore['ADDRESS']
116: range = datastore['RANGE']
117:
118: fail_with(Failure::BadConfig, 'ADDRESS or RANGE option must be set.') if address.blank? && range.blank?
119:
120: if session.platform == 'windows'
121: if session.type == 'meterpreter'
122: # Add ws2_32 just in case it isn't there...
123: session.railgun.ws2_32
WS2_32 is not available at this time, exiting
Here is a relevant code snippet related to the "WS2_32 is not available at this time, exiting" error message:
123: session.railgun.ws2_32
124:
125: # Check if gethostbyaddr is available
126: modhandle = session.railgun.kernel32.GetModuleHandleA('ws2_32.dll')
127: if modhandle['return'] == 0
128: fail_with(Failure::Unknown, 'WS2_32 is not available at this time, exiting')
129: end
130:
131: procaddr = session.railgun.kernel32.GetProcAddress(modhandle['return'], 'gethostbyaddr')
132: if procaddr['return'] == 0
133: fail_with(Failure::Unknown, 'WS2_32 was loaded but does not have the gethostbyaddr function, exiting')
WS2_32 was loaded but does not have the gethostbyaddr function, exiting
Here is a relevant code snippet related to the "WS2_32 was loaded but does not have the gethostbyaddr function, exiting" error message:
128: fail_with(Failure::Unknown, 'WS2_32 is not available at this time, exiting')
129: end
130:
131: procaddr = session.railgun.kernel32.GetProcAddress(modhandle['return'], 'gethostbyaddr')
132: if procaddr['return'] == 0
133: fail_with(Failure::Unknown, 'WS2_32 was loaded but does not have the gethostbyaddr function, exiting')
134: end
135: end
136: else
137: fail_with(Failure::NoTarget, "`host' command not found") unless command_exists?('host')
138: end
`host' command not found
Here is a relevant code snippet related to the "`host' command not found" error message:
132: if procaddr['return'] == 0
133: fail_with(Failure::Unknown, 'WS2_32 was loaded but does not have the gethostbyaddr function, exiting')
134: end
135: end
136: else
137: fail_with(Failure::NoTarget, "`host' command not found") unless command_exists?('host')
138: end
139:
140: unless address.blank?
141: print_status("Resolving #{address}")
142: host = resolve_ip(address)
Go back to menu.
Related Pull Requests
Go back to menu.
See Also
Check also the following modules related to this module:
- post/multi/recon/local_exploit_suggester
- post/multi/recon/multiport_egress_traffic
- post/multi/recon/sudo_commands
Authors
- mubix
Version
This page has been produced using Metasploit Framework version 6.2.29-dev. For more modules, visit the Metasploit Module Library.
Go back to menu.