snipt

Ctrl+h for KB shortcuts

Bash

infinite netcat

while true; do echo 'hello world' | netcat -l 80; done
https://snipt.net/embed/357df2b5856d7315e30f1650bf9b6c5d/
/raw/357df2b5856d7315e30f1650bf9b6c5d/
357df2b5856d7315e30f1650bf9b6c5d
bash
Bash
1
2019-06-24T12:14:08
True
False
False
Sep 23, 2013 at 05:07 PM
/api/public/snipt/82705/
infinite-netcat
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="k">while</span> true<span class="p">;</span> <span class="k">do</span> <span class="nb">echo</span> <span class="s1">&#39;hello world&#39;</span> <span class="p">|</span> netcat -l 80<span class="p">;</span> <span class="k">done</span> </span></pre></div> </td></tr></table>
bash, netcat

VimL

Sort by line length in vim

:%s/.*/\=printf("%03d", len(submatch(0)))."|".submatch(0)/ |sor n|
https://snipt.net/embed/a4ef05ccf477e90c082095a889ac6876/
/raw/a4ef05ccf477e90c082095a889ac6876/
a4ef05ccf477e90c082095a889ac6876
vim
VimL
1
2019-06-24T12:14:14
True
False
False
/api/public/snipt/27081/
sort-by-line-length-in-vim
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="p">:</span>%s<span class="sr">/.*/</span>\<span class="p">=</span>printf<span class="p">(</span><span class="s2">&quot;%03d&quot;</span><span class="p">,</span> len<span class="p">(</span>submatch<span class="p">(</span><span class="m">0</span><span class="p">)))</span>.<span class="s2">&quot;|&quot;</span>.submatch<span class="p">(</span><span class="m">0</span><span class="p">)</span>/ <span class="p">|</span><span class="k">sor</span> <span class="k">n</span><span class="p">|</span> </span></pre></div> </td></tr></table>
vim

Bash

Iptables map port 8080 to privileged port 80

sudo iptables -t nat -A PREROUTING -p tcp -m tcp --dport 80 -j REDIRECT --to-ports 8080
sudo iptables -t nat -A OUTPUT -p tcp -m tcp -d $HOST --dport 80 -j REDIRECT --to-ports 8080
https://snipt.net/embed/d35d44e9e9b2cd48611ec5068f81015d/
/raw/d35d44e9e9b2cd48611ec5068f81015d/
d35d44e9e9b2cd48611ec5068f81015d
bash
Bash
2
2019-06-24T12:14:20
True
False
False
/api/public/snipt/17274/
map-port-8080-to-privileged-port-80
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a>sudo iptables -t nat -A PREROUTING -p tcp -m tcp --dport <span class="m">80</span> -j REDIRECT --to-ports 8080 </span><span id="L-2"><a name="L-2"></a>sudo iptables -t nat -A OUTPUT -p tcp -m tcp -d <span class="nv">$HOST</span> --dport <span class="m">80</span> -j REDIRECT --to-ports 8080 </span></pre></div> </td></tr></table>
iptables, linux, nat

SQL

Monitor active PostgreSQL queries against a database

1
2
3
4
SELECT procpid, current_query, waiting
FROM   pg_stat_activity
WHERE  datname = 'your_database_name'
AND    current_query <> '<IDLE>';
https://snipt.net/embed/47684408f6eae77c0384c2e2644d693d/
/raw/47684408f6eae77c0384c2e2644d693d/
47684408f6eae77c0384c2e2644d693d
sql
SQL
4
2019-06-26T07:53:40
True
False
False
/api/public/snipt/13311/
monitor-active-postgresql-queries-against-a-database
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="k">SELECT</span> <span class="n">procpid</span><span class="p">,</span> <span class="n">current_query</span><span class="p">,</span> <span class="n">waiting</span> </span><span id="L-2"><a name="L-2"></a><span class="k">FROM</span> <span class="n">pg_stat_activity</span> </span><span id="L-3"><a name="L-3"></a><span class="k">WHERE</span> <span class="n">datname</span> <span class="o">=</span> <span class="s1">&#39;your_database_name&#39;</span> </span><span id="L-4"><a name="L-4"></a><span class="k">AND</span> <span class="n">current_query</span> <span class="o">&lt;&gt;</span> <span class="s1">&#39;&lt;IDLE&gt;&#39;</span><span class="p">;</span> </span></pre></div> </td></tr></table>
db, psql, query

Bash

Output PostgreSQL command as CSV

psql -F\; -A --pset footer -f input_file.sql -o output_file.csv database_name
https://snipt.net/embed/73e4d7ff8cf84e68e2485ca81586ee45/
/raw/73e4d7ff8cf84e68e2485ca81586ee45/
73e4d7ff8cf84e68e2485ca81586ee45
bash
Bash
1
2019-06-24T12:14:57
True
False
False
/api/public/snipt/9837/
output-postgresql-command-as-csv
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a>psql -F<span class="se">\;</span> -A --pset footer -f input_file.sql -o output_file.csv database_name </span></pre></div> </td></tr></table>
csv, postgresql, psql

Bash

Quick find a manufacturer's OUI

grep -i foundry /usr/share/nmap/nmap-mac-prefixes
https://snipt.net/embed/131333932558a7d000ac413f1c48564f/
/raw/131333932558a7d000ac413f1c48564f/
131333932558a7d000ac413f1c48564f
bash
Bash
1
2019-06-24T12:15:12
True
False
False
/api/public/snipt/7766/
quick-find-a-manufacturers-ouis
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a>grep -i foundry /usr/share/nmap/nmap-mac-prefixes </span></pre></div> </td></tr></table>
macaddr, networking, oui, security