Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Made masscan compatible to C++ compilers #585

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/compiler_abs_layer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#pragma once
#ifndef COMPILER_ABS_LAYER_H
#define COMPILER_ABS_LAYER_H

#if defined(__cplusplus) && __cplusplus >= 201703L
#define REGISTER
#else
#define REGISTER register
#endif

#endif // COMPILER_ABS_LAYER_H
10 changes: 5 additions & 5 deletions src/crypto-blackrock2.c
Original file line number Diff line number Diff line change
Expand Up @@ -285,13 +285,13 @@ blackrock2_init(struct BlackRock *br, uint64_t range, uint64_t seed, unsigned ro

/***************************************************************************
* The inner round/mixer function. In DES, it's a series of S-box lookups,
* which
* which
***************************************************************************/
static inline uint64_t
ROUND(uint64_t r, uint64_t R, uint64_t seed)
{
#define GETBYTE(R,n) ((uint64_t)(((((R)>>(n*8ULL)))&0xFFULL)))
#if 0
#if 0
uint64_t r0, r1, r2, r3;
#endif
uint64_t T, Y;
Expand All @@ -308,7 +308,7 @@ ROUND(uint64_t r, uint64_t R, uint64_t seed)
Y = SB7[ (T ) & 0x3F ] ^ \
SB5[ (T >> 8) & 0x3F ] ^ \
SB3[ (T >> 16) & 0x3F ] ^ \
SB1[ (T >> 24) & 0x3F ];
SB1[ (T >> 24) & 0x3F ];
}
return Y;
#if 0
Expand Down Expand Up @@ -451,8 +451,8 @@ verify(struct BlackRock *br, uint64_t max)
uint64_t range = br->range;

/* Allocate a list of 1-byte counters */
list = CALLOC(1, (size_t)((range<max)?range:max));
list = (unsigned char *) CALLOC(1, (size_t)((range<max)?range:max));

/* For all numbers in the range, verify increment the counter for the
* the output. */
for (i=0; i<range; i++) {
Expand Down
8 changes: 4 additions & 4 deletions src/event-timeout.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@


/***************************************************************************
* The timeout system is a circular ring. We move an index around the
* The timeout system is a circular ring. We move an index around the
* ring. At each slot in the ring is a linked-list of all entries at
* that time index. Because the ring can wrap, not everything at a given
* entry will be the same timestamp. Therefore, when doing the timeout
Expand Down Expand Up @@ -70,8 +70,8 @@ timeouts_create(uint64_t timestamp)
/*
* Allocate memory and initialize it to zero
*/
timeouts = CALLOC(1, sizeof(*timeouts));
timeouts = (struct Timeouts *) CALLOC(1, sizeof(*timeouts));

/*
* We just mask off the low order bits to determine wrap. I'm using
* a variable here because one of these days I'm going to make
Expand Down Expand Up @@ -107,7 +107,7 @@ timeouts_add(struct Timeouts *timeouts, struct TimeoutEntry *entry,
timeout_unlink(entry);

if (entry->prev) {
LOG(1, "***CHANGE %d-seconds\n",
LOG(1, "***CHANGE %d-seconds\n",
(int)((timestamp-entry->timestamp)/TICKS_PER_SECOND));
}

Expand Down
30 changes: 15 additions & 15 deletions src/in-binary.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ parse_status(struct Output *out,
case 53:
case 123:
case 137:
case 161:
case 161:
record.ip_proto = 17;
break;
case 36422:
Expand Down Expand Up @@ -166,7 +166,7 @@ _get_integer(const unsigned char *buf, size_t length, size_t *r_offset)
unsigned result;
size_t offset = *r_offset;
(*r_offset) += 4;

if (offset + 4 <= length) {
result = buf[offset+0]<<24
| buf[offset+1]<<16
Expand All @@ -183,7 +183,7 @@ _get_short(const unsigned char *buf, size_t length, size_t *r_offset)
unsigned short result;
size_t offset = *r_offset;
(*r_offset) += 2;

if (offset + 2 <= length) {
result = buf[offset+0]<<8
| buf[offset+1]<<0;
Expand All @@ -199,7 +199,7 @@ _get_long(const unsigned char *buf, size_t length, size_t *r_offset)
unsigned long long result;
size_t offset = *r_offset;
(*r_offset) += 8;

if (offset + 8 <= length) {
result =
(unsigned long long)buf[offset+0]<<56ULL
Expand Down Expand Up @@ -286,7 +286,7 @@ parse_banner6(struct Output *out, unsigned char *buf, size_t length,
record.timestamp = _get_integer(buf, length, &offset);
record.ip_proto = _get_byte(buf, length, &offset);
record.port = _get_short(buf, length, &offset);
record.app_proto = _get_short(buf, length, &offset);
record.app_proto = (enum ApplicationProtocol) _get_short(buf, length, &offset);
record.ttl = _get_byte(buf, length, &offset);
record.ip.version= _get_byte(buf, length, &offset);
if (record.ip.version != 6) {
Expand All @@ -295,18 +295,18 @@ parse_banner6(struct Output *out, unsigned char *buf, size_t length,
}
record.ip.ipv6.hi = _get_long(buf, length, &offset);
record.ip.ipv6.lo = _get_long(buf, length, &offset);

if (out->when_scan_started == 0)
out->when_scan_started = record.timestamp;


/*
* Filter out records if requested
*/
if (!readscan_filter_pass(record.ip, record.port, record.app_proto,
filter, btypes))
return;

/*
* Now print the output
*/
Expand Down Expand Up @@ -343,7 +343,7 @@ parse_banner3(struct Output *out, unsigned char *buf, size_t buf_length)
record.ip.ipv4 = buf[4]<<24 | buf[5]<<16 | buf[6]<<8 | buf[7];
record.ip.version = 4;
record.port = buf[8]<<8 | buf[9];
record.app_proto = buf[10]<<8 | buf[11];
record.app_proto = (enum ApplicationProtocol) (buf[10]<<8 | buf[11]);

if (out->when_scan_started == 0)
out->when_scan_started = record.timestamp;
Expand Down Expand Up @@ -383,7 +383,7 @@ parse_banner4(struct Output *out, unsigned char *buf, size_t buf_length)
record.ip.version = 4;
record.ip_proto = buf[8];
record.port = buf[9]<<8 | buf[10];
record.app_proto = buf[11]<<8 | buf[12];
record.app_proto = (enum ApplicationProtocol) (buf[11]<<8 | buf[12]);

if (out->when_scan_started == 0)
out->when_scan_started = record.timestamp;
Expand Down Expand Up @@ -426,7 +426,7 @@ parse_banner9(struct Output *out, unsigned char *buf, size_t buf_length,
record.ip.version = 4;
record.ip_proto = buf[8];
record.port = buf[9]<<8 | buf[10];
record.app_proto = buf[11]<<8 | buf[12];
record.app_proto = (enum ApplicationProtocol) (buf[11]<<8 | buf[12]);
record.ttl = buf[13];

if (out->when_scan_started == 0)
Expand All @@ -445,7 +445,7 @@ parse_banner9(struct Output *out, unsigned char *buf, size_t buf_length,
if (!readscan_filter_pass(record.ip, record.port, record.app_proto,
filter, btypes))
return;

/*
* Now print the output
*/
Expand Down Expand Up @@ -476,7 +476,7 @@ _binaryfile_parse(struct Output *out, const char *filename,
int x;

/* Allocate a buffer of up to one megabyte per record */
buf = MALLOC(BUF_MAX);
buf = (unsigned char *) MALLOC(BUF_MAX);

/* Open the file */
x = fopen_s(&fp, filename, "rb");
Expand Down Expand Up @@ -642,7 +642,7 @@ _binaryfile_parse(struct Output *out, const char *filename,
*****************************************************************************/
void
read_binary_scanfile(struct Masscan *masscan,
int arg_first, int arg_max, char *argv[])
int arg_first, int arg_max, const char *argv[])
{
struct Output *out;
int i;
Expand All @@ -651,7 +651,7 @@ read_binary_scanfile(struct Masscan *masscan,


out = output_create(masscan, 0);

/*
* Set the start time to zero. We'll read it from the first file
* that we parse
Expand Down
4 changes: 2 additions & 2 deletions src/in-binary.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ struct Masscan;
* JSON or XML.
*/
void
read_binary_scanfile(struct Masscan *masscan,
int arg_first, int arg_max, char *argv[]);
read_binary_scanfile(struct Masscan *masscan,
int arg_first, int arg_max, const char *argv[]);

#endif

54 changes: 27 additions & 27 deletions src/in-report.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ static const char *
cndb_lookup(unsigned ip)
{
const struct CNDB_Entry *entry;

if (db == NULL)
return 0;

Expand All @@ -53,14 +53,14 @@ cndb_add(unsigned ip, const unsigned char *name, size_t name_length)

if (name_length == 0)
return;

if (db == NULL) {
db = CALLOC(1, sizeof(*db));
db = (struct CNDB_Database *) CALLOC(1, sizeof(*db));
}
entry = MALLOC(sizeof(*entry));

entry = (struct CNDB_Entry *) MALLOC(sizeof(*entry));
entry->ip =ip;
entry->name = MALLOC(name_length+1);
entry->name = (char *) MALLOC(name_length+1);
memcpy(entry->name, name, name_length+1);
entry->name[name_length] = '\0';
entry->next = db->entries[ip&0xFFFF];
Expand All @@ -77,15 +77,15 @@ cndb_add_cn(unsigned ip, const unsigned char *data, size_t length)
size_t offset = 0;
size_t name_offset;
size_t name_length;

if (length < 7)
return;

/*cipher:0x39 , safe-we1.dyndns.org*/
if (memcmp(data+offset, "cipher:", 7) != 0)
return;
offset += 7;

/* skip to name */
while (offset < length && data[offset] != ',')
offset++;
Expand All @@ -97,13 +97,13 @@ cndb_add_cn(unsigned ip, const unsigned char *data, size_t length)
offset++;
if (offset >= length)
return;

/* we should have a good name */
name_offset = offset;
while (offset < length && data[offset] != ',')
offset++;
name_length = offset - name_offset;

/* now insert into database */
cndb_add(ip, data+name_offset, name_length);
}
Expand All @@ -116,7 +116,7 @@ static unsigned
found(const char *str, size_t str_len, const unsigned char *p, size_t length)
{
size_t i;

if (str_len > length)
return 0;

Expand Down Expand Up @@ -181,9 +181,9 @@ struct Names {
/* raspberry pi */
/* issuer[Debian */






{XNas, 9, "nasend~~]"},
Expand All @@ -198,14 +198,14 @@ struct Names {
{Xav, 16, "issuer[Kaspersky"},
{XFW, 17, "subject[Fortinet]"},
{XFW, 17, "issuer[ICC-FW CA]"},
{XCam, 17, "issuer[HIKVISION]"},
{XCam, 17, "issuer[HIKVISION]"},
{Xprint,17, "subject[SHARP MX-"},
{X509, 18, "issuer[GANDI SAS]"},
{XFW, 18, "subject[FortiGate]"},
{XFW, 18, "issuer[watchguard]"},
{XVM, 18, "issuer[VMware Inc]"},
{XVM, 18, "issuer[VMware Inc]"},
{Xbox, 19, "issuer[eBox Server]"},
{XFW, 19, "subject[WatchGuard]"},
{XFW, 19, "subject[WatchGuard]"},
{X509, 19, "issuer[RapidSSL CA]"},
{X509, 19, "issuer[AddTrust AB]"},
{XCom, 19, "issuer[Cisco SSCA2]"},
Expand All @@ -217,7 +217,7 @@ struct Names {
{XMail, 20, "issuer[EQ-MT-RAPTOR]"},
{X509, 20, "issuer[DigiCert Inc]"},
{X509, 21, "issuer[TERENA SSL CA]"},
{XFW, 21, "issuer[WatchGuard CA]"},
{XFW, 21, "issuer[WatchGuard CA]"},
{XVPN, 21, "issuer[OpenVPN Web CA"},
{X509, 21, "issuer[GeoTrust Inc.]"},
{XNas, 21, "issuer[TS Series NAS]"},
Expand All @@ -227,9 +227,9 @@ struct Names {
{Xdefault,21,"issuer[XX] issuer[XX]"},
{XWiFi, 21, "2Wire]Gateway Device]"},
{X509, 21, "subject[DigiCert Inc]"},
{XCam, 22, "issuer[SamsungTechwin]"},
{XCam, 22, "issuer[SamsungTechwin]"},
{X509, 22, "issuer[TAIWAN-CA INC.]"},
{X509, 22, "issuer[GeoTrust, Inc.]"},
{X509, 22, "issuer[GeoTrust, Inc.]"},
{X509, 22, "issuer[ValiCert, Inc.]"},
{0, 22, "issuer[Apache Friends]"},
{X509, 22, "issuer[VeriSign, Inc.]"},
Expand All @@ -242,7 +242,7 @@ struct Names {
{X509, 24, "issuer[GlobalSign nv-sa]"},
{XVPN, 24, "SonicWALL, Inc.]SSL-VPN]"},
{X509, 25, "issuer[Comodo CA Limited]"},
{X509, 25, "issuer[COMODO CA Limited]"},
{X509, 25, "issuer[COMODO CA Limited]"},
{X509, 25, "issuer[GoDaddy.com, Inc.]"},
{Xbox, 26, "subject[Barracuda Networks]"},
{X509, 26, "issuer[Equifax Secure Inc.]"},
Expand All @@ -266,7 +266,7 @@ struct Names {
{XVPN, 35, "SonicWALL, Inc.]Secure Remote Access]"},
{X509, 40, "issuer[Secure Digital Certificate Signing]"},
{X509, 40, "issuer[Equifax Secure Certificate Authority]"},
{XVM, 40, "subject[VMware ESX Server Default Certificate]"},
{XVM, 40, "subject[VMware ESX Server Default Certificate]"},
{XCam, 40, "issuer[Cisco Systems] issuer[Cisco Manufacturing CA]"},
{0,0, 0}
};
Expand Down Expand Up @@ -318,7 +318,7 @@ found_type(const unsigned char *banner, size_t banner_length)
(unsigned)banner_length);
if (id == SMACK_NOT_FOUND)
return 0;

counts[id]++;

return 1;
Expand All @@ -335,7 +335,7 @@ readscan_report( unsigned ip,


if (app_proto == PROTO_X509_CERT) {
unsigned char *der = MALLOC(data_length);
unsigned char *der = (unsigned char *) MALLOC(data_length);
struct CertDecode x;
size_t der_length;
struct BannerOutput banout[1];
Expand All @@ -345,7 +345,7 @@ readscan_report( unsigned ip,
banout_init(banout);

der_length = base64_decode(der, data_length, data, data_length);

x509_decode_init(&x, data_length);
x.is_capture_issuer = 1;
x.is_capture_subject = 1;
Expand All @@ -364,7 +364,7 @@ readscan_report( unsigned ip,
cndb_add(ip, data, data_length);*/
} else if (app_proto == PROTO_VULN) {
const char *name = cndb_lookup(ip);

if (data_length == 15 && memcmp(data, "SSL[heartbeat] ", 15) == 0)
return;

Expand Down
Loading