Skip to content

Instantly share code, notes, and snippets.

@namidairo
Last active February 21, 2023 21:18
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save namidairo/bc2533dc99cf580ed9050dcd29591102 to your computer and use it in GitHub Desktop.
Save namidairo/bc2533dc99cf580ed9050dcd29591102 to your computer and use it in GitHub Desktop.
Re-implementation of miwifi router update check.
import requests
import datetime
import base64
import hashlib
# Dummy values, countryCode required if querying EU servers
# Most important here are the hardware and channel
params = {
#"countryCode": "EU",
"deviceID": "",
"rom": "0.0.1",
"hardware": "RB03",
"cfe": "",
"linux": "0.0.1",
"ramfs": "0.0.1",
"sqafs": "0.0.1",
"rootfs": "0.0.1",
"channel": "release",
"serialNumber": "",
}
# Default server: http://api.miwifi.com, EU servers: http://eu.api.miwifi.com
server = "http://api.miwifi.com"
recoveryURL = "/rs/grayupgrade/recovery"
normalUpgradeUrl = "/rs/grayupgrade"
default_token = "8007236f-a2d6-4847-ac83-c49395ad6d65"
def main():
# Constuct initial sub url based on params
sub_url = recoveryURL + "?"
for key, value in params.items():
sub_url += key + "=" + value + "&"
# Add time to params formatted as %Y-%m-%d--%X
timestr = datetime.datetime.now().strftime("%Y-%m-%d--%X")
params["time"] = timestr
# Get sorted params list
sortedParams = sorted(params.items(), key=lambda x: x[0])
# Loop through sorted params to create params string
paramsString = ""
for item in sortedParams:
paramsString += item[0] + "=" + item[1] + "&"
# Append default token to paramsString
paramsString += default_token
# Create signature of paramsString (md5 with base64 contents)
signature = hashlib.md5(base64.b64encode(paramsString.encode('utf-8'))).hexdigest()
# Construct url
url = server + sub_url + "s=" + signature + "&time=" + timestr + "&token=" + default_token
print("URL: " + url)
# Set user agent to "miwifi-", similar to their recovery process
headers = {'User-Agent': 'miwifi-'}
# Make request with url and headers
response = requests.get(url, headers=headers)
# Print response details
print("Status code: " + str(response.status_code))
print("Response: " + response.text)
if __name__ == "__main__":
main()
@tiagoad
Copy link

tiagoad commented Feb 21, 2023

Thank you!

For RB01 (AX3200) it worked to simply uncomment "countryCode": "EU", changing hardware to RB01 and server = "http://eu.api.miwifi.com"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment