Skip to content

Commit

Permalink
split stack-tcp-app.c
Browse files Browse the repository at this point in the history
  • Loading branch information
robertdavidgraham committed Nov 13, 2023
1 parent 48bbcd7 commit 0e0fc1d
Show file tree
Hide file tree
Showing 58 changed files with 788 additions and 529 deletions.
2 changes: 1 addition & 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 Down
2 changes: 1 addition & 1 deletion src/main-conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include "massip-addr.h"
#include "masscan-version.h"
#include "string_s.h"
#include "logger.h"
#include "util-logger.h"
#include "proto-banner1.h"
#include "templ-payloads.h"
#include "crypto-base64.h"
Expand Down
2 changes: 1 addition & 1 deletion src/main-initadapter.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "masscan.h"
#include "logger.h"
#include "util-logger.h"
#include "rawsock.h"
#include "rawsock-adapter.h"
#include "stack-arpv4.h"
Expand Down
2 changes: 1 addition & 1 deletion src/main-listscan.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "masscan.h"
#include "logger.h"
#include "util-logger.h"
#include "crypto-blackrock.h"


Expand Down
2 changes: 1 addition & 1 deletion src/main-throttle.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/
#include "main-throttle.h"
#include "pixie-timer.h"
#include "logger.h"
#include "util-logger.h"
#include <string.h>
#include <stdio.h>

Expand Down
2 changes: 1 addition & 1 deletion src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#include "crypto-lcg.h" /* the LCG randomization func */
#include "crypto-base64.h" /* base64 encode/decode */
#include "templ-pkt.h" /* packet template, that we use to send */
#include "logger.h" /* adjust with -v command-line opt */
#include "util-logger.h" /* adjust with -v command-line opt */
#include "stack-ndpv6.h" /* IPv6 Neighbor Discovery Protocol */
#include "stack-arpv4.h" /* Handle ARP resolution and requests */
#include "rawsock.h" /* API on top of Linux, Windows, Mac OS X*/
Expand Down
2 changes: 1 addition & 1 deletion src/massip-parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include "massip-parse.h"
#include "massip-rangesv4.h"
#include "massip-rangesv6.h"
#include "logger.h"
#include "util-logger.h"
#include "util-bool.h"
#include "util-malloc.h"
#include "string_s.h"
Expand Down
2 changes: 1 addition & 1 deletion src/massip-rangesv4.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
*/
#include "massip-rangesv4.h"
#include "massip-port.h"
#include "logger.h"
#include "util-logger.h"
#include "util-bool.h"
#include "util-malloc.h"

Expand Down
2 changes: 1 addition & 1 deletion src/massip-rangesv6.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "massip-rangesv6.h"
#include "massip-rangesv4.h"
#include "util-malloc.h"
#include "logger.h"
#include "util-logger.h"
#include "massip.h"
#include "massip-parse.h"

Expand Down
2 changes: 1 addition & 1 deletion src/out-redis.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "output.h"
#include "masscan.h"
#include "pixie-sockets.h"
#include "logger.h"
#include "util-logger.h"
#include <ctype.h>

/****************************************************************************
Expand Down
2 changes: 1 addition & 1 deletion src/output.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
#include "masscan.h"
#include "masscan-status.h"
#include "string_s.h"
#include "logger.h"
#include "util-logger.h"
#include "proto-banner1.h"
#include "masscan-app.h"
#include "main-globals.h"
Expand Down
2 changes: 1 addition & 1 deletion src/proto-arp.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "proto-arp.h"
#include "proto-preprocess.h"
#include "logger.h"
#include "util-logger.h"
#include "output.h"
#include "masscan-status.h"
#include "unusedparm.h"
Expand Down
57 changes: 35 additions & 22 deletions src/proto-banner1.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "smack.h"
#include "rawsock-pcapfile.h"
#include "proto-preprocess.h"
#include "stack-handle.h"
#include "stack-tcp-api.h"
#include "proto-banner1.h"
#include "proto-http.h"
#include "proto-ssl.h"
Expand All @@ -19,10 +19,11 @@
#include "proto-vnc.h"
#include "proto-memcached.h"
#include "proto-mc.h"
#include "proto-versioning.h"
#include "masscan-app.h"
#include "scripting.h"
#include "versioning.h"
#include "util-malloc.h"
#include "util-logger.h"
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
Expand Down Expand Up @@ -115,7 +116,7 @@ banner1_parse(
struct StreamState *tcb_state,
const unsigned char *px, size_t length,
struct BannerOutput *banout,
struct stack_handle_t *more)
struct stack_handle_t *socket)
{
size_t x;
unsigned offset = 0;
Expand Down Expand Up @@ -171,14 +172,14 @@ banner1_parse(
tcb_state,
s, s_len,
banout,
more);
socket);
}
banner1_parse(
banner1,
tcb_state,
px, length,
banout,
more);
socket);
} else {
banout_append(banout, PROTO_HEUR, px, length);
}
Expand All @@ -189,15 +190,15 @@ banner1_parse(
tcb_state,
px, length,
banout,
more);
socket);
break;
case PROTO_SMTP:
banner_smtp.parse( banner1,
banner1->http_fields,
tcb_state,
px, length,
banout,
more);
socket);
break;

case PROTO_TELNET:
Expand All @@ -206,31 +207,31 @@ banner1_parse(
tcb_state,
px, length,
banout,
more);
socket);
break;
case PROTO_RDP:
banner_rdp.parse( banner1,
banner1->http_fields,
tcb_state,
px, length,
banout,
more);
socket);
break;
case PROTO_POP3:
banner_pop3.parse( banner1,
banner1->http_fields,
tcb_state,
px, length,
banout,
more);
socket);
break;
case PROTO_IMAP4:
banner_imap4.parse(banner1,
banner1->http_fields,
tcb_state,
px, length,
banout,
more);
socket);
break;

case PROTO_SSH1:
Expand All @@ -243,7 +244,7 @@ banner1_parse(
tcb_state,
px, length,
banout,
more);
socket);
break;
case PROTO_HTTP:
banner_http.parse(
Expand All @@ -252,7 +253,7 @@ banner1_parse(
tcb_state,
px, length,
banout,
more);
socket);
break;
case PROTO_SSL3:
banner_ssl.parse(
Expand All @@ -261,7 +262,7 @@ banner1_parse(
tcb_state,
px, length,
banout,
more);
socket);
break;
case PROTO_SMB:
banner_smb1.parse(
Expand All @@ -270,39 +271,39 @@ banner1_parse(
tcb_state,
px, length,
banout,
more);
socket);
break;
case PROTO_VNC_RFB:
banner_vnc.parse( banner1,
banner1->http_fields,
tcb_state,
px, length,
banout,
more);
socket);
break;
case PROTO_MEMCACHED:
banner_memcached.parse( banner1,
banner1->http_fields,
tcb_state,
px, length,
banout,
more);
socket);
break;
case PROTO_SCRIPTING:
banner_scripting.parse( banner1,
banner1->http_fields,
tcb_state,
px, length,
banout,
more);
socket);
break;
case PROTO_VERSIONING:
banner_versioning.parse( banner1,
banner1->http_fields,
tcb_state,
px, length,
banout,
more);
socket);
break;
case PROTO_MC:
banner_mc.parse(
Expand All @@ -311,7 +312,7 @@ banner1_parse(
tcb_state,
px, length,
banout,
more);
socket);
break;

default:
Expand Down Expand Up @@ -726,6 +727,8 @@ banner1_selftest()
length = (unsigned)strlen(http_header);


LOG(1, "[ ] banners: selftesting\n");

/*
* First, test the "banout" subsystem
*/
Expand Down Expand Up @@ -823,8 +826,18 @@ banner1_selftest()
fprintf(stderr, "RDP banner: selftest failed\n");
return 1;
}

return x;

if (x)
goto failure;
else
goto success;
}

success:
LOG(1, "[+] banners: success\n");
return 0;
failure:
LOG(1, "[-] banners: failure\n");
return 1;
}

18 changes: 12 additions & 6 deletions src/proto-banner1.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ typedef void (*BannerParser)(
struct StreamState *stream_state,
const unsigned char *px, size_t length,
struct BannerOutput *banout,
struct stack_handle_t *more);
struct stack_handle_t *socket);
struct Banner1
{
struct lua_State *L;
Expand All @@ -38,7 +38,7 @@ struct Banner1
unsigned is_poodle_sslv3:1;

struct {
struct ProtocolParserStream *tcp[65536];
const struct ProtocolParserStream *tcp[65536];
} payloads;

BannerParser parser[PROTO_end_of_list];
Expand Down Expand Up @@ -263,6 +263,12 @@ struct StreamState {
} sub;
};

enum StreamFlags {
SF__none = 0,
SF__close = 0x01, /* send FIN after the static Hello is sent*/
SF__nowait_hello = 0x02, /* send our hello immediately, don't wait for their hello */
};


/**
* A registration structure for various TCP stream protocols
Expand All @@ -273,7 +279,7 @@ struct ProtocolParserStream {
unsigned port;
const void *hello;
size_t hello_length;
unsigned ctrl_flags;
enum StreamFlags flags;
int (*selftest)(void);
void *(*init)(struct Banner1 *b);
void (*parse)(
Expand All @@ -282,9 +288,9 @@ struct ProtocolParserStream {
struct StreamState *stream_state,
const unsigned char *px, size_t length,
struct BannerOutput *banout,
struct stack_handle_t *more);
struct stack_handle_t *socket);
void (*cleanup)(struct StreamState *stream_state);
void (*transmit_hello)(const struct Banner1 *banner1, struct stack_handle_t *more);
void (*transmit_hello)(const struct Banner1 *banner1, struct stack_handle_t *socket);

/* When multiple items are registered for a port. When one
* connection is closed, the next will be opened.*/
Expand Down Expand Up @@ -339,7 +345,7 @@ banner1_parse(
struct StreamState *pstate,
const unsigned char *px, size_t length,
struct BannerOutput *banout,
struct stack_handle_t *more);
struct stack_handle_t *socket);



Expand Down
4 changes: 2 additions & 2 deletions src/proto-coap.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@
#include "proto-banner1.h"
#include "smack.h"
#include "unusedparm.h"
#include "logger.h"
#include "util-logger.h"
#include "masscan-app.h"
#include "output.h"
#include "stack-handle.h"
#include "stack-tcp-api.h"
#include "proto-preprocess.h"
#include "proto-ssl.h"
#include "proto-udp.h"
Expand Down
2 changes: 1 addition & 1 deletion src/proto-dns.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include "proto-dns-parse.h"
#include "proto-preprocess.h"
#include "syn-cookie.h"
#include "logger.h"
#include "util-logger.h"
#include "output.h"
#include "masscan-app.h"
#include "proto-banner1.h"
Expand Down
Loading

0 comments on commit 0e0fc1d

Please sign in to comment.