Created
June 26, 2019 23:57
-
-
Save jasonneurohr/318291445cac8cf3469ec97b165d8bda to your computer and use it in GitHub Desktop.
Simple Python script to backup a Cisco Expressway
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
import requests | |
import json | |
import re | |
def main(): | |
URL = "https://10.1.1.1" # UPDATE | |
USERNAME = "admin" | |
PASSWORD = "password" # UPDATE | |
BACKUP_PASSWORD = "password" # UPDATE | |
sessionid = "" | |
# Setup Session | |
s = requests.Session() | |
# Login | |
r = s.post( | |
url=f"{URL}/login", | |
data={ | |
"submitButton": "Login", | |
"username": USERNAME, | |
"password": PASSWORD, | |
"formbutton": "Login", | |
}, | |
headers={"Referer": f"{URL}/login"}, | |
verify=False, | |
) | |
# Load Backup and restore page | |
r = s.get(url=f"{URL}/backuprestore", verify=False) | |
# Get the sessionid value | |
# Split the response lines | |
for line in r.text.splitlines(): | |
if re.search(string=line, pattern="sessionid"): | |
line = line.split("/><") | |
line = line[0].split("><") | |
line = re.sub(string=line[1], pattern='"', repl="") | |
sessionid = line.split("value=")[1] | |
break | |
data = f"sessionid={sessionid}&submitbutton=Create+system+backup+file&backup_password={BACKUP_PASSWORD}&backup_password_confirm={BACKUP_PASSWORD}" | |
headers = {"Content-Type": "application/x-www-form-urlencoded"} | |
with s.post( | |
url=f"{URL}/backuprestore", | |
data=data, | |
verify=False, | |
headers=headers, | |
stream=True, | |
) as r: | |
r.raise_for_status() | |
timestamp = datetime.utcnow().strftime("%Y_%m_%d__%H_%M_%S") | |
filename = f"expressway_{timestamp}_backup.tar.gz.enc" | |
with open(filename, "wb") as f: | |
for chunk in r.iter_content(chunk_size=8192): | |
f.write(chunk) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment