Esempio n. 1
0
int STREAMDoPostConnect(STREAM *S, int Flags)
{
    int result=TRUE;
    char *ptr;
    struct timeval tv;


    if ((S->in_fd > -1) && (S->Timeout > 0) )
    {
        tv.tv_sec=S->Timeout;
        tv.tv_usec=0;
        if (FDSelect(S->in_fd, SELECT_WRITE, &tv) <=0)
        {
            close(S->in_fd);
            S->in_fd=-1;
            S->out_fd=-1;
        }
        else if (! (Flags & CONNECT_NONBLOCK))  STREAMSetNonBlock(S, FALSE);
    }

    if (S->in_fd > -1)
    {
        S->Type=STREAM_TYPE_TCP;
        result=TRUE;
        STREAMSetFlushType(S,FLUSH_LINE,0);
    }

//if (Flags & CONNECT_SOCKS_PROXY) result=DoSocksProxyTunnel(S);
    if (Flags & CONNECT_SSL) DoSSLClientNegotiation(S, Flags);

    ptr=GetRemoteIP(S->in_fd);
    if (ptr) STREAMSetValue(S,"PeerIP",ptr);

    return(result);
}
Esempio n. 2
0
int FDIsWritable(int fd)
{
struct timeval tv;

tv.tv_sec=0;
tv.tv_usec=0;
if (FDSelect(fd, SELECT_WRITE, &tv) & SELECT_WRITE) return(TRUE);
return(FALSE);
}
Esempio n. 3
0
int FDCheckForBytes(int fd)
{
struct timeval tv;

tv.tv_sec=0;
tv.tv_usec=0;
if (FDSelect(fd, SELECT_READ, &tv) & SELECT_READ) return(TRUE);
return(FALSE);
}
Esempio n. 4
0
void PTelnetDServerMode()
{
int listensock, fd, i;
struct sigaction sigact;
char *Tempstr=NULL, *IPStr=NULL;

listensock=InitServerSock(Settings.Interface,Settings.Port);
if (listensock==-1)
{
	printf("ERROR: Cannot bind to port %d on interface %s\n",Settings.Port,Settings.Interface);
	exit(3);
}

if (! (Settings.Flags & FLAG_NODEMON)) demonize();

SetupPidFile();

if (Settings.Flags & FLAG_HONEYPOT) JailAndSwitchUser(FLAG_CHROOT, Settings.RealUser, Settings.ChDir);

while (1)
{
/*Set up a signal handler for SIGCHLD so that our 'select' gets interrupted when something exits*/
sigact.sa_handler = default_signal_handler;   
sigemptyset(&sigact.sa_mask);
sigact.sa_flags = 0;
sigaction(SIGCHLD, &sigact, NULL);

if (FDSelect(listensock, SELECT_READ, NULL)) 
{
	fd=TCPServerSockAccept(listensock, &IPStr);
	if (fork()==0) 
	{
		//Sub processes shouldn't keep the pid file open, only the parent server
		//should
		close(PidFile);

		//if we've been passed a socket, then make it into stdin/stdout/stderr
		//but don't do this is fd==0, because then this has already been done by inetd
		close(0);
		close(1);
		close(2);
		dup(fd);
		dup(fd);
		dup(fd);

		//Having dupped it we no longer need to keep this copy open
		close(fd);
		Tempstr=MCopyStr(Tempstr, g_argv[0]," ",IPStr,NULL);
		for (i=0; i <g_argc; i++) memset(g_argv[i],0,StrLen(g_argv[i]));
		strcpy(g_argv[0],Tempstr);

		//In case logging demon was restarted, ensure we have connection before we chroot
		//Eric Wedaa modified the following line to log to the LongTail honeypot consolidation server
		openlog("ptelnetd",LOG_PID|LOG_NDELAY,LOG_AUTH);
		HandleClient();

		//Should be redundant, but if something goes wrong in HandleClient, we might want this
		//exit call
		_exit(0);
	}
	close(fd);
}
waitpid(-1,NULL,WNOHANG);
}

}