From Yuuki, 3 Years ago, written in Python.
Embed
  1. #!/usr/bin/python
  2. # Wii parental control password reset tool
  3. #
  4. # Copyright 2008-2009 Hector Martin Cantero <[email protected]>
  5. #
  6. # This program is free software; you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation; version 2 or version 3 of the License.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. # GNU General Public License for more details.
  14.  
  15. import time
  16. from urllib import parse as urlparse
  17.  
  18. def raw_application(environ, start_response):
  19.     start_response("200 OK", [("Content-type","text/html")])
  20.     yield """<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  21. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  22. <head>
  23. <title>Wii Parental Control Password Resetter</title>
  24. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  25. <style type="text/css">
  26.  
  27. .title {
  28.    font-size: 18pt;
  29.    font-family: sans-serif;
  30. }
  31.  
  32. .response {
  33.    font-size: 16pt;
  34.    font-family: sans-serif;
  35. }
  36.  
  37. .error {
  38.    color: red;
  39.    font-size: 16pt;
  40.    font-family: sans-serif;
  41. }
  42.  
  43.  
  44. </style>
  45. </head>
  46. <body>
  47. <div class="title">Wii Parental Control password reset tool</div>"""
  48.     form = urlparse.parse_qs(environ["QUERY_STRING"])
  49.  
  50.     ctime = time.time()
  51.  
  52.     def opt_date(delta):
  53.         t = time.gmtime(ctime + delta * 3600 * 24)
  54.         if delta == 0:
  55.                 selected = ' selected="selected"'
  56.         else:
  57.                 selected = ""
  58.         return '<option value="%02d%02d" %s>%s</option>'%(t.tm_mon,t.tm_mday,selected,time.strftime("%a, %d %b %Y",t))
  59.  
  60.     class CRC32:
  61.         def __init__(self):
  62.                 self.gentable()
  63.  
  64.  
  65.         def crc32(self, input, crc=0xffffffff):
  66.                 count = len(input)
  67.                 i = 0
  68.                 while count != 0:
  69.                         count -= 1
  70.                         temp1 = (crc >> 8) & 0xFFFFFF
  71.                         temp2 = self.table[(crc ^ ord(input[i])) & 0xFF]
  72.                         crc = temp1 ^ temp2
  73.                         i += 1
  74.                 return crc
  75.  
  76.         def gentable(self):
  77.                 self.table = []
  78.                 for i in range(256):
  79.                         crc = i
  80.                         for j in range(8):
  81.                                 if crc & 1:
  82.                                         crc = (crc >> 1) ^ 0xEDB88320
  83.                                 else:
  84.                                         crc >>= 1
  85.                         self.table.append(crc)
  86.  
  87.     def error(s):
  88.         return '<div class="error">%s</div>'%s
  89.  
  90.     def process():
  91.         try:
  92.                 int(form["number"][0]) #validate
  93.                 if len(form["number"][0]) != 8 or not all([x in "0123456789" for x in form["number"][0]]):
  94.                         raise ValueError()
  95.         except:
  96.                 return error("Please provide a valid 8-digit confirmation number")
  97.  
  98.         try:
  99.                 int(form["date"][0]) #validate
  100.                 if len(form["date"][0]) != 4 or not all([x in "0123456789" for x in form["date"][0]]):
  101.                         raise ValueError()
  102.         except:
  103.                 return error("Invalid date")
  104.  
  105.         fullnum = form["date"][0] + form["number"][0][4:8]
  106.  
  107.         crc = CRC32().crc32(fullnum)
  108.         code = ((crc ^ 0xaaaa) + 0x14c1) % 100000
  109.  
  110.         return '<div class="response">Your unlock code:<span class="code">%05d</span></div>'%code
  111.  
  112.     if "submit" in form:
  113.         yield process()
  114.  
  115.     yield """
  116. <div class="form">
  117.    <form action="/parental">
  118.        <p>Confirmation Number:
  119.                <input name="number" type="text" size="9" maxlength="8" value="" /></p>
  120.        <p>Current Date in your timezone:
  121.                <select name="date" size="1">"""
  122.     yield opt_date(-1)
  123.     yield opt_date(0)
  124.     yield opt_date(1)
  125.     yield """</select><br /></p>
  126.        <p><input name="submit" type="submit" value="Get Reset Code" /></p>
  127.    </form>
  128. </div>
  129. <p>
  130.    <a href="parental_src.py">Source code</a>
  131. </p>
  132.      
  133. </body>
  134. </html>"""
  135.  
  136. def app(*args, **kwargs):
  137.     return (i.encode("utf-8") for i in raw_application(*args, **kwargs))
  138.  
captcha