본문 바로가기

사이버보안 기능대회/3과제

서버 - Day02 : ssh, web, iptables

NAT 끄고 시작 - ip link set ens32 down

NAT, hostonly는 상황에 따라서 켜고 끄고

라우팅

/etc/sysctl.conf

해당 파일에 28번째 줄의 net.ipv4.ip_forward=1 주석을 해제해준다.

그리고 적용을 위해 sysctl -p /etc/sysctl.conf 를 입력해준다.

(일회용으로 해주고 싶으면 sysctl -w net.ipv4.ip_forward=1을 입력)

Main-Server -> Clinet1

Main-Server에서 Client1으로 ping을 보내면 잘 가는것을 확인할 수 있다.


NAT (일단보류)

더보기

masqurade 이용 : 모든 Client를 라우터의 ip로 변환해서 통신

iptables -A FORWARD -o ens34 -j ACCEPT : 규칙 추가, outbound로 ens34 인터페이스를 허용

iptables -t nat -A POSTROUTING -o ens33 -j MASQUERADE : MASQUERADE 사용


SSH

openssh 설치 후 접속

Main-Server

ssh 서버 설치 : apt install -y ssh (설치 후 재시작)

서비스 확인 : systemctl status ssh

Clint 접속 : ssh sunrin@22.1.24.10

 

root로그인 허용

Main-Server

vim /etc/ssh/sshd_config

28번째줄의 PermitRootLogin ~~ 를 yes로 변경

서비스 재시작

service restart ssh

service restart sshd

접속 확인

 

포트 22번에서 22000으로 변경

Main-Server

vim /etc/ssh/sshd_config

5번째 줄의 Port 22를 22000으로 변경

서비스 재시작

service restart ssh

service restart sshd


Web 서버

Main-Server : apache 서버

Slave-Server : nginx 서버

 

설치

Main-Server : apt -y install apache2

Slave-Server : apt -y install nginx

접속

Client1

index.html 변경

웹서버 루트 디렉터리 : /var/www/html/

Main-Server : vi /var/www/html/index.html

Slave-Server : vi /var/www/html/index.nginx-debian.html

들어간후 알아서 변경

확인

Client1

루트 디렉토리 변경

Main-Server : vi /etc/apache2/apache2.conf, vi /etc/apache2/sites-available/000-default.conf

그후 서비스 재시작 service apache2 restart

Slave-Server : vi /etc/nginx/sites-enabled/default

그후 서비스 재시작 service nginx restart

(당연히 /home/tempWeb 폴더와 그 안에 index.html 파일은 만들어져있어야 함)

확인

Client1


iptables

iptables로 라우터에서 client1이 Main-Server Web에 접속되는거 차단하기

router : iptables -A FORWARD -d 22.1.24.10 -p tcp --dport 80 -j DROP

FORWARD : -A CHAIN 에서 CHAIN에 들어가는 옵션으로 현재 Router는 자기한테 오는 패킷이 아닌 다른 PC에 가는 패킷을 검사하므로 FORARD를 입력해주어야 한다.

만약 자기한테 오는 패킷을 필터링하고 싶으면 INPUT

ex) Main-Server에서 ssh 차단

더보기

 

Main-Server

-d : destination

-p : protocol

--dport : destination port

-j DROP : 거부

성공적으로 로딩이 안되는것을 확인할 수 있다.