|
|
|
@ -382,7 +382,9 @@ if [ "X$reverse" != "X" ]; then
|
|
|
|
|
echo "*Warning*: -listen and a single proxy/gateway does not make sense."
|
|
|
|
|
sleep 2
|
|
|
|
|
fi
|
|
|
|
|
SSVNC_LISTEN_ONCE=1; export SSVNC_LISTEN_ONCE
|
|
|
|
|
|
|
|
|
|
# we now try to PPROXY_LOOP_THYSELF, set this var to disable that.
|
|
|
|
|
#SSVNC_LISTEN_ONCE=1; export SSVNC_LISTEN_ONCE
|
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
if [ "X$ssh_cmd" = "X" ]; then
|
|
|
|
@ -520,12 +522,6 @@ if [ "X$SSVNC_ULTRA_DSM" != "X" ]; then
|
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# (possibly) tell the vncviewer to only listen on lo:
|
|
|
|
|
if [ "X$reverse" != "X" -a "X$direct_connect" = "X" ]; then
|
|
|
|
|
VNCVIEWER_LISTEN_LOCALHOST=1
|
|
|
|
|
export VNCVIEWER_LISTEN_LOCALHOST
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# rsh mode is an internal/secret thing only I use.
|
|
|
|
|
rsh=""
|
|
|
|
|
if echo "$orig" | grep '^rsh://' > /dev/null; then
|
|
|
|
@ -551,11 +547,98 @@ else
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# extract host and disp number:
|
|
|
|
|
host=`echo "$orig" | awk -F: '{print $1}'`
|
|
|
|
|
disp=`echo "$orig" | awk -F: '{print $2}'`
|
|
|
|
|
|
|
|
|
|
# try to see if it is ipv6 address:
|
|
|
|
|
ipv6=0
|
|
|
|
|
if echo "$orig" | grep '\[' > /dev/null; then
|
|
|
|
|
# ipv6 [fe80::219:dbff:fee5:3f92%eth1]:5900
|
|
|
|
|
host=`echo "$orig" | sed -e 's/\].*$//' -e 's/\[//'`
|
|
|
|
|
disp=`echo "$orig" | sed -e 's/^.*\]://'`
|
|
|
|
|
ipv6=1
|
|
|
|
|
elif echo "$orig" | grep ':..*:' > /dev/null; then
|
|
|
|
|
# ipv6 fe80::219:dbff:fee5:3f92%eth1:5900
|
|
|
|
|
host=`echo "$orig" | sed -e 's/:[^:]*$//'`
|
|
|
|
|
disp=`echo "$orig" | sed -e 's/^.*://'`
|
|
|
|
|
ipv6=1
|
|
|
|
|
else
|
|
|
|
|
# regular host:port
|
|
|
|
|
host=`echo "$orig" | awk -F: '{print $1}'`
|
|
|
|
|
disp=`echo "$orig" | awk -F: '{print $2}'`
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
if [ "X$reverse" != "X" -a "X$STUNNEL_LISTEN" = "X" -a "X$host" != "X" ]; then
|
|
|
|
|
STUNNEL_LISTEN=$host
|
|
|
|
|
echo "set STUNNEL_LISTEN=$STUNNEL_LISTEN"
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
if [ "X$host" = "X" ]; then
|
|
|
|
|
host=$localhost
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
if [ "X$SSVNC_IPV6" = "X0" ]; then
|
|
|
|
|
# disable checking for it.
|
|
|
|
|
ipv6=0
|
|
|
|
|
#elif [ "X$reverse" != "X" -a "X$ipv6" = "X1" ]; then
|
|
|
|
|
# ipv6=0
|
|
|
|
|
elif [ "X$ipv6" = "X1" ]; then
|
|
|
|
|
:
|
|
|
|
|
elif echo "$host" | grep '^[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*$' > /dev/null; then
|
|
|
|
|
:
|
|
|
|
|
else
|
|
|
|
|
# regular hostname, can't be sure...
|
|
|
|
|
host "$host" >/dev/null 2>&1
|
|
|
|
|
host "$host" >/dev/null 2>&1
|
|
|
|
|
hout=`host "$host" 2>/dev/null`
|
|
|
|
|
if echo "$hout" | grep -i 'has ipv6 address' > /dev/null; then
|
|
|
|
|
if echo "$hout" | grep -i 'has address' > /dev/null; then
|
|
|
|
|
:
|
|
|
|
|
else
|
|
|
|
|
echo "ipv6: "`echo "$hout" | grep -i 'has ipv6 address' | head -n 1`
|
|
|
|
|
ipv6=1
|
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
if [ "X$ipv6" = "X0" ]; then
|
|
|
|
|
dout=`dig -t any "$host" 2>/dev/null`
|
|
|
|
|
if echo "$dout" | grep -i "^$host" | grep '[ ]AAAA[ ]' > /dev/null; then
|
|
|
|
|
if echo "$dout" | grep -i "^$host" | grep '[ ]A[ ]' > /dev/null; then
|
|
|
|
|
:
|
|
|
|
|
else
|
|
|
|
|
echo "ipv6: "`echo "$dout" | grep -i '[ ]AAAA[ ]' | head -n 1`
|
|
|
|
|
ipv6=1
|
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
if [ "X$ipv6" = "X0" ]; then
|
|
|
|
|
sout=`env LOOKUP="$host" \
|
|
|
|
|
perl -e ' eval {use Socket}; exit 0 if $@;
|
|
|
|
|
eval {use Socket6}; exit 0 if $@;
|
|
|
|
|
@res = getaddrinfo($ENV{LOOKUP}, "daytime", AF_UNSPEC, SOCK_STREAM);
|
|
|
|
|
$ipv4 = 0;
|
|
|
|
|
$ipv6 = 0;
|
|
|
|
|
$ip6 = "";
|
|
|
|
|
while (scalar(@res) >= 5) {
|
|
|
|
|
($family, $socktype, $proto, $saddr, $canon, @res) = @res;
|
|
|
|
|
$ipv4 = 1 if $family == AF_INET;
|
|
|
|
|
$ipv6 = 1 if $family == AF_INET6;
|
|
|
|
|
if ($family == AF_INET6 && $ip6 eq "") {
|
|
|
|
|
my ($host, $port) = getnameinfo($saddr, NI_NUMERICHOST | NI_NUMERICSERV);
|
|
|
|
|
$ip6 = $host;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (! $ipv4 && $ipv6) {
|
|
|
|
|
print "AF_INET6_ONLY: $ENV{LOOKUP}: $ip6\n";
|
|
|
|
|
}
|
|
|
|
|
exit 0;
|
|
|
|
|
' 2>/dev/null`
|
|
|
|
|
if echo "$sout" | grep AF_INET6_ONLY > /dev/null; then
|
|
|
|
|
echo "$sout"
|
|
|
|
|
ipv6=1
|
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
if [ "X$ipv6" = "X1" ]; then
|
|
|
|
|
echo "ipv6: addr=$host disp=$disp"
|
|
|
|
|
fi
|
|
|
|
|
if [ "X$disp" = "X" ]; then
|
|
|
|
|
port="" # probably -listen mode.
|
|
|
|
|
elif [ $disp -lt 0 ]; then
|
|
|
|
@ -573,6 +656,21 @@ else
|
|
|
|
|
port=$disp
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
if [ "X$ipv6" = "X1" -a "X$direct_connect" = "X1" ]; then
|
|
|
|
|
if [ "X$proxy" = "X" -a "X$reverse" = "X" ]; then
|
|
|
|
|
proxy="ipv6://$host:$port"
|
|
|
|
|
echo "direct connect: set proxy=$proxy"
|
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# (possibly) tell the vncviewer to only listen on lo:
|
|
|
|
|
if [ "X$reverse" != "X" ]; then
|
|
|
|
|
if [ "X$direct_connect" = "X" -o "X$proxy" != "X" -o "X$STUNNEL_LISTEN" != "X" ]; then
|
|
|
|
|
VNCVIEWER_LISTEN_LOCALHOST=1
|
|
|
|
|
export VNCVIEWER_LISTEN_LOCALHOST
|
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# try to find an open listening port via netstat(1):
|
|
|
|
|
inuse=""
|
|
|
|
|
if uname | grep Linux > /dev/null; then
|
|
|
|
@ -787,6 +885,60 @@ pcode() {
|
|
|
|
|
|
|
|
|
|
use IO::Socket::INET;
|
|
|
|
|
|
|
|
|
|
my $have_inet6 = "";
|
|
|
|
|
eval "use IO::Socket::INET6;";
|
|
|
|
|
$have_inet6 = 1 if $@ eq "";
|
|
|
|
|
|
|
|
|
|
#my $have_sock6 = "";
|
|
|
|
|
#eval "use Socket; use Socket6;";
|
|
|
|
|
#$have_sock6 = 1 if $@ eq "";
|
|
|
|
|
|
|
|
|
|
if (exists $ENV{PPROXY_LOOP_THYSELF}) {
|
|
|
|
|
# used for reverse vnc, run a repeating outer loop.
|
|
|
|
|
print STDERR "PPROXY_LOOP: $ENV{PPROXY_LOOP_THYSELF}\n";
|
|
|
|
|
my $rm = $ENV{PPROXY_REMOVE};
|
|
|
|
|
my $lp = $ENV{PPROXY_LOOP_THYSELF};
|
|
|
|
|
delete $ENV{PPROXY_REMOVE};
|
|
|
|
|
delete $ENV{PPROXY_LOOP_THYSELF};
|
|
|
|
|
$ENV{PPROXY_LOOP_THYSELF_MASTER} = $$;
|
|
|
|
|
my $pid = $$;
|
|
|
|
|
my $dbg = 0;
|
|
|
|
|
my $c = 0;
|
|
|
|
|
use POSIX ":sys_wait_h";
|
|
|
|
|
while (1) {
|
|
|
|
|
$pid = fork();
|
|
|
|
|
last if ! defined $pid;
|
|
|
|
|
if ($pid eq "0") {
|
|
|
|
|
last;
|
|
|
|
|
}
|
|
|
|
|
$c++;
|
|
|
|
|
print STDERR "\nPPROXY_LOOP: pid=$$ child=$pid count=$c\n";
|
|
|
|
|
while (1) {
|
|
|
|
|
waitpid(-1, WNOHANG);
|
|
|
|
|
fsleep(0.25);
|
|
|
|
|
if (! kill 0, $pid) {
|
|
|
|
|
print STDERR "PPROXY_LOOP: child=$pid gone.\n";
|
|
|
|
|
last;
|
|
|
|
|
}
|
|
|
|
|
print STDERR "PPROXY_LOOP: child=$pid alive.\n" if $dbg;
|
|
|
|
|
if (! -f $lp) {
|
|
|
|
|
print STDERR "PPROXY_LOOP: flag file $lp gone, killing $pid\n";
|
|
|
|
|
kill TERM, $pid;
|
|
|
|
|
fsleep(0.1);
|
|
|
|
|
wait;
|
|
|
|
|
last;
|
|
|
|
|
}
|
|
|
|
|
print STDERR "PPROXY_LOOP: file exists $lp\n" if $dbg;
|
|
|
|
|
}
|
|
|
|
|
last if ! -f $lp;
|
|
|
|
|
fsleep(0.25);
|
|
|
|
|
}
|
|
|
|
|
if ($pid ne "0") {
|
|
|
|
|
unlink($0) if $rm;
|
|
|
|
|
exit 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (exists $ENV{PPROXY_SLEEP} && $ENV{PPROXY_SLEEP} > 0) {
|
|
|
|
|
print STDERR "PPROXY_PID: $$\n";
|
|
|
|
|
sleep $ENV{PPROXY_SLEEP};
|
|
|
|
@ -835,7 +987,7 @@ if (exists $ENV{SSVNC_PREDIGESTED_HANDSHAKE}) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
my $have_gettimeofday = 0;
|
|
|
|
|
eval "use Time::HiRes";
|
|
|
|
|
eval "use Time::HiRes;";
|
|
|
|
|
if ($@ eq "") {
|
|
|
|
|
$have_gettimeofday = 1;
|
|
|
|
|
}
|
|
|
|
@ -862,7 +1014,11 @@ my ($mode_1st, $mode_2nd, $mode_3rd) = ("", "", "");
|
|
|
|
|
|
|
|
|
|
($first, $mode_1st) = url_parse($first);
|
|
|
|
|
|
|
|
|
|
my ($proxy_host, $proxy_port) = split(/:/, $first);
|
|
|
|
|
my ($proxy_host, $proxy_port) = ($first, "");
|
|
|
|
|
if ($proxy_host =~ /^(.*):(\d+)$/) {
|
|
|
|
|
$proxy_host = $1;
|
|
|
|
|
$proxy_port = $2;
|
|
|
|
|
}
|
|
|
|
|
my $connect = $ENV{PPROXY_DEST};
|
|
|
|
|
|
|
|
|
|
if ($second ne "") {
|
|
|
|
@ -875,13 +1031,15 @@ if ($third ne "") {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
print STDERR "\n";
|
|
|
|
|
print STDERR "PPROXY v0.3: a tool for Web, SOCKS, and UltraVNC proxies and VeNCrypt bridging.\n";
|
|
|
|
|
print STDERR "PPROXY v0.4: a tool for Web, SOCKS, and UltraVNC proxies and for\n";
|
|
|
|
|
print STDERR "PPROXY v0.4: IPv6 and VNC VeNCrypt bridging.\n";
|
|
|
|
|
print STDERR "proxy_host: $proxy_host\n";
|
|
|
|
|
print STDERR "proxy_port: $proxy_port\n";
|
|
|
|
|
print STDERR "proxy_connect: $connect\n";
|
|
|
|
|
print STDERR "pproxy_params: $ENV{PPROXY_PROXY}\n";
|
|
|
|
|
print STDERR "pproxy_listen: $ENV{PPROXY_LISTEN}\n";
|
|
|
|
|
print STDERR "pproxy_reverse: $ENV{PPROXY_REVERSE}\n";
|
|
|
|
|
print STDERR "io_socket_inet6: $have_inet6\n";
|
|
|
|
|
print STDERR "\n";
|
|
|
|
|
if (1) {
|
|
|
|
|
print STDERR "pproxy 1st: $first\t- $mode_1st\n";
|
|
|
|
@ -897,15 +1055,29 @@ sub pdie {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($ENV{PPROXY_REVERSE} ne "") {
|
|
|
|
|
my ($rhost, $rport) = split(/:/, $ENV{PPROXY_REVERSE});
|
|
|
|
|
my ($rhost, $rport) = ($ENV{PPROXY_REVERSE}, "");
|
|
|
|
|
if ($rhost =~ /^(.*):(\d+)$/) {
|
|
|
|
|
$rhost = $1;
|
|
|
|
|
$rport = $2;
|
|
|
|
|
}
|
|
|
|
|
$rport = 5900 unless $rport;
|
|
|
|
|
my $emsg = "";
|
|
|
|
|
$listen_handle = IO::Socket::INET->new(
|
|
|
|
|
PeerAddr => $rhost,
|
|
|
|
|
PeerPort => $rport,
|
|
|
|
|
Proto => "tcp"
|
|
|
|
|
);
|
|
|
|
|
$emsg = $!;
|
|
|
|
|
if (! $listen_handle && $have_inet6) {
|
|
|
|
|
eval {$listen_handle = IO::Socket::INET6->new(
|
|
|
|
|
PeerAddr => $rhost,
|
|
|
|
|
PeerPort => $rport,
|
|
|
|
|
Proto => "tcp"
|
|
|
|
|
);};
|
|
|
|
|
$emsg .= " / $!";
|
|
|
|
|
}
|
|
|
|
|
if (! $listen_handle) {
|
|
|
|
|
pdie "pproxy: $! -- PPROXY_REVERSE\n";
|
|
|
|
|
pdie "pproxy: $emsg -- PPROXY_REVERSE\n";
|
|
|
|
|
}
|
|
|
|
|
print STDERR "PPROXY_REVERSE: connected to $rhost $rport\n";
|
|
|
|
|
|
|
|
|
@ -914,27 +1086,75 @@ if ($ENV{PPROXY_REVERSE} ne "") {
|
|
|
|
|
my $maxtry = 12;
|
|
|
|
|
my $sleep = 5;
|
|
|
|
|
my $p2 = "";
|
|
|
|
|
my $emsg = "";
|
|
|
|
|
for (my $i=0; $i < $maxtry; $i++) {
|
|
|
|
|
if ($ENV{PPROXY_LISTEN} =~ /^INADDR_ANY:(.*)/) {
|
|
|
|
|
my $p = $1;
|
|
|
|
|
$p2 = "*:$p";
|
|
|
|
|
my ($if, $p) = ("", $ENV{PPROXY_LISTEN});
|
|
|
|
|
if ($p =~ /^(.*):(\d+)$/) {
|
|
|
|
|
$if = $1;
|
|
|
|
|
$p = $2;
|
|
|
|
|
}
|
|
|
|
|
$p2 = "*:$p";
|
|
|
|
|
if ($if eq "") {
|
|
|
|
|
$if = "localhost";
|
|
|
|
|
}
|
|
|
|
|
print STDERR "pproxy interface: $if\n";
|
|
|
|
|
|
|
|
|
|
$emsg = "";
|
|
|
|
|
if (($if eq "INADDR_ANY6" || $if eq "::") && $have_inet6) {
|
|
|
|
|
eval {$listen_sock = IO::Socket::INET6->new(
|
|
|
|
|
Listen => 2,
|
|
|
|
|
ReuseAddr => 1,
|
|
|
|
|
Domain => AF_INET6,
|
|
|
|
|
LocalAddr => "::",
|
|
|
|
|
LocalPort => $p,
|
|
|
|
|
Proto => "tcp"
|
|
|
|
|
);};
|
|
|
|
|
$p2 = ":::$p";
|
|
|
|
|
} elsif ($if =~ /^INADDR_ANY/) {
|
|
|
|
|
$listen_sock = IO::Socket::INET->new(
|
|
|
|
|
Listen => 2,
|
|
|
|
|
ReuseAddr => 1,
|
|
|
|
|
LocalPort => $p,
|
|
|
|
|
Proto => "tcp"
|
|
|
|
|
);
|
|
|
|
|
} elsif (($if eq "INADDR_LOOPBACK6" || $if eq "::1") && $have_inet6) {
|
|
|
|
|
$p2 = "::1:$p";
|
|
|
|
|
eval {$listen_sock = IO::Socket::INET6->new(
|
|
|
|
|
Listen => 2,
|
|
|
|
|
ReuseAddr => 1,
|
|
|
|
|
Domain => AF_INET6,
|
|
|
|
|
LocalAddr => "::1",
|
|
|
|
|
LocalPort => $p,
|
|
|
|
|
Proto => "tcp"
|
|
|
|
|
);};
|
|
|
|
|
$p2 = "::1:$p";
|
|
|
|
|
} else {
|
|
|
|
|
$p2 = "localhost:$ENV{PPROXY_LISTEN}";
|
|
|
|
|
$p2 = "$if:$p";
|
|
|
|
|
$listen_sock = IO::Socket::INET->new(
|
|
|
|
|
Listen => 2,
|
|
|
|
|
LocalAddr => "127.0.0.1",
|
|
|
|
|
LocalPort => $ENV{PPROXY_LISTEN},
|
|
|
|
|
ReuseAddr => 1,
|
|
|
|
|
LocalAddr => $if,
|
|
|
|
|
LocalPort => $p,
|
|
|
|
|
Proto => "tcp"
|
|
|
|
|
);
|
|
|
|
|
$emsg = $!;
|
|
|
|
|
|
|
|
|
|
if (! $listen_sock && $have_inet6) {
|
|
|
|
|
print STDERR "PPROXY_LISTEN: retry with INET6\n";
|
|
|
|
|
eval {$listen_sock = IO::Socket::INET6->new(
|
|
|
|
|
Listen => 2,
|
|
|
|
|
ReuseAddr => 1,
|
|
|
|
|
Domain => AF_INET6,
|
|
|
|
|
LocalAddr => $if,
|
|
|
|
|
LocalPort => $p,
|
|
|
|
|
Proto => "tcp"
|
|
|
|
|
);};
|
|
|
|
|
$emsg .= " / $!";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (! $listen_sock) {
|
|
|
|
|
if ($i < $maxtry - 1) {
|
|
|
|
|
warn "pproxy: $!\n";
|
|
|
|
|
warn "pproxy: $emsg $!\n";
|
|
|
|
|
warn "Could not listen on port $p2, retrying in $sleep seconds... (Ctrl-C to quit)\n";
|
|
|
|
|
sleep $sleep;
|
|
|
|
|
}
|
|
|
|
@ -943,7 +1163,7 @@ if ($ENV{PPROXY_REVERSE} ne "") {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (! $listen_sock) {
|
|
|
|
|
pdie "pproxy: $! -- PPROXY_LISTEN\n";
|
|
|
|
|
pdie "pproxy: $emsg -- PPROXY_LISTEN\n";
|
|
|
|
|
}
|
|
|
|
|
print STDERR "pproxy: listening on $p2\n";
|
|
|
|
|
my $ip;
|
|
|
|
@ -953,6 +1173,24 @@ if ($ENV{PPROXY_REVERSE} ne "") {
|
|
|
|
|
if (! $listen_handle) {
|
|
|
|
|
pdie "pproxy: $err\n";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($ENV{PPROXY_LOOP_THYSELF_MASTER}) {
|
|
|
|
|
my $sml = $ENV{SSVNC_MULTIPLE_LISTEN};
|
|
|
|
|
if ($sml ne "" && $sml ne "0") {
|
|
|
|
|
setpgrp(0, 0);
|
|
|
|
|
if (fork()) {
|
|
|
|
|
close $viewer_sock;
|
|
|
|
|
wait;
|
|
|
|
|
exit 0;
|
|
|
|
|
}
|
|
|
|
|
if (fork()) {
|
|
|
|
|
close $viewer_sock;
|
|
|
|
|
exit 0;
|
|
|
|
|
}
|
|
|
|
|
setpgrp(0, 0);
|
|
|
|
|
$parent = $$;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$sock = IO::Socket::INET->new(
|
|
|
|
@ -961,15 +1199,27 @@ $sock = IO::Socket::INET->new(
|
|
|
|
|
Proto => "tcp"
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
my $err = "";
|
|
|
|
|
|
|
|
|
|
if (! $sock && $have_inet6) {
|
|
|
|
|
$err = $!;
|
|
|
|
|
|
|
|
|
|
eval {$sock = IO::Socket::INET6->new(
|
|
|
|
|
PeerAddr => $proxy_host,
|
|
|
|
|
PeerPort => $proxy_port,
|
|
|
|
|
Proto => "tcp"
|
|
|
|
|
);};
|
|
|
|
|
$err .= " / $!";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (! $sock) {
|
|
|
|
|
my $err = $!;
|
|
|
|
|
unlink($0) if $ENV{PPROXY_REMOVE};
|
|
|
|
|
pdie "pproxy: $err\n";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unlink($0) if $ENV{PPROXY_REMOVE};
|
|
|
|
|
|
|
|
|
|
if ($ENV{PPROXY_PROXY} =~ /^vencrypt:/ && $ENV{PPROXY_LISTEN} =~ /^INADDR_ANY:/) {
|
|
|
|
|
if ($ENV{PPROXY_PROXY} =~ /^vencrypt:/ && $ENV{PPROXY_VENCRYPT_REVERSE}) {
|
|
|
|
|
print STDERR "\nPPROXY: vencrypt+reverse: swapping listen socket with connect socket.\n";
|
|
|
|
|
my $tmp_swap = $sock;
|
|
|
|
|
$sock = $listen_handle;
|
|
|
|
@ -1116,6 +1366,10 @@ xfer_both();
|
|
|
|
|
|
|
|
|
|
exit;
|
|
|
|
|
|
|
|
|
|
sub fsleep {
|
|
|
|
|
select(undef, undef, undef, shift);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sub url_parse {
|
|
|
|
|
my $hostport = shift;
|
|
|
|
|
my $mode = "http";
|
|
|
|
@ -1128,11 +1382,14 @@ sub url_parse {
|
|
|
|
|
} elsif ($hostport =~ m,^https?://(\S*)$,i) {
|
|
|
|
|
$mode = "http";
|
|
|
|
|
$hostport = $1;
|
|
|
|
|
} elsif ($hostport =~ m,^ipv6://(\S*)$,i) {
|
|
|
|
|
$mode = "ipv6";
|
|
|
|
|
$hostport = $1;
|
|
|
|
|
} elsif ($hostport =~ m,^repeater://(\S*)\+(\S*)$,i) {
|
|
|
|
|
# ultravnc repeater proxy.
|
|
|
|
|
$hostport = $1;
|
|
|
|
|
$mode = "repeater:$2";
|
|
|
|
|
if ($hostport !~ /:\d+/) {
|
|
|
|
|
if ($hostport !~ /:\d+$/) {
|
|
|
|
|
$hostport .= ":5900";
|
|
|
|
|
}
|
|
|
|
|
} elsif ($hostport =~ m,^vencrypt://(\S*)$,i) {
|
|
|
|
@ -1144,7 +1401,7 @@ sub url_parse {
|
|
|
|
|
$mode = $2;
|
|
|
|
|
}
|
|
|
|
|
$mode = "vencrypt:$m";
|
|
|
|
|
if ($hostport !~ /:\d+/) {
|
|
|
|
|
if ($hostport !~ /:\d+$/) {
|
|
|
|
|
$hostport .= ":5900";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -1161,6 +1418,8 @@ sub setmode {
|
|
|
|
|
} else {
|
|
|
|
|
$ENV{PPROXY_SOCKS} = 1;
|
|
|
|
|
}
|
|
|
|
|
} elsif ($mode =~ /^ipv6/i) {
|
|
|
|
|
$ENV{PPROXY_SOCKS} = 0;
|
|
|
|
|
} elsif ($mode =~ /^repeater:(.*)/) {
|
|
|
|
|
$ENV{PPROXY_REPEATER} = $1;
|
|
|
|
|
$ENV{PPROXY_SOCKS} = "";
|
|
|
|
@ -1180,7 +1439,11 @@ sub connection {
|
|
|
|
|
|
|
|
|
|
if ($ENV{PPROXY_SOCKS} eq "5") {
|
|
|
|
|
# SOCKS5
|
|
|
|
|
my ($h, $p) = split(/:/, $CONNECT);
|
|
|
|
|
my ($h, $p) = ($CONNECT, "");
|
|
|
|
|
if ($h =~ /^(.*):(\d+)$/) {
|
|
|
|
|
$h = $1;
|
|
|
|
|
$p = $2;
|
|
|
|
|
}
|
|
|
|
|
$con .= pack("C", 0x05);
|
|
|
|
|
$con .= pack("C", 0x01);
|
|
|
|
|
$con .= pack("C", 0x00);
|
|
|
|
@ -1242,9 +1505,13 @@ sub connection {
|
|
|
|
|
exit(1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} elsif ($ENV{PPROXY_SOCKS} ne "") {
|
|
|
|
|
} elsif ($ENV{PPROXY_SOCKS} eq "1") {
|
|
|
|
|
# SOCKS4 SOCKS4a
|
|
|
|
|
my ($h, $p) = split(/:/, $CONNECT);
|
|
|
|
|
my ($h, $p) = ($CONNECT, "");
|
|
|
|
|
if ($h =~ /^(.*):(\d+)$/) {
|
|
|
|
|
$h = $1;
|
|
|
|
|
$p = $2;
|
|
|
|
|
}
|
|
|
|
|
$con .= pack("C", 0x04);
|
|
|
|
|
$con .= pack("C", 0x01);
|
|
|
|
|
$con .= pack("n", $p);
|
|
|
|
@ -1296,6 +1563,9 @@ sub connection {
|
|
|
|
|
close $sock;
|
|
|
|
|
exit(1);
|
|
|
|
|
}
|
|
|
|
|
} elsif ($ENV{PPROXY_SOCKS} eq "0") {
|
|
|
|
|
# hack for ipv6 "proxy", nothing to do, assume INET6 call worked.
|
|
|
|
|
;
|
|
|
|
|
} elsif ($ENV{PPROXY_REPEATER} ne "") {
|
|
|
|
|
my $rep = $ENV{PPROXY_REPEATER};
|
|
|
|
|
print STDERR "repeater: $rep\n";
|
|
|
|
@ -1582,6 +1852,7 @@ sub do_vencrypt_viewer_bridge {
|
|
|
|
|
for (my $i=0; $i < $maxtry; $i++) {
|
|
|
|
|
$listen_sock = IO::Socket::INET->new(
|
|
|
|
|
Listen => 2,
|
|
|
|
|
ReuseAddr => 1,
|
|
|
|
|
LocalAddr => "127.0.0.1",
|
|
|
|
|
LocalPort => $listen,
|
|
|
|
|
Proto => "tcp"
|
|
|
|
@ -1606,6 +1877,23 @@ sub do_vencrypt_viewer_bridge {
|
|
|
|
|
if (! $viewer_sock) {
|
|
|
|
|
die "pproxy: vencrypt_viewer_bridge[$$]: $err\n";
|
|
|
|
|
}
|
|
|
|
|
if ($ENV{PPROXY_LOOP_THYSELF_MASTER}) {
|
|
|
|
|
my $sml = $ENV{SSVNC_MULTIPLE_LISTEN};
|
|
|
|
|
if ($sml ne "" && $sml ne "0") {
|
|
|
|
|
setpgrp(0, 0);
|
|
|
|
|
if (fork()) {
|
|
|
|
|
close $viewer_sock;
|
|
|
|
|
wait;
|
|
|
|
|
exit 0;
|
|
|
|
|
}
|
|
|
|
|
if (fork()) {
|
|
|
|
|
close $viewer_sock;
|
|
|
|
|
exit 0;
|
|
|
|
|
}
|
|
|
|
|
setpgrp(0, 0);
|
|
|
|
|
$parent = $$;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
print STDERR "vencrypt_viewer_bridge[$$]: viewer_sock $viewer_sock\n" if $db;
|
|
|
|
|
|
|
|
|
|
print STDERR "pproxy: vencrypt_viewer_bridge[$$]: connecting to 127.0.0.1:$connect\n";
|
|
|
|
@ -2055,13 +2343,18 @@ NHAFL_warning() {
|
|
|
|
|
echo "** Warning: you to manually remove a key from ~/.ssh/known_hosts.)"
|
|
|
|
|
echo "** Warning: "
|
|
|
|
|
echo "** Warning: This decreases security: a Man-In-The-Middle attack is possible."
|
|
|
|
|
echo "** Warning: For chained ssh connections the first ssh leg is secure but the"
|
|
|
|
|
echo "** Warning: 2nd ssh leg is vulnerable. For an ssh connection going through"
|
|
|
|
|
echo "** Warning: a HTTP or SOCKS proxy the ssh connection is vulnerable."
|
|
|
|
|
echo "** Warning: "
|
|
|
|
|
echo "** Warning: You can set the SSVNC_SSH_LOCALHOST_AUTH=1 env. var. to disable"
|
|
|
|
|
echo "** Warning: using the NoHostAuthenticationForLocalhost ssh option."
|
|
|
|
|
echo "** Warning: using the NoHostAuthenticationForLocalhost=yes ssh option."
|
|
|
|
|
echo "** Warning: "
|
|
|
|
|
echo "** Warning: A better solution is to configure (in the SSVNC GUI) the setting:"
|
|
|
|
|
echo "** Warning: 'Options -> Advanced -> Private SSH KnownHosts file' (or set"
|
|
|
|
|
echo "** Warning: SSVNC_KNOWN_HOSTS_FILE directly) to a per-connection known hosts"
|
|
|
|
|
echo "** Warning: file. This yields a both secure and convenient solution."
|
|
|
|
|
echo "** Warning: file. That file holds the 'localhost' cert for this specific"
|
|
|
|
|
echo "** Warning: connection. This yields a both secure and convenient solution."
|
|
|
|
|
echo ""
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -2243,6 +2536,7 @@ if [ "X$use_ssh" = "X1" ]; then
|
|
|
|
|
|
|
|
|
|
nd=`findfree 6600`
|
|
|
|
|
PPROXY_LISTEN=$nd; export PPROXY_LISTEN
|
|
|
|
|
# XXX no reverse forever PPROXY_LOOP_THYSELF ...
|
|
|
|
|
$ptmp &
|
|
|
|
|
sleep 1
|
|
|
|
|
if [ "X$ssh_NHAFL" != "X" -a "X$did_ssh_NHAFL" != "X1" ]; then
|
|
|
|
@ -2633,6 +2927,16 @@ if [ "X$crl" != "X" ]; then
|
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
if [ "X$showcert" = "X1" ]; then
|
|
|
|
|
if [ "X$ipv6" = "X1" -a "X$proxy" = "X" ]; then
|
|
|
|
|
proxy="ipv6://$host:$port"
|
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
if [ "X$direct_connect" != "X" -a "X$STUNNEL_LISTEN" != "X" ]; then
|
|
|
|
|
proxy=reverse_direct
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
ptmp=""
|
|
|
|
|
if [ "X$proxy" != "X" ]; then
|
|
|
|
|
ptmp="/tmp/ss_vncviewer${RANDOM}.$$.pl"
|
|
|
|
@ -2841,9 +3145,22 @@ if [ "X$direct_connect" != "X" ]; then
|
|
|
|
|
PPROXY_LISTEN=$use
|
|
|
|
|
export PPROXY_LISTEN
|
|
|
|
|
else
|
|
|
|
|
PPROXY_REVERSE="$localhost:$use"
|
|
|
|
|
export PPROXY_REVERSE
|
|
|
|
|
pps=3
|
|
|
|
|
if [ "X$proxy" = "Xreverse_direct" ]; then
|
|
|
|
|
PPROXY_LISTEN="$STUNNEL_LISTEN:`expr 5500 + $disp`"
|
|
|
|
|
PPROXY_DEST="$localhost:$use"
|
|
|
|
|
PPROXY_PROXY="ipv6://$localhost:$use" # not always ipv6..
|
|
|
|
|
export PPROXY_LISTEN PPROXY_DEST PPROXY_PROXY
|
|
|
|
|
pps=1
|
|
|
|
|
else
|
|
|
|
|
PPROXY_REVERSE="$localhost:$use"
|
|
|
|
|
export PPROXY_LISTEN
|
|
|
|
|
pps=3
|
|
|
|
|
fi
|
|
|
|
|
if [ "X$SSVNC_LISTEN_ONCE" != "X1" ]; then
|
|
|
|
|
PPROXY_LOOP_THYSELF=`mytmp "/tmp/pproxy_loop_thyself.${RANDOM}.$$"`
|
|
|
|
|
export PPROXY_LOOP_THYSELF
|
|
|
|
|
pps=2
|
|
|
|
|
fi
|
|
|
|
|
if [ "X$SSVNC_EXTRA_SLEEP" != "X" ]; then
|
|
|
|
|
pps=`expr $pps + $SSVNC_EXTRA_SLEEP`
|
|
|
|
|
fi
|
|
|
|
@ -2904,10 +3221,13 @@ if [ "X$direct_connect" != "X" ]; then
|
|
|
|
|
echo ""
|
|
|
|
|
trap "final" 0 2 15
|
|
|
|
|
if [ "X$SSVNC_ULTRA_DSM" != "X" ]; then
|
|
|
|
|
echo "NOTE: The ultravnc_dsm_helper only runs once. So after the first LISTEN"
|
|
|
|
|
echo " ends, you may have to Press Ctrl-C and restart for another connection."
|
|
|
|
|
echo ""
|
|
|
|
|
SSVNC_LISTEN_ONCE=1; export SSVNC_LISTEN_ONCE
|
|
|
|
|
if [ "X$SSVNC_LISTEN_ONCE" = "X1" ]; then
|
|
|
|
|
echo "NOTE: The ultravnc_dsm_helper only runs once. So after the first LISTEN"
|
|
|
|
|
echo " ends you must restart the Listening mode. You may also need to"
|
|
|
|
|
echo " Press Ctrl-C to stop the viewer and restart for another connection."
|
|
|
|
|
echo ""
|
|
|
|
|
fi
|
|
|
|
|
#SSVNC_LISTEN_ONCE=1; export SSVNC_LISTEN_ONCE
|
|
|
|
|
VNCVIEWER_LISTEN_LOCALHOST=1
|
|
|
|
|
export VNCVIEWER_LISTEN_LOCALHOST
|
|
|
|
|
dport=`expr 5500 + $disp`
|
|
|
|
@ -2917,8 +3237,13 @@ if [ "X$direct_connect" != "X" ]; then
|
|
|
|
|
echo
|
|
|
|
|
echo "$ustr &"
|
|
|
|
|
echo
|
|
|
|
|
$cmd &
|
|
|
|
|
dsm_pid=$!
|
|
|
|
|
if [ "X$SSVNC_LISTEN_ONCE" = "X1" ]; then
|
|
|
|
|
$cmd &
|
|
|
|
|
dsm_pid=$!
|
|
|
|
|
else
|
|
|
|
|
while [ 1 ]; do $cmd; sleep 1; done &
|
|
|
|
|
dsm_pid=$!
|
|
|
|
|
fi
|
|
|
|
|
sleep 2
|
|
|
|
|
disp=$use
|
|
|
|
|
if [ $disp -ge 5500 ]; then
|
|
|
|
@ -2935,6 +3260,9 @@ if [ "X$direct_connect" != "X" ]; then
|
|
|
|
|
echo "$VNCVIEWERCMD" "$@" -listen $disp2
|
|
|
|
|
echo ""
|
|
|
|
|
$VNCVIEWERCMD "$@" -listen $disp2
|
|
|
|
|
if [ "X$PPROXY_LOOP_THYSELF" != "X" ]; then
|
|
|
|
|
rm -f $PPROXY_LOOP_THYSELF
|
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
exit $?
|
|
|
|
|
fi
|
|
|
|
@ -2998,6 +3326,8 @@ else
|
|
|
|
|
hloc=""
|
|
|
|
|
if [ "X$use_ssh" = "X1" ]; then
|
|
|
|
|
hloc="$localhost:"
|
|
|
|
|
elif [ "X$STUNNEL_LISTEN" != "X" ]; then
|
|
|
|
|
hloc="$STUNNEL_LISTEN:"
|
|
|
|
|
fi
|
|
|
|
|
if echo "$proxy" | grep -i '^vencrypt:' > /dev/null; then
|
|
|
|
|
hloc="$localhost:"
|
|
|
|
@ -3127,7 +3457,12 @@ else
|
|
|
|
|
if echo "$proxy" | grep -i '^vencrypt:' > /dev/null; then
|
|
|
|
|
pstunnel=`echo "$proxy" | awk -F: '{print $2}'`
|
|
|
|
|
plisten=`echo "$proxy" | awk -F: '{print $3}'`
|
|
|
|
|
PPROXY_LISTEN="INADDR_ANY:$plisten"; export PPROXY_LISTEN
|
|
|
|
|
IF=INADDR_ANY
|
|
|
|
|
if [ "X$STUNNEL_LISTEN" != "X" ]; then
|
|
|
|
|
IF=$STUNNEL_LISTEN
|
|
|
|
|
fi
|
|
|
|
|
PPROXY_VENCRYPT_REVERSE=1; export PPROXY_VENCRYPT_REVERSE
|
|
|
|
|
PPROXY_LISTEN="$IF:$plisten"; export PPROXY_LISTEN
|
|
|
|
|
PPROXY_PROXY="vencrypt://$localhost:$pstunnel"; export PPROXY_PROXY
|
|
|
|
|
PPROXY_DEST="$localhost:$pstunnel"; export PPROXY_DEST
|
|
|
|
|
STUNNEL_ONCE=1; export STUNNEL_ONCE
|
|
|
|
@ -3140,6 +3475,11 @@ else
|
|
|
|
|
if [ $N2_trim -le 200 ]; then
|
|
|
|
|
N2_trim=`expr $N2_trim + 5500`
|
|
|
|
|
fi
|
|
|
|
|
if [ "X$SSVNC_LISTEN_ONCE" != "X1" ]; then
|
|
|
|
|
PPROXY_LOOP_THYSELF=`mytmp "/tmp/pproxy_loop_thyself1.${RANDOM}.$$"`
|
|
|
|
|
export PPROXY_LOOP_THYSELF
|
|
|
|
|
PPROXY_LOOP_THYSELF0=$PPROXY_LOOP_THYSELF
|
|
|
|
|
fi
|
|
|
|
|
env PPROXY_REMOVE=0 PPROXY_SLEEP=0 PPROXY_VENCRYPT_VIEWER_BRIDGE="-$port1,$port2" $ptmp &
|
|
|
|
|
sleep 1
|
|
|
|
|
fi
|
|
|
|
@ -3148,6 +3488,10 @@ else
|
|
|
|
|
PPROXY_SLEEP=1; export PPROXY_SLEEP;
|
|
|
|
|
fi
|
|
|
|
|
PPROXY_KILLPID=+1; export PPROXY_KILLPID;
|
|
|
|
|
if [ "X$SSVNC_LISTEN_ONCE" != "X1" ]; then
|
|
|
|
|
PPROXY_LOOP_THYSELF=`mytmp "/tmp/pproxy_loop_thyself2.${RANDOM}.$$"`
|
|
|
|
|
export PPROXY_LOOP_THYSELF
|
|
|
|
|
fi
|
|
|
|
|
$ptmp &
|
|
|
|
|
# Important to have no extra pids generated between here and VNCVIEWERCMD
|
|
|
|
|
fi
|
|
|
|
@ -3157,6 +3501,13 @@ else
|
|
|
|
|
echo "$VNCVIEWERCMD" "$@" -listen $N2
|
|
|
|
|
echo ""
|
|
|
|
|
$VNCVIEWERCMD "$@" -listen $N2
|
|
|
|
|
|
|
|
|
|
if [ "X$PPROXY_LOOP_THYSELF" != "X" ]; then
|
|
|
|
|
rm -f $PPROXY_LOOP_THYSELF
|
|
|
|
|
fi
|
|
|
|
|
if [ "X$PPROXY_LOOP_THYSELF0" != "X" ]; then
|
|
|
|
|
rm -f $PPROXY_LOOP_THYSELF0
|
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
sleep 1
|
|
|
|
|