Skip to content

Commit

Permalink
xml output
Browse files Browse the repository at this point in the history
  • Loading branch information
robertdavidgraham committed Aug 21, 2013
1 parent 2ab807c commit e8b1e93
Show file tree
Hide file tree
Showing 15 changed files with 1,246 additions and 535 deletions.
20 changes: 18 additions & 2 deletions src/logger.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
/*
log messages to console, depending on verbose level
Use -v (or -d) to get more verbose output. The more -v you add, the
more verbose the output becomes.
Details about the running of the program go to <stderr>.
Details about scan results go to <stdout>, so that they can easily
be redirected to a file.
*/
#include "logger.h"

Expand All @@ -8,15 +15,24 @@

int verbosity = 0; /* yea! a global variable!! */

void vLOG(int level, const char *fmt, va_list marker)

/***************************************************************************
***************************************************************************/
void
vLOG(int level, const char *fmt, va_list marker)
{
if (level <= verbosity) {
vfprintf(stderr, fmt, marker);
fflush(stderr);
}
}

void LOG(int level, const char *fmt, ...)

/***************************************************************************
* Prints the message if the global "verbosity" flag exceeds this level.
***************************************************************************/
void
LOG(int level, const char *fmt, ...)
{
va_list marker;

Expand Down
2 changes: 1 addition & 1 deletion src/logger.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#ifndef LOGGER_H
#define LOGGER_H

extern int verbosity; /* defined in logger.c */

void LOG(int level, const char *fmt, ...);


#endif
94 changes: 87 additions & 7 deletions src/main-conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,11 @@
#include "masscan.h"
#include "ranges.h"
#include "string_s.h"
#include "logger.h"

#include <ctype.h>


extern int verbosity; /* logger.c */

/***************************************************************************
***************************************************************************/
void masscan_usage(void)
Expand Down Expand Up @@ -101,7 +100,7 @@ masscan_echo(struct Masscan *masscan, FILE *fp)
fprintf(fp, "randomize-hosts = true\n");


fprintf(fp, "\n# adapter settings\n");
fprintf(fp, "# ADAPTER SETTINGS\n");
fprintf(fp, "adapter = %s\n", masscan->ifname);
fprintf(fp, "adapter-ip = %u.%u.%u.%u\n",
(masscan->adapter_ip>>24)&0xFF,
Expand All @@ -127,7 +126,7 @@ masscan_echo(struct Masscan *masscan, FILE *fp)
/*
* Output information
*/
fprintf(fp, "# output\n");
fprintf(fp, "# OUTPUT/REPORTING SETTINGS\n");
switch (masscan->nmap.format) {
case Output_Interactive:
fprintf(fp, "output-format = interactive\n");
Expand All @@ -142,12 +141,15 @@ masscan_echo(struct Masscan *masscan, FILE *fp)
fprintf(fp, "output-filename = %s\n", masscan->nmap.filename);
if (masscan->nmap.append)
fprintf(fp, "output-append = true\n");
fprintf(fp, "rotate = %u\n", masscan->rotate_output);
fprintf(fp, "rotate-dir = %s\n", masscan->rotate_directory);
fprintf(fp, "rotate-offset = %u\n", masscan->rotate_offset);


/*
* Targets
*/
fprintf(fp, "\n# targets\n");
fprintf(fp, "# TARGET SELECTION (IP, PORTS, EXCLUDES)\n");
fprintf(fp, "ports = ");
for (i=0; i<masscan->ports.count; i++) {
struct Range range = masscan->ports.list[i];
Expand Down Expand Up @@ -658,6 +660,86 @@ masscan_set_parameter(struct Masscan *masscan, const char *name, const char *val
} else {
masscan->retries = x;
}
} else if (EQUALS("rotate-output", name) || EQUALS("rotate", name) || EQUALS("ouput-rotate", name)) {
switch (tolower(value[0])) {
case 's':
masscan->rotate_output = 1;
return;
case 'm':
masscan->rotate_output = 60;
return;
case 'h':
masscan->rotate_output = 60*60;
return;
case 'd':
masscan->rotate_output = 24*60*60;
return;
case 'w':
masscan->rotate_output = 24*60*60*7;
return;
default:
if (isdigit(value[0]&0xFF)) {
masscan->rotate_output = strtoul(value, 0, 0);
return;
}
}
fprintf(stderr, "--rotate: unknown value (epected 'minute', 'hour', 'day', 'week')\n");
exit(1);
} else if (EQUALS("rotate-offset", name) || EQUALS("ouput-rotate-offset", name)) {
uint64_t num = 0;
unsigned is_negative = 0;
while (*value == '-') {
is_negative = 1;
value++;
}
while (isdigit(value[0]&0xFF)) {
num = num*10 + (value[0] - '0');
value++;
}
while (ispunct(value[0]) || isspace(value[0]))
value++;

if (isalpha(value[0]) && num == 0)
num = 1;

switch (tolower(value[0])) {
case 's':
num *= 1;
break;
case 'm':
num *= 60;
break;
case 'h':
num *= 60*60;
break;
case 'd':
num *= 24*60*60;
break;
case 'w':
num *= 24*60*60*7;
break;
default:
fprintf(stderr, "--rotate-offset: unknown character\n");
exit(1);
}
if (num >= 24*60*60) {
fprintf(stderr, "--rotate-offset: value is greater than 1 day\n");
exit(1);
}
if (is_negative)
num = 24*60*60 - num;

masscan->rotate_offset = (unsigned)num;
} else if (EQUALS("rotate-dir", name) || EQUALS("rotate-directory", name) || EQUALS("ouput-rotate-dir", name)) {
char *p;
strcpy_s( masscan->rotate_directory,
sizeof(masscan->rotate_directory),
value);

/* strip trailing slashes */
p = masscan->rotate_directory;
while (*p && (p[strlen(p)-1] == '/' || p[strlen(p)-1] == '/'))
p[strlen(p)-1] = '\0';
} else if (EQUALS("script", name)) {
fprintf(stderr, "nmap(%s): unsupported, it's too complex for this simple scanner\n", name);
exit(1);
Expand Down Expand Up @@ -893,8 +975,6 @@ masscan_command_line(struct Masscan *masscan, int argc, char *argv[])
break;
case 'X':
masscan->nmap.format = Output_XML;
fprintf(stderr, "nmap(%s): unsupported output format\n", argv[i]);
exit(1);
break;
case 'S':
masscan->nmap.format = Output_ScriptKiddie;
Expand Down
20 changes: 16 additions & 4 deletions src/main-dedup.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include <stdlib.h>
#include <string.h>

#define DEDUP_ENTRIES 1024
#define DEDUP_ENTRIES 4096

struct DedupEntry
{
Expand Down Expand Up @@ -55,17 +55,29 @@ dedup_is_duplicate(struct DedupTable *dedup, unsigned ip, unsigned port)
struct DedupEntry *bucket;
unsigned i;

/* THREAT: We've already validated resonses via SYN-cookies, so
* therefore we don't need a robust hash for duplicate detection */
/* THREAT: probably need to secure this hash, though the syn-cookies
* provides some protection */
hash = (ip + port) ^ ((ip>>8) + (ip>>16)) ^ (ip>>24);
hash &= DEDUP_ENTRIES-1;

/* Search in this bucket */
bucket = dedup->entries[hash];

for (i = 0; i < 4; i++) {
if (bucket[i].ip == ip && bucket[i].port == port)
if (bucket[i].ip == ip && bucket[i].port == port) {
/* move to end of list so constant repeats get ignored */
if (i > 0) {
bucket[i].ip ^= bucket[0].ip;
bucket[i].port ^= bucket[0].port;

bucket[0].ip ^= bucket[i].ip;
bucket[0].port ^= bucket[i].port;

bucket[i].ip ^= bucket[0].ip;
bucket[i].port ^= bucket[0].port;
}
return 1;
}
}

/* We didn't find it, so add it to our list. This will push
Expand Down
Loading

0 comments on commit e8b1e93

Please sign in to comment.