Skip to content

Commit

Permalink
ssl certs
Browse files Browse the repository at this point in the history
  • Loading branch information
robertdavidgraham committed Oct 4, 2013
1 parent e110927 commit 7fd2b2b
Show file tree
Hide file tree
Showing 17 changed files with 454 additions and 239 deletions.
5 changes: 5 additions & 0 deletions src/event-timeout.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>



Expand Down Expand Up @@ -75,10 +76,13 @@ timeouts_add(struct Timeouts *timeouts, struct TimeoutEntry *entry,
size_t offset, uint64_t timestamp)
{
unsigned index;
time_t now = time(0);
time_t time_future = (unsigned)(timestamp/16384ULL);

/* Unlink from wherever the entry came from */
timeout_unlink(entry);

printf("++ADD %d.%03u\n", time_future-now, (unsigned)(((timestamp%16384ULL)/16384.0)*1000.0));
/* Initialize the new entry */
entry->timestamp = timestamp;
entry->offset = (unsigned)offset;
Expand All @@ -90,6 +94,7 @@ timeouts_add(struct Timeouts *timeouts, struct TimeoutEntry *entry,
entry->prev = &timeouts->slots[index];
if (entry->next)
entry->next->prev = &entry->next;
printf("++PREV=0x%llx\n", entry->prev);
}

/***************************************************************************
Expand Down
1 change: 1 addition & 0 deletions src/event-timeout.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ timeout_unlink(struct TimeoutEntry *entry)
entry->next = 0;
entry->prev = 0;
entry->timestamp = 0;
printf("--PREV=0x%llx\n", entry->prev);
}

/***************************************************************************
Expand Down
2 changes: 1 addition & 1 deletion src/main-conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -1099,7 +1099,7 @@ masscan_command_line(struct Masscan *masscan, int argc, char *argv[])
case 'd': /* just do same as verbosity level */
{
int v;
for (v=1; argv[i][v] == 'v'; v++) {
for (v=1; argv[i][v] == 'd'; v++) {
verbosity++;
debuglevel++;
}
Expand Down
43 changes: 28 additions & 15 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#include "proto-snmp.h" /* parse SNMP responses */
#include "templ-port.h"

#include <assert.h>
#include <limits.h>
#include <string.h>
#include <time.h>
Expand Down Expand Up @@ -165,24 +166,24 @@ flush_packets(struct Adapter *adapter,
struct PacketBuffer *p;

/*
* Get the next packet from the transmit queue. This packet was
* put there by a receive thread, and will contain things like
* an ACK or an HTTP request
*/
* Get the next packet from the transmit queue. This packet was
* put there by a receive thread, and will contain things like
* an ACK or an HTTP request
*/
err = rte_ring_sc_dequeue(transmit_queue, (void**)&p);
if (err) {
break; /* queue is empty, nothing to send */
}

/*
* Actually send the packet
*/
* Actually send the packet
*/
rawsock_send_packet(adapter, p->px, (unsigned)p->length, 1);

/*
* Now that we are done with the packet, put it on the free list
* of buffers that the transmit thread can reuse
*/
* Now that we are done with the packet, put it on the free list
* of buffers that the transmit thread can reuse
*/
for (err=1; err; ) {
err = rte_ring_sp_enqueue(packet_buffers, p);
if (err) {
Expand All @@ -193,9 +194,9 @@ flush_packets(struct Adapter *adapter,


/*
* Remember that we sent a packet, which will be used in
* throttling.
*/
* Remember that we sent a packet, which will be used in
* throttling.
*/
(*packets_sent)++;
}

Expand Down Expand Up @@ -1163,9 +1164,21 @@ int main(int argc, char *argv[])
* of their ranges, and when doing wide scans, add the exclude list to
* prevent them from being scanned.
*/
rangelist_exclude(&masscan->targets, &masscan->exclude_ip);
rangelist_exclude(&masscan->ports, &masscan->exclude_port);
rangelist_remove_range2(&masscan->targets, range_parse_ipv4("224.0.0.0/4", 0, 0));
{
uint64_t range = rangelist_count(&masscan->targets) * rangelist_count(&masscan->ports);
uint64_t range2;
rangelist_exclude(&masscan->targets, &masscan->exclude_ip);
rangelist_exclude(&masscan->ports, &masscan->exclude_port);
rangelist_remove_range2(&masscan->targets, range_parse_ipv4("224.0.0.0/4", 0, 0));

range2 = rangelist_count(&masscan->targets) * rangelist_count(&masscan->ports);

if (range2 != range && masscan->resume.index) {
LOG(0, "FAIL: Attempted to add additional 'exclude' ranges after scan start.\n");
LOG(0, " ...This messes things up the scan randomization, so you have to restart scan\n");
exit(1);
}
}



Expand Down
4 changes: 4 additions & 0 deletions src/output.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ proto_string(unsigned proto)
case PROTO_DNS_VERSIONBIND: return "dns-ver";
case PROTO_SNMP: return "snmp";
case PROTO_NBTSTAT: return "nbtstat";
case PROTO_SSL3: return "ssl";
case PROTO_SMTP: return "smtp";
case PROTO_POP3: return "pop";
case PROTO_IMAP4: return "imap";

default:
sprintf_s(tmp, sizeof(tmp), "(%u)", proto);
Expand Down
76 changes: 53 additions & 23 deletions src/proto-banner1.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "proto-preprocess.h"
#include "proto-banner1.h"
#include "proto-http.h"
#include "proto-ssl.h"
#include "proto-ssh.h"
#include <ctype.h>
#include <stdlib.h>
Expand All @@ -19,6 +20,12 @@ struct Patterns patterns[] = {
{"HTTP/1.", 7, PROTO_HTTP, SMACK_ANCHOR_BEGIN},
{"220-", 4, PROTO_FTP1, SMACK_ANCHOR_BEGIN},
{"220 ", 4, PROTO_FTP2, SMACK_ANCHOR_BEGIN},
{"+OK ", 4, PROTO_POP3, SMACK_ANCHOR_BEGIN},
{"* OK ", 5, PROTO_IMAP4, SMACK_ANCHOR_BEGIN},
{"\x16\x03\x00",3, PROTO_SSL3, SMACK_ANCHOR_BEGIN},
{"\x16\x03\x01",3, PROTO_SSL3, SMACK_ANCHOR_BEGIN},
{"\x16\x03\x02",3, PROTO_SSL3, SMACK_ANCHOR_BEGIN},
{"\x16\x03\x03",3, PROTO_SSL3, SMACK_ANCHOR_BEGIN},
{0,0}
};

Expand All @@ -27,10 +34,11 @@ struct Patterns patterns[] = {

/***************************************************************************
***************************************************************************/
unsigned
void
banner1_parse(
struct Banner1 *banner1,
unsigned state, unsigned *proto,
struct Banner1State *pstate,
unsigned *proto,
const unsigned char *px, size_t length,
char *banner, unsigned *banner_offset, size_t banner_max)
{
Expand All @@ -41,29 +49,40 @@ banner1_parse(
case PROTO_UNKNOWN:
x = smack_search_next(
banner1->smack,
&state,
&pstate->state,
px, &offset, (unsigned)length);
if (x != SMACK_NOT_FOUND) {
if (x != SMACK_NOT_FOUND
&& !(x == PROTO_SSL3 && !pstate->is_sent_sslhello)) {
unsigned i;

/* Kludge: patterns look confusing, so add port info to the
* pattern */
switch (*proto) {
case PROTO_FTP2:
if (pstate->port == 25 || pstate->port == 587)
*proto = PROTO_SMTP;
break;
}

*proto = (unsigned)x;

/* reset the state back again */
state = 0;
pstate->state = 0;

/* re-read the stuff that we missed */
for (i=0; patterns[i].id != *proto; i++)
;

*banner_offset = 0;

state = banner1_parse(
banner1_parse(
banner1,
state, proto,
pstate, proto,
(const unsigned char*)patterns[i].pattern, patterns[i].pattern_length,
banner, banner_offset, banner_max);
state = banner1_parse(
banner1_parse(
banner1,
state, proto,
pstate, proto,
px+offset, length-offset,
banner, banner_offset, banner_max);
} else {
Expand All @@ -78,12 +97,24 @@ banner1_parse(
case PROTO_SSH2:
case PROTO_FTP1:
case PROTO_FTP2:
state = banner_ssh(banner1, state,
px, length,
banner, banner_offset, banner_max);
banner_ssh.parse( banner1,
banner1->http_fields,
pstate,
px, length,
banner, banner_offset, banner_max);
break;
case PROTO_HTTP:
state = banner_http(banner1, state,
banner_http.parse(
banner1,
banner1->http_fields,
pstate,
px, length,
banner, banner_offset, banner_max);
case PROTO_SSL3:
banner_ssl.parse(
banner1,
banner1->http_fields,
pstate,
px, length,
banner, banner_offset, banner_max);
break;
Expand All @@ -92,8 +123,6 @@ banner1_parse(
break;

}

return state;
}

/***************************************************************************
Expand All @@ -120,7 +149,8 @@ banner1_create(void)
patterns[i].is_anchored);
smack_compile(b->smack);

http_init(b);

banner_http.init(b);

return b;
}
Expand Down Expand Up @@ -211,7 +241,7 @@ int banner1_selftest()
struct Banner1 *b;
char banner[128];
unsigned banner_offset;
unsigned state;
struct Banner1State pstate[1];
unsigned proto;
const unsigned char *px;
unsigned length;
Expand All @@ -236,13 +266,13 @@ int banner1_selftest()
*/
b = banner1_create();
memset(banner, 0xa3, sizeof(banner));
state = 0;
memset(pstate, 0, sizeof(pstate[0]));
proto = 0;
banner_offset = 0;
for (i=0; i<length; i++)
state = banner1_parse(
banner1_parse(
b,
state,
pstate,
&proto,
px+i, 1,
banner, &banner_offset, sizeof(banner)
Expand All @@ -258,12 +288,12 @@ int banner1_selftest()
*/
b = banner1_create();
memset(banner, 0xa3, sizeof(banner));
state = 0;
memset(pstate, 0, sizeof(pstate[0]));
proto = 0;
banner_offset = 0;
state = banner1_parse(
banner1_parse(
b,
state,
pstate,
&proto,
px, length,
banner, &banner_offset, sizeof(banner)
Expand Down
Loading

0 comments on commit 7fd2b2b

Please sign in to comment.