Skip to content

Commit

Permalink
fixed banner 'tcp' problem
Browse files Browse the repository at this point in the history
  • Loading branch information
robertdavidgraham committed Jan 22, 2014
1 parent c3c7bde commit 3e9b90d
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 20 deletions.
5 changes: 4 additions & 1 deletion src/out-grepable.c
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,9 @@ grepable_out_banner(struct Output *out, FILE *fp, time_t timestamp,
(unsigned char)(ip>> 8),
(unsigned char)(ip>> 0)
);
fprintf(fp, "\tApp: %s", masscan_app_to_string(proto));
fprintf(fp, "\tPort: %u", port);

fprintf(fp, "\tService: %s", masscan_app_to_string(proto));

normalize_string(px, length, banner_buffer, sizeof(banner_buffer));

Expand All @@ -183,6 +185,7 @@ grepable_out_banner(struct Output *out, FILE *fp, time_t timestamp,
}



/****************************************************************************
* This is the only structure exposed to the rest of the system. Everything
* else in the file is defined 'static' or 'private'.
Expand Down
9 changes: 1 addition & 8 deletions src/out-text.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,20 +54,13 @@ text_out_banner(struct Output *out, FILE *fp, time_t timestamp,
enum ApplicationProtocol proto, const unsigned char *px, unsigned length)
{
char banner_buffer[4096];
char ip_proto_sz[64];

switch (ip_proto) {
case 1: strcpy_s(ip_proto_sz, sizeof(ip_proto_sz), "icmp"); break;
case 6: strcpy_s(ip_proto_sz, sizeof(ip_proto_sz), "tcp"); break;
case 17: strcpy_s(ip_proto_sz, sizeof(ip_proto_sz), "udp"); break;
default: sprintf_s(ip_proto_sz, sizeof(ip_proto_sz), "(%u)", ip_proto); break;
}

UNUSEDPARM(out);

fprintf(fp, "%s %s %u %u.%u.%u.%u %u %s %s\n",
"banner",
ip_proto_sz,
proto_from_proto(ip_proto),
port,
(ip>>24)&0xFF,
(ip>>16)&0xFF,
Expand Down
10 changes: 1 addition & 9 deletions src/out-xml.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,17 +97,9 @@ xml_out_banner(struct Output *out, FILE *fp, time_t timestamp,
enum ApplicationProtocol proto, const unsigned char *px, unsigned length)
{
char banner_buffer[4096];
char ip_proto_sz[64];

UNUSEDPARM(out);

switch (ip_proto) {
case 1: strcpy_s(ip_proto_sz, sizeof(ip_proto_sz), "icmp"); break;
case 6: strcpy_s(ip_proto_sz, sizeof(ip_proto_sz), "tcp"); break;
case 17: strcpy_s(ip_proto_sz, sizeof(ip_proto_sz), "udp"); break;
default: sprintf_s(ip_proto_sz, sizeof(ip_proto_sz), "(%u)", ip_proto); break;
}

fprintf(fp, "<host endtime=\"%u\">"
"<address addr=\"%u.%u.%u.%u\" addrtype=\"ipv4\"/>"
"<ports>"
Expand All @@ -124,7 +116,7 @@ xml_out_banner(struct Output *out, FILE *fp, time_t timestamp,
(ip>>16)&0xFF,
(ip>> 8)&0xFF,
(ip>> 0)&0xFF,
ip_proto_sz,
proto_from_proto(ip_proto),
port,
masscan_app_to_string(proto),
normalize_string(px, length, banner_buffer, sizeof(banner_buffer))
Expand Down
18 changes: 17 additions & 1 deletion src/output.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,21 @@
#include <string.h>


/*****************************************************************************
* The 'status' variable contains both the open/closed info as well as the
* protocol info. This splits it back out into two values.
*****************************************************************************/
const char *
proto_from_proto(unsigned ip_proto)
{
switch (ip_proto) {
case 1: return "icmp";
case 6: return "tcp";
case 17: return "udp";
case 132: return "sctp";
default: return "unknown";
}
}

/*****************************************************************************
* The 'status' variable contains both the open/closed info as well as the
Expand Down Expand Up @@ -740,8 +755,9 @@ output_report_banner(struct Output *out, time_t now,
unsigned count;
char banner_buffer[4096];

count = fprintf(stdout, "Banner on port %u/tcp on %u.%u.%u.%u: [%s] %s",
count = fprintf(stdout, "Banner on port %u/%s on %u.%u.%u.%u: [%s] %s",
port,
proto_from_proto(ip_proto),
(ip>>24)&0xFF,
(ip>>16)&0xFF,
(ip>> 8)&0xFF,
Expand Down
1 change: 1 addition & 0 deletions src/output.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ struct Output
} xml;
};

const char *proto_from_proto(unsigned ip_proto);
const char *proto_from_status(unsigned status);
const char *status_string(int x);
const char *reason_string(int x, char *buffer, size_t sizeof_buffer);
Expand Down
2 changes: 1 addition & 1 deletion src/templ-pkt.c
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,7 @@ template_set_target(

px[offset_tcp+6] = (unsigned char)(0);
px[offset_tcp+7] = (unsigned char)(0);
xsum = udp_checksum(tmpl);
xsum = udp_checksum2(px, offset_ip, offset_tcp, tmpl->length - offset_tcp);
/*xsum += (uint64_t)tmpl->checksum_tcp
+ (uint64_t)ip_me
+ (uint64_t)ip_them
Expand Down

0 comments on commit 3e9b90d

Please sign in to comment.