Thứ Năm, 9 tháng 6, 2016

Cài dvwa trên CentOS

Cai ip va name server
Yum install wget
Cai epel

sudo rpm -Uvh epel-release-6*.rpm
Upgrade installed packages to IUS versions
If you already have a software package installed that you want to upgrade to a newer version in the IUS repository, install the IUS yum plug-in for package replacement to simplify the upgrade process.
sudo yum install yum-plugin-replace
The plug-in provides a yum replace command that replaces a specified package and installs any required dependencies at the same time. For example, to replace the installed PHP package with the PHP 5.3 package from the IUS repository, run the following command:
sudo yum replace php --replace-with php53

Cai repo
wget https://centos6.iuscommunity.org/ius-release.rpm
sudo rpm -Uvh ius-release*.rpm
XOng bắt đầu cài web server:
1. Cài httpd
Khởi động bằng: /etc/init.d/httpd start
Khoi dong cung win: chkconfig httpd on --level 2345 (hoi ve cai nay)
2. caif mysql
3. cai mysql server
Mysqld start: service mysqld start
Start Up mysqld
Instructions:
chkconfig --level 2345 mysqld on
dat pass cho root:
mysqladmin -u root password dvwaPASSWORD
Login to mysql and create dvwa database
1.     mysql -uroot -p
2.     dvwaPASSWORD
3.     create database dvwa;
4.     quit
Cai php
Yum install php
yum install php-mysql
yum install php-pear php-pear-DB
Download bằng wget về thư mục var/www/html/
Wget …
cai Zip va unzip để giải nén
yum install zip
yum install unzip
Đổi tên thư mục thành dvwa (giống như database)
rm DVWA-0.19 dvwa
Xóa thư mục zip đi
rm –r DVWA-0.19.zip
Tạo file config.inc.php Backup
cp config.inc.php config.inc.php.BKP
chmod 000 config.inc.php.BKP (bo het quyen tren file backup)
Chỉnh sửa file config.inc.php
vi config.inc.php
thay password thanh pass da tao trong dvwa database
restart apache
Mở trình duyệt gõ:
http://IP/dvwa/setup.php
Nhấn create/reset database
Sau đó đăng nhập với user: admin và pass là: password

CAI MODSECURITY
yum install httpd-devel libxml2-devel pcre-devel apr-devel apr-util-devel curl-devel –y
#yum install gcc
cd /opt/
tar xzfv modsecurity-2.8.0.tar.gz 
cd modsecurity-2.8.0
Tiến hành cài đặt mod_security:
./configure
make
make install
Sau khi cài đặt xong copy file cấu hình và file unicode.mapping tới thư mục Apache
cp modsecurity.conf-recommended /etc/httpd/conf.d/modsecurity.conf
cp unicode.mapping /etc/httpd/conf.d/
Chúng ta đã cài đặt xong mod_security trên server. Bây giờ chúng ta cần cấu hình trong Apache.
Chỉnh sửa file cấu hình và thêm vào dòng sau:
vi /etc/httpd/conf/httpd.conf
LoadModule security2_module modules/mod_security2.so
Lưu  và restart lại Apache:
/etc/init.d/httpd restart

Đặt luật cho modsecurity

1. Đặt bộ luật có sẵn cho web
Tiếp theo chúng ta cấu hình tập luật cho mod_security sử dụng OWASP (Open Web Application Security Project)
cd /etc/httpd
git clone https://github.com/SpiderLabs/owasp-modsecurity-crs.git
mv owasp-modsecurity-crs modsecurity-crs
cd modsecurity-crs
cp modsecurity_crs_10_setup.conf.example modsecurity_crs_10_config.conf
Mở lại file config apache và thêm vào các dòng sau:
Include modsecurity-crs/modsecurity_crs_10_config.conf
Include modsecurity-crs/base_rules/*.conf
Restart lại apache để cập nhật:
/etc/init.d/httpd restart
Bây giờ bạn dùng một số công cụ để thử nghiệm thâm nhập website và kiểm tra lại quá trình làm việc của mod_security.
2. Đặt bằng tay
mở file httpd.conf thêm vào dòng sau:
LoadModule security_module libexec/mod_security.so
Để sử dụng mod_security bạn phải cấu hình cho nó( cái này tùy vào mỗi hệ thống mà sẽ dẫn đến những cấu hình khác nhau). Trước tiên bạn mở file httpd.conf ra và thêm vào dòng sau:
<IfModule mod_security.c>
   # cấu hình cho mod_security
</IfModule>
hoặc bạn có thể tạo riêng một file là modsecurity.conf trong thư mục conf cua apache và include nó tù file cấu hình của apache httpd.conf:
<IfModule mod_security.c>
   include conf/modsecurity.conf
</IfModule>
Sau khi cài đặt mặc định bộ máy filtering sẽ disable ( muốn dùng mod_security chúng ta phải bật nó lên).
Ban chỉ việc thêm vào dòng sau trong file modsecurity.conf:
SecFilterEngine On ( or Off , DynamicOnly )
Sau đây là cách cấu hình cho mod_security để hạn chế những kiểu tấn công cơ bản:

#Chống lại kiểu tấn công thực thi các lệnh:
SecFilter /etc/password
SecFilter /bin/ls
#Chống lại kiểu tấn công Directory traversal
SecFilter "\.\./"
#Lọc các kí tự hay dùng trong shell code
SecFilterForceByteRange 32 126
#Lọc các kí tụ hay dùng trong XSS attack
SecFilter "<(.|\n)+>"
SecFilter "<[[:space:]]*script"
#chống lại kiểu tấn công XSS thông qua PHP session cookie
SecFilterSelective ARG_PHPSESSID "!^[0-9a-z]*$"
SecFilterSelective COOKIE_PHPSESSID "!^[0-9a-z]*$"
#Hạn chế sqlinjection attack
SecFilter "delete[[:space:]]+from"
SecFilter "insert[[:space:]]+into"
SecFilter "select.+from"
#Hạn chế MSSQL injection attack
SecFilter xp_enumdsn
SecFilter xp_filelist
SecFilter xp_availablemedia
SecFilter xp_cmdshell
SecFilter xp_regread
SecFilter xp_regwrite
SecFilter xp_regdeletekey
#chống spam mail
<Location /cgi-bin/FormMail>
    SecFilterSelective "ARG_recipient" "!@modsecurity\.org$"
</Location>
#phát hiện xâm nhập
SecFilterSelective OUTPUT "Volume Serial Number"
SecFilterSelective OUTPUT "Command completed"
SecFilterSelective OUTPUT "Bad command or filename"
SecFilterSelective OUTPUT "file(s) copied"
SecFilterSelective OUTPUT "Index of /cgi-bin/"
SecFilterSelective OUTPUT ".*uid\=\("
#Nếu muốn ghi lại log
SecAuditLog logs/audit.log
SecFilterDebugLog logs/modsec.log
SecFilterDebugLevel 0
#Muốn mod_security phân tích POST request, dùng:
SecFilterScanPOST On

# để mod_security *kiểm tra* URL encoding và UTF-8.
SecFilterCheckURLEncoding On
SecFilterCheckUnicodeEncoding On
Lưu ý:nếu bạn dùng SecFilterCheckUnicodeEncoding On, một số bộ gõ hay input tiếng Việt sẽ không hoạt động, một số bộ gõ hay input tiếng Việt sẽ không hoạt động
Nếu bạn chạy web với nhiều virtualhost và muốn một site trong nhiều sites không dùng mod_security, bạn có thể dùng:
SecFilterSelective SERVERNAME "^tên_của_web_site$" nolog,allow



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

Đăng nhận xét