| import random |
| from pprint import pprint |
|
|
| import gradio as gr |
| import easy_db |
|
|
| def get_db_path(): |
| return "device_data.db" |
|
|
| def is_verifying_and_good_boot_state(dict_of_device_data_to_save): |
| if dict_of_device_data_to_save["verify"] == "enforcing" and dict_of_device_data_to_save["boot_state"] == "green": |
| return True |
| return False |
|
|
| def is_debug_enabled(dict_of_device_data_to_save): |
| if dict_of_device_data_to_save["debug_enabled"] == False: |
| return False |
| else: |
| return True |
|
|
| def is_installer_google(dict_of_device_data_to_save): |
| if dict_of_device_data_to_save["installer"] == True: |
| return True |
| else: |
| return False |
|
|
| def is_in_emulator(dict_of_device_data_to_save): |
| if dict_of_device_data_to_save["emulator"] == True: |
| return True |
| else: |
| return False |
|
|
| def do_certs_match(previous_entries_for_device,dict_of_device_data_to_save): |
| for entry in previous_entries_for_device: |
| if entry["primary_certificate"] != dict_of_device_data_to_save["primary_certificate"]: |
| return False |
|
|
| return True |
|
|
| def get_num_differences(previous_entries_for_device,dict_of_device_data_to_save): |
| differences = [] |
| for previous_entry in previous_entries_for_device: |
| difference = 0 |
| for key in list(dict_of_device_data_to_save.keys()): |
| if dict_of_device_data_to_save[key] != previous_entry[key]: |
| difference = difference + 1 |
| differences.append(difference) |
|
|
| if len(differences) != 0: |
| max_difference = max(differences) |
| else: |
| max_difference = 0 |
|
|
| return max_difference |
|
|
| def process_request(id_textbox, installer_textbox,boot_state_textbox,verify_textbox,patch_level_textbox, |
| oem_textbox,brand_textbox,model_textbox,unlocked_textbox,debug_enabled_textbox, |
| primary_certificate_textbox,emulator_textbox,fingerprint_status_textbox,storage_encryption_status_textbox, |
| market_apps_enabled_textbox,adb_enabled_textbox,lock_screen_timeout_textbox, |
| lock_screen_type_textbox,notification_visibility_textbox, app_permissions_textbox): |
| results = [] |
|
|
| apps_and_permissions = app_permissions_textbox.split("&&") |
| permissions_dict = {} |
| |
| for app_and_permissions in apps_and_permissions: |
| try: |
| app, permissions = app_and_permissions.split("*******") |
| permissions = permissions.split(" ") |
| permissions_dict[app] = permissions |
| except ValueError as e: |
| print(e) |
|
|
|
|
| pprint(permissions_dict) |
| |
| ''' is_malware_list = [] |
| for permission in permissions_dict: |
| detector = DroidDetective.APK_Analyser() |
| is_malware = detector.identify(permissions_dict[permission], "DroidDetective/apk_malware.model")[0] |
| |
| if is_malware == 0: |
| is_malware = False |
| else: |
| is_malware = True |
| |
| is_malware_list.append(is_malware) |
| |
| if True in is_malware_list: |
| results.append(True) |
| else: |
| results.append(False)''' |
| |
| dict_of_device_data_to_save = {"id": id_textbox, |
| "installer": installer_textbox, |
| "boot_state": boot_state_textbox, |
| "verify": verify_textbox, |
| "patch_level": patch_level_textbox, |
| "oem": oem_textbox, |
| "brand": brand_textbox, |
| "model": model_textbox, |
| "unlocked": unlocked_textbox, |
| "debug_enabled": debug_enabled_textbox, |
| "primary_certificate": primary_certificate_textbox, |
| "emulator": emulator_textbox, |
| "fingerprint_status": fingerprint_status_textbox, |
| "storage_encryption_status": storage_encryption_status_textbox, |
| "market_apps_enabled": market_apps_enabled_textbox, |
| "adb_enabled": adb_enabled_textbox, |
| "lock_screen_timeout": lock_screen_timeout_textbox, |
| "lock_screen_type": lock_screen_type_textbox, |
| "notification_visibility": notification_visibility_textbox} |
| db = easy_db.DataBase('device_data.db') |
|
|
|
|
| results.append(not is_debug_enabled(dict_of_device_data_to_save)) |
| results.append(not is_in_emulator(dict_of_device_data_to_save)) |
| results.append(is_installer_google(dict_of_device_data_to_save)) |
| results.append(is_verifying_and_good_boot_state(dict_of_device_data_to_save)) |
|
|
|
|
| table_names = db.table_names() |
| if 'devices' in table_names: |
| previous_entries_for_device = db.pull_where('devices', 'id = "{}"'.format(id_textbox)) |
| if previous_entries_for_device: |
| max_difference = get_num_differences(previous_entries_for_device, dict_of_device_data_to_save) |
| certs_match = do_certs_match(previous_entries_for_device, dict_of_device_data_to_save) |
| results.append(certs_match) |
|
|
|
|
|
|
| pprint(dict_of_device_data_to_save) |
|
|
| db.append('devices', [dict_of_device_data_to_save]) |
|
|
| print(results) |
| negative_results = results.count(True) |
| result = negative_results/ len(results) |
| result = result * 100 |
| history = [] |
| history.append(["Integrity Check Complete", str(result)]) |
| return history |
|
|
|
|
|
|
|
|
| block = gr.Blocks(css=".container { max-width: 800px; margin: auto; } h1 { margin: 0px; padding: 5px 0; line-height: 50px; font-size: 60pt; }.close-heading {margin: 0px; padding: 0px;} .close-heading p { margin: 0px; padding: 0px;}", title="Boudica") |
|
|
| db = easy_db.DataBase('device_data.db') |
|
|
| html_data = ''' |
| <!DOCTYPE html> |
| <html> |
| <head> |
| <meta charset="UTF-8"> |
| <meta name="viewport" content="width=device-width, initial-scale=1"> |
| <link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css"> |
| <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Poppins"> |
| <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"> |
| <style> |
| body,h1,h2,h3,h4,h5 {font-family: "Poppins", sans-serif} |
| body {font-size: 16px;} |
| img {margin-bottom: -8px;} |
| .mySlides {display: none;} |
| </style> |
| </head> |
| <body class="w3-content w3-black" style="max-width:1500px;"> |
| <!-- The App Section --> |
| <div class="w3-padding-large w3-white"> |
| <div class="w3-row-padding-large"> |
| <div class="w3-col"> |
| <h1 class="w3-jumbo"><b>Runic Integrity 🗿🛡️</b></h1> |
| <h1 class="w3-xxxlarge w3-text-blue"><b>Identify malicious changes to your device and apps</b></h1> |
| <p><span class="w3-xlarge">Download the Android App To Use Runic Integrity. ⬇ </span> Runic Integrity is an Android application designed to assess the integrity of a device and report that back to applications on that device for safety checks.</p> |
| <a href="#"><button class="w3-button w3-light-grey w3-padding-large w3-section " onclick="document.getElementById('download').style.display='block'"> |
| <i class=""></i> Find Out More! 💬 |
| </button></a> |
| <a href="https://ko-fi.com/jamesstevenson"><button class="w3-button w3-light-grey w3-padding-large w3-section " onclick="document.getElementById('download').style.display='block'"> |
| <i class=""></i> Support The Creator! ❤ |
| </button></a> |
| <a href="https://twitter.com/_JamesStevenson"><button class="w3-button w3-light-grey w3-padding-large w3-section " onclick="document.getElementById('download').style.display='block'"> |
| <i class=""></i> Follow The Creator! 🐦 |
| </button></a> |
| </div> |
| </div> |
| </div> |
| <!-- Modal --> |
| <script> |
| // Slideshow |
| var slideIndex = 1; |
| showDivs(slideIndex); |
| function plusDivs(n) { |
| showDivs(slideIndex += n); |
| } |
| function showDivs(n) { |
| var i; |
| var x = document.getElementsByClassName("mySlides"); |
| if (n > x.length) {slideIndex = 1} |
| if (n < 1) {slideIndex = x.length} |
| for (i = 0; i < x.length; i++) { |
| x[i].style.display = "none"; |
| } |
| x[slideIndex-1].style.display = "block"; |
| } |
| </script> |
| <br> |
| </body> |
| </html> |
| ''' |
|
|
|
|
| with block: |
| gr.HTML(value=html_data) |
| with gr.Group(): |
| with gr.Row().style(equal_height=True): |
| download_db_file = gr.File(value="device_data.db", interactive=False, label="Device Database") |
|
|
| with gr.Accordion("Open for More!", visible=False): |
| chatbot = gr.Chatbot().style(color_map=("green", "pink")) |
| |
| id_textbox = gr.Textbox(label="Android Secure ID") |
| |
| installer_textbox = gr.Textbox(label="Installer") |
| debug_enabled_textbox = gr.Textbox(label="Debug Enabled") |
| primary_certificate_textbox = gr.Textbox(label="primary_certificate") |
| emulator_textbox = gr.Textbox(label="Emulator") |
| |
| boot_state_textbox = gr.Textbox(label="Verify Boot State") |
| verify_textbox = gr.Textbox(label="Verify Mode") |
| patch_level_textbox = gr.Textbox(label="Security Patch Level") |
| oem_textbox = gr.Textbox(label="OEM Unlock Supported") |
| brand_textbox = gr.Textbox(label="Product Brand") |
| model_textbox = gr.Textbox(label="Product Model") |
| unlocked_textbox = gr.Textbox(label="OEM Unlock Status") |
| |
| fingerprint_status_textbox = gr.Textbox(label="Fingerprint Status") |
| storage_encryption_status_textbox = gr.Textbox(label="Storage Encryption Status") |
| market_apps_enabled_textbox = gr.Textbox(label="Market Apps Enabled") |
| adb_enabled_textbox = gr.Textbox(label="ADB Enabled") |
| lock_screen_timeout_textbox = gr.Textbox(label="Lock Screen Timeout") |
| lock_screen_type_textbox = gr.Textbox(label="Lock Screen Type") |
| notification_visibility_textbox = gr.Textbox(label="Notification Visibility") |
| app_permissions_textbox = gr.Textbox(label="App Permissions") |
|
|
| btn = gr.Button(label="Submit Data") |
| btn.click(fn=process_request, inputs=[id_textbox, installer_textbox,boot_state_textbox,verify_textbox,patch_level_textbox, |
| oem_textbox,brand_textbox,model_textbox,unlocked_textbox,debug_enabled_textbox, |
| primary_certificate_textbox,emulator_textbox,fingerprint_status_textbox,storage_encryption_status_textbox, |
| market_apps_enabled_textbox,adb_enabled_textbox,lock_screen_timeout_textbox, |
| lock_screen_type_textbox,notification_visibility_textbox,app_permissions_textbox], |
| outputs=[chatbot],api_name="submit") |
|
|
| |
| block.__enter__() |
| block.set_event_trigger( |
| event_name="load", fn=get_db_path, inputs=None, outputs=[download_db_file], no_target=True |
| ) |
| |
|
|
| |
| block.launch(enable_queue = True) |