Tuesday, 24 January 2023

DoS Detection for NTP server with Iptables

NTP service is one of the most popular target services. Almost Linux servers install an Iptables firewall by default that we can config Iptables to detect or block NTP flooding packets. This topic shows you an example use case of Iptables for handling DoS traffic. 

Example 1.  Logging flood by source IP address (without limit logging rate).

In this example, we create a new firewall chain named NTP in the 1st line, append the rate limit rule to allow normal usage in the 2nd line, and log abnormal packets in the 3rd line.

iptables -N NTP

iptables -A NTP --match hashlimit --hashlimit-mode srcip  --hashlimit-upto  10/sec  --hashlimit-burst 20  --hashlimit-name conn_rate_limit  -j ACCEPT

iptables -A NTP -j LOG --log-prefix "NTP-DoS: " 

iptables -A NTP -j ACCEPT

iptables -A INPUT -p udp --dport 123  -j NTP

Example 2. Logging flood by source IP address with limit log output.

In 3rd line, we set the rate limit for logging at a rate of 1 event per second.

iptables -N NTP

iptables -A NTP --match hashlimit --hashlimit-mode srcip  --hashlimit-upto 10/sec  --hashlimit-burst 20  --hashlimit-name conn_rate_limit  -j ACCEPT

iptables -A NTP --match hashlimit --hashlimit-mode srcip  --hashlimit-upto 1/sec --hashlimit-burst 1  --hashlimit-name log_limit  -j LOG --log-prefix "NTP-DoS: "

iptables -A NTP -j ACCEPT

iptables -A INPUT -p udp --dport 123  -j NTP

Example 3. Logging and Dropping flood packet.

In the 4th line, Iptables will drop a packet that incoming packet more than a threshold in the 2nd line.

iptables -N NTP

iptables -A NTP --match match hashlimit --hashlimit-mode srcip  --hashlimit-upto 10/sec  --hashlimit-burst 20  --hashlimit-name conn_rate_limit  -j ACCEPT

iptables -A NTP --match hashlimit --hashlimit-mode srcip  --hashlimit-upto 1/sec --hashlimit-burst 1  --hashlimit-name log_limit  -j LOG --log-prefix "NTP-DoS: "

iptables -A NTP -j DROP

iptables -A INPUT -p udp --dport 123  -j NTP


Example 4. Block flood source IP address for 5 minutes with ipset

Create a blacklist source IP address set with an Ipset name NTP-BLOCK. every item added in this set will countdown from 300 seconds, and will remove when the counter is over. 

ipset create NTP-BLOCK hash:ip family inet hashsize 8182 maxelem 65536 timeout 300


2nd line: Apply blocking rules with an option  "-m set --match-set" with a set named "NTP-BLOCK"  for the source IP address of the incoming packet.
6th line: Update item in "NTP-BLOCK" set with option "-j SET --add-set" to push source IP of a packet that matches this rule.

iptables -N NTP

iptables -A NTP  -m set --match-set NTP-BLOCK src -j DROP

iptables -A NTP --match match hashlimit --hashlimit-mode srcip  --hashlimit-upto 10/sec  --hashlimit-burst 20  --hashlimit-name conn_rate_limit  -j ACCEPT

iptables -A NTP --match hashlimit --hashlimit-mode srcip  --hashlimit-upto 1/sec --hashlimit-burst 1  --hashlimit-name log_limit  -j LOG --log-prefix "NTP-DoS: "

iptables -A NTP -j SET --add-set NTP-BLOCK src

iptables -A INPUT -p udp --dport 123  -j NTP




Wednesday, 12 October 2022

Show server hardware "Product Name" and "Serial Number" from shell

Just secure shell to server and run this command as a root permission

sudo dmidecode | egrep -i 'manufacturer|product|Serial'

The result will show information such as Manufacturer,  Product Name, Serial Number, etc.

Manufacturer: Dell Inc.

Product Name: PowerEdge R430

Serial Number: xxxxxx

Manufacturer: Dell Inc.

Product Name: zzzz

Serial Number: .xxx.yyy.

Manufacturer: Dell Inc.

Serial Number: xxxx

Sunday, 22 May 2022

อย่าลืมปิด Multicast Snooping บน Bridge Interface ถ้าจะติดตั้ง KVM โดยเชื่อมต่อเครือข่ายผ่าน Bridge เพราะอาจะมีปัญหาการใช้งาน IPv6 ของ Guest OS

โดยปกติการติดตั้ง Virtural Machine บน Linux OS หรือ KVM รอบรับใช้งานเครือข่ายระดับ Layer 2 ของ Guest OS ผ่าน Bridge ของ Linux Kernel ซึ่ง Bridge บน Host OS ทำหน้าที่เป็น Switch เชื่อมต่อ Guest OS กับเครือข่าย โดยมี Physical Interface บน Host OS ทำหน้าที่เป็น Uplink port ของ Switch 

แต่เนื่องจาก Bridge ของ Linux มีการเปิด Multicast Snooping เป็นค่าเริ่มต้น โดยนี้จะปิดกั้นการส่ง Multicast บางประเภทไม่ให้ส่งข้าม Bridge ซึ่งฟีเจอร์ Multicast Snooping อาจจะทำให้เครื่อง Guest OS ไม่สามารถเชื่อมต่อกับเครือข่ายผ่าน Bridge ด้วย IPv6 ได้ เนื่องจาก Multicast Snooping ไปปิดกั้นแพคเก็ตของ Neightbor Discovry Protocol (ND) ทำให้ไม่สามารถค้นหาเครื่องที่อยู่อีกฝากของเครือข่ายได้

ดังนั้นเพื่อป้องกันปัญหาได้กลาวมาข้างต้นนั้น จำเป็นต้องปิด Multicast Snooping ด้วยคำสั่งดังนี้

echo -n 0 > /sys/class/net/<brif>/bridge/multicast_snooping


Source : https://askubuntu.com/questions/460405/ipv6-does-not-work-over-bridge


Friday, 15 October 2021

How to enable serial console KVM guest os.

 1. Enable serial console with command :

 systemctl enable --now serial-getty@ttyS0.service  

2. Connecting to guest OS from KVM with command:

 virsh console [VM_NAME]  

ref: ostechnix.com

Saturday, 9 October 2021

How to fix expired Freeradius certificate problem.

Problem :

    1. Can't start RADIUS Systemd service.

    2. Log show like this. 

 Oct 9 00:00:49 radius1 sh[1114]: C = FR, ST = Radius, L = Somewhere, O = Example Inc., emailAddress = admin@example.org, CN = Example Certificate Authority  
 Oct 9 00:00:49 radius1 sh[1114]: error 10 at 1 depth lookup: certificate has expired  
 Oct 9 00:00:49 radius1 sh[1114]: C = FR, ST = Radius, O = Example Inc., CN = Example Server Certificate, emailAddress = admin@example.org  
 Oct 9 00:00:49 radius1 sh[1114]: error 10 at 0 depth lookup: certificate has expired  
 Oct 9 00:00:49 radius1 sh[1114]: error server.pem: verification failed  
 Oct 9 00:00:49 radius1 sh[1114]: make: *** [Makefile:107: server.vrfy] Error 2  
 Oct 9 00:00:49 radius1 rsyslogd[1098]: imjournal: journal files changed, reloading... [v8.1911.0-6.el8 try https://www.rsyslog.com/e/0 ]  
 Oct 9 00:00:49 radius1 systemd[1]: radiusd.service: Control process exited, code=exited status=2  
 Oct 9 00:00:49 radius1 systemd[1]: radiusd.service: Failed with result 'exit-code'.  
 Oct 9 00:00:49 radius1 systemd[1]: Failed to start FreeRADIUS high performance RADIUS server..  

Cause :

    Certificate file in `/etc/raddb/certs/` have any expired certificates.

Resolution 1 (If you do not user certificate in /Certs ) :

    Delete all certificate files in `/raddb/certs` with this command.

 rm -f *.pem *.der *.csr *.crt *.key *.p12 serial* index.txt*  

Resolution 2 :

     Create new certificate new certificate instead expired certs. 


   



Friday, 8 October 2021

Basic Firewalld configuration for Linux server

1. Show all zone name and information about those zone.

 firewall-cmd --list-all-zones  

2. Create new zone.

 firewall-cmd --new-zone=dmz2 --permanent
3. Add source network or source IP to firewall zone to allow those network access allow services or port number in specific zone.
 firewall-cmd --zone=dmz2 --add-source=192.168.0.0/24 --permanent  
 firewall-cmd --reload  #Apply

4. Add service port to allow sources network in a zone to access those port.

 firewall-cmd --zone=dmz2 --add-port=80/tcp --add-port=443 --permanent  
 firewall-cmd --reload  #apply

Wednesday, 12 April 2017

Simple way to install go for CENTOS


  1. Download Go From Go Site 
  2. Untar Go to /usr/local/
    tar -C /usr/local -xzf go-xx.tar
  3. Create Link in /usr/bin
    ln -s /usr/bin/go/ /usr/local/go/bin
  4. Create Go Working Directory
  5. mkdir /go
    
  6. Set GOPATH 
    export GOPATH=/go

Import SSH Private Key to Yubikey (PIV) for SSH Authentication

Introduction: This guide will walk you through the process of importing your SSH private key to a Yubikey (PIV) for SSH authentication on y...