1
0
mirror of https://github.com/nmap/nmap.git synced 2026-01-02 04:49:02 +00:00

Second commit from rpc-grind branch. Removing old implementation from output and portlist.

This commit is contained in:
kroosec
2012-08-17 18:31:50 +00:00
parent 7ff385da85
commit ba9c6ea5e1
3 changed files with 7 additions and 128 deletions

View File

@@ -105,7 +105,6 @@
#include "MACLookup.h"
#include "portreasons.h"
#include "protocols.h"
#include "nmap_rpc.h"
#include "Target.h"
#include "utils.h"
#include "xml.h"
@@ -234,13 +233,6 @@ static void print_xml_service(const struct serviceDeductions *sd) {
xml_attribute("method", "%s", (sd->dtype == SERVICE_DETECTION_TABLE) ? "table" : "probed");
xml_attribute("conf", "%i", sd->name_confidence);
if (sd->rpc_status == RPC_STATUS_GOOD_PROG) {
xml_attribute("rpcnum", "%li", sd->rpc_program);
xml_attribute("lowver", "%i", sd->rpc_lowver);
xml_attribute("highver", "%i", sd->rpc_highver);
xml_attribute("proto", "rpc");
}
if (sd->cpe.empty()) {
xml_close_empty_tag();
} else {
@@ -501,14 +493,11 @@ static char *formatScriptOutput(ScriptResult sr) {
should write helper functions to handle the table creation */
void printportoutput(Target *currenths, PortList *plist) {
char protocol[MAX_IPPROTOSTRLEN + 1];
char rpcinfo[64];
char rpcmachineinfo[64];
char portinfo[64];
char grepvers[256];
char *p;
const char *state;
char serviceinfo[64];
char *name = NULL;
int i;
int first = 1;
struct protoent *proto;
@@ -729,41 +718,7 @@ void printportoutput(Target *currenths, PortList *plist) {
if (sd.service_fp && saved_servicefps.size() <= 8)
saved_servicefps.push_back(sd.service_fp);
switch (sd.rpc_status) {
case RPC_STATUS_UNTESTED:
rpcinfo[0] = '\0';
strcpy(rpcmachineinfo, "");
break;
case RPC_STATUS_UNKNOWN:
strcpy(rpcinfo, "(RPC (Unknown Prog #))");
strcpy(rpcmachineinfo, "R");
break;
case RPC_STATUS_NOT_RPC:
rpcinfo[0] = '\0';
strcpy(rpcmachineinfo, "N");
break;
case RPC_STATUS_GOOD_PROG:
name = nmap_getrpcnamebynum(sd.rpc_program);
Snprintf(rpcmachineinfo, sizeof(rpcmachineinfo),
"(%s:%li*%i-%i)", (name) ? name : "", sd.rpc_program,
sd.rpc_lowver, sd.rpc_highver);
if (!name) {
Snprintf(rpcinfo, sizeof(rpcinfo), "(#%li (unknown) V%i-%i)",
sd.rpc_program, sd.rpc_lowver, sd.rpc_highver);
} else {
if (sd.rpc_lowver == sd.rpc_highver) {
Snprintf(rpcinfo, sizeof(rpcinfo), "(%s V%i)", name,
sd.rpc_lowver);
} else
Snprintf(rpcinfo, sizeof(rpcinfo), "(%s V%i-%i)", name,
sd.rpc_lowver, sd.rpc_highver);
}
break;
default:
fatal("Unknown rpc_status %d", sd.rpc_status);
break;
}
current->getNmapServiceName(serviceinfo, sizeof(serviceinfo), rpcinfo);
current->getNmapServiceName(serviceinfo, sizeof(serviceinfo));
Tbl->addItem(rowno, portcol, true, portinfo);
Tbl->addItem(rowno, statecol, false, state);
@@ -796,8 +751,8 @@ void printportoutput(Target *currenths, PortList *plist) {
p++;
}
}
log_write(LOG_MACHINE, "%d/%s/%s//%s/%s/%s/", current->portno,
state, protocol, serviceinfo, rpcmachineinfo, grepvers);
log_write(LOG_MACHINE, "%d/%s/%s//%s/%s/", current->portno,
state, protocol, serviceinfo, grepvers);
xml_open_start_tag("port");
xml_attribute("protocol", "%s", protocol);

View File

@@ -99,7 +99,6 @@
#include "NmapOps.h"
#include "services.h"
#include "protocols.h"
#include "nmap_rpc.h"
#include "tcpip.h"
#include "libnetutil/netutil.h"
@@ -159,7 +158,7 @@ void Port::freeScriptResults(void)
Name nmap normal output will use to describe the port. This takes
into account to confidence level, any SSL tunneling, etc. Truncates
namebuf to 0 length if there is no room.*/
void Port::getNmapServiceName(char *namebuf, int buflen, const char *rpcinfo) const {
void Port::getNmapServiceName(char *namebuf, int buflen) const {
const char *tunnel_prefix;
const char *service_name;
int len;
@@ -195,15 +194,6 @@ void Port::getNmapServiceName(char *namebuf, int buflen, const char *rpcinfo) co
return;
}
if (rpcinfo != NULL && rpcinfo[0] != '\0') {
namebuf += len;
buflen -= len;
len = Snprintf(namebuf, buflen, " %s", rpcinfo);
if (len >= buflen || len < 0) {
namebuf[0] = '\0';
return;
}
}
}
serviceDeductions::serviceDeductions() {
@@ -218,10 +208,6 @@ serviceDeductions::serviceDeductions() {
service_tunnel = SERVICE_TUNNEL_NONE;
service_fp = NULL;
dtype = SERVICE_DETECTION_TABLE;
rpc_status = RPC_STATUS_UNTESTED;
rpc_program = 0;
rpc_lowver = 0;
rpc_highver = 0;
}
// Uses the sd->{product,version,extrainfo} if available to fill
@@ -415,50 +401,6 @@ void PortList::setServiceProbeResults(u16 portno, int protocol,
}
}
/* Sets the results of an RPC scan. if rpc_status is not
RPC_STATUS_GOOD_PROGRAM, pass 0 for the other args. This function
takes care of setting the port's service and version appropriately. */
void PortList::setRPCProbeResults(u16 portno, int proto, int rpcs, unsigned long rpcp,
unsigned int rpcl, unsigned int rpch) {
Port *port;
const char *newsvc;
char verbuf[128];
port = createPort(portno, proto);
if (port->service == NULL)
port->service = new serviceDeductions;
port->service->rpc_status = rpcs;
if (port->service->rpc_status == RPC_STATUS_GOOD_PROG) {
port->service->rpc_program = rpcp;
port->service->rpc_lowver = rpcl;
port->service->rpc_highver = rpch;
// Now set the service/version info
newsvc = nmap_getrpcnamebynum(rpcp);
if (!newsvc) newsvc = "rpc.unknownprog"; // should never happen
if (port->service->name)
free(port->service->name);
port->service->name = strdup(newsvc);
if (port->service->rpc_lowver == port->service->rpc_highver)
Snprintf(verbuf, sizeof(verbuf), "%i", port->service->rpc_lowver);
else
Snprintf(verbuf, sizeof(verbuf), "%i-%i", port->service->rpc_lowver, port->service->rpc_highver);
port->service->version = strdup(verbuf);
Snprintf(verbuf, sizeof(verbuf), "rpc #%li", port->service->rpc_program);
port->service->extrainfo = strdup(verbuf);
port->service->name_confidence = 10;
port->service->dtype = SERVICE_DETECTION_PROBED;
} else if (port->service->rpc_status == RPC_STATUS_UNKNOWN) {
if (port->service->name)
free(port->service->name);
port->service->name = strdup("rpc.unknown");
port->service->name_confidence = 8;
port->service->dtype = SERVICE_DETECTION_PROBED;
}
}
#ifndef NOLUA
void PortList::addScriptResult(u16 portno, int protocol, ScriptResult& sr) {

View File

@@ -163,16 +163,6 @@ struct serviceDeductions {
// if we should give the user a service fingerprint to submit, here it is. Otherwise NULL.
char *service_fp;
enum service_detection_type dtype; // definition above
int rpc_status; /* RPC_STATUS_UNTESTED means we haven't checked
RPC_STATUS_UNKNOWN means the port appears to be RPC
but we couldn't find a match
RPC_STATUS_GOOD_PROG means rpc_program gives the prog #
RPC_STATUS_NOT_RPC means the port doesn't appear to
be RPC */
unsigned long rpc_program; /* Only valid if rpc_state == RPC_STATUS_GOOD_PROG */
unsigned int rpc_lowver;
unsigned int rpc_highver;
};
class Port {
@@ -182,7 +172,7 @@ class Port {
Port();
void freeService(bool del_service);
void freeScriptResults(void);
void getNmapServiceName(char *namebuf, int buflen, const char *rpcinfo) const;
void getNmapServiceName(char *namebuf, int buflen) const;
u16 portno;
u8 proto;
@@ -194,9 +184,8 @@ class Port {
#endif
private:
/* This is allocated only on demand by PortList::setServiceProbeResults or
PortList::setRPCProbeResults, to save memory for the many closed or
filtered ports that don't need it. */
/* This is allocated only on demand by PortList::setServiceProbeResults
Pto save memory for the many closed or filtered ports that don't need it. */
serviceDeductions *service;
};
@@ -278,13 +267,6 @@ class PortList {
// the fields that are populated. Returns 0 if at least a name is available.
void getServiceDeductions(u16 portno, int protocol, struct serviceDeductions *sd) const;
/* Sets the results of an RPC scan. if rpc_status is not
RPC_STATUS_GOOD_PROGRAM, pass 0 for the other args. This function
takes care of setting the port's service and version
appropriately. */
void setRPCProbeResults(u16 portno, int proto, int rpc_status, unsigned long rpc_program,
unsigned int rpc_lowver, unsigned int rpc_highver);
#ifndef NOLUA
void addScriptResult(u16 portno, int protocol, ScriptResult& sr);
#endif