dockeriq 0.2.4__tar.gz → 2.0.3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {dockeriq-0.2.4 → dockeriq-2.0.3}/PKG-INFO +1 -1
- {dockeriq-0.2.4 → dockeriq-2.0.3}/dockeriq/cli.py +72 -15
- {dockeriq-0.2.4 → dockeriq-2.0.3}/dockeriq.egg-info/PKG-INFO +1 -1
- {dockeriq-0.2.4 → dockeriq-2.0.3}/setup.py +1 -1
- {dockeriq-0.2.4 → dockeriq-2.0.3}/README.md +0 -0
- {dockeriq-0.2.4 → dockeriq-2.0.3}/dockeriq/__init__.py +0 -0
- {dockeriq-0.2.4 → dockeriq-2.0.3}/dockeriq.egg-info/SOURCES.txt +0 -0
- {dockeriq-0.2.4 → dockeriq-2.0.3}/dockeriq.egg-info/dependency_links.txt +0 -0
- {dockeriq-0.2.4 → dockeriq-2.0.3}/dockeriq.egg-info/entry_points.txt +0 -0
- {dockeriq-0.2.4 → dockeriq-2.0.3}/dockeriq.egg-info/top_level.txt +0 -0
- {dockeriq-0.2.4 → dockeriq-2.0.3}/setup.cfg +0 -0
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import subprocess
|
|
2
|
+
import argparse
|
|
2
3
|
import sys
|
|
3
4
|
import json
|
|
4
5
|
import os
|
|
@@ -8,6 +9,7 @@ import tarfile
|
|
|
8
9
|
import zipfile
|
|
9
10
|
import shutil
|
|
10
11
|
import urllib.request
|
|
12
|
+
from datetime import datetime # ← موجودة أصلاً
|
|
11
13
|
|
|
12
14
|
# ألوان الترمينال
|
|
13
15
|
class Colors:
|
|
@@ -50,7 +52,7 @@ def get_or_download_trivy():
|
|
|
50
52
|
|
|
51
53
|
system = platform.system().lower()
|
|
52
54
|
arch = platform.machine().lower()
|
|
53
|
-
|
|
55
|
+
|
|
54
56
|
# تحديد نظام التشغيل
|
|
55
57
|
if system == "darwin":
|
|
56
58
|
os_name = "macOS"
|
|
@@ -72,7 +74,6 @@ def get_or_download_trivy():
|
|
|
72
74
|
|
|
73
75
|
version = "0.69.3"
|
|
74
76
|
ext = "zip" if system == "windows" else "tar.gz"
|
|
75
|
-
# Trivy يستخدم '-' بين OS و arch، مش '_'
|
|
76
77
|
tarball_name = f"trivy_{version}_{os_name}-{arch_name}.{ext}"
|
|
77
78
|
url = f"https://github.com/aquasecurity/trivy/releases/download/v{version}/{tarball_name}"
|
|
78
79
|
|
|
@@ -114,18 +115,18 @@ def get_or_download_trivy():
|
|
|
114
115
|
print("👉 Please install Trivy manually from: https://github.com/aquasecurity/trivy")
|
|
115
116
|
sys.exit(1)
|
|
116
117
|
|
|
117
|
-
def scan_image(image_name):
|
|
118
|
+
def scan_image(image_name, output_file=None): # ← أضفنا output_file هنا
|
|
118
119
|
print_colored(f"\n[+] DockerIQ: Scanning image '{image_name}'...", Colors.CYAN)
|
|
119
120
|
|
|
120
121
|
trivy_path = get_or_download_trivy()
|
|
121
122
|
|
|
122
|
-
# أولًا: نزّل قاعدة البيانات
|
|
123
|
+
# أولًا: نزّل قاعدة البيانات
|
|
123
124
|
try:
|
|
124
125
|
subprocess.run([
|
|
125
126
|
trivy_path, "image", "--download-db-only", "--quiet"
|
|
126
127
|
], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, check=True)
|
|
127
128
|
except Exception:
|
|
128
|
-
pass
|
|
129
|
+
pass
|
|
129
130
|
|
|
130
131
|
# ثانيًا: شغّل الفحص الحقيقي
|
|
131
132
|
try:
|
|
@@ -140,17 +141,14 @@ def scan_image(image_name):
|
|
|
140
141
|
print_colored(f"❌ Scan failed to start: {e}", Colors.RED)
|
|
141
142
|
sys.exit(1)
|
|
142
143
|
|
|
143
|
-
# Trivy يرجع exit code 1 لو لقى ثغرات — ده طبيعي
|
|
144
144
|
if result.returncode not in (0, 1):
|
|
145
145
|
print_colored(f"❌ Trivy error: {result.stderr.strip()}", Colors.RED)
|
|
146
146
|
sys.exit(1)
|
|
147
147
|
|
|
148
|
-
# تحقق من أن الإخراج مش فارغ
|
|
149
148
|
if not result.stdout.strip():
|
|
150
149
|
print_colored("❌ Empty response from scanner.", Colors.RED)
|
|
151
150
|
sys.exit(1)
|
|
152
151
|
|
|
153
|
-
# اقرأ الـ JSON
|
|
154
152
|
try:
|
|
155
153
|
data = json.loads(result.stdout)
|
|
156
154
|
except json.JSONDecodeError:
|
|
@@ -202,15 +200,74 @@ def scan_image(image_name):
|
|
|
202
200
|
vid = v["id"]
|
|
203
201
|
title = v["title"][:80] + "..." if len(v["title"]) > 80 else v["title"]
|
|
204
202
|
print_colored(f" {icon} [{sev}] {vid} in `{pkg}`", color)
|
|
205
|
-
print(f" → {title}\n")
|
|
203
|
+
print(f" → {title}\n")
|
|
204
|
+
|
|
205
|
+
# 💾 === حفظ التقرير لو طلبه اليوزر ===
|
|
206
|
+
if output_file:
|
|
207
|
+
report = {
|
|
208
|
+
"tool": "DockerIQ",
|
|
209
|
+
"version": "2.0.1",
|
|
210
|
+
"image": image_name,
|
|
211
|
+
"timestamp": datetime.now().isoformat(),
|
|
212
|
+
"security_score": score,
|
|
213
|
+
"summary": {
|
|
214
|
+
"total": total,
|
|
215
|
+
"critical": len(critical),
|
|
216
|
+
"high": len(high),
|
|
217
|
+
"medium": len(medium),
|
|
218
|
+
"low": len(low)
|
|
219
|
+
},
|
|
220
|
+
"vulnerabilities": vulns # كل الثغرات مش بس أول 5
|
|
221
|
+
}
|
|
222
|
+
try:
|
|
223
|
+
with open(output_file, 'w', encoding='utf-8') as f:
|
|
224
|
+
json.dump(report, f, indent=2, ensure_ascii=False)
|
|
225
|
+
print_colored(f"\n💾 Report saved to: {output_file}", Colors.GREEN)
|
|
226
|
+
except Exception as e:
|
|
227
|
+
print_colored(f"❌ Failed to save report: {e}", Colors.RED)
|
|
228
|
+
|
|
229
|
+
|
|
206
230
|
def main():
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
231
|
+
# رسالة "Powered by" أول مرة
|
|
232
|
+
config_dir = os.path.expanduser("~/.dockeriq")
|
|
233
|
+
first_run = os.path.join(config_dir, "first_run")
|
|
234
|
+
if not os.path.exists(first_run):
|
|
235
|
+
print("\n Powered by Shahd Elsaidy")
|
|
236
|
+
print("Thank you for using DockerIQ!\n")
|
|
237
|
+
os.makedirs(config_dir, exist_ok=True)
|
|
238
|
+
with open(first_run, "w") as f:
|
|
239
|
+
f.write("done")
|
|
240
|
+
|
|
241
|
+
parser = argparse.ArgumentParser(
|
|
242
|
+
prog="dockeriq",
|
|
243
|
+
description="Scan Docker images for vulnerabilities"
|
|
244
|
+
)
|
|
245
|
+
parser.add_argument(
|
|
246
|
+
"command",
|
|
247
|
+
choices=["scan"],
|
|
248
|
+
help="Command to run (only 'scan' is supported)"
|
|
249
|
+
)
|
|
250
|
+
parser.add_argument(
|
|
251
|
+
"image",
|
|
252
|
+
help="Docker image name (e.g., nginx:latest or my-app)"
|
|
253
|
+
)
|
|
254
|
+
parser.add_argument(
|
|
255
|
+
"--upload",
|
|
256
|
+
action="store_true",
|
|
257
|
+
help="Upload scan results to your dashboard (requires auth)"
|
|
258
|
+
)
|
|
259
|
+
# ← أضفنا الـ argument ده
|
|
260
|
+
parser.add_argument(
|
|
261
|
+
"--output", "-o",
|
|
262
|
+
help="Save full scan results to JSON file"
|
|
263
|
+
)
|
|
264
|
+
|
|
265
|
+
args = parser.parse_args()
|
|
266
|
+
|
|
267
|
+
# مررنا output_file هنا ↓
|
|
268
|
+
scan_image(args.image, args.output)
|
|
211
269
|
|
|
212
|
-
image = sys.argv[2]
|
|
213
|
-
scan_image(image)
|
|
214
270
|
|
|
215
271
|
if __name__ == "__main__":
|
|
216
272
|
main()
|
|
273
|
+
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|