Last active
October 19, 2019 01:42
-
-
Save dlangille/f68c562ea6767b2a9b82c9406e28b0c8 to your computer and use it in GitHub Desktop.
using pam_exec to send pushover.net notifications of all logins (ssh, scp)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Credit to @feldpos for providing the original version of this file, designed for inclusion into a .bashrc etc file | |
$ ls -l /etc/pam.d/pushovernet.sh | |
-rwxr-xr-x 1 root wheel 485 Mar 22 14:48 /etc/pam.d/pushovernet.sh | |
$ cat /etc/pam.d/pushovernet.sh | |
#!/bin/sh | |
(if [ "${PAM_SM_FUNC}" == "pam_sm_open_session" ]; then | |
P_KEY="YOUR USER KEY HERE" | |
P_TOKEN="YOUR APP TOKEN HERE" | |
P_MSG="${PAM_USER} logged in to $(hostname) from ${PAM_RHOST} via ${PAM_SERVICE}" | |
P_DATE=`date +%s` | |
P_TITLE="Logins" | |
nohup /usr/local/bin/curl -q -s \ | |
--form-string "token=$P_TOKEN" \ | |
--form-string "user=$P_KEY" \ | |
--form-string "message=$P_MSG" \ | |
--form-string "timestamp=$P_DATE" \ | |
--form-string "title=$P_TITLE" \ | |
https://api.pushover.net/1/messages.json > /dev/null 2>&1 & | |
fi) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add this line to the bottom of /etc/pam.d/sshd | |
session optional pam_exec.so /etc/pam.d/pushovernet.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Login: dan logged in to empty.int.unixathome.org from 10.1.1.1 via sshd |
Using ubuntu? Replace:
if [ "${PAM_SM_FUNC}" == "pam_sm_open_session" ]; then
With:
if [ "${PAM_TYPE}" == "open_session" ]; then
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
you could dump the parameters into a tmpfile which you immediately delete or possibly pass them via stdin to prevent that. seems more effort than it's worth, though. an attacker can not do much but annoy you with messages.