<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>ssh on foosel.net</title><link>https://foosel.net/tags/ssh/</link><description>Recent content in ssh on foosel.net</description><generator>Hugo</generator><language>en-us</language><copyright>Gina Häußge (foosel)</copyright><lastBuildDate>Mon, 28 Aug 2023 00:00:00 +0000</lastBuildDate><atom:link href="https://foosel.net/tags/ssh/feed.xml" rel="self" type="application/rss+xml"/><item><title>How to monitor network traffic on my USG via Wireshark</title><link>https://foosel.net/til/2023-08-28-how-to-monitor-network-traffic-on-my-usg-via-wireshark/</link><pubDate>Mon, 28 Aug 2023 00:00:00 +0000</pubDate><guid>https://foosel.net/til/2023-08-28-how-to-monitor-network-traffic-on-my-usg-via-wireshark/</guid><description>&lt;p&gt;I&amp;rsquo;m currently trying to figure out some internal network issues&lt;sup id="fnref:1"&gt;&lt;a href="#fn:1" class="footnote-ref" role="doc-noteref"&gt;1&lt;/a&gt;&lt;/sup&gt; and for that need to monitor the traffic of a specific device on my network. I&amp;rsquo;m using a Unifi USG as my router (behind the ISP&amp;rsquo;s Fritzbox that I consider hostile since it&amp;rsquo;s not mine). I found &lt;a href="https://www.reddit.com/r/Ubiquiti/comments/ar444z/what_is_the_best_way_to_monitor_traffic_of_a/egkv91p/"&gt;this post on reddit&lt;/a&gt; that explains how to capture traffic on the USG via &lt;code&gt;tcpdump&lt;/code&gt; and send it through the SSH session to Wireshark on my laptop:&lt;/p&gt;</description><content:encoded><![CDATA[<p>I&rsquo;m currently trying to figure out some internal network issues<sup id="fnref:1"><a href="#fn:1" class="footnote-ref" role="doc-noteref">1</a></sup> and for that need to monitor the traffic of a specific device on my network. I&rsquo;m using a Unifi USG as my router (behind the ISP&rsquo;s Fritzbox that I consider hostile since it&rsquo;s not mine). I found <a href="https://www.reddit.com/r/Ubiquiti/comments/ar444z/what_is_the_best_way_to_monitor_traffic_of_a/egkv91p/">this post on reddit</a> that explains how to capture traffic on the USG via <code>tcpdump</code> and send it through the SSH session to Wireshark on my laptop:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>ssh admin@192.168.1.1 <span style="color:#e6db74">&#39;sudo tcpdump -f -i eth1 -w - src 192.168.1.12&#39;</span> | wireshark -k -i - 
</span></span></code></pre></div><p>I could confirm that this works and created a small script to make it easier to use by throwing this into <code>~/.local/bin/gatedump</code><sup id="fnref:2"><a href="#fn:2" class="footnote-ref" role="doc-noteref">2</a></sup>:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span><span style="color:#75715e">#!/bin/bash
</span></span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>ARGS<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;</span>$@<span style="color:#e6db74">&#34;</span>
</span></span><span style="display:flex;"><span>TCPDUMP<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;sudo tcpdump -f -w - </span>$ARGS<span style="color:#e6db74">&#34;</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>ssh usg <span style="color:#e6db74">&#34;</span>$TCPDUMP<span style="color:#e6db74">&#34;</span> | wireshark -k -i -
</span></span></code></pre></div><p>This now allows me to easily run <code>tcpdump</code> remotely with custom arguments, e.g. <code>gatedump -i eth1 host 192.168.1.123</code>, and have it fire up Wireshark automatically. Wish me luck I&rsquo;ll now be able to figure out what&rsquo;s going on on my network, because it&rsquo;s driving me up the wall.</p>
<p><em>Update from 2023-12-06</em>: In case you are wondering how this story ended, the issue resolved itself with the next OS update of my partner&rsquo;s iPhone. So whatever caused it, it&rsquo;s gone now, and I hope for good.</p>
<div class="footnotes" role="doc-endnotes">
<hr>
<ol>
<li id="fn:1">
<p>The iPhone of my partner seems to do something that makes my ISP&rsquo;s router freak out and drop packets every couple of minutes. No issue when he&rsquo;s not here or doesn&rsquo;t have it connected to the WiFi, immediate packet loss when it&rsquo;s on the WiFi. It started at the start of this month and we are both currently out of explanations.&#160;<a href="#fnref:1" class="footnote-backref" role="doc-backlink">&#x21a9;&#xfe0e;</a></p>
</li>
<li id="fn:2">
<p><code>ssh usg</code> does automatically use the correct host, port and user thanks to an entry in <code>~/.ssh/config</code>.&#160;<a href="#fnref:2" class="footnote-backref" role="doc-backlink">&#x21a9;&#xfe0e;</a></p>
</li>
</ol>
</div>
]]></content:encoded></item><item><title>About SSH escape sequences</title><link>https://foosel.net/til/2023-03-22-about-ssh-escape-sequences/</link><pubDate>Wed, 22 Mar 2023 00:00:00 +0000</pubDate><guid>https://foosel.net/til/2023-03-22-about-ssh-escape-sequences/</guid><description>&lt;p&gt;OpenSSH&amp;rsquo;s &lt;code&gt;ssh&lt;/code&gt; command supports a bunch of escape sequences while a session is running, by default triggered by the &lt;code&gt;~&lt;/code&gt; character. According to &lt;a href="https://linux.die.net/man/1/ssh"&gt;&lt;code&gt;man ssh&lt;/code&gt;&lt;/a&gt; a list of available commands can be requested with &lt;code&gt;~?&lt;/code&gt;. And indeed, hitting &lt;code&gt;~?&lt;/code&gt; within an open SSH session prints some helpful information:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-plain" data-lang="plain"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;$ ~?
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;Supported escape sequences:
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; ~. - terminate connection (and any multiplexed sessions)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; ~B - send a BREAK to the remote system
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; ~C - open a command line
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; ~R - request rekey
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; ~V/v - decrease/increase verbosity (LogLevel)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; ~^Z - suspend ssh
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; ~# - list forwarded connections
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; ~&amp;amp; - background ssh (when waiting for connections to terminate)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; ~? - this message
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; ~~ - send the escape character by typing it twice
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;(Note that escapes are only recognized immediately after newline.)
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;I most commonly require &lt;code&gt;~.&lt;/code&gt; to disconnect from a broken SSH session (e.g. something I still had open on my laptop when I sent it to sleep).&lt;/p&gt;</description><content:encoded><![CDATA[<p>OpenSSH&rsquo;s <code>ssh</code> command supports a bunch of escape sequences while a session is running, by default triggered by the <code>~</code> character. According to <a href="https://linux.die.net/man/1/ssh"><code>man ssh</code></a> a list of available commands can be requested with <code>~?</code>. And indeed, hitting <code>~?</code> within an open SSH session prints some helpful information:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"><code class="language-plain" data-lang="plain"><span style="display:flex;"><span>$ ~?
</span></span><span style="display:flex;"><span>Supported escape sequences:
</span></span><span style="display:flex;"><span> ~.   - terminate connection (and any multiplexed sessions)
</span></span><span style="display:flex;"><span> ~B   - send a BREAK to the remote system
</span></span><span style="display:flex;"><span> ~C   - open a command line
</span></span><span style="display:flex;"><span> ~R   - request rekey
</span></span><span style="display:flex;"><span> ~V/v - decrease/increase verbosity (LogLevel)
</span></span><span style="display:flex;"><span> ~^Z  - suspend ssh
</span></span><span style="display:flex;"><span> ~#   - list forwarded connections
</span></span><span style="display:flex;"><span> ~&amp;   - background ssh (when waiting for connections to terminate)
</span></span><span style="display:flex;"><span> ~?   - this message
</span></span><span style="display:flex;"><span> ~~   - send the escape character by typing it twice
</span></span><span style="display:flex;"><span>(Note that escapes are only recognized immediately after newline.)
</span></span></code></pre></div><p>I most commonly require <code>~.</code> to disconnect from a broken SSH session (e.g. something I still had open on my laptop when I sent it to sleep).</p>
<p>The command line opened via <code>~C</code> is quite interesting as well, as it allows configuration of port forwards on the fly, while the session is already running:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"><code class="language-plain" data-lang="plain"><span style="display:flex;"><span>ssh&gt; help
</span></span><span style="display:flex;"><span>Commands:
</span></span><span style="display:flex;"><span>      -L[bind_address:]port:host:hostport    Request local forward
</span></span><span style="display:flex;"><span>      -R[bind_address:]port:host:hostport    Request remote forward
</span></span><span style="display:flex;"><span>      -D[bind_address:]port                  Request dynamic forward
</span></span><span style="display:flex;"><span>      -KL[bind_address:]port                 Cancel local forward
</span></span><span style="display:flex;"><span>      -KR[bind_address:]port                 Cancel remote forward
</span></span><span style="display:flex;"><span>      -KD[bind_address:]port                 Cancel dynamic forward
</span></span></code></pre></div><p>This is once again a &ldquo;TIL&rdquo; that I didn&rsquo;t actually learn about only today, but I keep forgetting about it and then need to frantically google whenever I need it. I hope this way I&rsquo;ll finally remember this stuff 😅</p>
]]></content:encoded></item></channel></rss>