Saturday, August 25, 2012

a simple http transparent proxy with relayd

1) edit /etc/pf.conf, then run #pfctl -f /etc/pf.conf.

# anchor for relayd(8)
anchor "relayd/*"
pass in quick inet proto tcp to port www divert-to 127.0.0.1 port 8080

2) edit /etc/relayd.conf, then run # /usr/sbin/relayd -d, for console debugging. 

dest = "cnn.com"

http protocol httpfilter {
        # Return HTTP/HTML error pages to the client
        return error
        # Block some well-known Instant Messengers
        label "Instant messenger disallowed!"
        response header filter "application/x-msn-messenger" from "Content-Type"
        response header filter "app/x-hotbar-xip20" from "Content-Type"
        response header filter "application/x-icq" from "Content-Type"
        response header filter "AIM/HTTP" from "Content-Type"
        response header filter "application/x-comet-log" from "Content-Type"
}

relay httpproxy {
        # Listen on localhost, accept diverted connections from pf(4)
        listen on 127.0.0.1 port 8080
        protocol httpfilter
        forward to $dest port 80
}

3) change the $dest above to wherever you want. edit /etc/rc.conf.local for relayd bootup if needed!

No comments:

Post a Comment