OffSec Notes
  • Offensive Security Notes
    • Linux/Unix
      • Checklist - PrivEsc
        • Related Links
        • Kernel Exploits
        • MYSQL
          • HEX
        • SUID
        • Relative Path in SUID Program
        • Writable /etc/passwd file
        • Writable script in /etc/crontab
        • Writable services
        • Sudo <=1.8.14
        • Debian OpenSSL Predictable PRNG Bruteforce SSH Exploit
        • Docker
          • Docker Escape
        • davfs2
        • gcore
        • fail2ban
        • git
        • tar with wildcard
        • Exiftool
      • Limited Shell Escape
      • Wordpress
      • Apache Tomcat
      • Werkzeug Console PIN bypass
        • get_flask_pin.py
      • Java Object Deserialization
      • Redis RCE
      • mongodb
      • Postgres
      • Erlang - 4369
      • rsync - 873
      • Sendmail ClamAV
      • VNC Password Decryptor
    • Windows
      • Checklist - PrivEsc
        • MSSQL
        • PsExec.exe
        • Build Exploits
        • Unquoted Service Paths
        • SeImpersonateToken
        • SeRestorePrivilege
        • SeBackupPrivilege
        • Abuse GPO
        • Job with editable file
        • AlwaysInstallElevated
        • Misconfigured LDAP
        • GMSA
        • MS17-010
      • Useful PS Scripts
        • GetUserSPNs.ps1
        • Master MDF Hash Extraction
        • Spray-Passwords.ps1
      • Password Extraction
      • Office Macro
        • Microsoft Office
        • Open Office
      • Post Exploitation
    • Web
      • SQL Injection
        • mongodb 2.2.3
        • UNION BASED
          • MSSQL
          • Oracle
        • ERROR BASED
        • node.js
    • Nmap samples
    • Shells
      • node.js
      • msfvenom samples
      • Reverse Shells
      • Shellter
    • Enumeration
      • SMB
      • RPC
      • LDAP
    • Buffer Overflow
      • mona
      • fuzzer.py
      • exploit.py
      • bytearray.py
      • pattern_offset.rb
      • pattern_create.rb
    • Password Cracking
    • File Download
      • FTP
    • Port Forwarding
      • Dynamic Forwarding
    • Useful links
  • Blog
    • CRTO I & II
    • OSCP Preparation
    • New OSCP Exam vs Previous OSCP Exam
    • Movements in AD
    • PWK Lab vs PG Practice
  • PortSwigger Academy
    • Server-side topics
      • Authentication vulnerabilities
      • OS Command Injection
      • File Path Traversal
      • Business logic vulnerabilities
      • Information disclosure vulnerabilities
      • Access control vulnerabilities and privilege escalation
      • File upload vulnerabilities
      • Server-side request forgery (SSRF)
      • XML external entity (XXE) injection
    • Client-side topics
      • Cross-site scripting
      • Cross-origin resource sharing (CORS)
      • Cross-site request forgery (CSRF)
      • Clickjacking (UI redressing)
      • DOM-based vulnerabilities
      • Testing for WebSockets security vulnerabilities
    • Advanced topics
      • Insecure deserialization
      • Server-side template injection
      • Web cache poisoning
      • HTTP Host header attacks
      • HTTP request smuggling
      • OAuth 2.0 authentication vulnerabilities
      • JWT attacks
  • Walkthroughs
    • PG Practice
      • Linux
        • WARM UP
          • Bratarina
          • ClamAV
          • Exfiltrated
          • Hawat
          • Interface
          • Muddy
          • Pebbles
          • Twiggy
          • Wombo
        • GET TO WORK
          • Banzai
          • Cassios
          • Dibble
          • Fail
          • G00g
          • Hetemit
          • Hunit
          • Maria
          • Nappa
          • Nibbels
          • Nukem
          • Payday
          • Pelican
          • Readys
          • Roquefort
          • Snookums
          • Sorcerer
          • Splodge
          • Sybaris
          • Walla
          • Webcal
          • XposedAPI
          • ZenPhoto
          • Zino
          • QuackerJack
        • TRY HARDER
          • Clyde
          • Peppo
          • Sirol
      • Windows
        • WARM UP
          • Algernon
          • Compromised
          • Helpdesk
          • Internal
          • Kevin
          • Metallus
        • GET TO WORK
          • AuthBy
          • Billyboss
          • Craft
          • Fish
          • Hutch
          • Jacko
          • Nickel
          • Shenzi
          • Slort
        • TRY HARDER
          • Heist
          • Meathead
          • Vault
      • Template
  • About the author
Powered by GitBook
On this page
  • ON TARGET MACHINE
  • ON LOCAL MACHINE
  • ON TARGET MACHINE
  • ON LOCAL MACHINE
  1. Offensive Security Notes
  2. Port Forwarding

Dynamic Forwarding

Port Forwarding From Target Machine With SSH - Secure Way - Specify Ports with -R Option

ON TARGET MACHINE

cd /tmp
mkdir keys
ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/var/www/.ssh/id_rsa): /tmp/keys/id_rsa
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /tmp/keys/id_rsa.
Your public key has been saved in /tmp/keys/id_rsa.pub.
The key fingerprint is:
SHA256:p8BVmFym2cu0ORHMAZ4xxXDqHMbow9lkc6BXGfPbITI www-data@test
The key's randomart image is:
+---[RSA 2048]----+
|       .*@%+     |
|       =+#=+     |
|      o / E o .  |
|     + @ * B + . |
|      B S B . .  |
|       o o .     |
|        .        |
|                 |
|                 |
+----[SHA256]-----+
cd keys
ls
id_rsa
id_rsa.pub
cat id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDW6xqIeLknr+RcRMTYkkmMJZcHiZXVT7AxIKu8KMPeieZ+g8yMsBGeeeF4igNQOcOlPuYyY6HoMPGIThVxQBT5uPNQANAUGQE5MmZXTytkOzztYMxtPq3TjxhBxbd6rmEK/ApqREVo9NoGCi4TibfOuCpy3iY18w46F/bUzj2r2STytHvaUBhkS6pMh11WE18XC+ZQea0zOrRm6Nu+eDn3mwOYIaL4RHPKbnT6g55UzV8qNjtZRDRpkUww5SQwQIjoibgbZ0Qr/wT864kVUgOuthOKqJanwkKIo+URRp7c6E8i5d6y1CZIHU7touPEucJXFgfCdeda9PCDUpedlI39 www-data@test

ON LOCAL MACHINE

$ cat ~/.ssh/authorized_keys
from="192.168.1.2",command="echo 'This account can only be used for port forwarding'",no-agent-forwarding,no-X11-forwarding,no-pty ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDW6xqIeLknr+RcRMTYkkmMJZcHiZXVT7AxIKu8KMPeieZ+g8yMsBGeeeF4igNQOcOlPuYyY6HoMPGIThVxQBT5uPNQANAUGQE5MmZXTytkOzztYMxtPq3TjxhBxbd6rmEK/ApqREVo9NoGCi4TibfOuCpy3iY18w46F/bUzj2r2STytHvaUBhkS6pMh11WE18XC+ZQea0zOrRm6Nu+eDn3mwOYIaL4RHPKbnT6g55UzV8qNjtZRDRpkUww5SQwQIjoibgbZ0Qr/wT864kVUgOuthOKqJanwkKIo+URRp7c6E8i5d6y1CZIHU7touPEucJXFgfCdeda9PCDUpedlI39 www-data@test

$ sudo systemctl start ssh.service

ON TARGET MACHINE

ssh -f -N -R 1122:10.10.10.10:22 -R 13306:10.10.10.10:3306 -o "UserKnownHostsFile=/dev/null" -o "StrictHostKeyChecking=no" -i /tmp/keys/id_rsa cel1s0@192.168.1.1
Warning: Permanently added '192.168.1.1' (ECDSA) to the list of known hosts.
cel1s0@192.168.1.1's password: 

ON LOCAL MACHINE

$ netstat -tulpn        
(Not all processes could be identified, non-owned process info
 will not be shown, you would have to be root to see it all.)
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
LISTEN      -                   
tcp        0      0 127.0.0.1:13306         0.0.0.0:*               LISTEN      -                   
tcp        0      0 127.0.0.1:1122          0.0.0.0:*   
PreviousPort ForwardingNextUseful links

Last updated 3 years ago