đŸ•šī¸
Ghoulsec Vault
Website Toolbase
  • Welcome !
  • đŸ—ƒī¸Exam Prep Notes
    • 📔CEH V13 (Master Edition)
      • Module 02: Footprinting and Reconnaissance
      • Module 03: Scanning Networks
      • Module 04: Enumeration
      • Module 05: Vulnerability Analysis
      • Module 06: System Hacking
      • Module 07: Malware Threats
      • Module 08: Sniffing
      • Module 09 : Social Engineering
      • Module 10: Denial of Service
      • Module 11: Session Hijacking
      • Module 12: Evading IDS, Firewalls , Honeypots
      • Module 13: Hacking web servers
      • Module 14: Hacking Web Applications
      • Module 15:SQL Injection
      • Module 16: Wireless Attacks
      • Module 17: Hacking Mobile Platforms
      • Module 18: IoT & OT Hacking
      • Module 19 : Cloud Computing
      • Module 20 : Cryptography
    • 📘ISC2 -Certified in Cyber Security
      • Chapter -1 Security Principals
      • Chapter -2 Disaster Recovery,Business Continuity & Incident Response
      • Chapter -3 Access Control Concepts
      • Chapter -4 Network Security
      • Chapter -5 Security Operations
    • 📗AZ - 900
      • Basics of Cloud Computing
        • Economic of Scale
        • CapEx & OpEx
        • Consumption based model
        • Cloud Deployment Models
        • Shared Responsibility Model
        • Data centers, Regions & Availability Zones & Geographyies in Azure
        • Resources & Resource Group
        • Azure Access Tools
        • Azure Service Lifecycle
        • Azure SLAs
        • Azure Cloud Adoption Framework
      • Azure Services
        • Azure Computing Services
        • Azure Networking Services
        • Azure Storage Services
        • Azure Database Service
        • Azure Marketplace
        • Big Data & Azure
        • Azure Serverless Computing
        • IoT & Azure
        • Other Azure Services
        • Azure Resource Locks & Resource Tags
        • Azure Security Services
          • Security Groups
          • Routing Tables
          • Azure Firewall
          • Azure DDOS Protection
          • Azure Identity & Access Management (Azure AD)
          • Azure RBAC
          • Azure Security Center
          • Azure Key Vault
      • Azure policies & Blueprints
      • Azure Cost Management
      • Azure Core Tenents
    • 📗SC - 900
      • Zero Trust Model
      • Shared Responsibility Model
      • Defense in Depth
      • Security Controls
      • CIA Triad
      • Encryption / Hashing / Signing
      • Microsoft Security & Compliance Principals
      • Common Identity Attacks
      • Microsoft Identity as Primary Security Perimeter
      • Modern Authentication with Azure AD
      • Azure AD Identity Types
      • Azure External Identities
      • Hybrid Identities
      • Authentication Methods & Password Protection
      • Conditional Access
      • Azure AD Roles & RBAC
      • Governance in Azure AD
      • Azure Identity Protection
      • Azure NSG, DDOS, Firewall
      • Azure Bastion & Keyvault
      • Azure Encryption
      • Azure CSPM
      • Azure Security Center
      • Azure Defender
        • Microsoft O365 Defender
        • Azure Sentinel
      • Microsoft Cloud App Security
      • Microsoft Intune
      • Microsoft Complaince Manager
      • Information Protection
      • Microsoft insider risk capabilities
    • 📔AWS Cloud Practitioner
      • Cloud Deployment
        • AWS Global Infrastructure
      • AWS Cloud Essentials
        • AWS SNS
          • AWS SQS
      • AWS Compute & Container Services
        • AWS EC2
          • Elasticity & Agility
        • AWS Serverless Computing
        • AWS Container Services
        • AWS Beanstalk
        • AWS Load Balancing
      • AWS Storage & Databases
      • AWS Networking
      • AWS Security
        • AWS Organisation
        • AWS Compliance
        • AWS DDOS
        • Additional Security Services
      • AWS Monitoring & Analytics
        • Other Analytics Services
      • AWS Pricing & Support
      • AWS Migration & Innovation
        • Migration Statergies
        • AWS Snow Family
        • AWS Transfer Family
        • Innovation on AWS
      • AWS Well Architecture Framework
      • Other AWS Services
  • 🧑‍đŸ’ģCyber Security Base
    • Ghoul's Den
    • Cheatsheets
    • SSL Handbook
      • Installing OpenSSL
      • Encrypting Web Servers using SSL
      • Compiling .pfx file using openssl
      • De-compiling .pfx file
      • Zimbra Mail Server SSL renew
      • SSL Certificates
    • â˜ī¸Cloud Security
      • Amazon Web Services (AWS)
        • AWS - IAM & Policy Management
        • AWS Organization
        • AWS - Roles (Assume Role)
        • AWS - EC2 (Elastic Computing)
        • AWS - VPC
        • AWS - Bastion Host
        • AWS Application Load Balancer
        • AWS Auto Scaling Group
        • AWS WAF
        • AWS - VPC Peering
        • AWS Transit Gateway
        • AWS NAT Gateway
        • AWS - Route 53
        • AWS Certificates Manager
        • AWS Network Load Balancer (NLB)
    • đŸ•¸ī¸Network Security
      • Firewalls
        • Sophos - Security Suite
          • Sophos Firewalls
      • VPN
        • VPNs
          • Wireguard Tunneling
          • StrongSwan Gateway VPN Server on Ubuntu
      • IP Address and IP Subnetting
      • Basic to Advance Networking Materials
    • 🧑‍đŸ’ģVAPT
      • Sample Report Templete
      • OWASP
        • OWASP Web Application Security & WebGoat
      • Web Application testing checklist
        • Client Side Penetration Testing
          • Clickjacking
          • Websockets
          • CSRF
          • XSS Filters
        • Server Side Penetration Testing
        • Advanced Web Application Pentesting
          • OAuth
          • JWT Injection
          • Server Side Templete Injection
    • â˜„ī¸GRC
      • ISMS AUDIT PLAN
      • CIS Compliance Windows
    • 🔍Forensic
      • Forensic Tools
      • EMAIL Forensics
      • File header forensics
    • Trend Micro
      • Deep Security
        • Installation & Prerequisite
          • Microsoft SQL server 2022
          • Postgres 16 Core
          • Installation
    • Practical Malware Analysis & API Threats
  • đŸ•šī¸Server are fun !
    • Securing Linux
      • Securing SSH
      • Sudoers
      • UFW (Uncomplicated FW)
      • Unattended Upgrades
      • Password Complexiety
      • Auditing Linux
      • Samba - SMB
      • NFS - Network File System
      • FTP
      • AIDE
    • Servers
      • Linux Sever
        • OpenLDAP Server Setup
          • ldap-account-manager
          • Securing OpenLDAP
          • OpenLDAP client setup
          • Checking LDAP setup
        • Users & Groups
        • Password Policy
        • File & File Permissions
        • Automatic Updates
        • Adding GUI to Ubuntu Server
        • DNS Server
        • NTP Server
      • Windows Sever
        • Deep dive into Windows Server
        • Windows server Installation
        • Disable IPv6
        • Disable Server Manager on startup
        • Promoting OS to AD server
        • AD DNS
        • AD DHCP
        • AD Activation
        • AD Users & Groups
        • AD FileServer
        • Adding Users into AD
        • Bulk Importing users into Domain
        • Windows AD Resources
        • Group Policy Editor
          • Creating First Policy
          • Restricting CMD & Powershell
          • Password Policies
          • Audit Policies
          • Log Retention Policy
          • Windows Defender Firewall
          • Patch Management & Window Updates
        • Setting Up local accounts for windows hosts
    • Hacking Systems
      • Linux Systems
        • Battery Charge Threshold (Linux)
        • Metasploitable OS Complete Solved
      • Tricking Windows
        • Bitlocker & Time based policy bypass
    • Monitoring HeartBeats
    • RAID Technology
    • Managing Partitions
      • Parted
      • Fdisk
      • LVM
        • Re-claiming unused disk space
        • Adding physical volume into VG
        • Removing physical volume from VG
      • SWAP Memory
    • Virtualization
      • Proxmox
        • Proxmox VE Installation
        • Default Storage Expansion
        • Proxmox Network Link Aggegration
        • NAT Interface Configuration
        • Importing disk into proxmox
        • Creating an LVM Thin Pool
        • Proxmox IAM
  • đŸ™â€â™‚ī¸Dan the AI Expert
    • Ollama Ollama ...
      • Ollama
        • Ollama models
        • Open Web UI & Ollama Integration
    • Microsoft Presentation using AI
  • đŸ›Ąī¸Security Operations
    • Wazuh - Open Source XDR. Open Source SIEM.
      • Components
      • Deployment Methods
      • Installation
        • Single Node Installation
          • Wazuh Indexer Installation
          • Wazuh Server Installation
          • Wazuh Dashboard Installation
          • Single node deployment with Script
        • Managing multiple Wazuh clusters with Cross-Cluster Search
          • Cluster Configuration
          • Set up Cross-Cluster Search
        • Upgrading Wazuh Central Components
        • Uninstalling Wazuh
      • Custom Decoder & Rules
        • Pfsense Decoders
        • Pfsense Rules
      • Security Operations Center Tools (Wazuh)
    • IRIS-DFIR / Case Management
    • Graylog & ElasticSearch
    • Zabbix NMS
      • Zabbix Installation
      • Zabbix Database Management
        • Zabbix Database backup
        • Zabbix Database restore
        • MySQL Replication (M-M)
        • MySQL Replication (M-W)
      • Zabbix Geomap Setup
      • Adding Hosts into Zabbix
      • Zabbix Hostgroups
      • Auto Registration Hosts Zabbix
      • Zabbix Globalscrips
      • Zabbix HA Cluster
      • Zabbix Proxy
      • Zabbix Notifications
      • Zabbix Maintainance
      • Zabbix User Management & Authentication
      • Zabbix Housekeeping
      • Scheduled Reporting
      • Service Monitoring using Zabbix
  • Git the master!!
    • Configuring git
    • Git Branches
    • Undoing changes
    • Git - Cheat sheet
    • My first git...
Powered by GitBook
On this page
  • Securing SSH using Fail2Ban
  • Disabling root login using SSH
  • Restricting password based authentication
  • Enabling Authorized Key Based Authentication
  • Changing SSH port
  • Securing SSH using ufw
  1. Server are fun !
  2. Securing Linux

Securing SSH

SSH (Secure Shell) is a cryptographic network protocol used to securely access and manage remote systems over an unsecured network. It provides encrypted communication between a client and a server, ensuring data integrity and confidentiality. SSH is commonly used for logging into remote servers, executing commands, and transferring files securely. It replaces older, less secure protocols like Telnet and FTP. With features like public-key authentication, SSH ensures that only authorized users can connect, making it a vital tool for system administrators, developers, and anyone needing secure remote access.

We will make come configuration based changes to secure out our ssh service


Securing SSH using Fail2Ban

Fail2ban is a security tool that protects servers from brute-force attacks by monitoring log files and banning IP addresses that show suspicious activity, like repeated failed login attempts.

Instalation of Fail2Ban is simple , we can do this with :

$> sudo apt install fail2ban
$> sudo systemctl status fail2ban

Now we will configure the fail2ban , but we will not edit the .conf file directly we will copy it and create a local file to override the global settings and avoid messing up the fail2ban config.

By default the ssh is being protected by the fail2ban serivice we can check with the following command :

$> sudo fail2ban-client status
# The output should look like : 
Status
|- Number of jail:      1
`- Jail list:   sshd

Which means the ssh is indeed filtered by fail2ban by default, Now we will create local config file and configure ssh access using fail2ban

$> sudo cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local

Now we will edit the settings under the local file

First we wil look into the sshd section for the default config, Look for the following config

[sshd]

# To use more aggressive sshd modes set filter parameter "mode" in jail.local:
# normal (default), ddos, extra or aggressive (combines all).
# See "tests/files/logs/sshd" or "filter.d/sshd.conf" for usage example and details.
#mode   = normal
port    = ssh
logpath = %(sshd_log)s
backend = %(sshd_backend)s
  • port = ssh: Specifies the port to monitor for SSH connections (default is port 22).

  • logpath = %(sshd_log)s: Points to the log file for SSH logs (usually /var/log/auth.log).

  • backend = %(sshd_backend)s: Specifies the log backend to use for reading logs.

  • The mode option (commented out here) can set different levels of protection (normal, ddos, extra, aggressive) to handle SSH brute-force attacks with varying intensities.

Now we will configure the following parameters findtime , bantime & maxretries . Search for the following lines :

# "bantime" is the number of seconds that a host is banned.
bantime  = 10m
# A host is banned if it has generated "maxretry" during the last "findtime"
# seconds.
findtime  = 10m
# "maxretry" is the number of failures before a host get banned.
maxretry = 2

We have set the value of maxretry to 2 which will block our IP address for 10 Minutes if 2 failed password attempts are found in the interval of 10 mins.

Restarting the service :

$> sudo systemctl restart fail2ban

Testing fail2ban :

Here we can see the fail2ban has sucessfully banned the ssh connection from the IP & blacklisted the connections.

$> fail2ban-client status sshd
# The output should look like : 
Status for the jail: sshd
|- Filter
|  |- Currently failed: 0
|  |- Total failed:     2
|  `- File list:        /var/log/auth.log
`- Actions
   |- Currently banned: 1
   |- Total banned:     1
   `- Banned IP list:   3.3.3.126

Ignoring Trusted IP Addresses :

We can ignore certain trusted IPs from getting banned by adding the following line in the config file

ignore ip = 3.3.3.0/24 ## To Ignore this network range

Incrementing Bantime for repetative offenders :

bantime.increment = true # Increment by : 1 2 4 8 16 32 64 128

This is how we can secure our servers using fail2ban. We can also secure other services like Apache2, php & many more using fail2ban which can also be managed my the same config file.


Disabling root login using SSH

Directly accessing the root account with the SSH might pose a significant risk so we should consider disabling the SSH access over the root account.

The config file of the ssh service is located on /etc/ssh/sshd_config so we will edit the file and disable the root login parameter

sudo nano /etc/ssh/sshd_config

Under the authentication section we have the parameter named PermitRootLogin so we will set the value to yes to disable the root login.

# Authentication 
PermitRootLogin no

Upon restarting the service the changes will be applied and root login is now disabled.

sudo systemctl restart ssh

Restricting password based authentication

Password based authentication is a feature which allows the users to get authentication with the plain text. Allowing plain text the ssh service might be vulnerable for weak credentials and brute force attacks so we will disable the password based authentication.

We will edit the config in the same config file of the ssh service and then under the authentication section we will find the below options

# Authentication
# To disable tunneled clear text passwords, change to no here!
PasswordAuthentication no

Upon restarting the service the changes will be applied and we have sucessfully disabled the plain text authentication on the ssh server.

sudo systemctl restart ssh

Enabling Authorized Key Based Authentication

Authorized keys based authentication is the mechanism which only allows the certain public keys to authenticate with the server so it mitigates the threats of using password based authentication

We will edit the config in the same file and under the authentication section we will edit the following parameters

# Authentication
PubkeyAuthentication yes
PasswordAuthentication Yes

Now we will create the file authorized_keys file inside the .ssh/ directory and add the public keys of the systems on which access is required.

cd .ssh/
touch authorized_keys

After adding the keys we will save & exit the file and restart the ssh service to place the config in place

sudo systemctl restart ssh

Changing SSH port

Changing the default SSH port is very important steps to implement in the production environment to enusre the hackers and the scanners not easily identify and hack the servers using common ports

To change the ssh ports we will change the port config in the ssh config in the same file where above changes are done.

# General config 
port <port number other then 22>

restarting the services will confirm the changes.

sudo systemctl restart ssh

Securing SSH using ufw

ufw (Uncomplicated Firewall) is the default firewall on the system we can limit the access with ufw as follows :

  • Checking wheather the UFW is enabled

$> sudo ufw status
# Output :  ufw is active & rules will be displayed if active

If disabled we will have to enable it first so we will enable it with :

Ensure to add the ssh allow rule in case you are using ssh for accessing server , otherwise we might loose access over the server

$> sudo ufw allow ssh 
$> sudo ufw enable

If your ssh service is running & configure on the different port we can alow the following using :

$> sudo ufw allow <port>

To limit the SSH acces only through the particulat IP or network we can do this with :

## Access from a IP Address only
$> sudo ufw allow from 10.10.10.10 to any port 22
$> sudo ufw deny 22

### Access from a Network range 
sudo ufw allow from 10.10.10.10/24 to any port 22
sudo ufw deny 22

To learn more on UFW we will cover it in the upcoming sections ...

PreviousSecuring LinuxNextSudoers

Last updated 2 months ago

đŸ•šī¸