Git Product home page Git Product logo

34n0 / pam-authramp Goto Github PK

View Code? Open in Web Editor NEW
27.0 1.0 1.0 399 KB

pam-authramp | The AuthRamp PAM module provides an account lockout mechanism based on the number of authentication failures.

Home Page: https://copr.fedorainfracloud.org/coprs/34n0s/pam-authramp/

License: GNU General Public License v3.0

Rust 86.53% Makefile 3.07% C 10.40%
brute-force pam pam-authentication pam-module rust security security-tools

pam-authramp's Introduction

pam-authramp

The AuthRamp PAM (Pluggable Authentication Modules) module provides an account lockout mechanism based on the number of authentication failures. It calculates a dynamic delay for subsequent authentication attempts, increasing the delay with each failure to mitigate brute force attacks.

  1. Installation
  2. Configuration
  3. Threat model
  4. Contributing
  5. Mentions

Installation

RPM

If you're a RPM distribution user, then then pam-authramp can be installed using a binary .rpm file provided in each release.

curl -LO https://github.com/34N0/pam-authramp/releases/download/v0.9.1-beta/pam-authramp-0.9.1-1.x86_64.rpm
sudo rpm -i pam-authramp-0.9.1-1.x86_64.rpm

COPR

The module is released in a COPR repository:

sudo dnf copr enable 34n0s/pam-authramp
sudo dnf install pam-authramp

Debian

If you're a Debian user (or a user of a Debian derivative like Ubuntu), then pam-authramp can be installed using a binary .deb file provided in each release.

curl -LO https://github.com/34N0/pam-authramp/releases/download/v0.9.1-beta/pam-authramp_0.9.1-1_amd64.deb
sudo dpkg -i pam-authramp_0.9.1-1_amd64.deb

Manually

  1. Download the latest release.
  2. Copy the libpam_authramp.so library to the default PAM library directory. The directory varies for different distributions. For example, in current Fedora versions, the path is /lib64/security.
  3. Add the module library calls to the PAM service stack in /etc/pam.d.

Configuration

PAM service

Edit the PAM service stacks in '/etc/pam.d'. Add the preauth hook before the authentication module:

auth        required                                     libpam_authramp.so preauth

The actual authentication module needs to be 'sufficient':

auth        sufficient                                   pam_unix.so

Add the authfail hook right after the authentication module:

auth        [default=die]                                libpam_authramp.so authfail

And finally add the module to the top of the account stack:

account     required                                     libpam_authramp.so

authramp.conf

Create a configuration file under /etc/security/authramp.conf. This is an example configuration:

# AuthRamp Configuration File
# This file configures the behavior of the AuthRamp PAM module.
#
[Configuration]
# Directory where tally information is stored.
# Each user has a separate file in this directory to track authentication failures.
# tally_dir = /var/run/authramp
#
# Number of allowed free authentication attempts before applying delays.
# During these free tries, the module allows authentication without introducing delays.
# free_tries = 6
#
# Base delay applied to each authentication failure.
# This is the initial delay applied after the free tries are exhausted.
# base_delay_seconds = 30
#
# Multiplier for the delay calculation based on the number of failures.
# The delay for each subsequent failure is calculated as follows:
# delay = ramp_multiplier * (fails - free_tries) * ln(fails - free_tries) + base_delay_seconds
# ramp_multiplier = 50
#
# Even lock out the root user. Enabling this can be dangerous and may result in a total system lockout.
# For auditing purposes, the tally will still be created for the root user, even if this setting is disabled.
# If you plan to enable this feature, make sure there isn't any tally stored under <tally_dir>/root, or you risk immediate lockout.
# even_deny_root = false
#
# Whether the PAM user messages in the login screen should update automatically or not.
# countdown = true

default delay

The default configuration of this module is very restrictive. The standard delays are:

  • 0 to 6 failed attempts: no delay (2 sessions of 3 tries)
  • 7th failed attempt: 30-second delay
  • 15th failed attempt: 15 minutes delay
  • 30th failed attempt: 1-hour delay
  • 300th or later failed attempt: 24 hours delay

The formula used to calculate the delay is:

f : failedAttempts  
f₀ : freeTries  
r : rampMultiplier  
b : baseDelaySeconds  
delay = r * (f - f₀) * log(f - f₀) + b

Reset user

The cli uses the reads the same configuration in authramp.conf.

$ authramp --help

 █████ ██    ████████████   ████████  █████ ███    █████████  
██   ████    ██   ██   ██   ████   ████   ██████  ██████   ██ 
█████████    ██   ██   █████████████ █████████ ████ ████████  
██   ████    ██   ██   ██   ████   ████   ████  ██  ████      
██   ██ ██████    ██   ██   ████   ████   ████      ████

by [email protected]

Usage: authramp [COMMAND]

Commands:
  reset  Reset a locked PAM user
  help   Print this message or the help of the given subcommand(s)

Options:
  -h, --help  Print help

Logging

The module and cli generate logs following the PAM module logging style. For instance, the logging entries created during integration tests serve as examples.

Feb 04 01:42:42 fedora test_pam_auth-501103939372d9d4[89930]: libpam_authramp(test-authramp:auth): PAM_AUTH_ERR: Added tally (7 failures) for the "user" account. Account is locked until 2024-02-04 00:43:12.983474044 UTC.
Feb 04 01:42:42 fedora test_pam_auth-501103939372d9d4[89930]: libpam_authramp(test-authramp:auth): PAM_AUTH_ERR: Account User(1000, user) is getting bounced. Account still locked until 2024-02-04 00:43:12.983474044 UTC
Feb 04 01:43:15 fedora test_pam_auth-501103939372d9d4[89930]: libpam_authramp(test-authramp:auth): PAM_AUTH_ERR: Account User(1000, user) is getting bounced. Account still locked until 2024-02-04 00:43:12.983474044 UTC
Feb 04 01:43:15 fedora test_pam_auth-501103939372d9d4[89930]: libpam_authramp(test-authramp:account): PAM_SUCCESS: Clear tally (7 failures) for the "user" account. Account is unlocked.
Feb 04 01:43:19 fedora test_pam_auth-501103939372d9d4[89930]: libpam_authramp(test-authramp:account): PAM_SUCCESS: Clear tally (1 failures) for the "user" account. Account is unlocked.

Threat Model

The primary objective of pam-authramp is to enhance the security of Linux systems by implementing a dynamic account lockout mechanism based on the number of consecutive failed authentication attempts. This module aims to prevent unauthorized access to user accounts, mitigate brute-force attacks, and provide an additional layer of protection against malicious activities.

Key Objectives:

  1. Dynamic Lockout: Implement a flexible account lockout mechanism that adapts to the user's behavior, dynamically adjusting lockout durations based on the number of consecutive authentication failures.

  2. Configurability: Allow system administrators to configure lockout parameters such as the number of free authentication attempts, base delay duration, and the multiplier for ramping delays. This ensures adaptability to diverse security requirements.

  3. User-Friendly: Prioritize user experience by avoiding indefinite account lockouts. Temporary lockouts provide a balance between security and accessibility, ensuring users can regain access to their accounts after a defined period.

  4. Compatibility: Seamlessly integrate with the Linux Pluggable Authentication Module (PAM) framework, allowing easy adoption within various authentication scenarios and user environments.

  5. Usability in Restricted Environments: Cater to systems with security practices such as disabling the root account. pam-authramp acts as an additional safeguard without the need for a separate system administrator to unlock accounts.

pam-authramp provides a valuable layer of defense against brute-force attacks, but its successful implementation requires careful configuration, compatibility checks, and continuous monitoring. Administrators and users must consider its limitations and conduct thorough testing to ensure it aligns with the security goals of the system.

Contributing

Contributing is welcomed! Read the Contributing Guide and the CoC.

Mentions

  • This project would not have been possible without the work done in the pam-rs crate.
  • The Lockout mechanism is inspired by the GrapheneOS implementation.
  • This Module was developed to fix a PAM DoS vulnerability in Secureblue.

pam-authramp's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

qoijjj

pam-authramp's Issues

[FEATURE] Configurable lockout increase

Add a feature which allows configuration of the lockout mechanism called "bounce_while_locked"

  • true: while an account is locked every attempt should increase the lockout time. even if the password is correct to protect against brute forcing pam responses.
  • false: attempts while locked out should be ignored.

[BUG] Module not known on secureblue

I've been doing additional testing. There are several points of breakage even in GDM:

  1. I can still enter passwords even while locked out, and submitting passwords while locked out increases the time to unlock even if it's a valid password
  2. The countdown no longer works. It shows a static string that doesn't change.

Documentation

There are modules of the util and cli crates undocumented.

Handle and log misconfiguration

Currently failed config file parsing is not handled and logged. There are no crashes, but the default values are used without any explanation.

[FEATURE] Configurable countdown

Add a setting called "countdown":

  • true: loops the pam message to count down automatically
  • false: do not loop and only load latest message on new session

On Plasma, the password prompt still works even during lock, and doesn't accept valid passwords

Instead of Authentication failed, it now just lets me continuously enter passwords even after using the free tries. The only difference is after the free tries are used, a valid password no longer works.

Expected behavior:

During lock, passwords should not be able to be entered, and the text should tell the user they are locked out

Actual behavior:

During lock, passwords are still able to be entered, and there is no indication whatsoever that the system is locked.

Steps to reproduce:

Rebase to a secureblue kinoite vm with the br-staging-39 tag.

[BUG] Broken on LightDM, the unlock time text adds newlines instead of updating itself

Steps to reproduce:

Use authramp with LightDM / Cinnamon
enter incorrect passwords until lockout

Expected behavior:

on lockout, a timer should be displayed

Actual behavior:

on lockout, the timer text is displayed, but isn't updated. instead, updates are sent as newlines like so:

Account locked! Unlocking in 30 seconds.
Account locked! Unlocking in 29 seconds.
Account locked! Unlocking in 28 seconds.

And then trails off the bottom of the UX.

Please confirm that you can repro.

Key bypass

I'm surprised no one came up with this before you did, but as I was planning on using PAM authentication for my website, and kinda already started (via SMTP), the idea of how to throttle brute force attempts has become a priority of mine, so i stumbled on your project yesterday.

Part of me, however, does see why this wasn't created before: what if someone tries to lock down a system and prevent an administrator from getting in via SSH by locking down all known user accounts (you acknowledge this for root)? I was wondering if, perhaps, there were some way to have it skip this module on public key authentication. This would effectively prevent that very idea. Bonus if you can get it to work with a way to bypass locally with some sort of command line option (so people can unlock their accounts) (odds are, most people using this are more afraid of external brute force attempts, not local users trying to break in).

I'd mark this as a feature request, myself, but I don't use github's issue reporting often enough to know how to do that.

Conversation String plurals

Currently the message the user gets reads:

[...] Unlocking in NN minute and NN second.

It should append an s if the NN values are more than 1

Clean up bounce_auth function

If the Conversation::send result is an error it should be logged. The loop in bounce_auth should continue either way. Currently the result is ignored.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.