Skip to content

TCP proxy

matveynator edited this page Apr 29, 2023 · 6 revisions

xinetd TCP PROXY:

apt-get install -y xinetd

cat > /etc/xinetd.d/8888 <<EOF
service 8888
{
 disable = no
 type = UNLISTED
 socket_type = stream
 protocol = tcp
 wait = no
 redirect = 10.9.8.7 8888
 bind = 0.0.0.0
 port = 8888
 user = nobody
}
EOF;

systemctl reload xinetd

proxy 80 and 443 port interactive script

#!/bin/bash

apt-get -y install socat net-tools &> /dev/null
echo "============================"
echo "Please enter destination ip:"
read DST_IP

[ "${DST_IP}" == "" ] && echo "empty ip!" && exit 1

echo "stopping nginx and apache..."
/etc/init.d/nginx stop
/etc/init.d/apache2 stop
echo "done."

echo "proxying with socat to ${DST_IP} ..."

socat TCP4-LISTEN:80,fork TCP4:${DST_IP}:80 &
socat TCP4-LISTEN:443,fork TCP4:${DST_IP}:443 &

echo "done"

netstat -lpan |grep 80 |grep socat
netstat -lpan |grep 443 |grep socat

proxy 80 port

socat TCP4-LISTEN:80,fork TCP4:${DST_IP}:80

proxy 443 port

socat TCP4-LISTEN:443,fork TCP4:${DST_IP}:443
Clone this wiki locally