Thứ Hai, 7 tháng 5, 2012

Tăng cường bảo mật cho Kernel Linux


Vấn đề

Làm thế nào để thiết lập các tùy chọn bảo mật cấp cao với TCP/IP và bộ nhớ ảo (virtual memory) để cải thiện bảo mật và hiệu năng của hệ thống? Cấu hình Linux kernel như thế nào để ngăn chặn các dạng tấn công đã biết bằng cách sử dụng /etc/sysctl.conf? Thiết lập các tham số của kernel như thế nào?

Giải pháp

sysctl là một giao diện cho phép bạn thực hiện các thay đổi tới một Linux kernel đang hoạt động. Với /etc/sysctl.conf bạn có thể cấu hình rất nhiều các thiết lập về mạng và hệ thống Linux, như:
1.Cấu hình giới hạn băng thông mạng cho IPv4
2.Cấu hình giới hạn băng thông mạng cho IPv6
3. Bật lá chắn bảo vệ
4. Ngăn cản các dạng ‘syn flood attack’ thông thường
5. Bật chế độ xác thực địa chỉ IP nguồn verification
6. Ngăn chặn cracker sử dụng spoofing attack theo địa chỉ IP của server.
7. Log lại những kiểu gói tin (packets) khả nghi, như spoofed packets (giả mạo gói tin), các gói định tuyến nguồn, và chuyển hướng.

lệnh sysctl

Lệnh sysctl được sử dụng để sửa đổi các tham số của kernel khi đang chạy. /etc/sysctl.conf là một file text lưu trữ các giá trị sysctl để đọc vào bộ nhớ và thiết thiết lập bởi sysctl lúc khởi động. Để xem các giá trị hiện hành, dùng lệnh:

# sysctl -a
# sysctl -A
# sysctl mib
# sysctl net.ipv4.conf.all.rp_filter
Để tải các thiết lập, dùng lệnh:
# sysctl -p

File /etc/sysctl.conf mẫu

Sửa /etc/sysctl.conf và cập nhật nó như sau. File này có hướng dẫn với các comments kèm theo. Tuy nhiên, Tôi khuyên bạn nên đọc tài liệu hướng dẫn từ các file help chính thức của Linux kernel để điểu chỉnh sysctl (xem dưới đây):
# The following is suitable for dedicated web server, mail, ftp server etc.
# ---------------------------------------
# BOOLEAN Values:
# a) 0 (zero) - disabled / no / false
# b) Non zero - enabled / yes / true
# --------------------------------------
# Controls IP packet forwarding
net.ipv4.ip_forward = 0
 
# Controls source route verification
net.ipv4.conf.default.rp_filter = 1
 
# Do not accept source routing
net.ipv4.conf.default.accept_source_route = 0
 
# Controls the System Request debugging functionality of the kernel
kernel.sysrq = 0
 
# Controls whether core dumps will append the PID to the core filename
# Useful for debugging multi-threaded applications
kernel.core_uses_pid = 1
 
# Controls the use of TCP syncookies
#net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_synack_retries = 2
 
########## IPv4 networking start ##############
# Send redirects, if router, but this is just server
net.ipv4.conf.all.send_redirects = 0
net.ipv4.conf.default.send_redirects = 0
 
# Accept packets with SRR option? No
net.ipv4.conf.all.accept_source_route = 0
 
# Accept Redirects? No, this is not router
net.ipv4.conf.all.accept_redirects = 0
net.ipv4.conf.all.secure_redirects = 0
 
# Log packets with impossible addresses to kernel log? yes
net.ipv4.conf.all.log_martians = 1
net.ipv4.conf.default.accept_source_route = 0
net.ipv4.conf.default.accept_redirects = 0
net.ipv4.conf.default.secure_redirects = 0
 
# Ignore all ICMP ECHO and TIMESTAMP requests sent to it via broadcast/multicast
net.ipv4.icmp_echo_ignore_broadcasts = 1
 
# Prevent against the common 'syn flood attack'
net.ipv4.tcp_syncookies = 1
 
# Enable source validation by reversed path, as specified in RFC1812
net.ipv4.conf.all.rp_filter = 1
net.ipv4.conf.default.rp_filter = 1
 
########## IPv6 networking start ##############
# Number of Router Solicitations to send until assuming no routers are present.
# This is host and not router
net.ipv6.conf.default.router_solicitations = 0
 
# Accept Router Preference in RA?
net.ipv6.conf.default.accept_ra_rtr_pref = 0
 
# Learn Prefix Information in Router Advertisement
net.ipv6.conf.default.accept_ra_pinfo = 0
 
# Setting controls whether the system will accept Hop Limit settings from a router advertisement
net.ipv6.conf.default.accept_ra_defrtr = 0
 
#router advertisements can cause the system to assign a global unicast address to an interface
net.ipv6.conf.default.autoconf = 0
 
#how many neighbor solicitations to send out per address?
net.ipv6.conf.default.dad_transmits = 0
 
# How many global unicast IPv6 addresses can be assigned to each interface?
net.ipv6.conf.default.max_addresses = 1
 
########## IPv6 networking ends ##############
 
#Enable ExecShield protection
kernel.exec-shield = 1
kernel.randomize_va_space = 1
 
# TCP and memory optimization
# increase TCP max buffer size setable using setsockopt()
#net.ipv4.tcp_rmem = 4096 87380 8388608
#net.ipv4.tcp_wmem = 4096 87380 8388608
 
# increase Linux auto tuning TCP buffer limits
#net.core.rmem_max = 8388608
#net.core.wmem_max = 8388608
#net.core.netdev_max_backlog = 5000
#net.ipv4.tcp_window_scaling = 1
 
# increase system file descriptor limit
fs.file-max = 65535
 
#Allow for more PIDs
kernel.pid_max = 65536
 
#Increase system IP port limits
net.ipv4.ip_local_port_range = 2000 65000

Không có nhận xét nào:

Đăng nhận xét