Exemple #1
0
def user_rules():
    if not session.get('logged_in'):
        return jsonify({"status": False})

    user = User(session['user_email'])
    resp = {}
    resp['rules'] = rules.fill_rules(user.get_rules())
    resp['days'] = user.get_days()

    return jsonify(resp)
Exemple #2
0
    def process_user(self, user_email):
        # Get object
        u = User(user_email)
        days_to_run = u.get_days()
        last_day = u.last_run
        current_time = datetime.utcnow()
        current_day = int(current_time.strftime("%w")) + 1

        if current_day not in days_to_run:
            return

        day_diff = 2
        if last_day > 0:
            if last_day > current_day:
                current_day += 7
            day_diff = current_day - last_day

        # Get reports between the time requested plus some buffer time
        query_time = current_time - timedelta(hours=(day_diff * 24) + 4)
        reports = get_feed_reports(query_time)

        rules = u.get_rules()
        filled_rules = fill_rules(rules)

        report_map = {}

        for report in reports:
            self.check_report(report_map, report, filled_rules)

        sorted_reports = sorted(report_map,
                                key=lambda item: report_map[item]['score'],
                                reverse=True)

        scored_reports = []
        unscored_reports = []

        for item in sorted_reports:
            if report_map[item]['score'] > 0:
                scored_reports.append(report_map[item]['report'])
            else:
                unscored_reports.append(report_map[item]['report'])

        for item in sorted_reports:
            print(report_map[item]['score'])
            print(report_map[item]['report']['contents'])

        report_count = len(sorted_reports)

        render_map = {
            "vulncount": report_count,
            "scored_reports": scored_reports,
            "unscored_reports": unscored_reports
        }
        template_path = os.path.join(
            os.path.dirname(os.path.abspath(__file__)), "templates",
            'email_template.html')

        smtp_config = {
            'host': CONFIG.smtp_host,
            'port': CONFIG.smtp_port,
            'user': CONFIG.smtp_user,
            'password': CONFIG.smtp_pass,
            'ssl': True
        }

        m = emails.Message(html=JinjaTemplate(open(template_path).read()),
                           subject="VulnFeed Report for " +
                           time.strftime("%m/%d/%Y"),
                           mail_from=("VulnFeed Agent", "*****@*****.**"))
        response = m.send(render=render_map, to=user_email, smtp=smtp_config)
        print(response)
Exemple #3
0
    def process_user(self, user_email):
        # Get object
        u = User(user_email)

        if u.is_confirmed() == False:
            print("Ignoring " + user_email)
            return

        days_to_run = u.get_days()
        # Last run is day of year
        last_day = u.last_run

        # Get the current day
        current_time = datetime.combine(date.today(), datetime.min.time())
        current_day = int(current_time.strftime("%w")) + 1
        current_day_of_year = int(current_time.strftime("%j"))

        # Check if today is a day set by the user
        if current_day not in days_to_run:
            return

        # Check if same day
        if current_day_of_year == last_day:
            return

        day_diff = 2
        if last_day > 0:
            # If the last day is greater than the current day
            # we have had a new year!
            if last_day > current_day_of_year:
                leap_day = 0
                if calendar.isleap(current_time.year - 1):
                    leap_day = 1
                day_diff = (current_day_of_year + 365 + leap_day) - last_day
            else:
                day_diff = current_day_of_year - last_day

        # Get reports between the time requested plus some buffer time
        query_time = current_time - timedelta(hours=(day_diff * 24) + 2)
        reports = get_feed_reports(query_time)

        # Get rule data
        rules = u.get_rules()
        filled_rules = fill_rules(rules)

        # Score the reports
        report_map = {}
        for report in reports:
            self.check_report(report_map, report, filled_rules)

        # Sort the reports
        sorted_reports = sorted(report_map,
                                key=lambda item: report_map[item]['score'],
                                reverse=True)

        # Seperate reports into scored and unscored
        scored_reports = []
        unscored_reports = []

        # Clear the last report info
        u.last_scored_list = []
        u.last_unscored_list = []

        for item in sorted_reports:
            if report_map[item]['score'] > 0:
                scored_reports.append(report_map[item]['report'])
                u.last_scored_list.append(report_map[item])
            else:
                unscored_reports.append(report_map[item]['report'])
                u.last_unscored_list.append(report_map[item])

        # for item in sorted_reports:
        #     print(report_map[item]['score'])
        #     print(report_map[item]['report']['contents'])

        report_count = len(sorted_reports)

        # Prepare to render the email template
        render_map = {
            "vulncount": report_count,
            "scored_reports": scored_reports,
            "unscored_reports": unscored_reports
        }

        print(scored_reports)

        print("Sending for " + user_email)
        response = send_email(
            "reports_email.html",
            "VulnFeed Report for " + time.strftime("%m/%d/%Y"), render_map,
            user_email)

        # Update the users last sent day
        u.last_run = current_day_of_year
        u.last_status = "Status: " + str(
            response.status_code) + ", " + response.status_text.decode("utf-8")
        u.last_status = "Okay"
        u.update()
Exemple #4
0
    def process_user(self, user_email):
        # Get object
        u = User(user_email)
        days_to_run = u.get_days()
        last_day = u.last_run
        current_time = datetime.utcnow()
        current_day = int(current_time.strftime("%w")) + 1
        day_diff = 2
        if last_day > 0:
            if last_day > current_day:
                current_day += 7
            day_diff = current_day - last_day
        
        
        # Get reports between the time requested plus some buffer time
        query_time = current_time - timedelta(hours=(day_diff*24)+4)
        reports = get_feed_reports(query_time)

        rules = u.get_rules()
        filled_rules = fill_rules(rules)

        report_map = {}

        for report in reports:
            self.check_report(report_map, report, filled_rules)


        high_reports = []
        medium_reports = []
        low_reports = []
        report_count = 0

        for report_id in report_map:
            score = report_map[report_id]['score']
            report = report_map[report_id]['report']
            report_count += 1
            if score == 0:
                low_reports.append(report)
            else:
                high_reports.append(report)

        render_map = {
            "vulncount": report_count,
            "high_importance_reports": high_reports,
            "medium_importance_reports": medium_reports,
            "low_importance_reports": low_reports
        }
        template_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "templates", 'email_template.html')

        smtp_config = {
            'host': CONFIG.smtp_host,
            'port': CONFIG.smtp_port,
            'user': CONFIG.smtp_user,
            'password': CONFIG.smtp_pass,
            'ssl': True
        }

        m = emails.Message(html=JinjaTemplate(open(template_path).read()),  text="hi there",  subject="VulnFeed Test", mail_from=("VulnFeed Agent", "*****@*****.**"))
        response = m.send(render=render_map, to=user_email, smtp={smtp_config)
        print(response)

    def run(self):

        for user_email in self.user_chunk:
            self.process_user(user_email)

sm = SenderMaster()
sm.start_senders()