Skip to content

Instantly share code, notes, and snippets.

@Tugzrida
Last active September 21, 2019 06:48
Show Gist options
  • Save Tugzrida/83f9118b13d6b49769eb89f18eeaf48e to your computer and use it in GitHub Desktop.
Save Tugzrida/83f9118b13d6b49769eb89f18eeaf48e to your computer and use it in GitHub Desktop.
Python routine to get a session ID from a FRITZ!Box
#!/usr/bin/env python
# Simple python2/3 routine to get a SID from a FRITZ!Box as it took me forever to figure this out
# If you don't have https set up, set the urls to http and remove the two verify options
# If you do have https set up, point the two verify options to the CA cert
# (unless your FB cert is publicly signed, then remove the verify options)
from requests import get
from xml.etree import ElementTree
from hashlib import md5
username = "YOUR_USER"
password = "YOUR_PASSWORD"
challenge = ElementTree.fromstring(get("https://fritz.box/login_sid.lua", verify='/path/to/cert.pem').text)[1].text
hash = md5("{}-{}".format(challenge, password).encode("UTF-16LE")).hexdigest()
response = "{}-{}".format(challenge, hash)
print(ElementTree.fromstring(get("https://fritz.box/login_sid.lua?username={}&response={}".format(username, response), verify='/path/to/cert.pem').text)[0].text)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment