Listing 1: telnet_plugin.c
/* telnet_plugin.c
David Endler
Used to log the telnet/rlogin port for incoming connections */
#include <signal.h>
#include <sys/types.h>
#include <sys/resource.h>
#include <sys/param.h>
#include <sys/fcntl.h>
#include <sys/termios.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <stdio.h>
#include <varargs.h>
#include <signal.h>
#include <netdb.h>
#include <syslog.h>
#include <errno.h>
#include <string.h>
#include <stdlib.h>
extern int errno;
/* globals */
/*ARGSUSED*/
main(argc, argv)
int argc;
char **argv; /* argv1 is the service name */
{
int i;
char tbuf[1500];
char username[1500];
char* password;
int char_val=-1;
int non_white_space_flag=0;
int index=0;
sigset_t mask;
struct sigaction signal_vector;
openlog(telnet_plugin, LOG_PID | LOG_ODELAY, LOG_DAEMON);
/* SIGNAL HANDLING */
if (sigemptyset (&mask) == -1) {
perror (sigemptyset FAILED);
exit (1);
}
if ((sigaddset (&mask, SIGINT) == -1) ||
(sigaddset (&mask, SIGQUIT) == -1) ||
(sigaddset (&mask, SIGTSTP) == -1)) {
perror (sigaddset FAILED);
exit (1);
}
if (sighold (SIGINT) == -1) {
perror (sigaction FAILED FOR SIGINT);
exit (1);
}
if (sighold (SIGQUIT) == -1) {
perror (sigaction FAILED FOR SIGQUIT);
exit (1);
}
if (sighold (SIGTSTP) == -1) {
perror (sigaction FAILED FOR SIGTSTP);
exit (1);
}
fprintf(stderr, UNIX(r) System V Release 4.0 (honeypot));
/*
* We assume we're invoked by inetd, so the socket that the
* connection is on, is open on descriptors 0, 1 and 2.
*
* First get the Internet address of the client process.
* This is required for all the authentication we perform.
*/
for (i=0;i<5;i++) {
do {
non_white_space_flag = 0;
index = 0;
char_val=-1;
fprintf(stderr,login: );
while (char_val != 10) {
char_val = getc(stdin);
if ((char_val != 32) && (char_val != 10))
{non_white_space_flag=1;}
if (char_val != 10) {username[index++] = (char)char_val;}
}
username[index]='\0';
}
while (non_white_space_flag == 0);
fprintf(stderr,Password: );
password = getpass();
sleep(4);
fprintf(stderr,Login incorrect);
syslog(LOG_ALERT, Someone tried to access telnet port with \
username:%s and password:%s,username, password);
fprintf(stderr,\n);
}
}
|