브리지에서 http 프록시로 트래픽 리디렉션

브리지에서 http 프록시로 트래픽 리디렉션

이더넷 브리지의 새 인스턴스를 생성하는 경우:

# brctl addbr br1
# ip link set dev br1 up
# ip addr add 10.100.100.1/24 dev br1

기본 포트 8888에서 tinyproxy수신 대기를 시작합니다 .localhost

# tinyproxy

새 네트워크 네임스페이스를 생성 하고 firejail이를 브리지에 연결합니다.

# firejail --net=br1 /bin/bash

tinyproxy그런 다음 브리지를 통해 트래픽을 어떻게 라우팅하여 샌드박스 curl내에서 웹 페이지를 가져올 수 있습니까 firejail?

# curl --proxy http://10.100.100.1:8888 http://wtfismyip.com/text

답변1

다음 명령은 체인을 플러시/삭제하고 비활성화하는 데 유용합니다 ufw.

# /lib/ufw/ufw-init flush-all

이더넷 브리지를 만듭니다.

ext_if="enp8s8"
bridge="brtp8888"
proxy_port="8888"  # tinyproxy default

brctl addbr "${bridge}"
ip link set dev "${bridge}" up
ip addr add 10.100.100.1/24 dev "${bridge}"
# Allow the bridge to route traffic to localhost
sysctl net.ipv4.conf."${bridge}".route_localnet=1

브리지의 포트 8888에서 전달되는 TCP 트래픽을 다음을 통해 라우팅합니다 tinyproxy.

iptables -t nat -A PREROUTING -i "${bridge}" -p tcp -j DNAT --to-destination 127.0.0.1:"${proxy_port}"
iptables -t nat -A POSTROUTING -s 10.100.100.0/24 -o eth0 -j MASQUERADE

(NB 위의 내용은 다음에서 수정되었습니다.Tor HOWTO를 사용한 Firejail.)

Tinyproxy는 localhost구성 줄이 없으면 다음과 같이 연결을 제한합니다 /etc/tinyproxy.conf.

Allow 10.100.100.0/24

보다 완전한 iptables 규칙 세트:

iptables -P INPUT DROP
iptables -P FORWARD DROP
iptables -P OUTPUT ACCEPT

iptables -A INPUT -i lo -j ACCEPT
iptables -A INPUT -m state --state INVALID -j DROP
iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT

iptables -A INPUT -i "${bridge}" -p tcp --dport "${proxy_port}" -j ACCEPT
iptables -t nat -A PREROUTING -i "${bridge}" -p tcp -j DNAT --to-destination 127.0.0.1:"${proxy_port}"  # tinyproxy default
iptables -t nat -A POSTROUTING -s 10.100.100.0/24 -o eth0 -j MASQUERADE

이에 ufw상응하는 것:

## Copy the following into /etc/ufw/before.rules (see man ufw-framework, 'Port Redirections')
# *nat
# :PREROUTING ACCEPT [0:0]
# -A PREROUTING -p tcp -i brtp8888 --dport 8888 -j DNAT \
#   --to-destination 127.0.0.1:8888
# COMMIT
# *nat
# :POSTROUTING ACCEPT [0:0]
# -A POSTROUTING -s 10.100.100.0/24 -o eth0 -j MASQUERADE
# COMMIT

ufw allow in on "${bridge}" from 10.100.100.0/24 proto tcp

이 게시물도 참조하세요Firejail 및 호스트 OpenVPN 클라이언트를 통해 인터넷에 연결.

위에 설명된 대로 브리지를 만드는 이유를 설명할 수 있는 사람이 있다면 Firefox를 실행하는 샌드박스를 열고 --net=br1Firefox의 HTTP 프록시를 게이트웨이 IP(예: br1모든 포트)로 설정하는 것도 효과가 있다는 것을 알고 싶습니다.

관련 정보