csrf

CSRF漏洞

蓝咒 提交于 2019-12-02 20:25:18
CSRF漏洞原理: CSRF是跨站请求伪造,不攻击网站服务器,而是冒充用户在站内的正常操作。通常由于服务端没有对请求头做严格过滤引起的。CSRF会造成密码重置,用户伪造等问题,可能引发严重后果。 我们知道,绝大多数网站是通过cookie等方式辨识用户身份,再予以授权的。所以要伪造用户的正常操作,最好的方法是通过XSS或链接欺骗等途径,让用户在本机(即拥有身份cookie的浏览器端)发起用户所不知道的请求。CSRF攻击会令用户在不知情的情况下攻击自己已经登录的系统。 CSRF攻击的目的是滥用基本的Web功能。如果该网站可以使服务器上的状态变化,如改变受害者的电子邮件地址或密码,或购买的东西,强迫受害人检索数据等等。CSRF攻击会修改目标状态。在这一过程中,受害者会代替攻击者执行这些攻击,攻击者中不会收到响应,受害者会代替攻击者执行这些攻击。   在跨站点请求伪造(CSRF)攻击中,攻击者经由用户的浏览器注入网络请求来破坏用户与网站的会话的完整性。浏览器的安全策略允许网站将HTTP请求发送到任何网络地址。此策略允许控制浏览器呈现的内容的攻击者使用此用户控制下的其他资源。   需要对页面参数做修改时,可以使用burpsuite生成的csrf poc,从而进行poc测试,测试完成之后一定要验证,浏览器执行了我们生成的poc测试,令数据产生变化。   csrf可以和XSS联系在一起

How to render CSRF input in twig?

喜你入骨 提交于 2019-12-02 20:02:12
I know there's the usual way to render CSRF token hidden input with form_rest , but is there a way to render just CSRF input itself? I've overridden {% block field_widget %} in theme to render a piece of additional text. But as CSRF token is rendered in input field too and I got a piece of text I don't need next to a hidden field. So I'd like to render it separately with an argument that tells it not to render this text. you can do it with {{ form_widget(formView._token) }} If you have formView object, you can render it using Twig function: {{ form_widget(formView._token) }} If you haven't -

第十六章:集成的子框架 django.contrib

元气小坏坏 提交于 2019-12-02 19:42:13
第十六章:集成的子框架 django.contrib Python有众多优点,其中之一就是“开机即用”原则: 安装Python的同时会安装好大量的标准软件包,这样 你可以立即使用而不用自己去下载。 Django也遵循这个原则,它同样包含了自己的标准库。 这一章就来讲 这些集成的子框架。 Django标准库 Django的标准库存放在 django.contrib 包中。每个子包都是一个独立的附加功能包。 这些子包一般是互相独立的,不过有些 django.contrib 子包需要依赖其他子包。 在 django.contrib 中对函数的类型并没有强制要求 。其中一些包中带有模型(因此需要你在数据库中安装对应的数据表),但其它一些由独立的中间件及模板标签组成。 django.contrib 开发包共有的特性是: 就算你将整个 django.contrib 开发包删除,你依然可以使用 Django 的基础功能而不会遇到任何问题。 当 Django 开发者向框架增加新功能的时,他们会严格根据这一原则来决定是否把新功能放入 django.contrib 中。 django.contrib 由以下开发包组成: admin : 自动化的站点管理工具。 请查看第6章。 admindocs :为Django admin站点提供自动文档。 本书没有介绍这方面的知识;详情请参阅Django官方文档。

Cross domain ajax POST in chrome

倾然丶 夕夏残阳落幕 提交于 2019-12-02 19:40:44
There are several topics about the problem with cross-domain AJAX. I've been looking at these and the conclusion seems to be this: Apart from using somthing like JSONP, or a proxy sollution, you should not be able to do a basic jquery $.post() to another domain My test code looks something like this (running on " http://myTestdomain.tld/path/file.html ") var myData = {datum1 : "datum", datum2: "datum"} $.post("http://External-Ip:port", myData,function(return){alert(return);}); When I tried this (the reason I started looking), chrome-console told me: XMLHttpRequest cannot load http://External

CSRF token expires during login

本秂侑毒 提交于 2019-12-02 19:32:27
I'm working on Spring web application and I need to avoid problem with expire csrf token on login page, because if user is waiting too long and try to login only one way to resolve problem with csrf is to reload page and try to login again. But it's not user friendly and I want to avoid this situation. First question: Is it possible in general(by spring security 3.2.4)? Without disable csrf. I tried to use security="none" for login page and spring seciruty "login_check", but it's not working, i got infinity redirect or I got error that no mapping for url "myhost/login_check". Second question:

How can I embed django csrf token straight into HTML?

强颜欢笑 提交于 2019-12-02 19:08:26
within my django app I am storing strings of html in the db that will then be displayed on the users' home pages as "messages". Some of these messages contain forms, but not being written in the template language, I am not able to insert the csrf token (thus breaking the app). Is there a way to insert this token directly from within the python files i'm editing? i'm looking for something along the lines of: csrf_token = django.csrf.generate() message = "press the button please: <form><input type='hidden' name='csrf_token' value='%s'><input type='submit' value='press here'></form>" % (csrf

【1029 | Day55】AJAX简介及jQuery/Js实现AJAX

孤街浪徒 提交于 2019-12-02 18:12:25
目录 1. AJAX简介 1.1 示例 1.2 AJAX常见应用情景 1.3 AJAX的优缺点 优点 缺点: 2. jQuery实现的AJAX(掌握) 2.1 html 2.2 views.py 2.3 $.ajax参数 3. JS实现AJAX(了解) 4. AJAX请求如何设置 csrf_token 4.1 方式一 4.2 方式二 4.3 方式三 1. AJAX简介 在前一篇的知识储备下,开始接受 AJAX 的的洗礼吧。 AJAX(Asynchronous Javascript And XML)翻译成中文就是“异步的Javascript和XML”。 即使用Javascript语言与服务器进行异步交互,传输的数据为XML (当然,传输的数据不只是XML) 。 AJAX 不是新的编程语言,而是一种使用现有标准的新方法。 注意,接下来才是重点!!! 举个栗子: 我们经常会在网站搜图片或者看文章,当你不断下拉的时候,拉到页面底部,忽然!网页又加载出来一堆图片和文章,这种情况,其实就是我们的AJAX在干活,是不是心里有点数了? 第一,AJAX 最大的优点: 在不重新加载整个页面的情况下,可以与服务器交换数据并更新部分网页内容(这一特点给用户的感受是在不知不觉中完成请求和响应过程)。 第二,AJAX工作原理: 不需要任何浏览器插件,但需要用户允许JavaScript在浏览器上执行。 有人会问

常见web安全攻防总结

只愿长相守 提交于 2019-12-02 17:58:58
Web 安全的对于 Web 从业人员来说是一个非常重要的课题 , 所以在这里总结一下 Web 相关的安全攻防知识,希望以后不要再踩雷,也希望对看到这篇文章的同学有所帮助。今天这边文章主要的内容就是分析几种常见的攻击的类型以及防御的方法。 也许你对所有的安全问题都有一定的认识,但最主要的还是在编码设计的过程中时刻绷紧安全那根弦,需要反复推敲每个实现细节,安全无小事。 本文代码 Demo 都是基于 Node.js 讲解,其他服务端语言同样可以参考。 XSS 首先说下最常见的 XSS 漏洞,XSS (Cross Site Script),跨站脚本攻击,因为缩写和 CSS (Cascading Style Sheets) 重叠,所以只能叫 XSS。 XSS 的原理是恶意攻击者往 Web 页面里插入恶意可执行网页脚本代码,当用户浏览该页之时,嵌入其中 Web 里面的脚本代码会被执行,从而可以达到攻击者盗取用户信息或其他侵犯用户安全隐私的目的。XSS 的攻击方式千变万化,但还是可以大致细分为几种类型。 非持久型 XSS 非持久型 XSS 漏洞,也叫反射型 XSS 漏洞,一般是通过给别人发送带有恶意脚本代码参数的 URL,当 URL 地址被打开时,特有的恶意代码参数被 HTML 解析、执行。 20180113155741.jpg 一个例子,比如你的 Web 页面中包含有以下代码: <select

Why CSRF token should be in meta tag and in cookie?

ぐ巨炮叔叔 提交于 2019-12-02 17:31:38
What's the need of to put CSRF token name and value inside <head> tag using <meta> like: e.g: <meta content="authenticity_token" name="csrf-param" /> <meta content="4sWPhTlJAmt1IcyNq1FCyivsAVhHqjiDCKRXOgOQock=" name="csrf-token" /> I've read about concept to keep CSRF value in cookie but does not find about why to keep inside <head> tag. To prevent CSRF you need a value that is submitted with the request that cannot be sent by a malicious site. Authentication cookies are not suitable because if an attacker can make the browser send a request to the victim site, the cookies will automatically

Does a proper CORS setup prevent XSRF?

五迷三道 提交于 2019-12-02 17:29:30
If CORS is properly setup on a server to only allow a certain origins to access the server, is this enough to prevent XSRF attacks? To be more specific, it is easy to make the mistake of thinking that if evil.com cannot make a request to good.com due to CORS then CSRF is prevented. There are two problems being overlooked, however: CORS is respected by the browsers only. That means Google Chrome will obey CORS and not let evil.com make a request to good.com. However, imagine someone builds a native app or whatever which has a form that POSTs things to your site. XSRF tokens are the only way to