{"id":773,"date":"2021-06-13T22:25:45","date_gmt":"2021-06-14T02:25:45","guid":{"rendered":"https:\/\/www.unliterate.net\/?p=773"},"modified":"2021-06-13T22:26:29","modified_gmt":"2021-06-14T02:26:29","slug":"ssh-port-forwarding-ssh-tunneling","status":"publish","type":"post","link":"https:\/\/www.unliterate.net\/index.php\/2021\/06\/13\/ssh-port-forwarding-ssh-tunneling\/","title":{"rendered":"ssh port forwarding \/ ssh tunneling"},"content":{"rendered":"\n<p>I&#8217;ve always been curious on ssh port forwarding enough to experiment and learn it to be deadly enough. I currently have two machines that I&#8217;d like to test this with, both -L (local) and -R (remote).<\/p>\n\n\n\n<p>I have a C7 host behind a router and a C8 host on the internet that I&#8217;ll be testing with.<\/p>\n\n\n\n<p>Our set up is the following:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>192.168.2.222:22 (c7 Host) &lt;-> 192.168.2.1:* (router) &lt;-> 159.203.99.198:22 (c8 host)<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Local Forwarding<\/h2>\n\n\n\n<p>What I&#8217;m going to do is forward port 4444 on my c7 machine to connect to the c8 host on port 22 by launching the following on 192.168.2.222:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ ssh -L 192.168.2.222:4444:159.203.99.198:22 localhost<\/code><\/pre>\n\n\n\n<p>At this point I can start a SSH session to 192.168.2.222 at port 4444. I&#8217;m prompted to log in at 159.203.99.198, and i&#8217;m good to go. As long as the command is running I maintain a connection.<\/p>\n\n\n\n<p>To remove the login necessity I added ~\/.ssh\/id_rsa.pub to ~\/.ssh\/authorized_keys for passwordless local log in.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Remote Forwarding<\/h2>\n\n\n\n<p>Remote forwarding allows world-accessible hosts to provide access to internal hosts. In our previous scenario we forwarded from an intranetwork host to a world host. Now we&#8217;re gonna use that intranetwork host and make it so that if we SSH to the world host at port 4444 that we will be ssh-ing to our intranetwork host, bypassing the router.<\/p>\n\n\n\n<p>On 192.168.2.222 I execute the following:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ ssh -R 4444:localhost:22 159.203.99.198 -ldiffuser<\/code><\/pre>\n\n\n\n<p>On my world-accessible host I log in with &#8220;diffuser&#8221;, and the forwarding is set up.<\/p>\n\n\n\n<p>On 159.203.99.198 I can ssh to localhost:4444 and connect as internaluser with ease:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ ssh localhost -p 4444 -linternaluser<\/code><\/pre>\n\n\n\n<p>Due to how \/etc\/ssh\/sshd_config has <a href=\"https:\/\/www.ssh.com\/academy\/ssh\/tunneling\/example\" target=\"_blank\" rel=\"noreferrer noopener\">GatewayPorts set up by default<\/a> I cannot connect with my home computer to my world-accessible host. I would have to restart sshd service after setting GatewayPorts=yes (by default it&#8217;s no)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve always been curious on ssh port forwarding enough to experiment and learn it to be deadly enough. I currently have two machines that I&#8217;d like to test this with, both -L (local) and -R (remote). I have a C7 host behind a router and a C8 host on the internet that I&#8217;ll be testing [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[19,20,17],"tags":[],"class_list":["post-773","post","type-post","status-publish","format-standard","hentry","category-centos","category-geek-instructions","category-linux"],"_links":{"self":[{"href":"https:\/\/www.unliterate.net\/index.php\/wp-json\/wp\/v2\/posts\/773","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.unliterate.net\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.unliterate.net\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.unliterate.net\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.unliterate.net\/index.php\/wp-json\/wp\/v2\/comments?post=773"}],"version-history":[{"count":1,"href":"https:\/\/www.unliterate.net\/index.php\/wp-json\/wp\/v2\/posts\/773\/revisions"}],"predecessor-version":[{"id":774,"href":"https:\/\/www.unliterate.net\/index.php\/wp-json\/wp\/v2\/posts\/773\/revisions\/774"}],"wp:attachment":[{"href":"https:\/\/www.unliterate.net\/index.php\/wp-json\/wp\/v2\/media?parent=773"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.unliterate.net\/index.php\/wp-json\/wp\/v2\/categories?post=773"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.unliterate.net\/index.php\/wp-json\/wp\/v2\/tags?post=773"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}