Skip to content

Commit

Permalink
warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
robertdavidgraham committed Oct 29, 2013
1 parent 17a19cf commit 8d8956d
Show file tree
Hide file tree
Showing 53 changed files with 427 additions and 256 deletions.
5 changes: 3 additions & 2 deletions src/in-binary.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
translate the binary format into something more easily parsed, such
as the XML or JSON formats.
*/
#include "in-binary.h"
#include "masscan.h"
#include "masscan-app.h"
#include "main-globals.h"
Expand Down Expand Up @@ -92,7 +93,7 @@ parse_banner3(struct Output *out, unsigned char *buf, size_t buf_length)
* Parse the BANNER record, extracting the timestamp, IP addres, and port
* number. We also convert the banner string into a safer form.
***************************************************************************/
void
static void
parse_banner4(struct Output *out, unsigned char *buf, size_t buf_length)
{
struct MasscanRecord record;
Expand Down Expand Up @@ -123,7 +124,7 @@ parse_banner4(struct Output *out, unsigned char *buf, size_t buf_length)
/***************************************************************************
* Read in the file, one record at a time.
***************************************************************************/
uint64_t
static uint64_t
parse_file(struct Output *out, const char *filename)
{
FILE *fp = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/in-binary.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#ifndef IN_BINARY_H
#define IN_BINARY_H

struct Masscan;
void
convert_binary_files(struct Masscan *masscan, int arg_first, int arg_max, char *argv[]);

Expand Down
4 changes: 2 additions & 2 deletions src/logger.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ void LOG_add_level(int x)

/***************************************************************************
***************************************************************************/
void
static void
vLOG(int level, const char *fmt, va_list marker)
{
if (level <= global_debug_level) {
Expand All @@ -46,7 +46,7 @@ LOG(int level, const char *fmt, ...)

/***************************************************************************
***************************************************************************/
void
static void
vLOGip(int level, unsigned ip, unsigned port, const char *fmt, va_list marker)
{
if (level <= global_debug_level) {
Expand Down
73 changes: 45 additions & 28 deletions src/main-conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@

/***************************************************************************
***************************************************************************/
void masscan_usage(void)
void
masscan_usage(void)
{
printf("usage:\n");
printf("masscan -p80,8000-8100 10.0.0.0/8 --rate=10000\n");
Expand Down Expand Up @@ -172,7 +173,7 @@ masscan_echo_nic(struct Masscan *masscan, FILE *fp, unsigned i)
* Use#1: create a template file of all setable parameters.
* Use#2: make sure your configuration was interpreted correctly.
***************************************************************************/
void
static void
masscan_echo(struct Masscan *masscan, FILE *fp)
{
unsigned i;
Expand Down Expand Up @@ -316,9 +317,19 @@ masscan_save_state(struct Masscan *masscan)
}


/***************************************************************************
***************************************************************************/
void ranges_from_file(struct RangeList *ranges, const char *filename)
/*****************************************************************************
* Read in ranges from a file
*
* There can be multiple ranges on a line, delimited by spaces. In fact,
* millions of ranges can be on a line: there is limit to the line length.
* That makes reading the file a little bit squirrelly. From one perspective
* this parser doesn't treat the the new-line '\n' any different than other
* space. But, from another perspective, it has to, because things like
* comments are terminated by a newline. Also, it has to count the number
* of lines correctly to print error messages.
*****************************************************************************/
static void
ranges_from_file(struct RangeList *ranges, const char *filename)
{
FILE *fp;
errno_t err;
Expand All @@ -327,21 +338,19 @@ void ranges_from_file(struct RangeList *ranges, const char *filename)

err = fopen_s(&fp, filename, "rt");
if (err) {
//char dirname[256];
perror(filename);
//fprintf(stderr, "dir = %s\n", getcwd(dirname));
exit(1); /* HARD EXIT: because if it's an exclusion file, we don't
* want to continue. We don't want ANY chance of
* accidentally scanning somebody */
}

/* for all lines */
while (!feof(fp)) {
int c = '\n';

/* remove leading whitespace */
while (!feof(fp)) {
c = getc(fp);
line_number += (c == '\n');
if (!isspace(c&0xFF))
break;
}
Expand All @@ -350,37 +359,43 @@ void ranges_from_file(struct RangeList *ranges, const char *filename)
if (ispunct(c&0xFF)) {
while (!feof(fp)) {
c = getc(fp);
line_number += (c == '\n');
if (c == '\n') {
line_number++;
break;
}
}
/* Loop back to the begining state at the start of a line */
continue;
}

if (c == '\n') {
line_number++;
continue;
}

/*
* Read all space delimited entries
* Read in a single entry
*/
while (!feof(fp) && c != '\n') {
if (!feof(fp)) {
char address[64];
size_t i;
struct Range range;
unsigned offset = 0;


/* fetch next address range */
/* Grab all bytes until the next space or comma */
address[0] = (char)c;
i = 1;
while (!feof(fp)) {
c = getc(fp);
if (isspace(c&0xFF))
line_number += (c == '\n');
if (isspace(c&0xFF) || c == ',') {
break;
if (i+1 < sizeof(address))
}
if (i+1 >= sizeof(address)) {
LOG(0, "%s:%u:%u: bad address spec: \"%.*s\"\n",
filename, line_number, offset, i, address);
exit(1);
} else
address[i] = (char)c;
i++;
}
Expand All @@ -389,14 +404,14 @@ void ranges_from_file(struct RangeList *ranges, const char *filename)
/* parse the address range */
range = range_parse_ipv4(address, &offset, (unsigned)i);
if (range.begin == 0xFFFFFFFF && range.end == 0) {
fprintf(stderr, "%s:%u:%u: bad range spec: %s\n",
filename, line_number, offset, address);
LOG(0, "%s:%u:%u: bad range spec: \"%.*s\"\n",
filename, line_number, offset, i, address);
exit(1);
} else {
rangelist_add_range(ranges, range.begin, range.end);
}
}

line_number++;
}

fclose(fp);
Expand Down Expand Up @@ -582,7 +597,7 @@ ARRAY(const char *rhs)
* Called either from the "command-line" parser when it sees a --parm,
* or from the "config-file" parser for normal options.
***************************************************************************/
void
static void
masscan_set_parameter(struct Masscan *masscan,
const char *name, const char *value)
{
Expand Down Expand Up @@ -821,7 +836,7 @@ masscan_set_parameter(struct Masscan *masscan,
range = range_parse_ipv4(ranges, &offset, max_offset);
if (range.begin == 0 && range.end == 0) {
fprintf(stderr, "CONF: bad range spec: %s\n", ranges);
break;
exit(1);
}

rangelist_add_range(&masscan->exclude_ip, range.begin, range.end);
Expand Down Expand Up @@ -887,7 +902,7 @@ masscan_set_parameter(struct Masscan *masscan,
masscan->http_user_agent_length+1
);
} else if (memcmp("http-header", name, 11) == 0) {
unsigned index;
unsigned j;
unsigned name_length;
char *newname;
unsigned value_length = (unsigned)strlen(value);
Expand All @@ -910,11 +925,11 @@ masscan_set_parameter(struct Masscan *masscan,
newname[name_length] = '\0';


for (index=0; index < sizeof(masscan->http_headers)/sizeof(masscan->http_headers[0]); index++) {
if (masscan->http_headers[index].header_name == 0) {
masscan->http_headers[index].header_name = newname;
masscan->http_headers[index].header_value = newvalue;
masscan->http_headers[index].header_value_length = value_length;
for (j=0; j < sizeof(masscan->http_headers)/sizeof(masscan->http_headers[0]); j++) {
if (masscan->http_headers[j].header_name == 0) {
masscan->http_headers[j].header_name = newname;
masscan->http_headers[j].header_value = newvalue;
masscan->http_headers[j].header_value_length = value_length;
return;
}
}
Expand Down Expand Up @@ -1203,7 +1218,9 @@ is_singleton(const char *name)
return 0;
}

void
/*****************************************************************************
*****************************************************************************/
static void
masscan_help()
{
printf(
Expand Down Expand Up @@ -1663,4 +1680,4 @@ mainconf_selftest()
}

return 0;
}
}
7 changes: 5 additions & 2 deletions src/main-dedup.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
We can mimimize this with a table remembering recent responses. Occassional
duplicates still leak through, but it'll be less of a problem.
*/
#include "main-dedup.h"
#include <stdlib.h>
#include <string.h>

Expand All @@ -29,7 +30,7 @@ struct DedupTable
/***************************************************************************
***************************************************************************/
struct DedupTable *
dedup_create()
dedup_create(void)
{
struct DedupTable *result;

Expand All @@ -53,7 +54,9 @@ dedup_destroy(struct DedupTable *table)
/***************************************************************************
***************************************************************************/
unsigned
dedup_is_duplicate(struct DedupTable *dedup, unsigned ip_them, unsigned port_them, unsigned ip_me, unsigned port_me)
dedup_is_duplicate(struct DedupTable *dedup,
unsigned ip_them, unsigned port_them,
unsigned ip_me, unsigned port_me)
{
unsigned hash;
struct DedupEntry *bucket;
Expand Down
13 changes: 10 additions & 3 deletions src/main-dedup.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
#ifndef MAIN_DEDUP_H
#define MAIN_DEDUP_H

struct DedupTable *dedup_create();
void dedup_destroy(struct DedupTable *table);
unsigned dedup_is_duplicate(struct DedupTable *dedup, unsigned ip, unsigned port);
struct DedupTable *
dedup_create(void);

void
dedup_destroy(struct DedupTable *table);

unsigned
dedup_is_duplicate( struct DedupTable *dedup,
unsigned ip_them, unsigned port_them,
unsigned ip_me, unsigned port_me);


#endif
2 changes: 1 addition & 1 deletion src/main-listscan.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,4 @@ main_listscan(struct Masscan *masscan)
seed++;
goto infinite;
}
}
}
32 changes: 13 additions & 19 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
#include "in-binary.h" /* covert binary output to XML/JSON */
#include "main-globals.h" /* all the global variables in the program */
#include "proto-zeroaccess.h"
#include "siphash24.h"

#include <assert.h>
#include <limits.h>
Expand Down Expand Up @@ -158,7 +159,7 @@ struct ThreadPair {
* than individually. It increases latency, but increases performance. We
* don't really care about latency.
***************************************************************************/
void
static void
flush_packets(struct Adapter *adapter,
PACKET_QUEUE *packet_buffers,
PACKET_QUEUE *transmit_queue,
Expand Down Expand Up @@ -365,11 +366,11 @@ transmit_thread(void *v) /*aka. scanning_thread() */
* Figure out the source IP/port, and the SYN cookie
*/
if (src_ip_mask > 1 || src_port_mask > 1) {
uint64_t r = syn_cookie((unsigned)(i+repeats),
uint64_t ck = syn_cookie((unsigned)(i+repeats),
(unsigned)((i+repeats)>>32),
(unsigned)xXx, (unsigned)(xXx>>32));
port_me = src_port + (r & src_port_mask);
ip_me = src_ip + ((r>>16) & src_ip_mask);
port_me = src_port + (ck & src_port_mask);
ip_me = src_ip + ((ck>>16) & src_ip_mask);
} else {
ip_me = src_ip;
port_me = src_port;
Expand Down Expand Up @@ -470,17 +471,9 @@ transmit_thread(void *v) /*aka. scanning_thread() */
}


/*unsigned
is_nic_ip(const struct Masscan *masscan, unsigned ip)
{
unsigned i;
for (i=0; i<masscan->nic_count; i++)
if (is_my_ip(&masscan->nic[i].src, ip))
return 1;
return 0;
}
*/
unsigned
/***************************************************************************
***************************************************************************/
static unsigned
is_nic_port(const struct Masscan *masscan, unsigned ip)
{
unsigned i;
Expand Down Expand Up @@ -688,7 +681,7 @@ receive_thread(void *v)
break;

/* Ignore duplicates */
if (dedup_is_duplicate(dedup, ip_them, 0))
if (dedup_is_duplicate(dedup, ip_them, 0, ip_me, 0))
continue;

/* ...everything good, so now report this response */
Expand Down Expand Up @@ -830,7 +823,7 @@ receive_thread(void *v)
}

/* verify: ignore duplicates */
if (dedup_is_duplicate(dedup, ip_them, port_them))
if (dedup_is_duplicate(dedup, ip_them, port_them, ip_me, port_me))
continue;
total_synacks++;

Expand Down Expand Up @@ -1115,9 +1108,9 @@ main_scan(struct Masscan *masscan)
*/
{
char buffer[80];
time_t now = time(0);
struct tm x;

now = time(0);
gmtime_s(&x, &now);
strftime(buffer, sizeof(buffer), "%Y-%m-%d %H:%M:%S GMT", &x);
LOG(0, "\nStarting masscan 1.0 (http://bit.ly/14GZzcT) at %s\n", buffer);
Expand Down Expand Up @@ -1378,11 +1371,12 @@ int main(int argc, char *argv[])
*/
{
int x = 0;
x += siphash24_selftest();
x += snmp_selftest();
x += payloads_selftest();
x += blackrock_selftest();
x += rawsock_selftest();
x += randlcg_selftest();
x += lcg_selftest();
x += template_selftest();
x += ranges_selftest();
x += pixie_time_selftest();
Expand Down
Loading

0 comments on commit 8d8956d

Please sign in to comment.