Advertisement
Guest User

Untitled

a guest
Jan 18th, 2019
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 4.26 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3.  
  4. if [ "$(id -u)" -ne 0 ]; then
  5.     echo "[!] This script must run as root" >&2
  6.     exit 1
  7. fi
  8.  
  9.  
  10. /bin/echo "RaspTor - configure your Raspberry Pi into a TOR proxy."
  11.  
  12. /bin/echo "This script will auto-setup a Tor proxy for you. It is recommend that you
  13. run this script on a fresh installation of Raspbian."
  14.  
  15. read -p "Press [Enter] key to begin.." pause
  16.  
  17. DEFAULT_IP_ADDRESS="192.168.42.1"
  18. DEFAULT_IP_ADDRESS="vpn_ap_rpi"
  19. DEFAULT_WPA2="raspberry_pi_vpn"
  20. DEFAULT_CHANNEL="6"
  21. ETHERNET="enxb827eb9ae5d5"
  22. WIFI="wlxbcf685007b86"
  23. VPN="tun0"
  24.  
  25. # read -p "Enter the IP Address you wish to assign to your RaspTor <${IP_ADDRESS}> :" IP_ADDRESS
  26.  
  27. read -p "Enter your desired WLAN SSID [${DEFAULT_SSID}] :" SSID
  28.  
  29. read -p "Enter your desired WPA2 key [${DEFAULT_WPA2}] :" WPA2
  30.  
  31. read -p "Enter your desired WLAN radio channel [${DEFAULT_CHANNEL}] :" CHANNEL
  32.  
  33. # Set up default variables
  34. IP_ADDRESS=$DEFAULT_IP_ADDRESS
  35. SSID="${SSID:-$DEFAULT_SSID}"
  36. WPA2="${WPA2:-$DEFAULT_WPA2}"
  37. CHANNEL="${CHANNEL:-$DEFAULT_CHANNEL}"
  38.  
  39. # DHCP
  40. /bin/echo "Configuring DHCP.."
  41. cp /etc/dhcp/dhcpd.conf /etc/dhcp/dhcpd.conf.sample
  42. /bin/cat /dev/null > /etc/dhcp/dhcpd.conf
  43. /bin/cat <<dhcp_configuration >> /etc/dhcp/dhcpd.conf
  44. ddns-update-style none;
  45. authoritative;
  46. log-facility local7;
  47.  
  48. subnet 192.168.42.0 netmask 255.255.255.0 {
  49. range 192.168.42.10 192.168.42.50;
  50. option broadcast-address 192.168.42.255;
  51. option routers 192.168.42.1;
  52. default-lease-time 600;
  53. max-lease-time 2592000;
  54. option domain-name "local";
  55. option domain-name-servers 1.1.1.1, 1.0.0.1;
  56. }
  57. dhcp_configuration
  58.  
  59. cp /etc/default/isc-dhcp-server /etc/default/isc-dhcp-server.sample
  60. /bin/cat /dev/null > /etc/default/isc-dhcp-server
  61. /bin/cat <<isc_dhcp_configuration >> /etc/default/isc-dhcp-server
  62. INTERFACES="${WIFI}"
  63. isc_dhcp_configuration
  64.  
  65. /bin/echo "Configuring Interfaces.."
  66.  
  67. cp /etc/network/interfaces /etc/network/interfaces.sample
  68. /bin/cat /dev/null > /etc/network/interfaces
  69. /bin/cat <<interfaces_configuration >> /etc/network/interfaces
  70. auto lo
  71.  
  72. iface lo inet loopback
  73. iface eth0 inet dhcp
  74.  
  75. allow-hotplug ${WIFI}
  76. iface ${WIFI} inet static
  77.   address ${IP_ADDRESS}
  78.   netmask 255.255.255.0
  79.  
  80. up iptables-restore < /etc/iptables.ipv4.nat
  81.  
  82. interfaces_configuration
  83.  
  84. sudo ifconfig ${WIFI} $IP_ADDRESS
  85.  
  86. /bin/echo "Configuring hostapd.."
  87. touch /etc/hostapd/hostapd.conf
  88. cp /etc/hostapd/hostapd.conf /etc/hostapd/hostapd.conf.sample
  89. /bin/cat /dev/null > /etc/hostapd/hostapd.conf
  90. /bin/cat <<hostapd_configuration >> /etc/hostapd/hostapd.conf
  91. interface=${WIFI}
  92. driver=nl80211
  93. ssid=${SSID}
  94. hw_mode=g
  95. channel=${CHANNEL}
  96. macaddr_acl=0
  97. auth_algs=1
  98. ignore_broadcast_ssid=0
  99. wpa=2
  100. wpa_passphrase=${WPA2}
  101. wpa_key_mgmt=WPA-PSK
  102. wpa_pairwise=TKIP
  103. rsn_pairwise=CCMP
  104. hostapd_configuration
  105.  
  106. cp /etc/default/hostapd /etc/default/hostapd.sample
  107. /bin/cat /dev/null > /etc/default/hostapd
  108. /bin/cat <<hostapd_default >> /etc/default/hostapd
  109. DAEMON_CONF="/etc/hostapd/hostapd.conf"
  110. hostapd_default
  111.  
  112. /bin/echo "Configuring NAT and Routing.."
  113. cp /etc/sysctl.conf /etc/sysctl.conf.sample
  114. /bin/cat /dev/null > /etc/sysctl.conf
  115. /bin/cat <<sysctl_configuration >> /etc/sysctl.conf
  116. vm.swappiness=1
  117. vm.min_free_kbytes = 8192
  118. net.ipv4.ip_forward=1
  119. net.ipv4.conf.all.accept_redirects = 0
  120. sysctl_configuration
  121.  
  122. /bin/echo "Set up routing tables.."
  123. iptables -P INPUT ACCEPT
  124. iptables -P FORWARD ACCEPT
  125. iptables -P OUTPUT ACCEPT
  126. iptables -F
  127. iptables -X
  128. iptables -t nat -F
  129. iptables -t nat -X
  130. iptables -t mangle -F
  131. iptables -t mangle -X
  132. iptables -t raw -F
  133. iptables -t raw -X
  134.  
  135. sh -c "echo 1 > /proc/sys/net/ipv4/ip_forward"
  136. iptables -t nat -A POSTROUTING -o ${VPN} -j MASQUERADE
  137. iptables -A FORWARD -o ${WIFI} -m state --state RELATED,ESTABLISHED -j ACCEPT
  138. iptables -A FORWARD -i ${WIFI} -o ${VPN} -j ACCEPT
  139. iptables -A FORWARD -s 192.168.42.0/24 -i ${WIFI} -o ${ETHERNET} -m conntrack --ctstate NEW -j REJECT
  140. iptables -A FORWARD -s 192.168.42.0/24 -i ${WIFI} -o ${VPN} -m conntrack --ctstate NEW -j ACCEPT
  141. sh -c "iptables-save > /etc/iptables.ipv4.nat"
  142.  
  143. /bin/echo "Registering daemons as a service.."
  144. sudo service hostapd start
  145. sudo service isc-dhcp-server start
  146. sudo update-rc.d hostapd enable
  147. sudo update-rc.d isc-dhcp-server enable
  148.  
  149. /bin/echo "Installation complete! Restarting Raspberry Pi.."
  150. sudo shutdown -r now
  151.  
  152.  
  153. exit
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement