← Back to challenges

Injection IV: Inside the Function

PythonHarddata_structuresgameslogic

Instructions

The bookstore from [this collection] (https://innokodakademija.com/collection/dnXtkLPZpX25t227q) is adamant in using eval(), but has moved the users dictionary into a function to prevent copying. The exists() function returns entries in users which match a given username. Create a query that copies users to res.

Examples

from re import *

param = "your text here"

def exists(name):
  users = {
    "alice": "password",
    "bob": "password"
  }
  if not name.isalnum():
    return {"Error": "No users found."}
  return {
    k:users[k] for k in users
    if type(search("^%s$" % name, k)).__name__ == "SRE_Match"
  }

res = eval("search("%s")" % param)

print(res) ➞ users

Notes

  • Create a string, not a function.
  • Anything present in the Tests tab exists() function which doesn't appear here is test related and irrelevant.
  • Assume you know nothing about the usernames in the database.
  • For readability, try to break your string into smaller substrings.
python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.