nightly milestone build ecksdeeee
This commit is contained in:
parent
a72100ee23
commit
70945bcca7
60
certAlert.py
60
certAlert.py
@ -1,17 +1,34 @@
|
|||||||
#!/bin/env/python
|
#!/usr/bin/env python
|
||||||
import datetime, sys, re, urllib2
|
import datetime, sys, re, urllib2, logging
|
||||||
|
#from pushnotify import abstract, get_client, exceptions, pushover
|
||||||
|
import pushnotify
|
||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
|
|
||||||
|
ERRSTR = '!!!!!!!!!!!!! '
|
||||||
|
|
||||||
|
PUSHOVER_DEVICE = 'chromehome'
|
||||||
|
|
||||||
TARGET_URL = 'https://www.cert-bund.de/overview/AdvisoryShort'
|
TARGET_URL = 'https://www.cert-bund.de/overview/AdvisoryShort'
|
||||||
MEMORY_PATH = 'C:\Users\Panki\Desktop\Privat\Dev\certAlert\out.txt'
|
MEMORY_PATH = 'C:\Users\Panki\Desktop\Privat\Dev\certAlert\out.txt'
|
||||||
PROGRAMS = [u'Chrome', u'OpenSSH', u'Java', u'Linux']
|
|
||||||
|
USER_KEY_PATH = 'C:\Users\Panki\Desktop\Privat\Dev\pushover_user'
|
||||||
|
API_KEY_PATH = 'C:\Users\Panki\Desktop\Privat\Dev\pushover_key'
|
||||||
|
|
||||||
|
PROGRAMS = [u'Chrome', u'OpenSSH', u'Java', u'Linux', u'Apache', u'Windows']
|
||||||
|
|
||||||
|
with open(USER_KEY_PATH, 'r') as userKeyFile:
|
||||||
|
USER_KEY = userKeyFile.read()
|
||||||
|
userKeyFile.close()
|
||||||
|
with open(API_KEY_PATH, 'r') as apiKeyFile:
|
||||||
|
API_KEY = apiKeyFile.read()
|
||||||
|
userKeyFile.close()
|
||||||
|
|
||||||
class Advisory:
|
class Advisory:
|
||||||
def __init__(self, html):
|
def __init__(self, html):
|
||||||
|
|
||||||
self.date = datetime.datetime.strptime(html.td.text, '%d.%m.%y').date()
|
self.date = datetime.datetime.strptime(html.td.text, '%d.%m.%y').date()
|
||||||
self.risk = int(html.find('span', {'class': re.compile('search-result-crit-*')}).text)
|
self.risk = int(html.find('span', {'class': re.compile('search-result-crit-*')}).text)
|
||||||
self.identifier = html.find('a', {'class': 'search-result-link'}).text
|
self.identifier = html.find('a', {'class': 'search-result-link'}).text
|
||||||
self.link = TARGET_URL + html.find('a', {'class': 'search-result-link'})['href']
|
self.link = 'https://www.cert-bund.de/overview/' + html.find('a', {'class': 'search-result-link'})['href']
|
||||||
self.description = html.find_all('a', {'class': 'search-result-link'})[1].text
|
self.description = html.find_all('a', {'class': 'search-result-link'})[1].text
|
||||||
def debug(self):
|
def debug(self):
|
||||||
print('date: '+ self.date.isoformat())
|
print('date: '+ self.date.isoformat())
|
||||||
@ -20,12 +37,27 @@ class Advisory:
|
|||||||
print('desc: ' + self.description)
|
print('desc: ' + self.description)
|
||||||
print('link: ' + self.link)
|
print('link: ' + self.link)
|
||||||
|
|
||||||
|
def startLogger():
|
||||||
|
logger = logging.getLogger('pushnotify')
|
||||||
|
logger.setLevel(logging.DEBUG)F
|
||||||
|
formatter = logging.Formatter('%(name)s-%(levelname)s: %(message)s')
|
||||||
|
handler = logging.StreamHandler()
|
||||||
|
handler.setFormatter(formatter)
|
||||||
|
logger.addHandler(handler)
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
import pushnotify
|
||||||
|
startLogger()
|
||||||
|
#readKeys()
|
||||||
|
client = pushnotify.get_client('pushover', API_KEY, 'certAlert')
|
||||||
|
client.add_key(USER_KEY, PUSHOVER_DEVICE)
|
||||||
try:
|
try:
|
||||||
response = urllib2.urlopen(TARGET_URL)
|
response = urllib2.urlopen(TARGET_URL)
|
||||||
except:
|
except:
|
||||||
e = sys.exc_info()[0]
|
e = sys.exc_info()[0]
|
||||||
print('Error getting Webpage!\r\n' + e)
|
print(ERRSTR + 'Error getting Webpage!\r\n' + e)
|
||||||
sys.exit('Stopping execution!')
|
sys.exit(ERRSTR + 'Stopping execution!')
|
||||||
html = response.read()
|
html = response.read()
|
||||||
soup = BeautifulSoup(html, 'html.parser')
|
soup = BeautifulSoup(html, 'html.parser')
|
||||||
|
|
||||||
@ -38,8 +70,8 @@ try:
|
|||||||
checkedIDs = memFile.read()
|
checkedIDs = memFile.read()
|
||||||
memFile.close()
|
memFile.close()
|
||||||
except IOError:
|
except IOError:
|
||||||
print('Error reading memory file!')
|
print(ERRSTR + 'Error reading memory file!')
|
||||||
print('Continuing without list of checked IDs...')
|
print(ERRSTR + 'Continuing without list of checked IDs...')
|
||||||
checkedIDs = ''
|
checkedIDs = ''
|
||||||
except:
|
except:
|
||||||
e = sys.exc_info()[0]
|
e = sys.exc_info()[0]
|
||||||
@ -48,13 +80,19 @@ except:
|
|||||||
for result in results:
|
for result in results:
|
||||||
if result.risk > 3:
|
if result.risk > 3:
|
||||||
for prog in PROGRAMS:
|
for prog in PROGRAMS:
|
||||||
if re.match(prog, result.description):
|
if re.match(prog, result.description, re.IGNORECASE):
|
||||||
if result.identifier not in checkedIDs:
|
if result.identifier not in checkedIDs:
|
||||||
|
#this means we have found an alert that we have not seen before! lets alert the user...
|
||||||
|
client.notify(result.description, result.identifier, kwargs={'priority': 1, 'url': result.link,'url_title': result.identifier});
|
||||||
result.debug()
|
result.debug()
|
||||||
print('==================================')
|
print('========================================================================')
|
||||||
else:
|
else:
|
||||||
print('Already sent an alert for ' + result.identifier +', skipping...')
|
print('Already sent an alert for ' + result.identifier +', skipping...')
|
||||||
with open(MEMORY_PATH, 'w') as memFile:
|
with open(MEMORY_PATH, 'w') as memFile:
|
||||||
for result in results:
|
for result in results:
|
||||||
memFile.write(result.identifier + '\r\n')
|
memFile.write(result.identifier + '\r\n')
|
||||||
memFile.close()
|
memFile.close()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
Loading…
Reference in New Issue
Block a user