Sleep
3 min readOct 25, 2023

Android i2p ToR And Termux Harden

#!/bin/bash

# Update and upgrade Termux packages
pkg update
pkg upgrade

# Install necessary packages
pkg install i2pd tor

# Start I2P
i2pd

# Start Tor
tor

# Set up proxy for I2P
echo “socksProxyType = 0” >> $HOME/.i2pd/tunnels.conf

# Set up proxy for Tor
echo “SOCKS5Proxy 127.0.0.1:9050” >> $HOME/.torrc

# Harden I2P and Tor installations
# Disable non-localhost access to control port
echo “ControlPort 127.0.0.1:9051” >> $HOME/.torrc
echo “HashedControlPassword $(tor — hash-password YourStrongPassword)” >> $HOME/.torrc
echo “i2pd.disable.localconf=1” >> $HOME/.i2pd/i2pd.conf

# Restart I2P and Tor
pkill i2pd
i2pd
pkill tor
tor

# Print success message
echo “I2P and Tor are now installed, configured, and hardened on your Android device.”

# Update and upgrade packages
pkg update && pkg upgrade -y

# Remove unnecessary packages
pkg autoremove

# Set up a strong password for the user
passwd

# Install essential security tools
pkg install -y openssl openssh fail2ban

# Configure SSH server
cat <<EOL > $PREFIX/etc/ssh/sshd_config
PermitRootLogin no
PasswordAuthentication no
AllowUsers your_username_here
EOL

# Restart SSH server
sshd

# Set up firewall rules (if necessary)
# Example: ufw allow 22 (for allowing SSH)

# Enable fail2ban
sed -i ‘s/ENABLED=false/ENABLED=true/’ $PREFIX/etc/fail2ban/jail.conf

# Set up a firewall (if available)
# Example: ufw default deny incoming && ufw default allow outgoing && ufw enable

# Install and configure AppArmor (if supported)
# Example: pkg install apparmor && aa-enforce /etc/apparmor.d/*

# Harden shell environment
cat <<’EOL’ >> ~/.bashrc
# Set restrictive umask
umask 027

# Prevent file overwrite on redirect
set -o noclobber

# Set history controls
export HISTFILESIZE=1000
export HISTSIZE=1000
export HISTCONTROL=ignoredups
export HISTTIMEFORMAT=”%Y-%m-%d %H:%M:%S “

# Disable unnecessary services
services=(inetd telnet bluetooth)
for service in “${services[@]}”; do
su -c “pm disable $service”
done
EOL

echo “Termux command line security hardened successfully!”

# Step 1: Install I2P
wget https://download.i2p2.de/releases/1.5.0/i2pinstall_1.5.0.jar -P /tmp
java -jar /tmp/i2pinstall_1.5.0.jar -console
sudo systemctl start i2p

# Step 2: Configure I2P to act as a DNS forwarder
# You need to manually configure this through I2P’s web interface (http://127.0.0.1:7657/configclients).

# Step 3: Install DNSCrypt on Android
# You can download a DNSCrypt app from the Google Play Store.

# Step 4: Configure DNSCrypt with I2P’s DNS forwarder
# Obtain the IP address and port of your I2P router acting as a DNS forwarder.

I2P_DNS_IP=”127.0.0.1"
I2P_DNS_PORT=”4444"

# Replace ‘DNSCRYPT_CONFIG_FILE’ with the actual DNSCrypt configuration file path.
# For example, on Termux: DNSCRYPT_CONFIG_FILE=”$HOME/.config/dnscrypt-proxy/dnscrypt-proxy.toml”

DNSCRYPT_CONFIG_FILE=”/path/to/your/dnscrypt-proxy.toml”

# Append the I2P DNS forwarder to DNSCrypt configuration
echo “ [static.” >> $DNSCRYPT_CONFIG_FILE
echo “ [static.’i2p’]” >> $DNSCRYPT_CONFIG_FILE
echo “ addresses = [‘$I2P_DNS_IP:$I2P_DNS_PORT’]” >> $DNSCRYPT_CONFIG_FILE
echo “ ]” >> $DNSCRYPT_CONFIG_FILE

# Restart DNSCrypt
# Make sure you know the command to restart DNSCrypt on your Android device.

echo “DNSCrypt configured with I2P DNS forwarder.”

# Note: Always consult the official documentation and adjust settings according to your specific setup and Android device model.

# Install Orbot (Tor for Android)
adb install -r orbot.apk

# Start Orbot
adb shell am start -n org.torproject.android/.OrbotMainActivity

# Wait for Orbot to start
sleep 10

# Connect to the Tor network
adb shell input tap 50 520

# Install I2P (Note: You may need to replace the URL with the latest release)
adb install -r i2p-android-release.apk

# Start I2P
adb shell am start -n net.i2p.android.router/net.i2p.android.router.Main

# Wait for I2P to start
sleep 30

# Connect to the I2P network
adb shell input tap 150 800

Responses (1)