mirror of
https://github.com/nmap/nmap.git
synced 2026-11-22 23:50:56 +00:00
Merge fd59ddfd7f into 80dd68b8d8
This commit is contained in:
commit
8a25850895
5 changed files with 49 additions and 1 deletions
10
Target.cc
10
Target.cc
|
|
@ -346,6 +346,16 @@ void Target::setTargetName(const char *name) {
|
|||
}
|
||||
}
|
||||
|
||||
void Target::addTargetNameAlias(const char *name) {
|
||||
if (name)
|
||||
target_aliases.push_back(std::string(name));
|
||||
}
|
||||
|
||||
const std::vector<std::string> &Target::getTargetNameAliases() const {
|
||||
return target_aliases;
|
||||
}
|
||||
|
||||
|
||||
/* Generates a printable string consisting of the host's IP
|
||||
address and hostname (if available). Eg "www.insecure.org
|
||||
(64.71.184.53)" or "fe80::202:e3ff:fe14:1102". The name is
|
||||
|
|
|
|||
7
Target.h
7
Target.h
|
|
@ -184,6 +184,11 @@ class Target {
|
|||
order
|
||||
*/
|
||||
void setTargetName(const char *name);
|
||||
/* Add an additional user-supplied name that resolved to the same IP as this
|
||||
target (recorded when --unique suppresses duplicate scanning). */
|
||||
void addTargetNameAlias(const char *name);
|
||||
/* Returns the list of additional user-supplied names for this target. */
|
||||
const std::vector<std::string> &getTargetNameAliases() const;
|
||||
|
||||
/* If the host is directly connected on a network, set and retrieve
|
||||
that information here. directlyConnected() will abort if it hasn't
|
||||
|
|
@ -262,6 +267,8 @@ class Target {
|
|||
struct timeout_info to;
|
||||
char *hostname; // Null if unable to resolve or unset
|
||||
char * targetname; // The name of the target host given on the command line if it is a named host
|
||||
std::vector<std::string> target_aliases; /* Additional user-supplied names that resolved to this
|
||||
same IP, collected when --unique suppresses duplicate scanning. */
|
||||
|
||||
struct probespec traceroute_probespec;
|
||||
std::list <TracerouteHop> traceroute_hops;
|
||||
|
|
|
|||
11
output.cc
11
output.cc
|
|
@ -1271,7 +1271,7 @@ static void write_xml_initial_hostinfo(const Target *currenths,
|
|||
print_MAC_XML_Info(currenths);
|
||||
/* Output a hostnames element whenever we have a name to write or the target
|
||||
is up. */
|
||||
if (currenths->TargetName() != NULL || *currenths->HostName() || strcmp(status, "up") == 0) {
|
||||
if (currenths->TargetName() != NULL || *currenths->HostName() || strcmp(status, "up") == 0 || !currenths->getTargetNameAliases().empty()) {
|
||||
xml_start_tag("hostnames");
|
||||
xml_newline();
|
||||
if (currenths->TargetName() != NULL) {
|
||||
|
|
@ -1281,6 +1281,15 @@ static void write_xml_initial_hostinfo(const Target *currenths,
|
|||
xml_close_empty_tag();
|
||||
xml_newline();
|
||||
}
|
||||
/* Print additional names collected when --unique suppressed duplicate scanning. */
|
||||
for (std::vector<std::string>::const_iterator alias = currenths->getTargetNameAliases().begin();
|
||||
alias != currenths->getTargetNameAliases().end(); ++alias) {
|
||||
xml_open_start_tag("hostname");
|
||||
xml_attribute("name", "%s", alias->c_str());
|
||||
xml_attribute("type", "user");
|
||||
xml_close_empty_tag();
|
||||
xml_newline();
|
||||
}
|
||||
if (*currenths->HostName()) {
|
||||
xml_open_start_tag("hostname");
|
||||
xml_attribute("name", "%s", currenths->HostName());
|
||||
|
|
|
|||
21
targets.cc
21
targets.cc
|
|
@ -473,6 +473,27 @@ bool HostGroupState::get_next_host(struct sockaddr_storage *ss, size_t *sslen, s
|
|||
return false;
|
||||
}
|
||||
}
|
||||
/* This IP is already in the exclude list (a --unique duplicate).
|
||||
At this point *ss holds the excluded IP. If it came from a named
|
||||
host, attach that name as an alias on the existing Target in the
|
||||
current batch so it appears in XML output.
|
||||
|
||||
Note: Nmap's streaming XML architecture finalizes and closes <host> blocks
|
||||
after each batch. Therefore, it is impossible to attach aliases to duplicates
|
||||
that occur in a later batch than the original target without buffering
|
||||
|
||||
all XML in memory. We restrict our search to the current batch. */
|
||||
if (o.unique && current_group.get_namedhost() && current_group.is_resolved_address(ss)) {
|
||||
const char *skipped_name = current_group.get_resolved_name();
|
||||
if (skipped_name) {
|
||||
for (int i = 0; i < current_batch_sz; i++) {
|
||||
if (sockaddr_storage_cmp(hostbatch[i]->TargetSockAddr(), ss) == 0) {
|
||||
hostbatch[i]->addTargetNameAlias(skipped_name);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} while (true);
|
||||
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -66,6 +66,7 @@
|
|||
|
||||
#include "TargetGroup.h"
|
||||
#include <list>
|
||||
#include <string>
|
||||
#include <nbase.h>
|
||||
class Target;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue