I am making a SSRF scanner by python but I don't know much about 'sys.argv' in python. Here is my code and it doesn't work when I running(python3):
class targets: def __init__(self, url, ip, port, method, param, error): self.url = url self.ip = ip self.port = port self.method = method self.param = param self.er = error def scan(target): print("Success!") print(target.url) print(target.method) print(target.ip) for carg in sys.argv: target = targets('', '', '', '', '', "Please enter a valid command. If you don't know how to use it, enter '-help'") if "-u" in carg: argnum = sys.argv.index(carg) argnum += 1 target.url = sys.argv[argnum] if "-g" in carg: argnum += 1 target.method = "g" if "-i" in carg: argnum = sys.argv.index(carg) argnum += 1 target.ip = sys.argv[argnum] if "-pt" in carg: argnum = sys.argv.index(carg) argnum += 1 target.port = sys.argv[argnum] if "-p" in carg: if not "-pa" in carg: print("Please enter the parameters of request(POST)") quit argnum += 1 target.method = "p" if "-i" in carg: argnum = sys.argv.index(carg) argnum += 1 target.ip = sys.argv[argnum] if "-p" in carg: argnum = sys.argv.index(carg) argnum += 1 target.port = sys.argv[argnum] else: print(target.er) quit target.scan() elif carg == "-help": tuto = open("tutorial.dat", "r") tuto.read() tuto.close print(tuto) else: print(target.er) After running this code: ssrf.py -u google.com -g -i 123.123.123.123
I receive back this:
Please enter a valid command. If you don't know how to use it, enter '-help' Please enter a valid command. If you don't know how to use it, enter '-help' Success! google.com Please enter a valid command. If you don't know how to use it, enter '-help' Please enter a valid command. If you don't know how to use it, enter '-help' Please enter a valid command. If you don't know how to use it, enter '-help' Please enter a valid command. If you don't know how to use it, enter '-help' That not the thing I am waiting for:
Success! google.com g 123.123.123.123 Can anyone tell me what wrong in this code!(Sorry if this is a stupid question and sorry if bad English)
sys.argvis a list of strings. So each element ofsys.argv(e.g.carg) is just a string. So you probably don't want to do things likeif "-u" in carg, but instead just doif carg == "-u". This should all be very easy to debug. Just print outsys.argvandcargand it should be immediately obvious where you're going wrong.