Aircrack-ng: Pause and Resume Password Cracking

In some cases, it’s not possible to сrack WPA/WPA2-PSK key with aircrack-ng in one step, especially while using a large dictionary.

Unfortunately, aircrack-ng can’t pause and then resume cracking itself, but it is possible to save and then continue session with John The Ripper.

In this small note you’ll find how to save the current state of aircrack-ng and then continue the cracking from where it was stopped. (more…)

Disk Speed Test (Read/Write): HDD, SSD Performance in Linux

From this article you’ll learn how to measure an input/output performance of a file system on such devices as HDD, SSD, USB Flash Drive etc.

I’ll show how to test the read/write speed of a disk from the Linux command line using dd command.

I’ll also show how to install and use hdparm utility for measuring read speed of a disk on Linux Mint, Ubuntu, Debian, CentOS, RHEL. (more…)

Download YouTube Video – Linux Command Line

We can download YouTube video files from the Linux command line using a program, called youtube-dl.

It is a small python command-line program that can download videos from youtube.com and few more sites.

In this article you’ll find how to install YouTube downloader on your Linux system, depending on your distribution.

You’ll also see how to download YouTube video, channel or playlist of any available quality and formats from the Linux shell. (more…)

Fail2Ban: Install and Config – Ubuntu, CentOS – Protect SSH

Fail2ban helps to protect Linux servers from brute-force and DDOS attacks.

It scans logs for IP addresses that show the malicious signs and bans that IP addresses for a specified amount of time using iptables.

This article describes how to install and configure fail2ban on Ubuntu, CentOS and similar Linux distributions.

You’ll also learn how to protect SSH server from DDOS and brute-force attacks and how to manually unban IP address that was banned by fail2ban.

Install Fail2Ban on Ubuntu

Type the following command to install fail2ban on Ubuntu:

$ sudo apt-get install fail2ban

Install Fail2Ban on CentOS

There is no fail2ban package in the default CentOS repository, but it can be found in EPEL.

Cool Tip: Install EPEL repository in one command! Read more →

As only EPEL repository is enabled, you can install fail2ban:

$ sudo yum install fail2ban

Configure Fail2Ban

The default fail2ban configuration file is /etc/fail2ban/jail.conf.

However it is not recommended to modify /etc/fail2ban/jail.conf directly.

Instead, we should work with a local copy called jail.local, which will override the jail.conf file.

Make a local copy of fail2ban configuration file:

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

Edit /etc/fail2ban/jail.local:

$ sudo vi /etc/fail2ban/jail.local

Pay attention to the global options in [DEFAULT] section.

It covers the basic rules that fail2ban will follow:

Option Description
ignoreip Don’t ban a host which matches an address in this list. Several addresses can be defined using space separator.
bantime Duration (in seconds) for IP to be banned for. Negative number for permanent ban. Default is 10 minutes.
findtime The time window (in seconds) within which fail2ban keeps track failed login attempts. Default is 10 minutes.
maxretry The number of failures before a host get banned. Default is 3 attempts.

If you want to set up more nuanced protection, you can override the global options and customize the details in each jail (section with rules for each application).

Protect SSH Server with Fail2Ban

After completing with [DEFAULT] section, go down and update [ssh-iptables] section as below:

[ssh-iptables]

# 'enabled = true' means that SSH protection is on.
# It can be turned off with 'enabled = false'.
enabled  = true
# Use filter: /etc/fail2ban/filter.d/sshd.conf
filter   = sshd
# Action describes the steps that Fail2Ban will take to ban a matching IP address.
action   = iptables[name=SSH, port=ssh, protocol=tcp]
# Send notifications to admin@example.com
           sendmail-whois[name=SSH, dest=admin@example.com, sendername="Fail2Ban"]
# Log location that Fail2Ban will track
logpath  = /var/log/secure
# if during 1 hour
findtime    = 3600
# 5 failed login attempts would be detected
maxretry    = 5
# host will be banned for 24 hours
bantime     = 86400

Fail2ban is not limited to SSH only. Out of the box Fail2Ban comes with filters for various services (SSH, apache, asterisk, postfix, etc.), but only [ssh-iptables] jail is activated by default.

Tweaking Fail2Ban Filters

If you wish to tweak the existing filters or add new filters, you can find them in the /etc/fail2ban/filter.d directory.

For example, to modify fail2ban filter for OpenSSH, edit the following file:

$ sudo vi /etc/fail2ban/filter.d/sshd.conf

Start Fail2Ban

fail2ban is already configured to start during the system boot by default.

Don’t forget to restart fail2ban, each time after making any changes in it’s settings:

$ sudo service fail2ban restart

Test Fail2Ban

To test fail2ban and to see the rules that fail2ban puts in effect, look at iptables:

$ sudo iptables -L

Manually UnBan IP Banned by Fail2Ban

Use the flowing command to manually unban IP address, banned by fail2ban:

$ sudo fail2ban-client set JAIL unbanip IP

Unban IP 192.168.1.101, that was banned according to [ssh-iptables] jail:

$ sudo fail2ban-client set ssh-iptables unbanip 192.168.1.101

Mass Emails Sending From Bash Script in Linux

To prevent abuse and don’t allow to send bulk emails through SMTP server, it is recommended to restrict the number of messages that each user can send.

Let’s say we have limited the number of messages to send, but how can we check that the limitation works?

The best way to make such check is to try to send mass emails, as spammers usually do, using our SMTP server as relay.

From the Linux Command Line, we can create a simple Bash Script that can send multiple emails for testing purposes.

Sending Bulk Emails for Testing Purposes

Use the following Bash Script from your Linux machine to send 1000 emails to example@mail.tld:

#!/bin/bash
for i in {1..1000}; do
	echo "Test" | $(which mail) -s "Test Message №$i" "example@mail.tld"
done

Bash: String Length – How To Find Out

If you often create Bash scripts, you may sometimes need to get the length of a string or find out the length of a variable that stores some string.

This short note shows how to find out the length of a string from the Linux command line and how to count the length of the each line in a file.

You will also see how to get the length of a string if it is stored in a variable in Bash and then assign that calculated number of characters to another variable. (more…)

Crontab Format: Cron Job Examples in Linux

On the Linux system we can schedule a regular task, also knowns as a cron job, using a cron (crond) service.

The cron (crond) service reads crontab (cron tables) and executes listed scheduled tasks.

In this article i will show the format of a crontab and explain how to schedule a cron job in Linux.

You will also find here the most popular examples of cron job schedules, such as every minute cron job, every 5 minutes, every hour, every day (daily cron job) and others. (more…)

Ubuntu, CentOS – Enable or Disable Service Autostart in Linux

Very often it is needed to enable or disable autostart of some services in Linux.

There are different init systems exist, but on Ubuntu and CentOS the most common are SysV, Upstart and systemd.

Depending on distribution, the behavior of a service during system’s boot in Linux can be configured with systemctl or chkconfig commands.

This tutorial shows how to enable or disable autostart of system services in the most popular Linux distributions – Ubuntu and CentOS. (more…)

“Yes/No” in Bash Script – Prompt for Confirmation

Very often in bash scrips you need to ask for user input that requires a Yes or No answer.

For example, you may want to put a quick “Are you sure?” prompt for confirmation before execution of some potentially dangerous part of a bash script.

In this article you’ll find three easiest and fastest ways to prompt for “Yes/No” confirmation in bash script.

Prompt To Continue In Bash

The best way to prompt for a confirmation to continue in a bash script is to use the read command (source):

read -p "Are you sure? " -n 1 -r
echo    # (optional) move to a new line
if [[ ! $REPLY =~ ^[Yy]$ ]]
then
    exit 1
fi

Simple “Yes/No” Dialog In Bash

One of the most widely used method to ask user for a confirmation in a bash script is to combine read + case commands (source):

while true; do
    read -p "Do you wish to install this program?" yn
    case $yn in
        [Yy]* ) make install; break;;
        [Nn]* ) exit;;
        * ) echo "Please answer yes or no.";;
    esac
done

Select From “Yes/No” Menu In Bash

Another easy method is to use select command (source):

echo "Do you wish to install this program?"
select yn in "Yes" "No"; do
  case $yn in
    Yes ) make install;;
    No ) exit;;
  esac
done