繁体   English   中英

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

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

对于上下文,我正在尝试为 TryHackMe 'Dogcat' LFI CTF 创建一个脚本,我已经能够通过 LFI / 日志中毒漏洞注入命令,但现在我希望能够过滤掉响应。

我认为当前的问题是正则表达式失败,因为文件在 HTML 中返回的方式,我似乎无法找到如何让它工作,非常感谢任何帮助(下面的示例)

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

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.")

如果您在正则表达式中使用点,则它不包括换行符。 请记住,来自 5.0 或 69.0 的点也被视为“任何字符”,应该将其转义。 试试这个正则表达式:

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

使用 [\S\s] 你包括了一切,当你使用它时,使用一个不急切的量词是非常重要的? 后 *。

暂无
暂无

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

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