Skip to content

Commit

Permalink
Merge pull request #742 from robertdavidgraham/integration
Browse files Browse the repository at this point in the history
IVRE integration
  • Loading branch information
robertdavidgraham authored Nov 16, 2023
2 parents 9adf62a + 9cd6a29 commit b246710
Show file tree
Hide file tree
Showing 83 changed files with 4,711 additions and 2,543 deletions.
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
[![Masscan unittests](https://github.com/robertdavidgraham/masscan/actions/workflows/unittests.yml/badge.svg?branch=master)](https://github.com/robertdavidgraham/masscan/actions/workflows/unittests.yml/?branch=master)
[![Follow on Twitter](https://img.shields.io/twitter/follow/erratarob.svg?logo=twitter)](https://twitter.com/erratarob)
[![Follow on Mastodon](https://img.shields.io/mastodon/follow/109293216115833216?domain=https%3A%2F%2Finfosec.exchange&style=social)](https://infosec.exchange/@erratarob)
[![unittests](https://github.com/robertdavidgraham/masscan/actions/workflows/unittests.yml/badge.svg?branch=master)](https://github.com/robertdavidgraham/masscan/actions/workflows/unittests.yml/?branch=master)

# MASSCAN: Mass IP port scanner

Expand Down
14 changes: 13 additions & 1 deletion src/event-timeout.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
code and causing the bug to come back again.
*/
#include "event-timeout.h"
#include "logger.h"
#include "util-logger.h"
#include "util-malloc.h"
#include <stdint.h>
#include <stdlib.h>
Expand All @@ -48,6 +48,13 @@ struct Timeouts {
*/
uint64_t current_index;

/**
* Counts the number of outstanding timeouts. Adding a timeout increments
* this number, and removing a timeout decrements this number. The
* program shouldn't exit until this number is zero.
*/
uint64_t outstanding_count;

/**
* The number of slots is a power-of-2, so the mask is just this
* number minus 1
Expand Down Expand Up @@ -104,6 +111,8 @@ timeouts_add(struct Timeouts *timeouts, struct TimeoutEntry *entry,
unsigned index;

/* Unlink from wherever the entry came from */
if (entry->timestamp)
timeouts->outstanding_count--;
timeout_unlink(entry);

if (entry->prev) {
Expand All @@ -122,6 +131,8 @@ timeouts_add(struct Timeouts *timeouts, struct TimeoutEntry *entry,
entry->prev = &timeouts->slots[index];
if (entry->next)
entry->next->prev = &entry->next;

timeouts->outstanding_count++;
}

/***************************************************************************
Expand Down Expand Up @@ -155,6 +166,7 @@ timeouts_remove(struct Timeouts *timeouts, uint64_t timestamp)
}

/* unlink this entry from the timeout system */
timeouts--;
timeout_unlink(entry);

/* return a pointer to the structure holding this entry */
Expand Down
11 changes: 11 additions & 0 deletions src/event-timeout.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <stdint.h>
#include <stdio.h>
#include <stddef.h> /* offsetof*/
#include "util-bool.h" /* <stdbool.h> */
#if defined(_MSC_VER)
#undef inline
#define inline _inline
Expand Down Expand Up @@ -34,6 +35,16 @@ struct TimeoutEntry {
unsigned offset;
};

/***************************************************************************
***************************************************************************/
static inline bool
timeout_is_unlinked(const struct TimeoutEntry *entry) {
if (entry->prev == 0 || entry->next == 0)
return true;
else
return false;
}

/***************************************************************************
***************************************************************************/
static inline void
Expand Down
34 changes: 20 additions & 14 deletions src/in-binary.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "in-filter.h"
#include "in-report.h"
#include "util-malloc.h"
#include "util-logger.h"

#include <stdlib.h>
#include <assert.h>
Expand Down Expand Up @@ -485,17 +486,24 @@ _binaryfile_parse(struct Output *out, const char *filename,
goto end;
}

LOG(0, "[+] --readscan %s\n", filename);

if (feof(fp)) {
LOG(0, "[-] %s: file is empty\n", filename);
goto end;
}

/* first record is pseudo-record */
bytes_read = fread(buf, 1, 'a'+2, fp);
if (bytes_read < 'a'+2) {
perror(filename);
LOG(0, "[-] %s: %s\n", filename, strerror(errno));
goto end;
}

/* Make sure it's got the format string */
if (memcmp(buf, "masscan/1.1", 11) != 0) {
fprintf(stderr,
"%s: unknown file format (expeced \"masscan/1.1\")\n",
LOG(0,
"[-] %s: unknown file format (expeced \"masscan/1.1\")\n",
filename);
goto end;
}
Expand Down Expand Up @@ -557,7 +565,7 @@ _binaryfile_parse(struct Output *out, const char *filename,
length = (length << 7) | (buf[0] & 0x7F);
}
if (length > BUF_MAX) {
fprintf(stderr, "file corrupt\n");
LOG(0, "[-] file corrupt\n");
goto end;
}

Expand All @@ -582,7 +590,7 @@ _binaryfile_parse(struct Output *out, const char *filename,
break;
case 4:
if (fread(buf+bytes_read,1,1,fp) != 1) {
fprintf(stderr, "read() error\n");
LOG(0, "[-] read() error\n");
exit(1);
}
bytes_read++;
Expand Down Expand Up @@ -617,12 +625,12 @@ _binaryfile_parse(struct Output *out, const char *filename,
//goto end;
break;
default:
fprintf(stderr, "file corrupt: unknown type %u\n", type);
LOG(0, "[-] file corrupt: unknown type %u\n", type);
goto end;
}
total_records++;
if ((total_records & 0xFFFF) == 0)
fprintf(stderr, "%s: %8" PRIu64 "\r", filename, total_records);
LOG(0, "[+] %s: %8" PRIu64 "\r", filename, total_records);
}

end:
Expand All @@ -641,15 +649,15 @@ _binaryfile_parse(struct Output *out, const char *filename,
* other formats. This preserves the original timestamps.
*****************************************************************************/
void
read_binary_scanfile(struct Masscan *masscan,
readscan_binary_scanfile(struct Masscan *masscan,
int arg_first, int arg_max, char *argv[])
{
struct Output *out;
int i;

//readscan_report_init();


/*
* Create the output system, such as XML or JSON output
*/
out = output_create(masscan, 0);

/*
Expand All @@ -672,10 +680,8 @@ read_binary_scanfile(struct Masscan *masscan,
_binaryfile_parse(out, argv[i], &masscan->targets, &masscan->banner_types);
}

/* Done! */
output_destroy(out);

//readscan_report_print();

}


2 changes: 1 addition & 1 deletion src/in-binary.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ struct Masscan;
* JSON or XML.
*/
void
read_binary_scanfile(struct Masscan *masscan,
readscan_binary_scanfile(struct Masscan *masscan,
int arg_first, int arg_max, char *argv[]);

#endif
Expand Down
Loading

0 comments on commit b246710

Please sign in to comment.