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

2024-04-29 04:52:30 发布

您现在位置:Python中文网/ 问答频道 /正文

在上下文中,我试图为TryHackMe“Dogcat”LFI CTF创建一个脚本,我已经能够通过LFI/Log中毒漏洞注入命令,但现在我希望能够过滤掉响应

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

HTML输出

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

Tags: logmozillaindexaccessstylehtmlcontentfirefox
1条回答
网友
1楼 · 发布于 2024-04-29 04:52:30

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

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

使用[\S\S]时,您包括了所有内容,当您使用该词时,非常重要的一点是使用一个不急于使用的量词?之后*

相关问题 更多 >