hidden = random.random()
val = input("Guess the value of the randomly generated number. ")
if float(val) == hidden:
print("You got it!")
else:
print("Sorry. You missed.")
Hey Guys, Is there a way to exploit this raw input, and leak the value of the variable "hidden" from within the program? In other words, could you execute a line of code from the input alone? I tried format string attacking the program, but it didn't work. Note: You cannot change the code.
Any suggestions?
In Python 2, yes, because you didn't use
raw_input
, you usedinput
. So you can type "hidden" at the prompt and magically get it right (because it evaluates the value of the variable calledhidden
):In Python 3, no, because
input
now does whatraw_input
used to do, which is treat the value only as a string, to avoid this sort of sneakiness.