/usr/sbin/dbab-svr is in dbab 1.3.2-1.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 | #! /usr/bin/perl -Tw
##-----------------------------------------------------------------------
## Porgram: dbab-svr pixelserv
## Purpose: super minimal webserver serving a 1x1 pixel transparent gif
## Authors: Tong Sun (c) 2013,2014
## Authors: Originally wrote by Piet Wintjens, date unknown
## License: covered by the new BSD (no advertising clause) license
## Reference: Well House Consultants training course
## http://www.wellho.net/resources/ex.php4?item=p402/miniserver.pl
##-----------------------------------------------------------------------
use IO::Socket::INET;
my $conffile = "/etc/dbab/dbab.addr";
my $proxyfile = "/etc/dbab/dbab.proxy";
my $crlf = Socket::CRLF;
my $pixel = pack( "C*",
qw(71 73 70 56 57 97 1 0 1 0 128 0 0 255 255 255 0 0 0 33 249 4 1 0 0 0 0 44 0 0 0 0 1 0 1 0 0 2 2 68 1 0 59)
);
my $fh;
#-------- conf file ---------------
open($fh, "<", $conffile) || die "can't open $conffile: $!";
my $listento = do { local $/; <$fh> };
close($fh) || die "can't close $conffile: $!";
if ( $listento =~ /^([\d.]+)$/ ) {
$listento = $1; # $listento now untainted
}
else {
die "Bad listen to address: '$listento'";
}
#-------- proxy file ---------------
open($fh, "<", $proxyfile) || die "can't open $proxyfile: $!";
my $proxyaddr = do { local $/; <$fh> };
close($fh) || die "can't close $proxyfile: $!";
if ( $proxyaddr =~ /^([\w.]+)$/ ) {
$proxyaddr = $1; # $proxyaddr now untainted
}
else {
die "Error opening proxy definition file: '$proxyaddr'";
}
# Setup and create socket
my $sock = new IO::Socket::INET(
LocalHost => $listento,
LocalPort => '80',
Proto => 'tcp',
Listen => 30,
Reuse => 1
);
if ( !defined($sock) ) {
print "error : cannot bind : $! exit\n";
exit(1);
}
# Await requests and handle them as they arrive
while (my $new_sock = $sock->accept() ) {
my %request = ();
local $/ = $crlf;
#-------- Read Request ---------------
while (<$new_sock>) {
chomp; # Main http request
if (/\s*(\w+)\s*([^\s]+)\s*HTTP\/(\d.\d)/) {
$request{METHOD} = uc $1;
$request{URL} = $2;
$request{HTTP_VERSION} = $3;
next;
}
# print ">$_<\n";
if ( /^$/ ) { last; }
}
if (defined($request{METHOD}) and $request{METHOD} eq 'GET' and
($request{URL} eq '/proxy.pac' or
$request{URL} eq '/wpad.dat') ) {
#------- Serve pac/wpad file --------------------
print $new_sock "function FindProxyForURL(url, host) {".
qq| return "PROXY $proxyaddr:3128; DIRECT"; }$crlf|;
} else {
#------- Serve pixel file ----------------------
print $new_sock "HTTP/1.1 200 OK$crlf";
print $new_sock "Content-type: image/gif$crlf";
print $new_sock "Accept-ranges: bytes$crlf";
print $new_sock "Content-length: 43$crlf$crlf";
print $new_sock $pixel;
}
shutdown( $new_sock, 2 );
undef($new_sock);
}
close($sock);
exit(0);
|