Micsoftvn
  • 😙Micsoftvn
  • Use Cases
    • For Hacking
      • Kiểm thử mạng
      • Tor - Sock - Proxy
      • Poc
        • POC -draytek-vigor2960 ( CVE-2024-12987 )
    • For Security
      • Security website with htacess file
      • Incident Response
        • Cli AWS - Incident
        • Command line
      • Add basic Authen with Cloudflare
      • Haderning Apache
      • Thiết lập ANTT cho TLS
      • Check network traffic ( Ddos )
      • Tools
        • Tools for AWS
        • Fail2Ban Cheat Sheet
      • Các lỗi thường bảo mật với Websocket
    • For Engineering
      • Thiết lập cấu hình CMD log
      • Cấu hình CLI kết nối đến AWS
      • Sử dụng PET
      • 🔧 Gom Nhóm IP Thành Subnet CIDR Tối Ưu
      • PAC Proxy: Tự Động Cấu Hình Proxy Trong Môi Trường Doanh Nghiệp
      • Sử dụng Podman tạo base images Pentest
      • Tạo YUM Local Repository Trong Container CentOS 7 Sử Dụng Podman
    • For SysAdmin
      • Scripts
        • Bash Script Gen SSH key
        • Health check System
      • Install Oracle Java JDK 18 in Ubuntu 20.04
      • Run script on startup on Ubuntu 22.04
      • Remove Snap from Ubuntu
      • Config Network on Ubuntu Server
      • View Wifi Network Connection
      • Add user can access network interfaces
      • USB drive with QEMU
      • INSTALL AND MANAGE MULTIPLE JAVA JDK AND JRE VERSIONS ON UBUNTU
      • Export Windows Config
      • Auto Install Openvpn
      • Install Nginx Centos 7 or Docker
      • Install Mkdocs
      • Cheat Sheet
        • Cheat sheet Postgres
      • Cài Đặt Fluent Bit Trên Amazon Linux 2023 & Tạo Repository Offline
    • Installations
      • Install Helm on Ubuntu
  • Extras
    • Keyboard Shortcuts
Powered by GitBook
On this page

Was this helpful?

  1. Use Cases
  2. For Security

Haderning Apache

Hướng dẫn haderning cơ bản cho Apache đảm bảo an toàn cho Web Services

1. Xoá bỏ các Module không cần thiết

/usr/sbin/httpd -M

Loại bỏ các modules không cần thiết ( mod_info, mod_status, mod_version, mod_autoindex, mod_dav ) bằng cách edit file : /etc/httpd/conf/httpd.conf

2. Thay đổi các trang báo lỗi mặc định của Webservices

Add thêm các dòng bên dưới trong file : httpd.conf

ErrorDocument 400 /error.html
ErrorDocument 401 /error.html
ErrorDocument 402 /error.html
ErrorDocument 403 /error.html
ErrorDocument 404 /error.html
ErrorDocument 500 /error.html
ErrorDocument 501 /error.html
ErrorDocument 502 /error.html

3. Xoá bỏ banner webservice và thông tin

Add thêm 2 dòng bên dưới trong file : httpd.conf

ServerSignature Off
ServerTokens Prod

4. Giới hạn phương thức truyền lên

Thêm LimitExcept vào thêm trong thư mục Directory như bên dưới

<Directory "/var/www/web">
<LimitExcept GET POST HEAD>
Deny from all
</LimitExcept>
...
</Directory>

5. Giới hạn không cho list file và folder trên thư mục web

Thêm Options -Indexes trong Tag Directory của web

<Directory "/var/www/web">
 Options -Indexes 
</Directory>

6. Thiết lập run Webservices với quyền tối thiểu

Không cho phép user www-data được phép login

useradd –M www-data –s /bin/false
passwd –l www-data

7. Phân quyền thư mục web

chown -R www-data: www-data /var/www 
find /var/www -type d | xargs chmod -R 755
find /var/www -type f  | xargs chmod -R 644
chown -R www-data:www-data

8. Cho phép user www-data được phép run services

Tìm đến phần User và Group trong file httpd.conf

User root (Đổi thành user www-data)
Group root (Đổi thành group www-data)

9. Thiết lập cấu hình không cho phép chạy CGI

Thêm Options –ExecCGI -Includes vào trong tag Directory chứa thư mục web

<Directory /var/www/web>
Options –ExecCGI -Includes
</Directory>

10. Thiếp lập mã hoá Https

grep –i –r ”SSLProtocol” /etc/httpd

Chỉ cho phép sử dụng các giao thức SSL

Mở file : /etc/httpd/conf.d/ssl.conf và đổi thành như bên dưới

SSLProtocol all –SSLv2 –SSLv3

Thiết lập SSLCipherSuite như bên dưới

SSLCipherSuite          ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:DHE-RSA-AES256-SHA:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!3DES:!MD5:!PSK:!SSLv3:!SSLv2

11. Thiết lập cấu hình log Apache như bên dưới

LogFormat "%h %{X-Forwarded-For}i %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\"" tcbs_combined

12. Thiết lập giới hạn php trong php.ini

open_basedir = /var/www:/path/to/first/folder:/path/to/second/folder

Trong đó : /path/to/first/folder và /path/to/second/folder là những thư mục php được phép tác động đến

13. Loại bỏ các module nguy hiểm trong php

Thiết lập được thực hiện trong file php.ini

disable_functions = exec,passthru,shell_exec,system,proc_open,popen,curl_exec,
curl_multi_exec,parse_ini_file,show_source, symlink

Check kiểm tra load module

php -m
  • Lưu ý khi các thiết lập được cấu hình song cần restart lại dịch vụ

PreviousAdd basic Authen with CloudflareNextThiết lập ANTT cho TLS

Last updated 2 years ago

Was this helpful?