====== Squid + Portal Cautivo ====== ===== Descripción ===== Hace posible la interceptacion de trafico de un conjunto de equipos para mandarlos a una plataforma de autenticacion, para permitir y/o cobrar la navegacion.\\ \\ Esto es parte del proyecto KVD y varios temas estan asociados al mismo\\ ===== Prerequistos ===== Un Linux con Apache2 + PHP (por el portal) , un firewall configurado (turtlefirewall preferible) y un squid3 con extension\\ ===== Instalación ===== Monte los sistemas estandares poniendo a funcionar lo que se necesita para un proxy normalito, con la configuracion de squid y la configuracion de turtle normalito\\ \\ Por ejemplo [[index.php?menuaction=wiki.wiki_ui.view&lang=es-es&page=Proxy+Skina+Howto|Skina Proxy Howto]]\\ \\ OJO con squid3, hace falta una ultima version. SI esta en debian toca de testing: agregue los repositorios\\ \\ # Testing for squid\\ deb http:%%//%%ftp.br.debian.org/debian/ testing main contrib non-free\\ \\ Y agregue squid3.\\ \\ OJO .. revise que tenga la extension ext_session_acl\\ ===== Configuración ===== Este es el arbol de directorios de la versión funcional del portal cautivo para pruebas:\\ ==== A. Apache ==== - Abrimos el puerto 8080 para que el portal sirva por ese puerto. Agregamos este puerto >> /etc/apache2/ports.conf:   Listen 8080 \\ \\ Se agrega una pagina web en /var/www/index.php que es una redireccion al portal cautivo ==== B. Firewall ==== El firewall se encarga de las redirecciones y de los bloqueos. Se tiene un turtle modelo de acuerdo a las necesidades\\ \\ - Anexo 1 muestra el fw.xml\\ - Anexo 2 muestra la alteracion al init de turtle para que ejecute tambien las reglas especificas al portal\\ - Anexo 3 Muetra el script con las reglas nuevas que se encargan de marcar los paquetes\\ \\ * OJO que este depende de una lista de direcciones MAC ubicada en el archivo /var/lib/users  con el formato\\ \\      IP1 MAC-ADDR1\\   IP2 MAC-ADDR2\\   IP3 MAC-ADDR3 \\  \\ Estos son los equipos que tiene agente y no son bloqueados ni se les muestra el portal. ==== C. Squid ==== Squid forma parte de la solucion para llevar inventario y para servir de cache ...  Tiene configuraciones especiales para redirigir nuevamente al portal cautivo en caso de ser invalido.\\ \\ - Anexo 4 incluye el extracto de squid.conf\\   ==== D. Sudo ==== Por ultimo se requiere que la pagina del portal pueda permitir el accesso en el firewall lo que debo hacer es permitir a www-data ejecutar comandos del firewall.\\ La mejor .. fue usar sudo.\\   \\ \\ ├── etc\\ │   ├── apache2\\ │   │   └── ports.conf (se agrega el puerto 8080 para servir la pag del portal)\\ │   ├── init.d\\ │   │   └── turtlefirewall (se agrega el disparo automático de cp_iptables cada que se inicia el firewall)\\ │   ├── squid3\\ │   │   └── squid.conf (se sirve la pag del portal en el puerto 8080 en http)\\ │   ├── sudoers (se agregan las reglas para que el usuario https-data pueda correr iptables)\\ │   └── turtlefirewall\\ │       └── fw.xml (se elimina la regla de "Zexterna to Zexterna ALL" que genera conflictos con el portal, no funciona)\\ ├── usr\\ │   └── share\\ │       └── kuine\\ │           └── kvd\\ │               └── cp_iptables (reglas para la autenticacion y el bloqueo de paquetes)\\ └── var\\     ├── lib\\     │   └── users (tabla de macs preautenticadas FORMATO: IP \\t MAC, el tab es obligatiro)\\     └── www\\         └── index.php (archivo de redirección para https)\\ \\ \\ Existen un par de cambios en el sktimer\\ \\ 1. Agregar el boton de preautenticacion de MACs (Deiby ya lo agrego)\\ 2. y el archivo config_mac.php (ya está en el repo) ==== 1. Una accion ==== ==== 2. Segunda accion ==== ===== Trucos ===== ===== Problemas ===== ==== 1. Squid no sube.  "The session_active_def helpers are crashing too rapidly, need help!" ==== El que se muere es el ext_session_acl que son los helpers de squid.\\ \\ Solucion: borrar el contenido del directorio /var/lib/squd/session/*   Y reiniciar squid.\\ \\ Porque .. NI IDEA !!! pero ocurre solo cuando se cambia la configuracion de apache.\\ \\   ===== Referencias ===== - http:%%//%%www.andybev.com/index.php/Using_iptables_and_PHP_to_create_a_captive_portal\\ \\ - http:%%//%%wiki.squid-cache.org/ConfigExamples/Portal/Splash FIN ---- __**Advertencia**__ Este documento es privado y es de u so exclusivo de sus autores y de SKINA TECH. Cualquier uso sin una autorización escrita es contra la ley de derechos de autor y de propiedad intelectual, y será motivo de una acción legal. ----  \\ **Anexo 1**\\ ---------------------------------------------------------------------\\ /etc/turtlefirewall/fw.xml\\ ---------------------------------------------------------------------\\ \\ \\ \\ \\ \\ \\         \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ **Anexo 2**\\ ---------------------------------------------------------------------\\ /etc/init.d/turtlefirewall   ( solo la funcion start)\\ ---------------------------------------------------------------------\\ \\ start() {\\         /usr/sbin/turtlefirewall\\         if [ $? == 0 ] ; then\\                 /usr/share/kuine/kvd/cp_iptables\\                 touch $FLAG_FILE\\         fi\\         RETVAL=$?\\         return $RETVAL\\ }\\ \\ \\ **Anexo 3**\\ ---------------------------------------------------------------------\\ /usr/share/kuine/kvd/cp_iptables   (inspidado en la referencia)\\ ---------------------------------------------------------------------\\ \\  #!/bin/bash\\ \\ IPTABLES=/sbin/iptables\\ \\  # Create internet chain\\  # This is used to authenticate users who have already signed up\\ $IPTABLES -N ZInterna-ZExterna -t mangle\\ \\  # First send all traffic via newly created internet chain\\  # At the prerouting NAT stage this will DNAT, them to the local\\  # webserver for them to signup if they aren't authorised\\  # Packetc for unauthorized users are marked for dropping later\\ $IPTABLES -t mangle -A PREROUTING -j ZInterna-ZExterna\\ \\  ###### INTERNET CHAIN ##########\\  # Allow authorised clients in, redirect all others to login webserver\\  # Add known users to the NAT table to stop their dest being rewritten\\  # Ignore MAC address with a 10_consejos_para_la_resolucion_de_problemas.html acta_de_constitucion_interna_del_proyecto.html active_directory.html administrar_servidores_con_ipmi.html admin_rpms_con_yum.html albasoftware_libre_de_gestion_educativa.html alta_disponibilidad_de_conexion_a_internet.html ansible_administracion_centralizada_de_servidores.html anti_virusanti_spam_y_hardening_de_correo2024.html anti_virusanti_spam_y_hardening_de_correo.html apache2_mod_security.html apacheservidor_de_www.html aplicativos_usando_ldap.html autoconf.html aws_amazon_ec2.html aws_amazon_lambda.html bacula_backup2024.html bacula_backup.html bandwidthd.html bind_dns.html bonding.html cacti.html cambio_contrasena_ldap_ad_por_web.html cambios_recientes.html caracteres_octal_hexa_unicode_html.html centos_sobre_hyperv.html cfengine.html chumne_administrador_de_licencias.html ciclo_de_pruebas_orfeo.html cluster_con_haproxy.html cluster_ldap.html colaborador_del_mes.html comision_de_proyectos_obsoleto.html como_desplegar_remoto_con_un_tunel_ssh.html como_hacer_manual_de_funciones.html como_instalar_spoon.html como_limpiar_cache_dns.html como_publicar_docs.html como_reportar_spam.html como_se_implementa_orfeo_sgd.html compensatorios_obsoleto.html condiciones_generales_de_contrato_de_soporte_v14.html configuracion_de_tomcat_como_modulo_de_apache.html configuracion_de_x_lite_cliente_sip.html configuracion_pidgin.html configuracion_planta_telefonica_voip.html configurar_redes.html consola_serial.html consul_open_participation_ruby.html controlador_de_dominio_secundario_samba4.html convertir_pdf_a_a_pdf_plano.html copiar_disco_por_la_red.html cpanel.html crack_de_wep_con_aircrack_ng.html creacion_servidor_codema.html creacion_usuario_postgres_solo_para_consultas.html crear_instalador_de_windows_facil_con_nsis.html crear_instancias_de_orfeong.html crear_paquetes_deb_y_rpm.html crear_repositorios_de_paquetes_deb_y_rpm.html cuestionario_de_severidad.html cups.html cygwn.html dd_wrt.html declaracion_de_trabajo_sow.html deploy_instancia_de_orfeo_express_5x_en_amazon.html deploy_instancia_de_orfeo_express_6x_en_amazon.html descargar_pagina_web_recursivo.html deshabilite_ipv6.html dhcp_multiples_vlans.html dhcp_server.html dhcp_y_dns_dinamico.html directrices_de_manejo_de_tiquetes_en_mesa_de_ayuda_glpi.html docker.html documentacion_de_codigo.html documentos_de_implementacion_de_orfeo_5x.html documentos_estandar_control_proyectos_desarrollo.html dotproject.html drbd.html drp_plan_de_recuperacion_de_desastres.html dsl_personalizacion.html egroupware_ex_phpgw.html ejabberd.html elastix.html enigmail.html enlightenment.html entidad_de_certificacion_a_mano.html entidad_de_certificacion.html entidad_de_certificacion_openca.html envio_y_recepcion_de_fax_en_asterisk.html errores_modelos.html esquema_backup_ikatta.html estandar_bitacora.html estandar_comunicaciones_por_correo_electronico.html estandar_de_archivos_y_directorios.html estandar_de_interfaz_para_proyectos_de_desarrollo.html estandar_de_manejo_de_cronograma.html estandar_de_revision_de_documentos.html estandar_de_soporte_y_mantenimiento_de_skinatech.html estandares_de_comunicacion_de_soporte.html estandar_estacion_de_trabajo_gnu_linux.html estandar_estacion_de_trabajo_ms_windows.html estandar_firma_skina.html estandar_para_interfaz_de_proyectos_de_desarrollo.html estandar_para_la_creacion_de_bases_de_dato.html example_howto.html exim_mta.html extraccion_de_texto_de_documentos.html fail2ban.html falla_laboral.html fax_server.html fink.html firewalld.html firewall_skina_howto.html flujo_de_trabajo_de_proyecto.html flujo_de_trabajo_de_proyecto_trello.html formatos_de_documentos_estandares_de_skinatech.html freenas.html freenx.html freetds.html ftpproxy.html generar_diccionarios_de_datos_en_workbench.html getfacl_y_setfacl.html getmenu2.html gforge.html git_flow.html git.html gitlab.html glassfish.html glpi10.html glpi95.html gnokii.html gnupg_gpg.html google_cloud_platform.html graylog_consolidador_de_bitacoras.html grub.html hacer_modelo_y_o_backup.html hardening_de_linux.html hearbeat_cluster.html hipergate.html hispaniola_firewall_ikatta.html horario_de_trabajo.html how_to_enviar_html_imagenes_con_php5.html howto.html howto_mon.html howto_php_nuke.html huawei_e220.html ibm_aix_snmp_setup_for_nagios.html ibm_db2.html ids_logchecklogwatchtripwireaideetc.html ilo2_e_ilo3.html implementacion_de_oauth2_google_en_orfeo_ng.html implementacion_de_oauth2_microsoft_en_orfeo_ng.html implementacion_glpi.html indicadores_de_gestion.html informes_semanales.html informix_apache_php.html infraestructura_de_operacion.html instalacion_asterisk_en_centos_53.html instalacion_asterisk_en_.html instalacion_de_modelo_de_servidor_con_minilinux.html instalacion_de_modelo_de_servidor.html instalacion_de_pqrs_en_orfeo_sgd.html instalacion_ldap_smb_34_en_debian_lenny.html instalacion_minima_appliance.html instalacion_mi­nima.html instalacion_r_server_&_r_shiny.html instalacion_r_server_&_r_shiny_server.html instalacion_splunk.html instalacion_y_configuracion_apachephp_con_db2_y_soporte_con_odbc.html instalacion_y_configuracion_de_sphinx_para_orfeo.html instalacion_y_configuracion_gatekeeper_h323.html instalacion_y_configuracion_lotus_domino.html instalacion_zimbra.html instalar_cancelador_de_eco_hpec_en_asterisk.html instructivo_de_demos_de_skinatech.html instructivo_formato_de_diagnostico.html ipcop_firewall.html ipsec.html ipsec_zeroshell.html iptables.html iscsi.html ispconfig_v1.html ispconfig_v3.html iwatch_inotifywatch_notificar_eventos_en_carpetas.html jmeter.html joomla_cms.html kernel_compilar.html kuine_administracion_de_licencias.html kuine_generacion_de_licencias.html libchart.html licencia_por_calamidad_domestica.html linux_livecd.html lista_de_mejoras.html locale.html lvm.html lvs_linux_virtual_server.html mailman.html mailscanner.html manejo_de_certificados_integracion_pki.html manejo_de_firma_digital_en_php.html manejo_de_la_cuenta_de_correo_de_soporte.html manejo_de_mi_cuenta_de_correo_electronico.html manejo_de_recursos_egroupware_18.html mantis_bug_tracker.html manual_de_funciones_de_agente_de_soporte.html manual_de_funciones_de_consultor_de_tecnologia.html manual_de_telefonos.html manual_de_uso_asterisk.html manual_de_uso_fastrix.html manuales_de_funciones_area_administrativa.html manuales_de_funciones_area_tecnica.html maya_render_farm.html mdadm.html mejorar_rendimiento_libre_office.html metodologia_estandar_de_control_de_proyectos.html metodologia_estandar_de_control_de_proyectos_orfeo.html metodologia_para_desarrollo_de_software.html migracion_bacula_de_5_a_7.html migracion_orfeo_5_a_6.html migrando_samba3_a_samba4.html modelo_appliance.html modelo_de_procedimientos.html modelo_para_howtos.html modelo_para_propuesta.html monit.html montar_bucket_s3_amazon_y_oracle.html montar_orfeo_en_iis.html moodle.html ms_windows_en_linux_wine.html multi_factor_authentication_mfa.html multipath_conexion_con_san.html multiple_versiones_de_php.html multi_router_trafic_grapher_mrtg.html munin_alto_trafico.html munin.html mutliwan_openwrt.html mwan3_en_openwrt.html mysql_cluster_41.html mysql_ha.html mysql_mariadb.html mysql_proxy.html n2n_vpn.html nagios_30.html nagios_40.html nagios_bacula.html nagios_nrpe.html nagios_snmp.html netdata_monitor_tiempo_real.html network_load_balancing.html network_manager.html nextcloud.html nfs.html niveles_de_soporte.html no_conformidades.html novell_netware.html ntp_network_time_protocol.html nube_vs_servidores_locales.html oauth2.html objetivo_de_un_diagnostico_assestment.html ocr_en_linux.html ocs_inventory.html odbc.html office_365.html ofuscacion_de_codigo_yarchivo_de_autovalidacion_de_orfeo_50.html openfire.html openldap23.html openldap.html open_relay.html openssl.html openstack.html openswan.html openvas.html openvpn.html openvpnzeroshell_w2k12.html openwrt.html optimizacion_de_aplicaciones.html oracle_db.html orfeo_38_skn.html orfeo_bd.html orfeo_cargar_imagenes_fondo_acumulado.html orfeo.html orfeo_impedir_listar_directorios_apache2.html orfeong_php_81base_de_datos.html orfeong_pruebas_de_bases_de_datos.html orfeo_scan.html otp_one_time_password.html otras_directrices_y_comentarios.html otrs_open_ticket_request_system.html owncloud_91_centos_6.html p3scan.html palm_os.html parametrizacion_de_orfeo_ng.html parametrizacion_orfeo_6x.html parametrizacion_orfeo_express_6x.html particionamiento_gpt.html paso_a_produccion_orfeo_6x.html paso_a_produccion_orfeo_ng.html pasos_para_editar_skinascan.html perl.html personalizacion_usando_linux_logo.html pfsense.html php_52_y_53_en_centos_610.html php_db2.html php.html php_oracle.html planta_telefonica_programacion_obsoleta.html plantilla_primer_correo_cliente_orfeo_express.html plymouth.html politica_de_compensaciones.html politica_de_reporte_de_actividades.html politica_solicitud_permisos.html postfix_mta.html postgresql_ha.html postgresql.html postman.html powerpc_rs6k.html pptp.html procedimiento_de_manejo_para_nuevos_desarrollos.html procedimiento_entrega_servicio_orfeo_express.html procedimiento_inicio_servidor_de_impresion_obsoleto.html procedimiento_para_avalar_un_cliente.html procedimiento_salida_oficina.html procedimiento_se_fue_la_luz.html proceso_de_compra_para_proyectos.html proceso_de_control_y_seguimiento_de_proyectos.html proceso_de_creacion_de_usuario.html proceso_de_formalizacion_solucion_empresarial_2009.html proceso_de_formalizacion_solucion_empresarial_2018_2019.html proceso_ejecucion_proyecto.html proceso_instalador_tarificador_skclient.html programas_de_shell_utiles.html project_charter_implementacion_del_sgd_orfeo.html project_open.html protocolo_bioseguridad_covid_19_skinatech_azuan.html protocolo_de_apertura_y_cierre_de_contratos_glpi.html protocolo_de_apertura_y_cierre_de_contratos.html protocolo_de_apertura_y_cierre_de_proyectos_dotproject.html protocolo_de_creacion_de_proyectos_dentro_del_dotproject.html protocolos_de_salida_de_la_toficina.html proxmox.html proxy_configuration_por_dhcp_dns.html proxy_skina_howto.html proyecto_implementacion_orfeo_listado_de_documentos.html python.html qmail_mta.html que_debe_ir_en_el_crm.html quota.html radius_ppp.html radius_samba4.html recuperar_datos_borrados_con_rm.html red_hat_cluster.html redmine.html reducir_tamano_pdf.html regla_de_multas_por_faltas_de_calidad_obsoleto.html reglamentacion_de_viajes.html reglamento_de_capacitaciones.html reglas_del_uso_de_la_nevera_a.html reglas_del_uso_de_la_nevera.html reglas_de_uso_de_la_cafetera_y_tetera.html reglas_de_uso_del_espacio_para_almuerzo.html reglas_internas_de_skina.html reinicio_de_secuencias_en_orfeo.html remasterizar_knoppix_dsl.html renovar_certificados_acme_hispaniola.html resolver_expired_key_con_apt.html retirar_de_listas_negras_blacklists.html roadmap_infraestructura_interna.html roadmap_servicio_soporte.html roundcube.html router_bridge_inhalambrico_con_openwrt.html rrd_tool.html rsh_por_ssh.html rspamd.html ruby_passenger_apache.html samba4.html samba_ldap.html samba_version_3.html sane_scanner.html script_para_firmar_documentos.html sec_simple_event_correlation.html secure_shell_ssh.html seguridad_para_contrasenas.html seleccion_de_personal.html sendmail_mta.html servidor_bdatos_skina_howto.html servidor_de_correo2024.html servidor_de_correo.html servidor_de_mensajeri­a_instantanea_con_jabberd2.html servidor_ftp.html servidor_internet_skina_howto.html servidor_orfeo_skina_howto.html servidor_pop3_e_imap.html servidor_vpn_utilizando_ipsec_y_l2tp.html shell_scripting.html sincronizar_una_dir_desde_un_el_equipo_local_a_un_equipo_remoto_usando_rsync.html sistemas_de_correo_con_postfixcourierldapsaslamavis_new_y_spamassassin.html skina_administrativo.html skina_comercial.html skinatech_docs.html skinatech.html skina_tecnico.html smart_cards.html snapd.html snmp.html snort.html soap.html solr_full_text_search.html spamassassin.html sphinx_estrategia_orfeo_6.html sphinx_estrategia_orfeo_ng.html sql_server.html squid_portal_cautivo.html - these users are blocked\\  # This awk script goes through the /var/lib/users flat file line by line\\ awk 'BEGIN { FS="\\t"; } { system("iptables -t mangle -A ZInterna-ZExterna -m mac --mac-source "$2" -j RETURN"); }' /var/lib/users\\ \\  # MAC address not found. Mark the packet 99\\ $IPTABLES -t mangle -A ZInterna-ZExterna -j MARK --set-mark 99\\  ################################\\ \\  # Redirects web requests from Unauthorised users to logon Web Page\\ $IPTABLES -t nat -A PREROUTING -m mark --mark 99 -p tcp --dport 443 -j DNAT --to-destination 192.168.199.254\\ \\  # Now that we've got to the forward filter, drop all packets\\  # marked 99 - these are unknown users. We can't drop them earlier\\  # as there's no filter table\\ $IPTABLES -t filter -A FORWARD -m mark --mark 99 -j DROP\\ $IPTABLES -t filter -I ZInterna-ZExterna 1 -m mark --mark 99 -j DROP\\ \\ **\\ Anexo 4**\\ ---------------------------------------------------------------------\\ /etc/squid/squid.conf\\ ---------------------------------------------------------------------\\ acl manager proto cache_object\\ acl localhost src 127.0.0.1/32 ::1\\ acl localnet src 192.168.199.1-192.168.199.5\\ acl portal src 192.168.199.6-192.168.199.20\\ acl clean src 192.168.199.21-192.168.199.253\\ acl SSL_ports port 443\\ acl SSL_ports port 10000\\ acl SSL_ports port 563\\ acl SSL_ports port 873\\ acl Safe_ports port 80    81    # http\\ acl Safe_ports port 21        # ftp\\ acl Safe_ports port 443        # https\\ acl Safe_ports port 10000    # webmin\\ 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 Safe_ports port 631        # cups\\ acl Safe_ports port 873        # rsync\\ acl Safe_ports port 901        # SWAT\\ acl CONNECT method CONNECT\\ http_access deny !Safe_ports\\ http_access deny CONNECT !SSL_ports\\ http_access allow localhost manager\\ http_access deny manager\\ http_access allow localnet\\ http_access allow localhost\\ http_access allow clean\\ external_acl_type session_active_def concurrency=100 ttl=3 %SRC /usr/lib/squid3/ext_session_acl -a -T 10800 -b /var/lib/squid/session/\\ acl session_is_active external session_active_def\\ http_access deny CONNECT !session_is_active\\ deny_info http:%%//%%192.168.199.254:8080/sktimer/webservices/external-client/login-client.php?url=%u session_is_active\\ http_access deny !session_is_active\\ http_access allow portal\\ http_access deny all\\ http_port 3128\\ http_port 3129 transparent\\ coredump_dir /var/spool/squid3\\ refresh_pattern ^ftp:        1440    20%    10080\\ refresh_pattern ^gopher:    1440    0%    1440\\ refresh_pattern -i (/cgi-bin/|\\?) 0    0%    0\\ refresh_pattern .        0    20%    4320\\ \\ \\ \\ \\   ==============================================================