我正在互联网论坛上进行跨站点脚本攻击,可以将链接放在帖子中
[url]http://google.com[/url]
然后以
的形式浮出水面<a href="http://google.com">http://google.com</a>
在论坛的主题上。如果可能,我想使用通过href
调用JavaScript函数的技术,即
<script type="text/javascript">
function sayHello ( )
{
alert("Hello");
}
</script>
<a href="javascript:sayHello()">Clicking here alerts "Hello"</a>
但由于我没有办法使用预定义的JavaScript函数,我想知道我是否可以在其中放置匿名函数,例如。
<a href="javascript:function(){alert('Hellow');}">Clicking here alerts "Hello"</a>
我已经在记事本中使用简单的页面
对此进行了测试<html>
<head>
</head>
<body>
<div>
<p>Clicking on <a href="javascript:function(){alert('Hello');}">this</a> will alert "Hello""</p>
</div>
</body>
</html>
但它没有用。
对我有什么建议吗?
答案 0 :(得分:2)
使用IIFE:
<a href="javascript:(function(){stuff to do})()">Click here</a>
虽然没有IIFE就没有太大的区别,就像顶级JS代码一样:
<a href="javascript:stuff to do">Click here</a>
唯一重要的区别是你可以在函数中声明局部变量。