Hướng dẫn mở port và chặn port trên kali linux


Để an toàn, đôi khi bạn sẽ phải thực hiện chặn hoặc mở một port trên Server

Một số port phổ biến hay dùng
TCP port 80 – HTTP Server
TCP port 443 – HTTPS Server
TCP port 25 – Mail Server
TCP port 22 – OpenSSH (remote) secure shell server
TCP port 110 – POP3 (Post Office Protocol v3) server
TCP port 143 – Internet Message Access Protocol (IMAP) — management of email messages
TCP / UDP port 53 – Domain Name System (DNS)

Bạn có thể xem danh sách đầy đủ các port trong file /etc/services

Block Incoming Port

/sbin/iptables -A INPUT -p tcp --destination-port {PORT-NUMBER-HERE} -j DROP

### interface section use eth1 ###
/sbin/iptables -A INPUT -i eth1 -p tcp --destination-port {PORT-NUMBER-HERE} -j DROP
### only drop port for given IP or Subnet ##
/sbin/iptables -A INPUT -i eth0 -p tcp --destination-port {PORT-NUMBER-HERE} -s {IP-ADDRESS-HERE} -j DROP
/sbin/iptables -A INPUT -i eth0 -p tcp --destination-port {PORT-NUMBER-HERE} -s {IP/SUBNET-HERE} -j DROP

Ví dụ, để chặn imcoming port 80 (HTTP server), sử dụng lệnh sau

/sbin/iptables -A INPUT -p tcp --destination-port 80 -j DROP

/sbin/service iptables save

Để chặn port 80 với tất cả IP, chỉ cho duy nhất IP có địa chỉ 1.2.3.4 truy cập

/sbin/iptables -A INPUT -p tcp -i eth1 -s ! 1.2.3.4 --dport 80 -j DROP

Block Outgoing Port

Cú pháp

/sbin/iptables -A OUTPUT -p tcp --dport {PORT-NUMBER-HERE} -j DROP

### interface section use eth1 ###
/sbin/iptables -A OUTPUT -i eth1 -p tcp --dport {PORT-NUMBER-HERE} -j DROP
### only drop port for given IP or Subnet ##
/sbin/iptables -A OUTPUT -i eth0 -p tcp --destination-port {PORT-NUMBER-HERE} -s {IP-ADDRESS-HERE} -j DROP
/sbin/iptables -A OUTPUT -i eth0 -p tcp --destination-port {PORT-NUMBER-HERE} -s {IP/SUBNET-HERE} -j DROP

Ví dụ, để chặn outgoing port 25, sử dụng lệnh sau

/sbin/iptables -A OUTPUT -p tcp --dport 25 -j DROP

/sbin/service iptables save

để chặn outgoing port 1234 đối với VIP 192.168.1.2, sử dụng lệnh sau:

/sbin/iptables -A OUTPUT -p tcp -d 192.168.1.2 --dport 1234 -j DROP

/sbin/service iptables save

Nguồn: Vir | Area3

0 nhận xét