During my years in the networking business one of my frustrations is that it is very hard to backup the configuration of an ASA. There are some commercial products like Solarwinds that can accomplish this goal, but it costs money. An open source alternative like Rancid is also available but is pretty hard to configure.
Determined to find a solution I started searching the internet and came across some PowerShell scripts. I’m not a PowerShell specialist, but I do know how to put together the separate scripts. So to be clear, I did not invent the scipts I just put them together.
So let’s take a look at the script:
Read-Host “Enter Password” -AsSecureString | ConvertFrom-SecureString | Out-File c:\<map>\cred01.txt
–I don’t want to sent the password of the ASA user plain over the network. So with the above line I make sure the password is encrypted. It is possible to convert the password back to plain text, but then you’ll need access to the server. So it is not rocksollid save, but safer then sending the password in plain text over the internet. If you make sure that the useraccount only has minimal rights on the ASA, there is minimal change of getting unwanted guests on your ASA. The line converts the plain password to an encrypted password and writes it to a .txt file.
$ASApw = Get-Content “c:\<map>\cred01.txt” | ConvertTo-SecureString #-AsPlainText #-Force
$BSTR = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($ASApw)
$ASApw = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR)
–The above three lines are needed to convert the encrypted password from the credentials file. This is needed because the ASA is unable to read an encrypted password.
$ASAIP = “<ip address>”
$ASAUser = “<username>”
$ASAEnablepw = $ASApw
#Modifies the ASA firewall
#Starts by writing a “commands” file#
echo en >>
echo $ASAEnablepw >>
echo “conf t” >>
echo “no pager” >>
echo “show run” >>
echo “pager 24” >>
echo “copy running-config startup-config” >>
echo “running-config” >>
echo exit >>
echo exit >>
#Converts the file to ASCII format (separate file)#
$lines = gc “ ”
$lines | out-file -encoding Ascii -filepath
–The above lines writes the actual ASA commands to the file.
#Using the command file and
c:/Windows/System32/ -ssh -l $ASAUser -pw $ASApw $ASAIP -m > “c:\<map>\ ”
–To make things work you need to download the Plink tool. It is the command line version of Putty. It can be downloaded for free. I put the tool in de c:\windows\system32 folder, but you can place it everywhere you want. This line writes the configuration of the ASA to an .txt file.
#removes the files it created earlier#
As you can see it’s actually a pretty easy script an above all it’s free.
To make a daily backup, create a task through “Task scheduler”.