SlideShare a Scribd company logo
1 of 54
Download to read offline
SECURITY BOOTCAMP 2012 | Make yourself to be an expert!




           1




                         54




       Software Exploitation
          Nguyễn Chấn Việt | vietwow@gmail.com
SECURITY BOOTCAMP 2012 | Make yourself to be an expert!




               2
                     Who am I
Senior Security Researcher
+4 years in Information54  Security. Focusing on
Malware Analysis and Exploit Development
Twitter : https://twitter.com/vietwow
SECURITY BOOTCAMP 2012 | Make yourself to be an expert!



               Why study this ?
               3

This is real security. NOT Security+, CEH,
CISSP, …
                        54
Firewall, IDS/IPS, AV … cannot detect/prevent
HOT jobs :
  – Application Security/Pentest
  – Exploit Development
Bug Hunting : Vupen wins 1 million dollars with
Chrome exploit from Google offer
SECURITY BOOTCAMP 2012 | Make yourself to be an expert!



             Vulnerablity Finding
              4

Phases 1 :
  – Fuzzing / Reverse Engineer (Black-box)
                        54
  – Source code audit (White-box)
Phase 2 :
  – Exploit Development => We are here
Phase 3 :
  – $ell
  – To be Anonymous/Luzsec
SECURITY BOOTCAMP 2012 | Make yourself to be an expert!




               5
                   Requirements
x86 Assembly
C/C++                 54

Understand OS Primer and how function works
Use debugger tools
Scripting Language (prefered Python)
SECURITY BOOTCAMP 2012 | Make yourself to be an expert!




               6
                          Tools
IDA / IDA Pro
OllyDBG / Immunity Debugger
                    54

GDB
WinDBG
Metasploit
SECURITY BOOTCAMP 2012 | Make yourself to be an expert!



    Stack Buffer Overflow in Action
                   7

  Senior Security Researcher
                                 54




Bộ nhớ Stack ban đầu   Sau khi nhập chuỗi        Bộ nhớ Stack sau khi bị
                       “Hello”                   tràn
SECURITY BOOTCAMP 2012 | Make yourself to be an expert!



               Classical method
               8

Direct EIP overwrite : Chỉ cần overwrite EIP
thành địa chỉ của shellcode => khi function kết
                        54
thúc, CPU sẽ nhảy đến địa chỉ shellcode và thực
thi

=> Chỉ áp dụng được ở những năm 1990
SECURITY BOOTCAMP 2012 | Make yourself to be an expert!




                9
                 Some problems
Bad character => encode shellcode
Limited-size buffer => egg-hunter shellcode
                         54

Shifting stack pointer : giúp exploit của ta trở
nên “reliability” hơn vì đôi khi 1 số stack
operation trong chương trình sẽ làm corrupt
shellcode
  – add esp, xxxx
SECURITY BOOTCAMP 2012 | Make yourself to be an expert!




           10




                         54

Exploit Mitigation Techniques
SECURITY BOOTCAMP 2012 | Make yourself to be an expert!




           11




                         54
SECURITY BOOTCAMP 2012 | Make yourself to be an expert!




           12




                         54
SECURITY BOOTCAMP 2012 | Make yourself to be an expert!




           13




                         54
SECURITY BOOTCAMP 2012 | Make yourself to be an expert!




               14
                           /GS
Cơ chế bảo vệ của compiler
Chèn 1 giá trị random gọi là cookie vào trước
                        54
buffer trong stack
Khi chương trình kết thúc sẽ kiểm tra, nếu giá trị
này bị thay đổi thì chương trình sẽ bị kill ngay
lập tức
SECURITY BOOTCAMP 2012 | Make yourself to be an expert!


                       Memory Layout
                       15
        Parameters


      Return Address
                                  54

      Frame Pointer


          Locals

          (1)


(1) Without Cookie
SECURITY BOOTCAMP 2012 | Make yourself to be an expert!


                       Memory Layout
                       16
        Parameters               Parameters


      Return Address           Return Address
                                   54

      Frame Pointer            Frame Pointer


          Locals                  Cookie

          (1)
                                   Locals

(1) Without Cookie
                                     (2)
(2) MSVC++ 2003
SECURITY BOOTCAMP 2012 | Make yourself to be an expert!




               17
                    Bypass /GS
Cơ chế bảo vệ của compiler
Chèn 1 giá trị random gọi là cookie vào giữa
                        54
Saved EBP và RET
Khi chương trình kết thúc sẽ kiểm tra, nếu giá trị
này bị thay đổi thì chương trình sẽ bị kill ngay
lập tức
SECURITY BOOTCAMP 2012 | Make yourself to be an expert!




                18
                         Bypass /GS
SEH - “Structured Exception Handling” là cơ
chế xử lý Exception của Windows
                             54
            int test(void){
             int test(void){
            __try{
             __try{
               // Exception may occur here
                // Exception may occur here
            }}
            __except( EXCEPTION_EXECUTE_HANDLER ){
             __except( EXCEPTION_EXECUTE_HANDLER ){
               // This handles the exception
                // This handles the exception
            }}

            return 0;
             return 0;
            }}
SECURITY BOOTCAMP 2012 | Make yourself to be an expert!



            Memory Layout
           19




                         54




                                                     (3)
SECURITY BOOTCAMP 2012 | Make yourself to be an expert!



            Memory Layout
           20




                         54




                                                     (3)
SECURITY BOOTCAMP 2012 | Make yourself to be an expert!




               21
                    Bypass /GS
Vì SEH được trigger trước khi chương trình kết
thúc => điều đó đồng nghĩa với việc exploit của
                        54
ta sẽ được hiện trước chương trình kết thúc (và
kiểm tra cookie)
Để khai thác, ta phải tạo ra 1 exception. Sau đó
“ép” application jump đến shellcode của ta (thay
vì default sẽ là jump để real exception handler
function)
SECURITY BOOTCAMP 2012 | Make yourself to be an expert!




           22
                Bypass /GS

                         54
SECURITY BOOTCAMP 2012 | Make yourself to be an expert!




               23
                         ASLR
Cơ chế bảo vệ của OS
Nguyên tắc là OS sẽ randomize các address trên
                        54
memory như stack, heap, … (trừ text section) =>
khiến ta không thể search các address cần thiết
như địa chỉ shellcode, địa chỉ hàm, ….
SECURITY BOOTCAMP 2012 | Make yourself to be an expert!




               24
                  Bypass ASLR
Bruteforce : chỉ khả thi với hệ thống 32-bit
Non ASLR : Return-to-esp, Return-to-eax
                        54
Heap Spray
SECURITY BOOTCAMP 2012 | Make yourself to be an expert!




               25
                  Bypass ASLR
Return-to-esp :
  – overwrite địa chỉ RET thành địa chỉ của lệnh “JMP
                         54
    ESP” (FF E4) hoặc “CALL ESP”
  – Đặt shellcode ngay sau RET


=> Khi hàm kết thúc, lệnh “JMP ESP” / “CALL
 ESP” sẽ được thực thi, do đó phần shellcode
 ngay sau đó sẽ được thực thi
SECURITY BOOTCAMP 2012 | Make yourself to be an expert!




               26
                  Bypass ASLR
Return-to-eax :
  – Phương pháp này được sử dụng trong các trường
                         54
    hợp thanh ghi EAX được dùng để store return
    value, khi đó thanh ghi EAX sẽ trỏ về buffer, ta chỉ
    cần chèn shellcode vào buffer, sau đó tìm
    instruction “jmp eax” và overwrite vào RET
SECURITY BOOTCAMP 2012 | Make yourself to be an expert!




               27
                  Bypass ASLR
Heapspray :
  – Thay vì return về Stack, với cơ chế của các
                          54
    browser ngày nay, ta có thể return về Heap
  – Ta sẽ “spray” shellcode ở nhiều nơi trên Heap
  – Với kỹ thuật này, ta không cần quan tâm đến việc
    encode shellcode vì tất cả character đã được
    “allow” bởi Javascript
SECURITY BOOTCAMP 2012 | Make yourself to be an expert!




               28
                     DEP / NX
Cơ chế bảo vệ của OS
Nguyên tắc là OS sẽ mark các page memory là
                     54
Non-Execution => Shellcode đặt trên Stack hay
Heap đều không thể Execute
SECURITY BOOTCAMP 2012 | Make yourself to be an expert!




               29
                     DEP / NX
Cơ chế bảo vệ của OS
Nguyên tắc là OS sẽ mark các page memory là
                     54
Non-Execution => Shellcode đặt trên Stack hay
Heap đều không thể Execute
SECURITY BOOTCAMP 2012 | Make yourself to be an expert!



              Bypass DEP / NX
              30

Return-to-glibc
  – Section .text/.code luôn luôn được thực thi => thay
                           54
    vì trỏ về shellcode, ta có thể trỏ về các hàm trong
    glibc hay các instruction trong chính chương trình
SECURITY BOOTCAMP 2012 | Make yourself to be an expert!



              Bypass DEP / NX
              31

Return-to-glibc
  – Có thể thực hiện chained return-to-glibc bằng cách
                         54
    kết hợp sử dụng POP-POP-RET
SECURITY BOOTCAMP 2012 | Make yourself to be an expert!



              Bypass DEP / NX
              32

Return-to-glibc
  – Trên Windows, Cơ chế DEP cũ có thể dễ dạng bị
                        54
    disable bởi các Windows API
    “NtSetInformationProcess” thông qua kỹ thuật
    return-to-glibc
SECURITY BOOTCAMP 2012 | Make yourself to be an expert!



                Permanent DEP
               33

Phiên bản improve của DEP
DEP không thể bị change (disable) sau khi thiết
                      54
lập
SECURITY BOOTCAMP 2012 | Make yourself to be an expert!



        Bypass Permanent DEP
          34

Return Oriented Programing (ROP)
  – Là kỹ thuật mở rộng của return-to-glibc
                          54
  – Dựa trên kỹ thuật return-to-glibc và “borrowed
    code chunks” => Return về các instruction trong
    section text/code
  – ESP sẽ là key (thay vì EIP)


Payload Already Inside:Data re-use for ROP
Exploits – Long Le Dinh
SECURITY BOOTCAMP 2012 | Make yourself to be an expert!



            Other Vulnerbility ?
             35

Format String (lỗi định dạng)
Integer Overflow (tràn số nguyên)
                        54
  – Bypass checking
  – Possible memory corruption
Race Condition
User-after-free
SECURITY BOOTCAMP 2012 | Make yourself to be an expert!




               36
                  Format String
Xuất phát từ việc sử dụng format string không
đúng cách
                             54



print(“%d”,number);
print(number);

Khác nhau như thế nào ?
SECURITY BOOTCAMP 2012 | Make yourself to be an expert!




               37
                  Format String
Cho phép attack có thể “view” stack memory sử
dụng %x
                             54



Cho phép attack có thể write value vào 1
arbitrary memory sử dụng %n
SECURITY BOOTCAMP 2012 | Make yourself to be an expert!




               38
                  Format String
Không có RET => Làm sao để chiếm control ?
  – Overwrite section .dtors
                         54
  – Overwrite GOT table
SECURITY BOOTCAMP 2012 | Make yourself to be an expert!




               39
                  Use-after-free
Modern race condition for browser
Objects in memory     54
  – - Replacing objects in memory on the fly
  – - Replacing them with user-controlled strings
SECURITY BOOTCAMP 2012 | Make yourself to be an expert!




                            40
                               Use-after-free
Example : 1 class bao gồm 3 member và 3
method
                                         54


Class vuln()
{
    –   int number1, number2, number3;
    –   void func1() {…};
    –   void func2() {…};
    –   void func3() {…};

}
SECURITY BOOTCAMP 2012 | Make yourself to be an expert!




                     41
                        Use-after-free
Trên memory :
                                       54
VTABLE ----> FPTR1 ----------> code
NUMBER1       FPTR2 ----------> code
NUMBER2       FPTR3 ----------> code
NUMBER3
SECURITY BOOTCAMP 2012 | Make yourself to be an expert!




                     42
                        Use-after-free
Nếu ta khởi tạo 2 instance của class đó :
b VTABLE ----> FPTR1 ----------> code 54
 NUMBER1        FPTR2 ----------> code
 NUMBER2        FPTR3 ----------> code
 NUMBER3
a VTABLE ----> FPTR1 ----------> code
 NUMBER1        FPTR2 ----------> code
 NUMBER2        FPTR3 ----------> code
 NUMBER3
SECURITY BOOTCAMP 2012 | Make yourself to be an expert!



                 Vtable overwrite
                 43

Khi ta thực hiện :
                                  54
  – strcpy(b.number3, argv[1]);
  – a.method2();



=> Nếu ta input dữ liệu lớn hơn size của
number3 thì ta có thể overwrite lên các data khác
SECURITY BOOTCAMP 2012 | Make yourself to be an expert!




                   44
                      Use-after-free
Back to use-after-free :
  – x = new ABC()
  – y = clone(x)              54
  – destroy(x)
  – y.method2()
SECURITY BOOTCAMP 2012 | Make yourself to be an expert!




                 45
                    Use-after-free
x = new ABC() :
  – x VTABLE
  –   MEMBER1                  54
  –   MEMBER2
  –   MEMBER3
  –   MEMBER4
SECURITY BOOTCAMP 2012 | Make yourself to be an expert!




                  46
                     Use-after-free
y = clone(x) :
  – y pointer -----> x VTABLE
  –         MEMBER1             54
  –         MEMBER2
  –         MEMBER3
  –         MEMBER4
SECURITY BOOTCAMP 2012 | Make yourself to be an expert!




                 47
                    Use-after-free
destroy(x)
y.method2() :                  54
  – y VTABLE
  –   MEMBER1
  –   MEMBER2
  –   MEMBER3
  –   MEMBER4
SECURITY BOOTCAMP 2012 | Make yourself to be an expert!




                   48
                      Use-after-free
Idea : nếu ngay sau lúc destroy x, ta có thể input
data vào (đủ nhanh) với đúng memory size của
                        54
object x thì sẽ overwrite vtable object x thành
công

  – y pointer -----> 41414141
  –          AAAA
  –          AAAA
  –          AAAA
  –          AAAA
SECURITY BOOTCAMP 2012 | Make yourself to be an expert!



     0day 49 1day Vulnernablity
          vs
Reverse Engineering Patch for finding
Vulnerability
                             54
SECURITY BOOTCAMP 2012 | Make yourself to be an expert!



                Learning More ?
                50
Ebooks :
   – The Art of Exploitation
   – The Shellcoder's Handbook: Discovering and
                          54

     Exploiting Security Holes
   – Grey Hat Hacking - Ethical Hackers Handbook
   – Nghệ thuật tận dụng lỗi phần mềm - NamNT
Sites :
   – https://www.corelan.be
   – http://resources.infosecinstitute.com/
SECURITY BOOTCAMP 2012 | Make yourself to be an expert!



                 Learning More ?
                 51
Training Courses
Wargames :
                          54
  – Online : http://www.overthewire.org/wargames/
  – Offline : exploit-exercises
Capture The Flag :
  –   CSAW
  –   HITB
  –   Defcon
  –   …
SECURITY BOOTCAMP 2012 | Make yourself to be an expert!



           Exploit Listing Sites
               52
Exploit-DB
Injector
                       54
CVE Details
Packetstorm
CERT
Mitre
National Vulnerability Database
Common Weakness Enumberation
SECURITY BOOTCAMP 2012 | Make yourself to be an expert!



           Any Questions ?
           53




                         54
SECURITY BOOTCAMP 2012 | Make yourself to be an expert!




           54




     Thank you very much !
                         54

More Related Content

What's hot

SBC 2012 - Information Gathering (Lương Trung Thành)
SBC 2012 - Information Gathering (Lương Trung Thành)SBC 2012 - Information Gathering (Lương Trung Thành)
SBC 2012 - Information Gathering (Lương Trung Thành)Security Bootcamp
 
Trần Anh Khoa - Kautilya và Powershell trong kỹ thuật tấn công tiếp cận
Trần Anh Khoa - Kautilya và Powershelltrong kỹ thuật tấn công tiếp cậnTrần Anh Khoa - Kautilya và Powershelltrong kỹ thuật tấn công tiếp cận
Trần Anh Khoa - Kautilya và Powershell trong kỹ thuật tấn công tiếp cậnSecurity Bootcamp
 
Khai thác lỗi phần mềm thi chứng chỉ của Microsoft - Phạm Đình Thắng
Khai thác lỗi phần mềm thi chứng chỉ của Microsoft - Phạm Đình ThắngKhai thác lỗi phần mềm thi chứng chỉ của Microsoft - Phạm Đình Thắng
Khai thác lỗi phần mềm thi chứng chỉ của Microsoft - Phạm Đình ThắngSecurity Bootcamp
 
SBC 2012 - Database Security (Nguyễn Thanh Tùng)
SBC 2012 - Database Security (Nguyễn Thanh Tùng)SBC 2012 - Database Security (Nguyễn Thanh Tùng)
SBC 2012 - Database Security (Nguyễn Thanh Tùng)Security Bootcamp
 
XXE injection - Nguyễn Tăng Hưng
XXE injection - Nguyễn Tăng HưngXXE injection - Nguyễn Tăng Hưng
XXE injection - Nguyễn Tăng HưngVõ Thái Lâm
 
Hướng nghiên cứu mới cho ngành mật mã nước nhà - TS Hồ Ngọc Duy
Hướng nghiên cứu mới cho ngành mật mã nước nhà - TS Hồ Ngọc DuyHướng nghiên cứu mới cho ngành mật mã nước nhà - TS Hồ Ngọc Duy
Hướng nghiên cứu mới cho ngành mật mã nước nhà - TS Hồ Ngọc DuySecurity Bootcamp
 
Security Bootcamp 2013 penetration testing (basic)
Security Bootcamp 2013   penetration testing (basic)Security Bootcamp 2013   penetration testing (basic)
Security Bootcamp 2013 penetration testing (basic)Security Bootcamp
 
SBC 2012 - Một số thuật toán phân lớp và ứng dụng trong IDS (Nguyễn Đình Chiểu)
SBC 2012 - Một số thuật toán phân lớp và ứng dụng trong IDS (Nguyễn Đình Chiểu)SBC 2012 - Một số thuật toán phân lớp và ứng dụng trong IDS (Nguyễn Đình Chiểu)
SBC 2012 - Một số thuật toán phân lớp và ứng dụng trong IDS (Nguyễn Đình Chiểu)Security Bootcamp
 

What's hot (8)

SBC 2012 - Information Gathering (Lương Trung Thành)
SBC 2012 - Information Gathering (Lương Trung Thành)SBC 2012 - Information Gathering (Lương Trung Thành)
SBC 2012 - Information Gathering (Lương Trung Thành)
 
Trần Anh Khoa - Kautilya và Powershell trong kỹ thuật tấn công tiếp cận
Trần Anh Khoa - Kautilya và Powershelltrong kỹ thuật tấn công tiếp cậnTrần Anh Khoa - Kautilya và Powershelltrong kỹ thuật tấn công tiếp cận
Trần Anh Khoa - Kautilya và Powershell trong kỹ thuật tấn công tiếp cận
 
Khai thác lỗi phần mềm thi chứng chỉ của Microsoft - Phạm Đình Thắng
Khai thác lỗi phần mềm thi chứng chỉ của Microsoft - Phạm Đình ThắngKhai thác lỗi phần mềm thi chứng chỉ của Microsoft - Phạm Đình Thắng
Khai thác lỗi phần mềm thi chứng chỉ của Microsoft - Phạm Đình Thắng
 
SBC 2012 - Database Security (Nguyễn Thanh Tùng)
SBC 2012 - Database Security (Nguyễn Thanh Tùng)SBC 2012 - Database Security (Nguyễn Thanh Tùng)
SBC 2012 - Database Security (Nguyễn Thanh Tùng)
 
XXE injection - Nguyễn Tăng Hưng
XXE injection - Nguyễn Tăng HưngXXE injection - Nguyễn Tăng Hưng
XXE injection - Nguyễn Tăng Hưng
 
Hướng nghiên cứu mới cho ngành mật mã nước nhà - TS Hồ Ngọc Duy
Hướng nghiên cứu mới cho ngành mật mã nước nhà - TS Hồ Ngọc DuyHướng nghiên cứu mới cho ngành mật mã nước nhà - TS Hồ Ngọc Duy
Hướng nghiên cứu mới cho ngành mật mã nước nhà - TS Hồ Ngọc Duy
 
Security Bootcamp 2013 penetration testing (basic)
Security Bootcamp 2013   penetration testing (basic)Security Bootcamp 2013   penetration testing (basic)
Security Bootcamp 2013 penetration testing (basic)
 
SBC 2012 - Một số thuật toán phân lớp và ứng dụng trong IDS (Nguyễn Đình Chiểu)
SBC 2012 - Một số thuật toán phân lớp và ứng dụng trong IDS (Nguyễn Đình Chiểu)SBC 2012 - Một số thuật toán phân lớp và ứng dụng trong IDS (Nguyễn Đình Chiểu)
SBC 2012 - Một số thuật toán phân lớp và ứng dụng trong IDS (Nguyễn Đình Chiểu)
 

More from Security Bootcamp

Ransomware is Knocking your Door_Final.pdf
Ransomware is Knocking your Door_Final.pdfRansomware is Knocking your Door_Final.pdf
Ransomware is Knocking your Door_Final.pdfSecurity Bootcamp
 
Hieupc-The role of psychology in enhancing cybersecurity
Hieupc-The role of psychology in enhancing cybersecurityHieupc-The role of psychology in enhancing cybersecurity
Hieupc-The role of psychology in enhancing cybersecuritySecurity Bootcamp
 
Nguyen Huu Trung - Building a web vulnerability scanner - From a hacker’s view
Nguyen Huu Trung - Building a web vulnerability scanner - From a hacker’s viewNguyen Huu Trung - Building a web vulnerability scanner - From a hacker’s view
Nguyen Huu Trung - Building a web vulnerability scanner - From a hacker’s viewSecurity Bootcamp
 
Sbc 2020 bao gio vn co anm dua vao cong nghe mo
Sbc 2020 bao gio vn co anm dua vao cong nghe moSbc 2020 bao gio vn co anm dua vao cong nghe mo
Sbc 2020 bao gio vn co anm dua vao cong nghe moSecurity Bootcamp
 
Giam sat thu dong thong tin an toan hang hai su dung sdr
Giam sat thu dong thong tin an toan hang hai su dung sdrGiam sat thu dong thong tin an toan hang hai su dung sdr
Giam sat thu dong thong tin an toan hang hai su dung sdrSecurity Bootcamp
 
Insider threat-what-us-do d-want
Insider threat-what-us-do d-wantInsider threat-what-us-do d-want
Insider threat-what-us-do d-wantSecurity Bootcamp
 
Macro malware common techniques - public
Macro malware   common techniques - publicMacro malware   common techniques - public
Macro malware common techniques - publicSecurity Bootcamp
 
Malware detection-using-machine-learning
Malware detection-using-machine-learningMalware detection-using-machine-learning
Malware detection-using-machine-learningSecurity Bootcamp
 
Tim dieu moi trong nhung dieu cu
Tim dieu moi trong nhung dieu cuTim dieu moi trong nhung dieu cu
Tim dieu moi trong nhung dieu cuSecurity Bootcamp
 
Threat detection with 0 cost
Threat detection with 0 costThreat detection with 0 cost
Threat detection with 0 costSecurity Bootcamp
 
GOLDEN TICKET - Hiểm hoa tiềm ẩn trong hệ thống Active Directory
GOLDEN TICKET -  Hiểm hoa tiềm ẩn trong hệ thống Active DirectoryGOLDEN TICKET -  Hiểm hoa tiềm ẩn trong hệ thống Active Directory
GOLDEN TICKET - Hiểm hoa tiềm ẩn trong hệ thống Active DirectorySecurity Bootcamp
 
PHÂN TÍCH MỘT SỐ CUỘC TẤN CÔNG APT ĐIỂN HÌNH NHẮM VÀO VIỆT NAM 2017-2018
PHÂN TÍCH MỘT SỐ CUỘC TẤN CÔNG APT ĐIỂN HÌNH NHẮM VÀO VIỆT NAM 2017-2018PHÂN TÍCH MỘT SỐ CUỘC TẤN CÔNG APT ĐIỂN HÌNH NHẮM VÀO VIỆT NAM 2017-2018
PHÂN TÍCH MỘT SỐ CUỘC TẤN CÔNG APT ĐIỂN HÌNH NHẮM VÀO VIỆT NAM 2017-2018Security Bootcamp
 
Lannguyen-Detecting Cyber Attacks
Lannguyen-Detecting Cyber AttacksLannguyen-Detecting Cyber Attacks
Lannguyen-Detecting Cyber AttacksSecurity Bootcamp
 
Letrungnghia-gopyluananm2018
Letrungnghia-gopyluananm2018Letrungnghia-gopyluananm2018
Letrungnghia-gopyluananm2018Security Bootcamp
 

More from Security Bootcamp (20)

Ransomware is Knocking your Door_Final.pdf
Ransomware is Knocking your Door_Final.pdfRansomware is Knocking your Door_Final.pdf
Ransomware is Knocking your Door_Final.pdf
 
Hieupc-The role of psychology in enhancing cybersecurity
Hieupc-The role of psychology in enhancing cybersecurityHieupc-The role of psychology in enhancing cybersecurity
Hieupc-The role of psychology in enhancing cybersecurity
 
Nguyen Huu Trung - Building a web vulnerability scanner - From a hacker’s view
Nguyen Huu Trung - Building a web vulnerability scanner - From a hacker’s viewNguyen Huu Trung - Building a web vulnerability scanner - From a hacker’s view
Nguyen Huu Trung - Building a web vulnerability scanner - From a hacker’s view
 
Sbc 2020 bao gio vn co anm dua vao cong nghe mo
Sbc 2020 bao gio vn co anm dua vao cong nghe moSbc 2020 bao gio vn co anm dua vao cong nghe mo
Sbc 2020 bao gio vn co anm dua vao cong nghe mo
 
Deception change-the-game
Deception change-the-gameDeception change-the-game
Deception change-the-game
 
Giam sat thu dong thong tin an toan hang hai su dung sdr
Giam sat thu dong thong tin an toan hang hai su dung sdrGiam sat thu dong thong tin an toan hang hai su dung sdr
Giam sat thu dong thong tin an toan hang hai su dung sdr
 
Sbc2019 luong-cyber startup
Sbc2019 luong-cyber startupSbc2019 luong-cyber startup
Sbc2019 luong-cyber startup
 
Insider threat-what-us-do d-want
Insider threat-what-us-do d-wantInsider threat-what-us-do d-want
Insider threat-what-us-do d-want
 
Macro malware common techniques - public
Macro malware   common techniques - publicMacro malware   common techniques - public
Macro malware common techniques - public
 
Malware detection-using-machine-learning
Malware detection-using-machine-learningMalware detection-using-machine-learning
Malware detection-using-machine-learning
 
Tim dieu moi trong nhung dieu cu
Tim dieu moi trong nhung dieu cuTim dieu moi trong nhung dieu cu
Tim dieu moi trong nhung dieu cu
 
Threat detection with 0 cost
Threat detection with 0 costThreat detection with 0 cost
Threat detection with 0 cost
 
Build SOC
Build SOC Build SOC
Build SOC
 
AD red vs blue
AD red vs blueAD red vs blue
AD red vs blue
 
Securitybox
SecurityboxSecuritybox
Securitybox
 
GOLDEN TICKET - Hiểm hoa tiềm ẩn trong hệ thống Active Directory
GOLDEN TICKET -  Hiểm hoa tiềm ẩn trong hệ thống Active DirectoryGOLDEN TICKET -  Hiểm hoa tiềm ẩn trong hệ thống Active Directory
GOLDEN TICKET - Hiểm hoa tiềm ẩn trong hệ thống Active Directory
 
PHÂN TÍCH MỘT SỐ CUỘC TẤN CÔNG APT ĐIỂN HÌNH NHẮM VÀO VIỆT NAM 2017-2018
PHÂN TÍCH MỘT SỐ CUỘC TẤN CÔNG APT ĐIỂN HÌNH NHẮM VÀO VIỆT NAM 2017-2018PHÂN TÍCH MỘT SỐ CUỘC TẤN CÔNG APT ĐIỂN HÌNH NHẮM VÀO VIỆT NAM 2017-2018
PHÂN TÍCH MỘT SỐ CUỘC TẤN CÔNG APT ĐIỂN HÌNH NHẮM VÀO VIỆT NAM 2017-2018
 
Api security-present
Api security-presentApi security-present
Api security-present
 
Lannguyen-Detecting Cyber Attacks
Lannguyen-Detecting Cyber AttacksLannguyen-Detecting Cyber Attacks
Lannguyen-Detecting Cyber Attacks
 
Letrungnghia-gopyluananm2018
Letrungnghia-gopyluananm2018Letrungnghia-gopyluananm2018
Letrungnghia-gopyluananm2018
 

SBC 2012 - Software Exploitation (Nguyễn Chấn Việt)

  • 1. SECURITY BOOTCAMP 2012 | Make yourself to be an expert! 1 54 Software Exploitation Nguyễn Chấn Việt | vietwow@gmail.com
  • 2. SECURITY BOOTCAMP 2012 | Make yourself to be an expert! 2 Who am I Senior Security Researcher +4 years in Information54 Security. Focusing on Malware Analysis and Exploit Development Twitter : https://twitter.com/vietwow
  • 3. SECURITY BOOTCAMP 2012 | Make yourself to be an expert! Why study this ? 3 This is real security. NOT Security+, CEH, CISSP, … 54 Firewall, IDS/IPS, AV … cannot detect/prevent HOT jobs : – Application Security/Pentest – Exploit Development Bug Hunting : Vupen wins 1 million dollars with Chrome exploit from Google offer
  • 4. SECURITY BOOTCAMP 2012 | Make yourself to be an expert! Vulnerablity Finding 4 Phases 1 : – Fuzzing / Reverse Engineer (Black-box) 54 – Source code audit (White-box) Phase 2 : – Exploit Development => We are here Phase 3 : – $ell – To be Anonymous/Luzsec
  • 5. SECURITY BOOTCAMP 2012 | Make yourself to be an expert! 5 Requirements x86 Assembly C/C++ 54 Understand OS Primer and how function works Use debugger tools Scripting Language (prefered Python)
  • 6. SECURITY BOOTCAMP 2012 | Make yourself to be an expert! 6 Tools IDA / IDA Pro OllyDBG / Immunity Debugger 54 GDB WinDBG Metasploit
  • 7. SECURITY BOOTCAMP 2012 | Make yourself to be an expert! Stack Buffer Overflow in Action 7 Senior Security Researcher 54 Bộ nhớ Stack ban đầu Sau khi nhập chuỗi Bộ nhớ Stack sau khi bị “Hello” tràn
  • 8. SECURITY BOOTCAMP 2012 | Make yourself to be an expert! Classical method 8 Direct EIP overwrite : Chỉ cần overwrite EIP thành địa chỉ của shellcode => khi function kết 54 thúc, CPU sẽ nhảy đến địa chỉ shellcode và thực thi => Chỉ áp dụng được ở những năm 1990
  • 9. SECURITY BOOTCAMP 2012 | Make yourself to be an expert! 9 Some problems Bad character => encode shellcode Limited-size buffer => egg-hunter shellcode 54 Shifting stack pointer : giúp exploit của ta trở nên “reliability” hơn vì đôi khi 1 số stack operation trong chương trình sẽ làm corrupt shellcode – add esp, xxxx
  • 10. SECURITY BOOTCAMP 2012 | Make yourself to be an expert! 10 54 Exploit Mitigation Techniques
  • 11. SECURITY BOOTCAMP 2012 | Make yourself to be an expert! 11 54
  • 12. SECURITY BOOTCAMP 2012 | Make yourself to be an expert! 12 54
  • 13. SECURITY BOOTCAMP 2012 | Make yourself to be an expert! 13 54
  • 14. SECURITY BOOTCAMP 2012 | Make yourself to be an expert! 14 /GS Cơ chế bảo vệ của compiler Chèn 1 giá trị random gọi là cookie vào trước 54 buffer trong stack Khi chương trình kết thúc sẽ kiểm tra, nếu giá trị này bị thay đổi thì chương trình sẽ bị kill ngay lập tức
  • 15. SECURITY BOOTCAMP 2012 | Make yourself to be an expert! Memory Layout 15 Parameters Return Address 54 Frame Pointer Locals (1) (1) Without Cookie
  • 16. SECURITY BOOTCAMP 2012 | Make yourself to be an expert! Memory Layout 16 Parameters Parameters Return Address Return Address 54 Frame Pointer Frame Pointer Locals Cookie (1) Locals (1) Without Cookie (2) (2) MSVC++ 2003
  • 17. SECURITY BOOTCAMP 2012 | Make yourself to be an expert! 17 Bypass /GS Cơ chế bảo vệ của compiler Chèn 1 giá trị random gọi là cookie vào giữa 54 Saved EBP và RET Khi chương trình kết thúc sẽ kiểm tra, nếu giá trị này bị thay đổi thì chương trình sẽ bị kill ngay lập tức
  • 18. SECURITY BOOTCAMP 2012 | Make yourself to be an expert! 18 Bypass /GS SEH - “Structured Exception Handling” là cơ chế xử lý Exception của Windows 54 int test(void){ int test(void){ __try{ __try{ // Exception may occur here // Exception may occur here }} __except( EXCEPTION_EXECUTE_HANDLER ){ __except( EXCEPTION_EXECUTE_HANDLER ){ // This handles the exception // This handles the exception }} return 0; return 0; }}
  • 19. SECURITY BOOTCAMP 2012 | Make yourself to be an expert! Memory Layout 19 54 (3)
  • 20. SECURITY BOOTCAMP 2012 | Make yourself to be an expert! Memory Layout 20 54 (3)
  • 21. SECURITY BOOTCAMP 2012 | Make yourself to be an expert! 21 Bypass /GS Vì SEH được trigger trước khi chương trình kết thúc => điều đó đồng nghĩa với việc exploit của 54 ta sẽ được hiện trước chương trình kết thúc (và kiểm tra cookie) Để khai thác, ta phải tạo ra 1 exception. Sau đó “ép” application jump đến shellcode của ta (thay vì default sẽ là jump để real exception handler function)
  • 22. SECURITY BOOTCAMP 2012 | Make yourself to be an expert! 22 Bypass /GS 54
  • 23. SECURITY BOOTCAMP 2012 | Make yourself to be an expert! 23 ASLR Cơ chế bảo vệ của OS Nguyên tắc là OS sẽ randomize các address trên 54 memory như stack, heap, … (trừ text section) => khiến ta không thể search các address cần thiết như địa chỉ shellcode, địa chỉ hàm, ….
  • 24. SECURITY BOOTCAMP 2012 | Make yourself to be an expert! 24 Bypass ASLR Bruteforce : chỉ khả thi với hệ thống 32-bit Non ASLR : Return-to-esp, Return-to-eax 54 Heap Spray
  • 25. SECURITY BOOTCAMP 2012 | Make yourself to be an expert! 25 Bypass ASLR Return-to-esp : – overwrite địa chỉ RET thành địa chỉ của lệnh “JMP 54 ESP” (FF E4) hoặc “CALL ESP” – Đặt shellcode ngay sau RET => Khi hàm kết thúc, lệnh “JMP ESP” / “CALL ESP” sẽ được thực thi, do đó phần shellcode ngay sau đó sẽ được thực thi
  • 26. SECURITY BOOTCAMP 2012 | Make yourself to be an expert! 26 Bypass ASLR Return-to-eax : – Phương pháp này được sử dụng trong các trường 54 hợp thanh ghi EAX được dùng để store return value, khi đó thanh ghi EAX sẽ trỏ về buffer, ta chỉ cần chèn shellcode vào buffer, sau đó tìm instruction “jmp eax” và overwrite vào RET
  • 27. SECURITY BOOTCAMP 2012 | Make yourself to be an expert! 27 Bypass ASLR Heapspray : – Thay vì return về Stack, với cơ chế của các 54 browser ngày nay, ta có thể return về Heap – Ta sẽ “spray” shellcode ở nhiều nơi trên Heap – Với kỹ thuật này, ta không cần quan tâm đến việc encode shellcode vì tất cả character đã được “allow” bởi Javascript
  • 28. SECURITY BOOTCAMP 2012 | Make yourself to be an expert! 28 DEP / NX Cơ chế bảo vệ của OS Nguyên tắc là OS sẽ mark các page memory là 54 Non-Execution => Shellcode đặt trên Stack hay Heap đều không thể Execute
  • 29. SECURITY BOOTCAMP 2012 | Make yourself to be an expert! 29 DEP / NX Cơ chế bảo vệ của OS Nguyên tắc là OS sẽ mark các page memory là 54 Non-Execution => Shellcode đặt trên Stack hay Heap đều không thể Execute
  • 30. SECURITY BOOTCAMP 2012 | Make yourself to be an expert! Bypass DEP / NX 30 Return-to-glibc – Section .text/.code luôn luôn được thực thi => thay 54 vì trỏ về shellcode, ta có thể trỏ về các hàm trong glibc hay các instruction trong chính chương trình
  • 31. SECURITY BOOTCAMP 2012 | Make yourself to be an expert! Bypass DEP / NX 31 Return-to-glibc – Có thể thực hiện chained return-to-glibc bằng cách 54 kết hợp sử dụng POP-POP-RET
  • 32. SECURITY BOOTCAMP 2012 | Make yourself to be an expert! Bypass DEP / NX 32 Return-to-glibc – Trên Windows, Cơ chế DEP cũ có thể dễ dạng bị 54 disable bởi các Windows API “NtSetInformationProcess” thông qua kỹ thuật return-to-glibc
  • 33. SECURITY BOOTCAMP 2012 | Make yourself to be an expert! Permanent DEP 33 Phiên bản improve của DEP DEP không thể bị change (disable) sau khi thiết 54 lập
  • 34. SECURITY BOOTCAMP 2012 | Make yourself to be an expert! Bypass Permanent DEP 34 Return Oriented Programing (ROP) – Là kỹ thuật mở rộng của return-to-glibc 54 – Dựa trên kỹ thuật return-to-glibc và “borrowed code chunks” => Return về các instruction trong section text/code – ESP sẽ là key (thay vì EIP) Payload Already Inside:Data re-use for ROP Exploits – Long Le Dinh
  • 35. SECURITY BOOTCAMP 2012 | Make yourself to be an expert! Other Vulnerbility ? 35 Format String (lỗi định dạng) Integer Overflow (tràn số nguyên) 54 – Bypass checking – Possible memory corruption Race Condition User-after-free
  • 36. SECURITY BOOTCAMP 2012 | Make yourself to be an expert! 36 Format String Xuất phát từ việc sử dụng format string không đúng cách 54 print(“%d”,number); print(number); Khác nhau như thế nào ?
  • 37. SECURITY BOOTCAMP 2012 | Make yourself to be an expert! 37 Format String Cho phép attack có thể “view” stack memory sử dụng %x 54 Cho phép attack có thể write value vào 1 arbitrary memory sử dụng %n
  • 38. SECURITY BOOTCAMP 2012 | Make yourself to be an expert! 38 Format String Không có RET => Làm sao để chiếm control ? – Overwrite section .dtors 54 – Overwrite GOT table
  • 39. SECURITY BOOTCAMP 2012 | Make yourself to be an expert! 39 Use-after-free Modern race condition for browser Objects in memory 54 – - Replacing objects in memory on the fly – - Replacing them with user-controlled strings
  • 40. SECURITY BOOTCAMP 2012 | Make yourself to be an expert! 40 Use-after-free Example : 1 class bao gồm 3 member và 3 method 54 Class vuln() { – int number1, number2, number3; – void func1() {…}; – void func2() {…}; – void func3() {…}; }
  • 41. SECURITY BOOTCAMP 2012 | Make yourself to be an expert! 41 Use-after-free Trên memory : 54 VTABLE ----> FPTR1 ----------> code NUMBER1 FPTR2 ----------> code NUMBER2 FPTR3 ----------> code NUMBER3
  • 42. SECURITY BOOTCAMP 2012 | Make yourself to be an expert! 42 Use-after-free Nếu ta khởi tạo 2 instance của class đó : b VTABLE ----> FPTR1 ----------> code 54 NUMBER1 FPTR2 ----------> code NUMBER2 FPTR3 ----------> code NUMBER3 a VTABLE ----> FPTR1 ----------> code NUMBER1 FPTR2 ----------> code NUMBER2 FPTR3 ----------> code NUMBER3
  • 43. SECURITY BOOTCAMP 2012 | Make yourself to be an expert! Vtable overwrite 43 Khi ta thực hiện : 54 – strcpy(b.number3, argv[1]); – a.method2(); => Nếu ta input dữ liệu lớn hơn size của number3 thì ta có thể overwrite lên các data khác
  • 44. SECURITY BOOTCAMP 2012 | Make yourself to be an expert! 44 Use-after-free Back to use-after-free : – x = new ABC() – y = clone(x) 54 – destroy(x) – y.method2()
  • 45. SECURITY BOOTCAMP 2012 | Make yourself to be an expert! 45 Use-after-free x = new ABC() : – x VTABLE – MEMBER1 54 – MEMBER2 – MEMBER3 – MEMBER4
  • 46. SECURITY BOOTCAMP 2012 | Make yourself to be an expert! 46 Use-after-free y = clone(x) : – y pointer -----> x VTABLE – MEMBER1 54 – MEMBER2 – MEMBER3 – MEMBER4
  • 47. SECURITY BOOTCAMP 2012 | Make yourself to be an expert! 47 Use-after-free destroy(x) y.method2() : 54 – y VTABLE – MEMBER1 – MEMBER2 – MEMBER3 – MEMBER4
  • 48. SECURITY BOOTCAMP 2012 | Make yourself to be an expert! 48 Use-after-free Idea : nếu ngay sau lúc destroy x, ta có thể input data vào (đủ nhanh) với đúng memory size của 54 object x thì sẽ overwrite vtable object x thành công – y pointer -----> 41414141 – AAAA – AAAA – AAAA – AAAA
  • 49. SECURITY BOOTCAMP 2012 | Make yourself to be an expert! 0day 49 1day Vulnernablity vs Reverse Engineering Patch for finding Vulnerability 54
  • 50. SECURITY BOOTCAMP 2012 | Make yourself to be an expert! Learning More ? 50 Ebooks : – The Art of Exploitation – The Shellcoder's Handbook: Discovering and 54 Exploiting Security Holes – Grey Hat Hacking - Ethical Hackers Handbook – Nghệ thuật tận dụng lỗi phần mềm - NamNT Sites : – https://www.corelan.be – http://resources.infosecinstitute.com/
  • 51. SECURITY BOOTCAMP 2012 | Make yourself to be an expert! Learning More ? 51 Training Courses Wargames : 54 – Online : http://www.overthewire.org/wargames/ – Offline : exploit-exercises Capture The Flag : – CSAW – HITB – Defcon – …
  • 52. SECURITY BOOTCAMP 2012 | Make yourself to be an expert! Exploit Listing Sites 52 Exploit-DB Injector 54 CVE Details Packetstorm CERT Mitre National Vulnerability Database Common Weakness Enumberation
  • 53. SECURITY BOOTCAMP 2012 | Make yourself to be an expert! Any Questions ? 53 54
  • 54. SECURITY BOOTCAMP 2012 | Make yourself to be an expert! 54 Thank you very much ! 54