回来讲讲其他HTTP攻击吧!
在Day2的HTTP基础中,我们已经知道发送一个Request的格式,也知道Request的结尾会有一组CRLF,当Web Application没有检查/过滤来自使用者的某些input时,攻击者可以透过客制化Request,来增加、设置任意Header、控制body或将Web Server的Response拆成多个Response。
下面是一个网站的Response场景:
...
Name: Craig <--网站开发者自定义的Header
...
如果网站开发者没有进行正确的URL Encode而且透过get参数直接将这个Header反映在Header中,攻击者就可以插入两个CRLF,告诉Web Server接下来是Request Body。
GET /name=Craig%0d%0a%0d%0a<script>alert("XSS")</script>
Host: example.com
就可以作为XSS利用的一个管道。
或是
GET /name=Craig%0d%0a%0d%0aHTTP/1.1%20200%20OK%0d%0aContent-Type:%20text/html%0d%0aContent-Length:%2019%0d%0a%0d%0a<html>XXXXXX</html>
注: %0d%0a是\r\n的URL encode
decode:
GET/name=Craig
HTTP/1.1 200 OK
Content-Type: text/html
Content-Length: 19
<html>XXXXXX</html>
Response Result:
HTTP/1.1 302 Move Temporarily
... <-
... <- 网站原始的response
HTTP /1.1 200 OK <--从这行开始是上面写的payload,被spilt的部分
Content-Type: text/html
Content-Length: 19
<payload>
Server: XXX
<payload>
部分可以塞很多东西,可以让攻击者接管User的Browser、steal cookie、redirect到攻击者架设的web service、Web Cache Poison等等。
Drupal
在Drupal Core的一些版本中,允许用户提供的input data成为response header的一部分,这让攻击者可以利用它来进行HTTP Response Splitting,这会导致除了上面讲过的Web Cache Poison外,还有跨用户窜改(cross-user defacement)和任意程序码注入(injection of arbitrary code)
从Drupal发出的patch当中可以看出端倪
Index: includes/common.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/common.inc,v
retrieving revision 1.611.2.9
diff -u -F^f -r1.611.2.9 common.inc
--- includes/common.inc 26 Jul 2007 19:16:45 -0000 1.611.2.9
+++ includes/common.inc 17 Oct 2007 19:28:03 -0000
@@ -267,10 +267,6 @@ function drupal_get_destination() {
* 'user login'-block in a sidebar. The function drupal_get_destination()
* can be used to help set the destination URL.
*
- * It is advised to use drupal_goto() instead of PHP's header(), because
- * drupal_goto() will append the user's session ID to the URI when PHP is
- * compiled with "--enable-trans-sid".
- *
* This function ends the request; use it rather than a print theme('page')
* statement in your menu callback.
*
@@ -302,6 +298,8 @@ function drupal_goto($path = '', $query
}
$url = url($path, $query, $fragment, TRUE);
+ // Remove newlines from the URL to avoid header injection attacks.
+ $url = str_replace(array("\n", "\r"), '', $url);
// Before the redirect, allow modules to react to the end of the page request.
module_invoke_all('exit', $url);
可以看原本的22行,在未进行任何检查和过滤的状况下,直接引入了url的path,query和fragment做使用。新增的24行则是直接做replace CRLF的过滤。
下篇预告: ORM Injection
你听过SQL Injection,那ORM呢?
<<: Spring Framework X Kotlin Day 18 Coroutine
>>: 【领域展开 08 式】 WordPress 布景主题选择 (彷佛发现无底洞
系统工程是一门应用知识来创建或获取一个系统的学科,该系统由相互关联的元素组成,这些元素在整个系统开...
今天一样是语法糖的练习,而且我想把日期塞进去 (感谢 sololearn 的 David Carro...
数位逻辑 (Digital Logic) 是用来代表电路输入与输出的控制,横跨非常多领域,可以用电子...
这几天在改Laravel, 遇到一个很奇怪的问题, 我只要点击後台要到/admin/user/, 每...
Hashicorp Nomad: Submit a Job 今天来写最基本的提交工作(Submit ...