/***********************************************
 * released under (E) licensing ...            *
 *        (E) RULES AND REGULATIONS            *
 * permission to use/rewrite/add     : granted *
 * permission to trojan/steal        : denied  *
 * permission to use illegally       : denied  *
 * permission to use on /dev/urandom : denied  *
 ***********************************************/
/* contact el8@press.co.jp for full license    */
/* code copyrighted by ~el8 -- don't infringe! */

#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <signal.h>
#include <unistd.h>
#include <fcntl.h>
#include <linux/kd.h>
#define P4SSWD "O!"
#define PAGERPORT 1515
#define BACKL0G 1

int sfd,nfd;
void trapsig(int s)
{
  fprintf(stderr,"[%i]\n",s);
  close(sfd);
  exit(-1);
}

int MAXSLEEPTIME = 10;
int phreq = 1404;

void killdat(int,int);
void killdat(int bxpid,int sigy)
{
  if (( kill((pid_t)bxpid,sigy) )==-1)
        kill((pid_t)bxpid,sigy);
  waitpid((pid_t)bxpid,NULL,WNOHANG);
}
int d0p4g3r(void);
int d0p4g3r(void)
{
  int k0q;
  if ((k0q = open("/dev/console", O_RDWR | O_NOCTTY)) < 0)
    {
      perror("0p3n");
      exit(-1);
    }
  if (ioctl(k0q, KIOCSOUND, phreq) < 0)
    {
      perror("10ctl");
      exit(-1);
    }
  sleep(MAXSLEEPTIME);
  if (ioctl(k0q, KIOCSOUND, 0) < 0)
    {
      perror("10ctl");
      exit(-1);
    }
  close(k0q);
  return 1;
}

int daem0n(void)
{
  pid_t pid;
  if ((pid = fork()) != 0)
    exit(0);
  setsid();
  signal(SIGHUP, SIG_IGN);
  if ((pid = fork()) != 0)
    exit(0);
  chdir("/");
  umask(0);
  signal(SIGHUP, SIG_DFL);
  return (1);
}

int main(int argc, char *argv[])
{
  char pass[520];
  struct sockaddr_in yoyo;
  int BXPID,sig;
  unsigned int maxtime;
  signal(SIGTERM,trapsig);
  signal(SIGINT,trapsig);
  signal(SIGSEGV,trapsig);
  if (argc != 4)
    {
      fprintf(stderr,
        "usage: %s [seconds_for_beep] [pid_to_kill] [signal]\n",argv[0]);
      exit(-1);
    }
  if (argv[1] != '\0')
    {
      maxtime = atoi(argv[1]);
      printf("%i\n", maxtime);
      MAXSLEEPTIME = maxtime;
    }
  BXPID     = atoi(argv[2]);
  sig       = atoi(argv[3]);
  if (!daem0n())
    exit(-1);
  bzero(&yoyo, sizeof(yoyo));
  yoyo.sin_family = AF_INET;
  yoyo.sin_port = htons(PAGERPORT);
  yoyo.sin_addr.s_addr = INADDR_ANY;
  sfd = socket(AF_INET, SOCK_STREAM, 0);
  if (sfd < 0)
    {
      perror("s0ck3t");
      exit(-1);
    }
  if (bind(sfd, (struct sockaddr *) &yoyo, sizeof(yoyo)) < 0)
    {
      perror("b1nd");
      exit(-1);
    }
  listen(sfd, BACKL0G);
  for (;;)
    {
      if ((nfd = accept(sfd, 0, 0)) < 0)
        {
          perror("4cc3pt");
          exit(-1);
        }
      if (send(nfd, "enter passwd: ", strlen("enter passwd: "), 0) < 0)
        {
          perror("s3nd");
          exit(-1);
        }
      if (recv(nfd, pass, sizeof pass, 0) < 0)
        {
          perror("r3cv");
          exit(-1);
        }
      if (!strncmp(pass, P4SSWD, strlen(P4SSWD)))
        {
          if (send(nfd, "O!\r\n",
                   strlen("O!\r\n"), 0) < 0)
            {
              perror("s3nd");
              exit(-1);
            }
          d0p4g3r();
          killdat(BXPID,sig);
          break;
        }
      close(nfd);
    }
  return 1;
}


syntax highlighted by Code2HTML, v. 0.9.1