[SOLUCIONADO]pfSense – Notificar via email Alerta de acceso a shell interactiva
-
Hola
Para notificar vía email acceso a una shell interactiva, hago esto:
Edito /etc/rc.initial y añado al comienzo (después de los comentarios # )
echo "Acceso a shell :" `date` `who` | /usr/local/bin/php /usr/local/bin/mail.php -s"`hostname` Alerta de acceso a shell" logger -f /var/log/system.log "Notificado acceso a shell via email - `who`"
quedando como
#!/bin/sh
# /etc/rc.initial
# part of pfSense by Scott Ullrich
# Copyright (C) 2004-2011 Scott Ullrich, All rights reserved.
# originally based on m0n0wall (http://neon1.net/m0n0wall)
# Copyright (C) 2003-2004 Manuel Kasper mk@neon1.net.
# All rights reserved.# make sure the user can't kill us by pressing Ctrl-C,
# ctrl-z, etc.
#trap : 2
#trap : 3
#trap : 4echo "Acceso a shell :"
date
who
| /usr/local/bin/php /usr/local/bin/mail.php -s"hostname
Alerta de acceso a shell"
logger -f /var/log/system.log "Notificado acceso a shell via email -who
"if [ -f /etc/rc.local ]; then
RCLOCALPWD=`ps awux | grep rc.local | grep -v grep | awk '{ print $2 }'
# continueMe funciona bien.
Pero, para sesiones no interactivas, (como ejecución remota de comandos vía script vía cliente ssh como plink) Como hacerlo?
Salu2
(referencias
post en inglés: https://forum.pfsense.org/index.php?topic=112305.0
blog: https://www.javcasta.com/pfsense-notificar-via-email-alerta-de-acceso-a-shell/
) -
Hola.
Encontré una solución a:
pfSense – Notificar via email Alerta de acceso a shell interactiva y NO interactiva.
Procedimiento:
-Condición necesaria: Tener configurado y operativo: System > Advanced > Notifications > E-Mail
Se crea (o se modifica si existiese) el fichero sshrc en /etc/ssh ( /etc/ssh/sshrc ) con el contenido:
ipfrom=`echo $SSH_CONNECTION | cut -d " " -f 1` ippf=`echo $SSH_CONNECTION | cut -d " " -f 3` theport=`echo $SSH_CONNECTION | cut -d " " -f 4` echo "User $USER just logged in from $ipfrom to $ippf at port $theport || date: `date` || who: `who`" | /usr/local/bin/php /usr/local/bin/mail.php -s"`hostname`"
Y ya sea por un login vía SSH interactivo (con shell) o no interactivo (sin shell, como cuando se ejecuta un comando remoto vía ssh), el sistema nos enviará un e-mail con los datos:
User root just logged in from 10.2.0.10 to 10.2.0.254 at port 22 || date: Wed Mar 22 15:58:25 CET 2017 || who: root ttyv0 Mar 14 13:23
root pts/0 Mar 22 15:51 (10.2.0.10)
Salu2
-
Muy interesante
-
-
Hola.
¿Alguien sabria cómo hacer lo mismo pero para notificar comienzo de sesiones WEB GUI (notificar logins desde http y https )?
No es buena idea tocar el fichero /usr/local/www/index.php , pero pfSense notifica los inicios de sesión http/https a la shell, ¿Donde está el servicio o disparador o script que lo notifica a la consola?.
Bueno, ya me enteraré… ;)
Salu2