Advertisement
Guest User

Tor Trasparent Proxy

a guest
Apr 9th, 2013
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.85 KB | None | 0 0
  1. #!/bin/sh
  2.  
  3. NON_TOR=`ifconfig | grep "inet:" | awk -F: '{print $2}' | awk '{print $1}' | xargs echo`
  4. ID=`id -u debian-tor`
  5. TCP="9040"
  6. DNS="53"
  7. TORRC="/etc/tor/torrc"
  8.  
  9. function stop {
  10.     iptables -F
  11.     iptables -t nat -F
  12.     iptables -t nat -XT
  13.     iptables -P FORWARD ACCEPT
  14.     iptables -P OUTPUT ACCEPT
  15.     iptables -P INPUT ACCEPT
  16.     cp /etc/resolv.conf.orig /etc/resolv.conf
  17.     echo "Trasparent Proxy Stop......"
  18. }
  19.  
  20. function torrc_config {
  21.     echo "Torrc configure for Trasparent Proxy..."
  22. cat << EOF >> $TORRC
  23. VirtualAddrNetwork 10.192.0.0/10
  24. echo "AutomapHostsOnResolve 1
  25. TransPort 9040
  26. DNSPort 53
  27. EOF
  28.     echo "restarting tor..."
  29.     /etc/init.d/tor restart
  30. }
  31.  
  32. function trasparent_proxy {
  33.     cp /etc/resolv.conf /etc/resolv.conf.orig
  34.     echo "nameserver 127.0.0.1" > /etc/resolv.conf
  35.     iptables -t nat -F  
  36.     iptables -t nat -A OUTPUT -p tcp -d 10.192.0.0/10 -j REDIRECT --to-ports $TCP
  37.     iptables -t nat -A OUTPUT -m owner --uid-owner $ID -j RETURN
  38.     iptables -t nat -A OUTPUT -p udp --dport $DNS -j REDIRECT --to-ports $DNS
  39.     for NET in $NON_TOR; do
  40.         iptables -t nat -A OUTPUT -d $NET -j RETURN
  41.     done
  42.     iptables -t nat -A OUTPUT -p tcp --syn -j REDIRECT --to-ports $TCP
  43.     iptables -A OUTPUT -m state --state ESTABLISHED,RELATED -j ACCEPT  
  44.     for NET in $NON_TOR; do
  45.         iptables -A OUTPUT -d $NET -j ACCEPT
  46.     done
  47.     iptables -A OUTPUT -m owner --uid-owner $ID -j ACCEPT
  48.     iptables -A OUTPUT -j REJECT --reject-with icmp-net-prohibited
  49.     echo "Tor Trasparent Proxy start....."
  50. }
  51.  
  52. function help {
  53. cat << EOF
  54. Tor Trasparent Proxy
  55. Usage: sudo ./file <option>
  56. Option:
  57.  -i --install
  58.  -s --stop
  59.  -r --run
  60.  -h --help
  61. EOF
  62. }  
  63.  
  64. args=`getopt -l help,run,stop,install :hrsi $*`
  65.  
  66. for i in $args; do
  67.     case $i in
  68.         -h|--help)
  69.             help
  70.         ;;
  71.         -r|--run)
  72.             trasparent_proxy
  73.         ;;
  74.         -s|--stop)
  75.             stop
  76.         ;;
  77.         -i|--install)
  78.             torrc_config
  79.         ;;
  80.     esac
  81. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement