🕹️
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
  • Adding users to `sudo` group to allow sudo access
  • Adding users to sudoers file to allow sudo access
  • Limiting user root access to certain path or files
  • Locking and unlocking users
  • Allowing root level perms based on groups
  • Permanently blocking root account by changing shells
  1. Server are fun !
  2. Securing Linux

Sudoers

The sudoers file is a configuration file used in Unix-like operating systems (such as Linux) to define user permissions for running commands with superuser privileges via the sudo command. It controls who can run what commands as which user (often root), and under what conditions.

The typical location of the sudoers file is located at the /etc/sudoers location on the machine but it is always advisable to edit it with the visudo utility to avoid common syntax & logic errors while editing the configuration. Here are some files related to users & root management which will be used in this section

$> /etc/sudoers 
$> /etc/passwd
$> /etc/shadow

Adding users to `sudo` group to allow sudo access

When creating a user with sudo access we need to add the user into the sudo group first to allow accessing root. We can do the following with the following command :

$> sudo useradd -m -s /bin/bash <username>

Here there are some parameters used which means :

  • -m : Creates the user directory

  • -s : defines the user welcome shell

After creating the user we will add the user into the sudo group to allow access root

$> sudo su
$> sudo usermod -aG sudo <username>

Here the parameter -aG defines to adding user into the group.


Adding users to sudoers file to allow sudo access

When we require the user to be able to access root but we dont want to add the user into sudo group then we can directly give access to users from the sudoers file.

$> sudo visudo
# User privilege specification
root ALL=(ALL:ALL) ALL
<username> ALL=(ALL:ALL) ALL

This will allow the user to get same level of access as the root user on the system

The block structure of the following files is like this :

<username> <which_user>=(<which_user_runas>:<which_group_runas>) <which_files>

Limiting user root access to certain path or files

As we have configured the user above with all the rights we can also configure user to be able to access certain files only.

$> sudo visudo
# User privilege specification
root ALL=(ALL:ALL) ALL
<username> ALL=(ALL) /usr/bin/apt

This will only allow the user to access the apt command with the root level rights and limiting the overall root access of the user.

If we want that user should not require the password while performing allowed root levels we can configure the file like :

$> sudo visudo
# User privilege specification
root ALL=(ALL:ALL) ALL
<username> ALL=(ALL) NOPASSWD: /usr/bin/apt

Locking and unlocking users

When we require that certain users should not be able to access we can lock their access using the following commands :

$> sudo usermod -L <username> ##Lock user

To unlock the user back we can use :

$> sudo usermod -U <username> ## unlock user

To verify the users account are locked or unlocked we can pass the following command :

$> sudo cat /etc/shadow

Here there are two conditions :

  • If we have ! sign before the user password which means the user is locked

  • If dont the user is unlocked and we can access it


Allowing root level perms based on groups

You want to give 10 users permission to run the command /usr/bin/apt with sudo (for package management) without giving them full access to all commands.

  • reate a new group (e.g., apt-users):

    sudo groupadd apt-users
  • Add the 10 users to the apt-users group:

    sudo usermod -aG apt-users <username>

    Repeat this for each of the 10 users.

  • Edit the sudoers file (using visudo for safety):

    sudo visudo
  • Add the rule for the apt-users group:

    %apt-users ALL=(ALL) /usr/bin/apt

Permanently blocking root account by changing shells

Changing welcome shells of the user can be the most prominent ways to block the logins. To check the current shells of the user we can see using the following command :

$> sudo cat /etc/passwd

Here are some common shells seen in that files :

  • /bin/bash: A widely used, feature-rich shell that supports scripting, job control, and command-line editing.

  • /usr/sbin/nologin: Prevents login access, often used for system or service accounts that should not have a shell.

  • /bin/sync: A command shell that syncs file system data before shutdown or restart, primarily for the sync user.

  • /bin/false: A shell that immediately exits with a failure status, preventing login; often used for service accounts.

Here the shell /bin/bash is the shell which provides the terminal access so changing shell of the user root from /bin/bash will make the user shell inaccessible , So to change the shell of user we can pass the following command :

DANGER : Before passing this command ensure atleast one another user is configured with sudo access otherwise the session might be bricked

Changing the shell of user root :

$> chsh root
Password: 
Changing the login shell for vishvam
Enter the new value, or press ENTER for the default
        Login Shell [/bin/bash]: /usr/sbin/nologin
# Changing the shell to /usr/sbin/nologin will block the shell access of user root

This is how we can manage sudoers file and limit the attack vectors to minimum. In the next section we will learn about ufw.

PreviousSecuring SSHNextUFW (Uncomplicated FW)

Last updated 2 months ago

🕹️
Here ! indicates the following users are locked
the last section after ":" indicates the current shells