HowTo: Use AirCrack-NG – WiFi Password Hacker – Tutorial

If you want to know how to hack WiFi access point – just read this step by step aircrack-ng tutorial, run the verified commands and hack WiFi password easily.

With the help a these commands you will be able to hack WiFi AP (access points) that use WPA/WPA2-PSK (pre-shared key) encryption.

The basis of this method of hacking WiFi lies in capturing of the WPA/WPA2 authentication handshake and then cracking the PSK using aircrack-ng. (more…)

List All VHosts in Apache

If you have to troubleshoot any Apache issues, it is always a good idea to start with checking of the currently enabled Virtual Hosts.

This can be done with the -S option used on the httpd/apache2 or on the apachectl/apache2ctl.

-S option shows which ports and which IP addresses or domain names are configured for each website being served, shows where the configuration file for each VirtualHost is located and performs a syntax check.

Get a List of All VHosts in Apache

Use one of the following commands to get a list of all VHosts in Apache on RHEL, CentOS, Fedora etc.:

$ httpd -S
$ apachectl -S

List All Virtual Hosts Served by Apache2

Use one of the following commands to list all Virtual Hosts served by Apache2 on Ubuntu, Debian, Linux Mint etc.:

$ apache2 -S
$ apache2ctl -S

In the output of the above commands you’ll see all currently enabled Virtual Hosts and the result of a syntax check:

VirtualHost configuration:
1.2.3.4:80          is a NameVirtualHost
default server default (/etc/apache2/sites-enabled/default.conf:1)
port 80 namevhost example.com (/etc/apache2/sites-enabled/example.conf:1)
port 443 namevhost example.com (/etc/apache2/sites-enabled/example.conf:15)
Syntax OK

HowTo: Create a Password Protected ZIP File in Linux

This is a small note that describes how to encrypt and decrypt a ZIP file from the Linux command line.

I’ll show how to create a password protected ZIP archive from one or several unprotected files or folders.

Warning! The standard ZIP encryption is very weak and could be cracked easily.

Password Protected ZIP File in Linux

Create an encrypted ZIP file secure.zip from some file:

$ zip --encrypt secure.zip file
Enter password: 
Verify password: 
  adding: file (deflated 8%)

Create password protected ZIP archive secure.zip from the several files:

$ zip --encrypt secure.zip file1 file2 file3
Enter password: 
Verify password: 
  adding: file1 (stored 15%)
  adding: file2 (deflated 30%)
  adding: file3 (deflated 45%)

Create an encrypted ZIP archive secure.zip from a folder /var/log/:

$ zip --encrypt -r secure.zip /var/log/
Enter password: 
Verify password: 
  adding: var/log/ (stored 0%)
  adding: var/log/dmesg.0 (deflated 74%)
  adding: var/log/dpkg.log.9.gz (deflated 0%)
  adding: var/log/samba/log.asc-nb (deflated 96%)
***

Use the following command to uncompress a ZIP file:

$ unzip secure.zip
Enter password:
***

Encrypt and Decrypt ZIP Archive in Linux

You were interactively prompted for the password in the examples above.

If you want to create a password protected ZIP file from some shell script, you may want to do it non-interactively.

This method is more insecure, as the password is entered as plain text.

You can easily encrypt and decrypt ZIP files from the Linux command line without being prompted for the password.

Do it as follows:

$ zip -P passw0rd secure.zip file
$ zip -P passw0rd secure.zip file1 file2 file3
$ zip -P passw0rd -r secure.zip /var/log/

Uncompress a password protected ZIP archive:

$ unzip -P passw0rd secure.zip

Anonymous Port Scanning: Nmap + Tor + ProxyChains

In this article i will explain how to stay anonymous during port scanning with Nmap (utility for network discovery and security auditing).

I’ll show how to perform an anonymous port scanning through the Tor network, using ProxyChains utility.

I’ll also show how to get round a situation where scan fails, because Tor endpoints are blocked.

Install Tor + Nmap + ProxyChains

To perform an anonymous port scanning, we need to install the following tools:

Package Description
tor Anonymizing overlay network for TCP
nmap Network port scanner
proxychains Redirect connections through proxy servers

Tor

Install Tor from the standard repositories:

$ sudo apt-get install tor

Nmap

$ sudo apt-get install nmap

ProxyChains

$ sudo apt-get install proxychains

ProxyChains is already configured to use Tor by default.

You can verify this by looking up /etc/proxychains.conf.

The last lines should be like these:

[ProxyList]
# add proxy here ...
# meanwile
# defaults set to "tor"
socks4 127.0.0.1 9050

Anonymous Port Scanning Through Tor

Run the following command to perform an anonymous Nmap scanning through Tor network:

$ proxychains nmap -sT -PN -n -sV -p 80,443,21,22 217.xx.xx.xx
ProxyChains-3.1 (http://proxychains.sf.net)

Starting Nmap 6.00 ( http://nmap.org ) at 2014-03-24 17:34 EET
|S-chain|-<>-127.0.0.1:9050-<><>-217.xx.xx.xx:443-<><>-OK
|S-chain|-<>-127.0.0.1:9050-<><>-217.xx.xx.xx:21-<><>-OK
|S-chain|-<>-127.0.0.1:9050-<><>-217.xx.xx.xx:80-<><>-OK
|S-chain|-<>-127.0.0.1:9050-<><>-217.xx.xx.xx:22-<--denied

Nmap scan report for 217.xx.xx.xx
Host is up (0.14s latency).
PORT    STATE  SERVICE  VERSION
21/tcp  open   ftp      Pure-FTPd
22/tcp  closed ssh
80/tcp  open   http     Apache httpd 2.2.26 ((CentOS))
443/tcp open   ssl/http Apache httpd 2.2.26 ((CentOS))

In the scan log we can see the ‘chain’ that goes from Tor-proxy (127.0.0.1:9050) to our scanned host (217.xx.xx.xx).

Nmap Through Tor: Get Round Blocked Endpoints

It is possible that we will encounter a situation where scan fails, because Tor endpoints are blocked.

The solution may be in adding common public proxy server to the ‘chain’.

We can do that by simply editing the /etc/proxychains.conf and adding a new entry at the end of the [ProxyList] (be sure that random_chain option is disabled).

[ProxyList]
# add proxy here ...
# meanwile
# defaults set to "tor"
socks4  127.0.0.1 9050
socks4 115.71.237.212 1080

The new ‘chain’ goes through the Tor-proxy (127.0.0.1:9050) to some public proxy server (115.71.237.212:1080) and then to our scanned host (217.xx.xx.xx).

$ proxychains nmap -sT -PN -n -sV -p 21 217.xx.xx.xx
ProxyChains-3.1 (http://proxychains.sf.net)

Starting Nmap 6.00 ( http://nmap.org ) at 2014-03-25 11:05 EET
|S-chain|-<>-127.0.0.1:9050-<>-115.71.237.212:1080-<><>-217.xx.xx.xx:21-<><>-OK
|S-chain|-<>-127.0.0.1:9050-<>-115.71.237.212:1080-<><>-217.xx.xx.xx:21-<><>-OK
Nmap scan report for 217.xx.xx.xx
Host is up (1.2s latency).
PORT   STATE SERVICE VERSION
21/tcp open  ftp     Pure-FTPd

In the examples above, i run Nmap with the following options:

Option Description
-sT full TCP connection scan
-PN do not perform host discovery
-n never perform DNS resolution (to prevent DNS leaks)
-sV determine service version/info
-p ports to scan

Scanning through Tor is very slow. That is why, i’ve scanned only several specified ports in the examples above.

Lists of Free Public Proxy Servers

Even if you are using proxy, all your DNS queries still go to the DNS server of your ISP.

To prevent DNS leaks, use tor-resolve command to resolve a hostname to an IP address via Tor network:

$ tor-resolve google.com
173.194.34.174

RegEx: Find IP Addresses in a File Using Grep

Here are some regular expressions that will help you to perform a validation and to extract all matched IP addresses from a file.

The following regular expressions match IPv4 addresses.

Matched IP addresses can be extracted from a file using grep command.

In this article you’ll find a regular expressions themselves and an example of how to extract matched IP addresses from a file with the grep command.

Regular Expression to Match IP Addresses

Use the following regular expression to match IPv4 addresses (actually it matches all expressions from 0.0.0.0 to 999.999.999.999).

"([0-9]{1,3}[\.]){3}[0-9]{1,3}"

Grep IP Addresses

Parse a file and print all expressions that match a range between 0.0.0.0 and 999.999.999.999.

$ grep -E -o "([0-9]{1,3}[\.]){3}[0-9]{1,3}" file.txt

This regular expression is quite simple but you should understand that not all matches are technically valid IP addresses.

Let’s find only valid IP addresses with the second regular expression.

Match only Valid IPv4 Addresses

Use the following regular expression to find and validate the IPv4 addresses:

"(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)"

Grep Only Valid IP Addresses

Find and extract only valid IP addresses from a file:

$ grep -E -o "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)" file.txt
Option Description
-E, –extended-regexp Use extended regular expression
-o, –only-matching Print IP addresses only

Omit -o option to print lines that contains IP addresses.

HowTo: Create CSR using OpenSSL Without Prompt (Non-Interactive)

In this article you’ll find how to generate CSR (Certificate Signing Request) using OpenSSL from the Linux command line, without being prompted for values which go in the certificate’s subject field.

Below you’ll find two examples of creating CSR using OpenSSL.

In the first example, i’ll show how to create both CSR and the new private key in one command.

And in the second example, you’ll find how to generate CSR from the existing key (if you already have the private key and want to keep it).

Both examples show how to create CSR using OpenSSL non-interactively (without being prompted for subject), so you can use them in any shell scripts.

Create CSR and Key Without Prompt using OpenSSL

Use the following command to create a new private key 2048 bits in size example.key and generate CSR example.csr from it:

$ openssl req -nodes -newkey rsa:2048 -keyout example.key -out example.csr -subj "/C=GB/ST=London/L=London/O=Global Security/OU=IT Department/CN=example.com"
Option Description
openssl req certificate request generating utility
-nodes if a private key is created it will not be encrypted
-newkey creates a new certificate request and a new private key
rsa:2048 generates an RSA key 2048 bits in size
-keyout the filename to write the newly created private key to
-out specifies the output filename
-subj sets certificate subject

Generate CSR From the Existing Key using OpenSSL

Use the following command to generate CSR example.csr from the private key example.key:

$ openssl req -new -key example.key -out example.csr -subj "/C=GB/ST=London/L=London/O=Global Security/OU=IT Department/CN=example.com"
Option Description
openssl req certificate request generating utility
-new generates a new certificate request
-key specifies the file to read the private key from
-out specifies the output filename
-subj sets certificate subject

Automated Non-Interactive CSR Generation

The magic of CSR generation without being prompted for values which go in the certificate’s subject field, is in the -subj option.

-subj arg Replaces subject field of input request with specified data and outputs modified request. The arg must be formatted as /type0=value0/type1=value1/type2=…, characters may be escaped by \ (backslash), no spaces are skipped.

The fields, required in CSR are listed below:

Field Meaning Example
/C= Country GB
/ST= State London
/L= Location London
/O= Organization Global Security
/OU= Organizational Unit IT Department
/CN= Common Name example.com

You’ve created encoded file with certificate signing request.

Now you can decode CSR to verify that it contains the correct information.

Creating ASCII Text Banners from the Linux Command Line

In this article, i’ll show how to make ASCII text banner or signature from the Linux command line.

You can use such text in SSH warning banners and welcome messages.

To convert plain text to a large ASCII banner, we need to install a Linux command line utility, named FIGlet.

FIGlet is a program for making large letters out of ordinary text.

In most cases you’ll find FIGlet in standard repositories of your distribution, but if there is no FIGlet package, you can take it from EPEL repository.

Installing FIGlet In Linux

Install a FIGlet utility, to be able to convert text to ASCII Art from the Linux command line.

In Ubuntu, Debian, Linux Mint etc.

$ sudo apt-get install figlet

In CentOS, RHEL, Fedora etc.

$ yum install figlet

Generate ASCII Text Banners

To use FIGlet with its default settings, simply type:

$ figlet "Shell Hacks"
 ____  _          _ _   _   _            _        
/ ___|| |__   ___| | | | | | | __ _  ___| | _____ 
\___ \| '_ \ / _ \ | | | |_| |/ _` |/ __| |/ / __|
 ___) | | | |  __/ | | |  _  | (_| | (__|   <\__ \
|____/|_| |_|\___|_|_| |_| |_|\__,_|\___|_|\_\___/

To change the font, use the -f option, for example:

$ figlet -f digital "Shell Hacks"
+-+-+-+-+-+ +-+-+-+-+-+
|S|h|e|l|l| |H|a|c|k|s|
+-+-+-+-+-+ +-+-+-+-+-+

Use the -c option if you would prefer centered output:

$ figlet -c "Shell Hacks"

List FIGlet Fonts

Print a list of available FIGlet fonts:

$ showfigfonts

You can also download and use additional FIGlet fonts, for example:

$ wget http://www.figlet.org/fonts/univers.flf
$ figlet -f univers.flf "lol"
                   
88             88  
88             88  
88             88  
88  ,adPPYba,  88  
88 a8"     "8a 88  
88 8b       d8 88  
88 "8a,   ,a8" 88  
88  `"YbbdP"'  88  

Create ASCII Art From Text

If you would like to display the output of a command using FIGlet, simply pipe the command into FIGlet:

$ date +%r | figlet -f bubble
  _   _   _   _   _   _   _   _     _   _  
 / \ / \ / \ / \ / \ / \ / \ / \   / \ / \ 
( 0 | 4 |: | 5 | 1 |: | 4 | 9 ) ( P | M )
 \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/   \_/ \_/ 

$ echo "WTF?" | figlet -f banner
#     # ####### #######  #####  
#  #  #    #    #       #     # 
#  #  #    #    #             # 
#  #  #    #    #####      ###  
#  #  #    #    #          #    
#  #  #    #    #               
 ## ##     #    #          #  

If FIGlet gets its input from a file, use -p option:

$ cat myfile
Shell Hacks
$ figlet -p < myfile
 ____  _          _ _   _   _            _        
/ ___|| |__   ___| | | | | | | __ _  ___| | _____ 
\___ \| '_ \ / _ \ | | | |_| |/ _` |/ __| |/ / __|
 ___) | | | |  __/ | | |  _  | (_| | (__|   <\__ \
|____/|_| |_|\___|_|_| |_| |_|\__,_|\___|_|\_\___/

Now have fun, creating your own ASCII text banners from the Linux terminal.

More information can be found on FIGlet official site.

Mounting an ISO Image in Linux

You can easily access an ISO image of a CD or DVD (e.g. RHEL DVD) from the command line in Linux.

To access an ISO disc image, you have to create a mount point (empty folder that will be used as a root filesystem) and mount an ISO file to it.

In this article, i’ll show how to Mount and Unmount an ISO file from the Linux Command Line (CentOS, RHEL, Fedora, Ubuntu, Debian, Mint etc.).

To mount an ISO image in Linux, you must be a root or use sudo.

Create a Mount Point for ISO Image

A mount point – is a directory (typically an empty folder) from which the content of an ISO disc image will be accessible.

Create a mount point:

$ sudo mkdir -p /mnt/mount_point

Mount an ISO File in Linux

Mount an ISO file /home/user/disk.iso to the mount point /mnt/mount_point:

$ sudo mount -o loop /home/user/disk.iso /mnt/mount_point

After ISO disk is mounted, you will receive the following message: ‘mount: warning: /mnt/mount_point seems to be mounted read-only‘.

You can ignore it, because according to the ISO 9660 standard, ISO images are always mounted in read-only mode.

Verify that ISO File is Mounted

List mounted devices to verify that ISO image has successfully been mounted:

$ mount

Below you should see a line like the following:

/home/user/disk.iso on /mnt/mount_point type iso9660 (ro)

Now you can access the mount point and list the files stored on the ISO disk image:

$ cd /mnt/mount_point
$ ls -l

Unmount an ISO File in Linux

Use the following command to unmount an ISO disc image:

$ sudo umount /mnt/mount_point

Removing EXIF Data From Images and Photos in Linux

Most digital cameras and cell phone add EXIF metadata to the images.

EXIF metadata includes camera specifications, settings, location (GPS coordinates) and more.

If you’re worried about the privacy, you may want to anonymize your images and photos by removing all the EXIF metadata.

In this small guide, i’ll show how to read and then remove all EXIF metadata, using Linux command line utility, named ExifTool.

Install ExifTool

Under Ubuntu/Linux Mint/Dedian etc.:

$ sudo apt-get install libimage-exiftool-perl

Read EXIF Metadata from Image

Extract and view all EXIF metadata from an image or photo:

$ exiftool image.jpeg

Remove EXIF Metadata from Image

Remove all EXIF metadata from an image or photo:

$ exiftool -all= image.jpeg

Remove EXIF Data from Multiple Files

The next commands, also makes copies of the original files with the “_original” prefix.

Go into the directory with the images.

Execute the following command to remove all EXIF metadata from all images in the current directory:

$ exiftool -all= *

Remove EXIF metadata from images with “.jpeg” extensions only:

$ exiftool -all= *.jpeg

SED/AWK – Add to the End or Beginning of a Line

From time to time it is required to modify some file very fast.

And it goes without saying that the most popular command line tools for this in Linux are sed and awk – the two best text processing programs.

In the following article, you’ll find an information about how to add some text, character or comma to the beginning or to the end of every line in a file using sed and awk. (more…)