CONTENTS IN DETAIL

ACKNOWLEDGMENTS

INTRODUCTION

What’s in This Book

What Is Ethical Hacking?

Penetration Testing

Military and Espionage

Why Hackers Use Linux

Linux Is Open Source

Linux Is Transparent

Linux Offers Granular Control

Most Hacking Tools Are Written for Linux

The Future Belongs to Linux/Unix

Downloading Kali Linux

Virtual Machines

Installing VirtualBox

Setting Up Your Virtual Machine

Installing Kali on the VM

Setting Up Kali

1
GETTING STARTED WITH THE BASICS

Introductory Terms and Concepts

A Tour of Kali

The Terminal

The Linux Filesystem

Basic Commands in Linux

Finding Yourself with pwd

Checking Your Login with whoami

Navigating the Linux Filesystem

Getting Help

Referencing Manual Pages with man

Finding Stuff

Searching with locate

Finding Binaries with whereis

Finding Binaries in the PATH Variable with which

Performing More Powerful Searches with find

Filtering with grep

Modifying Files and Directories

Creating Files

Creating a Directory

Copying a File

Renaming a File

Removing a File

Removing a Directory

Go Play Now!

Exercises

2
TEXT MANIPULATION

Viewing Files

Taking the Head

Grabbing That Tail

Numbering the Lines

Filtering Text with grep

Hacker Challenge: Using grep, nl, tail, and head

Using sed to Find and Replace

Viewing Files with more and less

Controlling the Display with more

Displaying and Filtering with less

Summary

Exercises

3
ANALYZING AND MANAGING NETWORKS

Analyzing Networks with ifconfig

Checking Wireless Network Devices with iwconfig

Changing Your Network Information

Changing Your IP Address

Changing Your Network Mask and Broadcast Address

Spoofing Your MAC Address

Assigning New IP Addresses from the DHCP Server

Manipulating the Domain Name System

Examining DNS with dig

Changing Your DNS Server

Mapping Your Own IP Addresses

Summary

Exercises

4
ADDING AND REMOVING SOFTWARE

Using apt to Handle Software

Searching for a Package

Adding Software

Removing Software

Updating Packages

Upgrading Packages

Adding Repositories to Your sources.list File

Using a GUI-based Installer

Installing Software with git

Summary

Exercises

5
CONTROLLING FILE AND DIRECTORY PERMISSIONS

Different Types of Users

Granting Permissions

Granting Ownership to an Individual User

Granting Ownership to a Group

Checking Permissions

Changing Permissions

Changing Permissions with Decimal Notation

Changing Permissions with UGO

Giving Root Execute Permission on a New Tool

Setting More Secure Default Permissions with Masks

Special Permissions

Granting Temporary Root Permissions with SUID

Granting the Root User’s Group Permissions SGID

The Outmoded Sticky Bit

Special Permissions, Privilege Escalation, and the Hacker

Summary

Exercises

6
PROCESS MANAGEMENT

Viewing Processes

Filtering by Process Name

Finding the Greediest Processes with top

Managing Processes

Changing Process Priority with nice

Killing Processes

Running Processes in the Background

Moving a Process to the Foreground

Scheduling Processes

Summary

Exercises

7
MANAGING USER ENVIRONMENT VARIABLES

Viewing and Modifying Environment Variables

Viewing All Environment Variables

Filtering for Particular Variables

Changing Variable Values for a Session

Making Variable Value Changes Permanent

Changing Your Shell Prompt

Changing Your PATH

Adding to the PATH Variable

How Not to Add to the PATH Variable

Creating a User-Defined Variable

Summary

Exercises

8
BASH SCRIPTING

A Crash Course in Bash

Your First Script: “Hello, Hackers-Arise!”

Setting Execute Permissions

Running HelloHackersArise

Adding Functionality with Variables and User Input

Your Very First Hacker Script: Scan for Open Ports

Our Task

A Simple Scanner

Improving the MySQL Scanner

Common Built-in Bash Commands

Summary

Exercises

9
COMPRESSING AND ARCHIVING

What Is Compression?

Tarring Files Together

Compressing Files

Compressing with gzip

Compressing with bzip2

Compressing with compress

Creating Bit-by-Bit or Physical Copies of Storage Devices

Summary

Exercises

10
FILESYSTEM AND STORAGE DEVICE MANAGEMENT

The Device Directory /dev

How Linux Represents Storage Devices

Drive Partitions

Character and Block Devices

List Block Devices and Information with lsblk

Mounting and Unmounting

Mounting Storage Devices Yourself

Unmounting with umount

Monitoring Filesystems

Getting Information on Mounted Disks

Checking for Errors

Summary

Exercises

11
THE LOGGING SYSTEM

The rsyslog Logging Daemon

The rsyslog Configuration File

The rsyslog Logging Rules

Automatically Cleaning Up Logs with logrotate

Remaining Stealthy

Removing Evidence

Disabling Logging

Summary

Exercises

12
USING AND ABUSING SERVICES

Starting, Stopping, and Restarting Services

Creating an HTTP Web Server with the Apache Web Server

Starting with Apache

Editing the index.html File

Adding Some HTML

Seeing What Happens

OpenSSH and the Raspberry Spy Pi

Setting Up the Raspberry Pi

Building the Raspberry Spy Pi

Configuring the Camera

Starting to Spy

Extracting Information from MySQL

Starting MySQL

Interacting with MySQL

Setting a MySQL Password

Accessing a Remote Database

Connecting to a Database

Database Tables

Examining the Data

PostgreSQL with Metasploit

Summary

Exercises

13
BECOMING SECURE AND ANONYMOUS

How the Internet Gives Us Away

The Onion Router System

How Tor Works

Security Concerns

Proxy Servers

Setting Proxies in the Config File

Some More Interesting Options

Security Concerns

Virtual Private Networks

Encrypted Email

Summary

Exercises

14
UNDERSTANDING AND INSPECTING WIRELESS NETWORKS

Wi-Fi Networks

Basic Wireless Commands

Wi-Fi Recon with aircrack-ng

Detecting and Connecting to Bluetooth

How Bluetooth Works

Bluetooth Scanning and Reconnaissance

Summary

Exercises

15
MANAGING THE LINUX KERNEL AND LOADABLE KERNEL MODULES

What Is a Kernel Module?

Checking the Kernel Version

Kernel Tuning with sysctl

Managing Kernel Modules

Finding More Information with modinfo

Adding and Removing Modules with modprobe

Inserting and Removing a Kernel Module

Summary

Exercises

16
AUTOMATING TASKS WITH JOB SCHEDULING

Scheduling an Event or Job to Run on an Automatic Basis

Scheduling a Backup Task

Using crontab to Schedule Your MySQLscanner

crontab Shortcuts

Using rc Scripts to Run Jobs at Startup

Linux Runlevels

Adding Services to rc.d

Adding Services to Your Bootup via a GUI

Summary

Exercises

17
PYTHON SCRIPTING BASICS FOR HACKERS

Adding Python Modules

Using pip

Installing Third-Party Modules

Getting Started Scripting with Python

Variables

Comments

Functions

Lists

Modules

Object-Oriented Programming (OOP)

Network Communications in Python

Building a TCP Client

Creating a TCP Listener

Dictionaries, Loops, and Control Statements

Dictionaries

Control Statements

Loops

Improving Our Hacking Scripts

Exceptions and Password Crackers

Summary

Exercises

INDEX