Created
November 20, 2024 11:06
-
-
Save anontheauditor/a9095e8a2f3d5b0aca7e3fd12731f88d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| c2dc67f3bfa73d31817d7b30d37d5d5535038230 | |
| b33e5713ae0bfe6b3893dad3cfbb7ab0355c5f5d | |
| 2563bef0a467e0b6c9abefac1adcdc96af523005 | |
| e33cf5eddce94aa9ab81e0fdd78c9c9b4ddef17b | |
| f1922ef8e28d064415d52f1c1a2cdde69e00ece3 | |
| b657b93f2006b6c9833e42fdaab0446f4de830fe | |
| b657b93f2006b6c9833e42fdaab0446f4de830fe | |
| 8daee5ed6b3d55195a18ac918ca8d794972c7022 | |
| 2a0f08a595b51cbb447c59a331fc0d9f3efb88c9 | |
| 85c64476c3d25a37652bcd49ebf81251ceff1a2e | |
| b6d1d6e58c6c7b471816dfdc2c2841e838ea1841 | |
| 5151768eb7d99e1de53b8ab24d872a305e66d016 | |
| 90a14fb353d17b0492fde037700a2e5f4c1d8810 | |
| 69d4c209ca90b7e5d02ffe797093ddc0bc19d30b | |
| 3a5d508188c45e6ada22c4622a5cd798ebc30cb1 | |
| 97d676617b489b56ed69ebf49da8bd90a11544d1 | |
| cdc8af65ae6ebc98ff6b0d79874da9e5a6e229ed | |
| 6b18e7862e1d6c778ecb459005b26da555278df5 | |
| 597f04eddd8520ca1278d9741bed12b7c8fe9264 | |
| 0b466dacc6a090ed252805a81ce3da896ffc2c00 | |
| 35f8bb75855efeb215451cd3faf3c312897a4819 | |
| 319afb98536ee0e336e6a122aa48324bda516cda | |
| 066f26577dc2d7642f8f4600d42311665f0ae32c | |
| c5e711a76bf345c3ed98a9a847399601c071aeab | |
| 3a5d508188c45e6ada22c4622a5cd798ebc30cb1 | |
| da9af35e64a9ac05e5956d4b0646cdfd03074d11 | |
| 97d676617b489b56ed69ebf49da8bd90a11544d1 | |
| d1f9a0477fef164bde91f80cc5a3eea1b472f96b | |
| e2dd433d9e959b2bea90e7341c3b8db32ffef860 | |
| 92f83e6b481fec1a72bdab2a06266d6a8f421355 | |
| 218bec77d9254f7a93f3a2bbe01c995fb0eb2428 | |
| 3a5d508188c45e6ada22c4622a5cd798ebc30cb1 | |
| 827406678a8c289ba9a4de1470ccd18a36eba460 | |
| e33cf5eddce94aa9ab81e0fdd78c9c9b4ddef17b | |
| 6633b122a2d3fea5448bb199fbd9cf9dfeb4101a | |
| b6d1d6e58c6c7b471816dfdc2c2841e838ea1841 | |
| 3a5d508188c45e6ada22c4622a5cd798ebc30cb1 | |
| b9bf879d7e1118088197e89c8270d7f875b08511 | |
| 5af1e7e3aef2704645dbb96d3820c1e3a8d0a353 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import requests | |
| import base64 | |
| import re | |
| from datetime import datetime | |
| import os | |
| GITHUB_TOKEN = "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" | |
| def get_processed_files(): | |
| if os.path.exists('processed_files.txt'): | |
| with open('processed_files.txt', 'r') as f: | |
| return set(f.read().splitlines()) | |
| return set() | |
| def update_processed_files(commit_hash): | |
| with open('processed_files.txt', 'a') as f: | |
| f.write(f"{commit_hash}\n") | |
| def get_file_content(file_url): | |
| headers = {'Authorization': f'token {GITHUB_TOKEN}'} | |
| response = requests.get(file_url, headers=headers) | |
| if response.status_code == 200: | |
| try: | |
| return base64.b64decode(response.json()['content']).decode('utf-8') | |
| except requests.exceptions.JSONDecodeError: | |
| return response.text | |
| else: | |
| print(f"Failed to fetch file: {file_url}") | |
| return None | |
| def format_file(content): | |
| parts = content.split("# Findings", 1) | |
| if len(parts) > 1: | |
| content = parts[1] | |
| else: | |
| content = parts[0] | |
| formatted = "**Auditor**\n\n[Shieldify Security](https://x.com/ShieldifySec)\n\n# Findings\n\n" | |
| lines = content.split('\n') | |
| current_risk = None | |
| for i, line in enumerate(lines): | |
| if re.match(r'^\s*#\s*\[(C|H|M|L)-\d+\]', line): | |
| finding_type = re.search(r'\[(C|H|M|L)-', line).group(1) | |
| if finding_type in ['C', 'H']: | |
| current_risk = "High Risk" | |
| elif finding_type == 'M': | |
| current_risk = "Medium Risk" | |
| elif finding_type == 'L': | |
| current_risk = "Low Risk" | |
| formatted += f"## {current_risk}\n" | |
| formatted += "### " + re.sub(r'^#+\s*', '', line.strip()) + "\n" | |
| elif line.strip().startswith(('#', '##', '###', '####')): | |
| formatted += f"**{line.lstrip('#').strip()}**\n" | |
| else: | |
| formatted += line + '\n' | |
| formatted = re.sub(r'\n{3,}', '\n\n', formatted) | |
| return formatted.strip() + '\n' | |
| def get_file_info(repo_owner, repo_name, file_path): | |
| api_url = f"https://api.github.com/repos/{repo_owner}/{repo_name}/commits" | |
| params = { | |
| 'path': file_path, | |
| 'per_page': 1 | |
| } | |
| headers = {'Authorization': f'token {GITHUB_TOKEN}'} | |
| response = requests.get(api_url, params=params, headers=headers) | |
| if response.status_code == 200: | |
| commits = response.json() | |
| if commits: | |
| creation_date = commits[0]['commit']['author']['date'] | |
| commit_hash = commits[0]['sha'] | |
| return datetime.strptime(creation_date, "%Y-%m-%dT%H:%M:%SZ").strftime('%Y-%m-%d'), commit_hash | |
| return None, None | |
| def get_protocol_name(filename): | |
| return filename.replace('-Security-Review', '').replace('.md', '') | |
| api_url = "https://api.github.com/repos/shieldify-security/audits-portfolio-md/contents" | |
| repo_owner = "shieldify-security" | |
| repo_name = "audits-portfolio-md" | |
| processed_files = get_processed_files() | |
| headers = {'Authorization': f'token {GITHUB_TOKEN}'} | |
| response = requests.get(api_url, headers=headers) | |
| if response.status_code == 200: | |
| files = response.json() | |
| for file in files: | |
| if file['name'].endswith('.md'): | |
| print(f"Processing {file['name']}") | |
| try: | |
| file_path = f"/{file['name']}" | |
| date, commit_hash = get_file_info(repo_owner, repo_name, file_path) | |
| if not date or not commit_hash: | |
| print(f"Failed to get file info for {file['name']}, skipping...") | |
| continue | |
| if commit_hash in processed_files: | |
| print(f"File {file['name']} already processed, skipping...") | |
| continue | |
| file_content = get_file_content(file['download_url']) | |
| if file_content: | |
| formatted_content = format_file(file_content) | |
| protocol_name = get_protocol_name(file['name']) | |
| new_filename = f"{date}-{protocol_name}.md" | |
| with open(new_filename, 'w', encoding='utf-8') as f: | |
| f.write(formatted_content) | |
| update_processed_files(commit_hash) | |
| except Exception as e: | |
| print(f"Error processing {file['name']}: {str(e)}") | |
| print("Formatting complete!") | |
| else: | |
| print(f"Failed to fetch directory contents. Status code: {response.status_code}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment