diff --git a/Makefile b/Makefile index 083f5ab..8461c49 100644 --- a/Makefile +++ b/Makefile @@ -5,6 +5,7 @@ LDFLAGS += -lpthread -lssh -lrt -rdynamic NAME = cbrutekrag SRCS := cbrutekrag.c \ + context.c \ log.c \ str.c \ iprange.c \ diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 4d816b5..c9ac7e7 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -6,6 +6,7 @@ set(SOURCE_FILES getdelim.c getline.c cbrutekrag.c + context.c log.c str.c iprange.c diff --git a/src/cbrutekrag.c b/src/cbrutekrag.c index 81d596d..4c91096 100644 --- a/src/cbrutekrag.c +++ b/src/cbrutekrag.c @@ -72,7 +72,7 @@ static struct option long_options[] = { { NULL, 0, NULL, 0 } }; -void print_banner() +static void print_banner(void) { printf("\033[92m _ _ _\n" " | | | | | |\n" @@ -82,11 +82,11 @@ void print_banner() "\033[37m \\___|\033[92m|_.__/|_| \\__,_|\\__\\___|_|\\_\\_| \\__,_|\\__, |\n" " \033[0m\033[1mOpenSSH Brute force tool 0.6.0\033[0m\033[92m __/ |\n" " \033[0m(c) Copyright 2014-2024 Jorge Matricali\033[92m |___/\033[0m\n\n" - " \033[36mhttps://github.com/matricali/cbrutekrag\n" - "\033[0m\n"); + " \033[36mhttps://github.com/matricali/cbrutekrag\n" + "\033[0m\n"); } -void usage(const char *p) +static void usage(const char *p) { printf("\nusage: %s [-h] [-v] [-aA] [-D] [-P] [-T TARGETS.lst] [-C credentials.lst]\n" "\t\t[-t THREADS] [-F OUTPUT FORMAT] [-o OUTPUT.txt] [TARGETS...]\n\n", @@ -156,40 +156,6 @@ static void btkg_console_setup() } #endif -void btkg_options_init(btkg_options_t *options) -{ - if (options == NULL) - return; - - options->timeout = 3; - options->max_threads = 1; - options->progress_bar = 0; - options->verbose = 0; - options->dry_run = 0; - options->perform_scan = 0; - options->non_openssh = 0; - options->allow_honeypots = 0; -} - -void btkg_context_init(btkg_context_t *context) -{ - if (context == NULL) { - return; - } - - btkg_options_init(&context->options); - - context->output = NULL; - context->count = 0; - context->successful = 0; - context->total = 0; - context->credentials_idx = 0; - context->targets_idx = 0; - - btkg_credentials_list_init(&context->credentials); - btkg_target_list_init(&context->targets); -} - int main(int argc, char **argv) { int opt; diff --git a/src/cbrutekrag.h b/src/cbrutekrag.h index 2e300de..31b146f 100644 --- a/src/cbrutekrag.h +++ b/src/cbrutekrag.h @@ -23,10 +23,10 @@ SOFTWARE. #ifndef CBRUTEKRAG_H #define CBRUTEKRAG_H -#include +#include -#include "target.h" #include "credentials.h" +#include "target.h" #define CBRUTEKRAG_VERBOSE_MODE 0x1 #define CBRUTEKRAG_VERBOSE_SSHLIB 0x2 @@ -54,7 +54,24 @@ typedef struct { FILE *output; } btkg_context_t; -void print_banner(void); -void usage(const char *p); +/** + * @brief Initializes the options structure with default values. + * + * This function sets the default values for the options used in the brute + * force tool. + * + * @param options Pointer to the options structure to be initialized. + */ +void btkg_options_init(btkg_options_t *options); + +/** + * @brief Initializes the context structure with default values. + * + * This function initializes the context structure, including its embedded + * options, credentials list, and target list, with default values. + * + * @param context Pointer to the context structure to be initialized. + */ +void btkg_context_init(btkg_context_t *context); #endif /* CBRUTEKRAG_H */ diff --git a/src/context.c b/src/context.c new file mode 100644 index 0000000..ce7a7bc --- /dev/null +++ b/src/context.c @@ -0,0 +1,73 @@ +/* +Copyright (c) 2024 Jorge Matricali + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ + +#include "cbrutekrag.h" + +/** + * @brief Initializes the options structure with default values. + * + * This function sets the default values for the options used in the brute + * force tool. + * + * @param options Pointer to the options structure to be initialized. + */ +void btkg_options_init(btkg_options_t *options) +{ + if (options == NULL) + return; + + options->timeout = 3; + options->max_threads = 1; + options->progress_bar = 0; + options->verbose = 0; + options->dry_run = 0; + options->perform_scan = 0; + options->non_openssh = 0; + options->allow_honeypots = 0; +} + +/** + * @brief Initializes the context structure with default values. + * + * This function initializes the context structure, including its embedded + * options, credentials list, and target list, with default values. + * + * @param context Pointer to the context structure to be initialized. + */ +void btkg_context_init(btkg_context_t *context) +{ + if (context == NULL) { + return; + } + + btkg_options_init(&context->options); + + context->output = NULL; + context->count = 0; + context->successful = 0; + context->total = 0; + context->credentials_idx = 0; + context->targets_idx = 0; + + btkg_credentials_list_init(&context->credentials); + btkg_target_list_init(&context->targets); +} diff --git a/src/credentials.c b/src/credentials.c index d30f012..5069f1d 100644 --- a/src/credentials.c +++ b/src/credentials.c @@ -70,7 +70,8 @@ void btkg_credentials_list_init(btkg_credentials_list_t *credentials) } /** - * @brief Loads credentials from a given file and appends them into the given btkg_credentials_list_t. + * @brief Loads credentials from a given file and appends them into the given + * btkg_credentials_list_t. * * @param credentials_list Pointer to the btkg_credentials_list_t structure to append the loaded credentials to. * @param filename The name of the file to load the credentials from. diff --git a/src/detection.h b/src/detection.h index a023a54..c8bedae 100644 --- a/src/detection.h +++ b/src/detection.h @@ -25,6 +25,7 @@ SOFTWARE. #include +#include "cbrutekrag.h" #include "target.h" /**