Skip to content

Commit

Permalink
range-file - reading IP addresses from file
Browse files Browse the repository at this point in the history
  • Loading branch information
robertdavidgraham committed May 22, 2019
1 parent 6e119b0 commit 19e9adf
Show file tree
Hide file tree
Showing 10 changed files with 283 additions and 32 deletions.
27 changes: 23 additions & 4 deletions src/main-conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "masscan.h"
#include "masscan-version.h"
#include "ranges.h"
#include "range-file.h" /* reads millions of IP addresss from a file */
#include "string_s.h"
#include "logger.h"
#include "proto-banner1.h"
Expand Down Expand Up @@ -326,7 +327,7 @@ masscan_save_state(struct Masscan *masscan)
}



#if 0
/*****************************************************************************
* Read in ranges from a file
*
Expand Down Expand Up @@ -430,6 +431,7 @@ ranges_from_file(struct RangeList *ranges, const char *filename)
* before it can be used */
rangelist_sort(ranges);
}
#endif

/***************************************************************************
***************************************************************************/
Expand Down Expand Up @@ -1940,11 +1942,21 @@ masscan_set_parameter(struct Masscan *masscan,
} else if (EQUALS("excludefile", name)) {
unsigned count1 = masscan->exclude_ip.count;
unsigned count2;
int err;
const char *filename = value;

LOG(1, "EXCLUDING: %s\n", value);
ranges_from_file(&masscan->exclude_ip, value);
err = rangefile_read(filename, &masscan->exclude_ip, &masscan->exclude_ipv6);
if (err) {
LOG(0, "FAIL: error reading from exclude file\n");
exit(1);
}

/* Detect if this file has made any change, otherwise don't print
* a message */
count2 = masscan->exclude_ip.count;
if (count2 - count1)
fprintf(stderr, "%s: excluding %u ranges from file\n",
fprintf(stderr, "%s: excluding %u ranges from file\n",
value, count2 - count1);
} else if (EQUALS("heartbleed", name)) {
masscan->is_heartbleed = 1;
Expand Down Expand Up @@ -2004,7 +2016,14 @@ masscan_set_parameter(struct Masscan *masscan,
} else if (EQUALS("iflist", name)) {
masscan->op = Operation_List_Adapters;
} else if (EQUALS("includefile", name)) {
ranges_from_file(&masscan->targets, value);
int err;
const char *filename = value;

err = rangefile_read(filename, &masscan->targets, &masscan->targets_ipv6);
if (err) {
LOG(0, "FAIL: error reading from include file\n");
exit(1);
}
if (masscan->op == 0)
masscan->op = Operation_Scan;
} else if (EQUALS("infinite", name)) {
Expand Down
2 changes: 2 additions & 0 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
#include "vulncheck.h" /* checking vulns like monlist, poodle, heartblee */
#include "main-readrange.h"
#include "scripting.h"
#include "range-file.h" /* reading ranges from a file */
#include "read-service-probes.h"
#include "util-malloc.h"

Expand Down Expand Up @@ -1686,6 +1687,7 @@ int main(int argc, char *argv[])
x += lcg_selftest();
x += template_selftest();
x += ranges_selftest();
x += rangefile_selftest();
x += pixie_time_selftest();
x += rte_ring_selftest();
x += mainconf_selftest();
Expand Down
3 changes: 3 additions & 0 deletions src/masscan.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <time.h>

#include "ranges.h"
#include "ranges6.h"
#include "packet-queue.h"

struct Adapter;
Expand Down Expand Up @@ -141,6 +142,7 @@ struct Masscan
* and such, and sort the target ranges.
*/
struct RangeList targets;
struct Range6List targets_ipv6;

/**
* The ports we are scanning for. The user can specify repeated ports
Expand All @@ -166,6 +168,7 @@ struct Masscan
*/
struct RangeList exclude_ip;
struct RangeList exclude_port;
struct Range6List exclude_ipv6;


/**
Expand Down
1 change: 1 addition & 0 deletions src/proto-oproto.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "proto-oproto.h"
#include "unusedparm.h"

void
handle_oproto(struct Output *out, time_t timestamp,
Expand Down
4 changes: 2 additions & 2 deletions src/proto-tcp-rdp.c
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ cotp_parse(struct BannerOutput *banout, struct RDPSTUFF *rdp, const unsigned cha
* by 1. */
assert(bytes_parsed != 0);
offset += bytes_parsed - 1;
rdp->cotp.len -= bytes_parsed;
rdp->cotp.len -= (unsigned char)bytes_parsed;

/* If we have bytes left in the TPKT, then stay in this state,
* otherwise transition to the next TPKT */
Expand Down Expand Up @@ -267,7 +267,7 @@ rdp_parse( const struct Banner1 *banner1,
* by 1. */
assert(bytes_parsed != 0);
offset += bytes_parsed - 1;
rdp->tpkt_length -= bytes_parsed;
rdp->tpkt_length -= (unsigned short)bytes_parsed;

/* If we have bytes left in the TPKT, then stay in this state,
* otherwise transition to the next TPKT */
Expand Down
Loading

0 comments on commit 19e9adf

Please sign in to comment.