簡體   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