如何使用Python2.7检测危险信号、网络钓鱼或恶意网站?

2024-04-26 07:19:50 发布

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

我想用python检测恶意站点。你知道吗

现在,我尝试使用requests模块获取网站的内容,然后在其中搜索malicious words。但是,我没能成功。你知道吗

here example images of red page

这是我的全部代码:link code

req_check = requests.get(url)

    if 'malicious words' in req_check.content:
        print ('[Your Site Detect Red Page]   ===>   '+url)
    else:
        print ('[Your Site Not Detect Red Page]   ===>   '+url)

Tags: 模块urlyour站点网站checkpagesite
3条回答

它不起作用,因为你用错了requests库。你知道吗

在您的代码中,基本上只获得病毒站点的HTML(代码行:req_check = requests.get(url, verify=False)if 'example for detect ' in req_check.content:{源代码:https://pastebin.com/6x24SN6v})

在Chrome中,浏览器会在已知病毒链接的数据库中运行(比这更复杂),并查看链接是否安全。但是,requests不执行此操作。相反,您最好使用他们的API。如果您想了解如何将API与requests结合使用,您可以看到我对另一个问题的回答:Is there a way to extract information from shadow-root on a Website?

旁注,redage()从未被调用?你知道吗

告诉用户进入一个网站,然后使用selenium或其他东西将url上传到virustotal.com你知道吗

我想说的是,你的缩进可能是混乱的地方有其他代码。否则,它应该完美地工作。你知道吗

编辑2

似乎OP是在寻找一种在python中检测恶意站点的方法。这是来自totalvirus的文档,解释了如何利用它们的APIs。你知道吗

现在给您一个工作示例,它将打印一个报告阳性的引擎列表:

import requests


apikey = '<api_key>'

def main():
    scan_url('https://friborgerforbundet.no/')

def scan_url(url):
    params = {'apikey': apikey, 'url': url}
    response = requests.post('https://www.virustotal.com/vtapi/v2/url/scan', data=params)
    scan_id = response.json()['scan_id']
    report_params = {'apikey': apikey, 'resource': scan_id}
    report_response = requests.get('https://www.virustotal.com/vtapi/v2/url/report', params=report_params)
    scans = report_response.json()['scans']

    positive_sites = []
    for key, value in scans.items():
        if value['detected'] == True:
            positive_sites.append(key)

    print(positive_sites)


if __name__ == '__main__':
    main()

相关问题 更多 >