| 23 | |
| 24 | |
| 25 | class SensitiveInfoExtractor(object): |
| 26 | |
| 27 | def get_all_file_paths(self, file_path): |
| 28 | totalFiles = [] |
| 29 | for root, dirs, files in os.walk(file_path): |
| 30 | tempFiles = [os.path.join(root, i) for i in files] |
| 31 | totalFiles += tempFiles |
| 32 | |
| 33 | return totalFiles |
| 34 | |
| 35 | def extract_all_sensitive_info(self, list_of_files, relative_path): |
| 36 | """ |
| 37 | This function detects M1: Insecure Authentication/Authorization |
| 38 | Extracts all the keys for all the apk file |
| 39 | in: file list - all file path |
| 40 | relative - gives the path relative to this path |
| 41 | Out: string path: key type: value |
| 42 | """ |
| 43 | all_sensitive_info_list = [] |
| 44 | indent = " " |
| 45 | |
| 46 | excluded_extensions = ['.ttf', '.otf', '.png', '.jpg', '.jpeg', '.gif', '.webp', '.dex', '.gradle'] |
| 47 | |
| 48 | for file in list_of_files: |
| 49 | _, file_extension = os.path.splitext(file) |
| 50 | if file_extension.lower() not in excluded_extensions: |
| 51 | try: |
| 52 | with open(file, "r", encoding='utf-8', errors='ignore') as f: |
| 53 | read = f.read() |
| 54 | types_ioc_list = self.extract(read) |
| 55 | real_relative_path = os.path.relpath(file, relative_path) |
| 56 | for items in types_ioc_list: |
| 57 | print(indent + items) |
| 58 | parts = items.split(": ", 1) |
| 59 | secret_info = { |
| 60 | "type": parts[0], |
| 61 | "ioc": parts[1] if len(parts) > 1 else "", |
| 62 | "path": real_relative_path, |
| 63 | } |
| 64 | all_sensitive_info_list.append(secret_info) |
| 65 | except Exception: |
| 66 | continue |
| 67 | return all_sensitive_info_list |
| 68 | |
| 69 | def extract_insecure_request_protocol(self, list_of_files): |
| 70 | """ |
| 71 | This function detects M2: Insecure Communication in OWASP Top 10 |
| 72 | It will check for all the insure communication used throughout the app source code. |
| 73 | """ |
| 74 | final_list = list() |
| 75 | script_dir = os.path.dirname(os.path.abspath(__file__)) |
| 76 | file_path = os.path.join(script_dir, 'known_false_positives.txt') |
| 77 | # Read known false positives from a file (skip empty lines and comments) |
| 78 | with open(file_path, 'r') as f: |
| 79 | known_false_positives = [ |
| 80 | line.strip() for line in f |
| 81 | if line.strip() and not line.strip().startswith('#') |
| 82 | ] |
nothing calls this directly
no outgoing calls
no test coverage detected