-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqguard.py
More file actions
102 lines (79 loc) · 3.14 KB
/
qguard.py
File metadata and controls
102 lines (79 loc) · 3.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import cv2
import numpy as np
import pickle
# --- 1. LOAD THE BRAIN ---
print("Loading QGuard AI Model...")
try:
with open("phishing_model.pkl", "rb") as file:
model = pickle.load(file)
print("✅ AI Model Loaded Successfully!")
except FileNotFoundError:
print("❌ ERROR: 'phishing_model.pkl' not found.")
exit()
# --- 2. DEFINE THE RULES ---
def get_features(url):
url = str(url)
return [
len(url),
url.count('.'),
url.count('@'),
url.count('-'),
1 if "https" in url else 0,
sum(c.isdigit() for c in url)
]
# --- 3. THE WHITELIST (New Feature!) ---
def check_whitelist(url):
# These are safe keywords for payments or common sites
safe_keywords = ["upi://", "paytm", "phonepe", "gpay", "bhim", "google.com", "amazon"]
for keyword in safe_keywords:
if keyword.lower() in url.lower():
return True # It is safe!
return False # Not in whitelist, ask the AI
# --- 4. START THE SYSTEM ---
def start_qguard():
cap = cv2.VideoCapture(0)
detector = cv2.QRCodeDetector()
# UI Colors
RED = (0, 0, 255)
GREEN = (0, 255, 0)
ORANGE = (0, 165, 255) # New color for Whitelisted items
font = cv2.FONT_HERSHEY_SIMPLEX
print("🛡️ QuishGuard Active. Point camera at a QR Code...")
while True:
_, frame = cap.read()
data, bbox, _ = detector.detectAndDecode(frame)
if bbox is not None and data:
points = bbox.astype(int)
# --- LOGIC START ---
# STEP 1: Check Whitelist (Is it a Payment QR?)
if check_whitelist(data):
color = ORANGE
text = "SAFE: PAYMENT/VERIFIED"
print(f"Scanned: {data} -> [WHITELISTED SAFE]")
# STEP 2: If not whitelisted, ask AI
else:
features = np.array([get_features(data)])
prediction = model.predict(features)[0]
if prediction == 1:
color = RED
text = "DANGER: PHISHING!"
else:
color = GREEN
text = "SAFE URL"
print(f"Scanned: {data} -> {text}")
# --- LOGIC END ---
# Draw Box
for i in range(len(points[0])):
cv2.line(frame, tuple(points[0][i]), tuple(points[0][(i+1) % 4]), color, 5)
# Draw Text
cv2.rectangle(frame, (points[0][0][0], points[0][0][1] - 40),
(points[0][0][0] + 350, points[0][0][1]), color, -1)
cv2.putText(frame, text, (points[0][0][0], points[0][0][1] - 10),
font, 0.6, (255, 255, 255), 2)
cv2.imshow('QuishGuard - Live Protection', frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()
if __name__ == "__main__":
start_qguard()