SAI CHARAN KATKAM
SAI CHARAN KATKAM

Reputation: 9

I need to inject the code with eval() function to complete my task, do i need to changes in eval() funcction?

I need to complete this task, please see the below comments, You are calling the hack() function in your text files which is a good start. The goal of the task inject the hack() function into the Python programs. To do this you need to have a look at the last line of code in Python files, this is where the eval() function is. The eval() function converts a string into lines of code, so you should structure the values that you write in your text files in a way that looks like a line of code with additional formatting.

hack1.py file

import os
from vulnerability import hack

def login(username):
    users = ['Nkoli', 'Hyperion', 'Ori', 'Tony']
    if username in users:
        return f"Welcome, {username}."
    else:
        return ""


print("This code will log a username in")

if os.path.exists("hack3.txt"):
    with open("hack3.txt", 'r') as in_file:
        user_input = in_file.read()

else:
    user_input = input("Enter your username\n: ")
// Then, we run the code
print(eval(f"login('{user_input}')"))

# hack1.txt

hack()

Upvotes: 0

Views: 688

Answers (0)

Related Questions