Advertisement
Sweetening

Harden Termux

Oct 18th, 2023
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # Update and upgrade packages
  4. pkg update -y
  5. pkg upgrade -y
  6.  
  7. # Install essential packages
  8. pkg install -y git openssh openssl termux-api
  9.  
  10. # Configure SSH
  11. ssh-keygen -t rsa -b 4096 -f ~/.ssh/id_rsa
  12. echo "PermitRootLogin no" >> $PREFIX/etc/ssh/sshd_config
  13. echo "PasswordAuthentication no" >> $PREFIX/etc/ssh/sshd_config
  14. sshd
  15.  
  16. # Set up firewall rules
  17. ufw enable
  18. ufw default deny incoming
  19. ufw default allow outgoing
  20. ufw allow ssh
  21.  
  22. # Install and set up a VPN
  23. pkg install -y openvpn easy-rsa
  24. mkdir -p ~/openvpn
  25. cd ~/openvpn
  26. cp -r $PREFIX/share/easy-rsa/* .
  27. chmod 700 ~/openvpn
  28. cd ~/openvpn/easyrsa3
  29. ./easyrsa init-pki
  30. ./easyrsa build-ca
  31. ./easyrsa gen-req server nopass
  32. ./easyrsa sign-req server server
  33. ./easyrsa gen-dh
  34. openvpn --genkey --secret ta.key
  35. cp pki/ca.crt pki/private/server.key pki/issued/server.crt pki/dh.pem ta.key $HOME/openvpn
  36.  
  37. # Enable SELinux
  38. setenforce 1
  39.  
  40. # Install and configure a firewall
  41. pkg install -y iptables
  42. iptables -P INPUT DROP
  43. iptables -P FORWARD DROP
  44. iptables -P OUTPUT ACCEPT
  45. iptables -A INPUT -i lo -j ACCEPT
  46. iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
  47. iptables -A INPUT -p tcp --dport 22 -j ACCEPT
  48. iptables -A INPUT -p icmp --icmp-type echo-request -j ACCEPT
  49. iptables -A INPUT -j DROP
  50.  
  51. # Disable unnecessary services
  52. # (Note: Some services may not be available in Termux)
  53. # systemctl disable bluetooth.service
  54. # systemctl disable cups.service
  55. # systemctl disable cups-browsed.service
  56.  
  57. # Clean up
  58. pkg clean
  59.  
  60. # Check for Android Security Bulletins
  61. adb shell "am start -a android.intent.action.VIEW -d https://source.android.com/security/bulletin"
  62.  
  63. # Check and update packages through adb
  64. adb shell "su -c 'pkg update -y && pkg upgrade -y'"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement