Linux/보안장비 운용

DMZ 내부망 서버 설정하기

GGkeeper 2022. 2. 20. 12:32

실습> DMZ 내부망 서버 설정하기

-- UTM1 네트워크 구성도 --

192.168.108.1 : Host OS
192.168.108.100 : CentOS 7,    F/W(NIDS) F/W에 Snort 를 설치한다.
192.168.108.101 : CentOS 7,    DMZ망 WEB Server#1 IP주소 (DNAT/SNAT o)
192.168.108.102 : Rocky Linux, DMZ망 WEB Server#2 IP주소 (DNAT/SNAT o)
192.168.108.103 : Rocky Linux, DMZ망 WEB Server#3 IP주소 (DNAT/SNAT o)
192.168.108.104 : CentOS 7,    DMZ망 DB Server IP주소 (DNAT x, SNAT o)
192.168.108.105 :              내부망 윈도우의 SNAT용 IP주소 (DNAT x, SNAT o)
192.168.108.110 : CentOS 7,    DMZ망 DNS Server (DNAT/SNAT o)
192.168.108.200 : Kali Linux,  Attacker 

                  192.168.108.110  -------------------------------------------------------+ 
                  192.168.108.105                  DNAT                                   |
                  192.168.108.104(DBMS)                                                   |
                  192.168.108.103:80 -------------------------------+                     |
192.168.108.200   192.168.108.102:80 ------------------------+      |                     |
Attacker          192.168.108.101:80 -----------------+      |      |                     |
  |               192.168.108.0/24                    |      |      |                     |
  |          108.150  |                               |      |      |                     |
  |     eth0(vmnet8)  |                               |      |      |                     |
외부망 --------------[ SOPHOS UTM1 ] ------- 내부망   |      |      |                     |
  |      eth2(vmnet2) |    |  eth1(vmnet1)            |80    |80    |80                   |
  |           102.254 |      101.254                  |      |      |                     |
  |          <--------+-----------------+             v      v      v                     |
  |                   |   SNAT          |            CentOS Rocky  Rocky                  v
 Host OS              |                 +----------- WEB#1  WEB#2  WEB#3  DBMS(MariaDB)  DNS#1
  |                   | ens38(vmnet2)                .101   .102   .103   .104           .110
192.168.108.1         |                                |      |      |      ^
                    Windows                            |      |      |      |
                     .105                              +------+------+------+
                    ens38(vment2)                      웹서버 모두 DBMS 서버를 사용
                 192.168.102.0/24                          ens33 (vmnet1)
          

내부망의 전체 WEB#1, WEB#2, WEB#3, DBMS(MariaDB) 설정에서 WEB#1 서버만 설정한다.

네트워크 정보 
WEB#1
Network Adapter : VMnet1
서버 유형 : 첫 번째 웹서버
IP주소 : 192.168.101.101
서브넷마스크 : /24
Gateway : 192.168.101.254
DNS1 : 168.126.63.1

IP주소와 라우팅 테이블을 확인한다.
[root@web1 ~]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:0c:29:4a:e5:6c brd ff:ff:ff:ff:ff:ff
    inet 192.168.101.101/24 brd 192.168.101.255 scope global noprefixroute ens33
       valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:fe4a:e56c/64 scope link 
       valid_lft forever preferred_lft forever

[root@web1 ~]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.101.254 0.0.0.0         UG    100    0        0 ens33
192.168.101.0   0.0.0.0         255.255.255.0   U     100    0        0 ens33

WEB#1 서버가 UTM1 장비(192.168.1.254)와 통신이 잘되는지 확인한다.

!!! 확인 !!!
192.168.101.254 UTM1 장비의 MAC 주소가 아닌 다른 MAC주소로 잡고 있어서 고정으로 설정을 하고 통신을 확인한다.

utm1:/root # ifconfig eth1
eth1      Link encap:Ethernet  HWaddr 00:0C:29:99:EC:76  
          inet addr:192.168.101.254  Bcast:192.168.101.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:14 errors:0 dropped:0 overruns:0 frame:0
          TX packets:9 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:840 (840.0 b)  TX bytes:602 (602.0 b)
          Interrupt:16 Base address:0x20a4 

[root@web1 ~]# arp -s 192.168.101.254 00:0c:29:99:ec:76
[root@web1 ~]# arp -n
Address                  HWtype  HWaddress           Flags Mask            Iface
192.168.101.1            ether   00:50:56:c0:00:01   C                     ens33
192.168.101.254          ether   00:0c:29:99:ec:76   CM                    ens33

[root@web1 ~]# ping -c 4 192.168.101.254 
PING 192.168.101.254 (192.168.101.254) 56(84) bytes of data.
64 bytes from 192.168.101.254: icmp_seq=1 ttl=64 time=14.1 ms
64 bytes from 192.168.101.254: icmp_seq=2 ttl=64 time=0.601 ms
64 bytes from 192.168.101.254: icmp_seq=3 ttl=64 time=0.533 ms
64 bytes from 192.168.101.254: icmp_seq=4 ttl=64 time=0.720 ms

--- 192.168.101.254 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3003ms
rtt min/avg/max/mdev = 0.533/3.991/14.113/5.844 ms

내부망에 있는 web1서버가 8.8.8.8과 통신을 하면 실패가 된다.
이유는 UTM의 방화벽 기본 정책이 DROP이기 때문이다.
[root@web1 ~]# ping 8.8.8.8
PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
^C
--- 8.8.8.8 ping statistics ---
7 packets transmitted, 0 received, 100% packet loss, time 6000ms

UTM의 방화벽 기본 정책을 확인한다.
utm1:/root # iptables -nL | grep poli
Chain INPUT (policy DROP)
Chain FORWARD (policy DROP)
Chain OUTPUT (policy DROP)
DROP       icmp --  0.0.0.0/0            0.0.0.0/0            icmptype 8 code 0 policy match dir in pol none
DROP       icmp --  0.0.0.0/0            0.0.0.0/0            icmptype 0 code 0 policy match dir in pol none


IP주소 추가하기
외부에서 192.168.108.101로 접속하면 내부망 웹서버 WEB#1로 보내주기 위한 IP주소를 추가한다. 
Interfaces & Routing
Interfaces -> Additional Addresses -> New Additional Address...

Name: WEB#1
On interface: External
IPv4 address: 192.168.108.101
Netmask: /24 (255.255.255.0)
Comment: 내부망 웹서버#1


SNAT 설정
메뉴 -> Network Protection -> NAT -> NAT
New NAT Rule... 

192.168.101.101 SNAT 설정

Group: :: No Group :: 
Position: Bottom
Rule type: SNAT (source)

Matching condition
For traffic from: WEB#1  <-- WEB#1이 없으니 + 아이콘을 눌러서 등록한다. (카톡 캡처 참고) <-- 192.168.101.101
Using service: Any
Going to: Any

Action
Change the source to: External [WEB#1] (Address)  <-- 192.168.108.101
And the service to:

Automatic firewall rule: 체크 O
Comment: WEB#1 SNAT 설정


SNAT 설정을 하고 Save를 하지 않았을 경우의 iptables nat 테이블의 설정 룰을 확인하면
내부망 웹서버의 IP주소가 등록되지 않은 것을 확인할 수 있다.
utm1:/root # iptables -t nat -nL | grep 192.168.101.101

룰을 저장하기 위해서 Save 버튼을 누른다.

Save하고 나서 콘솔에서 iptables 의 nat 룰을 확인한다.
SNAT 설정을 하고 Save를 했을 경우의 iptables nat 테이블의 설정 룰을 확인하면
내부망 웹서버의 IP주소가 등록된 것을 확인할 수 있다.
utm1:/root # iptables -t nat -nL | grep 192.168.101.101
SNAT       all  --  192.168.101.101      0.0.0.0/0            policy match dir out pol none to:192.168.108.101


내부망 웹서버가 8.8.8.8로 ping 테스트를 하면 외부와 통신이 되는 것을 확인할 수 있다.
[root@web1 ~]# ping -c 4  8.8.8.8
PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
64 bytes from 8.8.8.8: icmp_seq=1 ttl=127 time=40.3 ms
64 bytes from 8.8.8.8: icmp_seq=2 ttl=127 time=38.6 ms
64 bytes from 8.8.8.8: icmp_seq=3 ttl=127 time=39.5 ms
64 bytes from 8.8.8.8: icmp_seq=4 ttl=127 time=40.0 ms

--- 8.8.8.8 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3006ms
rtt min/avg/max/mdev = 38.611/39.621/40.314/0.653 ms


DNAT 설정
외부에서 DMZ 내부망에 있는 서버들로 접속할 수 있도록 길을 열어주는 설정이다.

메뉴 -> Network Protection -> NAT -> NAT
New NAT Rule... 

192.168.108.101 DNAT 설정

Group: :: Please select ::
Position: Bottom
Rule type: DNAT (destination)

Matching condition
For traffic from: Any
Using service: HTTP
Going to: External [WEB#1] (Address)  <-- 192.168.108.101

Action
Change the destination to: WEB#1  <-- 192.168.101.101
And the service to: HTTP

Automatic firewall rule: 체크
Comment: WEB#1 DNAT 설정

DNAT 설정을 하고 Save를 하지 않았을 경우의 iptables nat 테이블의 설정 룰을 확인하면
내부망 웹서버의 IP주소의 SNAT만 설정되어 있고 DNAT가 등록되지 않은 것을 확인할 수 있다.
utm1:/root # iptables -t nat -nL | grep 192.168.101.101
SNAT       all  --  192.168.101.101      0.0.0.0/0            policy match dir out pol none to:192.168.108.101

룰을 저장하기 위해서 Save 버튼을 누르고 룰을 활성화(Enable) 시켜준다.

Save하고 나서 콘솔에서 iptables 의 nat 룰을 확인한다.
DNAT 설정을 하고 Save를 하고 룰을 활성화할 경우의 iptables nat 테이블의 설정 룰을 확인하면
내부망 웹서버의 IP주소의 DNAT가 등록되지 않은 것을 확인할 수 있다.
utm1:/root # iptables -t nat -nL | grep 192.168.101.101
DNAT       tcp  --  0.0.0.0/0            192.168.108.101      tcp spts:1:65535 dpt:80 to:192.168.101.101
SNAT       all  --  192.168.101.101      0.0.0.0/0            policy match dir out pol none to:192.168.108.101
DNAT       tcp  --  0.0.0.0/0            192.168.108.101      tcp spts:1:65535 dpt:80 to:192.168.101.101

웹서버 접속
내부망 web1 서버의 index.html 파일을 작성한다.
[root@web1 ~]# vi /var/www/html/index.html 
Welcome to 192.168.108.101 Server!

브라우저에서 http://192.168.108.101/ 로 접속하면 된다.
http://192.168.108.101/
Welcome to 192.168.108.101 Server!

'Linux > 보안장비 운용' 카테고리의 다른 글

내부망 Win7 설정  (0) 2022.03.02
내부망 WinXP 설정하기  (0) 2022.03.02
Routing 경로 설정  (0) 2022.02.20
UTM 인터페이스 설정  (0) 2022.02.20
쉘 접속 설정  (0) 2022.02.20