Skip to content

Commit

Permalink
Merge pull request #699 from Nightsuki/master
Browse files Browse the repository at this point in the history
Add support for redis auth
  • Loading branch information
robertdavidgraham authored Nov 1, 2023
2 parents 731a485 + e644ad8 commit 66ca4df
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/main-conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -2461,6 +2461,8 @@ masscan_set_parameter(struct Masscan *masscan,
strcpy_s(masscan->output.filename,
sizeof(masscan->output.filename),
"<redis>");
} else if(EQUALS("redis-pwd", name)) {
masscan->redis.password = strdup(value);
} else if (EQUALS("release-memory", name)) {
fprintf(stderr, "nmap(%s): this is our default option\n", name);
} else if (EQUALS("resume", name)) {
Expand Down
1 change: 1 addition & 0 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1596,6 +1596,7 @@ int main(int argc, char *argv[])
masscan->shard.one = 1;
masscan->shard.of = 1;
masscan->min_packet_size = 60;
masscan->redis.password = NULL;
masscan->payloads.udp = payloads_udp_create();
masscan->payloads.oproto = payloads_oproto_create();
strcpy_s( masscan->output.rotate.directory,
Expand Down
1 change: 1 addition & 0 deletions src/masscan.h
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,7 @@ struct Masscan

struct {
ipaddress ip;
char *password;
unsigned port;
} redis;

Expand Down
22 changes: 22 additions & 0 deletions src/out-redis.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,28 @@ redis_out_open(struct Output *out, FILE *fp)
unsigned char line[1024];

UNUSEDPARM(out);
if (out->redis.password != NULL)
{
sprintf_s(line, sizeof(line),
"*2\r\n"
"$4\r\nAUTH\r\n"
"$%u\r\n%s\r\n",
(unsigned)strlen(out->redis.password), out->redis.password);

count = send(fd, line, (int)strlen(line), 0);
if (count != strlen(line))
{
LOG(0, "redis: error auth\n");
exit(1);
}

count = recv_line(fd, line, sizeof(line));
if (count != 5 && memcmp(line, "+OK\r\n", 5) != 0)
{
LOG(0, "redis: unexpected response from redis server: %s\n", line);
exit(1);
}
}

count = send((SOCKET)fd, "PING\r\n", 6, 0);
if (count != 6) {
Expand Down
1 change: 1 addition & 0 deletions src/output.c
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,7 @@ output_create(const struct Masscan *masscan, unsigned thread_index)
out->rotate.filesize = masscan->output.rotate.filesize;
out->redis.port = masscan->redis.port;
out->redis.ip = masscan->redis.ip;
out->redis.password = masscan ->redis.password;
out->is_banner = masscan->is_banners;
out->is_gmt = masscan->is_gmt;
out->is_interactive = masscan->output.is_interactive;
Expand Down
1 change: 1 addition & 0 deletions src/output.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ struct Output
struct {
ipaddress ip;
unsigned port;
char *password;
ptrdiff_t fd;
uint64_t outstanding;
unsigned state;
Expand Down

0 comments on commit 66ca4df

Please sign in to comment.