0

I have over 100 different parameters that will be tested against a single variable. But I am having trouble assigned the parameters as variables. For example: The parameters are as follows:

/master.passwd
etc/passwd
etc/shadow%00
/etc/passwd
/etc/passwd%00
../etc/passwd
../etc/passwd%00
../../etc/passwd
../../etc/passwd%00

and each parameter will be added to a variable named

tree 

How can I use python to assign one variable to 100's of parameters and than add each parameter to the variable named tree? I have looked at list[], dict{}, and a tuple() but I am not coming up with a solution.

Code example

1
  • The best data type to use depends on what you're going to do with the data. How are you going to use it, modify it, relate it to other data or itself, output it? Commented Nov 11, 2015 at 18:22

1 Answer 1

2

It sounds like you want to iterate over a bunch of strings and do something with them? One way of doing this is to use a list:

url='https://10.10.20.161/IHUD/'
parameters = ["master.passwd",
    "etc/passwd",
    "etc/shadow%00",
    "/etc/passwd",
    "/etc/passwd%00",
    "../etc/passwd",
    "../etc/passwd%00",
    "../../etc/passwd",
    "../../etc/passwd%00"]

for p in parameters:
    tree = url + p
    print(tree)

Outputs:

https://10.10.20.161/IHUD/master.passwd
https://10.10.20.161/IHUD/etc/passwd
https://10.10.20.161/IHUD/etc/shadow%00
https://10.10.20.161/IHUD//etc/passwd
https://10.10.20.161/IHUD//etc/passwd%00
https://10.10.20.161/IHUD/../etc/passwd
https://10.10.20.161/IHUD/../etc/passwd%00
https://10.10.20.161/IHUD/../../etc/passwd
https://10.10.20.161/IHUD/../../etc/passwd%00
Sign up to request clarification or add additional context in comments.

6 Comments

Yes, I am trying to iterate over a bunch of strings but the problem with the list[] I am getting the output with a bunch of '' attached to my strings as show ['master.passwd', 'etc/passwd', 'etc/shadow%00', '/etc/passwd', '/etc/passwd%00', '../etc/passwd', '../etc/passwd%00', '../../etc/passwd', '../../etc/passwd%00'] @Galax
If you write print(parameters) you'll see something like: ['master.passwd', 'etc/passwd', 'etc/shadow%00', '/etc/passwd', '/etc/passwd%00', '../etc/passwd', '../etc/passwd%00', '../../etc/passwd', '../../etc/passwd%00'] Can you show the code you are using as it may help to explain the problem you are having a little better.
I just added a screenshot to my question @Galax. So after I have defined the parameter to the variable tree, the output format needs to look like: url + tree 10.10.20.161/IHUD/etc/passwd for each parameter
I've updated my code, the problem with your screenshot is that str(parameters) converts the list to a string representation of a list, with all the [, and '.
I see now! So p can be seen as a variable in the list parameters defining each parameter in the list? I just want to make sure my interpretation is right.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.