Skip to content

Commit

Permalink
merge soc07 r5085 - Changing bare printf()s to log_write(LOG_PLAIN,)s…
Browse files Browse the repository at this point in the history
… because these were always printed even when things like XML and greppable output were sent to stdout (e.g. -oX -). This also adds o.scriptTrace() to make --script-trace behave more like --packet-trace and --version-trace. Nsock tracing was done unconditionally in NSE, and that has been changed to only be done when o.scriptTrace() is true.
  • Loading branch information
fyodor committed Aug 11, 2007
1 parent 010c733 commit 8dc9673
Show file tree
Hide file tree
Showing 13 changed files with 160 additions and 154 deletions.
3 changes: 3 additions & 0 deletions NmapOps.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,9 @@ class NmapOps {
int sendpref;
bool packetTrace() { return (debugging >= 3)? true : pTrace; }
bool versionTrace() { return packetTrace()? true : vTrace; }
#ifndef NOLUA
bool scriptTrace() { return packetTrace()? true : scripttrace; }
#endif
// Note that packetTrace may turn on at high debug levels even if
// setPacketTrace(false) has been called
void setPacketTrace(bool pt) { pTrace = pt; }
Expand Down
14 changes: 7 additions & 7 deletions nmap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1446,13 +1446,13 @@ int nmap_main(int argc, char *argv[]) {

// At this point we should fully know our timing parameters
if (o.debugging) {
printf("--------------- Timing report ---------------\n");
printf(" hostgroups: min %d, max %d\n", o.minHostGroupSz(), o.maxHostGroupSz());
printf(" rtt-timeouts: init %d, min %d, max %d\n", o.initialRttTimeout(), o.minRttTimeout(), o.maxRttTimeout());
printf(" max-scan-delay: TCP %d, UDP %d\n", o.maxTCPScanDelay(), o.maxUDPScanDelay());
printf(" parallelism: min %d, max %d\n", o.min_parallelism, o.max_parallelism);
printf(" max-retries: %d, host-timeout: %ld\n", o.getMaxRetransmissions(), o.host_timeout);
printf("---------------------------------------------\n");
log_write(LOG_PLAIN, "--------------- Timing report ---------------\n");
log_write(LOG_PLAIN, " hostgroups: min %d, max %d\n", o.minHostGroupSz(), o.maxHostGroupSz());
log_write(LOG_PLAIN, " rtt-timeouts: init %d, min %d, max %d\n", o.initialRttTimeout(), o.minRttTimeout(), o.maxRttTimeout());
log_write(LOG_PLAIN, " max-scan-delay: TCP %d, UDP %d\n", o.maxTCPScanDelay(), o.maxUDPScanDelay());
log_write(LOG_PLAIN, " parallelism: min %d, max %d\n", o.min_parallelism, o.max_parallelism);
log_write(LOG_PLAIN, " max-retries: %d, host-timeout: %ld\n", o.getMaxRetransmissions(), o.host_timeout);
log_write(LOG_PLAIN, "---------------------------------------------\n");
}

/* Before we randomize the ports scanned, we must initialize PortList class. */
Expand Down
37 changes: 19 additions & 18 deletions nmap_rpc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ int send_rpc_query(const struct in_addr *target_host, unsigned short portno,
rpc_xid_base = (unsigned long) get_random_uint();

if (o.debugging > 1) {
printf("Sending RPC probe for program %li to %hu/%s -- scan_offset=%d trynum=%d xid=%lX\n", program, portno, proto2ascii(ipproto), scan_offset, trynum, rpc_xid_base + ((portno & 0x3FFF) << 16) + (trynum << 30) + scan_offset);
log_write(LOG_PLAIN, "Sending RPC probe for program %li to %hu/%s -- scan_offset=%d trynum=%d xid=%lX\n", program, portno, proto2ascii(ipproto), scan_offset, trynum, rpc_xid_base + ((portno & 0x3FFF) << 16) + (trynum << 30) + scan_offset);
}

/* First we check whether we have to create a new connection -- we
Expand Down Expand Up @@ -357,9 +357,9 @@ static int rpc_are_we_done(char *msg, int msg_len, Target *target,
/* This is not a valid reply -- we kill the port
(from an RPC perspective) */
if (o.debugging > 1) {
printf("Port %hu/%s labelled NON_RPC because of invalid sized message (%d)\n",
rsi->rpc_current_port->portno,
proto2ascii(rsi->rpc_current_port->proto, true), msg_len);
log_write(LOG_PLAIN, "Port %hu/%s labelled NON_RPC because of invalid sized message (%d)\n",
rsi->rpc_current_port->portno,
proto2ascii(rsi->rpc_current_port->proto, true), msg_len);
}
rsi->rpc_status = RPC_STATUS_NOT_RPC;
ss->numqueries_outstanding = 0;
Expand All @@ -372,7 +372,7 @@ static int rpc_are_we_done(char *msg, int msg_len, Target *target,
if (((scan_offset >> 16) & 0x3FFF) != (unsigned long) (rsi->rpc_current_port->portno & 0x3FFF)) {
/* Doh -- this doesn't seem right */
if (o.debugging > 1) {
printf("Port %hu/%s labelled NON_RPC because ((scan_offset >> 16) & 0x3FFF) is %li\n", rsi->rpc_current_port->portno, proto2ascii(rsi->rpc_current_port->proto, true), ((scan_offset >> 16) & 0x3FFF));
log_write(LOG_PLAIN, "Port %hu/%s labelled NON_RPC because ((scan_offset >> 16) & 0x3FFF) is %li\n", rsi->rpc_current_port->portno, proto2ascii(rsi->rpc_current_port->proto, true), ((scan_offset >> 16) & 0x3FFF));
}
rsi->rpc_status = RPC_STATUS_NOT_RPC;
ss->numqueries_outstanding = 0;
Expand Down Expand Up @@ -542,12 +542,12 @@ unsigned long current_msg_len;
return;
}
if (o.debugging > 1)
printf("Received %d byte UDP packet\n", res);
log_write(LOG_PLAIN, "Received %d byte UDP packet\n", res);
/* Now we check that the response is from the expected host/port */
if (from.sin_addr.s_addr != target->v4host().s_addr ||
from.sin_port != htons(rsi->rpc_current_port->portno)) {
if (o.debugging > 1) {
printf("Received UDP packet from %d.%d.%d.%d/%hu when expecting packet from %d.%d.%d.%d/%hu\n", NIPQUAD(from.sin_addr.s_addr), ntohs(from.sin_port), NIPQUAD(target->v4host().s_addr), rsi->rpc_current_port->portno);
log_write(LOG_PLAIN, "Received UDP packet from %d.%d.%d.%d/%hu when expecting packet from %d.%d.%d.%d/%hu\n", NIPQUAD(from.sin_addr.s_addr), ntohs(from.sin_port), NIPQUAD(target->v4host().s_addr), rsi->rpc_current_port->portno);
}
continue;
}
Expand Down Expand Up @@ -578,10 +578,10 @@ unsigned long current_msg_len;
/* This is suspiciously small -- I'm assuming this is not the first
part of a valid RPC packet */
if (o.debugging > 1) {
printf("Port %hu/%s labelled NON_RPC because tcp_readlen is %d (should be at least 28)\n",
rsi->rpc_current_port->portno,
proto2ascii(rsi->rpc_current_port->proto, true),
(int) tcp_readlen);
log_write(LOG_PLAIN, "Port %hu/%s labelled NON_RPC because tcp_readlen is %d (should be at least 28)\n",
rsi->rpc_current_port->portno,
proto2ascii(rsi->rpc_current_port->proto, true),
(int) tcp_readlen);
}
ss->numqueries_outstanding = 0;
rsi->rpc_status = RPC_STATUS_NOT_RPC;
Expand All @@ -592,9 +592,10 @@ unsigned long current_msg_len;

if (current_msg_len > tcp_readlen - 4) {
if (o.debugging > 1) {
printf("Port %hu/%s labelled NON_RPC because current_msg_len is %li while tcp_readlen is %d\n", rsi->rpc_current_port->portno,
proto2ascii(rsi->rpc_current_port->proto, true),
current_msg_len, (int) tcp_readlen);
log_write(LOG_PLAIN, "Port %hu/%s labelled NON_RPC because current_msg_len is %li while tcp_readlen is %d\n",
rsi->rpc_current_port->portno,
proto2ascii(rsi->rpc_current_port->proto, true),
current_msg_len, (int) tcp_readlen);
}
ss->numqueries_outstanding = 0;
rsi->rpc_status = RPC_STATUS_NOT_RPC;
Expand Down Expand Up @@ -622,10 +623,10 @@ unsigned long current_msg_len;
if (current_msg_len < 24 || current_msg_len > 32) {
ss->numqueries_outstanding = 0;
if (o.debugging > 1) {
printf("Port %hu/%s labelled NON_RPC because current_msg_len is %li\n",
rsi->rpc_current_port->portno,
proto2ascii(rsi->rpc_current_port->proto, true),
current_msg_len);
log_write(LOG_PLAIN, "Port %hu/%s labelled NON_RPC because current_msg_len is %li\n",
rsi->rpc_current_port->portno,
proto2ascii(rsi->rpc_current_port->proto, true),
current_msg_len);
}
rsi->rpc_status = RPC_STATUS_NOT_RPC;
return;
Expand Down
21 changes: 11 additions & 10 deletions nse_debug.cc
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
#include "nse_debug.h"
#include "output.h"

void l_dumpStack(lua_State* l) {
int stack_height = lua_gettop(l);
int i;

printf("-== Stack Dump Begin ==-\n");
log_write(LOG_PLAIN, "-== Stack Dump Begin ==-\n");
for(i = -1; i >= 0 - stack_height; i--) {
printf("%d: ", i);
log_write(LOG_PLAIN, "%d: ", i);
l_dumpValue(l, i);
}

printf("-== Stack Dump End ==-\n");
log_write(LOG_PLAIN, "-== Stack Dump End ==-\n");
}

void l_dumpValue(lua_State* l, int i) {
Expand All @@ -20,19 +21,19 @@ void l_dumpValue(lua_State* l, int i) {
l_dumpFunction(l, i);
else if(lua_isstring(l, i)) {
lua_pushvalue(l, i);
printf("string '%s'\n", lua_tostring(l, -1));
log_write(LOG_PLAIN, "string '%s'\n", lua_tostring(l, -1));
lua_pop(l, 1);
}
else if(lua_isboolean(l, i))
printf("boolean: %s", lua_toboolean(l, i) ? "true\n" : "false\n");
log_write(LOG_PLAIN, "boolean: %s", lua_toboolean(l, i) ? "true\n" : "false\n");
else if(lua_isnumber(l, i))
printf("number: %g\n", lua_tonumber(l, i));
log_write(LOG_PLAIN, "number: %g\n", lua_tonumber(l, i));
else
printf("%s\n", lua_typename(l, lua_type(l, i)));
log_write(LOG_PLAIN, "%s\n", lua_typename(l, lua_type(l, i)));
}

void l_dumpTable(lua_State *l, int index) {
printf("table\n");
log_write(LOG_PLAIN, "table\n");
lua_pushnil(l);

if (index<0) --index;
Expand All @@ -47,12 +48,12 @@ void l_dumpTable(lua_State *l, int index) {
void l_dumpFunction(lua_State* l, int index) {
// lua_Debug ar;

printf("function\n");
log_write(LOG_PLAIN, "function\n");

// lua_pushvalue(l, index);
// lua_getinfo(l, ">n", &ar);
//
// printf("\tname: %s %s\n", ar.namewhat, ar.name);
// log_write(LOG_PLAIN, "\tname: %s %s\n", ar.namewhat, ar.name);
fflush(stdout);
}

12 changes: 7 additions & 5 deletions nse_nsock.cc
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ int l_nsock_open(lua_State* l) {
auxiliar_newclass(l, "nsock", l_nsock);

nsp = nsp_new(NULL);
nsp_settrace(nsp, o.debugging, o.getStartTime());

if (o.scriptTrace())
nsp_settrace(nsp, 5, o.getStartTime());

return NSOCK_WRAPPER_SUCCESS;
}
Expand Down Expand Up @@ -183,7 +185,7 @@ static int l_nsock_connect(lua_State* l) {
void l_nsock_connect_handler(nsock_pool nsp, nsock_event nse, void *lua_state) {
lua_State* l = (lua_State*) lua_state;

if(o.scripttrace) {
if(o.scriptTrace()) {
l_nsock_trace(nse_iod(nse), "CONNECT", TO);
}

Expand All @@ -206,7 +208,7 @@ static int l_nsock_send(lua_State* l) {
return 2;
}

if(o.scripttrace) {
if(o.scriptTrace()) {
hexified = nse_hexify((const void*)string, string_len);
l_nsock_trace(udata->nsiod, hexified, TO);
free(hexified);
Expand Down Expand Up @@ -279,7 +281,7 @@ void l_nsock_receive_handler(nsock_pool nsp, nsock_event nse, void *lua_state) {
if(l_nsock_checkstatus(l, nse) == NSOCK_WRAPPER_SUCCESS) {
rcvd_string = nse_readbuf(nse, &rcvd_len);

if(o.scripttrace) {
if(o.scriptTrace()) {
hexified = nse_hexify((const void*) rcvd_string, (size_t) rcvd_len);
l_nsock_trace(nse_iod(nse), hexified, FROM);
free(hexified);
Expand Down Expand Up @@ -407,7 +409,7 @@ static int l_nsock_close(lua_State* l) {
return 2;
}

if(o.scripttrace) {
if(o.scriptTrace()) {
l_nsock_trace(udata->nsiod, "CLOSE", TO);
}

Expand Down
12 changes: 6 additions & 6 deletions osscan.cc
Original file line number Diff line number Diff line change
Expand Up @@ -910,7 +910,7 @@ static FingerPrint *get_fingerprint(Target *target, struct seq_info *si) {
}

if (o.debugging)
printf("The avg TCP TS HZ is: %f\n", avg_ts_hz);
log_write(LOG_PLAIN, "The avg TCP TS HZ is: %f\n", avg_ts_hz);

if (avg_ts_hz > 0 && avg_ts_hz < 3.9) { /* relatively wide range because sampling time so short and frequency so slow */
si->ts_seqclass = TS_SEQ_2HZ;
Expand Down Expand Up @@ -1164,11 +1164,11 @@ static int compareclassifications(FingerPrint *referenceFP,
}
} else {
if (verbose)
printf("Observed fingerprint lacks a classification\n");
log_write(LOG_PLAIN, "Observed fingerprint lacks a classification\n");
return 1;
}
if (verbose)
printf("[WARN] Classification of observed fingerprint does not appear in reference fingerprint.\n");
log_write(LOG_PLAIN, "[WARN] Classification of observed fingerprint does not appear in reference fingerprint.\n");
return 1;
}

Expand Down Expand Up @@ -1293,9 +1293,9 @@ static int AVal_match(struct AVal *reference, struct AVal *fprint, struct AVal *
return 0;
}
if (verbose)
printf("%s.%s: \"%s\" NOMATCH \"%s\" (%d %s)\n", testGroupName,
current_ref->attribute, current_fp->value,
current_ref->value, pointsThisTest, (pointsThisTest == 1)? "point" : "points");
log_write(LOG_PLAIN, "%s.%s: \"%s\" NOMATCH \"%s\" (%d %s)\n", testGroupName,
current_ref->attribute, current_fp->value,
current_ref->value, pointsThisTest, (pointsThisTest == 1)? "point" : "points");
} else subtests_succeeded += pointsThisTest;
/* Whew, we made it past one Attribute alive , on to the next! */
}
Expand Down
38 changes: 19 additions & 19 deletions osscan2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -782,7 +782,7 @@ list<OFProbe *>::iterator HostOsScanStats::getActiveProbe(OFProbeType type, int
if(probeI == probesActive.end()) {
/* not found!? */
if(o.debugging > 1)
printf("Probe doesn't exist! Probe type: %d. Probe subid: %d\n", type, subid);
log_write(LOG_PLAIN, "Probe doesn't exist! Probe type: %d. Probe subid: %d\n", type, subid);
return probesActive.end();
}

Expand Down Expand Up @@ -811,8 +811,8 @@ double HostOsScanStats::timingRatio() {
int msec_taken = TIMEVAL_MSEC_SUBTRACT(seq_send_times[NUM_SEQ_SAMPLES -1 ],
seq_send_times[0]);
if (o.debugging) {
printf("OS detection timingRatio() == (%.3f - %.3f) * 1000 / %d == %.3f\n",
seq_send_times[NUM_SEQ_SAMPLES - 1].tv_sec + seq_send_times[NUM_SEQ_SAMPLES - 1].tv_usec / 1000000.0, seq_send_times[0].tv_sec + (float) seq_send_times[0].tv_usec / 1000000.0, msec_ideal, (float) msec_taken / msec_ideal);
log_write(LOG_PLAIN, "OS detection timingRatio() == (%.3f - %.3f) * 1000 / %d == %.3f\n",
seq_send_times[NUM_SEQ_SAMPLES - 1].tv_sec + seq_send_times[NUM_SEQ_SAMPLES - 1].tv_usec / 1000000.0, seq_send_times[0].tv_sec + (float) seq_send_times[0].tv_usec / 1000000.0, msec_ideal, (float) msec_taken / msec_ideal);
}
return (double) msec_taken / msec_ideal;
}
Expand Down Expand Up @@ -1283,8 +1283,8 @@ void HostOsScan::sendNextProbe(HostOsScanStats *hss) {
hss->moveProbeToActiveList(probeI);

if (o.debugging > 1) {
printf("Send probe (type: %s, subid: %d) to %s\n",
probe->typestr(), probe->subid, hss->target->targetipstr());
log_write(LOG_PLAIN, "Send probe (type: %s, subid: %d) to %s\n",
probe->typestr(), probe->subid, hss->target->targetipstr());
}

}
Expand Down Expand Up @@ -1521,8 +1521,8 @@ bool HostOsScan::processResp(HostOsScanStats *hss, struct ip *ip, unsigned int l
adjust_times(hss, probe, rcvdtime);

if(o.debugging > 1)
printf("Got a valid response for probe (type: %s subid: %d) from %s\n",
probe->typestr(), probe->subid, hss->target->targetipstr());
log_write(LOG_PLAIN, "Got a valid response for probe (type: %s subid: %d) from %s\n",
probe->typestr(), probe->subid, hss->target->targetipstr());

/* delete the probe. */
hss->removeActiveProbe(probeI);
Expand Down Expand Up @@ -3290,7 +3290,7 @@ static void begin_sniffer(HostOsScan *HOS, vector<Target *> &Targets) {
fatal("ran out of space in pcap filter");
filterlen = len;

if (o.debugging > 2) printf("Pcap filter: %s\n", pcap_filter);
if (o.debugging > 2) log_write(LOG_PLAIN, "Pcap filter: %s\n", pcap_filter);
set_pcap_filter(Targets[0]->deviceName(), HOS->pd, pcap_filter);

return;
Expand Down Expand Up @@ -3347,7 +3347,7 @@ static void doSeqTests(OsScanInfo *OSI, HostOsScan *HOS) {
do {
if(timeToSleep > 0) {
if(o.debugging > 1) {
printf("Sleep %dus for next sequence probe\n", timeToSleep);
log_write(LOG_PLAIN, "Sleep %dus for next sequence probe\n", timeToSleep);
}
usleep(timeToSleep);
}
Expand All @@ -3359,9 +3359,9 @@ static void doSeqTests(OsScanInfo *OSI, HostOsScan *HOS) {
if(o.debugging > 2) {
for(hostI = OSI->incompleteHosts.begin(); hostI != OSI->incompleteHosts.end(); hostI++) {
hss = (*hostI)->hss;
printf("Host %s. ProbesToSend %d: \tProbesActive %d\n",
hss->target->targetipstr(), hss->numProbesToSend(),
hss->numProbesActive());
log_write(LOG_PLAIN, "Host %s. ProbesToSend %d: \tProbesActive %d\n",
hss->target->targetipstr(), hss->numProbesToSend(),
hss->numProbesActive());
}
}

Expand Down Expand Up @@ -3416,7 +3416,7 @@ static void doSeqTests(OsScanInfo *OSI, HostOsScan *HOS) {
if(to_usec < 2000) to_usec = 2000;

if(o.debugging > 2)
printf("pcap wait time is %ld.\n", to_usec);
log_write(LOG_PLAIN, "pcap wait time is %ld.\n", to_usec);

ip = (struct ip*) readip_pcap(HOS->pd, &bytes, to_usec, &rcvdtime, &linkhdr);

Expand Down Expand Up @@ -3514,7 +3514,7 @@ static void doTUITests(OsScanInfo *OSI, HostOsScan *HOS) {

if(timeToSleep > 0) {
if(o.debugging > 1) {
printf("Time to sleep %d. Sleeping. \n", timeToSleep);
log_write(LOG_PLAIN, "Time to sleep %d. Sleeping. \n", timeToSleep);
}

usleep(timeToSleep);
Expand All @@ -3528,9 +3528,9 @@ static void doTUITests(OsScanInfo *OSI, HostOsScan *HOS) {
for(hostI = OSI->incompleteHosts.begin();
hostI != OSI->incompleteHosts.end(); hostI++) {
hss = (*hostI)->hss;
printf("Host %s. ProbesToSend %d: \tProbesActive %d\n",
hss->target->targetipstr(), hss->numProbesToSend(),
hss->numProbesActive());
log_write(LOG_PLAIN, "Host %s. ProbesToSend %d: \tProbesActive %d\n",
hss->target->targetipstr(), hss->numProbesToSend(),
hss->numProbesActive());
}
}

Expand Down Expand Up @@ -3585,7 +3585,7 @@ static void doTUITests(OsScanInfo *OSI, HostOsScan *HOS) {
if(to_usec < 2000) to_usec = 2000;

if(o.debugging > 2)
printf("pcap wait time is %ld.\n", to_usec);
log_write(LOG_PLAIN, "pcap wait time is %ld.\n", to_usec);

ip = (struct ip*) readip_pcap(HOS->pd, &bytes, to_usec, &rcvdtime, &linkhdr);

Expand Down Expand Up @@ -3849,7 +3849,7 @@ static int os_scan_2(vector<Target *> &Targets) {
if (!plural) {
(*(OSI->incompleteHosts.begin()))->target->NameIP(targetstr, sizeof(targetstr));
} else snprintf(targetstr, sizeof(targetstr), "%d hosts", (int) OSI->numIncompleteHosts());
printf("%s OS detection (try #%d) against %s\n", (itry == 0)? "Initiating" : "Retrying", itry + 1, targetstr);
log_write(LOG_PLAIN, "%s OS detection (try #%d) against %s\n", (itry == 0)? "Initiating" : "Retrying", itry + 1, targetstr);
log_flush_all();
}
startRound(OSI, HOS, itry);
Expand Down
2 changes: 1 addition & 1 deletion portlist.cc
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ int PortList::addPort(u16 portno, u8 protocol, char *owner, int state) {
int PortList::removePort(u16 portno, u8 protocol) {
Port *answer = NULL;

printf("Removed %d\n", portno);
log_write(LOG_PLAIN, "Removed %d\n", portno);

answer = getPortEntry(portno, protocol);
if (!answer)
Expand Down
Loading

0 comments on commit 8dc9673

Please sign in to comment.