vulpfest 1.0.1__tar.gz → 1.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.
- vulpfest-1.0.2/.github/dependabot.yml +10 -0
- vulpfest-1.0.2/.github/workflows/publish.yml +49 -0
- {vulpfest-1.0.1 → vulpfest-1.0.2}/PKG-INFO +3 -1
- {vulpfest-1.0.1 → vulpfest-1.0.2}/README.md +2 -0
- {vulpfest-1.0.1 → vulpfest-1.0.2}/pyproject.toml +1 -1
- vulpfest-1.0.2/src/vulpfest/__init__.py +1 -0
- {vulpfest-1.0.1 → vulpfest-1.0.2}/src/vulpfest/logo.py +19 -19
- {vulpfest-1.0.1/src/vulpfest/tools/scanner → vulpfest-1.0.2/src/vulpfest/tools/scamcheck}/ssrf_guard.py +142 -142
- {vulpfest-1.0.1 → vulpfest-1.0.2}/src/vulpfest/tools/scanner/auth_scan.py +175 -175
- {vulpfest-1.0.1 → vulpfest-1.0.2}/src/vulpfest/tools/scanner/cli.py +167 -167
- {vulpfest-1.0.1 → vulpfest-1.0.2}/src/vulpfest/tools/scanner/deep_web.py +353 -353
- {vulpfest-1.0.1 → vulpfest-1.0.2}/src/vulpfest/tools/scanner/dns_email.py +202 -202
- {vulpfest-1.0.1 → vulpfest-1.0.2}/src/vulpfest/tools/scanner/manual_review.py +60 -60
- {vulpfest-1.0.1 → vulpfest-1.0.2}/src/vulpfest/tools/scanner/repo_scan.py +434 -434
- {vulpfest-1.0.1 → vulpfest-1.0.2}/src/vulpfest/tools/scanner/scanner.py +885 -885
- {vulpfest-1.0.1/src/vulpfest/tools/scamcheck → vulpfest-1.0.2/src/vulpfest/tools/scanner}/ssrf_guard.py +142 -142
- vulpfest-1.0.1/src/vulpfest/__init__.py +0 -1
- {vulpfest-1.0.1 → vulpfest-1.0.2}/.github/FUNDING.yml +0 -0
- {vulpfest-1.0.1 → vulpfest-1.0.2}/.gitignore +0 -0
- {vulpfest-1.0.1 → vulpfest-1.0.2}/LICENSE +0 -0
- {vulpfest-1.0.1 → vulpfest-1.0.2}/SECURITY.md +0 -0
- {vulpfest-1.0.1 → vulpfest-1.0.2}/src/vulpfest/__main__.py +0 -0
- {vulpfest-1.0.1 → vulpfest-1.0.2}/src/vulpfest/banner.py +0 -0
- {vulpfest-1.0.1 → vulpfest-1.0.2}/src/vulpfest/i18n.py +0 -0
- {vulpfest-1.0.1 → vulpfest-1.0.2}/src/vulpfest/tools/gmapscout/cli.py +0 -0
- {vulpfest-1.0.1 → vulpfest-1.0.2}/src/vulpfest/tools/gmapscout/gmapscout_core.py +0 -0
- {vulpfest-1.0.1 → vulpfest-1.0.2}/src/vulpfest/tools/leadscout/cli.py +0 -0
- {vulpfest-1.0.1 → vulpfest-1.0.2}/src/vulpfest/tools/leadscout/leadscout_core.py +0 -0
- {vulpfest-1.0.1 → vulpfest-1.0.2}/src/vulpfest/tools/scamcheck/checker.py +0 -0
- {vulpfest-1.0.1 → vulpfest-1.0.2}/src/vulpfest/tools/scamcheck/cli.py +0 -0
- {vulpfest-1.0.1 → vulpfest-1.0.2}/src/vulpfest/ui.py +0 -0
- {vulpfest-1.0.1 → vulpfest-1.0.2}/tests/test_cli.py +0 -0
- {vulpfest-1.0.1 → vulpfest-1.0.2}/tools/make_logo.py +0 -0
- {vulpfest-1.0.1 → vulpfest-1.0.2}/tools/sync_tools.py +0 -0
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
name: Publish to PyPI
|
|
2
|
+
|
|
3
|
+
# Terbit otomatis saat sebuah Release dipublikasikan di GitHub.
|
|
4
|
+
# Tanpa token: PyPI mempercayai workflow ini lewat Trusted Publishing (OIDC).
|
|
5
|
+
on:
|
|
6
|
+
release:
|
|
7
|
+
types: [published]
|
|
8
|
+
|
|
9
|
+
permissions:
|
|
10
|
+
contents: read
|
|
11
|
+
|
|
12
|
+
jobs:
|
|
13
|
+
build:
|
|
14
|
+
runs-on: ubuntu-latest
|
|
15
|
+
steps:
|
|
16
|
+
- uses: actions/checkout@v4
|
|
17
|
+
- uses: actions/setup-python@v5
|
|
18
|
+
with:
|
|
19
|
+
python-version: "3.12"
|
|
20
|
+
- name: Tag must match package version
|
|
21
|
+
run: |
|
|
22
|
+
TAG="${GITHUB_REF_NAME#v}"
|
|
23
|
+
VER=$(python -c "import tomllib; print(tomllib.load(open('pyproject.toml','rb'))['project']['version'])")
|
|
24
|
+
if [ "$TAG" != "$VER" ]; then echo "Release tag $GITHUB_REF_NAME does not match version $VER in pyproject.toml"; exit 1; fi
|
|
25
|
+
- name: Test
|
|
26
|
+
run: |
|
|
27
|
+
python -m pip install -e . pytest
|
|
28
|
+
python -m pytest -q tests
|
|
29
|
+
- name: Build
|
|
30
|
+
run: |
|
|
31
|
+
python -m pip install build
|
|
32
|
+
python -m build
|
|
33
|
+
- uses: actions/upload-artifact@v4
|
|
34
|
+
with:
|
|
35
|
+
name: dist
|
|
36
|
+
path: dist/
|
|
37
|
+
|
|
38
|
+
publish:
|
|
39
|
+
needs: build
|
|
40
|
+
runs-on: ubuntu-latest
|
|
41
|
+
environment: pypi
|
|
42
|
+
permissions:
|
|
43
|
+
id-token: write # izin sementara untuk Trusted Publishing, hanya di job ini
|
|
44
|
+
steps:
|
|
45
|
+
- uses: actions/download-artifact@v4
|
|
46
|
+
with:
|
|
47
|
+
name: dist
|
|
48
|
+
path: dist/
|
|
49
|
+
- uses: pypa/gh-action-pypi-publish@release/v1
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: vulpfest
|
|
3
|
-
Version: 1.0.
|
|
3
|
+
Version: 1.0.2
|
|
4
4
|
Summary: Vulpfest Lab tools in one place: a web security scanner and a scam-link checker, from your terminal.
|
|
5
5
|
Project-URL: Homepage, https://lab.vulpfest.com
|
|
6
6
|
Project-URL: Source, https://github.com/vulpfest/vulpfest-cli
|
|
@@ -38,6 +38,8 @@ Description-Content-Type: text/markdown
|
|
|
38
38
|
|
|
39
39
|
# vulpfest
|
|
40
40
|
|
|
41
|
+
[](https://pypi.org/project/vulpfest/)
|
|
42
|
+
|
|
41
43
|
All four free tools from [Vulpfest Lab](https://lab.vulpfest.com) in one terminal command. Type `vulpfest`,
|
|
42
44
|
pick a tool from the menu, and run it — on Windows, macOS or Linux.
|
|
43
45
|
|
|
@@ -7,6 +7,8 @@
|
|
|
7
7
|
|
|
8
8
|
# vulpfest
|
|
9
9
|
|
|
10
|
+
[](https://pypi.org/project/vulpfest/)
|
|
11
|
+
|
|
10
12
|
All four free tools from [Vulpfest Lab](https://lab.vulpfest.com) in one terminal command. Type `vulpfest`,
|
|
11
13
|
pick a tool from the menu, and run it — on Windows, macOS or Linux.
|
|
12
14
|
|
|
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "vulpfest"
|
|
7
|
-
version = "1.0.
|
|
7
|
+
version = "1.0.2"
|
|
8
8
|
description = "Vulpfest Lab tools in one place: a web security scanner and a scam-link checker, from your terminal."
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.9"
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "1.0.2"
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
"""Dibuat otomatis oleh tools/make_logo.py dari path SVG logo Vulpfest."""
|
|
2
|
-
LOGO = [
|
|
3
|
-
' ▄▄ ▄▄ ',
|
|
4
|
-
' ████▄ ▄████ ',
|
|
5
|
-
' ████▀██▄ ▄██▀████ ',
|
|
6
|
-
' ████ ▀██▄▄ ▄▄██▀ ████ ',
|
|
7
|
-
' ▀███ ▀▀██▄ ██ ▄██▀▀ ███▀ ',
|
|
8
|
-
' ███▄ ▀███▄▀▀▄███▀ ▄███ ',
|
|
9
|
-
' ███ ▀██████▀ ███ ',
|
|
10
|
-
' ███ ▀▀ ███ ',
|
|
11
|
-
' ▀██▄ ▄ ▄ ▄██▀ ',
|
|
12
|
-
' ██████▄ ▄██████ ',
|
|
13
|
-
' ▀█▀██▄ ▄████▀ ',
|
|
14
|
-
' ▀███ ███▀ ',
|
|
15
|
-
' ▀███▄▄███▀ ',
|
|
16
|
-
' ██████ ',
|
|
17
|
-
' ▀██▀ ',
|
|
18
|
-
' ▀▀ ',
|
|
19
|
-
]
|
|
1
|
+
"""Dibuat otomatis oleh tools/make_logo.py dari path SVG logo Vulpfest."""
|
|
2
|
+
LOGO = [
|
|
3
|
+
' ▄▄ ▄▄ ',
|
|
4
|
+
' ████▄ ▄████ ',
|
|
5
|
+
' ████▀██▄ ▄██▀████ ',
|
|
6
|
+
' ████ ▀██▄▄ ▄▄██▀ ████ ',
|
|
7
|
+
' ▀███ ▀▀██▄ ██ ▄██▀▀ ███▀ ',
|
|
8
|
+
' ███▄ ▀███▄▀▀▄███▀ ▄███ ',
|
|
9
|
+
' ███ ▀██████▀ ███ ',
|
|
10
|
+
' ███ ▀▀ ███ ',
|
|
11
|
+
' ▀██▄ ▄ ▄ ▄██▀ ',
|
|
12
|
+
' ██████▄ ▄██████ ',
|
|
13
|
+
' ▀█▀██▄ ▄████▀ ',
|
|
14
|
+
' ▀███ ███▀ ',
|
|
15
|
+
' ▀███▄▄███▀ ',
|
|
16
|
+
' ██████ ',
|
|
17
|
+
' ▀██▀ ',
|
|
18
|
+
' ▀▀ ',
|
|
19
|
+
]
|
|
@@ -1,142 +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
|
|
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
|