Esempio n. 1
0
def hash_analyzer(filename):
    #sha256 hash
    sha256_hash = hashlib.sha256()
    with open(filename, "rb") as f:
        # Read and update hash string value in blocks of 4K
        for byte_block in iter(lambda: f.read(4096), b""):
            sha256_hash.update(byte_block)
        print('sha256: ' + sha256_hash.hexdigest())
        generate_report(sha256_hash.hexdigest())

    #sha1 hash
    sha1_hash = hashlib.sha1()
    with open(filename, 'rb') as f:
        # Read and update hash string value in blocks of 1K
        for byte_block in iter(lambda: f.read(1024), b""):
            sha1_hash.update(byte_block)
        print('sha1:   ' + sha1_hash.hexdigest())
        # generate_report(sha1_hash.hexdigest())

    #md5 hash
    md5_hash = hashlib.md5()
    with open(filename, 'rb') as f:
        # Read and update hash string value in blocks of 8K
        for byte_block in iter(lambda: f.read(8192), b""):
            md5_hash.update(byte_block)
        print('md5:    ' + md5_hash.hexdigest())
def main(argv):
    global log_format, dburi, tweet_collection, report_collection, summary_collection, report_interval_minutes, small_summary_interval_minutes, big_summary_interval_minutes

    logging.basicConfig(format=log_format, level=logging.DEBUG, stream=sys.stdout)
    logger = logging.getLogger('statistics')
    logger.info("Starting statistics manager")

    try:
        client = pymongo.MongoClient(dburi)
    except:
        logger.fatal("Couldn't connect to MongoDB. Please check your --db argument settings.")
        sys.exit(1)

    parsed_dburi = pymongo.uri_parser.parse_uri(dburi)
    db = client[parsed_dburi['database']]

    tweet_db = db[tweet_collection]
    tweet_db.ensure_index("id", direction=pymongo.DESCENDING, unique=True)
    tweet_db.ensure_index([("coordinates.coordinates", pymongo.GEO2D), ])
    tweet_db.ensure_index("created_at", direction=pymongo.ASCENDING)
    tweet_db.ensure_index("entities.hashtags.text", direction=pymongo.ASCENDING)
    tweet_db.ensure_index("entities.user_mentions.screen_name", direction=pymongo.ASCENDING)

    report_db = db[report_collection]
    report_db.ensure_index("created_at", direction=pymongo.ASCENDING)

    summary_db = db[summary_collection]
    summary_db.ensure_index("created_at", direction=pymongo.ASCENDING)

    last_time_report = time.time()
    last_time_small_summary = time.time()
    last_time_big_summary = time.time()

    while True:
        time_since_report = time.time() - last_time_report
        time_since_small_summary = time.time() - last_time_small_summary
        time_since_big_summary = time.time() - last_time_big_summary

        if time_since_report >= (report_interval_minutes * 60):
            start = datetime.datetime.utcnow() - datetime.timedelta(minutes=report_interval_minutes)
            end = datetime.datetime.utcnow()

            report_generator.generate_report(tweet_db, report_db, start, end)
            last_time_report = time.time()

        if time_since_small_summary >= (small_summary_interval_minutes * 60):
            start = datetime.datetime.utcnow() - datetime.timedelta(minutes=small_summary_interval_minutes)
            end = datetime.datetime.utcnow()
            summary_generator.generate_summary(report_db, summary_db, start, end)
            last_time_small_summary = time.time()

        if time_since_big_summary >= (big_summary_interval_minutes * 60):
            start = datetime.datetime.utcnow() - datetime.timedelta(minutes=big_summary_interval_minutes)
            end = datetime.datetime.utcnow()
            summary_generator.generate_summary(report_db, summary_db, start, end)
            last_time_big_summary = time.time()

        # sleep one minute
        time.sleep(60)
Esempio n. 3
0
def monitorNewAccounts():
    #time when emails will be sent
    start = datetime.time(16, 59)
    end = datetime.time(17, 00)
    while (datetime.datetime.now().time() < start
           or datetime.datetime.now().time() > end):

        #takes input through keyboard on 20 second timer (so it doesnt get tied up when reports get emailed)
        stringer = timed_Input()

        #if there was an email
        if (stringer != None):
            #parses the input message
            message = stringer.split(",")

            #if the message is saying to create a new account with signal "0000"
            if (message[0] == "0000"):
                if (len(message) >= 10):
                    # creates new user with an email
                    new_account = Accounts(float(message[1]), float(
                        message[2]), float(message[3]), float(message[4]),
                                           float(message[5]),
                                           float(message[6]),
                                           float(message[7]),
                                           float(message[8]), message[9])
            # email not included
                else:
                    new_account = Accounts(float(message[1]), float(
                        message[2]), float(message[3]), float(message[4]),
                                           float(message[5]),
                                           float(message[6]),
                                           float(message[7]),
                                           float(message[8]))

                #creates new user id, if it already exists increments until finds number that doesnt exist
                new_id = random.randrange(1, 999)
                while (new_id in created_accounts):
                    new_id = new_id + 1

                #adds new account with new id to the existing accounts
                created_accounts[str(new_id)] = new_account

                #generate report
                reply = generate_report(str(new_id), created_accounts, True)

            #else the user already exists OR you need to create new account
            else:
                reply = generate_report(str(message[0]), created_accounts,
                                        False)

            #returns the report generated
            print(reply)
            print('\nEnter something.')

    #in time range to send reports so calls send reports and then loops back in
    sendReports()
Esempio n. 4
0
def main():
    report = generate_report(duration=timedelta(seconds=2))

    formatted = format_report(report)

    print(formatted)
    email_send(formatted)
Esempio n. 5
0
def run_scanner(args):
    is_recursive = args["recursive"]

    try:
        if args["scan_dir"] is not None:
            match_result = yara_scanner.scan_directory(args["scan_dir"].strip(), is_recursive)
        elif args["scan_file"] is not None:
            match_result = yara_scanner.scan_file(args["scan_file"].strip())
        elif args["scan_access_logs"] is not None and args["www_path"] is not None:
            access_log_file_path = args["scan_access_logs"].strip()
            www_dir_path = args["www_path"].strip()
            match_result = yara_scanner.scan_access_logs(access_log_file_path, www_dir_path, args["tail"])
        else:
            arg_parser.print_help()
            sys.exit(0)
        if match_result is None:
            raise Exception()
    except:
        sys.exit(0)

    # Generate report
    report_file_name = 'YaraScanner_Report_{}.html'.format(datetime.now().strftime('%Y_%B_%d_%H_%M_%S'))
    if args['gen_report']:
        print('[+] Generating report..')

    if args['gen_report']:
        report = report_generator.generate_report(match_result)
        common_functions.write_to_file(report_file_name, report)
        print('[+] Report saved to "{}"'.format(report_file_name))

    # send report by email
    if args['gen_report'] and len(settings.smtp_host) > 0 and settings.smtp_port > 0:
        report = report_generator.generate_report(match_result)

        attachment = [{'text': report, 'file_name': report_file_name}]
        smtp_mailer_param = common_functions.build_smtp_config_dict()
        smtp_mailer_param['message_body'] = settings.email_body_scan_complete
        smtp_mailer_param['subject'] = 'Scan Report {}'.format(common_functions.get_datetime())
        smtp_mailer_param['attachments'] = attachment

        print('[+] Delivering report to {}'.format(settings.email_alert_recipients))
        email_sender.send_message(smtp_mailer_param)
        print('[+] Report sent to {}'.format(settings.email_alert_recipients))
Esempio n. 6
0
def _analysis(file):
    face_images = FaceDetector(file).get_faces_with_features()
    faces = [
        generate_report(url, image_id)
        for url, image_id in _save_images(face_images)
    ]

    return render_template("analysis.html",
                           faces=faces,
                           render_suggestion=render_suggestion)
Esempio n. 7
0
def sendReports():
    # iterates through created accounts and if it contains email piece sends email with report
    print('Going to send reports piece.')
    for account in created_accounts:
        destination = (created_accounts[account].emailAddress)
        # the email address is not null so send email to destination with message
        if (destination != None):
            message = (generate_report(account, created_accounts, False))
            sendReport(destination, message)
    time.sleep(60)
    print('Starting to monitor again.')
    monitorNewAccounts()
Esempio n. 8
0
def run(args):
    print('[+] Analyzing "{}" .. This may take some time.'.format(
        args["log_file"]))
    result = analyze_access_log_file(args["log_file"], args["log_format"])
    try:
        print('[+] Generating report..')
        report = generate_report(result)
        save_path = str(args["out"].strip())
        write_to_file(save_path, report)
        print('[+] Report saved to "{}"'.format(save_path))

    except Exception as e:
        print(
            "[-] An error has occurred while writing the report. {}".format(e))
def test_report_foo_generator():
    global report_foo_db, tweet_db
    start = datetime.datetime.utcnow() - datetime.timedelta(hours=8)
    end = datetime.datetime.utcnow()
    report_generator.generate_report(tweet_db, report_foo_db, start, end)
Esempio n. 10
0
def test_report_generator():
    global tweet_db, report_db
    start = datetime.datetime.utcnow() - datetime.timedelta(days=3)
    end = datetime.datetime.utcnow()
    report_generator.generate_report(tweet_db, report_db, start, end)
Esempio n. 11
0
def main():
    """ Main thread of the program, handles the GUI and calls to separate modules """

    root = Tk()
    root.title("Facebook Data Analyser")

    welcome_message = """Thanks for choosing to use the FB Data Analyser! \n
    This tool requires you to first download your Facebook data from the Facebook website.\n
    If you have not already done this: 
    1) Go to "facebook.com/your_information"
    2) Click on "download my data"
    3) Select "all data", "JSON file" and click create file.
    
    Facebook will then send you an e-mail when your data is ready to download, simply follow the instructions provided in the e-mail.
    You do not need to unzip this data, the tool will do this for you."""

    info_text = Label(root, text="Please select your facebook data file.")
    info_text.pack()

    progress = ttk.Progressbar(root, orient='horizontal', length=700)
    progress.config(mode="determinate", maximum=100)
    progress.pack()

    status = Label(root, text="")
    status.pack()
    # Gets the requested values of the height and width.
    windowWidth = root.winfo_reqwidth()
    windowHeight = root.winfo_reqheight()

    # Gets both half the screen width/height and window width/height
    positionRight = int(root.winfo_screenwidth() / 2 - windowWidth / 2 - 300)
    positionDown = int(root.winfo_screenheight() / 2 - windowHeight / 2)

    # Positions the window in the center of the page.
    root.geometry("+{}+{}".format(positionRight, positionDown))

    showinfo("Facebook Data Analyser Startup", welcome_message)
    showinfo("Info", "Please select your Facebook zip file...")
    update_status("Selecting a Facebook data zip file", status, root)
    zip_path = file_picker()

    skip_nudity_check = askyesno(
        "Nudity Check?",
        "Do you want to perform a nudity check on all your photos sent in messages? This task is very time consuming, so if you are sure that there are no compromising pictures, it is recommended that you select \"no\""
    )

    info_text[
        "text"] = "The tool is now running, this can take up to a few minutes, depending on the amount of data and speed of your computer."

    update_status("Unzipping Facebook data archive", status, root)
    zip_opener(zip_path)
    update_progress(progress, 25, root)

    update_status("Validating Data", status, root)
    validate_uploaded_data()
    update_progress(progress, 5, root)

    # Parse data starting here
    user_data = {}

    update_status("Parsing User Information", status, root)
    user_data = parse_user_info(user_data)
    update_progress(progress, 3, root)

    update_status("Parsing Location History", status, root)
    user_data = parse_location_history(user_data)
    update_progress(progress, 5, root)

    update_status("Parsing Facial Recognition Data", status, root)
    user_data = parse_facial_recognition(user_data)
    update_progress(progress, 2, root)

    update_status("Parsing Off-Facebook activities", status, root)
    user_data = parse_off_facebook_activities(user_data)
    update_progress(progress, 5, root)

    update_status("Parsing advertisement interactions", status, root)
    user_data = parse_ad_interactions(user_data)
    update_progress(progress, 1, root)

    update_status("Parsing Interests", status, root)
    user_data = parse_interests(user_data)
    update_progress(progress, 4, root)

    update_status("Parsing Messages", status, root)
    user_data = parse_messages(user_data)
    update_progress(progress, 8, root)

    update_status("Parsing Posts", status, root)
    user_data = parse_posts(user_data)
    update_progress(progress, 3, root)

    update_status("Parsing comments", status, root)
    user_data = parse_comments(user_data)
    update_progress(progress, 1, root)

    update_status("Parsing friends", status, root)
    user_data = parse_friends(user_data)
    update_progress(progress, 3, root)

    update_status("Parsing photos", status, root)
    user_data = parse_photos(user_data)
    update_progress(progress, 3, root)

    update_status("Parsing peer group", status, root)
    user_data = parse_peer_group(user_data)
    update_progress(progress, 1, root)

    if skip_nudity_check:
        update_status("Scanning photos for unsafe content", status, root)
        user_data = check_for_nudity(user_data)
    else:
        user_data["nbr_of_unsafe_photos"] = "Skipped"
    update_progress(progress, 10, root)

    update_status("Generating Report", status, root)
    generate_report(user_data)
    update_progress(progress, 5, root)

    update_status("Moving Profile Picture", status, root)
    profile_picture_mover()
    update_progress(progress, 3, root)

    if skip_nudity_check:
        update_status("Moving Unsafe Pictures", status, root)
        unsafe_photo_mover(user_data)
    update_progress(progress, 3, root)

    update_status("Deleting Temporary Folder", status, root)
    delete_temp()
    update_progress(progress, 5, root)

    showinfo(
        "Success",
        "The tool has finished generating your report, it will be automatically opened in your preferred web browser."
    )
    report_path = os.getcwd() + "/report_generated/index.html"
    webbrowser.open(report_path)
Esempio n. 12
0
def main():
    report = generate_report(duration=timedelta(seconds=10))
    formatted = line_char(report)
    send_mail(formatted)
Esempio n. 13
0
 def get_html_report(self):
     if self.report_json:
         return generate_report(self.type_name, self.report_json)