LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Security
User Name
Password
Linux - Security This forum is for all security related questions.
Questions, tips, system compromises, firewalls, etc. are all included here.

Notices


Reply
  Search this Thread
Old 02-12-2009, 08:33 AM   #1
knichel
LQ Newbie
 
Registered: Nov 2005
Distribution: Ubuntu
Posts: 26

Rep: Reputation: 15
IPtables - Dansguardian - Squid & Gmail Please help...


Greetings. I am trying to prevent my users from getting to mail.google.com (Gmail). I use Google Apps for my domain so I want them to be able to access mail.google.com/a/mydomain.net.

I have IPTables set to transparently proxy all port 80 traffic. I also have it set to allow all traffic from lo and finally block all port 443 traffic.

If a user wants to get to port 443, they must point to my filter (Dansguardian on port 8080).

I added mail.google.com to my bannedsitelist and added mail.google.com/a/mydomain.net to exceptionurllist. When my users try to go to the later, they are banned.

I then tried to add mail.google.com and mail.google.com/mail to bannedurllist. When users tried to go to either of them they were blocked unless they used https.

Should I be using squid to block these? If so, an example would be terrific.

Thanks in advance for your assistance.

Mike
 
Old 02-12-2009, 11:32 AM   #2
win32sux
LQ Guru
 
Registered: Jul 2003
Location: Los Angeles
Distribution: Ubuntu
Posts: 9,870

Rep: Reputation: 380Reputation: 380Reputation: 380Reputation: 380
Quote:
Originally Posted by knichel View Post
Greetings. I am trying to prevent my users from getting to mail.google.com (Gmail). I use Google Apps for my domain so I want them to be able to access mail.google.com/a/mydomain.net.

I have IPTables set to transparently proxy all port 80 traffic. I also have it set to allow all traffic from lo and finally block all port 443 traffic.

If a user wants to get to port 443, they must point to my filter (Dansguardian on port 8080).

I added mail.google.com to my bannedsitelist and added mail.google.com/a/mydomain.net to exceptionurllist. When my users try to go to the later, they are banned.

I then tried to add mail.google.com and mail.google.com/mail to bannedurllist. When users tried to go to either of them they were blocked unless they used https.

Should I be using squid to block these? If so, an example would be terrific.

Thanks in advance for your assistance.

Mike
An example of doing this in Squid might be:
Code:
acl google_apps_http url_regex -i ^http://mail.google.com/a/mydomain.net
acl google_apps_https url_regex -i ^https://mail.google.com/a/mydomain.net
acl gmail dstdomain .mail.google.com
http_access allow google_apps_https
http_access allow google_apps_http
http_access deny gmail
But I'm not sure it would work in real life.

Try it, and tell us what the log file says if it doesn't work.

EDIT: Please note that since Squid doesn't see an HTTPS URL (only the domain and port), one can't do regular expression matching on it. Therefore, the relevant line above is incorrect.

Last edited by win32sux; 10-07-2009 at 11:48 PM.
 
Old 02-12-2009, 12:15 PM   #3
knichel
LQ Newbie
 
Registered: Nov 2005
Distribution: Ubuntu
Posts: 26

Original Poster
Rep: Reputation: 15
Thanks. I tried your sugestion, but it did not work. I can still get to https://mail.google.com

Mike

PS Log file has this in it if it helps...
1234456490.410 79 127.0.0.1 TCP_MISS/200 607 GET http://mail.google.com/ - DIRECT/74.125.45.18 text/html
1234456503.915 10134 127.0.0.1 TCP_MISS/200 6028 CONNECT www.google.com:443 - DIRECT/74.125.45.147 -

Last edited by knichel; 02-12-2009 at 12:55 PM.
 
Old 02-12-2009, 01:20 PM   #4
win32sux
LQ Guru
 
Registered: Jul 2003
Location: Los Angeles
Distribution: Ubuntu
Posts: 9,870

Rep: Reputation: 380Reputation: 380Reputation: 380Reputation: 380
Quote:
Originally Posted by knichel View Post
Thanks. I tried your sugestion, but it did not work. I can still get to https://mail.google.com

Mike

PS Log file has this in it if it helps...
1234456490.410 79 127.0.0.1 TCP_MISS/200 607 GET http://mail.google.com/ - DIRECT/74.125.45.18 text/html
1234456503.915 10134 127.0.0.1 TCP_MISS/200 6028 CONNECT www.google.com:443 - DIRECT/74.125.45.147 -
That's weird. Looks like mail.google.com is being allowed even though there is an ACL explicitly disallowing it. Could you post your entire squid.conf please? Use a command like this to strip the comments and empty lines:
Code:
cat /etc/squid/squid.conf | grep -v ^# | grep -v ^$
To test whether the problem is being caused by the url_regex ACLs, try with only this chunk:
Code:
acl gmail dstdomain .mail.google.com
http_access deny gmail
BTW, Make sure you do this after making any changes to the squid.conf file:
Code:
squid -k reconfigure

Last edited by win32sux; 02-12-2009 at 01:25 PM.
 
Old 02-12-2009, 01:58 PM   #5
knichel
LQ Newbie
 
Registered: Nov 2005
Distribution: Ubuntu
Posts: 26

Original Poster
Rep: Reputation: 15
Ok, here is my current squid3 config file...

Code:
http_port 127.0.0.1:3128
icp_port 3130
hierarchy_stoplist cgi-bin ?
acl QUERY urlpath_regex cgi-bin \?
cache deny QUERY
refresh_pattern ^ftp:		1440	20%	10080
refresh_pattern ^gopher:	1440	0%	1440
refresh_pattern .		0	20%	4320
acl allowQ3 url_regex -i q3ait.org
acl google_apps_http url_regex -i ^http://mail.google.com/a/q3ait.org
acl google_apps_https url_regex -i ^https://mail.google.com/a/q3ait.org
acl block_google_mail_https url_regex -i ^https://mail.google.com
acl gmail dstdomain .mail.google.com
acl all src 0.0.0.0/0.0.0.0
acl manager proto cache_object
acl localhost src 127.0.0.1/255.255.255.255
acl to_localhost dst 127.0.0.0/8
acl SSL_ports port 443
acl Safe_ports port 80		# http
acl Safe_ports port 21		# ftp
acl Safe_ports port 443		# https
acl Safe_ports port 70		# gopher
acl Safe_ports port 210		# wais
acl Safe_ports port 1025-65535	# unregistered ports
acl Safe_ports port 280		# http-mgmt
acl Safe_ports port 488		# gss-http
acl Safe_ports port 591		# filemaker
acl Safe_ports port 777		# multiling http
acl CONNECT method CONNECT
http_access allow manager localhost
http_access deny manager
http_access allow allowQ3
http_access allow google_apps_https
http_access allow google_apps_http
http_access deny block_google_mail_https
http_access deny gmail
http_access deny !Safe_ports
http_access deny CONNECT !SSL_ports
acl our_nets src 192.168.6.0/24
http_access allow our_nets
http_access allow localhost
http_access deny all
http_reply_access allow all
icp_access allow all
coredump_dir /var/spool/squid3
I have tried many things... Crazy that over 4000 lines of code for this few lines of actual config... Comments help I guess...

Thanks for the help.

Mike
 
Old 02-12-2009, 02:24 PM   #6
win32sux
LQ Guru
 
Registered: Jul 2003
Location: Los Angeles
Distribution: Ubuntu
Posts: 9,870

Rep: Reputation: 380Reputation: 380Reputation: 380Reputation: 380
Quote:
Originally Posted by knichel View Post
Ok, here is my current squid3 config file...

Code:
http_port 127.0.0.1:3128
icp_port 3130
hierarchy_stoplist cgi-bin ?
acl QUERY urlpath_regex cgi-bin \?
cache deny QUERY
refresh_pattern ^ftp:		1440	20%	10080
refresh_pattern ^gopher:	1440	0%	1440
refresh_pattern .		0	20%	4320
acl allowQ3 url_regex -i q3ait.org
acl google_apps_http url_regex -i ^http://mail.google.com/a/q3ait.org
acl google_apps_https url_regex -i ^https://mail.google.com/a/q3ait.org
acl block_google_mail_https url_regex -i ^https://mail.google.com
acl gmail dstdomain .mail.google.com
acl all src 0.0.0.0/0.0.0.0
acl manager proto cache_object
acl localhost src 127.0.0.1/255.255.255.255
acl to_localhost dst 127.0.0.0/8
acl SSL_ports port 443
acl Safe_ports port 80		# http
acl Safe_ports port 21		# ftp
acl Safe_ports port 443		# https
acl Safe_ports port 70		# gopher
acl Safe_ports port 210		# wais
acl Safe_ports port 1025-65535	# unregistered ports
acl Safe_ports port 280		# http-mgmt
acl Safe_ports port 488		# gss-http
acl Safe_ports port 591		# filemaker
acl Safe_ports port 777		# multiling http
acl CONNECT method CONNECT
http_access allow manager localhost
http_access deny manager
http_access allow allowQ3
http_access allow google_apps_https
http_access allow google_apps_http
http_access deny block_google_mail_https
http_access deny gmail
http_access deny !Safe_ports
http_access deny CONNECT !SSL_ports
acl our_nets src 192.168.6.0/24
http_access allow our_nets
http_access allow localhost
http_access deny all
http_reply_access allow all
icp_access allow all
coredump_dir /var/spool/squid3
I have tried many things... Crazy that over 4000 lines of code for this few lines of actual config... Comments help I guess...

Thanks for the help.

Mike
I just tried with your squid.conf file and it works mostly as expected for me. All I changed in your squid.conf was I added an access_log line in order to log access attempts. The result was:

-> mail.google.com on it's own was blocked when accessed with http://mail.google.com or https://mail.google.com

-> http://mail.google.com/a/q3ait.org was allowed

-> https://mail.google.com/a/q3ait.org was denied. Looks like this fails because one gets redirected to the root directory at https://mail.google.com/ (which conflicts with the gmail ACL). Not sure at this point what a workaround for that would be. Regardless, you've got bigger fish to fry right now, as our Squid's are behaving differently with the same configurations.

The log for my access looks like:
Code:
1234469873.304      0 127.0.0.1 TCP_DENIED/403 1404 GET http://mail.google.com/ - NONE/- text/html
1234469899.034      0 127.0.0.1 TCP_DENIED/403 1396 CONNECT mail.google.com:443 - NONE/- text/html
1234469912.118    400 127.0.0.1 TCP_MISS/302 1302 GET http://mail.google.com/a/q3ait.org - DIRECT/74.125.19.18 text/html
1234469923.172  11036 127.0.0.1 TCP_MISS/200 8374 CONNECT www.google.com:443 - DIRECT/208.67.217.230 -
1234469923.264  10370 127.0.0.1 TCP_MISS/200 5132 CONNECT www.google.com:443 - DIRECT/208.67.217.231 -
1234469925.753      0 127.0.0.1 TCP_DENIED/403 1396 CONNECT mail.google.com:443 - NONE/- text/html
The last line corresponds to the failed attempt to access https://mail.google.com/a/q3ait.org.

Last edited by win32sux; 02-12-2009 at 02:58 PM.
 
Old 02-12-2009, 02:37 PM   #7
win32sux
LQ Guru
 
Registered: Jul 2003
Location: Los Angeles
Distribution: Ubuntu
Posts: 9,870

Rep: Reputation: 380Reputation: 380Reputation: 380Reputation: 380
Quote:
Originally Posted by win32sux View Post
https://mail.google.com/a/q3ait.org was denied. Looks like this fails because one gets redirected to the root directory at https://mail.google.com/ (which conflicts with the gmail ACL). Not sure at this point what a workaround for that would be.
Okay I seem to have found a workaround for this.

Basically, just use "www" instead of "mail" when accessing your app. So the whole thing could look like:
Code:
acl google_apps_http url_regex -i ^http://www.google.com/a/q3ait.org
acl google_apps_https url_regex -i ^https://www.google.com/a/q3ait.org
acl gmail dstdomain .mail.google.com
http_access allow google_apps_http
http_access allow google_apps_https
http_access deny gmail
EDIT: Please note that since Squid doesn't see an HTTPS URL (only the domain and port), one can't do regular expression matching on it. Therefore, the relevant line above is incorrect.

Last edited by win32sux; 10-07-2009 at 11:49 PM.
 
Old 02-13-2009, 10:44 AM   #8
knichel
LQ Newbie
 
Registered: Nov 2005
Distribution: Ubuntu
Posts: 26

Original Poster
Rep: Reputation: 15
Thank you for the help. Initial testing looks good. This may be it.

I am very grateful.
--
Mike
 
Old 02-13-2009, 11:20 AM   #9
knichel
LQ Newbie
 
Registered: Nov 2005
Distribution: Ubuntu
Posts: 26

Original Poster
Rep: Reputation: 15
Now I think I have a different problem. When I try to install software (in kubuntu/ubuntu) using apt-get, I get errors...
Code:
Err http://us.archive.ubuntu.com intrepid-updates/main konversation 1.1-0ubuntu2.1
  400 Bad Request [IP: 91.189.88.45 80]
Failed to fetch http://us.archive.ubuntu.com/ubuntu/pool/main/k/konversation/konversation_1.1-0ubuntu2.1_i386.deb  400 Bad Request [IP: 91.189.88.45 80]
E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?
I wonder if this is because apt is trying to go to an IP?

Any ideas?

--
Mike
 
Old 02-13-2009, 11:25 AM   #10
win32sux
LQ Guru
 
Registered: Jul 2003
Location: Los Angeles
Distribution: Ubuntu
Posts: 9,870

Rep: Reputation: 380Reputation: 380Reputation: 380Reputation: 380
Quote:
Originally Posted by knichel View Post
Now I think I have a different problem. When I try to install software (in kubuntu/ubuntu) using apt-get, I get errors...
Code:
Err http://us.archive.ubuntu.com intrepid-updates/main konversation 1.1-0ubuntu2.1
  400 Bad Request [IP: 91.189.88.45 80]
Failed to fetch http://us.archive.ubuntu.com/ubuntu/pool/main/k/konversation/konversation_1.1-0ubuntu2.1_i386.deb  400 Bad Request [IP: 91.189.88.45 80]
E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?
I wonder if this is because apt is trying to go to an IP?

Any ideas?
I don't know, although the error message is recommending that you run "apt-get update" to see if it helps. That said, please use a separate thread for this new, unrelated issue.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Proxy won't let me connect, iptables, squid and dansguardian hindenbergbaby Linux - Networking 4 12-02-2009 03:45 AM
IPTABLES, SQUID, DANSGUARDIAN and Transparent Proxy metallica1973 Linux - Networking 18 09-03-2007 07:17 PM
iptables -> squid -> dansguardian (same box) knichel Linux - Security 1 05-14-2007 01:16 PM
setting up dansguardian, squid and iptables as webfilter!! cryonics Linux - Security 1 03-10-2006 06:29 PM
iptables, DansGuardian, and Squid. cth3 Linux - Networking 1 02-10-2005 09:04 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Security

All times are GMT -5. The time now is 10:28 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration