• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Php防跨站分析

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

今天在改bug时,发现同事写的代码里存在跨站漏洞,于是加了个php防跨站函数htmlentities()。

因为以前也没有认真分析过此函数,翻了下文档,想了解透测点。

Htmlentities() 转化所有适当字符为html实体

  函数说明:

string htmlentities ( string $string [, int $flags = ENT_COMPAT [, string $charset [, bool $double_encode = true ]]] )

 

string :为输入需转换的字符

flags :和htmlspecialchars()一样,第二个参数允许你定义单双引号将做什么。它需要是默认常数ENT_COMPAT的三个参数之一,可以结合第四个ENT_IGNORE

ENT_COMPAT

Will convert double-quotes and leave single-quotes alone.

ENT_QUOTES

Will convert both double and single quotes.

ENT_NOQUOTES

Will leave both double and single quotes unconverted.

ENT_IGNORE

Silently discard invalid code unit sequences instead of returning an empty string. Added in PHP 5.3.0. This is provided for backwards compatibility; avoid using it as it may have security implications.

charset :与htmlspecialchars()一样 ,它带有一个可选的第三个参数做为字符集转换,目前,默认ISO-8859-1字符集

支持的字符集列表

字符集

别名

描述

ISO-8859-1

ISO8859-1

西欧,Latin-1

ISO-8859-15

ISO8859-15

西欧,Latin-9。增加欧元符号,法语和芬兰语字母在 Latin-1(ISO-8859-1) 中缺失。

UTF-8

 

ASCII 兼容的多字节 8 位 Unicode。

cp866

ibm866, 866

DOS 特有的西里尔编码。本字符集在 4.3.2 版本中得到支持。

cp1251

Windows-1251, win-1251, 1251

Windows 特有的西里尔编码。本字符集在 4.3.2 版本中得到支持。

cp1252

Windows-1252, 1252

Windows 特有的西欧编码。

KOI8-R

koi8-ru, koi8r

俄语。本字符集在 4.3.2 版本中得到支持。

BIG5

950

繁体中文,主要用于中国 台@@湾 省。

GB2312

936

简体中文,中国国家标准字符集。

BIG5-HKSCS

 

繁体中文,附带香港扩展的 Big5 字符集。

Shift_JIS

SJIS, 932

日语

EUC-JP

EUCJP

日语

 

double_encode :当double_encode为关闭状态,php默认将一切都转换为html实体

 

返回值

返回已经编码的字符串

 html_entity_decode()与htmlentities()为反向函数,一个解码,一个编码。

 但是如果出现没有这些字符集呢?那么这个函数就不起作用了。那起不悲剧,于是还是自己再写个函数过滤下吧。

function inxss($url)
{
$arr = array('http','script','iframe','com','www');//过江的字符,呵,自由发挥吧。最好用正则处理,因为我的是在iframe的跨站,其实只要针对着不让它传入http://。。。这些url进来就行了
foreach($arr as $value)
{
if( strstr($url,$value))
{
exit;
}
else
{
return $url;
}
}
}
$url = htmlentities(inxss($_GET["url"]));双重过虑。呵

这样的话应该可以多了点安全

 

 

 

 


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP图片操作类发布时间:2022-07-10
下一篇:
php用urlencode、urldecode解决汉字乱码问题发布时间:2022-07-10
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap