termux-nethunter

Install Kali NetHunter in Termux

View on GitHub

TERMUX NETHUNTER

<div align=”center”;background-color:black;border:3px solid black;border-radius:6px;margin:5px 0;padding:2px 5px”> Image could not be loaded! </div>

Are you a linux fan or do you just love playing with the terminal and executing cool commands, just to look like a tech genius? Well, for whatever reason it is that you want to install linux on your phone, I got you covered.

Installing linux on your phone might not make you a hacker, but it will certainly make you look and feel like one.

With this guide, you will be able to run a full linux system, including every linux command you can think of and install different PC software, all on your phone! Wait that’s not all, you can run a desktop environment and enjoy the PC graphical interface and probably try to hack into NASA using your phone like the guy in that one movie.

Did I mention that you do not require root access to do all this? All you have to do is follow these simple installation instructions and you are a few keystrokes away from running all the cool programs created by the linux community.

Contents
Features
  • anti-root fuse
  • interactive installation
  • color output (if supported)
  • command line options
    • install in custom directory
    • make clean install (no configurations)
    • configurations only (if already installed)
    • uninstall
    • color
    • log
  • creates vnc wrapper
  • automatic configurations
  • provides access to system and Termux commands
  • customize default shell and local time during installation
  • minor tweaks

Installation

How to install

Download and install the Termux app on your phone, then open it and execute the following commands.

  1. Upgrade Termux packages
pkg update && pkg upgrade
  1. Install curl
pkg install curl
  1. Download the install script
curl -fsSLO https://raw.githubusercontent.com/jorexdeveloper/termux-nethunter/main/install-nethunter.sh
  1. Execute install script
bash install-nethunter.sh

See bash install-nethunter.sh --help for usage information.

It’s probably a good idea to inspect any install script from projects you don’t yet know. You can do that by downloading the install script, looking through it so everything looks fine before running it.

If you are lazy like me, you can just copy and paste the commands below in Termux.

pkg update -y && pkg upgrade -y && pkg install -y curl && curl -fsSLO https://raw.githubusercontent.com/jorexdeveloper/termux-nethunter/main/install-nethunter.sh && bash install-nethunter.sh

Launch and set up

After successful installation, you need to launch the system and make a few set ups.

How to launch

Launch the system by simply executing the following command.

nethunter

or with a shorter version

nh

You will be logged in with the default user name, kali (You can login as another user by providing their user name as an argument. See nethunter --help for usage information).

How to install desktop and vnc server

For the minimal and nano installations, you will need to install a desktop environment and a vnc server to get a graphical interface to interact with.

Launch the system and execute the following commands.

  1. Upgrade system packages
sudo apt update && apt full-upgrade
  1. Install vnc server
sudo apt install tigervnc-standalone-server dbus-x11
  1. Install desktop environment
sudo apt install kali-desktop-xfce

This command will not only take several gigabytes of your storage but also take a while to complete, grab a coffee and make sure you keep Termux open during the installation or you might run into some problems later (You can also acquire Termux wake lock but it will only work if battery optimization is disabled).

Login

Now all that’s left is to login into your newly installed system and start playing around with some commands. To do that, you need to start a vnc server in the system and connect to it through a vnc viewer.

How to start vnc server

Launch the system and execute the following command.

vnc

See vnc help for usage information.

On the first run of the command above, you will be prompted for a vnc password. This is the password that will be used to securely connect to the vnc server, in the vnc viewer, so save it somewhere.

How to connect to vnc server

To connect to the vnc server, you will need to download and install a vnc viewer app of your choice (I recommend AVNC).

Start the vnc server and minimize Termux.

Then open the vnc viewer app, click add server and fill in with the following details:

Name

Kali Desktop

Host

localhost

Port

The default display port differs for the root user and other users (Don’t ask me why, I just got here).

user name port
root 5900
kali (and any other users) 5901

You shall use the second one if you are logged in as kali (The default login).

Password

Enter the vnc password you set when starting the vnc server for the first time.

Have fun

If you managed to get this far without any problems, congratulations! Linux now is installed on your phone and it’s time to explore and have some fun with it!

The possibilities are endless and the only limits that exist are the ones you set up for yourself.

You might wan’t to google for some cool commands and programs to execute or even when get you stuck, good luck.

Backup and Restore

I stubbornly refuse to add a backup feature to the install script because it defeats the whole design structure of making the program do one thing extremely well.

But, backing up the installed rootfs is more complicated than just running an ordinary tar command.

How to backup

To backup your installed rootfs, you need to execute the tar command with a few extra options to ensure that file permissions are properly handled and your system remains usable.

Here is a simple shell function to help you do that.

Note: This process requires you to backup and restore the rootfs to the same directory as the original installation, otherwise the proot links get broken and some system files get corrupted.

backup() {
	if [ -n "${1}" ] && [ -d "${1}" ]; then
		if [ -n "${2}" ]; then
			local file="${2}"
		else
			# Default archive name if not given.
			local file="${HOME}/$(basename "${1}").tar.xz"
		fi
		# Directories to include in the archive some read-only directories
    # like /dev need to be ignored but you can add your own if you wish
		local dirs=(.l2s bin boot etc home lib media mnt opt proc root run sbin snap srv sys tmp usr var)
		echo "Packing chroot into '${file}'."
		echo "Including ${dirs[*]}"
		# Make sure all directories exist
		for i in "${dirs[@]}"; do
			mkdir -p "${1}/${i}"
		done
		unset i
		# Switch to the chroot directory and
		# backup the given directories
		tar \
			--warning=no-file-ignored \
			--one-file-system \
			--xattrs \
			--xattrs-include='*' \
			--preserve-permissions \
			--create \
			--auto-compress \
			-C "${1}" --file "${file}" "${dirs[@]}"
	else
		echo "Usage: chroot-backup PATH [FILE]"
	fi
}

Just copy and paste the above code in Termux and then run the command below.

backup <path-to-rootfs-directory>

How to restore

To restore your installation from the archive, execute the following commands.

Restore your previous installation directory first. (using another directory breaks the installed system because the proot links get broken).

mkdir -p <path-to-rootfs-directory>

Switch to the directory.

cd <path-to-rootfs-directory>

Unpack the archive.

tar \
    --delay-directory-restore \
    --preserve-permissions \
    --warning=no-unknown-keyword \
    --extract \
    --auto-compress \
    --file "<path-to-rootfs-archive>"

If you feel like all that is too technical, feel free to contribute a backup/restore script that automates the entire process because i’m just lil lazy for that right now (see the contributions section).

Uninstallation

If for some reason you need to uninstall the system from Termux, just follow the steps below.

How to uninstall

Simply execute the install script again in Termux with the option --uninstall.

bash install-nethunter.sh --uninstall

Note: If you installed the system in a custom directory, supply the path to the installation directory as an additional argument.

FAQ

If you got some hickups during the installation or have some burning questions, you are probably not the first one. Feel free to document them in the issues section

However, a few frequently asked questions have been answered below.

What happens if Termux has root access?

This guide assumes that Termux has no root access and the only root permissions that exist are those simulated in the installed system.

However, if you have tried following the steps above with root permissions in Termux, then you have probably not succeeded because installing and running the system with root permissions in Termux can have unintended effects, and should never be done (unless you are sure of what you are doing) otherwise you might end up damaging your device.

For that reason, I added an anti-root fuse to the install script that prevents the installation process if Termux has root access.

There should not be a good enough reason to launch the system when Termux has root permissions because harmless root privileges are still simulated in the system with help of proot.

Work around

If you don’t mind damaging your device (probably making it unusable) and are ready to get your hands dirty, this section might resonate.

Disabling the anti-root fuse will require a deeper understanding of the install script and the installation process. You will need to edit the install script as follows:

Not very helpful, is it? That because this is definitely a bad idea and you are completely liable for any unintended effects of this action.

Just remember, I am mostly lazy and would never implement an anti-root fuse for absolutely no reason.

Contribution

Contributions to this project are not only welcome, but also encouraged.

Here is the current TODO list.

  1. Create a backup/restore script that:

    • Is intuitive and not boring.
    • Can be back up and restore into another directory (proot links are kept intact).
    • Includes usage information.
  2. Utilize the dialog command to perform the installation using GUI (the dialog command comes pre-installed in Termux).
  3. Any other improvements.

And most imporantly, make sure any new programs/scripts/functions do only one thing and extrenely well.

License

    Copyright (C) 2023  Jore

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <https://www.gnu.org/licenses/>.