Twitch Bot URL 恶意软件/病毒检测 PYTHON

问题描述

需要帮助!!

我正在使用 Python 开发一个 Twitch Bot 模块,其中 Bot 会持续监视某人消息中的 URL,并确定该 URL 是否是恶意的。恶意软件功能已经可以运行,并且已经针对 Python 中设置的字符串进行了测试。

这是好的代码,它从一个字符串创建一个 URL 数组:

好的代码

regex = r"(?i)\b((?:https?://|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'\".,<>?«»“”‘’]))"

def Find(string):   
    # findall() has been used  
    # with valid conditions for urls in string 
    regex = r"(?i)\b((?:https?://|www\d{0,<>?«»“”‘’]))"
    url = re.findall(regex,string)       
    return [x[0] for x in url]
    
# Driver Code 
string = 'hey guys I think you really need to check www.youtube.com and www.discovery.com out'

indicators = Find(string)

def malware(bot,user):
    for site in indicators:
        params = {'apikey': api_key,'resource': site}
        response = requests.get(url,params=params)
        response_json = json.loads(response.content)

        if response_json['positives'] <= 0:
            bot.send_message(f"The URL {site} has been determined to be: NOT MALICIoUS AND SAFE")

        elif 1 >= response_json['positives'] >= 3:
            bot.send_message(f"The URL {site} has been determined to be: POSSIBLY MALICIoUS")

        elif response_json['positives'] >= 4:
            bot.send_message(f"The URL {site} has been determined to be: DEFINITELY MALICIoUS")

        else:
            bot.send_message(f"The URL {site} cannot be determined to be safe or not: PROCEED WITH CAUTION!!!!")

        time.sleep(5)

不幸的是,当我尝试进一步开发此代码以持续监控消息时,它要么不起作用,要么将包含 URL 的原始消息拉到恶意软件功能上,然后功能中断。

谁能给我一些关于如何使这个糟糕的代码工作的想法?

我需要“检查”功能的帮助

错误代码

def Find2(message):   
    regex = r"(?i)\b((?:https?://|www\d{0,message)       
    return [x[0] for x in url]

LINKS = ("www.yes.com","www.google.com")

regex = r"(?i)\b((?:https?://|www\d{0,<>?«»“”‘’]))"

def Check(bot,user,message):
    if any([site in message for site in LINKS]):
        indicators = Find2(message)
        malware(bot,indicators)
        return False

    return True

def malware(bot,message):
    for site in message:
        params = {'apikey': api_key,params=params)
        response_json = json.loads(response.content)
        bot.send_message(f"I detected the URL {site} before I broke")

        if response_json['positives'] <= 0:
            bot.send_message(f"The URL {site} has been determined to be: NOT MALICIoUS AND SAFE")

        elif 1 >= response_json['positives'] >= 3:
            bot.send_message(f"The URL {site} has been determined to be: POSSIBLY MALICIoUS")

        elif response_json['positives'] >= 4:
            bot.send_message(f"The URL {site} has been determined to be: DEFINITELY MALICIoUS")

        else:
            bot.send_message(f"The URL {site} cannot be determined to be safe or not: PROCEED WITH CAUTION!!!!")

        time.sleep(5)

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)