Inj3ct0r
Inj3ct0r

Reputation: 65

Python - while input doesn't work

Why doesn't this work? I input windows/meterpreter/reverse_tcp and it returns the error...again

def shellcode():
    os.system("clear")
    print style
    print green + "  [+]Your Choose 4 | C Type Format - ShellCode Generate"
    print style
    print payload_types
    print ' '
    payload_choose = raw_input(time + white + "Choose Payload > ")
    while (payload_choose != "windows/meterpreter/reverse_tcp" or "linux/x86/meterpreter/reverse_tcp"):
        print "[-]error"
        payload_choose = raw_input(time + white + "Choose Payload > ")
    print "ok"

Upvotes: 0

Views: 124

Answers (1)

user94559
user94559

Reputation: 60143

This line:

while (payload_choose != "windows/meterpreter/reverse_tcp" or "linux/x86/meterpreter/reverse_tcp"):

probably doesn't do what you want. I think you probably meant this?

while payload_choose != "windows/meterpreter/reverse_tcp" and payload_choose != "linux/x86/meterpreter/reverse_tcp":

Further explanation

This expression:

a or b

means "a is true or b is true".

This expression:

foo != 'hello' or 'goodbye'

means "(foo != 'hello') is true or 'goodbye' is true". In Python, a non-empty string is considered "truthy", so your original while loop condition is always true.

Upvotes: 4

Related Questions