dockeriq 0.2.3__tar.gz → 2.0.2__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.3 → dockeriq-2.0.2}/PKG-INFO +1 -1
- {dockeriq-0.2.3 → dockeriq-2.0.2}/dockeriq/cli.py +91 -17
- {dockeriq-0.2.3 → dockeriq-2.0.2}/dockeriq.egg-info/PKG-INFO +1 -1
- {dockeriq-0.2.3 → dockeriq-2.0.2}/setup.py +1 -1
- {dockeriq-0.2.3 → dockeriq-2.0.2}/README.md +0 -0
- {dockeriq-0.2.3 → dockeriq-2.0.2}/dockeriq/__init__.py +0 -0
- {dockeriq-0.2.3 → dockeriq-2.0.2}/dockeriq.egg-info/SOURCES.txt +0 -0
- {dockeriq-0.2.3 → dockeriq-2.0.2}/dockeriq.egg-info/dependency_links.txt +0 -0
- {dockeriq-0.2.3 → dockeriq-2.0.2}/dockeriq.egg-info/entry_points.txt +0 -0
- {dockeriq-0.2.3 → dockeriq-2.0.2}/dockeriq.egg-info/top_level.txt +0 -0
- {dockeriq-0.2.3 → dockeriq-2.0.2}/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,33 +115,47 @@ 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
|
|
|
123
|
+
# أولًا: نزّل قاعدة البيانات
|
|
124
|
+
try:
|
|
125
|
+
subprocess.run([
|
|
126
|
+
trivy_path, "image", "--download-db-only", "--quiet"
|
|
127
|
+
], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, check=True)
|
|
128
|
+
except Exception:
|
|
129
|
+
pass
|
|
130
|
+
|
|
131
|
+
# ثانيًا: شغّل الفحص الحقيقي
|
|
122
132
|
try:
|
|
123
133
|
result = subprocess.run([
|
|
124
134
|
trivy_path, "image",
|
|
125
|
-
"--quiet",
|
|
126
|
-
"--skip-db-update",
|
|
127
135
|
"--format", "json",
|
|
136
|
+
"--no-progress",
|
|
137
|
+
"--quiet",
|
|
128
138
|
image_name
|
|
129
|
-
],
|
|
139
|
+
], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
|
|
130
140
|
except Exception as e:
|
|
131
|
-
print_colored(f"❌ Scan failed: {e}", Colors.RED)
|
|
141
|
+
print_colored(f"❌ Scan failed to start: {e}", Colors.RED)
|
|
132
142
|
sys.exit(1)
|
|
133
143
|
|
|
134
144
|
if result.returncode not in (0, 1):
|
|
135
|
-
print_colored(f"❌ Trivy error: {result.stderr}", Colors.RED)
|
|
145
|
+
print_colored(f"❌ Trivy error: {result.stderr.strip()}", Colors.RED)
|
|
146
|
+
sys.exit(1)
|
|
147
|
+
|
|
148
|
+
if not result.stdout.strip():
|
|
149
|
+
print_colored("❌ Empty response from scanner.", Colors.RED)
|
|
136
150
|
sys.exit(1)
|
|
137
151
|
|
|
138
152
|
try:
|
|
139
153
|
data = json.loads(result.stdout)
|
|
140
154
|
except json.JSONDecodeError:
|
|
141
|
-
print_colored("❌ Invalid scan output.", Colors.RED)
|
|
155
|
+
print_colored("❌ Invalid scan output (not valid JSON).", Colors.RED)
|
|
142
156
|
sys.exit(1)
|
|
143
157
|
|
|
158
|
+
# استخرج الثغرات
|
|
144
159
|
vulns = []
|
|
145
160
|
for res in data.get("Results", []):
|
|
146
161
|
for v in res.get("Vulnerabilities", []):
|
|
@@ -151,6 +166,7 @@ def scan_image(image_name):
|
|
|
151
166
|
"title": v.get("Title", "No title available")
|
|
152
167
|
})
|
|
153
168
|
|
|
169
|
+
# حساب الدرجة والعرض
|
|
154
170
|
critical = [v for v in vulns if v["severity"] == "CRITICAL"]
|
|
155
171
|
high = [v for v in vulns if v["severity"] == "HIGH"]
|
|
156
172
|
medium = [v for v in vulns if v["severity"] == "MEDIUM"]
|
|
@@ -175,8 +191,8 @@ def scan_image(image_name):
|
|
|
175
191
|
if low:
|
|
176
192
|
print_colored(f" 🟢 Low: {len(low)}", Colors.GREEN)
|
|
177
193
|
|
|
178
|
-
print(f"\n🔍 Details:")
|
|
179
|
-
for v in vulns:
|
|
194
|
+
print(f"\n🔍 Details (first 5):")
|
|
195
|
+
for v in vulns[:5]:
|
|
180
196
|
sev = v["severity"]
|
|
181
197
|
icon = "🔴" if sev == "CRITICAL" else "🟠" if sev == "HIGH" else "🟡" if sev == "MEDIUM" else "🟢"
|
|
182
198
|
color = Colors.RED if sev == "CRITICAL" else Colors.ORANGE if sev == "HIGH" else Colors.YELLOW if sev == "MEDIUM" else Colors.GREEN
|
|
@@ -186,14 +202,72 @@ def scan_image(image_name):
|
|
|
186
202
|
print_colored(f" {icon} [{sev}] {vid} in `{pkg}`", color)
|
|
187
203
|
print(f" → {title}\n")
|
|
188
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
|
+
|
|
189
230
|
def main():
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
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)
|
|
194
269
|
|
|
195
|
-
image = sys.argv[2]
|
|
196
|
-
scan_image(image)
|
|
197
270
|
|
|
198
271
|
if __name__ == "__main__":
|
|
199
272
|
main()
|
|
273
|
+
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|