-
Notifications
You must be signed in to change notification settings - Fork 0
TCP proxy
matveynator edited this page Jun 17, 2023
·
6 revisions
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
!/bin/bash
apt-get update
apt-get install -y xinetd
echo ""
echo "Enter destination host or IP:"
read dst_host
echo ""
echo "Enter destination ports (e.g., 80 443 19091 19092 20002 20001 20101):"
read ports
echo ""
echo "OK: host=${dst_host}; ports=${ports};"
echo "Press any key to continue or CTRL+C to abort..."
read -n 1 -s
for port in $ports; do
echo "tcp proxy (/etc/xinetd.d/${port}): 0.0.0.0:${port} -> ${dst_host}:${port}"
cat > /etc/xinetd.d/$port <<EOF
service ${port}
{
disable = no
type = UNLISTED
socket_type = stream
protocol = tcp
wait = no
redirect = $dst_host $port
bind = 0.0.0.0
port = $port
user = nobody
}
EOF
systemctl reload xinetd
netstat -lpan |grep $port
done
#!/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
socat TCP4-LISTEN:80,fork TCP4:${DST_IP}:80
socat TCP4-LISTEN:443,fork TCP4:${DST_IP}:443