- All the info was extracted from Offsec, Pen-103, under the following licencese
6. Configuring Kali Linux
In this chapter, we will take a look at various ways you can configure Kali Linux. First, inĀ Configuring the Network, we will show you how to configure your network settings using a graphical environment and the command line. InĀ Managing Unix Users and Unix Groups, we will talk about users and groups, showing you how to create and modify user accounts, set passwords, disable accounts, and manage groups. Finally, we will discuss services inĀ Configuring ServicesĀ and explain how to set up and maintain generic services and also focus on three very important and specific services: SSH, PostgreSQL, and Apache.
6.1.1. On the Desktop with NetworkManager
In a typical desktop installation, youāll haveĀ NetworkManagerĀ already installed and it can be controlled and configured through Xfceās system settings and through the top-right menu as shown in Figure 1.
Figure 1: Network Configuration Screen
The default network configuration relies on DHCP to obtain an IP address, DNS server, and gateway, but you can use the gear icon in the lower-left corner to alter the configuration in many ways (for example: set the MAC address, switch to a static setup, enable or disable IPv6, and add additional routes). You can create profiles to save multiple wired network configurations and easily switch between them. For wireless networks, their settings are automatically tied to their public identifier (SSID).
NetworkManager also handles connections by mobile broadband (Wireless Wide Area Network WWAN) and by modems using point-to-point protocol over ethernet (PPPoE). Last but not least, it provides integration with many types of virtual private networks (VPN) through dedicated plugins: SSH, OpenVPN, Ciscoās VPNC, PPTP, Strongswan. Check out theĀ network-manager-*Ā packages; most of them are not installed by default.
6.1.2. On the Command Line with Ifupdown
Alternatively, when you prefer not to use (or donāt have access to) a graphical desktop, you can configure the network with the already-installedĀ ifupdown
Ā package, which includes theĀ ifup
Ā andĀ ifdown
Ā tools. These tools read definitions from theĀ /etc/network/interfaces
Ā configuration file and are at the heart of theĀ /etc/init.d/networking
Ā init script that configures the network at boot time.
Using sudo to access Administrative Privileges
TheĀ sudo
Ā (super user do) command allows privileged users to run commands with administrative permissions. This gives full access to items that may be restricted to only the root user, such as programs inĀ /sbin/
Ā or access to network options that are useful for common penetration testing tools.
The command takes one argument, being the subsequent command that will be run with administrative permissions. One useful use case when dealing with services is to elevate to the root user account. To elevate to root user, we will use the commandĀ su
Ā (substitute user) to create a shell under the root user. The substitute user command takes a user account as an argument. Additionally, theĀ su
Ā command has a useful flag (--login
, orĀ -l
, orĀ -
) to use the substituted userās login environment. Multiple commands in the following chapter require the use ofĀ sudo
, as such we will elevate to the root user to seamlessly execute these commands.
$ sudo su --login
[sudo] password for kali:
root@kali:~#
Each network device managed byĀ ifupdownĀ can be deconfigured at any time withĀ ifdown network-device
. You can then modifyĀ /etc/network/interfaces
Ā and bring the network back up (with the new configuration) withĀ ifup network-device
.
Letās take a look at what we can put in ifupdownās configuration file. There are two main directives:Ā auto network-device
, which tellsĀ ifupdownĀ to automatically configure the network interface once it is available, andĀ iface network-device inet/inet6 type
Ā to configure a given interface. For example, a plain DHCP configuration looks like this:
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet dhcp
Note that the special configuration for the loopback device should always be present in this file. For a fixed IP address configuration, you have to provide more details such as the IP address, the network, and the IP of the gateway:
auto eth0
iface eth0 inet static
address 192.168.0.3
netmask 255.255.255.0
broadcast 192.168.0.255
network 192.168.0.0
gateway 192.168.0.1
For wireless interfaces, you must have theĀ wpasupplicant
Ā package (included in Kali by default), which provides manyĀ wpa-*
Ā options that can be used inĀ /etc/network/interfaces
. Have a look atĀ /usr/share/doc/wpasupplicant/README.Debian.gz
Ā for examples and explanations. The most common options areĀ wpa-ssid
Ā (which defines the name of the wireless network to join) andĀ wpa-psk
Ā (which defines the passphrase or the key protecting the network).
iface wlan0 inet dhcp
wpa-ssid MyNetWork
wpa-psk plaintextsecret
6.1.3. On the Command Line with systemd-networkd
WhileĀ ifupdownĀ is the historical tool used by Debian and Kali, and while it is still the default for minimal installations, there is a newer tool worth considering:Ā systemd-networkd. Its integration with theĀ systemdĀ init system makes it a very attractive choice. It is not specific to Debian-based distributions (contrary toĀ ifupdown) and has been designed to be very small, efficient, and relatively easy to configure if you understand the syntax of systemd unit files. This is an especially attractive choice if you considerĀ NetworkManagerĀ bloated and hard to configure.
You configureĀ systemd-networkd
Ā by placingĀ .network
Ā files into theĀ /etc/systemd/network/
Ā directory. Alternatively, you can useĀ /lib/systemd/network/
Ā for packaged files orĀ /run/systemd/network/
Ā for files generated at run-time. The format of those files is documented in systemd.network(5) (seeĀ Manual Pages). The [Match
] section indicates the network interfaces the configuration applies to. You can specify the interface in many ways, including by media access control (MAC) address or device type. The [Network
] section defines the network configuration.
Example 5.1. Static Configuration inĀ /etc/systemd/network/50-static.network
[Match]
Name=enp2s0
[Network]
Address=192.168.0.15/24
Gateway=192.168.0.1
DNS=8.8.8.8
Example 5.2. DHCP-based Configuration inĀ /etc/systemd/network/80-dhcp.network
[Match]
Name=en*
[Network]
DHCP=yes
Note thatĀ system-networkd
Ā is disabled by default, so if you want to use it, you should enable it. It also depends onĀ systemd-resolved
Ā for proper integration of DNS resolution, which in turn requires you to replaceĀ /etc/resolv.conf
Ā with a symlink toĀ /run/systemd/resolve/resolv.conf
, which is managed byĀ systemd-resolved
.
systemctl enable systemd-networkd
systemctl enable systemd-resolved
systemctl start systemd-networkd
systemctl start systemd-resolved
ln -sf /run/systemd/resolve/resolv.conf /etc/resolv.conf
AlthoughĀ systemd-networkd
Ā suffers from some limitations, like the lack of integrated support for wireless networks, you can rely on a pre-existing externalĀ wpa_supplicant
Ā configuration for wireless support. However, it is particularly useful in containers and virtual machines, and was originally developed for environments in which a containerās network configuration depended on its hostās network configuration. In this scenario,Ā systemd-networkd
Ā makes it easier to manage both sides in a consistent manner while still supporting all sorts of virtual network devices that you might need in this type of scenario (see systemd.netdev(5) inĀ Manual Pages).
6.2. Managing Unix Users and Unix Groups
The database of Unix users and groups consists of the textual filesĀ /etc/passwd
Ā (list of users),Ā /etc/shadow
Ā (encrypted passwords of users),Ā /etc/group
Ā (list of groups), andĀ /etc/gshadow
Ā (encrypted passwords of groups). Their formats are documented in passwd(5), shadow(5), group(5), and gshadow(5) respectively (seeĀ Manual Pages. While these files can be manually edited with tools likeĀ vipw
Ā andĀ vigr
, there are higher level tools to perform the most common operations.
UsingĀ getent
Ā to Consult the User Database
TheĀ getent
Ā (get entries) command checks the system databases (including those of users and groups) using the appropriate library functions, which in turn call the name service switch (NSS) modules configured in theĀ /etc/nsswitch.conf
Ā file. The command takes one or two arguments: the name of the database to check, and a possible search key. Thus, the commandĀ getent passwd kaliuser1
Ā will return the information from the user database regarding the userĀ kaliuser1
.
root@kali:~# getent passwd kaliuser1
kaliuser1:x:1001:1001:Kali User,4444,123-867-5309,321-867-5309:/home/kaliuser1:/bin/bash
6.2.1. Creating User Accounts
Although Kali is most often run while privileged with sudo permissions, you may often need to create non-privileged user accounts for various reasons, particularly if you are using Kali as a primary operating system. The most typical way to add a user is with theĀ adduser
Ā command, which takes a required argument: the username for the new user that you would like to create.
TheĀ adduser
Ā command asks a few questions before creating the account but its usage is fairly straightforward. Its configuration file,Ā /etc/adduser.conf
, includes many interesting settings. You can, for example, define the range of user identifiers (UIDs) that can be used, dictate whether or not users share a common group or not, define default shells, and more.
The creation of an account triggers the population of the userās home directory with the contents of theĀ /etc/skel/
Ā template. This provides the user with a set of standard directories and configuration files.
In some cases, it will be useful to add a user to a group (other than their default main group) in order to grant additional permissions. For example, a user who is included in theĀ dockerĀ group has full access to docker commands and services. This can be achieved with a command such asĀ adduser user group
.
6.2.2. Modifying an Existing Account or Password
The following commands allow modification of the information stored in specific fields of the user databases:
passwd
āpermits a regular user to change their password, which in turn, updates theĀ/etc/shadow
Ā file.chfn
ā(CHange Full Name), reserved for the super-user (root), modifies theĀGECOS
, or āgeneral informationā field.chsh
ā(CHange SHell) changes the userās login shell. However, available choices will be limited to those listed inĀ/etc/shells
; the administrator, on the other hand, is not bound by this restriction and can set the shell to any program chosen.chage
ā(CHange AGE) allows the administrator to change the password expiration settings by passing the user name as an argument or list current settings using theĀ-l user
Ā option. Alternatively, you can also force the expiration of a password using theĀpasswd -e user
Ā command, which forces the user to change their password the next time they log in.
6.2.3. Disabling an Account
You may find yourself needing to disable an account (lock out a user) as a disciplinary measure, for the purposes of an investigation, or simply in the event of a prolonged or definitive absence of a user. A disabled account means the user cannot login or gain access to the machine. The account remains intact on the machine and no files or data are deleted; it is simply inaccessible. This is accomplished by using the commandĀ passwd -l user
Ā (lock). Re-enabling the account is done in similar fashion, with theĀ -u
Ā option (unlock).
6.2.4. Managing Unix Groups
TheĀ addgroup
Ā andĀ delgroup
Ā commands add or delete a group, respectively. TheĀ groupmod
Ā command modifies a groupās information (itsĀ gid
Ā or identifier). The commandĀ gpasswd group
Ā changes the password for the group, while theĀ gpasswd -r group
Ā command deletes it.
Working with Several Groups
Each user may be a member of many groups. A userās main group is, by default, created during initial user configuration. By default, each file that a user creates belongs to the user, as well as to the userās main group. This is not always desirable; for example, when the user needs to work in a directory shared by a group other than their main group. In this case, the user needs to change groups using one of the following commands:Ā newgrp
, which starts a new shell, orĀ sg
, which simply executes a command using the supplied alternate group. These commands also allow the user to join a group to which they do not currently belong. If the group is password protected, they will need to supply the appropriate password before the command is executed.
Alternatively, the user can set theĀ setgid
Ā bit on the directory, which causes files created in that directory to automatically belong to the correct group. For more details, seeĀ SECURITYĀ setgid
Ā directory and sticky bit.
TheĀ id
Ā command displays the current state of a user, with their personal identifier (uid
Ā variable), current main group (gid
Ā variable), and the list of groups to which they belong (groups
Ā variable).
6.3. Configuring Services
In this section we will take a look at services (sometimes called daemons), or programs that run as a background process and perform various functions for the system. We will start by discussing configuration files and will proceed to explain how some important services (such as SSH, PostgreSQL, and Apache) function and how they can be configured.
Kali Linuxās policy is to have any network services disabled by default, which is a different behavior to other Linux operating systems. For more information seeĀ Kali Linux Policies.
6.3.1. Configuring a Specific Program
When you want to configure an unknown package, you must proceed in stages. First, you should read what the package maintainer has documented. TheĀ /usr/share/doc/package/README.Debian
Ā file is a good place to start. This file will often contain information about the package, including pointers that may refer you to other documentation. You will often save yourself a lot of time, and avoid a lot of frustration, by reading this file first since it often details the most common errors and solutions to most common problems.
Next, you should look at the softwareās official documentation. Refer toĀ Documentation SourcesĀ for tips on how to find various documentation sources. TheĀ dpkg -L package
Ā command gives a list of files included in the package; you can therefore quickly identify the available documentation (as well as the configuration files, located inĀ /etc/
). Also,Ā dpkg -s package
Ā displays the package meta-data and shows any possible recommended or suggested packages; in there, you can find documentation or perhaps a utility that will ease the configuration of the software.
Finally, the configuration files are often self-documented by many explanatory comments detailing the various possible values for each configuration setting. In some cases, you can get software up and running by uncommenting a single line in the configuration file. In other cases, examples of configuration files are provided in theĀ /usr/share/doc/package/examples/
Ā directory. They may serve as a basis for your own configuration file.
6.3.2. Configuring SSH for Remote Logins
SSH allows you to remotely log into a machine, transfer files, or execute commands. It is an industry standard tool (ssh
) and service (sshd
) for connecting to machines remotely.
While theĀ openssh-server
Ā package is installed by default, theĀ SSHĀ service is disabled by default and thus is not started at boot time. You can manually start the SSH service withĀ systemctl start ssh
Ā or configure it to start at boot time withĀ systemctl enable ssh
.
The SSH service has a relatively sane default configuration, but given its powerful capabilities and sensitive nature, it is good to know what you can do with its configuration file,Ā /etc/ssh/sshd_config
. All the options are documented in sshd_config(5) (seeĀ Manual Pages).
The default configuration allows password-based logins. If this is not wanted, you can disable this by settingĀ PasswordAuthentication
Ā toĀ no
. Doing so will mean that and SSH key will need to be generated. The SSH service listens by default on port 22 but you can change this with theĀ Port
Ā directive.
To apply the new settings, you should runĀ systemctl reload ssh
.
Generating New SSH Host Keys
Each SSH server has its own cryptographic keys; they are named āSSH host keysā and are stored inĀ /etc/ssh/ssh_host_*
. They must be kept private if you want confidentiality and they should not be shared by multiple machines.
When you install your system by copying a full disk image (instead of using debian-installer such as ARM images), the image might contain pre-generated SSH host keys that you should thus replace with newly-generated keys. The image probably also comes with a default user password that you want to reset at the same time. You can do all this with the following commands:
# passwd
[...]
# rm /etc/ssh/ssh_host_*
# dpkg-reconfigure openssh-server
# systemctl restart ssh
6.3.3. Configuring PostgreSQL Databases
PostgreSQL is a database server. It is rarely useful on its own but is used by many other services to store data. Those services will generally access the database server over the network and usually require authentication credentials to be able to connect. Setting up those services thus requires creating PostgreSQL databases and user accounts with appropriate privileges on the database. To be able to do that, we need the service to be running, so letās start it withĀ systemctl start postgresql
.
Multiple PostgreSQL versions supported
The PostgreSQL packaging allows for multiple versions of the database server to be co-installed. It is also possible to handle multipleĀ clustersĀ (a cluster is a collection of databases served by the sameĀ postmaster
). To achieve this, the configuration files are stored inĀ /etc/postgresql/version/cluster-name/
.
In order for clusters to run side-by-side, each new cluster gets assigned the next available port number (usually 5433 for the second cluster). TheĀ postgresql.service
Ā file is an empty shell, making it easy to act on all clusters together as each cluster has its own unit (postgresql@version-cluster.service
).
Connection Type and Client Authentication
By default, PostgreSQL listens for incoming connections in two ways: on TCP port 5432 of the localhost interface and on file-based socketĀ /var/run/postgresql/.s.PGSQL.5432
. This can be configured inĀ postgresql.conf
Ā with various directives:Ā listen_addresses
Ā for the addresses to listen to,Ā port
Ā for the TCP port, andĀ unix_socket_directories
Ā to define the directory where the file-based sockets are created.
Depending on how they connect, clients are authenticated in different ways. TheĀ pg_hba.conf
Ā configuration file defines who is allowed to connect on each socket and how they are authenticated. By default, connections on the file-based socket use the Unix user account as the name of the PostgreSQL user, and it assumes that no further authentication is required. On the TCP connection, PostgreSQL requires the user to authenticate with a username and a password (though not a Unix username/password but rather one managed by PostgreSQL itself).
TheĀ postgres
Ā user is special and has full administrative privileges over all databases. We will use this identity to create new users and new databases.
Creating Users and Databases
TheĀ createuser
Ā command adds a new user andĀ dropuser
Ā removes one. Likewise, theĀ createdb
Ā command adds a new database andĀ dropdb
Ā removes one. Each of these commands have their own manual pages but we will discuss some of the options here. Each command acts on the default cluster (running on port 5432) but you can passĀ --port=port
Ā to modify users and databases of an alternate cluster.
These commands must connect to the PostgreSQL server to do their job and they must be authenticated as a user with sufficient privileges to be able to execute the specified operation. The easiest way to achieve this is to use theĀ postgres
Ā Unix account and connect over the file-based socket:
# su - postgres
postgres@kali:~$ createuser -P king_phisher
Enter password for new role:
Enter it again:
postgres@kali:~$ createdb -T template0 -E UTF-8 -O king_phisher king_phisher
postgres@kali:~$ exit
In the example above, theĀ -P
Ā option asksĀ createuser
Ā to query for a password once it creates the newĀ king_phisher
Ā user. Looking at theĀ createdb
Ā command, theĀ -O
Ā defines the user owning the new database (which will thus have full rights to create tables and grant permissions and so on). We also want to be able to use Unicode strings, so we add theĀ -E UTF-8
Ā option to set the encoding, which in turn requires us to use theĀ -T
Ā option to pick another database template.
We can now test that we can connect to the database over the socket listening on localhost (-h localhost
) as the king_phisher user (-U king_phisher
):
# psql -h localhost -U king_phisher king_phisher
Password for user king_phisher:
psql (9.5.2)
SSL connection (protocol: TLSv1.2, cipher: ECDHE-RSA-AES256-GCM-SHA384, bits: 256, compression: off)
Type "help" for help.
king_phisher=>
As you can see, the connection was successful.
Managing PostgreSQL Clusters
First, it is worth noting that the concept of āPostgreSQL clusterā is aĀ Debian-specific additionĀ and that you will not find any reference to this term in theĀ official PostgreSQL documentation. From the point of view of the PostgreSQL tools, such a cluster is just an instance of a database server running on a specific port.
That said, DebianāsĀ postgresql-common
Ā package provides multiple tools to manage such clusters:Ā pg_createcluster
,Ā pg_dropcluster
,Ā pg_ctlcluster
,Ā pg_upgradecluster
,Ā pg_renamecluster
, andĀ pg_lsclusters
. We wonāt cover all those tools here, but you can refer to their respective manual pages for more information.
What you must know is that when a new major version of PostgreSQL gets installed on your system, it will create a new cluster that will run on the next port (usually 5433) and you will keep using the old version until you migrate your databases from the old cluster to the new one.
You can retrieve a list of all the clusters and their status withĀ pg_lsclusters
. More importantly, you can automate the migration of your cluster to the latest PostgreSQL version withĀ pg_upgradecluster old-version cluster-name
. For this to succeed, you might have to first remove the (empty) cluster created for the new version (withĀ pg_dropcluster new-version cluster-name
). The old cluster is not dropped in the process, but it also wonāt be started automatically. You can drop it once you have checked that the upgraded cluster works fine.
6.3.4. Configuring Apache
A typical Kali Linux installation includes the Apache web server, provided by theĀ apache2
Ā package. Being a network service, it is disabled by default. You can manually start it withĀ systemctl start apache2
.
With more and more applications being distributed as web applications, it is important to have some knowledge of Apache in order to host those applications, whether for local usage or for making them available over the network.
Apache is a modular server and many features are implemented by external modules that the main program loads during its initialization. The default configuration only enables the most common modules, but enabling new modules is easily done by runningĀ a2enmod _module_
. UseĀ a2dismod module
Ā to disable a module. These programs actually only create (or delete) symbolic links inĀ /etc/apache2/mods-enabled/
, pointing at the actual files (stored inĀ /etc/apache2/mods-available/
).
There are many modules available, but two are worth initial consideration: PHP and SSL (used for TLS). Web applications written with PHP are executed by the Apache web server with the help of the dedicated module provided by theĀ libapache-mod-php
Ā package, and its installation automatically enables the module.
Apache 2.4 includes the SSL module required for Hypertext Transfer Protocol Secure (HTTPS) out of the box. It first needs to be enabled withĀ a2enmod ssl
, then the required directives must be added to the configuration files. A configuration example is provided inĀ /etc/apache2/sites-available/default-ssl.conf
. SeeĀ https://httpd.apache.org/docs/2.4/mod/mod_ssl.htmlĀ for more information.
The full list of standard Apache modules can be found online atĀ https://httpd.apache.org/docs/2.4/mod/index.html.
With its default configuration, the web server listens on port 80 (as configured inĀ /etc/apache2/ports.conf
), and serves pages from theĀ /var/www/html/
Ā directory by default (as configured inĀ /etc/apache2/sites-enabled/000-default.conf
).
Configuring Virtual Hosts
A virtual host is an extra identity for the web server. The same Apache process can serve multiple websites (sayĀ www.kali.org
Ā andĀ www.offsec.com
) because the HTTP requests embed both the name of the website requested and the URL localpart (this feature is known asĀ name-based virtual hosts).
The default configuration for Apache 2 enables name-based virtual hosts. In addition, a default virtual host is defined in theĀ /etc/apache2/sites-enabled/000-default.conf
Ā file; this virtual host will be used if no host matching the request sent by the client is found.
Important
Requests concerning unknown virtual hosts will always be served by the first defined virtual host, which is why the package ships aĀ 000-default.conf
Ā configuration file, which is sorted first among all other files that you might create.
Each extra virtual host is then described by a file stored inĀ /etc/apache2/sites-available/
. The file is usually named after the hostname of the website followed by aĀ .conf
Ā suffix (for example:Ā www.kali.org.conf
). You can then enable the new virtual host withĀ a2ensite www.kali.org
. Here is a minimal virtualhost configuration for a website whose files are stored inĀ /srv/www.kali.org/www/
Ā (defined with theĀ DocumentRoot
Ā option):
<VirtualHost *:80>
ServerName www.kali.org
ServerAlias kali.org
DocumentRoot /srv/www.kali.org/www
</VirtualHost>
You might also consider addingĀ CustomLog
Ā andĀ ErrorLog
Ā directives to configure Apache to output logs in files dedicated to the virtual host.
Common Directives
This section briefly reviews some of the commonly-used Apache configuration directives.
The main configuration file usually includes severalĀ Directory
Ā blocks; they allow specifying different behaviors for the server depending on the location of the file being served. Such a block commonly includesĀ Options
Ā andĀ AllowOverride
Ā directives:
<Directory /var/www>
Options Includes FollowSymLinks
AllowOverride All
DirectoryIndex index.php index.html index.htm
</Directory>
TheĀ DirectoryIndex
Ā directive contains a list of files to try when the client request matches a directory. The first existing file in the list is used and sent as a response.
TheĀ Options
Ā directive is followed by a list of options to enable. TheĀ None
Ā value disables all options; correspondingly,Ā All
Ā enables them all exceptĀ MultiViews
. Available options include:
ExecCGI
Ā - indicates that CGI scripts can be executed.FollowSymLinks
Ā - tells the server that symbolic links can be followed, and that the response should contain the contents of the target of such links.SymLinksIfOwnerMatch
Ā - also tells the server to follow symbolic links, but only when the link and its target have the same owner.Includes
Ā - enablesĀ Server Side IncludesĀ (SSI). These are directives embedded in HTML pages and executed on the fly for each request.Indexes
Ā - tells the server to list the contents of a directory if the HTTP request sent by the client points to a directory without an index file (that is, when no files mentioned by theĀDirectoryIndex
Ā directive exist in this directory).MultiViews
Ā - enables content negotiation; this can be used by the server to return a web page matching the preferred language as configured in the browser.
Requiring Authentication
In some circumstances, access to part of a website needs to be restricted, so only legitimate users who provide a username and a password are granted access to the contents.
TheĀ .htaccess
Ā file contains Apache configuration directives enforced each time a request concerns an element from the directory where theĀ .htaccess
Ā file is stored. These directives are recursive, expanding the scope to all subdirectories.
Most of the directives that can occur in aĀ Directory
Ā block are also legal in anĀ .htaccess
Ā file. TheĀ AllowOverride
Ā directive lists all the options that can be enabled or disabled by way ofĀ .htaccess
. A common use of this option is to restrictĀ ExecCGI
, so that the administrator chooses which users are allowed to run programs under the web serverās identity (theĀ www-data
Ā user).
Example 5.3.Ā .htaccess
Ā File Requiring Authentication
Require valid-user
AuthName "Private directory"
AuthType Basic
AuthUserFile /etc/apache2/authfiles/htpasswd-private
Basic Authentication Offers No Security
The authentication system used in the above example (Basic
) has minimal security as the password is sent in clear text (it is only encoded asĀ base64, which is a simple encoding rather than an encryption method). It should also be noted that the documents protected by this mechanism also go over the network in the clear. If security is important, the entire HTTP session should be encrypted with Transport Layer Security (TLS).
TheĀ /etc/apache2/authfiles/htpasswd-private
Ā file contains a list of users and passwords; it is commonly manipulated with theĀ htpasswd
Ā command. For example, the following command is used to add a user or change their password:
# htpasswd /etc/apache2/authfiles/htpasswd-private user
New password:
Re-type new password:
Adding password for user user
Restricting Access
TheĀ Require
Ā directive controls access restrictions for a directory (and its subdirectories, recursively).
It can be used to restrict access based on many criteria; we will stop at describing access restriction based on the IP address of the client but it can be made much more powerful than that, especially when severalĀ Require
Ā directives are combined within aĀ RequireAll
Ā block.
For instance, you could restrict access to the local network with the following directive:
Require ip 192.168.0.0/16
6.4. Managing Services
Kali usesĀ systemd
Ā as its init system, which is not only responsible for the boot sequence, but also permanently acts as a full featured service manager, starting and monitoring services.
systemd
Ā can be queried and controlled withĀ systemctl
. Without any argument, it runs theĀ systemctl list-units
Ā command, which outputs a list of the activeĀ units. If you runĀ systemctl status
, the output shows a hierarchical overview of the running services. Comparing both outputs, you immediately see that there are multiple kinds of units and that services are only one among them.
Each service is represented by aĀ service unit, which is described by a service file usually shipped inĀ /lib/systemd/system/
Ā (orĀ /run/systemd/system/
, orĀ /etc/systemd/system/
; they are listed by increasing order of importance, and the last one wins). Each is possibly modified by otherĀ service-name.service.d/*.conf
Ā files in the same set of directories. Those unit files are plain text files whose format is inspired by the well-known ā*.iniā files of Microsoft Windows, withĀ key = value
Ā pairs grouped betweenĀ [section]
Ā headers. Here we see a sample service file forĀ /lib/systemd/system/ssh.service
:
[Unit]
Description=OpenBSD Secure Shell server
After=network.target auditd.service
ConditionPathExists=!/etc/ssh/sshd_not_to_be_run
[Service]
EnvironmentFile=-/etc/default/ssh
ExecStart=/usr/sbin/sshd -D $SSHD_OPTS
ExecReload=/bin/kill -HUP $MAINPID
KillMode=process
Restart=on-failure
RestartPreventExitStatus=255
Type=notify
[Install]
WantedBy=multi-user.target
Alias=sshd.service
Target units are another part of systemdās design. They represent a desired state that you want to attain in terms of activated units (which means a running service in the case of service units). They exist mainly as a way to group dependencies on other units. When the system starts, it enables the units required to reach theĀ default.target
Ā (which is a symlink toĀ graphical.target
, and which in turn depends onĀ multi-user.target
). So all the dependencies of those targets get activated during boot.
Such dependencies are expressed with theĀ Wants
Ā directive on the target unit. But you donāt have to edit the target unit to add new dependencies, you can also create a symlink pointing to the dependent unit in theĀ /etc/systemd/system/target-name.target.wants/
Ā directory. And this is exactly whatĀ systemctl enable foo.service
Ā does. When you enable a service, you tell systemd to add a dependency on the targets listed in theĀ WantedBy
Ā entry of theĀ [Install]
Ā section of the service unit file. Conversely,Ā systemctl disable foo.service
Ā drops the same symlink and thus the dependency.
TheĀ enable
Ā andĀ disable
Ā commands do not change anything regarding the current status of the services. They only influence what will happen at next boot. If you want to run the service immediately, you should executeĀ systemctl start foo.service
. Conversely, you can stop it withĀ systemctl stop foo.service
. You can also inspect the current status of a service withĀ systemctl status foo.service
, which usefully includes the latest lines of the associated log. After having changed the configuration of a service, you may wish to reload it or restart it: those operations are done withĀ systemctl reload foo.service
Ā andĀ systemctl restart foo.service
Ā respectively.
# systemctl status postgresql
ā postgresql.service - PostgreSQL RDBMS
Loaded: loaded (/lib/systemd/system/postgresql.service; disabled; vendor preset: disabled)
Active: inactive (dead)
# ls -al /etc/systemd/system/multi-user.target.wants/postgresql.service
ls: cannot access '/etc/systemd/system/multi-user.target.wants/postgresql.service': No such file or directory
# systemctl enable postgresql
[...]
# ls -al /etc/systemd/system/multi-user.target.wants/postgresql.service
lrwxrwxrwx 1 root root 38 Jan 26 19:09 /etc/systemd/system/multi-user.target.wants/postgresql.service -> /lib/systemd/system/postgresql.service
# systemctl status postgresql
ā postgresql.service - PostgreSQL RDBMS
Loaded: loaded (/lib/systemd/system/postgresql.service; enabled; vendor preset: disabled)
Active: inactive (dead)
# systemctl start postgresql
# systemctl status postgresql
ā postgresql.service - PostgreSQL RDBMS
Loaded: loaded (/lib/systemd/system/postgresql.service; enabled; vendor preset: disabled)
Active: active (exited) since Tue 2021-01-26 19:10:31 EST; 5s ago
Process: 1495 ExecStart=/bin/true (code=exited, status=0/SUCCESS)
Main PID: 1495 (code=exited, status=0/SUCCESS)
Jan 26 19:10:31 kali-rolling systemd[1]: Starting PostgreSQL RDBMS...
Jan 26 19:10:31 kali-rolling systemd[1]: Started PostgreSQL RDBMS.
6.5. Summary
In this chapter, we learned how to configure Kali Linux. We configured network settings, talked about users and groups, and discussed how to create and modify user accounts, set passwords, disable accounts, and manage groups. Finally, we discussed services and explained how to set up and maintain generic services, specifically SSH, PostgreSQL, and Apache.
Summary Tips:
- In a typical desktop installation, you will haveĀ NetworkManagerĀ already installed and it can be controlled and configured through Xfceās system settings and through the top-right menu.
- You can configure the network from the command line with theĀ
ifup
Ā andĀifdown
Ā tools, which read their instructions from theĀ/etc/network/interfaces
Ā configuration file. An even newer tool,Ā systemd-networkdĀ works with theĀ systemdĀ init system. - By default, the database of Unix users and groups consists of the textual filesĀ
/etc/passwd
Ā (list of users),Ā/etc/shadow
Ā (encrypted passwords of users),Ā/etc/group
Ā (list of groups), andĀ/etc/gshadow
Ā (encrypted passwords of groups). - You can use theĀ
getent
Ā command to consult the user database and other system databases. - TheĀ
adduser
Ā command asks a few questions before creating the account, but is a straightforward way to create a new user account. - Several commands can be used to modify specific fields in the user database including:Ā
passwd
Ā (change password),Āchfn
Ā (change full name and theĀGECOS
, or general information field),Āchsh
Ā (change login shell),Āchage
Ā (change password age), andĀpasswd -e user
Ā (forces the user to change their password the next time they log in). - Each user can be a member of one or multiple groups. Several commands can be used to modify group identity:Ā
newgrp
Ā changes the current group ID,Āsg
Ā executes a command using the supplied alternate group, theĀsetgid
Ā bit can be placed on a directory, causing files created in that directory to automatically belong to the correct group. In addition, theĀid
Ā command displays the current state of a user including a list of their group membership. - You can manually start SSH withĀ
systemctl start ssh
Ā or permanently enable it withĀsystemctl enable ssh
. - PostgreSQL is a database server. It is rarely useful on its own but is used by many other services to store data.
- A typical Kali Linux installation includes the Apache web server, provided by theĀ
apache2
Ā package. Being a network service, it is disabled by default. You can manually start it withĀsystemctl start apache2
. - With its default configuration, Apache listens on port 80 (as configured inĀ
/etc/apache2/ports.conf
), and serves pages from theĀ/var/www/html/
Ā directory by default (as configured inĀ/etc/apache2/sites-enabled/000-default.conf
).
Now that we have tackled Linux fundamentals and Kali Linux installation and configuration, letās discuss how to troubleshoot Kali and teach you some tools and tricks to get you back up and running when you run into problems.
6.6.1. Configuring users in Kali
Exercise:
- Create a standard user account. Add the new user to theĀ sudoĀ group
- Change the default login shell to be bash
Exercise solution:
Use commands similar to the following:
kali@kali:~$ sudo adduser username
kali@kali:~$
kali@kali:~$ sudo passwd username
kali@kali:~$
kali@kali:~$ sudo usermod -a -G sudo username
kali@kali:~$
kali@kali:~$ sudo chsh -s /bin/bash username
kali@kali:~$
6.6.2. Configuring the network
Exercise:
- Stop the Network Manager service and completely disable it at boot time.
- Configure your Kali machine for DHCP on eth0.
- Bring down the eth0 interface.
- Connect to the wireless network using your wireless USB dongle by configuringĀ
/etc/network/interfaces
Ā accordingly.
Exercise solution:
- Network Manager is handy, but for pentesting you really need to get hold of your interfaces and bend them to your will without any surprises. To stop Network Manager and disable it at boot time:
kali@kali:~$ sudo systemctl stop NetworkManager.service
kali@kali:~$
kali@kali:~$ sudo systemctl disable NetworkManager.service
kali@kali:~$
You can check the status of Network Manager managed interfaces with:
kali@kali:~$ nmcli dev status
kali@kali:~$
Pro tip: Stop Network Manager from adding dns-servers toĀ /etc/resolv.conf
Ā file:
kali@kali:~$ sudo nano /etc/NetworkManager/NetworkManager.conf
kali@kali:~$
AddĀ dns=noneĀ to the [main] section.
- Configure eth0 for DHCP. Change theĀ
/etc/network/interfaces
Ā file to include:
auto eth0
iface eth0 inet dhcp
You can also set up a static address with something like the following:
auto eth0
iface eth0 inet static
address 192.168.1.160
netmask 255.255.255.0
gateway 192.168.1.1
- Bringing down the eth0 interface:
kali@kali:~$ sudo ifconfig eth0 down
kali@kali:~$
- Connecting to a wireless network. Note that if youāre in a VM youāll need a USB wireless adapter. This example assumes WPA2. Generate a PSK using the following command:
kali@kali:~$ wpa_passphrase myssid wpa-password
kali@kali:~$
Now insert the PSK together with the following into yourĀ /etc/network/interfaces
Ā file:
auto wlan0
iface wlan0 inet dhcp
wpa-ssid myssid
wpa-psk {whatever the PSK hash was}
Spin up the interface:
kali@kali:~$ sudo ifup wlan0
kali@kali:~$
6.6.3. Configuring services (part 1)
Exercise:
- Start the SSH service and connect to it from your host system as theĀ kaliĀ user.
- Configure the SSH service to start at boot time.
- Change the default password and generate new SSH host keys.
Exercise solution:
- Start sshd:
kali@kali:~$ sudo systemctl start ssh
kali@kali:~$
Connect to it from your host system:
user@host:~$ ssh kali@192.168.1.12
kali@kali:~$
- Enable sshd at boot:
kali@kali:~$ sudo systemctl enable ssh
kali@kali:~$
- For security reasons, change the password and generate new SSH host keys:
kali@kali:~$ passwd
[...]
kali@kali:~$
kali@kali:~$ sudo rm /etc/ssh/ssh_host_*
kali@kali:~$
kali@kali:~$ sudo dpkg-reconfigure openssh-server
kali@kali:~$
kali@kali:~$ sudo service ssh restart
kali@kali:~$
6.6.4. Configuring services (part 2)
Exercise:
In this exercise, weāll install masscan. This is a cool tool and the full installation will help review some of the configuration concepts weāve explored in this chapter. The process is broken into several steps:
- Install and start the Apache the PostgreSQL services.
- Configure Apache and PostgreSQL to start at boot time.
- Install masscan, its prerequisites, and OffSecās masscan web interface. Use an Apache / PostgreSQL stack.
- Import a previous scan and view the results.
- Protect the Apache installation with a htaccess username / password.
Exercise solution:
This solution will be a bit out of order. To begin, checkout a copy of the masscan-web-ui repository:
kali@kali:~$ cd ~
kali@kali:~$
kali@kali:~$ git clone https://github.com/offensive-security/masscan-web-ui
kali@kali:~$
Next, make sure all the massscan prerequisites are in place and copy over the masscan web ui files to the web root. Note that if youāre copying and pasting the apt-get line, it is long. Be sure to grab it all:
kali@kali:~$ sudo apt-get install apache2 php libapache2-mod-php php-xml postgresql php-pgsql
kali@kali:~$
kali@kali:~$ sudo mv masscan-web-ui/* /var/www/html/
kali@kali:~$
kali@kali:~$ sudo rm /var/www/html/index.html
kali@kali:~$
Start up Apache and Postgres:
kali@kali:~$ sudo systemctl start apache2
kali@kali:~$
kali@kali:~$ sudo systemctl start postgresql
kali@kali:~$
With Apache and PostgreSQL started, masscan installed and Apacheās default index.html out of the way, you can browse to your Apache server to see masscan. However, it rightly complains about password authentication failures. Letās fix that. Create the masscan user, and create the masscan database.
kali@kali:~$ sudo su - postgres
postgres@kali:~$
postgres@kali:~$ createuser -P masscan
Enter password for new role:
Enter it again:
postgres@kali:~$
postgres@kali:~$ createdb -T template0 -E UTF-8 -O masscan masscandb
postgres@kali:~$
postgres@kali:~$ exit
postgres@kali:~$
Next, modify the password you set and the database name (masscandb) in theĀ defineĀ lines:
kali@kali:~$ sudo nano /var/www/html/config.php
[...]
kali@kali:~$
kali@kali:~$ grep ^define /var/www/html/config.php
define('DB_DRIVER', 'pgsql');
define('DB_HOST', '127.0.0.1');
define('DB_USERNAME', 'masscan');
define('DB_PASSWORD', 'toortoor');
define('DB_DATABASE', 'masscandb');
kali@kali:~$
Browse to http://localhost on your local machine (or the remote address if browsing from outside the VM) which should indicate that masscan is set up properly:
Figure 2: Massscan success
Next, letās import some scan results from a previously run scan. Weāll clear the database since this is the first time weāve used masscan:
kali@kali:~$ wget https://kali.training/downloads/masscan.xml
kali@kali:~$
kali@kali:~$ php /var/www/html/import.php /home/kali/masscan.xml
Do you want to clear the database before importing (yes/no)?: yes
Clearing the db
Reading file
Parsing file
Processing data (This may take some time depending on file size)
Summary:
Total records:4646
Inserted records:4646
Took about:10 seconds
kali@kali:~$
Next, browse to your http://localhost to view the imported data. Since this is āsensitive dataā we want to password-protect the root web directory. To do this we must start with Apache directives:
kali@kali:~$ sudo nano /etc/apache2/sites-enabled/000-default.conf
kali@kali:~$
Add these lines:
AuthType Basic
AuthName "Restricted Content"
AuthUserFile /etc/apache2/htpasswd
Require valid-user
And letās create credentials for a new user:
kali@kali:~$ sudo htpasswd -c /etc/apache2/htpasswd myuser
kali@kali:~$
Lastly, browse to your http://localhost, enter your credentials and view the report.
Did you know?
The Kali Linux policy of disabling network services by default is configured byĀ /lib/systemd/system-preset/{95-kali.preset,99-default.preset}.
6.6.5. Raspberry Pi access point
If you donāt have a Raspberry Pi 3 (RPi 3), you should really get one. They are super cool and relatively inexpensive. In this exercise, you will configure a Raspberry Pi 3 to run as a Wireless Access Point, granting connected users access to the Internet. This exercise is great because you will install Kali to the Raspberry Pi, edit files, change file permissions, configure network interfaces, install and configure services, configure iptables rules and more. Itās a great overview.
Exercise:
- Install Kali on the Raspberry Pi 3. You could use a custom image, but if you do, you might have more troubleshooting to do. If youāre unsure, use the stock image, which this solution was written for.
- Implement WPA2 security on the AP.
- ConfigureĀ eth0Ā as DHCP, andĀ wlan0Ā as static.
- Configure the Raspberry Pi as a DHCP server for any wireless clients and assign a DHCP pool with 12-hour leases.
- Have the SSH server start up at boot time so you can SSH to the Raspberry Pi once itās booted.
- Forward all outbound traffic, including DNS, fromĀ wlan0Ā toĀ eth0.
- Allow inbound established (stateful) connections fromĀ eth0Ā toĀ wlan0.
- Hint: Although you have not learned aboutĀ hostapdĀ orĀ dnsmasq, you will use them in this exercise.
Exercise solution:
This will require a few things:
- Raspberry Pi 3. You can use an older model with a USB wifi but youāre on your own when it comes to configuringĀ wlan0.
- hostapd: This creates an access point
- dnsmasq: This does DNS forwarding and provides a DHCP sever
- dhcpcd5: A DHCP client (which also does other cool network management stuff)
Grab the required packages:
kali@kali:~$ sudo apt-get install dnsmasq hostapd dhcpcd5
kali@kali:~$
First, letās tell dhcpcd to ignore wlan0ās setup. Weāll configure a static IP later:
kali@kali:~$ sudo nano /etc/dhcpcd.conf
kali@kali:~$
Put this above any interface lines that may be in the file:
denyinterfaces wlan0
Now, letās set up our Wi-Fi interface. If you have a Pi 2 with a USB Wi-Fi adapter, go ahead and plug it in now. Edit the interfaces file:
kali@kali:~$ sudo nano /etc/network/interfaces
kali@kali:~$
Add this section:
allow-hotplug wlan0
iface wlan0 inet static
address 172.24.1.1
netmask 255.255.255.0
network 172.24.1.0
broadcast 172.24.1.255
Restart dhcpcd with:
kali@kali:~$ sudo service dhcpcd restart
kali@kali:~$
and then reload the configuration for wlan0 with:
kali@kali:~$ sudo ifdown wlan0; sudo ifup wlan0
kali@kali:~$
Next, letās configure hostapd with a new configuration file. Note that an SSID and passphrase are configured for your access point.
kali@kali:~$ sudo nano /etc/hostapd/hostapd.conf
[...]
kali@kali:~$
kali@kali:~$ cat /etc/hostapd/hostapd.conf
# This is the name of the WiFi interface we configured above
interface=wlan0
# Use the nl80211 driver with the brcmfmac driver
driver=nl80211
# This is the name of the network
ssid=Kali-Pi3
# Use the 2.4GHz band
hw_mode=g
# Use channel 6
channel=6
# Enable 802.11n
ieee80211n=1
# Enable WMM
wmm_enabled=1
# Enable 40MHz channels with 20ns guard interval
ht_capab=[HT40][SHORT-GI-20][DSSS_CCK-40]
# Accept all MAC addresses
macaddr_acl=0
# Use WPA authentication
auth_algs=1
# Require clients to know the network name
ignore_broadcast_ssid=0
# Use WPA2
wpa=2
# Use a pre-shared key
wpa_key_mgmt=WPA-PSK
# The network passphrase
wpa_passphrase=raspberrytoor
# Use AES, instead of TKIP
rsn_pairwise=CCMP
kali@kali:~$
At this point, we can test things out. Run:
kali@kali:~$ sudo /usr/sbin/hostapd /etc/hostapd/hostapd.conf
This shows a successful run. Note that the errors pertaining to monitor mode are not relevant to us. For a RPi3 using the nexmon firmware, we would needĀ nexutil -m2.
kali@kali:~$ sudo /usr/sbin/hostapd /etc/hostapd/hostapd.conf
Configuration file: /etc/hostapd/hostapd.conf
Failed to create interface mon.wlan0: -95 (Operation not supported)
wlan0: Could not connect to kernel driver
Using interface wlan0 with hwaddr b6:ae:d7:42:a1:70 and ssid "Kali-Pi3"
wlan0: interface state UNINITIALIZED->ENABLED
wlan0: AP-ENABLED
kali@kali:~$
You can connect to this access point and hostapd will show some output:
wlan0: STA 78:4f:43:7c:6d:32 IEEE 802.11: associated
And once you enter the passphrase you should see something like this:
wlan0: AP-STA-CONNECTED 78:4f:43:7c:6d:32
wlan0: STA 78:4f:43:7c:6d:32 RADIUS: starting accounting session 5991CC2F-00000000
wlan0: STA 78:4f:43:7c:6d:32 WPA: pairwise key handshake completed (RSN)
wlan0: STA 78:4f:43:7c:6d:32 IEEE 802.11: disassociated
wlan0: AP-STA-DISCONNECTED 78:4f:43:7c:6d:32
wlan0: INTERFACE-DISABLED
wlan0: STA 00:00:00:00:00:00 IEEE 802.11: disassociated
wlan0: INTERFACE-ENABLED
wlan0: STA 78:4f:43:7c:6d:32 IEEE 802.11: associated
Note that your client may disconnect and reconnect because it didnāt get an IP address. This is normal. You wonāt get an IP address until we configure dnsmasq. Have fun with this! It gives you an idea of how this process works, behind the scenes.
Press Ctrl-C to stopĀ hostapd.
Next, weāll tell hostapd where to find its config file:
kali@kali:~$ sudo nano /etc/default/hostapd
kali@kali:~$
Find the lineĀ #DAEMON_CONF=""
Ā and replace it withĀ DAEMON_CONF="/etc/hostapd/hostapd.conf"
.
Letās getĀ dnsmasqĀ set up:
kali@kali:~$ sudo mv /etc/dnsmasq.conf /etc/dnsmasq.conf.orig
kali@kali:~$
kali@kali:~$ sudo nano /etc/dnsmasq.conf
kali@kali:~$
The file should look like this:
interface=wlan0 # Use interface wlan0
listen-address=172.24.1.1 # Set our listening address
bind-interfaces # Bind to the interface to make sure we aren't sending things elsewhere
server=8.8.8.8 # Forward DNS requests to Google DNS
domain-needed # Don't forward short names
bogus-priv # Never forward addresses in the non-routed address spaces.
dhcp-range=172.24.1.50,172.24.1.150,12h # Assign IP addresses between 172.24.1.50 and 172.24.1.150 with a 12 hour lease time
Now, we have two interfaces active, and we have a DHCP client for our Pi and a DHCP server for our wireless guests. Now we need to forward traffic between the Wi-Fi and Ethernet interfaces. We can make this happen immediately with a simple command to update /proc:
kali@kali:~$ echo 1 | sudo tee /proc/sys/net/ipv4/ip_forward
kali@kali:~$
kali@kali:~$ cat /proc/sys/net/ipv4/ip_forward
1
kali@kali:~$
However, this change wonāt stick between reboots. We need to make it permanent through sysctl:
kali@kali:~$ sudo nano /etc/sysctl.conf
kali@kali:~$
Uncomment the line containingĀ net.ipv4.ip_forward=1:
kali@kali:/var/www/html$ grep ip_forward /etc/sysctl.conf
net.ipv4.ip_forward = 1
kali@kali:~$
The forward isnāt quite enough to give our wifi guests Internet access (through our eth0 interface). We need iptables to help us do this.
kali@kali:~$ sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
kali@kali:~$
kali@kali:~$ sudo iptables -A FORWARD -i eth0 -o wlan0 -m state --state RELATED,ESTABLISHED -j ACCEPT
kali@kali:~$
kali@kali:~$ sudo iptables -A FORWARD -i wlan0 -o eth0 -j ACCEPT
kali@kali:~$
Letās unwrap these commands:
- Whenever a new connection is encountered (-t nat), we want to alter the packets as they are about to go out (-A POSTROUTING) on our Ethernet interface (-o eth0). The -j MASQUERADE target masks the private IP address of the client with the external IP address of the firewall/gateway (Kali Pi).
- Next, we append (-A) a rule to the FORWARD chain (packets being routed through the Pi) which accepts (-j ACCEPT) packets from eth0 to wlan0 (-i eth0 -o wlan0) that belong to (ESTABLISHED) or are related to (RELATED) an existing connection.
- Lastly, we will forward (and accept) all packets from wlan0 to eth0.
Check out our rules:
kali@kali:~$ sudo iptables -S
-P INPUT ACCEPT
-P FORWARD ACCEPT
-P OUTPUT ACCEPT
-A FORWARD -i eth0 -o wlan0 -m state --state RELATED,ESTABLISHED -j ACCEPT
-A FORWARD -i wlan0 -o eth0 -j ACCEPT
kali@kali:~$
Output our rules to a file:
kali@kali:~$ iptables-save | sudo tee /etc/iptables.ipv4.nat
kali@kali:~$
Apply these rules every time we boot the Pi by editing theĀ /etc/rc.localĀ file:
kali@kali:~$ sudo nano /etc/rc.local
[...]
kali@kali:~$ more /etc/rc.local
#!/bin/sh -e
iptables-restore < /etc/iptables.ipv4.nat
Make the file executable:
kali@kali:~$ sudo chmod 711 /etc/rc.local
kali@kali:~$ ls -l /etc/rc.local
-rwx--x--x 1 root root 57 Aug 10 19:37 /etc/rc.local
kali@kali:~$
As weāve seen,Ā hostapdĀ andĀ dnsmasqĀ ship with all theĀ init systemĀ goodies (see /etc/init.d), so letās start the services up and check that they are happy:
kali@kali:~$ sudo systemctl start hostapd dnsmasq
kali@kali:~$ sudo systemctl status hostapd dnsmasq
ā hostapd.service - LSB: Advanced IEEE 802.11 management daemon
Loaded: loaded (/etc/init.d/hostapd; generated; vendor preset: disabled)
Active: active (running) since Mon 2017-08-14 19:24:43 UTC; 2s ago
[...]
ā dnsmasq.service - dnsmasq - A lightweight DHCP and caching DNS server
Loaded: loaded (/lib/systemd/system/dnsmasq.service; disabled; vendor preset:
Active: active (running) since Mon 2017-08-14 19:24:43 UTC; 2s ago
kali@kali:~$
And letās set them to run on next reboot:
kali@kali:~$ sudo systemctl enable hostapd dnsmasq
hostapd.service is not a native service, redirecting to systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable hostapd
Synchronizing state of dnsmasq.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable dnsmasq
kali@kali:~$
Finally, reboot and make sure the rules stick after a reboot. Once rebooted, you should be able to connect to the āKali Piā and surf!
Next Module ā Configuring Kali Linux šø