vulpfest 1.0.0__py3-none-any.whl
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.
- vulpfest/__init__.py +1 -0
- vulpfest/__main__.py +108 -0
- vulpfest/banner.py +69 -0
- vulpfest/logo.py +19 -0
- vulpfest/tools/gmapscout/cli.py +51 -0
- vulpfest/tools/gmapscout/gmapscout_core.py +202 -0
- vulpfest/tools/leadscout/cli.py +52 -0
- vulpfest/tools/leadscout/leadscout_core.py +72 -0
- vulpfest/tools/scamcheck/checker.py +266 -0
- vulpfest/tools/scamcheck/cli.py +88 -0
- vulpfest/tools/scamcheck/ssrf_guard.py +142 -0
- vulpfest/tools/scanner/auth_scan.py +175 -0
- vulpfest/tools/scanner/cli.py +167 -0
- vulpfest/tools/scanner/deep_web.py +353 -0
- vulpfest/tools/scanner/dns_email.py +202 -0
- vulpfest/tools/scanner/manual_review.py +60 -0
- vulpfest/tools/scanner/repo_scan.py +434 -0
- vulpfest/tools/scanner/scanner.py +886 -0
- vulpfest/tools/scanner/ssrf_guard.py +142 -0
- vulpfest/ui.py +38 -0
- vulpfest-1.0.0.dist-info/METADATA +103 -0
- vulpfest-1.0.0.dist-info/RECORD +25 -0
- vulpfest-1.0.0.dist-info/WHEEL +4 -0
- vulpfest-1.0.0.dist-info/entry_points.txt +2 -0
- vulpfest-1.0.0.dist-info/licenses/LICENSE +21 -0
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
"""Scam Check - analisis tautan di sisi server.
|
|
2
|
+
|
|
3
|
+
Server yang membuka tautan, bukan perangkat pengguna. JavaScript tidak dijalankan, file tidak
|
|
4
|
+
diunduh penuh (hanya header), dan semua permintaan lewat ssrf_guard (menolak alamat internal).
|
|
5
|
+
Hasil: daftar sinyal. checker tidak pernah menyatakan sebuah tautan "aman"; penilaian akhir
|
|
6
|
+
(bahaya/hati-hati/bersih) dihitung dari bobot sinyal di verdict().
|
|
7
|
+
"""
|
|
8
|
+
import re
|
|
9
|
+
import socket
|
|
10
|
+
from datetime import datetime, timezone
|
|
11
|
+
from urllib.parse import urlparse, urljoin
|
|
12
|
+
|
|
13
|
+
import requests
|
|
14
|
+
from bs4 import BeautifulSoup
|
|
15
|
+
|
|
16
|
+
from ssrf_guard import BlockedTarget, check_url, guard_session
|
|
17
|
+
|
|
18
|
+
MAX_REDIRECTS = 8
|
|
19
|
+
TIMEOUT = 8
|
|
20
|
+
|
|
21
|
+
# Merek yang sering ditiru (global + Indonesia). Dipakai untuk mendeteksi domain peniru.
|
|
22
|
+
BRANDS = {
|
|
23
|
+
"paypal": ("paypal.com",), "amazon": ("amazon.com",), "apple": ("apple.com", "icloud.com"),
|
|
24
|
+
"microsoft": ("microsoft.com", "live.com", "outlook.com"), "google": ("google.com",),
|
|
25
|
+
"netflix": ("netflix.com",), "facebook": ("facebook.com",), "instagram": ("instagram.com",),
|
|
26
|
+
"whatsapp": ("whatsapp.com",), "binance": ("binance.com",), "coinbase": ("coinbase.com",),
|
|
27
|
+
"metamask": ("metamask.io",), "steam": ("steampowered.com",), "dhl": ("dhl.com",),
|
|
28
|
+
"bca": ("bca.co.id", "klikbca.com"), "mandiri": ("bankmandiri.co.id",), "bri": ("bri.co.id", "bankbri.co.id"),
|
|
29
|
+
"bni": ("bni.co.id",), "dana": ("dana.id",), "ovo": ("ovo.id",), "gopay": ("gopay.co.id",),
|
|
30
|
+
"shopee": ("shopee.co.id", "shopee.com"), "tokopedia": ("tokopedia.com",), "lazada": ("lazada.co.id",),
|
|
31
|
+
"jne": ("jne.co.id",), "jnt": ("jet.co.id",), "sicepat": ("sicepat.com",), "bpjs": ("bpjs-kesehatan.go.id",),
|
|
32
|
+
"prakerja": ("prakerja.go.id",), "pajak": ("pajak.go.id",),
|
|
33
|
+
}
|
|
34
|
+
BRAND_HOSTS = {h for hosts in BRANDS.values() for h in hosts}
|
|
35
|
+
|
|
36
|
+
RISKY_TLDS = (".zip", ".mov", ".xyz", ".top", ".tk", ".ml", ".ga", ".cf", ".gq", ".work", ".click",
|
|
37
|
+
".link", ".rest", ".country", ".kim", ".loan", ".download", ".racing", ".win", ".bid")
|
|
38
|
+
SHORTENERS = ("bit.ly", "t.co", "tinyurl.com", "goo.gl", "ow.ly", "is.gd", "buff.ly", "cutt.ly",
|
|
39
|
+
"rebrand.ly", "s.id", "bit.do", "shorturl.at", "rb.gy", "t.ly", "linktr.ee")
|
|
40
|
+
DOWNLOAD_EXT = (".apk", ".exe", ".msi", ".bat", ".scr", ".jar", ".dmg", ".apks", ".xapk")
|
|
41
|
+
SENSITIVE_WORDS = ("password", "kata sandi", "sandi", "pin", "otp", "cvv", "cvc", "kartu kredit",
|
|
42
|
+
"card number", "nomor kartu", "mother", "ibu kandung", "nik", "ktp")
|
|
43
|
+
# huruf yang sering dipakai menyamar
|
|
44
|
+
CONFUSABLE = str.maketrans({"0": "o", "1": "l", "3": "e", "4": "a", "5": "s", "7": "t", "$": "s"})
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def normalize(raw):
|
|
48
|
+
raw = (raw or "").strip()
|
|
49
|
+
if not raw:
|
|
50
|
+
return None
|
|
51
|
+
if "://" not in raw:
|
|
52
|
+
raw = "http://" + raw
|
|
53
|
+
return raw
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def registered_domain(host):
|
|
57
|
+
host = (host or "").lower().strip(".")
|
|
58
|
+
parts = host.split(".")
|
|
59
|
+
sld = {"co", "or", "go", "ac", "sch", "web", "my", "net", "com", "org"}
|
|
60
|
+
if len(parts) >= 3 and len(parts[-1]) == 2 and parts[-2] in sld:
|
|
61
|
+
return ".".join(parts[-3:])
|
|
62
|
+
return ".".join(parts[-2:]) if len(parts) >= 2 else host
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def brand_impersonation(host, full_url):
|
|
66
|
+
"""Cari merek yang disebut di domain/subdomain/path tetapi domain terdaftarnya bukan domain resmi."""
|
|
67
|
+
host = (host or "").lower()
|
|
68
|
+
reg = registered_domain(host)
|
|
69
|
+
if reg in BRAND_HOSTS:
|
|
70
|
+
return None # ini domain resmi
|
|
71
|
+
labels = host.split(".")[:-2] if host.count(".") >= 2 else []
|
|
72
|
+
hay_host = host.translate(CONFUSABLE)
|
|
73
|
+
for brand, official in BRANDS.items():
|
|
74
|
+
# merek muncul sebagai label subdomain, atau nama merek menempel di domain (bca-co-id, klik-bca)
|
|
75
|
+
in_sub = any(brand in lbl.translate(CONFUSABLE) for lbl in labels)
|
|
76
|
+
in_dom = brand in reg.split(".")[0].translate(CONFUSABLE)
|
|
77
|
+
if (in_sub or in_dom) and reg not in official:
|
|
78
|
+
return {"brand": brand, "official": official[0], "found_in": host}
|
|
79
|
+
return None
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def is_punycode(host):
|
|
83
|
+
return "xn--" in (host or "").lower()
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
def _session():
|
|
87
|
+
s = requests.Session()
|
|
88
|
+
s.headers["User-Agent"] = ("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 "
|
|
89
|
+
"(KHTML, like Gecko) Chrome/130.0 Safari/537.36 VulpfestScamCheck/1.0")
|
|
90
|
+
s.headers["Accept"] = "text/html,application/xhtml+xml,*/*;q=0.8"
|
|
91
|
+
return guard_session(s, max_redirects=MAX_REDIRECTS)
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def follow(url):
|
|
95
|
+
"""Ikuti redirect di server. Kembalikan (respons akhir, rantai, error)."""
|
|
96
|
+
s = _session()
|
|
97
|
+
chain, current = [], url
|
|
98
|
+
try:
|
|
99
|
+
for _ in range(MAX_REDIRECTS + 1):
|
|
100
|
+
check_url(current)
|
|
101
|
+
r = s.get(current, timeout=TIMEOUT, allow_redirects=False, verify=True)
|
|
102
|
+
chain.append({"url": current, "status": r.status_code})
|
|
103
|
+
if r.is_redirect or r.is_permanent_redirect:
|
|
104
|
+
loc = r.headers.get("Location", "")
|
|
105
|
+
if not loc:
|
|
106
|
+
break
|
|
107
|
+
current = urljoin(current, loc)
|
|
108
|
+
continue
|
|
109
|
+
return r, chain, None
|
|
110
|
+
return None, chain, "Terlalu banyak pengalihan (redirect)."
|
|
111
|
+
except BlockedTarget as e:
|
|
112
|
+
return None, chain, str(e)
|
|
113
|
+
except requests.exceptions.SSLError:
|
|
114
|
+
try:
|
|
115
|
+
r = s.get(current, timeout=TIMEOUT, allow_redirects=False, verify=False)
|
|
116
|
+
chain.append({"url": current, "status": r.status_code, "ssl_error": True})
|
|
117
|
+
return r, chain, None
|
|
118
|
+
except requests.exceptions.RequestException as e:
|
|
119
|
+
return None, chain, _err(e)
|
|
120
|
+
except requests.exceptions.RequestException as e:
|
|
121
|
+
return None, chain, _err(e)
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
def _err(e):
|
|
125
|
+
return f"{e.__class__.__name__}"
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
def domain_age_days(host):
|
|
129
|
+
"""Umur domain via RDAP (data pendaftaran publik). None bila tidak diketahui."""
|
|
130
|
+
reg = registered_domain(host)
|
|
131
|
+
try:
|
|
132
|
+
r = requests.get(f"https://rdap.org/domain/{reg}", timeout=6, headers={"Accept": "application/rdap+json"})
|
|
133
|
+
if r.status_code != 200:
|
|
134
|
+
return None
|
|
135
|
+
for ev in r.json().get("events", []):
|
|
136
|
+
if ev.get("eventAction") == "registration" and ev.get("eventDate"):
|
|
137
|
+
d = datetime.fromisoformat(ev["eventDate"].replace("Z", "+00:00"))
|
|
138
|
+
return (datetime.now(timezone.utc) - d).days
|
|
139
|
+
except (requests.RequestException, ValueError, KeyError):
|
|
140
|
+
return None
|
|
141
|
+
return None
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
def looks_like_login(resp):
|
|
145
|
+
"""Halaman meminta kredensial? (ada input password, atau kata sensitif + input)."""
|
|
146
|
+
ctype = resp.headers.get("Content-Type", "").lower()
|
|
147
|
+
if "html" not in ctype:
|
|
148
|
+
return None
|
|
149
|
+
soup = BeautifulSoup(resp.text[:200000], "html.parser")
|
|
150
|
+
has_password = bool(soup.find("input", attrs={"type": "password"}))
|
|
151
|
+
text = soup.get_text(" ", strip=True).lower()[:5000]
|
|
152
|
+
mentions = [w for w in SENSITIVE_WORDS if w in text]
|
|
153
|
+
forms_post = soup.find_all("form")
|
|
154
|
+
# form mengirim ke domain lain?
|
|
155
|
+
page_host = (urlparse(resp.url).hostname or "").lower()
|
|
156
|
+
cross = []
|
|
157
|
+
for f in forms_post:
|
|
158
|
+
action = (f.get("action") or "").strip()
|
|
159
|
+
if action.startswith(("http://", "https://")):
|
|
160
|
+
ah = (urlparse(action).hostname or "").lower()
|
|
161
|
+
if ah and registered_domain(ah) != registered_domain(page_host):
|
|
162
|
+
cross.append(ah)
|
|
163
|
+
if has_password or (mentions and forms_post):
|
|
164
|
+
return {"password_field": has_password, "sensitive_words": mentions[:5], "cross_domain_post": sorted(set(cross))[:3]}
|
|
165
|
+
return None
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
def download_kind(resp, final_url):
|
|
169
|
+
cd = resp.headers.get("Content-Disposition", "").lower()
|
|
170
|
+
ctype = resp.headers.get("Content-Type", "").lower()
|
|
171
|
+
path = urlparse(final_url).path.lower()
|
|
172
|
+
ext = next((e for e in DOWNLOAD_EXT if path.endswith(e) or e[1:] in cd), None)
|
|
173
|
+
app_ct = any(x in ctype for x in ("application/vnd.android.package-archive", "application/x-msdownload",
|
|
174
|
+
"application/octet-stream", "application/x-apple-diskimage"))
|
|
175
|
+
if ext:
|
|
176
|
+
return ext
|
|
177
|
+
if app_ct and "attachment" in cd:
|
|
178
|
+
return "file aplikasi"
|
|
179
|
+
return None
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
def analyze(raw_url):
|
|
183
|
+
url = normalize(raw_url)
|
|
184
|
+
out = {"input": raw_url, "url": url, "signals": [], "chain": [], "final_url": None, "error": None}
|
|
185
|
+
if not url:
|
|
186
|
+
out["error"] = "empty"
|
|
187
|
+
return out
|
|
188
|
+
p0 = urlparse(url)
|
|
189
|
+
host0 = (p0.hostname or "").lower()
|
|
190
|
+
|
|
191
|
+
def sig(level, code, **extra):
|
|
192
|
+
out["signals"].append({"level": level, "code": code, **extra})
|
|
193
|
+
|
|
194
|
+
# --- sinyal dari URL mentah, tanpa koneksi ---
|
|
195
|
+
if "@" in (p0.netloc or ""):
|
|
196
|
+
sig("danger", "at-symbol")
|
|
197
|
+
if re.match(r"^\d{1,3}(\.\d{1,3}){3}$", host0 or ""):
|
|
198
|
+
sig("warn", "ip-host")
|
|
199
|
+
if is_punycode(host0):
|
|
200
|
+
sig("warn", "punycode", host=host0)
|
|
201
|
+
if host0 in SHORTENERS:
|
|
202
|
+
sig("info", "shortener", host=host0)
|
|
203
|
+
if any(host0.endswith(t) or registered_domain(host0).endswith(t) for t in RISKY_TLDS):
|
|
204
|
+
sig("info", "risky-tld", tld=next(t for t in RISKY_TLDS if host0.endswith(t) or registered_domain(host0).endswith(t)))
|
|
205
|
+
imp0 = brand_impersonation(host0, url)
|
|
206
|
+
if imp0:
|
|
207
|
+
sig("danger", "brand-impersonation", **imp0)
|
|
208
|
+
if any(url.lower().split("?")[0].endswith(e) for e in DOWNLOAD_EXT):
|
|
209
|
+
sig("danger", "download-ext", ext=next(e for e in DOWNLOAD_EXT if url.lower().split('?')[0].endswith(e)))
|
|
210
|
+
|
|
211
|
+
# --- buka tautan di server ---
|
|
212
|
+
resp, chain, err = follow(url)
|
|
213
|
+
out["chain"] = chain
|
|
214
|
+
if err:
|
|
215
|
+
out["error"] = err
|
|
216
|
+
return out # sinyal URL (mis. peniru merek) sudah terkumpul di atas dan tetap dinilai
|
|
217
|
+
out["final_url"] = resp.url
|
|
218
|
+
pf = urlparse(resp.url)
|
|
219
|
+
host_f = (pf.hostname or "").lower()
|
|
220
|
+
|
|
221
|
+
if len([c for c in chain if c.get("status", 0) in (301, 302, 303, 307, 308)]) >= 2:
|
|
222
|
+
sig("info", "redirect-chain", hops=len(chain))
|
|
223
|
+
if host_f and registered_domain(host_f) != registered_domain(host0):
|
|
224
|
+
sig("info", "redirects-elsewhere", to=host_f)
|
|
225
|
+
|
|
226
|
+
dk = download_kind(resp, resp.url)
|
|
227
|
+
if dk and not any(x["code"] == "download-ext" for x in out["signals"]):
|
|
228
|
+
sig("danger", "download", kind=dk)
|
|
229
|
+
|
|
230
|
+
impf = brand_impersonation(host_f, resp.url)
|
|
231
|
+
if impf and impf != imp0:
|
|
232
|
+
sig("danger", "brand-impersonation", **impf)
|
|
233
|
+
|
|
234
|
+
if not dk:
|
|
235
|
+
login = looks_like_login(resp)
|
|
236
|
+
if login:
|
|
237
|
+
lvl = "danger" if login["cross_domain_post"] else "warn"
|
|
238
|
+
sig(lvl, "credential-form", **login)
|
|
239
|
+
|
|
240
|
+
age = domain_age_days(host_f)
|
|
241
|
+
if age is not None:
|
|
242
|
+
out["domain_age_days"] = age
|
|
243
|
+
if age <= 30:
|
|
244
|
+
sig("warn", "new-domain", days=age)
|
|
245
|
+
elif age <= 180:
|
|
246
|
+
sig("info", "youngish-domain", days=age)
|
|
247
|
+
|
|
248
|
+
return out
|
|
249
|
+
|
|
250
|
+
|
|
251
|
+
def verdict(result):
|
|
252
|
+
"""Tiga tingkat jujur dari sinyal. Tidak pernah menyatakan 'aman'."""
|
|
253
|
+
sigs = result.get("signals", [])
|
|
254
|
+
if result.get("error") and not any(s["level"] in ("danger", "warn") for s in sigs):
|
|
255
|
+
return {"level": "unknown", "signals": sigs}
|
|
256
|
+
levels = [s["level"] for s in result["signals"]]
|
|
257
|
+
danger = levels.count("danger")
|
|
258
|
+
warn = levels.count("warn")
|
|
259
|
+
info = levels.count("info")
|
|
260
|
+
if danger >= 1:
|
|
261
|
+
level = "danger"
|
|
262
|
+
elif warn >= 1 or info >= 3:
|
|
263
|
+
level = "warn"
|
|
264
|
+
else:
|
|
265
|
+
level = "clear"
|
|
266
|
+
return {"level": level, "counts": {"danger": danger, "warn": warn, "info": info}, "signals": result["signals"]}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"""Scam Check from the command line.
|
|
2
|
+
|
|
3
|
+
Examples:
|
|
4
|
+
python cli.py bca-co-id.xyz
|
|
5
|
+
python cli.py example.com/undangan.apk
|
|
6
|
+
python cli.py suspicious.link --json
|
|
7
|
+
|
|
8
|
+
Works on Windows, macOS and Linux. Only needs: requests, beautifulsoup4.
|
|
9
|
+
Exit codes: 0 no danger found, 1 caution, 2 danger, 3 could not check.
|
|
10
|
+
"""
|
|
11
|
+
import argparse
|
|
12
|
+
import json
|
|
13
|
+
import sys
|
|
14
|
+
|
|
15
|
+
import checker
|
|
16
|
+
|
|
17
|
+
VERDICT = {
|
|
18
|
+
"danger": ("BAHAYA", "tanda penipuan yang kuat"),
|
|
19
|
+
"warn": ("HATI-HATI", "beberapa hal yang mencurigakan"),
|
|
20
|
+
"clear": ("TIDAK DITEMUKAN TANDA BAHAYA", "tetap waspada"),
|
|
21
|
+
"unknown": ("TIDAK DAPAT DIPERIKSA", "periksa kembali tautannya"),
|
|
22
|
+
}
|
|
23
|
+
EXIT = {"clear": 0, "warn": 1, "danger": 2, "unknown": 3}
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def explain(s):
|
|
27
|
+
c = s.get("code")
|
|
28
|
+
if c in ("download", "download-ext"):
|
|
29
|
+
return f"Mengunduh file aplikasi ({s.get('ext') or s.get('kind')}). Jangan dipasang."
|
|
30
|
+
if c == "brand-impersonation":
|
|
31
|
+
return f"Menyebut \"{s.get('brand')}\" tetapi bukan alamat resminya ({s.get('official')})."
|
|
32
|
+
if c == "credential-form":
|
|
33
|
+
extra = " dan mengirimnya ke domain lain" if s.get("cross_domain_post") else ""
|
|
34
|
+
return f"Meminta data rahasia (sandi/PIN/OTP){extra}."
|
|
35
|
+
if c == "at-symbol":
|
|
36
|
+
return "Memakai tanda @ yang bisa menyembunyikan tujuan sebenarnya."
|
|
37
|
+
if c == "ip-host":
|
|
38
|
+
return "Alamat berupa angka IP, bukan nama domain."
|
|
39
|
+
if c == "punycode":
|
|
40
|
+
return "Memakai huruf non-Latin yang bisa menyamar jadi huruf biasa."
|
|
41
|
+
if c == "new-domain":
|
|
42
|
+
return f"Domain baru dibuat sekitar {s.get('days')} hari lalu."
|
|
43
|
+
if c == "shortener":
|
|
44
|
+
return "Tautan pendek yang menyembunyikan tujuan."
|
|
45
|
+
if c == "redirect-chain":
|
|
46
|
+
return f"Melewati {s.get('hops')} pengalihan sebelum sampai tujuan."
|
|
47
|
+
if c == "redirects-elsewhere":
|
|
48
|
+
return f"Berpindah ke alamat lain: {s.get('to')}."
|
|
49
|
+
if c == "risky-tld":
|
|
50
|
+
return f"Akhiran domain {s.get('tld')} sering dipakai untuk penipuan."
|
|
51
|
+
if c == "no-https":
|
|
52
|
+
return "Tidak memakai HTTPS, data tidak terenkripsi."
|
|
53
|
+
return c
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def main():
|
|
57
|
+
ap = argparse.ArgumentParser(description="Periksa sebuah tautan untuk tanda-tanda penipuan (Vulpfest Lab).")
|
|
58
|
+
ap.add_argument("url", help="tautan yang ingin diperiksa, misalnya bca-co-id.xyz")
|
|
59
|
+
ap.add_argument("--json", action="store_true", help="tampilkan hasil mentah sebagai JSON")
|
|
60
|
+
args = ap.parse_args()
|
|
61
|
+
|
|
62
|
+
print("Pengingat: periksa tautan yang Anda terima; jangan memindai sistem orang lain tanpa izin.", file=sys.stderr)
|
|
63
|
+
result = checker.analyze(args.url)
|
|
64
|
+
result["verdict"] = checker.verdict(result)
|
|
65
|
+
level = result["verdict"]["level"]
|
|
66
|
+
|
|
67
|
+
if args.json:
|
|
68
|
+
print(json.dumps(result, indent=2, ensure_ascii=False))
|
|
69
|
+
return EXIT.get(level, 3)
|
|
70
|
+
|
|
71
|
+
label, tag = VERDICT.get(level, VERDICT["unknown"])
|
|
72
|
+
mark = {"danger": "[!]", "warn": "[~]", "clear": "[ok]", "unknown": "[?]"}.get(level, "[?]")
|
|
73
|
+
print(f"\n {mark} {label} - {tag}")
|
|
74
|
+
print(f" Anda masukkan : {result.get('input')}")
|
|
75
|
+
if result.get("final_url") and result["final_url"] != result.get("input"):
|
|
76
|
+
print(f" Tujuan akhir : {result['final_url']}")
|
|
77
|
+
print()
|
|
78
|
+
for i, s in enumerate(result.get("signals", []), 1):
|
|
79
|
+
pre = {"danger": "!", "warn": "~", "info": "-"}.get(s.get("level"), "-")
|
|
80
|
+
print(f" {pre} {explain(s)}")
|
|
81
|
+
if not result.get("signals"):
|
|
82
|
+
print(" (tidak ada sinyal yang ditemukan)")
|
|
83
|
+
print("\n Catatan: tidak ada alat yang menjamin tautan 100% aman. Tetap waspada.\n")
|
|
84
|
+
return EXIT.get(level, 3)
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
if __name__ == "__main__":
|
|
88
|
+
sys.exit(main())
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
"""Pengaman SSRF untuk Cyber Web Scanner.
|
|
2
|
+
|
|
3
|
+
Pemindai mengambil URL dari pengguna, jadi ia tidak boleh dipakai untuk menghubungi jaringan
|
|
4
|
+
internal: alamat privat, loopback, link-local (termasuk metadata cloud 169.254.169.254), CGNAT,
|
|
5
|
+
dan sejenisnya. Pemeriksaan dilakukan di tiga lapis:
|
|
6
|
+
1. sebelum setiap permintaan HTTP, termasuk setiap lompatan redirect;
|
|
7
|
+
2. setelah koneksi terbuka, terhadap IP yang benar-benar dihubungi (menutup celah DNS rebinding);
|
|
8
|
+
3. untuk koneksi TLS langsung (pemeriksaan sertifikat dan TLS lama).
|
|
9
|
+
"""
|
|
10
|
+
import ipaddress
|
|
11
|
+
import socket
|
|
12
|
+
from urllib.parse import urlparse
|
|
13
|
+
|
|
14
|
+
import requests
|
|
15
|
+
import urllib3.util.connection as _u3conn
|
|
16
|
+
from requests.adapters import HTTPAdapter
|
|
17
|
+
|
|
18
|
+
ALLOWED_SCHEMES = ("http", "https")
|
|
19
|
+
ALLOWED_PORTS = (None, 80, 443, 8080, 8443)
|
|
20
|
+
MAX_REDIRECTS = 5
|
|
21
|
+
MAX_BYTES = 5 * 1024 * 1024
|
|
22
|
+
BLOCKED_SUFFIXES = (".localhost", ".local", ".internal", ".lan", ".home.arpa")
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class BlockedTarget(requests.exceptions.RequestException):
|
|
26
|
+
"""Tujuan ditolak demi keamanan (jaringan internal, skema, atau port tidak diizinkan)."""
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
class ResponseTooLarge(requests.exceptions.RequestException):
|
|
30
|
+
"""Respons melebihi batas ukuran."""
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def is_public_ip(ip):
|
|
34
|
+
"""True hanya untuk alamat yang dapat dirutekan di internet publik."""
|
|
35
|
+
try:
|
|
36
|
+
addr = ipaddress.ip_address(str(ip).split("%")[0])
|
|
37
|
+
except ValueError:
|
|
38
|
+
return False
|
|
39
|
+
if addr.version == 6 and addr.ipv4_mapped:
|
|
40
|
+
addr = addr.ipv4_mapped
|
|
41
|
+
return addr.is_global and not addr.is_multicast
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def resolve_public(host):
|
|
45
|
+
"""Resolusi DNS; tolak bila SATU saja alamatnya bukan alamat publik."""
|
|
46
|
+
host = (host or "").strip().strip("[]").rstrip(".").lower()
|
|
47
|
+
if not host:
|
|
48
|
+
raise BlockedTarget("Alamat tujuan kosong.")
|
|
49
|
+
if host == "localhost" or host.endswith(BLOCKED_SUFFIXES):
|
|
50
|
+
raise BlockedTarget(f"Alamat {host} adalah jaringan lokal; pemindaian ditolak.")
|
|
51
|
+
try:
|
|
52
|
+
infos = socket.getaddrinfo(host, None, proto=socket.IPPROTO_TCP)
|
|
53
|
+
except socket.gaierror as e:
|
|
54
|
+
raise requests.exceptions.ConnectionError(f"Nama domain {host} tidak dapat ditemukan ({e}).")
|
|
55
|
+
ips = sorted({info[4][0] for info in infos})
|
|
56
|
+
for ip in ips:
|
|
57
|
+
if not is_public_ip(ip):
|
|
58
|
+
raise BlockedTarget(f"Alamat {host} mengarah ke jaringan privat atau internal ({ip}); pemindaian ditolak.")
|
|
59
|
+
return ips
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def check_url(url):
|
|
63
|
+
"""Validasi satu URL sebelum dihubungi."""
|
|
64
|
+
p = urlparse(url)
|
|
65
|
+
if p.scheme.lower() not in ALLOWED_SCHEMES:
|
|
66
|
+
raise BlockedTarget("Hanya alamat http:// dan https:// yang dapat dipindai.")
|
|
67
|
+
try:
|
|
68
|
+
port = p.port
|
|
69
|
+
except ValueError:
|
|
70
|
+
raise BlockedTarget("Port pada alamat tidak valid.")
|
|
71
|
+
if port not in ALLOWED_PORTS:
|
|
72
|
+
raise BlockedTarget(f"Port {port} tidak diizinkan; hanya port web standar (80, 443, 8080, 8443).")
|
|
73
|
+
if p.username or p.password:
|
|
74
|
+
raise BlockedTarget("Alamat yang berisi nama pengguna atau kata sandi tidak dapat dipindai.")
|
|
75
|
+
return resolve_public(p.hostname)
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
# --- Lapis 2: periksa IP yang benar-benar dihubungi ---
|
|
79
|
+
_original_create_connection = _u3conn.create_connection
|
|
80
|
+
_installed = False
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def _guarded_create_connection(address, *args, **kwargs):
|
|
84
|
+
sock = _original_create_connection(address, *args, **kwargs)
|
|
85
|
+
try:
|
|
86
|
+
peer = sock.getpeername()[0]
|
|
87
|
+
except OSError:
|
|
88
|
+
peer = None
|
|
89
|
+
if peer is None or not is_public_ip(peer):
|
|
90
|
+
sock.close()
|
|
91
|
+
raise BlockedTarget(f"Koneksi ke alamat internal ({peer}) diblokir.")
|
|
92
|
+
return sock
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def install_connection_guard():
|
|
96
|
+
global _installed
|
|
97
|
+
if not _installed:
|
|
98
|
+
_u3conn.create_connection = _guarded_create_connection
|
|
99
|
+
_installed = True
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
# --- Lapis 3: koneksi soket langsung (TLS) ---
|
|
103
|
+
def connect_public(address, timeout=None):
|
|
104
|
+
host, port = address
|
|
105
|
+
resolve_public(host)
|
|
106
|
+
sock = socket.create_connection(address, timeout=timeout)
|
|
107
|
+
peer = sock.getpeername()[0]
|
|
108
|
+
if not is_public_ip(peer):
|
|
109
|
+
sock.close()
|
|
110
|
+
raise BlockedTarget(f"Koneksi ke alamat internal ({peer}) diblokir.")
|
|
111
|
+
return sock
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
# --- Lapis 1: setiap permintaan, termasuk setiap redirect, plus batas ukuran ---
|
|
115
|
+
class GuardedAdapter(HTTPAdapter):
|
|
116
|
+
def send(self, request, stream=False, **kwargs):
|
|
117
|
+
check_url(request.url)
|
|
118
|
+
resp = super().send(request, stream=True, **kwargs)
|
|
119
|
+
if stream:
|
|
120
|
+
return resp
|
|
121
|
+
data = resp.raw.read(MAX_BYTES + 1, decode_content=True)
|
|
122
|
+
if len(data) > MAX_BYTES:
|
|
123
|
+
resp.close()
|
|
124
|
+
raise ResponseTooLarge(f"Respons lebih dari {MAX_BYTES // (1024 * 1024)} MB; pengambilan dihentikan.")
|
|
125
|
+
resp._content = data
|
|
126
|
+
resp._content_consumed = True
|
|
127
|
+
try:
|
|
128
|
+
resp.raw.release_conn()
|
|
129
|
+
except Exception:
|
|
130
|
+
pass
|
|
131
|
+
return resp
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
def guard_session(session, max_redirects=MAX_REDIRECTS):
|
|
135
|
+
"""Pasang semua pengaman pada sebuah requests.Session."""
|
|
136
|
+
install_connection_guard()
|
|
137
|
+
adapter = GuardedAdapter(max_retries=0)
|
|
138
|
+
session.mount("http://", adapter)
|
|
139
|
+
session.mount("https://", adapter)
|
|
140
|
+
session.max_redirects = max_redirects
|
|
141
|
+
session.trust_env = False # abaikan proxy dari environment agar pemeriksaan IP akurat
|
|
142
|
+
return session
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
"""Mode D: pemeriksaan terautentikasi (terminal saja, untuk situs milik sendiri)."""
|
|
2
|
+
import base64
|
|
3
|
+
import json
|
|
4
|
+
import re
|
|
5
|
+
import secrets
|
|
6
|
+
import time
|
|
7
|
+
|
|
8
|
+
import requests
|
|
9
|
+
|
|
10
|
+
from ssrf_guard import check_url, guard_session
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class AuthConfig:
|
|
14
|
+
def __init__(self, data):
|
|
15
|
+
self.accounts = data.get('accounts') or []
|
|
16
|
+
self.login = data.get('login') or {}
|
|
17
|
+
self.object_urls = data.get('object_urls') or []
|
|
18
|
+
self.reset = data.get('reset') or {}
|
|
19
|
+
|
|
20
|
+
@property
|
|
21
|
+
def ok(self):
|
|
22
|
+
return len(self.accounts) >= 1
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
EXAMPLE = {
|
|
26
|
+
"accounts": [
|
|
27
|
+
{"name": "A", "cookies": {"session": "paste-account-A-session-cookie"}},
|
|
28
|
+
{"name": "B", "cookies": {"session": "paste-account-B-session-cookie"}},
|
|
29
|
+
],
|
|
30
|
+
"object_urls": [
|
|
31
|
+
{"as": "A", "url": "https://example.com/api/orders/1001", "owned_by_other": "https://example.com/api/orders/2002"}
|
|
32
|
+
],
|
|
33
|
+
"login": {"url": "https://example.com/api/login", "method": "POST",
|
|
34
|
+
"json": {"email": "a@example.com", "password": "wrong-on-purpose"}},
|
|
35
|
+
"reset": {"url": "https://example.com/api/forgot-password", "method": "POST",
|
|
36
|
+
"json": {"email": "a@example.com"}}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def _session(verify):
|
|
41
|
+
s = requests.Session()
|
|
42
|
+
s.headers['User-Agent'] = 'CyberWebScanner/2.0 (authenticated, owner-verified)'
|
|
43
|
+
s.verify = verify
|
|
44
|
+
return guard_session(s)
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def verify_ownership(host):
|
|
48
|
+
token = 'cws-' + secrets.token_hex(16)
|
|
49
|
+
return token, {
|
|
50
|
+
'file': f'https://{host}/.well-known/cws-verify-{token}.txt (isi file: {token})',
|
|
51
|
+
'dns': f'TXT record di _cws-verify.{host} dengan nilai: {token}',
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def confirm_ownership(host, token, verify=True):
|
|
56
|
+
s = _session(verify)
|
|
57
|
+
try:
|
|
58
|
+
r = s.get(f'https://{host}/.well-known/cws-verify-{token}.txt', timeout=8, allow_redirects=False)
|
|
59
|
+
if r.status_code == 200 and token in (r.text or '')[:200]:
|
|
60
|
+
return True, 'file'
|
|
61
|
+
except requests.exceptions.RequestException:
|
|
62
|
+
pass
|
|
63
|
+
try:
|
|
64
|
+
import dns_email
|
|
65
|
+
_, txt = dns_email.doh(f'_cws-verify.{host}', 'TXT')
|
|
66
|
+
if any(token in t for t in txt):
|
|
67
|
+
return True, 'dns'
|
|
68
|
+
except Exception:
|
|
69
|
+
pass
|
|
70
|
+
return False, None
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def _acc_session(acc, verify):
|
|
74
|
+
s = _session(verify)
|
|
75
|
+
for k, v in (acc.get('cookies') or {}).items():
|
|
76
|
+
s.cookies.set(k, v)
|
|
77
|
+
s.headers.update(acc.get('headers') or {})
|
|
78
|
+
return s
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def check_idor(cfg, verify):
|
|
82
|
+
findings = []
|
|
83
|
+
sessions = {a['name']: _acc_session(a, verify) for a in cfg.accounts}
|
|
84
|
+
for item in cfg.object_urls:
|
|
85
|
+
other = item.get('owned_by_other')
|
|
86
|
+
who = item.get('as')
|
|
87
|
+
if not other or who not in sessions:
|
|
88
|
+
continue
|
|
89
|
+
check_url(other)
|
|
90
|
+
try:
|
|
91
|
+
r = sessions[who].get(other, timeout=10, allow_redirects=False)
|
|
92
|
+
except requests.exceptions.RequestException:
|
|
93
|
+
continue
|
|
94
|
+
body = (r.text or '')[:4000]
|
|
95
|
+
if r.status_code == 200 and ('json' in r.headers.get('Content-Type', '').lower() or len(body) > 200):
|
|
96
|
+
findings.append({'url': other, 'as': who, 'status': r.status_code})
|
|
97
|
+
return findings
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
def check_rate_limit(cfg, verify):
|
|
101
|
+
lg = cfg.login
|
|
102
|
+
if not lg.get('url'):
|
|
103
|
+
return None
|
|
104
|
+
check_url(lg['url'])
|
|
105
|
+
s = _session(verify)
|
|
106
|
+
codes = []
|
|
107
|
+
for _ in range(8):
|
|
108
|
+
try:
|
|
109
|
+
r = s.request(lg.get('method', 'POST'), lg['url'], json=lg.get('json'), data=lg.get('data'), timeout=8, allow_redirects=False)
|
|
110
|
+
codes.append(r.status_code)
|
|
111
|
+
if r.status_code == 429:
|
|
112
|
+
break
|
|
113
|
+
except requests.exceptions.RequestException:
|
|
114
|
+
break
|
|
115
|
+
time.sleep(0.3)
|
|
116
|
+
return {'attempts': len(codes), 'codes': codes, 'limited': 429 in codes}
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
def check_session_tokens(cfg, verify):
|
|
120
|
+
issues = []
|
|
121
|
+
for a in cfg.accounts:
|
|
122
|
+
for k, v in (a.get('cookies') or {}).items():
|
|
123
|
+
if re.search(r'(sess|sid|token|auth|jwt)', k, re.I) and re.match(r'^eyJ[A-Za-z0-9_-]+\.', v or ''):
|
|
124
|
+
try:
|
|
125
|
+
head = json.loads(base64.urlsafe_b64decode(v.split('.')[0] + '=='))
|
|
126
|
+
if str(head.get('alg', '')).lower() == 'none':
|
|
127
|
+
issues.append({'account': a['name'], 'issue': 'JWT memakai alg: none'})
|
|
128
|
+
except Exception:
|
|
129
|
+
pass
|
|
130
|
+
return issues
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
def check_host_header(cfg, verify):
|
|
134
|
+
rs = cfg.reset
|
|
135
|
+
if not rs.get('url'):
|
|
136
|
+
return None
|
|
137
|
+
check_url(rs['url'])
|
|
138
|
+
s = _session(verify)
|
|
139
|
+
marker = 'cws-hosttest.example'
|
|
140
|
+
try:
|
|
141
|
+
r = s.request(rs.get('method', 'POST'), rs['url'], json=rs.get('json'), data=rs.get('data'),
|
|
142
|
+
headers={'X-Forwarded-Host': marker}, timeout=8, allow_redirects=False)
|
|
143
|
+
except requests.exceptions.RequestException:
|
|
144
|
+
return None
|
|
145
|
+
return {'reflected': marker in (r.text or '')[:4000]}
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
def run(cfg, verify=True):
|
|
149
|
+
out = {'idor': [], 'rate_limit': None, 'session': [], 'host_header': None, 'notes': []}
|
|
150
|
+
for name, fn in (('idor', check_idor), ('rate_limit', check_rate_limit), ('host_header', check_host_header)):
|
|
151
|
+
try:
|
|
152
|
+
out[name] = fn(cfg, verify)
|
|
153
|
+
except Exception as e:
|
|
154
|
+
out['notes'].append(f'{name}: {e.__class__.__name__}')
|
|
155
|
+
out['session'] = check_session_tokens(cfg, verify)
|
|
156
|
+
return out
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
def findings(r):
|
|
160
|
+
out = []
|
|
161
|
+
for x in r.get('idor', []):
|
|
162
|
+
out.append(('AUTH-IDOR', 30, 'Tinggi', f"Kontrol akses bocor: akun {x['as']} dapat membaca objek milik akun lain ({x['url']}).",
|
|
163
|
+
'Pastikan setiap endpoint memeriksa bahwa objek yang diminta milik pengguna yang login.', 'identity', 'senior', 'high'))
|
|
164
|
+
rl = r.get('rate_limit')
|
|
165
|
+
if rl and not rl.get('limited') and rl.get('attempts', 0) >= 5:
|
|
166
|
+
out.append(('AUTH-NO-RATE-LIMIT', 10, 'Menengah', f"Login tidak membatasi percobaan ({rl['attempts']} percobaan tanpa HTTP 429).",
|
|
167
|
+
'Batasi percobaan login per akun dan per IP; tambahkan penundaan atau CAPTCHA.', 'identity', 'beginner', 'medium'))
|
|
168
|
+
for x in r.get('session', []):
|
|
169
|
+
out.append(('AUTH-WEAK-JWT', 10, 'Menengah', f"Token sesi akun {x['account']} lemah: {x['issue']}.",
|
|
170
|
+
'Pakai algoritma tanda tangan yang kuat dan verifikasi setiap token.', 'identity', 'senior', 'high'))
|
|
171
|
+
hh = r.get('host_header')
|
|
172
|
+
if hh and hh.get('reflected'):
|
|
173
|
+
out.append(('AUTH-HOST-HEADER', 10, 'Menengah', 'Alur reset memantulkan header Host dari penyerang.',
|
|
174
|
+
'Bangun tautan reset dari alamat situs yang tetap di server, bukan dari header Host.', 'identity', 'senior', 'medium'))
|
|
175
|
+
return out
|