Skip to content

Commit

Permalink
context.c
Browse files Browse the repository at this point in the history
  • Loading branch information
matricali committed Jul 28, 2024
1 parent d6dda79 commit dc91b97
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 43 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ LDFLAGS += -lpthread -lssh -lrt -rdynamic

NAME = cbrutekrag
SRCS := cbrutekrag.c \
context.c \
log.c \
str.c \
iprange.c \
Expand Down
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ set(SOURCE_FILES
getdelim.c
getline.c
cbrutekrag.c
context.c
log.c
str.c
iprange.c
Expand Down
42 changes: 4 additions & 38 deletions src/cbrutekrag.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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",
Expand Down Expand Up @@ -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;
Expand Down
25 changes: 21 additions & 4 deletions src/cbrutekrag.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ SOFTWARE.
#ifndef CBRUTEKRAG_H
#define CBRUTEKRAG_H

#include <stdint.h>
#include <stdio.h>

#include "target.h"
#include "credentials.h"
#include "target.h"

#define CBRUTEKRAG_VERBOSE_MODE 0x1
#define CBRUTEKRAG_VERBOSE_SSHLIB 0x2
Expand Down Expand Up @@ -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 */
73 changes: 73 additions & 0 deletions src/context.c
Original file line number Diff line number Diff line change
@@ -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);
}
3 changes: 2 additions & 1 deletion src/credentials.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions src/detection.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ SOFTWARE.

#include <stdint.h>

#include "cbrutekrag.h"
#include "target.h"

/**
Expand Down

0 comments on commit dc91b97

Please sign in to comment.