iptables with --uid-owner denying traffic to local/private IP space (plus infrastructure-specific stuff like EC2's instance metadata service) would probably be the best option.
-A OUTPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
# Create a chain for outgoing proxy traffic
-N PROXY_OUT
-A OUTPUT -m owner --uid-owner proxy -j PROXY_OUT
# Allow replies to the requestor
-A PROXY_OUT -p tcp --sport 8080 -j ACCEPT
# Prevent proxy from talking to anything non HTTP{,s} (and DNS)
-A PROXY_OUT -p tcp -m multiport ! --dports 80,443,53 -j DROP
# Allow DNS udp
-A PROXY_OUT -p udp --dport 53 -j ACCEPT
# Allow the proxy to specific private ips (demos servers)
-A PROXY_OUT -d xxx.xxx.xxx.xxx/32 -j ACCEPT
# Prevent proxy from talking to anything private
-A PROXY_OUT ! -o <%= @public_iface %> -j DROP
-A PROXY_OUT -d 10.0.0.0/8 -j DROP
-A PROXY_OUT -d 172.16.0.0/12 -j DROP
-A PROXY_OUT -d 192.168.0.0/16 -j DROP
# Prevent proxy from talking to services via public ips
<% @aws_public_ips.each do |name, facts| %>
# <%= name %>
-A PROXY_OUT -d <%= facts['ec2_public_ipv4'] %>/32 -j DROP
<% end %>
Anything I missed? Blocking outgoing ports is to taste.-A PROXY_OUT -d 127.0.0.0/8 -j DROP
-A PROXY_OUT -d 169.254.0.0/16 -j DROP
That seems to cover everything in IPv4, but if you have IPv6 enabled, you probably want fd00::/8, fe80::/10 and ::1/128 as well (disclaimer: my knowledge of IPv6 is rather limited.)
iptables -A OUTPUT -m owner --uid-owner mike -d 127.0.0.0/8 -j REJECT
ip6tables -A OUTPUT -m owner --uid-owner mike -d ::1 -j REJECT
$ ping 2130706433
PING 2130706433 (127.0.0.1): 56 data bytes
64 bytes from 127.0.0.1: icmp_seq=0 ttl=64 time=0.043 ms
64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.106 ms
^C
Dotted quad is just a convenient representation of an unsigned int.They should have run the proxy on a host that they didn't give any special IP-based privileges to. The other nodes shouldn't honor X-Forwarded-For headers from the IP hosting the proxy.
And the IPv6 equivalent is "::1". Did they even set up basic packet filtering or ACLs for IPv6 requests? If they have no public IPv6 address, they probably never did.
People's results here might vary depending on their operating system. For me, these pings were returned on a vagrant box running ubuntu, but dropped (not blocked) on the host system.
On the flip side, if you're doing a security test like this, I've gotten mileage out of convincing apps to access local resources with things like 127.88.23.245, precisely because the developer blocked 127.0.0.1 specifically and thought they were done.
You should also usually block all internal and external IPs for your entire network, but especially in the cloud this can begin to get tricky. Still, you should.
And don't forget IPv6.