실습> 아래 조건에 맞게 서버를 설정하시오.
웹 애플리케이션 보안에 취약하게 만들 Victim Linux를 설치한다.
이 Victim Linux는 웹 애플리케이션이 올라가 있고 공격자가 이 서버를
통해서 여러가지 웹 취약점(취약한 부분)을 통해서 서버를 공격하고 서버에 침투할 수 있다.
보안 담당자는 이 서버의 문제점을 파악하고 서버의 취약점을 해결해서 공격자의 공격을 방어할 수 있다.
-- 조건 --
1. 도메인명
- server1.kr
- www.server1.kr
2. 웹애플리케이션
- 아파치 웹서버
- 가상호스트 : server1.kr
- 웹디렉터리 : /var/www/html
- APM + GD
3. 네트워크 설정
- IP주소 : 192.168.108.101/24
- Gateway : 192.168.108.2
- DNS : 192.168.108.2
4. DB 설정
- DB 사용자 : root
- DB 관리자 비번 : P@ssw0rd
5. OS
- CentOS 7
- 가상머신 이름 : VictimWEB1
- 메모리 : 512M (설치는 1G, 설치 후 512M)
- 어뎁터 : VMnet8(NAT)
-- 조건 --
CentOS 7을 설치 후에 진행한다.
1. 호스트명 등록
호스트명은 설치할 때 설정할 수 있다.
/etc/hosts 파일에 IP주소/도메인명을 등록한다.
[root@www ~]# hostname
www.server1.kr
[root@www ~]# vi /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.108.101 www.server1.kr server1
2. 방화벽 중지
웹서버1에서 네트워크 방화벽을 사용하기 때문에 호스트 방화벽을 모두 내린다.
[root@www ~]# systemctl stop firewalld
[root@www ~]# systemctl disable firewalld
[root@www ~]# iptables -nL
Chain INPUT (policy ACCEPT)
target prot opt source destination
Chain FORWARD (policy ACCEPT)
target prot opt source destination
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
3. APM 설치
웹서버1에서 APM 관련 패키지를 설치한다.
[root@www ~]# yum -y install httpd php php-mysql mariadb mariadb-server
GD 라이브러리를 설치한다.
GD 라이브러리는 서버를 설치하는데 있어서 무조건 필수라고 생각하면 된다.
[root@www ~]# yum -y install php-gd gd gd-devel libjpeg libjpeg-devel giflib giflib-devel libpng libpng-devel freetype freetype-devel
4. 아파치 설정
웹서버 설정파일을 수정한다.
파일의 확장자가 .php, .html이면 php로 인식하는 설정을 한다.
[root@www ~]# vi /etc/httpd/conf.d/php.conf
<FilesMatch \.(php|html)$>
SetHandler application/x-httpd-php
</FilesMatch>
DirectoryIndex index.php index.html
가상호스트를 설정한다.
[root@www ~]# vi /etc/httpd/conf/httpd.conf
:
:(생략)
#############
# server1.kr
#############
# http 설정
<VirtualHost *:80>
ServerAdmin webmaster@server1.kr
DocumentRoot /var/www/html
ServerName server1.kr
ServerAlias www.server1.kr
ErrorLog logs/server1.kr-error_log
CustomLog logs/server1.kr-access_log common
</VirtualHost>
httpd -s 현재 설정된 가상 호스트와 여러 정보들을 확인한다.
[root@www ~]# httpd -S
설정이 완료되면 설정파일의 문법을 체크해서 Syntax OK 메세지가 나오면
설정파일에 정상적으로 설정이 완료된 것이다. 이때 아파치 웹서버를 재시작한다.
/usr/sbin/httpd : 아파치 웹서버 데몬
httpd -t : 설정파일 문법 검사
[root@www ~]# httpd -t
Syntax OK
웹서버 포트를 확인한다.
[root@www ~]# yum -y install net-tools
[root@www ~]# netstat -nltp | grep 80
tcp6 0 0 :::80 :::* LISTEN 897/httpd
5. PHP 설정
PHP 설정파일을 수정한다.
date.timezone : 시간대 설정
short_open_tag : <?php -> <?
expose_php : 연동된 정보 출력 여부
display_errors : 개발용 On, 운영용 Off
개발용 On : PHP 코드가 에러가 발생되면 브라우저 화면에 에러가 출력된다.
운영용 Off : /var/log/httpd 로그 디렉터리에 파일로 기록된다.
[root@www ~]# vi /etc/php.ini
[Date]
date.timezone = Asia/Seoul
short_open_tag = On
#expose_php = Off
display_errors = On
6. 웹서버 연동 확인
아파치 웹서버를 활성화 시키고 시작한다.
[root@www ~]# systemctl --now enable httpd
[root@www ~]# systemctl status httpd
웹 페이지가 잘 연동 되었는지 확인한다.
[root@www ~]# cd /var/www/html
[root@www html]# echo '<? phpinfo(); ?>' > index.html
웹 브라우저에서 PHP 연동이 잘 되었는지 확인한다.
APM 연동 성공 : PHP 연동 정보가 나온다.
APM 연동 실패 : index.html 파일이 다운로드가 된다. 출력이 아무것도 안된다.
http://192.168.108.101/
APM 연동에 성공했다면 index.html 파일은 삭제한다.
[root@www html]# rm -f index.html
명령행에서 php -m을 이용해서 모듈의 정보를 확인할 수 있다.
[root@www html]# php -m
[PHP Modules]
bz2
calendar
Core
ctype
:
:(생략)
7. DBMS 설정
MariaDB 설정파일을 utf8로 동작할 수 있도록 수정한다.
[root@www html]# cd
[root@www ~]# vi /etc/my.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
collation-server = utf8_general_ci
character-set-server = utf8
skip-character-set-client-handshake
bind-address = 127.0.0.1
MariaDB 서비스를 활성화시키고 서비스를 시작한다.
[root@www ~]# systemctl --now enable mariadb
[root@www ~]# systemctl status mariadb
관리자(root) 비밀번호를 P@ssw0rd로 변경한다.
[root@www ~]# mysqladmin -p password
Enter password: <-- 엔터(비번이 없으므로)
New password: <-- P@ssw0rd
Confirm new password: <-- P@ssw0rd
접속용 자동화 설정파일을 생성한다.
[root@www ~]# vi .my.cnf
[client]
host = localhost
user = root
password = P@ssw0rd
[root@www ~]# mysql mysql
MariaDB [mysql]> select host,user,password from user;
+----------------------+------+-------------------------------------------+
| host | user | password |
+----------------------+------+-------------------------------------------+
| localhost | root | *8232A1298A49F710DBEE0B330C42EEC825D4190A |
| web1.linuxmaster.net | root | | <-- 삭제
| 127.0.0.1 | root | | <-- 삭제
| ::1 | root | | <-- 삭제
| localhost | | | <-- 삭제
| web1.linuxmaster.net | | | <-- 삭제
+----------------------+------+-------------------------------------------+
6 rows in set (0.00 sec)
user 테이블에 password 커럼이 값은 없는 레코드를 모두 삭제한다.
MariaDB [mysql]> delete from user where password = '';
Query OK, 5 rows affected (0.00 sec)
MariaDB [mysql]> select host,user,password from user;
+-----------+------+-------------------------------------------+
| host | user | password |
+-----------+------+-------------------------------------------+
| localhost | root | *8232A1298A49F710DBEE0B330C42EEC825D4190A |
+-----------+------+-------------------------------------------+
1 row in set (0.00 sec)
MariaDB [mysql]> select host,user,db from db;
+------+------+---------+
| host | user | db |
+------+------+---------+
| % | | test | <-- 삭제
| % | | test\_% | <-- 삭제
+------+------+---------+
2 rows in set (0.00 sec)
db 테이블에 모든 레코드를 삭제한다.
MariaDB [mysql]> delete from db;
Query OK, 2 rows affected (0.00 sec)
MariaDB [mysql]> select host,user,db from db;
Empty set (0.00 sec)
권한을 다시 적용시킨다.
MariaDB [mysql]> flush privileges;
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> \s
--------------
mysql Ver 15.1 Distrib 5.5.68-MariaDB, for Linux (x86_64) using readline 5.1
Connection id: 3
Current database:
Current user: root@localhost
SSL: Not in use
Current pager: stdout
Using outfile: ''
Using delimiter: ;
Server: MariaDB
Server version: 5.5.68-MariaDB MariaDB Server
Protocol version: 10
Connection: Localhost via UNIX socket <-- 소켓 파일을 이용해서 접속
Server characterset: utf8 <-- 확인
Db characterset: utf8 <-- 확인
Client characterset: utf8 <-- 확인
Conn. characterset: utf8 <-- 확인
UNIX socket: /var/lib/mysql/mysql.sock
Uptime: 3 min 9 sec
Threads: 1 Questions: 7 Slow queries: 0 Opens: 0 Flush tables: 2 Open table avg: 0.037
--------------
MariaDB [(none)]> quit
실습> mywebsite 설정하기
아래 조건에 맞는 웹사이트를 설정한다.
-- 조건 --
1. WEB 백업 파일명 : mywebsite20220119.tar.gz
- 웹 경로 : /var/www/html
2. DB 백업 파일명 : mywebsite.sql
- 압축을 해제하면 그 안에 있다.
3. DB 정보
- DB명 : mywebsite
- 사용자 : root
- 비밀번호 : P@ssw0rd
-- 조건 --
http://192.168.108.101 접속 시 웹페이지가 뜨면 성공
1. WEB 파일 업로드
winscp 프로그램으로 파일을 업로드한다.
[root@www ~]# ls
anaconda-ks.cfg mywebsite20220119.tar.gz
[root@www ~]# cp mywebsite20220119.tar.gz /var/www/html/
[root@www ~]# cd /var/www/html/
[root@www html]# tar xzf mywebsite20220119.tar.gz
[root@www html]# ls
mywebsite20220119.tar.gz public_html
[root@www html]# mv public_html/* .
[root@www html]# rm -rf mywebsite20220119.tar.gz public_html/
2. DB 설정
mywebsite DB를 생성하고 mywebsite.sql 파일의 내용을 모두 mywebsite DB에 넣으면 복구가 된다.
[root@www html]# mysql -e 'create database mywebsite'
[root@www html]# mysql mywebsite < mywebsite.sql
DB 접속 파일을 확인하고 자신의 DB 정보에 맞게 수정한다.
[root@www html]# vi dbconnect.php
<?
$DBHOST = "localhost";
$DBUSER = "root";
$DBPASS = "P@ssw0rd";
$DBNAME = "mywebsite";
$TBNAME = (isset($_GET['id'])) ? $_GET['id'] : "";
$connect = mysqli_connect($DBHOST, $DBUSER, $DBPASS, $DBNAME) or die("DBMS에 접속 실패");
?>
3. 웹 페이지 접속
웹사이트로 접속해서 웹페이지가 나오면 성공이다.
http://192.168.108.101
실습> 입력값 검증
# vi test.sh
#!/bin/sh
$1
# chmod 755 test.sh
# ./test.sh pwd
# ./test.sh pwd ls
# ./test.sh pwd;ls
프록시의 역할
Client가 Resquest 하는 웹 데이터를 중간에 가로채서 Server로 전송하는 역할을 한다.
Server가 Responset하는 웹 데이터를 중간에 가로채서 Client로 전송하는 역할을 한다.
이를 통해 Client와 Server간에 지나다니는 웹 데이터를 가로채서 분석에 활용할 수 있다.
프록시의 위치
프록시는 Client와 Server의 중간에 위치한 상태에 놓이게 된다.
Request
----------> ---------->
[Client] [Proxy] [Server]
<---------- <----------
Response
프록시의 종류
Burp suite, Paros, fiddler ...
'Linux > 모의해킹' 카테고리의 다른 글
| 웹 데이터 조작하기 (0) | 2022.01.19 |
|---|---|
| burp (proxy) 툴 사용하기 (0) | 2022.01.19 |
| 모의해킹 체크리스트 (0) | 2022.01.19 |
| 웹 서버 접속 룰 탐지하기 (0) | 2022.01.14 |
| snort rule 설정 (0) | 2022.01.14 |