/**raidon Fake Daemon 
made by ev1lut10n
A Chinese Man Lives in Indonesia
Special thanks to : Cakill, Whitehat,Paulus gandung, Danzel, flyff66, p4, X-hack and also thanks to Raidon and all my bro
[c] Copyright 2012-2015 All Rights Reserved 
compile: gcc -o raidon raidon.c -Wall
then run as root , ex: ./raidon 2078
**/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/syslog.h>
#include <netinet/in.h>
#include <netdb.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <unistd.h>

static void gime_er_mas()
{
	  printf("\nFailed to run please check your privilege\n");	
}

static void banner()
{
	 printf("==============Raidon [Fake Daemon Version 1.0]=================\nmade by ev1lut10n\nUsage : ./raidon port_number\n");
}

static void handle_this_client(char *ip)
{
	syslog(LOG_INFO,"-Raidon Fake Daemon Log, got connection from : %s-",ip);

}

unsigned int run_ev1lut10n_fake_daemon(char port[])
{
FILE * awakenz;
char *ada_kotor;
int childpid;
unsigned int soket,bindres,listenres,newfd,pjg;

//deklarasi struktur lokal
struct sockaddr_in lokal;

///deklarasi struktur klien
struct sockaddr_in klien_addr;	
	
char str[1000];
int jumlah_proc=1;
	
//here our lokal struct
	lokal.sin_family = PF_INET;
	lokal.sin_port = htons(atoi(port));
	lokal.sin_addr.s_addr = htonl(INADDR_ANY); 

	
//first we create a PF_INET socket
	soket = socket(PF_INET,SOCK_STREAM,0);
	if(soket<0)
	   {
		gime_er_mas();
		return -1;
	   }

//then bind, don't forget about the casting here : (struct sockaddr *)
	bindres=bind(soket, (struct sockaddr *)&lokal, 0x10);
	if(bindres<0)
	     {
		gime_er_mas(); 
		return -1;		     
	     }
 //finally we listen
	     listenres=listen(soket, 10);
	      if(listenres<0)
	     {
		gime_er_mas(); 
		return -1;		     
	     }

	     
while(1)
    {
	   char *ip_klien;
	    pjg=sizeof(klien_addr);
	   newfd=accept(soket,(struct sockaddr *) &klien_addr, &pjg);
	    if(newfd)
	     {
		   awakenz = popen("/bin/ps aux | grep raidon", "r");
		   while(fgets(str,sizeof(str),awakenz) != NULL)
			{
				int len = strlen(str)-1;
				if(str[len] == '\n') 
				{
				  str[len] = 0;
					ada_kotor= strstr(str,"raidon");
					if(ada_kotor) 
					{
						jumlah_proc++;
						
					}
				}
		        }
		     
		if(jumlah_proc<50)
		{	
		     if ( (childpid = fork()) < 0)
		       {
			       gime_er_mas();
			     
		       }
		   else if (childpid == 0)
		      {
		      close(soket);	
			      
		      ip_klien=inet_ntoa(klien_addr.sin_addr);			      
		      handle_this_client(ip_klien);
		      exit(0);
		      }
	      }     
    }
    close(newfd);
     
    }

	   
 return 0;
}

int main(int argc, char *argv[])
{
if(argc<2)
 {
  banner();	
  return -1; 
 }
if (fork() != 0)
    {       
        exit(1);
    }         

run_ev1lut10n_fake_daemon(argv[1]);
return 0;
}