- Copyright (c) 2005 tyranix
- Distributed under the X11 license
- See doc/LegalStuff for a full text
These scripts perform almost all of the steps involved in creating a chroot in OpenBSD for tor. It now includes all the configuration files you will need.
When a new version of tor is released, I run this script and copy my old /home/chrooted/tor/etc/tor/systrace directory over.
The systrace policies and updated rc.local are included here.
== Cautions ==
Currently tested but still needs more testing. I use these for my own setup. Don't run these on any kind of production system. However, if you have a spare machine around, try it out.
== Notes ==
OpenBSD 3.8 now has a recent version of libevent! So there is no need to compile your own any longer. Watch out for the dsocks package in 3.8 though. It does not include the tor-dns-proxy.py script that I use as a DNS resolver. I had to download it from the upstream location. You may have to modify your systrace policies for python 2.4 as well. It uses libstdc++ now.
Eventually, I would like to turn this script into a perl module. That way the error checking is more robust (or even present).
Also, it would be nice if I could upload my chroot to some website so people can easily download files and compare their configuration with mine.
=== Stage 1: Run as root ===
I hard coded the paths to /home/chrooted/tor on purpose. If this is ever converted into perl, then with the use strict; mode I would add the path as a parameter. Since the shell won't warn you if you have a typo, I try to use hard coded paths as much as possible.
Be sure to change the TOR_BUILD_USER and TOR_BUILD_GROUP to your own user. This is who is building the source. The files themselves will later be owned by _tor or root depending on the file.
tor_stage1_root.sh
# Fail on the first error (non-zero return value)
set -e -x
TOR_BUILD_USER=tyranix
TOR_BUILD_GROUP=tyranix
## This is part one of the install.
##
## Be sure to set these variables below if you want them changed for this
## script
if [ ! "`/usr/bin/id -u`" = "0" ]; then
echo "Error: Must run $0 with root privileges"
exit 1
fi
check_package()
{
if [ ! "$#" = "2" ]; then
echo "Must send \"packagename\" \"return code\""
exit 1
fi
if [ ! "$2" = "0" ]; then
echo "Could not find \"$1\""
echo "Please build the port or install the package"
exit 1
fi
}
echo "Stage 1: Verify presence of pre-requisite programs"
# XXX Change this to use pkg_info -e (now implemented in OpenBSD 3.8).
for package in gnupg gmake privoxy; do
/usr/sbin/pkg_info ${package} >/dev/null 2>&1
check_package "${package}" $?
done
/usr/bin/id _tor >/dev/null 2>&1
if [ "$?" = "0" ]; then
echo "Stage 1: System already has a _tor user"
else
echo "Stage 1: Creating group _tor"
/usr/sbin/groupadd _tor
echo "Stage 1: Creating user _tor"
/usr/sbin/useradd -g _tor -d /nonexistent -c "tor anonymizer" -s /sbin/nologin _tor
fi
echo "Stage 1: Creating directory structure"
/bin/mkdir -p /home/chrooted/tor/dev /home/chrooted/tor/etc \
/home/chrooted/tor/usr/lib /home/chrooted/tor/usr/libexec \
/home/chrooted/tor/var/lib/tor /home/chrooted/tor/var/log/tor
/bin/chmod -R 0700 /home/chrooted
/sbin/chown -R ${TOR_BUILD_USER}:${TOR_BUILD_GROUP} /home/chrooted
echo "Stage 1: Creating virtual filesystem svnd0c for devices"
cd /home/chrooted/tor
/bin/dd if=/dev/zero of=/home/chrooted/tor/devfs bs=1024 count=256
if [ X"`/usr/sbin/vnconfig -l svnd0 | grep 'not in use'`" = "X" ]; then
if [ ! X"`/sbin/mount | grep '^/dev/svnd0c'`" = "X" ]; then
/sbin/umount /dev/svnd0c
fi
/usr/sbin/vnconfig -u /dev/svnd0c
fi
/usr/sbin/vnconfig -c -v /dev/svnd0c /home/chrooted/tor/devfs
/sbin/newfs /dev/svnd0c
/sbin/mount -o softdep /dev/svnd0c /home/chrooted/tor/dev
echo "Stage 1: Adding necessary devices"
cd /home/chrooted/tor/dev
/bin/sh /dev/MAKEDEV random
/bin/sh /dev/MAKEDEV std
/bin/rm console drum klog kmem ksyms mem tty xf86
echo "Stage 1: Done, please run Stage 2-3 next"
=== Stage 2: Run as the user ===
Run this as the user you specified at the top of stage1.
There's really no reason to set this to use static linking. It might go away in a future version.
tor_stage2_user.sh
# Fail on the first non-zero return value
set -e -x
## Stage two which is done by a user account
TOR_VERSION=0.1.1.12-alpha
# XXX Should take static out. Since this is now scripted, there's little
# reason to want static over dynamic.
TOR_LINKING=dynamic # "dynamic" or "static"
if [ "`/usr/bin/id -u`" = "0" ]; then
echo "Error: Must run $0 WITHOUT root privileges"
exit 1
fi
echo "Stage 2: Creating temporary build directory"
TMPDIR=`mktemp -d -t tor_install.XXXXXXXXXX`;
cd ${TMPDIR}
echo "Stage 2: Downloading tor ${TOR_VERSION}"
/usr/local/bin/wget http://tor.eff.org/dist/tor-${TOR_VERSION}.tar.gz http://tor.eff.org/dist/tor-${TOR_VERSION}.tar.gz.asc
echo "Stage 2: Checking for arma's GPG key"
/usr/local/bin/gpg --list-keys 0x28988BF5 >/dev/null 2>&1
if [ ! "$?" = "0" ]; then
echo "Error: Arma's key not found; cannot verify download"
echo "Please run /usr/local/bin/gpg --keyserver subkeys.pgp.net --search-keys 0x28988BF5"
exit 1
fi
echo "Stage 2: Verifying tor ${TOR_VERSION}"
/usr/local/bin/gpg --verify tor-${TOR_VERSION}.tar.gz.asc tor-${TOR_VERSION}.tar.gz
echo "Stage 2: Unpacking tor ${TOR_VERSION} source"
/bin/tar -zxvf tor-${TOR_VERSION}.tar.gz
cd tor-${TOR_VERSION}
echo "Stage 2: Configuring tor ${TOR_VERSION}"
if [ "${TOR_LINKING}" = "dynamic" ]; then
./configure --prefix=/
elif [ "${TOR_LINKING}" = "static" ]; then
env CFLAGS=-static ./configure --prefix=/
else
echo "Invalid linking mode: either \"static\" or \"dynamic\""
exit 1
fi
OLDDIR=`pwd`
echo "Stage 2: Building, but not installing, tor ${TOR_VERSION}"
/usr/local/bin/gmake
cd ${TMPDIR}
if [ "${TOR_LINKING}" = "dynamic" ]; then
echo "Stage 2: Copying dynamic libraries to the chrooted area"
# Get the list of libraries we need to copy
for lib in `/usr/bin/ldd tor-${TOR_VERSION}/src/or/tor | /usr/bin/egrep '^[[:space:]]+[0-9a-f]{8}[[:space:]]+[0-9a-f]{8}' | /usr/bin/sed -e 's/.* //' | /usr/bin/grep '^/usr'`; do
echo "Copying library \"${lib}\""
/bin/cp ${lib} /home/chrooted/tor/${lib}
done
fi
cd ${OLDDIR}
echo "Stage 2: Installing tor ${TOR_VERSION} into the chrooted area"
/usr/local/bin/gmake DESTDIR=/home/chrooted/tor install
echo "Stage 2: Creating a partial copy of /etc/passwd related files for _tor"
cd /home/chrooted/tor/etc
/usr/bin/grep '^_tor:' /etc/passwd | /usr/bin/sed -e 's/:tor/::0:0:tor/' > /home/chrooted/tor/etc/newpasswd
/usr/sbin/pwd_mkdb -p -d /home/chrooted/tor/etc newpasswd
echo "Stage 2: Copying over the _tor group into the chrooted area group"
/usr/bin/grep '^_tor:' /etc/group > /home/chrooted/tor/etc/group
# Note: With 0.1.1.12, you must specify a log file location.
echo "Stage 2: Creating a Tor config file for the chroot"
/bin/cp tor/torrc.sample tor/torrc
cat <<EOF>> tor/torrc
User _tor
Group _tor
Log notice file /var/log/tor/notices.log
RunAsDaemon 1
ClientOnly 1
DataDirectory /var/lib/tor
EOF
echo "Stage 2: Copying over configuration files to the chrooted area "
echo " (except resolv.conf)"
for file in hosts localtime; do
/bin/cp -H /etc/${file} /home/chrooted/tor/etc/
done
echo "Stage 2: Assuming you use a Tor DNS (such as dsocks' tor-dns-proxy.py)"
echo "Stage 2: If you do not: 'cp /etc/resolv.conf /home/chrooted/tor/etc/'"
echo "lookup file bind" > /home/chrooted/tor/etc/resolv.conf
echo "nameserver 127.0.0.1" >> /home/chrooted/tor/etc/resolv.conf
/bin/chmod 0744 /home/chrooted/tor/etc/resolv.conf /home/chrooted/tor/etc/hosts
echo "Stage 2: Done, please run stage 3"
=== Stage 3: Run as root ===
Final stage. This sets up all of the permissions.
tor_stage3_root.sh
set -e -x
if [ ! "`/usr/bin/id -u`" = "0" ]; then
echo "Error: Must run $0 with root privileges"
exit 1
fi
echo "Stage 3: Fixing chroot area permissions"
cd /home/chrooted/tor
/sbin/chown -R root:wheel /home/chrooted/tor
/sbin/chown root:_shadow /home/chrooted/tor/etc/spwd.db
echo "Stage 3: Fixing directory permissions"
for dir in dev etc var var/lib var/log; do
/bin/chmod 0755 /home/chrooted/tor/${dir}
done
# Only do this step for dynamic linked
if [ "`/usr/bin/ldd bin/tor | grep 'not a dynamic executable'`" = "" ]; then
echo "Stage 3: Fixing dynamic link library permissions"
/bin/chmod -R 0755 /home/chrooted/tor/usr
/bin/chmod 0444 /home/chrooted/tor/usr/lib/*
/bin/chmod 0555 /home/chrooted/tor/usr/libexec/*
fi
# Don't allow anyone but root into "/home/chrooted"
echo "Stage 3: Fixing chroot area top level permissions"
/sbin/chown root:wheel /home/chrooted
/bin/chmod 0700 /home/chrooted
echo "Stage 3: Letting _tor into the Tor chroot area"
/bin/chmod 0755 /home/chrooted/tor
/bin/chmod -R 0755 /home/chrooted/tor/etc
echo "Stage 3: Fixing permissions for a few files/directories for _tor"
/sbin/chown -R _tor:_tor /home/chrooted/tor/var/log/tor /home/chrooted/tor/var/lib/tor
/usr/bin/touch /home/chrooted/tor/etc/tor/dirservers
/sbin/chown _tor:_tor /home/chrooted/tor/etc/tor/dirservers
echo "Stage 3: Done"
echo "Setup complete!"
echo "Don't forget to modify the privoxy configuration"
echo " and add systrace policies to the chroot"
Configuration files
The systrace policy files should have leading tabs instead of spaces!
==== /etc/rc.local ====
/etc/rc.local
# $OpenBSD: rc.local,v 1.38 2005/03/29 21:41:59 uwe Exp $
# site-specific startup actions, daemons, and other things which
# can be done AFTER your system goes into securemode. For actions
# which should be done BEFORE your system has gone into securemode
# please see /etc/rc.securelevel
# site-specific startup actions, daemons which can be run
# Add your local startup actions to this file
echo -n 'starting local daemons:'
if [ -x /usr/local/sbin/cfsd ]; then
if ps auxc | grep -q '^ *root .* mountd$'; then
echo -n ' cfsd'; /usr/local/sbin/cfsd >/dev/null 2>&1
mount -o port=3049,nfsv2,intr localhost:/null /crypt
else
echo -n ' cfsd (failed, no mountd running)'
fi
fi
#if [ -x /usr/local/sbin/snmpd ]; then
# echo -n ' snmpd'; /usr/local/sbin/snmpd
#fi
echo '.'
# Netatalk stuff
#if [ -f /etc/netatalk/rc.atalk ]; then
# . /etc/netatalk/rc.atalk
#fi
## Tor related startup
# Mount for tor. This should NOT use fsck but there needs to be a better way
# to make sure we unmount it. Will /etc/rc.shutdown be called after tor is
# killed?
if [ -f /home/chrooted/tor/devfs ]; then
echo -n ' tor /dev';
/usr/sbin/vnconfig -c -v /dev/svnd0c /home/chrooted/tor/devfs
/sbin/fsck -y /dev/svnd0c
/sbin/mount -o softdep /dev/svnd0c /home/chrooted/tor/dev
fi
# Tor client
if [ -x /home/chrooted/tor/bin/tor ]; then
echo -n ' tor';
/bin/systrace -a -d /home/chrooted/tor/etc/tor/systrace /usr/sbin/chroot -u _tor -g _tor /home/chrooted/tor /bin/tor -f /etc/tor/torrc
fi
# Tor-ized web proxy
if [ -x /usr/local/sbin/privoxy ]; then
echo -n ' tor privoxy';
/bin/systrace -a -c 516:516 -d /home/chrooted/tor/etc/tor/systrace /usr/local/sbin/privoxy --user _privoxy._privoxy /etc/privoxy/config
fi
# Tor-ized DNS to prevent DNS leaks. Runs as 'nobody' except for an escalated
# bind to port 53 by systrace.
# XXX Should also verify that /etc/resolv.conf only contains nameserver entries
# XXX for 127.0.0.1 but may include 'lookup file bind'
if [ -f /opt/dsocks-1.3/tor-dns-proxy.py ]; then
echo -n ' tor DNS':
/bin/systrace -a -c 32767:32767 -d /home/chrooted/tor/etc/tor/systrace /usr/local/bin/python2.4 /opt/dsocks-1.3/tor-dns-proxy.py >/dev/null 2>&1 &
fi
==== /home/chrooted/tor/etc/tor/systrace/bin_tor ====
/home/chrooted/tor/etc/tor/systrace/bin_tor
Policy: /bin/tor, Emulation: native
native-__sysctl: permit
native-kqueue: permit
native-kevent: permit
native-setitimer: permit
# Memory
native-mprotect: permit
native-mmap: permit
native-mquery: permit
# Files
native-close: permit
native-dup2: permit
native-fstat: permit
native-fcntl: permit
native-getdirentries: permit
native-lseek: permit
native-read: permit
native-ioctl: permit
native-write: permit
native-pread: permit
native-fstatfs: permit
# File reads
native-fsread: filename match "/<non-existent filename>: *" then deny
native-fsread: filename eq "/dev/crypto" then permit
native-fsread: filename eq "/dev/null" then permit
native-fsread: filename eq "/dev/srandom" then permit
native-fsread: filename eq "/etc/group" then permit
native-fsread: filename eq "/etc/pwd.db" then permit
native-fsread: filename eq "/etc/spwd.db" then permit
native-fsread: filename eq "/etc/tor/torrc" then permit
native-fsread: filename eq "/etc/malloc.conf" then permit
native-fsread: filename eq "/etc/localtime" then permit
native-fsread: filename eq "/usr/lib" then permit
native-fsread: filename match "/usr/lib/libc.so*" then permit
native-fsread: filename match "/usr/lib/libcrypto.so*" then permit
native-fsread: filename match "/usr/lib/libssl.so*" then permit
native-fsread: filename match "/usr/lib/libz.so*" then permit
native-fsread: filename match "/usr/lib/libpthread.so*" then permit
native-fsread: filename match "/usr/local/opt/lib/libevent.so*" then permit
native-fsread: filename match "/usr/lib/libevent.so*" then permit
native-fsread: filename eq "/usr/share/nls/C/libc.cat" then permit
native-fsread: filename match "/usr/share/zoneinfo/*" then permit
native-fsread: filename match "/var/lib/tor" then permit
native-fsread: filename match "/var/lib/tor/*" then permit
native-fsread: filename match "/var/log/tor" then permit
native-fsread: filename match "/var/log/tor/*" then permit
# Memory
native-munmap: permit
native-break: permit
native-gettimeofday: permit
# User ID and group ID. Change these as needed.
native-setgid: gid eq "1001" then permit
native-setuid: uid eq "1001" and uname eq "_tor" then permit
native-getuid: permit
# Resource limits
native-getrlimit: permit
native-setrlimit: permit
native-chdir: filename eq "/var/lib/tor" then permit
# Process
native-exit: permit
native-fork: permit
native-pipe: permit
# Permission bits
native-getpid: permit
native-geteuid: permit
native-issetugid: permit
native-setsid: permit
# Signals
native-sigaction: permit
native-sigprocmask: permit
native-sigreturn: permit
# File writes
native-fswrite: filename match "/<non-existent filename>: *" then deny
native-fswrite: filename eq "/dev/crypto" then permit
native-fswrite: filename eq "/dev/null" then permit
native-fswrite: filename match "/var/log/tor/*" then permit
native-fswrite: filename match "/var/lib/tor/*" then permit
native-rename: filename match "/var/lib/tor/cached-directory*" and filename[1] match "/var/lib/tor/cached-directory*" then permit
native-rename: filename match "/var/lib/tor/cached-status/*" and filename[1] match "/var/lib/tor/cached-status/*" then permit
native-rename: filename match "/var/lib/tor/stat*" and filename[1] match "/var/lib/tor/stat*" then permit
native-rename: filename match "/var/lib/tor/cach*" and filename[1] match "/var/lib/tor/cach*" then permit
# Networking
native-bind: sockaddr eq "inet-[127.0.0.1]:9050" then permit
native-socket: sockdom eq "AF_INET" and socktype eq "SOCK_STREAM" then permit
native-socket: sockdom eq "AF_INET" and socktype eq "SOCK_DGRAM" then permit
native-setsockopt: permit
native-listen: permit
native-poll: permit
native-getsockopt: permit
native-getsockname: permit
native-accept: permit
native-recvfrom: permit
native-sendto: true then permit
# Without socketpair, you cannot use hidden services.
native-socketpair: permit
# List of ports to connect to. These are needed for the server list and potentially
# using a tor server.
native-connect: sockaddr match "inet-*:80" then permit
native-connect: sockaddr match "inet-*:443" then permit
# Typically, tor servers are in the range of 8,000 - 10,000. But there's no harm
# in letting them connect to any unpriv port.
# Match ports 1024 through 1999
native-connect: sockaddr re "inet-.*:102[4-9]$" then permit
native-connect: sockaddr re "inet-.*:10[3-9][0-9]$" then permit
native-connect: sockaddr re "inet-.*:1[1-9][0-9]{2}$" then permit
# Match 2000 - 9999
native-connect: sockaddr re "inet-.*:[2-9][0-9]{3}$" then permit
# Match ports 10000 - 65535
native-connect: sockaddr re "inet-.*:[1-9][0-9]{4}$" then permit
==== /home/chrooted/tor/etc/tor/systrace/usr_local_bin_python2.4 ====
This systrace policy is configured for python to only execute dsocks' python script.
/home/chrooted/tor/etc/tor/systrace/usr_local_bin_python2.4
Policy: /usr/local/bin/python2.4, Emulation: native
native-issetugid: permit
native-__sysctl: permit
# Memory
native-mprotect: permit
native-mmap: permit
native-mquery: permit
native-munmap: permit
# Denied
native-fsread: filename eq "/" then deny
native-fsread: filename eq "/etc/." then deny
native-fsread: filename eq "/home" then deny
# System files
native-fsread: filename match "/<non-existent filename>: *" then permit
native-fsread: filename eq "/etc/malloc.conf" then permit
native-fsread: filename match "/usr/lib/libc.so.*" then permit
native-fsread: filename match "/usr/lib/libm.so.*" then permit
native-fsread: filename match "/usr/lib/libpthread.so.*" then permit
native-fsread: filename match "/usr/lib/libstdc++.so.*" then permit
native-fsread: filename match "/usr/lib/libutil.so.*" then permit
native-fsread: filename match "/usr/lib/libssl.so.*" then permit
native-fsread: filename match "/usr/lib/libcrypto.so.*" then permit
native-fsread: filename eq "/usr/local/lib" then permit
native-fsread: filename eq "/usr/local/bin/python" then permit
native-fsread: filename match "/usr/local/bin/python2.?" then permit
native-fsread: filename match "/usr/local/lib/python2.?" then permit
native-fsread: filename match "/usr/local/lib/python2?.zip" then permit
native-fsread: filename re "/usr/local/lib/python2\.[0-9]+/.*" then permit
native-fsread: filename eq "/usr/local/lib/site-python" then permit
native-fsread: filename re "/usr/local/lib/site-python/.*" then permit
native-fsread: filename match "/usr/share/zoneinfo/*/*" then permit
native-fsread: filename eq "/usr/share/nls/C/libc.cat" then permit
native-fsread: filename eq "/var/run/ld.so.hints" then permit
native-fsread: filename eq "/opt/." then permit
# User files
native-fsread: filename eq "/root/.systrace/." then deny
native-fsread: filename match "/opt/dsocks-1.?/." then permit
native-fsread: filename re "/opt/dsocks-1\.[0-9]+" then permit
native-fsread: filename re "/opt/dsocks-1\.[0-9]+/.*" then permit
# File system
native-chdir: filename match "/opt/dsocks-1.?" then permit
native-fchdir: permit
native-fcntl: permit
native-fstat: permit
native-fstatfs: permit
native-getdirentries: permit
# Read/write
native-close: permit
native-ioctl: permit
native-lseek: permit
native-poll: permit
native-read: permit
native-write: permit
# Signals
native-sigaction: permit
native-sigprocmask: permit
native-sigreturn: permit
# User information
native-getpid: permit
# Process control
native-exit: permit
native-pipe: permit
# Time
native-clock_gettime: permit
native-gettimeofday: permit
native-setitimer: permit
# Resources
native-getrlimit: permit
native-break: permit
# Networking
native-sendto: permit
native-bind: sockaddr eq "inet-[127.0.0.1]:53" then permit as root
native-connect: sockaddr eq "inet-[127.0.0.1]:9050" then permit
native-recvfrom: permit
native-socket: sockdom eq "AF_INET" and socktype eq "SOCK_STREAM" then permit
native-socket: sockdom eq "AF_INET" and socktype eq "SOCK_DGRAM" then permit
native-socket: sockdom eq "AF_UNIX" and socktype eq "SOCK_DGRAM" then permit
native-socket: sockdom eq "AF_UNIX" and socktype eq "SOCK_STREAM" then permit
native-setgid: gid eq "32767" then permit
native-setuid: uid eq "32767" and uname eq "nobody" then permit
==== /home/chrooted/tor/etc/tor/systrace/usr_local_sbin_privoxy ====
/home/chrooted/tor/etc/tor/systrace/usr_local_sbin_privoxy
Policy: /usr/local/sbin/privoxy, Emulation: native
native-issetugid: permit
native-mprotect: permit
native-mmap: permit
native-__sysctl: permit
native-fsread: filename eq "/var/run/ld.so.hints" then permit
native-fstat: permit
native-close: permit
native-read: permit
native-mquery: permit
native-fsread: filename eq "/etc/hosts" then permit
native-fsread: filename eq "/etc/group" then permit
native-fsread: filename eq "/etc/malloc.conf" then permit
native-fsread: filename eq "/etc/pwd.db" then permit
native-fsread: filename eq "/etc/resolv.conf" then permit
native-fsread: filename eq "/etc/spwd.db" then permit
native-fsread: filename re "/etc/privoxy/.*" then permit
native-fsread: filename re "/usr/share/zoneinfo/.*" then permit
native-fsread: filename eq "/usr/share/nls/C/libc.cat" then permit
native-fsread: filename match "/usr/local/lib/libpcreposix.so*" then permit
native-fsread: filename match "/usr/lib/libpthread.so*" then permit
native-fsread: filename match "/usr/local/lib/libpcre.so*" then permit
native-fsread: filename match "/usr/lib/libc.so*" then permit
native-munmap: permit
native-sigprocmask: permit
native-getpid: permit
native-pipe: permit
native-fcntl: permit
native-break: permit
native-gettimeofday: permit
native-sigaction: permit
native-getrlimit: permit
native-pread: permit
native-fork: permit
native-poll: permit
native-setsid: permit
native-chdir: filename eq "/" then permit
native-setgid: gid eq "516" then permit
native-setuid: uid eq "516" and uname eq "_privoxy" then permit
native-write: permit
native-fswrite: filename re "/var/log/privoxy/.*" then permit
native-lseek: permit
native-socket: sockdom eq "AF_INET" and socktype eq "SOCK_STREAM" then permit
native-socket: sockdom eq "AF_INET" and socktype eq "SOCK_DGRAM" then permit
native-socket: sockdom eq "AF_UNIX" and socktype eq "SOCK_DGRAM" then permit
native-setsockopt: permit
native-bind: sockaddr eq "inet-[127.0.0.1]:8118" then permit
native-connect: sockaddr eq "inet-[127.0.0.1]:9050" then permit
# For DNS
native-connect: sockaddr eq "inet-[127.0.0.1]:53" then permit
native-sendto: permit
native-recvfrom: permit
native-listen: permit
native-accept: permit
native-wait4: permit
native-setitimer: permit
native-exit: permit
native-getsockname: permit
native-clock_gettime: permit
native-sigreturn: permit
==== /home/chrooted/tor/etc/tor/systrace/usr_sbin_chroot ====
/home/chrooted/tor/etc/tor/systrace/usr_sbin_chroot
Policy: /usr/sbin/chroot, Emulation: native
native-__sysctl: permit
native-issetugid: permit
native-mmap: permit
native-break: permit
native-mprotect: permit
native-fsread: filename eq "/etc/group" then permit
native-fsread: filename eq "/etc/malloc.conf" then permit
native-fsread: filename eq "/etc/spwd.db" then permit
native-fcntl: permit
native-fstat: permit
native-read: permit
native-pread: permit
native-close: permit
native-setgid: gid eq "1001" then permit
native-setgroups: permit
native-chroot: filename match "/home/chrooted/tor*" then permit
native-chdir: filename eq "/" then permit
native-getsid: permit
native-getpid: permit
native-setsid: permit
native-setuid: uid eq "1001" and uname eq "_tor" then permit
native-execve: filename eq "/bin/tor" and argv eq "/bin/tor -f /etc/tor/torrc" then permit
==== /etc/privoxy/config ====
Changes: disable cookie file, pass traffic to Tor, and disable logging every URL request (unfortunately that's the default).
/etc/privoxy/config {{{
Sample Configuration File for Privoxy v3.0.x
http://privoxy.org
Copyright (C) 2001-2004 Privoxy Developers$Id: config,v 1.39.2.13 2004/01/29 12:56:03 oes Exp $
####################################################################
Table of Contents
I. INTRODUCTION
II. FORMAT OF THE CONFIGURATION FILE
1. CONFIGURATION AND LOG FILE LOCATIONS
2. LOCAL SET-UP DOCUMENTATION
3. DEBUGGING
4. ACCESS CONTROL AND SECURITY
5. FORWARDING
6. WINDOWS GUI OPTIONS
####################################################################
I. INTRODUCTION
===============
This file holds the Privoxy configuration. If you modify this file,
you will need to send a couple of requests to the proxy before any
changes take effect.
When starting Privoxy on Unix systems, give the name of this file as
an argument. On Windows systems, Privoxy will look for this file
with the name 'config.txt' in the same directory where Privoxy
is installed.
II. FORMAT OF THE CONFIGURATION FILE
====================================
Configuration lines consist of an initial keyword followed by a
list of values, all separated by whitespace (any number of spaces
or tabs). For example,
actionsfile default.action
Indicates that the actionsfile is named 'default.action'.
The '#' indicates a comment. Any part of a line following a '#'
is ignored, except if the '#' is preceded by a ''.
Thus, by placing a # at the start of an existing configuration line,
you can make it a comment and it will be treated as if it weren't
there. This is called "commenting out" an option and can be useful.
Note that commenting out and option and leaving it at its default
are two completely different things! Most options behave very
differently when unset. See the the "Effect if unset" explanation
in each option's description for details.
Long lines can be continued on the next line by using a `' as the
last character.
1. CONFIGURATION AND LOG FILE LOCATIONS
=======================================
Privoxy can (and normally does) use a number of other files for
additional configuration, help and logging. This section of the
configuration file tells Privoxy where to find those other files.
The user running Privoxy, must have read permission for all
configuration files, and write permission to any files that would
be modified, such as log files and actions files.
1.1. confdir
============
Specifies:
The directory where the other configuration files are located
Type of value:
Path name
Default value:
/etc/privoxy (Unix) or Privoxy installation dir (Windows)
Effect if unset:
Mandatory
Notes:
No trailing "/", please
When development goes modular and multi-user, the blocker,
filter, and per-user config will be stored in subdirectories of
"confdir". For now, the configuration directory structure is
flat, except for confdir/templates, where the HTML templates
for CGI output reside (e.g. Privoxy's 404 error page).
confdir /etc/privoxy
1.2. logdir
===========
Specifies:
The directory where all logging takes place (i.e. where logfile
and jarfile are located)
Type of value:
Path name
Default value:
/var/log/privoxy (Unix) or Privoxy installation dir (Windows)
Effect if unset:
Mandatory
Notes:
No trailing "/", please
logdir /var/log/privoxy
1.3. actionsfile
================
Specifies:
The actions file(s) to use
Type of value:
File name, relative to confdir, without the .action suffix
Default values:
standard # Internal purposes, no editing recommended
default # Main actions file
user # User customizations
Effect if unset:
No actions are taken at all. Simple neutral proxying.
Notes:
Multiple actionsfile lines are permitted, and are in fact
recommended!
The default values include standard.action, which is used
for internal purposes and should be loaded, default.action,
which is the "main" actions file maintained by the developers,
and user.action, where you can make your personal additions.
Actions files are where all the per site and per URL
configuration is done for ad blocking, cookie management,
privacy considerations, etc. There is no point in using Privoxy
without at least one actions file.
actionsfile standard # Internal purpose, recommended actionsfile default # Main actions file actionsfile user # User customizations
1.4. filterfile
===============
Specifies:
The filter file to use
Type of value:
File name, relative to confdir
Default value:
default.filter (Unix) or default.filter.txt (Windows)
Effect if unset:
No textual content filtering takes place, i.e. all +filter{name}
actions in the actions files are turned neutral.
Notes:
The filter file contains content modification rules that use
regular expressions. These rules permit powerful changes on the
content of Web pages, e.g., you could disable your favorite
JavaScript annoyances, re-write the actual displayed text,
or just have some fun replacing "Microsoft" with "MicroSuck"
wherever it appears on a Web page.
The +filter{name} actions rely on the relevant filter (name)
to be defined in the filter file!
A pre-defined filter file called default.filter that contains
a bunch of handy filters for common problems is included in the
distribution. See the section on the filter action for a list.
filterfile default.filter
1.5. logfile
============
Specifies:
The log file to use
Type of value:
File name, relative to logdir
Default value:
logfile (Unix) or privoxy.log (Windows)
Effect if unset:
No log file is used, all log messages go to the console (STDERR).
Notes:
The windows version will additionally log to the console.
The logfile is where all logging and error messages are
written. The level of detail and number of messages are set with
the debug option (see below). The logfile can be useful for
tracking down a problem with Privoxy (e.g., it's not blocking
an ad you think it should block) but in most cases you probably
will never look at it.
Your logfile will grow indefinitely, and you will probably
want to periodically remove it. On Unix systems, you can do
this with a cron job (see "man cron"). For Red Hat, a logrotate
script has been included.
On SuSE Linux systems, you can place a line like
"/var/log/privoxy.* +1024k 644 nobody.nogroup" in /etc/logfiles,
with the effect that cron.daily will automatically archive,
gzip, and empty the log, when it exceeds 1M size.
Any log files must be writable by whatever user Privoxy is
being run as (default on UNIX, user id is "privoxy").
logfile logfile
1.6. jarfile
============
Specifies:
The file to store intercepted cookies in
Type of value:
File name, relative to logdir
Default value:
jarfile (Unix) or privoxy.jar (Windows)
Effect if unset:
Intercepted cookies are not stored at all.
Notes:
The jarfile may grow to ridiculous sizes over time.
#jarfile jarfile
1.7. trustfile
==============
Specifies:
The trust file to use
Type of value:
File name, relative to confdir
Default value:
Unset (commented out). When activated: trust (Unix) or trust.txt
(Windows)
Effect if unset:
The entire trust mechanism is turned off.
Notes:
The trust mechanism is an experimental feature for building
white-lists and should be used with care. It is NOT recommended
for the casual user.
If you specify a trust file, Privoxy will only allow access to
sites that are specified in the trustfile. Sites can be listed
in one of two ways:
Prepending a ~ character limits access to this site only (and
www.example.com.
any sub-paths within this site), e.g. ~Or, you can designate sites as trusted referrers, by prepending
the name with a + character. The effect is that access to
untrusted sites will be granted -- but only if a link from this
trusted referrer was used. The link target will then be added
to the "trustfile" so that future, direct accesses will be
granted. Sites added via this mechanism do not become trusted
referrers themselves (i.e. they are added with a ~ designation).
If you use the + operator in the trust file, it may grow
considerably over time.
It is recommended that Privoxy be compiled with the
--disable-force, --disable-toggle and --disable-editor options,
if this feature is to be used.
Possible applications include limiting Internet access for
children.
#trustfile trust
2. LOCAL SET-UP DOCUMENTATION
=============================
If you intend to operate Privoxy for more users than just yourself,
it might be a good idea to let them know how to reach you, what
you block and why you do that, your policies, etc.
2.1. user-manual
================
Specifies:
Location of the Privoxy User Manual.
Type of value:
A fully qualified URI
Default value:
Unset
Effect if unset:
http://www.privoxy.org/version/user-manual/ will be used,
where version is the Privoxy version.
Notes:
The User Manual URI is used for help links from some of the
internal CGI pages. The manual itself is normally packaged
with the binary distributions, so you probably want to set this
to a locally installed copy. For multi-user setups, you could
provide a copy on a local webserver for all your users and use
the corresponding URL here.
Examples:
Unix, in local filesystem:
file:///usr/share/doc/privoxy-3.0.1/user-manual/index.html
user-manualWindows, in local filesystem, must use forward slash notation,
%0.1.2.20 to denote spaces in path names:
andfile:///c:/some%20dir/privoxy/user-manual/index.html
user-manualWindows, UNC notation (forward slashes required again):
file://///some-server/some-path/privoxy/user-manual/index.html
user-manualAny platform, on local webserver (called "local-webserver"):
http://local-webserver/privoxy-user-manual/
user-manualWARNING!!!
If set, this option should be the first option in the config
file, because it is used while the config file is being read.
#user-manual http://www.privoxy.org/user-manual/
2.2. trust-info-url
===================
Specifies:
A URL to be displayed in the error page that users will see if
access to an untrusted page is denied.
Type of value:
URL
Default value:
Two example URL are provided
Effect if unset:
No links are displayed on the "untrusted" error page.
Notes:
The value of this option only matters if the experimental trust
mechanism has been activated. (See trustfile above.)
If you use the trust mechanism, it is a good idea to write
up some on-line documentation about your trust policy and to
specify the URL(s) here. Use multiple times for multiple URLs.
The URL(s) should be added to the trustfile as well, so users
don't end up locked out from the information on why they were
locked out in the first place!
#trust-info-url http://www.example.com/why_we_block.html #trust-info-url http://www.example.com/what_we_allow.html
2.3. admin-address
==================
Specifies:
An email address to reach the proxy administrator.
Type of value:
Email address
Default value:
Unset
Effect if unset:
No email address is displayed on error pages and the CGI user
interface.
Notes:
If both admin-address and proxy-info-url are unset, the whole
"Local Privoxy Support" box on all generated pages will not
be shown.
#admin-address privoxy-admin@example.com
2.4. proxy-info-url
===================
Specifies:
A URL to documentation about the local Privoxy setup,
configuration or policies.
Type of value:
URL
Default value:
Unset
Effect if unset:
No link to local documentation is displayed on error pages and
the CGI user interface.
Notes:
If both admin-address and proxy-info-url are unset, the whole
"Local Privoxy Support" box on all generated pages will not
be shown.
This URL shouldn't be blocked ;-)
#proxy-info-url http://www.example.com/proxy-service.html
3. DEBUGGING
============
These options are mainly useful when tracing a problem. Note that
you might also want to invoke Privoxy with the --no-daemon command
line option when debugging.
3.1. debug
==========
Specifies:
Key values that determine what information gets logged to
the logfile.
Type of value:
Integer values
Default value:
12289 (i.e.: URLs plus informational and warning messages)
Effect if unset:
Nothing gets logged.
Notes:
The available debug levels are:
debug 1 # show each GET/POST/CONNECT request
debug 2 # show each connection status
debug 4 # show I/O status
debug 8 # show header parsing
debug 16 # log all data into the logfile
debug 32 # debug force feature
debug 64 # debug regular expression filter
debug 128 # debug fast redirects
debug 256 # debug GIF de-animation
debug 512 # Common Log Format
debug 1024 # debug kill pop-ups
debug 2048 # CGI user interface
debug 4096 # Startup banner and warnings.
debug 8192 # Non-fatal errors
To select multiple debug levels, you can either add them or
use multiple debug lines.
A debug level of 1 is informative because it will show you each
request as it happens. 1, 4096 and 8192 are highly recommended
so that you will notice when things go wrong. The other levels
are probably only of interest if you are hunting down a specific
problem. They can produce a hell of an output (especially 16).
The reporting of fatal errors (i.e. ones which crash Privoxy)
is always on and cannot be disabled.
If you want to use CLF (Common Log Format), you should set
"debug 512" ONLY and not enable anything else.
#debug 1 # show each GET/POST/CONNECT request debug 4096 # Startup banner and warnings debug 8192 # Errors - we highly recommended enabling this
3.2. single-threaded
====================
Specifies:
Whether to run only one server thread
Type of value:
None
Default value:
Unset
Effect if unset:
Multi-threaded (or, where unavailable: forked) operation,
i.e. the ability to serve multiple requests simultaneously.
Notes:
This option is only there for debug purposes and you should
never need to use it. It will drastically reduce performance.
#single-threaded
4. ACCESS CONTROL AND SECURITY
==============================
This section of the config file controls the security-relevant
aspects of Privoxy's configuration.
4.1. listen-address
===================
Specifies:
The IP address and TCP port on which Privoxy will listen for
client requests.
Type of value:
[IP-Address]:Port
Default value:
127.0.0.1:8118
Effect if unset:
Bind to 127.0.0.1 (localhost), port 8118. This is suitable and
recommended for home users who run Privoxy on the same machine
as their browser.
Notes:
You will need to configure your browser(s) to this proxy address
and port.
If you already have another service running on port 8118, or
if you want to serve requests from other machines (e.g. on your
local network) as well, you will need to override the default.
If you leave out the IP address, Privoxy will bind to all
interfaces (addresses) on your machine and may become reachable
from the Internet. In that case, consider using access control
lists (ACL's, see below), and/or a firewall.
If you open Privoxy to untrusted users, you will also want
to turn off the enable-edit-actions and enable-remote-toggle
options!
Example:
Suppose you are running Privoxy on a machine which has the
address 192.168.0.1 on your local private network (192.168.0.0)
and has another outside connection with a different address. You
want it to serve requests from inside only:
listen-address 192.168.0.1:8118
listen-address 127.0.0.1:8118
4.2. toggle
===========
Specifies:
Initial state of "toggle" status
Type of value:
1 or 0
Default value:
1
Effect if unset:
Act as if toggled on
Notes:
If set to 0, Privoxy will start in "toggled off" mode,
i.e. behave like a normal, content-neutral proxy where all ad
blocking, filtering, etc are disabled. See enable-remote-toggle
below. This is not really useful anymore, since toggling is
much easier via the web interface than via editing the conf file.
The windows version will only display the toggle icon in the
system tray if this option is present.
toggle 1
4.3. enable-remote-toggle
=========================
Specifies:
Whether or not the web-based toggle feature may be used
Type of value:
0 or 1
Default value:
1
Effect if unset:
The web-based toggle feature is disabled.
Notes:
When toggled off, Privoxy acts like a normal, content-neutral
proxy, i.e. it acts as if none of the actions applied to
any URL.
For the time being, access to the toggle feature can not be
controlled separately by "ACLs" or HTTP authentication, so that
everybody who can access Privoxy (see "ACLs" and listen-address
above) can toggle it for all users. So this option is not
recommended for multi-user environments with untrusted users.
Note that you must have compiled Privoxy with support for this
feature, otherwise this option has no effect.
enable-remote-toggle 1
4.4. enable-edit-actions
========================
Specifies:
Whether or not the web-based actions file editor may be used
Type of value:
0 or 1
Default value:
1
Effect if unset:
The web-based actions file editor is disabled.
Notes:
For the time being, access to the editor can not be controlled
separately by "ACLs" or HTTP authentication, so that everybody
who can access Privoxy (see "ACLs" and listen-address above)
can modify its configuration for all users. So this option is
not recommended for multi-user environments with untrusted users.
Note that you must have compiled Privoxy with support for this
feature, otherwise this option has no effect.
enable-edit-actions 1
4.5. ACLs: permit-access and deny-access
========================================
Specifies:
Who can access what.
Type of value:
src_addr[/src_masklen] [dst_addr[/dst_masklen]]
Where src_addr and dst_addr are IP addresses in dotted decimal
notation or valid DNS names, and src_masklen and dst_masklen are
subnet masks in CIDR notation, i.e. integer values from 2 to 30
representing the length (in bits) of the network address. The
masks and the whole destination part are optional.
Default value:
Unset
Effect if unset:
Don't restrict access further than implied by listen-address
Notes:
Access controls are included at the request of ISPs and systems
administrators, and are not usually needed by individual
users. For a typical home user, it will normally suffice to
ensure that Privoxy only listens on the localhost (127.0.0.1)
or internal (home) network address by means of the listen-address
option.
Please see the warnings in the FAQ that this proxy is not
intended to be a substitute for a firewall or to encourage
anyone to defer addressing basic security weaknesses.
Multiple ACL lines are OK. If any ACLs are specified, then
the Privoxy talks only to IP addresses that match at least one
permit-access line and don't match any subsequent deny-access
line. In other words, the last match wins, with the default
being deny-access.
If Privoxy is using a forwarder (see forward below) for a
particular destination URL, the dst_addr that is examined is
the address of the forwarder and NOT the address of the ultimate
target. This is necessary because it may be impossible for the
local Privoxy to determine the IP address of the ultimate target
(that's often what gateways are used for).
You should prefer using IP addresses over DNS names, because
the address lookups take time. All DNS names must resolve! You
can not use domain patterns like "*.org" or partial domain
names. If a DNS name resolves to multiple IP addresses, only
the first one is used.
Denying access to particular sites by ACL may have undesired
side effects if the site in question is hosted on a machine
which also hosts other sites.
Examples:
Explicitly define the default behavior if no ACL and
listen-address are set: "localhost" is OK. The absence of a
dst_addr implies that all destination addresses are OK:
permit-access localhost
www.privoxy.org
Allow any host on the same class C subnet aswww.example.com:
access to nothing butwww.privoxy.org/24 www.example.com/32
permit-accessAllow access from any host on the 26-bit subnet 192.168.45.64
to anywhere, with the exception that 192.168.45.73 may not
www.dirty-stuff.example.com:
accesspermit-access 192.168.45.64/26
www.dirty-stuff.example.com
deny-access 192.168.45.734.6. buffer-limit
=================
Specifies:
Maximum size of the buffer for content filtering.
Type of value:
Size in Kbytes
Default value:
4096
Effect if unset:
Use a 4MB (4096 KB) limit.
Notes:
For content filtering, i.e. the +filter and +deanimate-gif
actions, it is necessary that Privoxy buffers the entire document
body. This can be potentially dangerous, since a server could
just keep sending data indefinitely and wait for your RAM to
exhaust -- with nasty consequences. Hence this option.
When a document buffer size reaches the buffer-limit, it is
flushed to the client unfiltered and no further attempt to filter
the rest of the document is made. Remember that there may be
multiple threads running, which might require up to buffer-limit
Kbytes each, unless you have enabled "single-threaded" above.
buffer-limit 4096
5. FORWARDING
=============
This feature allows routing of HTTP requests through a chain
of multiple proxies. It can be used to better protect privacy
and confidentiality when accessing specific domains by routing
requests to those domains through an anonymous public proxy (see
http://www.multiproxy.org/anon_list.htm) Or to use a caching
e.g.proxy to speed up browsing. Or chaining to a parent proxy may be
necessary because the machine that Privoxy runs on has no direct
Internet access.
Also specified here are SOCKS proxies. Privoxy supports the SOCKS
4 and SOCKS 4A protocols.
5.1. forward
============
Specifies:
To which parent HTTP proxy specific requests should be routed.
Type of value:
target_pattern http_parent[:port]
where target_pattern is a URL pattern that specifies to which
requests (i.e. URLs) this forward rule shall apply. Use /
to denote "all URLs". http_parent[:port] is the DNS name or
IP address of the parent HTTP proxy through which the requests
should be forwarded, optionally followed by its listening port
(default: 8080). Use a single dot (.) to denote "no forwarding".
Default value:
Unset
Effect if unset:
Don't use parent HTTP proxies.
Notes:
If http_parent is ".", then requests are not forwarded to
another HTTP proxy but are made directly to the web servers.
Multiple lines are OK, they are checked in sequence, and the
last match wins.
Examples:
Everything goes to an example anonymizing proxy, except SSL on
port 443 (which it doesn't handle):
forward / anon-proxy.example.org:8080
forward :443 .
Everything goes to our example ISP's caching proxy, except for
requests to that ISP's sites:
forward / caching-proxy.example-isp.net:8000
forward .example-isp.net .
5.2. forward-socks4 and forward-socks4a
=======================================
Specifies:
Through which SOCKS proxy (and to which parent HTTP proxy)
specific requests should be routed.
Type of value:
target_pattern socks_proxy[:port] http_parent[:port]
where target_pattern is a URL pattern that specifies to which
requests (i.e. URLs) this forward rule shall apply. Use / to
denote "all URLs". http_parent and socks_proxy are IP addresses
in dotted decimal notation or valid DNS names (http_parent may
be "." to denote "no HTTP forwarding"), and the optional port
parameters are TCP ports, i.e. integer values from 1 to 64535
Default value:
Unset
Effect if unset:
Don't use SOCKS proxies.
Notes:
Multiple lines are OK, they are checked in sequence, and the
last match wins.
The difference between forward-socks4 and forward-socks4a
is that in the SOCKS 4A protocol, the DNS resolution of the
target hostname happens on the SOCKS server, while in SOCKS 4
it happens locally.
If http_parent is ".", then requests are not forwarded to another
HTTP proxy but are made (HTTP-wise) directly to the web servers,
albeit through a SOCKS proxy.
Examples:
From the company example.com, direct connections are made to all
"internal" domains, but everything outbound goes through their
ISP's proxy by way of example.com's corporate SOCKS 4A gateway
to the Internet.
forward-socks4a / socks-gw.example.com:1080 www-cache.example-isp.net:8080
forward .example.com .
A rule that uses a SOCKS 4 gateway for all destinations but no
HTTP parent looks like this:
forward-socks4 / socks-gw.example.com:1080 .
forward-socks4a / 127.0.0.1:9050 .
6. WINDOWS GUI OPTIONS
======================
Privoxy has a number of options specific to the Windows GUI
interface:
If "activity-animation" is set to 1, the Privoxy icon will animate
when "Privoxy" is active. To turn off, set to 0.
#activity-animation 1
If "log-messages" is set to 1, Privoxy will log messages to the
console window:
#log-messages 1
If "log-buffer-size" is set to 1, the size of the log buffer,
i.e. the amount of memory used for the log messages displayed in
the console window, will be limited to "log-max-lines" (see below).
Warning: Setting this to 0 will result in the buffer to grow
infinitely and eat up all your memory!
#log-buffer-size 1
log-max-lines is the maximum number of lines held in the log
buffer. See above.
#log-max-lines 200
If "log-highlight-messages" is set to 1, Privoxy will highlight
portions of the log messages with a bold-faced font:
#log-highlight-messages 1
The font used in the console window:
#log-font-name Comic Sans MS
Font size used in the console window:
#log-font-size 8
"show-on-task-bar" controls whether or not Privoxy will appear as
a button on the Task bar when minimized:
#show-on-task-bar 0
If "close-button-minimizes" is set to 1, the Windows close button
will minimize Privoxy instead of closing the program (close with
the exit option on the File menu).
#close-button-minimizes 1
The "hide-console" option is specific to the MS-Win console version
of Privoxy. If this option is used, Privoxy will disconnect from
and hide the command console.
#hide-console
}}