/*--------------- GrAzEr1's BAIT SYSTEM -------------------*/
/* Use this program to detect people who are connecting    */
/* to you machine on a specified port (such as trojan ports)*/ 
/* They will be logged!                                    */
/* to compile: gcc GBS.c -o BGS        logfile: log.txt    */ 
/* default port: 12345                                     */ 
/*-------------------------------------------------------- */ 
/* Please e-mail your comments to: uuhaas@hotmail.com      */ 
/* Greetingz fly out to :              ToXic N Togooz      */ 
/*                                   05-03-2000 by GrAzEr1 */   



#include <stdio.h> 
#include <string.h> 
#include <sys/types.h> 
#include <netinet/in.h> 
#include <sys/socket.h> 
#include <sys/wait.h> 
#include <stdlib.h>  
#include <errno.h> 

#define portnr 12345    
#define que 2     

main()
 {
  int fpoint;
  int sockfd, new_s;  
  struct sockaddr_in my_addr;    
  struct sockaddr_in their_addr; 
  int sin_size;

  if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) == -1) 
 {
  perror("socket error");
  exit(1);
  }

  my_addr.sin_family = AF_INET;         
  my_addr.sin_port = htons(portnr);     
  my_addr.sin_addr.s_addr = INADDR_ANY; 
  bzero(&(my_addr.sin_zero), 8);        

  if (bind(sockfd, (struct sockaddr *)&my_addr, sizeof(struct sockaddr)) 
                                                                     == -1) 
        {
            perror("cannot bind");
            exit(1);
        }

  if (listen(sockfd, que) == -1) 
        {
            perror("listen error");
            exit(1);
        }

        while(1) {  
            sin_size = sizeof(struct sockaddr_in);
            if ((new_s = accept(sockfd, (struct sockaddr *)&their_addr, 
                                                          &sin_size)) == -1) 
            {
                perror("accept error");
                continue;
            }
            
            {
                FILE *fpoint;
                fpoint = fopen ("log.txt", "a");
                 {
                 fputs (inet_ntoa(their_addr.sin_addr),fpoint);
                 fputs ("\n ",fpoint);
                 }
                fclose (fpoint);
            }
            
            
             if (!fork()) 
           { 
           if (send(new_s, "U R LOGGED\n", 11, 0) == -1)                    
           perror("unable to send");                                
           exit(0);  
           }  
           close(new_s); 
              while(waitpid(-1,NULL,WNOHANG) > 0); 
         }
    }
