简体   繁体   English

Python 正则表达式 - 查找不同行上两个特定单词之间的所有单词

[英]Python Regular Expression - Find all words between two specific words on different lines

for context I am attempting to create a script for the TryHackMe 'Dogcat' LFI CTF, I have gotten so far as to being able to inject commands via the LFI / Log Poisoning vulnerability but now I want to be able to filter out the response.对于上下文,我正在尝试为 TryHackMe 'Dogcat' LFI CTF 创建一个脚本,我已经能够通过 LFI / 日志中毒漏洞注入命令,但现在我希望能够过滤掉响应。

The current issue I believe is that the regular expression is failing because of the way the files are returned in the HTML and I can't seem to find out how to get it to work, any help is greatly appreciated (example below)我认为当前的问题是正则表达式失败,因为文件在 HTML 中返回的方式,我似乎无法找到如何让它工作,非常感谢任何帮助(下面的示例)

HTML OUTPUT HTML OUTPUT

<ip> - - [10/Jun/2020:07:41:20 +0000] "GET / HTTP/1.1" 200 537 "-" "Mozilla/5.0 access.log
cat.php
cats
dog.php
dogs
flag.php
index.php
style.css
 Firefox/69.0"

PYTHON PYTHON

response = request.get(url+"/?view=php://filter/dog/resource=/var/log/apache2/access.log&ext"+cmd+command)
    html_content = response.text


    test = "Mozilla/5.0 access.log cat.php cats dog.php dogs flag.php index.php style.css Firefox/69.0"
    #The Test works but the real content doesn't, likely something to do with the new lines after each file.

    output = re.findall("Mozilla/5.0 (.*?) Firefox/69.0", html_content)

    try:
        print(output)
    except:
        print("There was an error.")

If you use the dot in regular expressions it does not includes line breaks.如果您在正则表达式中使用点,则它不包括换行符。 And remember that dots from 5.0 or 69.0 are being considered "any character" too, it should be scaped.请记住,来自 5.0 或 69.0 的点也被视为“任何字符”,应该将其转义。 Try this regex:试试这个正则表达式:

Mozilla/5\.0 ([\S\s]*?) Firefox/69\.0

With [\S\s] you are including everything, when you use that it is very important to use a not eager quantifier with the?使用 [\S\s] 你包括了一切,当你使用它时,使用一个不急切的量词是非常重要的? after *.后 *。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM