Skip to content

Instantly share code, notes, and snippets.

@eyJhb
Last active July 13, 2018 16:30
Show Gist options
  • Save eyJhb/77d920c29e330a24d35bc6ce4d27848d to your computer and use it in GitHub Desktop.
Save eyJhb/77d920c29e330a24d35bc6ce4d27848d to your computer and use it in GitHub Desktop.
Simple bash script to login on a pfsense router to download the configuration and save it as a file for backups
#!/bin/bash
username="backup"
password="password"
router_ip="https://192.168.1.1"
backup_location="/tmp"
csrf=$(wget -qO- --keep-session-cookies --save-cookies cookies.txt \
--no-check-certificate $router_ip/diag_backup.php \
| grep "name='__csrf_magic'" | sed 's/.*value="\(.*\)".*/\1/')
csrf=$(wget -qO- --keep-session-cookies --load-cookies cookies.txt \
--save-cookies cookies.txt --no-check-certificate \
--post-data "login=Login&usernamefld=$username&passwordfld=$password&__csrf_magic=$csrf" \
$router_ip/diag_backup.php | grep "name='__csrf_magic'" \
| sed 's/.*value="\(.*\)".*/\1/')
wget --keep-session-cookies --load-cookies cookies.txt --no-check-certificate \
--post-data "download=download&donotbackuprrd=yes&__csrf_magic=$csrf" \
$router_ip/diag_backup.php -O $backup_location/pfsense-`date +%Y-%m-%d`.xml
rm cookies.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment