csrf

中间件、csrf跨站请求伪造、Auth模块

☆樱花仙子☆ 提交于 2019-11-30 12:32:04
Django中间件 1、什么是中间件? 官方的说法:中间件是一个用来处理Django的请求和响应的框架级别的钩子。它是一个轻量、低级别的插件系统,用于在全局范围内改变Django的输入和输出。每个中间件组件都负责做一些特定的功能 说的直白一点中间件是帮助我们 在视图函数执行之前和执行之后都可以做一些额外的操作 ,它本质上就是一个自定义类,类中定义了几个方法,Django框架会在请求的特定的时间去执行这些方法。 我们一直都在使用中间件,只是没有注意到而已,打开Django项目的Settings.py文件,看到下图的MIDDLEWARE配置项。 默认的七个中间件: MIDDLEWARE = [ 'django.middleware.security.SecurityMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware

Pikachu漏洞练习平台实验——CSRF(三)

情到浓时终转凉″ 提交于 2019-11-30 12:12:38
概述   - 攻击场景例子   - CSRF攻击需要条件   - CSRF和XSS的区别   - 如何确认一个目标站点是否有CSRF漏洞 CSRF(get) CSRF(post) CSRF(token) 防护措施 概述 CSRF 是 Cross Site Request Forgery 的 简称,中文名为 跨域请求伪造 在CSRF的攻击场景中, 攻击者会伪造一个请求(一般是一个链接) 然后欺骗目标用户进行点击,用户一旦点击了这个请求,这个攻击也就完成了 所以CSRF攻击也被称为“one click”攻击 攻击场景例子 lucy想要在购物网站上 修改购物地址 ,这个操作是lucy通过浏览器向后端发送了请求。 这个请求里面包含了lucy的新有货地址,如果是通过GET提交的,那么会以URL传参的方式的方式将新的地址提交给后台,类似上图中的URL, 相当于点了链接就能修改个人信息 。 如果这时候攻击者想要修改lucy的信息怎么办?那么他需要取得lucy的账号, 获得登录权限 。这时候他可以将修改个人信息的 请求伪造 一下,构造类似下图中的URL,引诱lucy在登录状态下进行点击,这样攻击就成功了。 CSRF攻击需要条件 ① 目标网站没有对修改个人信息修改的请求进行防CSRF处理,导致该请求容易被伪造 因此,判断一个网站有没有CSRF漏洞,其实就是判断对关键信息(密码等)的操作(增删改

what is the difference between X-XSRF-TOKEN and X-CSRF-TOKEN?

陌路散爱 提交于 2019-11-30 11:59:49
When use hidden field and when use header and why ? X-XSRF_TOKEN when we use? X-CSRF TOKEN when we use? when you are submitting your data using ajax you will need headers for CSRF token because ajax will not send the token along with the data. You can use hidden field for ajax request with following code $.ajaxSetup( { headers: { 'X-CSRF-Token': $('input[name="_token"]').val() } }); but you will have to add hidden field for every ajax requests. The difference between the X-CSRF-TOKEN and X-XSRF-TOKEN is that the first uses a plain text value and the latter uses an encrypted value, because

CSRF tokens vs Nonce confusion - are they the same?

佐手、 提交于 2019-11-30 11:58:11
In a attempt to make the current application I'm developing more secure, I've been reading about CSRF tokens and also Nonce. My question simply is, Are CSRF tokens and Nonce the same thing? from what I could gather so far is that both these methods have different techniques to accomplish the same goal, or am I misunderstanding something? If they are different, could you be nice enough to provide some example code or point me to some links where i can learn more about how to implementing nonces in PHP apps. Thanks! zerkms Nonce is usually some random string that is added to request just to

Rails 5 API protect_from_forgery

佐手、 提交于 2019-11-30 11:56:46
问题 I have a Rails 5 API app ( ApplicationController < ActionController::API ). The need came up to add a simple GUI form for one endpoint of this API. Initially I was getting ActionView::Template::Error undefined method protect_against_forgery? when I tried to render the form. I added include ActionController::RequestForgeryProtection and protect_from_forgery with:exception to that endpoint. Which solved that issue as expected. However, when I try to submit this form I get: 422 Unprocessable

How to prevent automated AJAX attacks

时间秒杀一切 提交于 2019-11-30 10:06:00
How to prevent USER from doing automated posts/spam? Here is my way of doing it, new php session for each page request, which has its own limitations, no multitabing. I used new session for each page as defense against both CSRF and automated attacks. Lets say we have forum that uses AJAX to post threads and its validated by PHP SESSION. add_answer.php?id=123 <?php if(!is_ajax()){// function that determines whether the request is from ajax (http header stuff) $_SESSION['token'] = md5(rand()); } //some ajax request to ajax.php?id=123 ?> ajax.php?id=123 <?php if($_SESSION['token'] == $_GET[

ng2 get csrf token from cookie post it as header

孤人 提交于 2019-11-30 09:39:09
After spending 2 full days searching the web and reading docs and tons of open questions of people facing the same problem, i still don't grasp how Angular 2 handles the (x-origin) cookies and how to access them. The problem: Back-end sends 2 cookies with x-csrf-token & JSESSIONID inside of it. My job is to keep the csrf token in memory (ng2) and send it (only) back as header (not cookie) with every post to the back-end. HTTP/1.1 200 OK Server: Apache-Coyote/1.1 Access-Control-Allow-Origin: http://localhost:4200 Access-Control-Allow-Credentials: true Access-Control-Expose-Headers: Access

Symfony 1.4: Custom error message for CSRF in forms

99封情书 提交于 2019-11-30 09:27:26
Can anyone tell me where/how to customise the CSRF token error message for forms in Symfony 1.4. I'm using sfDoctrineGuard for logins and in this form particularly, whenever a session runs out and you still have the page open, it throws a very user-unfriendly error: "CSRF attack detected". Something like "This session has expired. Please return to the home page and try again" sounds better. What's the right way to do this in the form class? Thanks. The only way seems to be to overwrite sfForm::addCSRFProtection() . In /lib/form/BaseForm.class.php you can add this piece of code: class BaseForm

Cakephp Security

此生再无相见时 提交于 2019-11-30 09:09:51
I am new to Security of Web apps. I am developing an application in Cakephp and one of my friends told me about the Cross-site request forgery (CSRF) and cross-site scripting (XSS) attacks etc. not sure how many more are there. I need some help in understanding how to make Cakephp defend my web app against these. we are low budget and we cant hire a security consulant as of now. We are still developing the app and plan to release in by the end of the month. so wanna take care of the initial stuff that can help me stand un hacked ;) There is not (and cannot be) one tool you can deploy and then

Difference between CSRF and X-CSRF-Token

ぃ、小莉子 提交于 2019-11-30 08:58:56
What is the difference between use X-CSRF-Token in header or token in hidden field ? When use hidden field and when use header and why? I think that X-CSRF-Token is when i'm using javascript/ajax but im not sure CSRF protection comes in a number of methods. The traditional way ( the "Synchronizer token" pattern ) usually involves setting a unique valid Token value for each request and then verifying that unique value when the request is subsequently sent in. It is usually done by setting a hidden form field. The token value is usually short lived and associated to that session, so if a hacker