I understand that relying on Python 2's built-in input()
function (as opposed to raw_input()
, which was renamed to input()
in Python 3) is prone to security bugs. In this question, I'm trying to determine how to demonstrate this class of vulnerability.
Specifically, I'm trying to determine how to generate input to the code below which will cause "Access granted" to be emitted, without modifying the program itself, only by changing the value passed to stdin in response to the input()
call.
import random
pass_true = input("What is the password?")
password = random.randint(0,2**30)
if password == pass_true:
print("Access granted.")
else:
print ("Access denied.")
If the random number were generated before the input call (that is, if the second and third lines were switched), one could merely enter pass_true
as the string, which would subsequently be evaluated to the value of the variable by that name -- but since the random number isn't yet known at the input()
invocation, this approach doesn't work.