From 3dd6ba51a2d4abc6eeca3f1aee46ab63a65d84f8 Mon Sep 17 00:00:00 2001 From: amadejpapez <63184600+amadejpapez@users.noreply.github.com> Date: Sun, 7 Feb 2021 00:21:37 +0100 Subject: [PATCH] Version 4.0 --- ApplSec.py | 89 +++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 74 insertions(+), 15 deletions(-) diff --git a/ApplSec.py b/ApplSec.py index f711daa..2d4a965 100644 --- a/ApplSec.py +++ b/ApplSec.py @@ -3,6 +3,7 @@ import tweepy import requests from datetime import date +from collections import Counter from bs4 import BeautifulSoup, SoupStrainer api_key = "x" @@ -13,30 +14,56 @@ auth = tweepy.OAuthHandler(api_key, api_secret_key) auth.set_access_token(access_token, access_secret_key) api = tweepy.API(auth) -api + updatesPage = requests.get("https://support.apple.com/en-us/HT201222").text currentDateFormatOne = str(date.today().day) + " " + str(date.today().strftime("%B")[0:3]) + " " + str(date.today().year) currentDateFormatTwo = str(date.today().strftime("%B")) + " " + str(date.today().day) + ", " + str(date.today().year) - newHeader = [] numberCVE = [] +countStrong = [] +newStrong = [] def getData(link): for x in link: newPage = requests.get(x) soup = BeautifulSoup(newPage.content, "html.parser") + # get the title of the new version allHeaders = soup.find_all("h2") - newHeader.append(re.sub("<[^>]*?>","", str(allHeaders[1]))) + currentHeader = re.sub("<[^>]*?>","", str(allHeaders[1])) + if "macOS" in currentHeader: + # if macOS in the title take only the first part + currentHeader = currentHeader.split(",", 1)[0] + if "iOS" in currentHeader: + # if iOS in the title take only the first part; without iPadOS + currentHeader = currentHeader.split("and", 1)[0].rstrip() + newHeader.append(currentHeader) + # get the number of CVEs on the page numberCVE.append(len(re.findall("CVE", str(soup))) - 1) - for x in newHeader: - # if there is macOS in the header take only the first part, not the full title - if "macOS" in x: - macosIsHere = newHeader.index(x) - newHeader[macosIsHere] = x.split(",", 1)[0] + + # search if there were any zero-day vulnerabilities fixed + number0Days = 0 + if link == newLinks: + if "in the wild" or "actively exploited" in soup: + number0Days = len(re.findall("in the wild", str(soup))) + number0Days += len(re.findall("actively exploited", str(soup))) + results0Days3 = "" + if number0Days == 1: + results0Days3 += str(number0Days) + " zero-day vulnerability fixed in " + currentHeader + else: + results0Days3 += str(number0Days) + " zero-day vulnerabilities fixed in " + currentHeader + + if number0Days >= 1: + if len(re.findall("zero-day", results0Days3)) == 1: + results0Days2 = ":mega: EMERGENCY UPDATE :mega:\n\n" + else: + results0Days2 = ":mega: EMERGENCY UPDATES :mega:\n\n" + results0Days1 = results0Days2 + results0Days3 + + api.update_status(emoji.emojize("{}".format(results0Days1), use_aliases=True)) allLinks = [] @@ -50,11 +77,26 @@ def getData(link): # get only the new links from the page newLinks = allLinks[22:len(re.findall(currentDateFormatOne, updatesPage)) + 22] getData(newLinks) - # print results - results = ":closed_lock_with_key: NEW UPDATES RELEASED :closed_lock_with_key:\n\n" + + # api.update_status results + if len(newHeader) == 1: + results = ":collision: NEW UPDATE RELEASED :collision:\n\n" + else: + results = ":collision: NEW UPDATES RELEASED :collision:\n\n" + for x in newHeader: - results += "• " + x + " released with " + str(numberCVE[0]) + " security fixes\n" + if "iOS" in x: + results += ":iphone: " + x + " - " + str(numberCVE[0]) + " bugs fixed\n" + elif "watchOS" in x: + results += ":watch: " + x + " - " + str(numberCVE[0]) + " bugs fixed\n" + elif "tvOS" in x: + results += ":tv: " + x + " - " + str(numberCVE[0]) + " bugs fixed\n" + elif "macOS" in x: + results += ":computer: " + x + " - " + str(numberCVE[0]) + " bugs fixed\n" + else: + results += ":hammer_and_wrench: " + x + " - " + str(numberCVE[0]) + " bugs fixed\n" numberCVE.pop(0) + api.update_status(emoji.emojize("{}".format(results), use_aliases=True)) @@ -63,15 +105,32 @@ def getData(link): # check if the last 20 update pages got any changes today page = requests.get(x).text search = "Entry added " + str(currentDateFormatTwo) + if search in page: updatedLinks.append(x) if updatedLinks != []: + # if any security notes were updated newHeader.clear() getData(updatedLinks) - # print results - results = "UPDATED TODAY:\n" + + # api.update_status results + if len(newHeader) == 1: + results = ":arrows_counterclockwise: " + str(len(updatedLinks)) + " SECURITY NOTE UPDATED :arrows_counterclockwise:\n\n" + else: + results = ":arrows_counterclockwise: " + str(len(updatedLinks)) + " SECURITY NOTES UPDATED :arrows_counterclockwise:\n\n" + for x in newHeader: - results += x + " was released " + str(numberCVE[0]) + " security fixes\n" + if "iOS" in x: + results += ":iphone: " + x + " - " + str(numberCVE[0]) + " bugs fixed\n" + elif "watchOS" in x: + results += ":watch: " + x + " - " + str(numberCVE[0]) + " bugs fixed\n" + elif "tvOS" in x: + results += ":tv: " + x + " - " + str(numberCVE[0]) + " bugs fixed\n" + elif "macOS" in x: + results += ":computer: " + x + " - " + str(numberCVE[0]) + " bugs fixed\n" + else: + results += ":hammer_and_wrench: " + x + " - " + str(numberCVE[0]) + " bugs fixed\n" numberCVE.pop(0) - api.update_status(emoji.emojize(results)) \ No newline at end of file + + api.update_status(emoji.emojize("{}".format(results), use_aliases=True)) \ No newline at end of file