Skip to content

Commit

Permalink
add mongodb functions
Browse files Browse the repository at this point in the history
  • Loading branch information
ngn13 committed Jun 16, 2024
1 parent 681b382 commit ef08b14
Show file tree
Hide file tree
Showing 18 changed files with 620 additions and 526 deletions.
15 changes: 8 additions & 7 deletions scanner/.clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
Language: Cpp
# BasedOnStyle: LLVM
AccessModifierOffset: -2
AlignAfterOpenBracket: Align
AlignArrayOfStructures: None
AlignAfterOpenBracket: DontAlign
AlignArrayOfStructures: Left
AlignConsecutiveAssignments:
Enabled: false
Enabled: true
AcrossEmptyLines: false
AcrossComments: false
AlignCompound: false
Expand All @@ -17,7 +17,7 @@ AlignConsecutiveBitFields:
AlignCompound: false
PadOperators: false
AlignConsecutiveDeclarations:
Enabled: false
Enabled: true
AcrossEmptyLines: false
AcrossComments: false
AlignCompound: false
Expand All @@ -38,7 +38,7 @@ AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: Never
AllowShortCaseLabelsOnASingleLine: false
AllowShortEnumsOnASingleLine: true
AllowShortFunctionsOnASingleLine: All
AllowShortFunctionsOnASingleLine: None
AllowShortIfStatementsOnASingleLine: Never
AllowShortLambdasOnASingleLine: All
AllowShortLoopsOnASingleLine: false
Expand All @@ -48,7 +48,7 @@ AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: MultiLine
AttributeMacros:
- __capability
BinPackArguments: true
BinPackArguments: false
BinPackParameters: true
BitFieldColonSpacing: Both
BraceWrapping:
Expand Down Expand Up @@ -81,7 +81,7 @@ BreakBeforeTernaryOperators: true
BreakConstructorInitializers: BeforeColon
BreakInheritanceList: BeforeColon
BreakStringLiterals: true
ColumnLimit: 80
ColumnLimit: 120
CommentPragmas: '^ IWYU pragma:'
CompactNamespaces: false
ConstructorInitializerIndentWidth: 4
Expand Down Expand Up @@ -223,3 +223,4 @@ WhitespaceSensitiveMacros:
- STRINGIZE
...


2 changes: 2 additions & 0 deletions scanner/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
compile_commands.json
massacr
.cache
7 changes: 5 additions & 2 deletions scanner/Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
HEADERS = $(wildcard inc/*.h)
CSRCS = $(wildcard *.c) $(wildcard */*.c)
VERSION = 1.2
CFLAGS = -O3 -march=native -fstack-protector-strong -fcf-protection=full -fstack-clash-protection
LIBS = -lpthread $(shell pkg-config --libs --cflags libnet) $(shell pkg-config --libs --cflags libmongoc-1.0)

VERSION = 1.3
prefix = /usr
CC = gcc

massacr: $(CSRCS) $(HEADERS)
$(CC) $(CFLAGS) $(CSRCS) -o $@ -DVERSION=\"${VERSION}\" -lnet -lcurl
$(CC) $(CFLAGS) $(CSRCS) -o $@ -DVERSION=\"${VERSION}\" $(LIBS)

install:
install -v -m755 massacr $(DESTDIR)$(prefix)/bin/massacr
Expand Down
11 changes: 0 additions & 11 deletions scanner/inc/api.h

This file was deleted.

12 changes: 12 additions & 0 deletions scanner/inc/db.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#pragma once
#include <stdbool.h>
#include <stdint.h>

typedef struct db_args {
uint16_t port;
uint32_t ipv4;
} db_args_t;

bool db_init(char *);
void db_add(void *);
void db_free();
14 changes: 7 additions & 7 deletions scanner/inc/log.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@

#include "../inc/op.h"

#define RED "\x1b[31m"
#define BOLD "\x1b[1m"
#define BLUE "\x1b[34m"
#define GRAY "\x1b[37m"
#define RESET "\x1b[0m"
#define GREEN "\x1b[32m"
#define SPACE " "
#define FG_RED "\x1b[31m"
#define FG_BOLD "\x1b[1m"
#define FG_BLUE "\x1b[34m"
#define FG_GRAY "\x1b[37m"
#define FG_RESET "\x1b[0m"
#define FG_GREEN "\x1b[32m"
#define FG_SPACE " "

void info(const char *, ...);
void error(const char *, ...);
Expand Down
16 changes: 10 additions & 6 deletions scanner/inc/net.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ struct tcphdr_ {
struct {
uint16_t th_sport; /* source port */
uint16_t th_dport; /* destination port */
tcp_seq th_seq; /* sequence number */
tcp_seq th_ack; /* acknowledgement number */
tcp_seq th_seq; /* sequence number */
tcp_seq th_ack; /* acknowledgement number */
#if __BYTE_ORDER == __LITTLE_ENDIAN
uint8_t th_x2 : 4; /* (unused) */
uint8_t th_off : 4; /* data offset */
Expand Down Expand Up @@ -64,11 +64,15 @@ struct tcphdr_ {
};
};

typedef struct RecvArgs {
typedef struct net_recv_args {
uint16_t port;
bool should_run;
bool should_run;
int threads;
} recv_args_t;

extern pthread_mutex_t net_lock;
bool net_syn(char *, int, int);
bool net_receive(void *);

bool net_init();
void net_free();
bool net_syn(uint32_t, int, int);
void net_receive(void *);
14 changes: 7 additions & 7 deletions scanner/inc/op.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ typedef struct Option {
char *value;
char *name;
char *desc;
int type;
int type;
} option_t;

extern option_t options[];
char *extract_value(char *);
bool parse_opt(char *);
bool get_bool(char *);
char *get_str(char *);
int get_int(char *);
void print_opts();
char *extract_value(char *);
bool parse_opt(char *);
bool get_bool(char *);
char *get_str(char *);
int get_int(char *);
void print_opts();
10 changes: 5 additions & 5 deletions scanner/inc/pool.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

typedef void (*func_t)(void *arg);
typedef struct work_t {
func_t func;
void *arg;
func_t func;
void *arg;
struct work_t *next;
} work_t;

Expand All @@ -20,9 +20,9 @@ typedef struct pool_t {

work_t *first;
work_t *last;
bool stop;
bool stop;
} pool_t;

pool_t *pool_init(int);
bool pool_add(pool_t *, func_t, void *);
void pool_stop(pool_t *);
bool pool_add(pool_t *, func_t, void *);
void pool_stop(pool_t *);
17 changes: 7 additions & 10 deletions scanner/inc/util.h
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
#pragma once
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>

#define contains(str, sub) (strchr(str, sub) != NULL)
#define startswith(str, sub) (strncmp(str, sub, strlen(sub)) == 0)
#define neq(s1, s2) (strcmp(s1, s2) != 0)
#define eq(s1, s2) (strcmp(s1, s2) == 0)

typedef struct Range {
typedef struct subnet {
uint8_t ip[4];
uint8_t net;
} range_t;
} subnet_t;

int *parse_ports(char *, int *);
void clean_ports(int *);
uint16_t *parse_ports(char *);
void clean_ports(uint16_t *);

bool get_range(range_t *, char *);
bool skip_range(range_t *, uint8_t *);
void urljoin(char *, char *, char *);
extern int common_ports[];
extern char *bad_ranges[];
extern int bad_range_size;
bool get_subnet(subnet_t *, char *);
bool subnet_contains(uint32_t, subnet_t *, size_t);
Loading

0 comments on commit ef08b14

Please sign in to comment.