Professional Documents
Culture Documents
################################################################################
####################
1.- Instalar Paquetes
$> yum -y install squid httpd
2.- Configurar Proxy
$> cd /etc/squid
$> vim squid.conf
-------------------------------------------------------------------------------------------#
# Recommended minimum configuration:
#
# Example rule allowing access from your local networks.
# Adapt to list your (internal) IP networks from where browsing
# should be allowed
acl localnet src 10.0.0.0/8 # RFC1918 possible internal network
acl localnet src 172.16.0.0/12 # RFC1918 possible internal network
acl localnet src 192.168.0.0/16 # RFC1918 possible internal network
acl localnet src fc00::/7
# RFC 4193 local private network range
acl localnet src fe80::/10
# RFC 4291 link-local (directly plugged) machine
s
acl
acl
acl
acl
acl
acl
acl
acl
acl
acl
acl
acl
acl
acl
# ACLs personalizados
#############################################################
acl gerentes src "/etc/squid/reglas/gerentes.ips"
acl asistentes src "/etc/squid/reglas/asistentes.ips"
acl usuarios src "/etc/squid/reglas/usuarios.ips"
acl limitados src "/etc/squid/reglas/limitados.ips"
acl redessociales url_regex "/etc/squid/reglas/redessociales"
# dominios permitidos
acl listablanca dstdomain "/etc/squid/reglas/listablanca"
# dominios denegados
acl listanegra dstdomain "/etc/squid/reglas/listanegra"
# ips permitidos
acl ipsblancos dst "/etc/squid/reglas/ipsblancos"
# pornos
acl palabrasprohibidas url_regex "/etc/squid/reglas/palabrasprohibidas"
# eje: avi, mp3
acl archivosprohibidos urlpath_regex "/etc/squid/reglas/archivosprohibidos"
# eje: pif, bat
acl archivospeligrosos urlpath_regex "/etc/squid/reglas/archivospeligrosos"
# hora de almuerzo
acl almuerzo time MTWHFS 13:00-14:00
#
# Recommended minimum Access Permission configuration:
#
########### Restriccin de accesos
# Only allow cachemgr access from localhost
http_access allow localhost manager
## denegando acceso a archivos perligrosos
http_access deny archivospeligrosos
## acceso libre a gerentes
http_access allow gerentes
# Deny requests to certain unsafe ports
http_access deny !Safe_ports
# Deny CONNECT to other than secure SSL ports
http_access deny CONNECT !SSL_ports
# aceso libre para todos a la lista blanca e ips blancos
http_access allow asistentes listablanca
http_access allow asistentes ipsblancos
http_access allow usuarios listablanca
http_access allow usuarios ipsblancos
http_access allow limitados listablanca
http_access allow limitados ipsblancos
# todo el mundo tiene redessociales solo una horita en el almuerzo pa que no se
estresen
http_access allow redessociales almuerzo
# asistente se le deniega palabras prohibidas pero tiene redessociales
http_access deny palabrasprohibidas
http_access allow asistentes
http_access deny redessociales
http_access deny listanegra
http_access deny archivosprohibidos
# usuario no tiene redessociales, porno ni baja archivos de hueveo
http_access allow usuarios
http_access deny manager
# We strongly recommend the following be uncommented to protect innocent
# web applications running on the proxy server who think the only
# one who can access services on "localhost" is a local user
#http_access deny to_localhost
#
# INSERT YOUR OWN RULE(S) HERE TO ALLOW ACCESS FROM YOUR CLIENTS
#
# Example rule allowing access from your local networks.
# Adapt localnet in the ACL section to list your (internal) IP networks
# from where browsing should be allowed
http_access allow localhost
http_access deny localnet
# And finally deny all other access to this proxy
Explicacin de parmetros
################################################################################
############
Definicin de Acls
-------------------------------------------------------------------------acl nombredelacl tipodeacl valor
tipos de acl
------------------------------src
direccion o red de origen
port puerto de destino
proto proceso
dst
direccion o red de destino
url_regex filtro de palabras en el URL
urlpath_regex extension de archivo
dstdomain dominio de destino
proxy_auth verifica autenticacin
time especifica una restriccin horaria
# Red local
8 acl localnet src 10.0.0.0/8 # RFC1918 possible internal network
9 acl localnet src 172.16.0.0/12 # RFC1918 possible internal network
10 acl localnet src 192.168.0.0/16 # RFC1918 possible internal network
11 acl localnet src fc00::/7
# RFC 4193 local private network range
12 acl localnet src fe80::/10
# RFC 4291 link-local (directly plugged) mach
ines
# Puertos que se pueden usar en https
Ej: https://dom.com:7071
$> cd /etc/squid
$> wget --user=linux --password=ad1estra www.adiestra.pe/centos7/reglas.tgz
$> tar -zxvf reglas.tgz
$> cd reglas
$> vim gerentes.ips
192.168.130.101
$> vim asistentes.ips
192.168.130.102
$> vim usuarios.ips
192.168.130.103
192.168.130.104
$> vim limitados.ips
192.168.130.105
$> systemctl start squid
$> systemctl enable squid
$> systemctl status squid
Ver Logs del Servicio
$> tail -f /var/log/squid/squid.out
Ver logs de Acceso
$> tail -f /var/log/squid/access.log
Ver logs de Acceso de un usuario especifico (ej 192.168.100.232)
$> tail -f /var/log/squid/access.log | grep 192.168.100.232
Hacer pruebas de navegacion poniendole proxy al navegador
Cuando se hace cambios en los archivos de reglas
Ejecutar
$> systemctl restart squid
Agregar al script del firewall el acceso al puerto 3128 tcp
echo "permitiendo acceso al servidor squid"
iptables -A INPUT -p tcp --dport 3128 -m state --state NEW,ESTABLISHED,RELATED j ACCEPT
iptables -A OUTPUT -p tcp --sport 3128 -m state --state ESTABLISHED,RELATED -j A
CCEPT
ec
$> vim /root/firewall-bastion
.
.
$> ./firewall-bastion
SARG
-------------------------------------------------------------------Sarg genera reportes diarios, semanales y mensuales, automaticamente
$> yum -y install gcc gd gd-devel make perl-GD wget httpd pcre-devel
$> cd
$> wget http://garr.dl.sourceforge.net/project/sarg/sarg/sarg-2.3.7/sarg-2.3.7.t
ar.gz
$> tar -xvzf sarg-2.3.7.tar.gz
$> cd sarg-2.3.7/
$> ./configure
$> make
$> make install
$> vim /usr/local/etc/sarg.conf
7: access_log /var/log/squid/access.log
120: output_dir /var/www/sarg
216: date_format e
257 overwrite_report yes
Generar los reportes del momento ejecutando
$> mkdir /var/www/sarg
$> sarg -x
Ver Reportes de Sarg a nivel de toda la red
-----------------------------------------------$> vim /etc/httpd/conf.d/sarg.conf
Alias /sarg /var/www/sarg
<Directory /var/www/sarg>
Options Indexes FollowSymLinks
AllowOverride All
DirectoryIndex index.html
Order deny,allow
Allow from all
</Directory>
$> vim /var/www/sarg/.htaccess
AuthType basic
AuthName "reportes de sarg"
AuthUserFile /usr/local/etc/sarg.user
Require valid-user
$> htpasswd -c /usr/local/etc/sarg.user admin
clave: admin
$> systemctl restart httpd
$> systemctl enable httpd
Agregar al script del firewall el acceso al puerto 80 tcp
$> vim /root/firewall-bastion
.
.
$> ./firewall-bastion
Acceder con
http://192.168.130.X/sarg
Automatizando los reportes de sarg
$> vim /etc/cron.daily/sarg
#!/bin/bash
sarg -d day-1 -w /tmp/sarg.daily -o /var/www/sarg/Daily /var/log/squid/access.lo
g*
$> vim /etc/cron.weekly/sarg
#!/bin/bash
sarg -d week-1 -w /tmp/sarg.weekly -o /var/www/sarg/Weekly /var/log/squid/access
.log*
$> vim /etc/cron.monthly/sarg
#!/bin/bash
sarg -d month-1 -w /tmp/sarg.monthly -o /var/www/sarg/Monthly /var/log/squid/acc
ess.log*
$> chmod 755 /etc/cron.daily/sarg /etc/cron.weekly/sarg /etc/cron.monthly/sarg
Proxy con autenticacion
################################################################################
##########
Comentamos las lneas de usuarios con Ip y agregamos usuarios por autenticacin
$>
31
32
33
34
35
36
37
38
39
vim /etc/squid/squid.conf
#acl gerentes src "/etc/squid/reglas/gerentes.ips"
#acl asistentes src "/etc/squid/reglas/asistentes.ips"
#acl usuarios src "/etc/squid/reglas/usuarios.ips"
#acl limitados src "/etc/squid/reglas/limitados.ips"
auth_param basic program /usr/lib64/squid/basic_ncsa_auth /etc/squid/usuarios
acl gerentes proxy_auth "/etc/squid/reglas/gerentes.usr"
acl asistentes proxy_auth "/etc/squid/reglas/asistentes.usr"
acl usuarios proxy_auth "/etc/squid/reglas/usuarios.usr"
acl limitados proxy_auth "/etc/squid/reglas/limitados.usr"