BugScanTeam / GitHack

.git 泄漏利用工具,可还原历史版本
GNU General Public License v3.0
722 stars 150 forks source link

修复 windows 中读取 user-agents.txt 存在 \r 的问题 #4

Closed restran closed 7 years ago

restran commented 7 years ago

Windows 使用 \r\n 换行,未对读取的 user-agents.txt 内容做过滤,没有去掉每行最后的 \r,在 /lib/request/request_data 函数中,会因为设置的 UserAgent 存在 \r 而出现异常。

initAgents

def initAgents():
    data = readFile(paths.USER_AGENTS).split("\n")
    data = [t.rstrip('\r').strip() for t in data]
    agents.extend(data)

request_data

def request_data(url):
    for i in range(3):
        data = None
        try:
            request = urllib2.Request(url, None, {'User-Agent': randomAgent()})
            data = urllib2.urlopen(request).read()
            if data:
                return data
        except Exception, e:
            if DEBUG:
                logger.warning("Request Exception: %s" % str(e))
    return None
howmp commented 7 years ago
>>> a = '111\r\n222'
>>> a.split("\n")
['111\r', '222']
>>> a.splitlines()
['111', '222']
>>>

建议使用splitlines()

restran commented 7 years ago

@howmp 赞

def initAgents():
    data = readFile(paths.USER_AGENTS).splitlines()
    data = [t.strip() for t in data if t.strip() != '']
    agents.extend(data)

改成这样,把空格的行也去掉?