我们真的能免受 CSRF 的影响吗?

发布于 2024-11-28 00:10:09 字数 1376 浏览 1 评论 0 原文

确认.php

<前><代码>
> 您真的要删除吗? <输入类型=“提交”值=“是”/> >

inform_save.php

<?php
 session_start();
 $token= $_SESSION['delete_customer_token'];
 unset($_SESSION['delete_customer_token']);
 session_write_close();
 if ($_POST['token']==$token) {
   // delete the record
 } else {
   // log potential CSRF attack.
 }
?>

假设我们有一个像这样的典型 CSRF 保护 如果攻击者使用此代码绕过 csrf 令牌怎么办?

//On any site
<img src="http://cia.teletubbies.com/csrf.php" height="0" weight="0"/>

//csrf.php
$cont = get_file_contents("http://cia.google.com/confirm.php");
// parse the html using [PHP Simple HTML DOM Parser][2] and get the CSRF token
//CURL and send a POST request to confirm_save.php with the token

这件事一直困扰着我,但我懒得尝试对任何随机站点进行攻击。这不是可能吗?

示例代码是从阻止 php 中的 csrf 中窃取的

已更新

当有人想要将令牌从一个平台传递到另一个平台或从服务器端传递到客户端时会发生什么?以Flash到PHP为例,它如何免受csrf的影响?

confirm.php

<?php
 session_start();
 $token= md5(uniqid());
 $_SESSION['delete_customer_token']= $token;
 session_write_close();
?>
<form method="post" action="confirm_save.php">
<input type="hidden" name="token" value="<?php echo $token; ?>" />
Do you really want to delete?
<input type="submit" value=" Yes " />
<input type="button" value=" No " onclick="history.go(-1);" />

confirm_save.php

<?php
 session_start();
 $token= $_SESSION['delete_customer_token'];
 unset($_SESSION['delete_customer_token']);
 session_write_close();
 if ($_POST['token']==$token) {
   // delete the record
 } else {
   // log potential CSRF attack.
 }
?>

Lets say we have a typical CSRF protection like this one
What if an attacket uses this code to bypass the csrf token?

//On any site
<img src="http://cia.teletubbies.com/csrf.php" height="0" weight="0"/>

//csrf.php
$cont = get_file_contents("http://cia.google.com/confirm.php");
// parse the html using [PHP Simple HTML DOM Parser][2] and get the CSRF token
//CURL and send a POST request to confirm_save.php with the token

This thing keeps bugging me, but im too lazy to try an attack on any random site. Isnt this is possible?

The example code was stolen from preventing csrf in php

Updated

What happens when someone wants to pass a token from one platform to another or from server side to the client side? Flash to PHP for instance, how could its secure from csrf?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

流年已逝 2024-12-05 00:10:09

您将获得用于抓取页面的服务器会话的 CSRF 令牌。由于该会话不是受害者的会话,因此它是安全的。 (如果您窃取了用户的会话,那么它就不再是 CSRF 攻击!)

所以,是的,除非实施得很糟糕,否则您不能只是抓取 CSRF 令牌并将其用于 CSRF 攻击。

You'd be getting the CSRF token for the session of the server you are using to scrape the page. Since that session is not the victim's, it's secure. (If you're stealing the user's session, it's no longer a CSRF attack!)

So, yes, unless it's implemented horribly, you can't just scrape a CSRF token and use it in a CSRF attack.

明媚殇 2024-12-05 00:10:09

CSRF 保护有效,因为只有经过身份验证的用户才能访问令牌。

您的 csrf.php 页面位于另一个域中,因此无法看到合法站点的会话 cookie,也无法获取 CSRF 令牌。

The CSRF protection works since only the authenticated user can access the token.

Your csrf.php page is on another domain, and can thus not see session cookies for the legitimate site, nor get to the CSRF token.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文