Yuri Slobodyanyuk Blog on Information Security 2024年09月12日
Checkpoint – back up centrally for recovery.
index_new5.html
../../../zaker_core/zaker_tpl_static/wap/tpl_guoji1.html

 

文章介绍了一种通过设置高度安全的服务器,定期运行脚本备份客户端防火墙的方法,包括其原理、优势、劣势及具体脚本内容。

🎯通过设置安全服务器并运行脚本备份防火墙,利用SSH连接远程防火墙,执行upgrade_export命令,使用SCP下载备份并删除原备份。此方法可解决手动备份的繁琐问题,适用于多防火墙的情况。

💪这种备份模式的优势在于服务器安全性更高,无远程可访问服务运行,减少远程攻击可能;可在服务器前设置防火墙规则;集中管理备份脚本,便于修改。

🚫然而,该方法的劣势是进入防火墙的密码以明文形式存储在脚本中。

📄文中详细介绍了备份脚本的内容,包括设置超时时间、密码、用户名、文件命名格式等,以及一系列的操作命令和流程。

Backing up firewall configs for disaster recovery  is tedious and mundane task. And if you have enough firewalls doing it manually becomes impractical . To address this case I set up a highly secured server that periodically runs script backing up the clients’ firewalls.

I use here poll model – this central server connects by SSH to the remote firewalls ,issues upgrade_export command then downloads backup using SCP and finally deletes the backup from the firewall itself.
Advantage of such a schema as opposed to the push model where firewalls push backups to the central server I see in that:
 - I can secure this server much more as no remotely accessible services are running (so no remote exploit is possible)
 - I can have rule in firewall before this server Inbound - > Deny Any Any
 - I centrally manage the backup script , if something changes I fix just one script .
Disadvantage – password to enter the firewalls is stored clear text in the script.
Now to the script – I did it in Expect to make life easier , in short it just emulates interactive login by SSH, then runs upgrade_export command, downloads by SCP the backup file, also creating file with md5sum of the backup and downloading it as well. The final action is to login by SSH back and remove the backup file from the firewall.
It names file by adding current date to the IP of the firewall. No error checking is done. Files used in script:
hosts  - file containing IPs of the firewalls to backup in the form one per line .

The script goes next (at the end you can download script as file to fix lines wrapping):

#!/usr/local/bin/expect#set timeout to suffice for the largest backup file to downloadset timeout 3000 #set password to enter the firewallset password passwordset username  admin#set format for naming filesset timeand_date [clock format [clock seconds] -format %B-%Y-%m-%d]#open hosts file that contains IPs of the firewalls and read it in a loopset ff [open "hosts" r]while {[gets $ff hostName] >= 0} {  puts "Entering $hostName" spawn ssh -l $username $hostName expect {        {[Pp]assword:} { send "$password\r" } "(yes*no)" { send "yes\r"              expect {[Pp]assword:} { send "$password\r" }}} #increase timeout of SSH session expect {*#}  { send "TMOUT=900\r" } expect {*#}  { send "export TMOUT\r"}#Create backup directory expect {*#}  { send "mkdir /var/Upgrade_export_backups\r"  } expect {*#}  { send "cd /var/Upgrade_export_backups\r"  }#Issue the upgrade_export command expect {*#}  {   send "\$FWDIR/bin/upgrade_tools/upgrade_export $timeand_date$hostName\r"  }   expect {{ready} { send "\r"      } {(y/n) [n]} { send "yes\r" }}#Calculate md5sum of the newly created backup file and save it to fileexpect {*#} {send "md5sum $timeand_date$hostName.tgz > $timeand_date$hostName.md5sum\r"} expect {*#} {  send "exit\r"}  spawn  scp  [$username@$hostName:/var/Upgrade_export_backups/\{$timeand_date$hostName.md5sum,$timeand_date$hostName.tgz\](mailto:$username@$hostName:/var/Upgrade_export_backups/\{$timeand_date$hostName.md5sum,$timeand_date$hostName.tgz\)}    .expect {        {[Pp]assword:} { send "$password\r" }} expect {#}   { #send "exit\r"}  spawn ssh -l $username $hostName expect {        {[Pp]assword:} { send "$password\r" } "(yes*no)" { send "yes\r"              expect {[Pp]assword:} { send "$password\r" }}} #remove created backup file expect {*#}  { send "cd /var/Upgrade_export_backups\r"  }   expect {*#}  {   send "rm -f $timeand_date$hostName.tgz\r"  } expect {*#}  { send "exit\r"  }  }close $ff interact

Script as a file

Follow me on https://www.linkedin.com/in/yurislobodyanyuk/ not to miss what I publish on Linkedin, Github, blog, and more.

Fish AI Reader

Fish AI Reader

AI辅助创作,多种专业模板,深度分析,高质量内容生成。从观点提取到深度思考,FishAI为您提供全方位的创作支持。新版本引入自定义参数,让您的创作更加个性化和精准。

FishAI

FishAI

鱼阅,AI 时代的下一个智能信息助手,助你摆脱信息焦虑

联系邮箱 441953276@qq.com

相关标签

防火墙备份 安全服务器 备份脚本 优势与劣势
相关文章