Skip to content

Commit bc40035

Browse files
committed
first commit
0 parents  commit bc40035

File tree

3 files changed

+123
-0
lines changed

3 files changed

+123
-0
lines changed

.github/workflows/scan.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: "Scan Release Artifacts and Update README"
2+
3+
on:
4+
schedule:
5+
- cron: '0 2 * * *'
6+
workflow_dispatch:
7+
8+
jobs:
9+
virus-scan:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Checkout repo
14+
uses: actions/checkout@v3
15+
16+
- name: Set up Python
17+
uses: actions/setup-python@v4
18+
with:
19+
python-version: '3.x'
20+
21+
- name: Install dependencies
22+
run: |
23+
pip install --upgrade pip
24+
pip install requests PyGithub vt-py
25+
26+
- name: Scan & update README
27+
env:
28+
VT_API_KEY: ${{ secrets.VT_API_KEY }}
29+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
30+
EXCLUDE_NAMES: 'LICENSE'
31+
EXCLUDE_PREFIXES: '_'
32+
PYTHONUNBUFFERED: '1' # ensure immediate output flushing
33+
REPOSITORY_TO_SCAN: 'simplex-chat/simplex-chat'
34+
run: python scripts/scan_and_update.py

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# simplex-virutstotal-scan

scripts/scan_and_update.py

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
import os
2+
import sys
3+
import requests
4+
import vt
5+
import tempfile
6+
from pathlib import Path
7+
from github import Github
8+
9+
# Download release assets, scan with VirusTotal, update README
10+
11+
def main():
12+
vt_key = os.getenv('VT_API_KEY')
13+
gh_token = os.getenv('GITHUB_TOKEN')
14+
repo_name = os.getenv('REPOSITORY_TO_SCAN')
15+
exclude_names = set(n.strip() for n in os.getenv('EXCLUDE_NAMES', '').split(',') if n.strip())
16+
prefixes = [p for p in os.getenv('EXCLUDE_PREFIXES', '').split(',') if p]
17+
18+
if not vt_key or not gh_token or not repo_name:
19+
print('ERROR: VT_API_KEY, GITHUB_TOKEN, and REPOSITORY_TO_SCAN must be set')
20+
sys.exit(1)
21+
22+
vt_client = vt.Client(vt_key)
23+
gh = Github(gh_token)
24+
repo = gh.get_repo(repo_name)
25+
26+
results = []
27+
releases = requests.get(
28+
f'https://api.github.com/repos/{repo_name}/releases',
29+
headers={'Authorization': f'token {gh_token}', 'Accept': 'application/vnd.github.v3+json'}
30+
).json()
31+
32+
for release in releases:
33+
for asset in release.get('assets', []):
34+
name = asset.get('name')
35+
if not name or name in exclude_names or any(name.startswith(pref) for pref in prefixes):
36+
print(f"Skipping {name}")
37+
continue
38+
39+
url = asset.get('browser_download_url')
40+
if not url:
41+
continue
42+
43+
print(f"Downloading and scanning {name}...")
44+
try:
45+
with tempfile.NamedTemporaryFile(delete=False) as tmp_file:
46+
download = requests.get(url, stream=True)
47+
for chunk in download.iter_content(chunk_size=8192):
48+
tmp_file.write(chunk)
49+
tmp_file_path = tmp_file.name
50+
51+
with open(tmp_file_path, 'rb') as f:
52+
analysis = vt_client.scan_file(f, wait_for_completion=True)
53+
stats = analysis.data.attributes.stats
54+
results.append((name,
55+
stats.get('malicious', 0),
56+
stats.get('suspicious', 0),
57+
stats.get('undetected', 0)))
58+
os.remove(tmp_file_path)
59+
except Exception as e:
60+
print(f"Failed to scan {name}: {e}")
61+
62+
vt_client.close()
63+
64+
if not results:
65+
print("No scan results to update.")
66+
return
67+
68+
lines = [
69+
'# VirusTotal Scan Results',
70+
'',
71+
'| Filename | Malicious | Suspicious | Undetected |',
72+
'| --- | --- | --- | --- |'
73+
]
74+
for name, mal, sus, und in results:
75+
lines.append(f"| {name} | {mal} | {sus} | {und} |")
76+
content = '\n'.join(lines)
77+
78+
contents = repo.get_contents('README.md')
79+
repo.update_file(
80+
contents.path,
81+
'chore: update README with VT scan results',
82+
content,
83+
contents.sha
84+
)
85+
print("README.md updated.")
86+
87+
if __name__ == '__main__':
88+
main()

0 commit comments

Comments
 (0)