1

I want to ask.

  • url = [domaina.com/def, domainb.com/abc, domainc.com/]
  • payload = [abc, def, ghi]

how to call url and payload together using regex if match, for example:

  • domaina.com/abc
  • domaina.com/def

then

  • domainb.com/abc

  • domainb.com/def

    import re
    import csv
    import collections
    
    def log_file_reader(filename):
    
     f = open(filename, "r")
        #log = f.read()
        #payload = a.read() 
     for url in f:
      a = open("xss.txt", encoding='utf-8')
      for payload in a:
       #regex = r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}'
       ip_list = re.findall(payload, url)
       return ip_list
       #print(payload, url)
    
    if __name__ == "__main__":
      log_file_reader('url')
    
3
  • What do you mean by call url and payload together using regex? Judging from your code, the expected result will be the list of url which matches the payload: domaina.com/def and domainb.com/abc, correct? Commented May 24, 2021 at 5:17
  • Yes, the expected results show a list of urls that match the existing payload Commented May 24, 2021 at 5:50
  • Thank you for the prompt feedback. I have posted an answer. I hope it will meet your requirement. Commented May 24, 2021 at 5:59

1 Answer 1

2

Would you please try something like:

def log_file_reader(filename):
    # assuming files are already opened as f and a
    l = []
    for url in f:
        for payload in a:
            if re.search('/' + payload + '$', url):
                l.append(url)
    return l

With the provided examples, it will return:

['domaina.com/def', 'domainb.com/abc']

I have prepended / and appended $ to the string payload to avoid the possible partial match (e.g. ab or ef are given in the payload list).

Sign up to request clarification or add additional context in comments.

Comments

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.