KỸ THUẬT TẤN CÔNG VÀ PHÒNG THỦ TRÊN KHÔNG GIAN MẠNG

Institute of Network Security - istudy.ispace.edu.vn

NỘI DUNG

• Module 01: Tổng quan An ninh mạng • MMoodduullee 0022:: KKỹỹ tthhuuậậtt ttấấnn ccôônngg • Module 03: Kỹ thuật mã hóa • Module 04: Bảo mật hệ điều hành • Module 05: Bảo mật ứng dụng • Module 06: Virus và mã độc • Module 07: Các công cụ phân tích an ninh mạng • Module 08: Chính sách bảo mật và phục hồi thảm họa dữ liệu • Ôn tập • Báo cáo đồ án • Thi cuối khóa

Institute of Network Security - istudy.ispace.edu.vn

Module 02: KỸ THUẬT TẤN CÔNG

• Lesson 01: Footprinting và Reconnaissance • Lesson 02: Google Hacking • Lesson 03: Scanning Networks • Lesson 04: Enumeration • Lesson 05: System Hacking • Lesson 06: Sniffer hệ thống mạng • Lesson 07: Social Engineering • Lesson 08: Denial of Service • Lesson 09: Session Hijacking • Lesson 10: SQL Injection • Lesson 11: Hacking Wireless Networks • Lesson 12: Buffer Overflow

Institute of Network Security - istudy.ispace.edu.vn

Buffer Overflows

Institute of Network Security - istudy.ispace.edu.vn

Nội dung

• Giới thiệu về lỗi tràn bộ đệm • Windows Assembly • Stack Overflows • Heap Corruption • Format String Vulnerability

Institute of Network Security - istudy.ispace.edu.vn

Giới thiệu về lỗi tràn bộ đệm

• Buffer(bộ đệm) là một vùng dữ liệu (trên RAM) được cấp

phát trong quá trình thực thi ứng dụng.

• Buffer OverFlow (BoF –tràn bộ đệm) là lỗi của phần mềm khi ghi khối dữ liệu quá lớn so với kích thước thực của Buffer.

• Lỗ hổng tràn bộ đệm là lỗi tràn bộ đệm của phần mềm cho phép Hacker lợi dụng cài đặt mã độc và kiểm soát hệ thống.

• Giới thiệu về Shellcode:

– Là một đoạn mã máy dùng để thực hiện một việc gì đó khi được

gọi đến như: mở cmd, bind port, load dll…

Institute of Network Security - istudy.ispace.edu.vn

Giới thiệu về lỗi tràn bộ đệm

void buffover(int i)

{ byte buffer[5]; strcpy(buffer,”123”); }

void demo_function(int i) { byte buffer[8];

strcpy(buffer,”123456…shellcode”); -> Tấn công ở đây! }

Institute of Network Security - istudy.ispace.edu.vn

Giới thiệu về lỗi tràn bộ đệm

• Dấu hiệu nhận diện ứng dụng bị lỗi tràn bộ đệm

Institute of Network Security - istudy.ispace.edu.vn

Giới thiệu về lỗi tràn bộ đệm

• Sơ đồ phân bố vùng nhớ

của ứng dụng

• Windows x86 32 bit

– System dll – Stack – Heap

Institute of Network Security - istudy.ispace.edu.vn

Giới thiệu về lỗi tràn bộ đệm

• Memory Allocation

Institute of Network Security - istudy.ispace.edu.vn

Giới thiệu về lỗi tràn bộ đệm

• Application Memory Layout

– 2GB của bộ nhớ ảo sẽ được cấp cho user mode và 2GB còn lại là

cho kernel mode.

– Trong Windows địa chỉ từ 0x00000000 đến 0x7fffffff dành cho user mode và từ 0x80000000 đến 0xBfffffff cho kernel mode.

Institute of Network Security - istudy.ispace.edu.vn

Giới thiệu về lỗi tràn bộ đệm

• Application Structure

Institute of Network Security - istudy.ispace.edu.vn

Giới thiệu về lỗi tràn bộ đệm

• Phân loại vùng đệm – Stack OverFlow

• (Buffer trên Stack)

– Heap OverFlow

• (Buffer trên Heap)

Institute of Network Security - istudy.ispace.edu.vn

Giới thiệu về lỗi tràn bộ đệm

Institute of Network Security - istudy.ispace.edu.vn

Giới thiệu về lỗi tràn bộ đệm

Institute of Network Security - istudy.ispace.edu.vn

Giới thiệu về lỗi tràn bộ đệm

• Tăng tốc lây lan và phá hoại của Virus

– Code Red (2001) –lỗi trong IIS. – Blaster (2003) –lỗi trong DCOM RPC. – Sasser (2004) –lỗi trong LSASS. – Conficker (2009) –lỗi RPC…

• Mất quyền kiểm soát hệ thống, mất thông tin nhạy

cảm…

Institute of Network Security - istudy.ispace.edu.vn

Shell Code

• Đoạn mã máy nhỏ. • Thực thi nhiệm vụ đơn

giản.

• Phụ thuộc hệ điều hành, cấu trúc tập lệnh CPU.

• Mã độc.

Institute of Network Security - istudy.ispace.edu.vn

Shell Code

• Conflicker Shellcode

Institute of Network Security - istudy.ispace.edu.vn

Stack Overflow

Institute of Network Security - istudy.ispace.edu.vn

Stack Overflow

• LIFO. • Biến cục bộ. • Lời gọi hàm. • Exception

Institute of Network Security - istudy.ispace.edu.vn

Stack Overflow

Institute of Network Security - istudy.ispace.edu.vn

Stack Overflow

Institute of Network Security - istudy.ispace.edu.vn

Stack Overflow

• Buffer Injection Techniques • Optimizing the Injection Vector – Quyết định vị trí đặt payload. – File trên đĩa. – Những biến môi trường được điều khiển bởi local user. – Biến môi trường bên trong một Web request. – Những vùng có thể điều chỉnh bởi người dùng trong một giao thức

mạng.

• Những phương pháp để payload được xử lý

– Direct jump ( Guessing Offsets) – Blind Return – Pop Return – Call Register – No Operation (NOP) Sled

Institute of Network Security - istudy.ispace.edu.vn

Stack Overflow

A(){ // … A1(“Xin chào”); A2(“tiếp tục’); } A1(char* in){ *bar; char c[12]; char strcpy(c,in); return; }

Institute of Network Security - istudy.ispace.edu.vn

Stack Overflow

• Gọi hàm A1(AAAAAAAA…AAAAAAAA);

Institute of Network Security - istudy.ispace.edu.vn

Stack Overflow

Thay thế địa chỉ trả về bằng địa chỉ Shellcode

Institute of Network Security - istudy.ispace.edu.vn

Heap Corruption

Institute of Network Security - istudy.ispace.edu.vn

Heap Corruption

Institute of Network Security - istudy.ispace.edu.vn

Heap Corruption

Institute of Network Security - istudy.ispace.edu.vn

Heap Corruption

Institute of Network Security - istudy.ispace.edu.vn

Heap Corruption

Institute of Network Security - istudy.ispace.edu.vn

Phòng chống lỗi Buffer Overflow

Institute of Network Security - istudy.ispace.edu.vn

Phòng chống lỗi Buffer Overflow

• Giải pháp ngăn chặn việc chặn địa chỉ trả về.

Institute of Network Security - istudy.ispace.edu.vn

Phòng chống lỗi Buffer Overflow

• Ghi đè SEH Handle thay vì địa chỉ trả về.

– Microsoft sử dụng thuật toán kiểm tra độ chính xác của địa chỉ

SEH.

– Thuật toán này không hoàn thiện dẫn đến khả năng đánh lừa

thuật toán (Bypass SafeSEH).

– Ngăn chặn thực thi Shellcode trong vùng dữ liệu (Heap, Stack). – Vì lý do tương thích, trong một vài trường hợp Microsoft vẫn cho phép tắt DEP. Điều này dẫn đến khả năng đánh lừa DEP và thực thi mã độc.

• Thay đổi liên tục địa chỉ các vùng nhớ. Làm cho địa chỉ

trả về trở nên vô tác dụng. – Thuật toán thay đổi địa chỉ (ramdom) của Microsoft chưa hoàn

thiện dẫn đến có thể bypass trong một vài trường hợp

Institute of Network Security - istudy.ispace.edu.vn

TÓM LƯỢC BÀI HỌC

• Buffer Overflow. • Các công cụ cần thiết. • Các điểm cần lưu ý.

Institute of Network Security - istudy.ispace.edu.vn

36

Q & A

Institute of Network Security - istudy.ispace.edu.vn