如何利用此代码获得管理员访问权限?

How do I get admin access by exploiting this code?

我正在参加比赛,我无法完成这个任务。 objective 是在不知道密码的情况下使用机密字典中列出的不同帐户登录。 不允许更改代码。 例如,您可以使用以下输入以访客身份登录:

anything
0

和用户:

user
-1

我不知道如何使用管理员登录。

#!/usr/bin/python3
# Change the pin codes here before using this software:
secrets = {
    "guest": 123456,
    "user": 123456,
    "admin": 123456
    }

def authenticate():
  selected_user = input("Enter your username: ")

  if selected_user.lower() == "admin":
    print("Administrator access is disabled on this interface!")
    return None

  real_user = "guest"
  real_pin = 0

  for (user, pin) in secrets.items():
    if user.upper() == selected_user.upper():
      real_user = user
      real_pin = pin

  try:
    pin_as_string = input("Enter your PIN code: ")
    selected_pin = int(pin_as_string)
  except:
    print("Some error occured while reading PIN code, please try again!")
    return None

  if not pin_as_string.isdigit():
    print("Warning: the PIN contains a non-digit character!")

  elif selected_pin != real_pin:
    print("Incorrect PIN code!")
    return None

  return real_user

user = authenticate()
if user is not None:
  print("Successful login as", user)

您想要一个映射到大写字母 "ADMIN" 的字符。要Python很容易:

lst = []
for i in range(0xffff):
    try:
        c = chr(i)
        if c.upper() in "ADMIN": print(hex(i), c, c.lower())
    except Exception as e:       # don't break if any exception
        print(i, "->", e)

你得到

0x41 A a
0x44 D d
0x49 I i
0x4d M m
0x4e N n
0x61 a a
0x64 d d
0x69 i i
0x6d m m
0x6e n n
0x131 ı ı

这个有趣的值是最后一个:U+0131,根据 unicodedata 模块,它是 LATIN SMALL LETTER DOTLESS I

在 Microsoft Windows 中,此字符存在于代码页 850 中:print(chr(0x131).encode('cp850')) 给出 b'\xd5'。所以序列 Alt Num 2 Num 1 Num 3将允许在控制台中输入它(hex(213)'0xd5')。 +1 或 -1 作为密码就可以了!从我自己的控制台:

Enter your username: admın
Enter your PIN code: +1
Warning: the PIN contains a non-digit character!
Successful login as admin

不确定其他系统,但维基百科上的 Unicode input 可能会有所帮助。