Python 2 Vulnerabilities
The Python 2 input() function evaluates user-supplied text as Python code rather than treating it as a plain string. An attacker could supply a variable name to bypass a password check or supply an expression to execute code, potentially leading to remote code execution.
Published on infosecwriteups.com
The Python Programming Foundation has issued a statement announcing that they have chosen to retire Python2 on January 1, 2020, effective immediately.
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the use of Python 2's input() function, which evaluates user input as Python code instead of returning it as a string.
Impact
An attacker could bypass authentication checks and, by supplying code that imports the os module, execute commands on the server, leading to remote code execution.
What the attacker needed
Application uses Python 2 input(); attacker can supply input to the application
The fix
Applications should use raw_input() instead of input() in Python 2, or migrate to Python 3 where input() behaves like raw_input().
How it was found
- Create a Python 2 script that uses input() to read a password and compares it to a hard-coded value.
- Run the script and, when prompted, enter the name of the variable that holds the password.
- Observe that the script prints 'Login successful' without the correct password.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
In Python 2, the input() function does not just read text; it runs the text as if it were part of the program. So if a program asks for a password and you type the name of a variable that holds the real password, the program compares the password to itself and lets you in. You can also type code that the program will run, which is dangerous.
What is RCE?
Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.