Security Linux
• • • • • • • • Discretionary access control (DAC) Linux Security Modules (LSM) Framework SELinux Concepts. NFS security. NIS (Network Information Service ) ( PAM (Pluggable Authentication Modules) FIREWALL. LDAP directory
Discretionary access control (DAC)
• • • • Prior to Linux kernel 2.6, DAC was the only security framework for Linux. In a DAC model, security decisions are based solely on user identity and ownership of the objects. No protection against malicious or flawed software. Each user has complete discretion over his/her own objects.
DAC
• Only two major categories of users: admin and other. • Too much privilege. • Unbounded privilege escalation
DAC: Details
• Each process is associated with some credentials, which binds the process to a specific user or a specific group. The use of credentials requires support both in the process data structure and in the resource being protected.
uid,gid user and group real identifiers User and group effective identifiers fuid, egid
fsuid,fsgid
•
User and group effective identifiers for file access Supplemental group identifiers
groups
suid,sgid
user and group saved identifiers
DAC: Details
• • • •
uid=0 is root, gid=0 is root group. If uid=0, kernel bypasses the permission checks. When a process is created, it always inherit the credentials of its parent. Effective credentials can be modified using system calls; setuid(), setresuid(), setfsuid() and setreuid()
Linux Security Modules (LSM) Framework
• At the Linux Kernel 2.5 Summit (2001), several different security projects were proposed for the kernel. • These different approaches were often incompatible. • Under guidance of Linus, a group was formed to create Linux Security Modules framework with following principles: – The Linux kernel still does its normal security checks. – When kernel needs to decide if access should be granted, it also asks a security module whether or not the action is okay. – An administrator should pick the security module he wants.
LSM Architecture
• The LSM framework was designed so that almost all of its hooks would be restrictive • An authoritative hook makes the absolute final decision: if the hook says a request should be granted, then it's granted no matter what. • A restrictive hook can only add additional restrictions; it can't grant new permissions. • Authoritative model is more flexible. But it requires many radical changes to the Linux kernel.
LSM Architecture
User space Kernel space
Operation
context DAC
0/ERR
LSM
Primary Security Module
0/ERR
Execute operation
Policy files (policy database)
Security Enhanced Linux (SELinux) Module
• Developed by National Security Agency (NSA) • The most comprehensive implementation of LSM. • Most of SElinux became part of LSM framework. • SELinux is primary security module in Fedora distribution.
SELinux: Object Labeling
• Important objects in the OS are labelled; Processes, files, inodes, superblocks etc. • Files persistently labelled via extended attributes. • Labels are called security contexts.
SELinux Concepts
• Identity: each user and process has a unique identity on the system. • Roles – Used to specify acceptable actions from a user. Each role has a set of privileges assigned to it
SELinux Concepts
• Type: This refers to the privileges assigned to the object • Policy rules: allow sysadm_t shadow_t:file getattr;
Simple Sandbox Security Module (sandbox)
• Although a few security modules exists that are very comprehensive, including SELinux, they are hard to manage. • It is difficult for a system administrator to write a correct security policy. • So, I wrote a simple sandbox security module that jail programs to a certain directory during inode_create operation.
sandbox
• In order for it to run:
– Capabilities module needs to be set to m (loadable module, not built-in module) during build process. – Without capabilities module running, sandbox module can stack against SELinux module.
1. Quá trình hoạt động của NFS.
• NFS là dịch vụ hổ trợ cơ chế chia sẻ tài nguyên giữa các máy chủ Linux. Dịch vụ NFS sử dụng rộng rãi dịch vụ RPC (Remote Procedure Call).
• Một số khái niệm chính về NFS
– Virtual filesystem (VFS) là một kỹ thuật tự động chuyển hướng tất cả các truy xuất đến NFS-mount file một cách thông suốt trên Remote Server. – Stateless Operation là những chương trình đọc và ghi tập tin trên hệ thống tập tin cục bộ dựa vào hệ thống để theo dõi và ghi nhận vị trí đọc dữ liệu thông qua con trỏ địa chỉ pointer.
Quá trình hoạt động của NFS (tt).
– Caching trên NFS Client để lưu lại một số dữ liệu cần thiết vào hệ thống cục bộ. – NFS Background Mounting chỉ định khoảng thời gian đợi với tham số gb trong trường hợp Remote Server không tồn tại. – Hard and Soft Mounts có ý nghĩa rằng quá trình mount file luôn được tiến hành và quá trình sử dụng RPC để mount remote file system. – NFS Versions là các phiên bản của NFS. Hiện tại NFS có 3 phiên bản 2, 3 và 4.
NFS security
• Để đảm bảo NFS security, sử dụng dựa vào 2 file /etc/hosts.allow và /etc/hosts.deny. • File /etc/hosts.deny
– portmap,lockd,mountd,rquotad,statd: ALL
Giới thiệu NIS
• Trước khi có NIS, việc chứng thực cho một user login vào hệ thống như sau:
Testuser muốn logon vào ServerB ServerB tìm dữ liệu chứng thực cho testuser trong /etc/passwd. Kết quả: không tìm thấy
`
Testuser không thể login
`
19
Giới thiệu NIS (tt)
• Khi có NIS, việc chứng thực cho user login vào hệ thống có thể hiểu như sau:
Testuser muốn logon vào ServerB ServerB tìm dữ liệu chứng thực cho testuser trong /etc/passwd. Kết quả: không tìm thấy
`
Testuser được phép login
Server B query thông tin NIS database của server A để tìm thông tin chứng thực cho testuser. Kết quả: tìm thấy trong NIS database
`
20
Giới thiệu NIS (tt)
• NIS – Network Information Service là nơi lưu trữ dữ liệu tập trung để các client có thể truy vấn. • Dữ liệu có thể lưu trữ trong NIS là những dữ liệu text.
– /etc/passwd, /etc/hosts, /etc/services, /etc/protocol… – những dữ liệu text này cách nhau bằng “tab”, và có ít nhất một cột có giá trị duy nhất trên mỗi dòng.
21
Pluggable Authentication Modules
• Mỗi ứng dụng có một kiểu xác thực => phức tạp hệ thống. • Pluggable Authentication Modules – PAM: cung cấp một phương thức xác thực tập trung. • Ứng dụng không trực tiếp xác thực, mà chuyển request cho PAM, yêu cầu xác thực. • PAM làm việc và trả về kết quả xác thực cho ứng dụng. • Ứng dụng quyết định cho phép user login hay không.
22
PAM (tt)
• Theo cách hiểu của Windows, PAM đóng vai trò như DLL đối với các ứng dụng khác. • Theo cách hiểu của Linux, PAM là một thư viện. • PAM cung cấp nhiều module xác thực /lib/security từ đơn giản đến phức tạp. • Khi ứng dụng cần xác thực theo phương thức nào thì gọi phương thức đó của trong thư viện của PAM. • Thông tin về các module xác thực của PAM:
– man [pam_module]
23
PAM (tt)
• /lib/security: những module xác thực của PAM. • /etc/security: file cấu hình tương ứng của từng module xác thực của PAM. • /etc/pam.d: file cấu hình của những ứng dụng sử dụng PAM xác thực.
– => mỗi ứng dụng xác thực bằng PAM có một file cấu hình trong /etc/pam.d
24
• module_type: nhận một trong 4 giá trị: auth, account, session, password. • control_flag: cấu hình cách xử lí của ứng dụng với kết quả xác thực do PAM trả về. • module_path: đường dẫn cụ thể của module xác thực. • arguments: các tham số khác.
25
PAM (tt)
module_type auth account Mô tả Ứng dụng yêu cầu user phải nhập password. Không thực hiện chứng thực, dựa vào các yếu tố khác để quyết định user có được login không: login từ đâu, vào giờ nào… Chỉ định những thao tác cần thực hiện trước hoặc sau khi user login. Cho phép user đổi password.
26
session password
PAM (tt)
control_flag required requisite Mô tả Module phải chứng thực thành công, nếu không kết quả fail sẽ được gởi về. Nếu module này fail, kết quả sẽ được trả về ngay lập tức, không sử dụng đến các module sau. Nếu module này thành công, và không có module required nào nữa, kết quả thành công sẽ được trả về. Cho phép tiếp tục kiểm tra module khác, dù module này bị fail.
27
sufficient
optional
PAM (tt)
argument debug no_warn Mô tả Log lại thông tin debug Không gởi msg waring đến ứng dụng.
use_first_pass Lưu lại password, để sử dụng cho lần xác thực sau. try_first_pass Giống option trên, tuy nhiên nếu password fail, yêu cầu user nhập lại.
28
PAM (tt)
Dùng lệnh man [pam_module] để tìm hiểu về từng module xác thực: Vd: man pam_nologin
29
1. FIREWALL.
Firewall : là một kỹ thuật được tích hợp vào hệ thống mạng để chống lại việc truy cập trái phép, bảo vệ các nguồn tài nguyên cũng như hạn chế sự xâm nhập vào hệ thống. Cụ thể firewall sẽ bảo vệ mạng nội bộ (LAN) với mạng Internet. Firewall có các chức năng sau : • Tất cả các trao đổi từ trong ra ngoài và ngược lại đều phải thông qua Firewall. • Chỉ có những trao đổi được phép bởi hệ thống mạng nội bộ mới được quyền thông qua Firewall. • Quản lý chứng thực. • Quản lý cấp quyền. • Quản lý kế toán.
FIREWALL (tt).
Những chính sách Firewall : – Những dịch vụ nào cần ngăn chặn? – Những người nào bạn cần phục vụ? – Mỗi nhóm cần truy cập những dịch vụ nào? – Mỗi dịch vụ sẽ được bảo vệ như thế nào?
2. CÁC LOẠI FIREWALL.
• Packet filtering (Bộ lọc packet) – Địa chỉ IP nơi xuất phát. – Địa chỉ IP nơi nhận. – Cổng TCP nơi xuất phát. – Cổng TCP nơi nhận. • Application gateway : Cơ chế hoạt động dựa trên mô hình Proxy Service. Đòi hỏi trong mô hình này cần phải tồn tại một hay nhiều máy tính đóng vai trò Proxy Server.
Nội dung
Giới thiệu Network Directory Giới thiệu LDAP protocol Cấu trúc lưu trữ LDAP Directory Giới thiệu Openldap
server side daemon client side command
33
Network Directory
• Network directory là một cấu trúc dùng để tổ chức lưu trữ theo dạng phân cấp hình cây. • Network directory được tổ chức để thuận tiện nhất cho việc đọc và tìm kiếm. • Nếu ứng dụng cần nhiều thao tác insert, update thì không nên lưu trữ theo kiểu network directory. • X.500 là một network directory.
34
Giới thiệu LDAP protocol
• Để truy vấn network directory, người ta đã sử dụng giao thức DAP – Directory Access Protocol. • Giao thức này qui định một tập lệnh giao tiếp giữa client và server lưu trữ (network directory) để truy vấn dữ liệu cần thiết. • DAP hoạt động dựa trên giao thức OSI. • LDAP – Lightweight Directory Access Protocol là giao thức ra đời để thay thế DAP. • LDAP định nghĩa một tập lệnh giao tiếp giữa client/server dựa trên giao thức TCP để truy vấn dữ liệu directory.
35
LDAP protocol (tt)
36
LDAP directory
uid=babs, ou=people, dc=example, dc=com DN: Distinguished Name
LDAP directory (tt)
• Những schema và objectclass thường được dùng đều đã được định nghĩa sẵn trong RFC. • Khi muốn định nghĩa một cấu trúc cây thư mục, phân tích, quyết định cần những attribute nào, sau đó tìm những objectclass, schema có những attribute này. • Từ đó, xây dựng nên cấu trúc cây thư mục. • Nếu không có schema thỏa mãn yêu cầu, có thể định nghĩa schema, objectclass mới.
39
LDAP directory (tt)
40
OPENLDAP (tt)
• Openldap là phần mềm mã nguồn mở, dùng để hiện thực LDAP chạy trên hệ điều hành Linux/ UNIX. • Phía server gồm có hai dịch vụ chính:
– slapd: standalone LDAP daemon. Daemon này lắng nghe các request truy vấn LDAP từ client, tiến hành truy vấn, và gởi câu trả lời. – slurpd: LDAP replication daemon. Daemon này dùng để đồng bộ những thay đổi từ LDAP master server sang LDAP slave server.
41
OPENLDAP (tt)
• Để truy vấn LDAP, client dùng những lệnh sau:
– ldapadd: thêm một entry mới. – ldapmodify: chỉnh sửa thông tin một entry. – ldapdelete: xóa một entry. – ldapmodrdn: chỉnh sửa RDN của entry. – ldapsearch: tìm kiếm thông tin entry.
42