#!/usr/bin/perl -w # # $Id: //websites/unixwiz/unixwiz.net/webroot/tools/zalistener.txt#2 $ # # written by : Stephen J. Friedl # Software Consultant # Tustin, California USA # http://www.unixwiz.net # # ======================================================== # This program is in the public domain; have fun. # ======================================================== # # This program is a trivial webserver simulator used for testing the # ZoneAlarm false-proxy problem. It listens on port 80 for inbound # connections from clients, receives and displays the data submitted, # then sends a canned response. # # Our purpose is to get a reproduceable testbed to find the smallest # sequences that confuse ZoneAlarm, and to let the engineers from # Zone Labs attempt to fix it. # # COMMAND LINE # ------------ # # --help # # Show a brief help listing to stderr, then exit with success # # --port=P # # Listen on port P/tcp (default 80/tcp). If testing the listener on # on a UNIX system without root access, one can pick a port >=1024 # to listen on; zatest is happy to talk on and get confused by any # port. # # --timeout=N # # When collecting data from the client, wait up to N seconds for # data; this is our implicit endmarker. A real webserver analyzes # the content of the data, but we don't have that luxury as we # are not always dealing with a well-formed HTTP stream. # use strict; use IO::Socket::INET; use IO::Select; my $port = 80; my $timeout = 2; foreach ( @ARGV ) { if ( m/^--help/i ) { print STDERR <new(Listen => 5, LocalAddr => '0.0.0.0', # all interfaces LocalPort => $port, Reuse => 1, Proto => 'tcp'); die "ERROR: cannot create listener [$!]\n" if not defined $sock; print "Listening on port $port/tcp\n"; while ( defined ( my $client = $sock->accept() ) ) { print "Accepted client connection\n"; my $s = IO::Select->new( $client ); my $rdata = ""; while ( $s->can_read($timeout) ) { sysread($client, $rdata, 64, length $rdata); } printf "Received %d bytes of data\n", length $rdata; print "-------------------------------\n"; print $rdata; print "-------------------------------\n"; print "\n"; print "Sending response:\n"; print "-------------------------------\n"; print $response; print "-------------------------------\n"; print $client $response; $client->close; print "Client connection closed\n\n"; }