Advertisement
Guest User

teste

a guest
Mar 24th, 2017
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.13 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. ### BEGIN INIT INFO
  4. # Provides: anonsurf
  5. # Required-Start:
  6. # Required-Stop:
  7. # Should-Start:
  8. # Default-Start:
  9. # Default-Stop:
  10. # Short-Description: Transparent Proxy through TOR.
  11. ### END INIT INFO
  12.  
  13. # AnonSurf is inspired by the homonimous module of PenMode, developed by the "Pirates' Crew" in
  14. # order to make it fully compatible with
  15. # Parrot OS and other debian-based systems, and it is part of
  16. # parrot-anon package.
  17. #
  18. #
  19. # Devs:
  20. # Lorenzo 'EclipseSpark' Faletra <eclipse@frozenbox.org>
  21. # Lisetta 'Sheireen' Ferrero <sheireen@frozenbox.org>
  22. # Francesco 'mibofra'/'Eli Aran'/'SimpleSmibs' Bonanno <mibofra@ircforce.tk> <mibofra@frozenbox.org>
  23. #
  24. #
  25. # anonsurf is free software: you can redistribute it and/or
  26. # modify it under the terms of the GNU General Public License as
  27. # published by the Free Software Foundation, either version 3 of the
  28. # License, or (at your option) any later version.
  29. # You can get a copy of the license at www.gnu.org/licenses
  30. #
  31. # anonsurf is distributed in the hope that it will be
  32. # useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
  33. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  34. # General Public License for more details.
  35. #
  36. # You should have received a copy of the GNU General Public License
  37. # along with Parrot Security OS. If not, see <http://www.gnu.org/licenses/>.
  38.  
  39.  
  40. export BLUE='\033[1;94m'
  41. export GREEN='\033[1;92m'
  42. export RED='\033[1;91m'
  43. export RESETCOLOR='\033[1;00m'
  44.  
  45. # Destinations you don't want routed through Tor
  46. TOR_EXCLUDE="192.168.0.0/16 172.16.0.0/12 10.0.0.0/8"
  47.  
  48. # The UID Tor runs as
  49. # change it if, starting tor, the command 'ps -e | grep tor' returns a different UID
  50. TOR_UID="debian-tor"
  51.  
  52. # Tor's TransPort
  53. TOR_PORT="9040"
  54.  
  55.  
  56. function notify {
  57. if [ -e /usr/bin/notify-send ]; then
  58. /usr/bin/notify-send "AnonSurf" "$1"
  59. fi
  60. }
  61.  
  62. export notify
  63.  
  64.  
  65. function init {
  66. echo -e -n " $GREEN*$BLUE killing dangerous applications"
  67. killall -q chrome dropbox iceweasel skype icedove thunderbird firefox chromium xchat transmission
  68. notify "dangerous applications killed"
  69.  
  70. echo -e -n " $GREEN*$BLUE cleaning some dangerous cache elements"
  71. bleachbit -c adobe_reader.cache chromium.cache chromium.current_session chromium.history elinks.history emesene.cache epiphany.cache firefox.url_history flash.cache flash.cookies google_chrome.cache google_chrome.history links2.history opera.cache opera.search_history opera.url_history &> /dev/null
  72. notify "cache cleaned"
  73. }
  74.  
  75.  
  76.  
  77.  
  78. function starti2p {
  79. echo -e -n " $GREEN*$BLUE starting I2P services"
  80. service tor stop
  81. cp /etc/resolv.conf /etc/resolv.conf.bak
  82. touch /etc/resolv.conf
  83. echo -e 'nameserver 127.0.0.1\nnameserver 199.175.54.136\nnameserver 23.94.123.134' > /etc/resolv.conf
  84. echo -e " $GREEN*$BLUE Modified resolv.conf to use localhost and FrozenDNS"
  85. sudo -u i2psvc i2prouter start
  86. iceweasel http://127.0.0.1:7657/home &
  87. notify "I2P daemon started"
  88. }
  89.  
  90. function stopi2p {
  91. echo -e -n " $GREEN*$BLUE stopping I2P services"
  92. sudo -u i2psvc i2prouter stop
  93. if [ -e /etc/resolv.conf.bak ]; then
  94. rm /etc/resolv.conf
  95. cp /etc/resolv.conf.bak /etc/resolv.conf
  96. fi
  97. notify "I2P daemon stopped"
  98. }
  99.  
  100.  
  101.  
  102. function ip {
  103.  
  104. echo -e "\nMy ip is:\n"
  105. sleep 1
  106. wget -qO- http://frozenbox.org/ip
  107. echo -e "\n\n----------------------------------------------------------------------"
  108. }
  109.  
  110. function iceweasel_tor {
  111. directory="/dev/shm/.mozilla/firefox/profile/a6mpn2rf.default"
  112. profile="profile_for_tor.tar.gz"
  113.  
  114. if [ -d "$directory" ] ; then
  115. echo -e "\n[$CYAN nfo$RESETCOLOR ]$GREEN Please wait ...$RESETCOLOR\n"
  116. notify "Please wait ..."
  117. sleep 0.7
  118. echo -e "\n[$CYAN nfo$RESETCOLOR ]$GREEN The profile was loaded in the ram.$RESETCOLOR\n"
  119. notify "The profile was loaded in the ram."
  120. sleep 0.4
  121. killall -q iceweasel firefox
  122. iceweasel -profile /dev/shm/.mozilla/firefox/profile/a6mpn2rf.default &
  123. exit
  124. else
  125. echo -e "\n[$CYAN nfo$RESETCOLOR ]$GREEN Please wait ...$RESETCOLOR\n"
  126. notify "Please wait ..."
  127. sleep 0.3
  128. cd /opt/anonsurf/
  129. cp $profile /dev/shm/ #> /dev/null
  130. sleep 0.3
  131. cd /dev/shm/
  132. tar xzvf $profile #> /dev/null
  133. sleep 0.3
  134. echo -e "\n[$CYAN nfo$RESETCOLOR ]$GREEN The profile was loaded in the ram.$RESETCOLOR\n"
  135. notify "Starting browser in RAM-only mode"
  136. sleep 0.4
  137. killall -q iceweasel firefox
  138. iceweasel -profile /dev/shm/.mozilla/firefox/profile/a6mpn2rf.default &
  139. exit
  140. fi
  141. }
  142.  
  143.  
  144.  
  145.  
  146.  
  147.  
  148. function start {
  149. # Make sure only root can run this script
  150. if [ $(id -u) -ne 0 ]; then
  151. echo -e -e "\n$GREEN[$RED!$GREEN] $RED R U DRUNK?? This script must be run as root$RESETCOLOR\n" >&2
  152. exit 1
  153. fi
  154.  
  155. # Check defaults for Tor
  156. grep -q -x 'RUN_DAEMON="yes"' /etc/default/tor
  157. if [ $? -ne 0 ]; then
  158. echo -e "\n$GREEN[$RED!$GREEN]$RED Please add the following to your /etc/default/tor and restart service:$RESETCOLOR\n" >&2
  159. echo -e "$BLUE#----------------------------------------------------------------------#$RESETCOLOR"
  160. echo -e 'RUN_DAEMON="yes"'
  161. echo -e "$BLUE#----------------------------------------------------------------------#$RESETCOLOR\n"
  162. exit 1
  163. fi
  164.  
  165. # Check torrc config file
  166. grep -q -x 'VirtualAddrNetwork 10.192.0.0/10' /etc/tor/torrc
  167. if [ $? -ne 0 ]; then
  168. echo -e "\n$RED[!] Please add the following to your /etc/tor/torrc and restart service:$RESETCOLOR\n" >&2
  169. echo -e "$BLUE#----------------------------------------------------------------------#$RESETCOLOR"
  170. echo -e 'VirtualAddrNetwork 10.192.0.0/10'
  171. echo -e 'AutomapHostsOnResolve 1'
  172. echo -e 'TransPort 9040'
  173. echo -e 'SocksPort 9050'
  174. echo -e 'DNSPort 53'
  175. echo -e 'RunAsDaemon 1'
  176. echo -e "$BLUE#----------------------------------------------------------------------#$RESETCOLOR\n"
  177. exit 1
  178. fi
  179. grep -q -x 'AutomapHostsOnResolve 1' /etc/tor/torrc
  180. if [ $? -ne 0 ]; then
  181. echo -e "\n$RED[!] Please add the following to your /etc/tor/torrc and restart service:$RESETCOLOR\n" >&2
  182. echo -e "$BLUE#----------------------------------------------------------------------#$RESETCOLOR"
  183. echo -e 'VirtualAddrNetwork 10.192.0.0/10'
  184. echo -e 'AutomapHostsOnResolve 1'
  185. echo -e 'TransPort 9040'
  186. echo -e 'SocksPort 9050'
  187. echo -e 'DNSPort 53'
  188. echo -e 'RunAsDaemon 1'
  189. echo -e "$BLUE#----------------------------------------------------------------------#$RESETCOLOR\n"
  190. exit 1
  191. fi
  192. grep -q -x 'TransPort 9040' /etc/tor/torrc
  193. if [ $? -ne 0 ]; then
  194. echo -e "\n$RED[!] Please add the following to your /etc/tor/torrc and restart service:$RESETCOLOR\n" >&2
  195. echo -e "$BLUE#----------------------------------------------------------------------#$RESETCOLOR"
  196. echo -e 'VirtualAddrNetwork 10.192.0.0/10'
  197. echo -e 'AutomapHostsOnResolve 1'
  198. echo -e 'TransPort 9040'
  199. echo -e 'SocksPort 9050'
  200. echo -e 'DNSPort 53'
  201. echo -e 'RunAsDaemon 1'
  202. echo -e "$BLUE#----------------------------------------------------------------------#$RESETCOLOR\n"
  203. exit 1
  204. fi
  205. grep -q -x 'SocksPort 9050' /etc/tor/torrc
  206. if [ $? -ne 0 ]; then
  207. echo -e "\n$RED[!] Please add the following to your /etc/tor/torrc and restart service:$RESETCOLOR\n" >&2
  208. echo -e "$BLUE#----------------------------------------------------------------------#$RESETCOLOR"
  209. echo -e 'VirtualAddrNetwork 10.192.0.0/10'
  210. echo -e 'AutomapHostsOnResolve 1'
  211. echo -e 'TransPort 9040'
  212. echo -e 'SocksPort 9050'
  213. echo -e 'DNSPort 53'
  214. echo -e 'RunAsDaemon 1'
  215. echo -e "$BLUE#----------------------------------------------------------------------#$RESETCOLOR\n"
  216. #exit 1
  217. fi
  218. grep -q -x 'DNSPort 53' /etc/tor/torrc
  219. if [ $? -ne 0 ]; then
  220. echo -e "\n$RED[!] Please add the following to your /etc/tor/torrc and restart service:$RESETCOLOR\n" >&2
  221. echo -e "$BLUE#----------------------------------------------------------------------#$RESETCOLOR"
  222. echo -e 'VirtualAddrNetwork 10.192.0.0/10'
  223. echo -e 'AutomapHostsOnResolve 1'
  224. echo -e 'TransPort 9040'
  225. echo -e 'SocksPort 9050'
  226. echo -e 'DNSPort 53'
  227. echo -e 'RunAsDaemon 1'
  228. echo -e "$BLUE#----------------------------------------------------------------------#$RESETCOLOR\n"
  229. exit 1
  230. fi
  231. grep -q -x 'RunAsDaemon 1' /etc/tor/torrc
  232. if [ $? -ne 0 ]; then
  233. echo -e "\n$RED[!] Please add the following to your /etc/tor/torrc and restart service:$RESETCOLOR\n" >&2
  234. echo -e "$BLUE#----------------------------------------------------------------------#$RESETCOLOR"
  235. echo -e 'VirtualAddrNetwork 10.192.0.0/10'
  236. echo -e 'AutomapHostsOnResolve 1'
  237. echo -e 'TransPort 9040'
  238. echo -e 'SocksPort 9050'
  239. echo -e 'DNSPort 53'
  240. echo -e 'RunAsDaemon 1'
  241. echo -e "$BLUE#----------------------------------------------------------------------#$RESETCOLOR\n"
  242. #exit 1
  243. fi
  244.  
  245. echo -e "\n$GREEN[$BLUE i$GREEN ]$BLUE Starting anonymous mode:$RESETCOLOR\n"
  246.  
  247. if [ ! -e /var/run/tor/tor.pid ]; then
  248. echo -e " $RED*$BLUE Tor is not running! $GREEN starting it $BLUE for you\n" >&2
  249. echo -e -n " $GREEN*$BLUE Service "
  250. service resolvconf stop
  251. service dnsmasq stop
  252. service nscd stop
  253. sleep 4
  254. service tor start
  255. sleep 6
  256. fi
  257. if ! [ -f /etc/network/iptables.rules ]; then
  258. iptables-save > /etc/network/iptables.rules
  259. echo -e " $GREEN*$BLUE Saved iptables rules"
  260. fi
  261.  
  262. iptables -F
  263. iptables -t nat -F
  264.  
  265. cp /etc/resolv.conf /etc/resolv.conf.bak
  266. touch /etc/resolv.conf
  267. echo -e 'nameserver 127.0.0.1\nnameserver 199.175.54.136\nnameserver 23.94.123.134' > /etc/resolv.conf
  268. echo -e " $GREEN*$BLUE Modified resolv.conf to use Tor and FrozenDNS"
  269.  
  270. # set iptables nat
  271. iptables -t nat -A OUTPUT -m owner --uid-owner $TOR_UID -j RETURN
  272. iptables -t nat -A OUTPUT -p udp --dport 53 -j REDIRECT --to-ports 53
  273. iptables -t nat -A OUTPUT -p tcp --dport 53 -j REDIRECT --to-ports 53
  274. iptables -t nat -A OUTPUT -p udp -m owner --uid-owner $TOR_UID -m udp --dport 53 -j REDIRECT --to-ports 53
  275.  
  276. #resolve .onion domains mapping 10.192.0.0/10 address space
  277. iptables -t nat -A OUTPUT -p tcp -d 10.192.0.0/10 -j REDIRECT --to-ports 9040
  278. iptables -t nat -A OUTPUT -p udp -d 10.192.0.0/10 -j REDIRECT --to-ports 9040
  279.  
  280. #exclude local addresses
  281. for NET in $TOR_EXCLUDE 127.0.0.0/9 127.128.0.0/10; do
  282. iptables -t nat -A OUTPUT -d $NET -j RETURN
  283. done
  284.  
  285. #redirect all other output through TOR
  286. iptables -t nat -A OUTPUT -p tcp --syn -j REDIRECT --to-ports $TOR_PORT
  287. iptables -t nat -A OUTPUT -p udp -j REDIRECT --to-ports $TOR_PORT
  288. iptables -t nat -A OUTPUT -p icmp -j REDIRECT --to-ports $TOR_PORT
  289.  
  290. #accept already established connections
  291. iptables -A OUTPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
  292.  
  293. #exclude local addresses
  294. for NET in $TOR_EXCLUDE 127.0.0.0/8; do
  295. iptables -A OUTPUT -d $NET -j ACCEPT
  296. done
  297.  
  298. #allow only tor output
  299. iptables -A OUTPUT -m owner --uid-owner $TOR_UID -j ACCEPT
  300. iptables -A OUTPUT -j REJECT
  301.  
  302. echo -e "$GREEN *$BLUE All traffic was redirected throught Tor\n"
  303. echo -e "$GREEN[$BLUE i$GREEN ]$BLUE You are under AnonSurf tunnel$RESETCOLOR\n"
  304. notify "Global Anonymous Proxy Activated"
  305. sleep 4
  306. }
  307.  
  308.  
  309.  
  310.  
  311.  
  312. function stop {
  313. # Make sure only root can run our script
  314. if [ $(id -u) -ne 0 ]; then
  315. echo -e "\n$GREEN[$RED!$GREEN] $RED R U DRUNK?? This script must be run as root$RESETCOLOR\n" >&2
  316. exit 1
  317. fi
  318. echo -e "\n$GREEN[$BLUE i$GREEN ]$BLUE Stopping anonymous mode:$RESETCOLOR\n"
  319.  
  320. iptables -F
  321. iptables -t nat -F
  322. echo -e " $GREEN*$BLUE Deleted all iptables rules"
  323.  
  324. if [ -f /etc/network/iptables.rules ]; then
  325. iptables-restore < /etc/network/iptables.rules
  326. rm /etc/network/iptables.rules
  327. echo -e " $GREEN*$BLUE Iptables rules restored"
  328. fi
  329. echo -e -n " $GREEN*$BLUE Service "
  330. if [ -e /etc/resolv.conf.bak ]; then
  331. rm /etc/resolv.conf
  332. cp /etc/resolv.conf.bak /etc/resolv.conf
  333. fi
  334. service tor stop
  335. sleep 4
  336. service resolvconf start
  337. service nscd start
  338. service dnsmasq start
  339. sleep 1
  340.  
  341. echo -e " $GREEN*$BLUE Anonymous mode stopped\n"
  342. notify "Global Anonymous Proxy Stopped"
  343. sleep 4
  344. }
  345.  
  346. function change {
  347. service tor reload
  348. sleep 4
  349. echo -e " $GREEN*$BLUE Tor daemon reloaded and forced to change nodes\n"
  350. notify "Identity changed"
  351. sleep 1
  352. }
  353.  
  354. function status {
  355. service tor status
  356. }
  357.  
  358. case "$1" in
  359. start)
  360. init
  361. start
  362. ;;
  363. stop)
  364. init
  365. stop
  366. ;;
  367. change)
  368. change
  369. ;;
  370. status)
  371. status
  372. ;;
  373. myip)
  374. ip
  375. ;;
  376. iceweasel_tor)
  377. iceweasel_tor
  378. ;;
  379. starti2p)
  380. starti2p
  381. ;;
  382. stopi2p)
  383. stopi2p
  384. ;;
  385. restart)
  386. $0 stop
  387. sleep 1
  388. $0 start
  389. ;;
  390. *)
  391. echo -e "
  392. Parrot AnonSurf Module (v 1.3.1)
  393. Usage:
  394. $RED┌──[$GREEN$USER$YELLOW@$BLUE`hostname`$RED]─[$GREEN$PWD$RED]
  395. $RED└──╼ \$$GREEN"" anonsurf $RED{$GREEN""start$RED|$GREEN""stop$RED|$GREEN""restart$RED|$GREEN""change$RED""$RED|$GREEN""status$RED""}
  396.  
  397. $RED start$BLUE -$GREEN Start system-wide anonymous
  398. tunneling under TOR proxy through iptables
  399. $RED stop$BLUE -$GREEN Reset original iptables settings
  400. and return to clear navigation
  401. $RED restart$BLUE -$GREEN Combines \"stop\" and \"start\" options
  402. $RED change$BLUE -$GREEN Changes identity restarting TOR
  403. $RED status$BLUE -$GREEN Check if AnonSurf is working properly
  404. ----[ I2P related features ]----
  405. $RED starti2p$BLUE -$GREEN Start i2p services
  406. $RED stopi2p$BLUE -$GREEN Stop i2p services
  407.  
  408. $RESETCOLOR" >&2
  409. exit 1
  410. ;;
  411. esac
  412.  
  413. echo -e $RESETCOLOR
  414. exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement