Skip to content

Commit

Permalink
telnet windows fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
robertdavidgraham committed May 8, 2019
1 parent b3134b2 commit 0e17953
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 15 deletions.
23 changes: 14 additions & 9 deletions src/proto-coap.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@
#include "templ-port.h"
#include "util-malloc.h"
#include "string_s.h"
#include "util-bool.h"
#include <ctype.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>

struct CoapLink
{
Expand Down Expand Up @@ -294,6 +294,10 @@ coap_parse(const unsigned char *px, size_t length, struct BannerOutput *banout,
unsigned code = 0;
unsigned token_length = 0;
unsigned long long token = 0;
unsigned offset;
unsigned optnum;
unsigned content_format;
size_t i;

/* All coap responses will be at least 8 bytes */
if (length < 4) {
Expand Down Expand Up @@ -339,7 +343,7 @@ coap_parse(const unsigned char *px, size_t length, struct BannerOutput *banout,
}

token = 0;
for (size_t i=0; i<token_length; i++) {
for (i=0; i<token_length; i++) {
token = token << 8ULL;
token = token | (unsigned long long)px[i];
}
Expand Down Expand Up @@ -387,9 +391,9 @@ coap_parse(const unsigned char *px, size_t length, struct BannerOutput *banout,
\ \
+-------------------------------+
*/
unsigned offset = 4 + token_length;
unsigned optnum = 0;
unsigned content_format = 0;
offset = 4 + token_length;
optnum = 0;
content_format = 0;
while (offset < length) {
unsigned delta;
unsigned opt;
Expand Down Expand Up @@ -630,9 +634,10 @@ test_is_link(const char *name, const unsigned char *vinput, struct CoapLink *lin
const char *input = (const char *)vinput;

for (i=0; i<count; i++) {
const char *name2;
if (name_length != links[i].link_length)
continue;
const char *name2 = input + links[i].link_offset;
name2 = input + links[i].link_offset;
if (memcmp(name2, name, name_length) != 0)
continue;
return 1; /* found */
Expand All @@ -656,7 +661,7 @@ proto_coap_selftest(void)
{
static const unsigned char *input = (const unsigned char *)
"</sensors/temp>;if=\"se\\\"\\;\\,\\<\\>\\\\nsor\",</success>";
links = parse_links(input, 0, (~0), &count);
links = parse_links(input, 0, (unsigned)(~0), &count);
if (!test_is_link("/success", input, links, count, __LINE__))
return 1;
}
Expand All @@ -665,7 +670,7 @@ proto_coap_selftest(void)
{
static const unsigned char *input = (const unsigned char *)
"</sensors/temp>;if=\"sensor\"";
links = parse_links(input, 0, (~0), &count);
links = parse_links(input, 0, (unsigned)(~0), &count);
if (!test_is_link("/sensors/temp", input, links, count, __LINE__))
return 1;
}
Expand All @@ -688,7 +693,7 @@ proto_coap_selftest(void)
"</t>;anchor=\"/sensors/temp\";rel=\"alternate\","
"</firmware/v2.1>;rt=\"firmware\";sz=262144"
;
links = parse_links(input, 0, (~0), &count);
links = parse_links(input, 0, (unsigned)(~0), &count);
if (!test_is_link("/firmware/v2.1", input, links, count, __LINE__))
return 1;
}
Expand Down
12 changes: 6 additions & 6 deletions src/proto-tcp-telnet.c
Original file line number Diff line number Diff line change
Expand Up @@ -262,30 +262,30 @@ telnet_parse( const struct Banner1 *banner1,
}

{
const size_t r_length = 256*3*4;
#define r_length (256*3*4)
unsigned char reply[r_length];
size_t r_offset = 0;
size_t i;
for (i=0; i<256 && r_offset + 3 < r_length; i++) {
if (nego[i] & FLAG_WILL) {
reply[r_offset++] = 0xFF; /* IAC */
reply[r_offset++] = 0xFB; /* WILL */
reply[r_offset++] = i;
reply[r_offset++] = (unsigned char)i;
}
if (nego[i] & FLAG_WONT) {
reply[r_offset++] = 0xFF; /* IAC */
reply[r_offset++] = 0xFC; /* WONT */
reply[r_offset++] = i;
reply[r_offset++] = (unsigned char)i;
}
if (nego[i] & FLAG_DO) {
reply[r_offset++] = 0xFF; /* IAC */
reply[r_offset++] = 0xFD; /* DO */
reply[r_offset++] = i;
reply[r_offset++] = (unsigned char)i;
}
if (nego[i] & FLAG_DONT) {
reply[r_offset++] = 0xFF; /* IAC */
reply[r_offset++] = 0xFE; /* DONT */
reply[r_offset++] = i;
reply[r_offset++] = (unsigned char)i;
}
}
if (r_offset) {
Expand Down Expand Up @@ -336,7 +336,7 @@ telnet_selftest_item(const char *input, const char *output)
banout1,
&more
);
fprintf(stderr, "%.*s\n", (int)banout_string_length(banout1, PROTO_TELNET), banout_string(banout1, PROTO_TELNET));
//fprintf(stderr, "%.*s\n", (int)banout_string_length(banout1, PROTO_TELNET), banout_string(banout1, PROTO_TELNET));
/*
* Verify that somewhere in the output is the string
* we are looking for
Expand Down
9 changes: 9 additions & 0 deletions src/util-bool.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#ifndef UTIL_BOOL_H
#define UTIL_BOOL_H

#if _MSC_VER && _MSC_VER < 1800
typedef enum {false=0, true=1} bool;
#else
#include <stdbool.h>
#endif
#endif
3 changes: 3 additions & 0 deletions vs10/masscan.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
<ClCompile Include="..\src\proto-arp.c" />
<ClCompile Include="..\src\proto-banner1.c" />
<ClCompile Include="..\src\proto-banout.c" />
<ClCompile Include="..\src\proto-coap.c" />
<ClCompile Include="..\src\proto-dns.c" />
<ClCompile Include="..\src\proto-ftp.c" />
<ClCompile Include="..\src\proto-http.c" />
Expand Down Expand Up @@ -145,6 +146,7 @@
<ClInclude Include="..\src\proto-arp.h" />
<ClInclude Include="..\src\proto-banner1.h" />
<ClInclude Include="..\src\proto-banout.h" />
<ClInclude Include="..\src\proto-coap.h" />
<ClInclude Include="..\src\proto-dns-parse.h" />
<ClInclude Include="..\src\proto-dns.h" />
<ClInclude Include="..\src\proto-ftp.h" />
Expand Down Expand Up @@ -190,6 +192,7 @@
<ClInclude Include="..\src\syn-cookie.h" />
<ClInclude Include="..\src\templ-payloads.h" />
<ClInclude Include="..\src\templ-pkt.h" />
<ClInclude Include="..\src\util-bool.h" />
<ClInclude Include="..\src\util-malloc.h" />
<ClInclude Include="..\src\versioning.h" />
<ClInclude Include="..\src\vulncheck.h" />
Expand Down
9 changes: 9 additions & 0 deletions vs10/masscan.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,9 @@
<ClCompile Include="..\src\util-malloc.c">
<Filter>Source Files\misc</Filter>
</ClCompile>
<ClCompile Include="..\src\proto-coap.c">
<Filter>Source Files\proto</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\src\proto-arp.h">
Expand Down Expand Up @@ -566,6 +569,12 @@
<ClInclude Include="..\src\util-malloc.h">
<Filter>Source Files\misc</Filter>
</ClInclude>
<ClInclude Include="..\src\proto-coap.h">
<Filter>Source Files\proto</Filter>
</ClInclude>
<ClInclude Include="..\src\util-bool.h">
<Filter>Source Files\proto</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="..\README.md" />
Expand Down

0 comments on commit 0e17953

Please sign in to comment.