# Local Port Forwarding ```bash # LHOST가 생략되면 SSH 클라이언트는 자동으로 localhost로 바인딩 된다. # SERVER_IP는 피벗 또는 대상 호스트 SSH 사용자 및 서버 IP 주소. ssh -L 8080:127.0.0.1:8080 [email protected] # Forwarding multiple ports ssh -L 1234:localhost:3306 -L 8080:localhost:80 [email protected] # -f: backgrounds the shell immediately so that we have our own terminal back. # -N: tells SSH that it doesn't need to execute any commands ssh -L 8000:172.16.0.10:80 [email protected] -fN ``` # Remote Port Forwarding ```bash ssh -R [REMOTE:]<REMOTE_PORT>:DESTINATION:DESTINATION_PORT [USER]@SSH_SERVER ssh -R 2222:172:16.0.200:22 [email protected] -i id_rsa -fN ``` # Dynamic Port Forwarding ```bash ssh -D <LOCAL_PORT> [USER]@SSH_SERVER /etc/proxychains.conf socks4 127.0.0.1 9050 # 아래 명령은 127.0.0.1:9050에 SOCKS5 프록시를 열고, 이 프록시를 통해 전달되는 트래픽은 SSH 터널을 통해 10.129.202.64 서버를 거쳐서 최종 목적지로 전달된다는 뜻 # 127.0.0.1:9050 → SSH → 10.129.202.64 → 내부 네트워크 ssh -D 9050 [email protected] # 이제 proxychains와 nmap을 실행하면 Nmap의 모든 패킷이 로컬 포트 9050으로 라우팅되며, 여기에 SSH 클라이언트가 수신하고 있다가 이 모든 패킷을 SSH를 통해 172.16.5.0/23 네트워크로 전달한다. proxychains nmap -v -sn 172.16.5.1-200 ```