T05 · Unauthorized Access and Privilege Escalation
Error
- Location
- scripts/audit.sh:6
- Finding
- Unrestricted URL Fetching Enables Server-Side Request Forgery<![CDATA[ ## Vulnerability Details **File Location**: `scripts/audit.sh`, lines 6-18 and 74-86 **Vulnerability Type**: Server-Side Request Forgery (SSRF) through unrestricted outbound requests **Risk Level**: High ### Vulnerable Code ```bash URL=$1 if [ -z "$URL" ]; then echo "Usage: ./audit.sh <url>" exit 1 fi echo "=== SEO AUDIT: $URL ===" echo "" # Fetch main page echo "--- MAIN PAGE ---" HTTP_CODE=$(curl -s -o /tmp/seo_page.html -w "%{http_code}" -L "$URL" 2>/dev/null) ``` Additional requests are constructed from the same unvalidated input: ```bash echo "--- ROBOTS.TXT ---" ROBOTS_CODE=$(curl -s -o /tmp/seo_robots.txt -w "%{http_code}" "$URL/robots.txt" 2>/dev/null) echo "--- SITEMAP.XML ---" SITEMAP_CODE=$(curl -s -o /tmp/seo_sitemap.xml -w "%{http_code}" "$URL/sitemap.xml" 2>/dev/null) ``` ### Technical Analysis The script accepts an arbitrary URL as its first argument and passes it directly to `curl`. It does not enforce an `http` or `https` scheme, validate the destination hostname, resolve and inspect destination IP addresses, or reject loopback, private, link-local, reserved, and cloud metadata addresses. The main-page request also uses `curl -L`, which follows redirects. Even if an initial public hostname were trusted, that hostname could redirect the request to an internal address. The destination of each redirect is not revalidated. The downloaded main-page response is parsed and selected values are printed. All fetched responses are also saved to predictable files under `/tmp`. Therefore, the issue can be used for internal network probing and potentially for accessing services that trust requests originating from the host running the skill. ### Attack Path 1. An attacker supplies a URL pointing to an internal service, loopback interface, link-local service, or an attacker-controlled public endpoint. 2. The script passes that URL directly to `curl`. 3. Alternatively, the public endpoint returns a redirect to an internal destination ...[truncated 1212 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Parse the URL with a dedicated URL parser rather than relying on shell string operations. 2. Permit only explicitly required schemes, preferably `https`; reject `file`, `ftp`, `gopher`, and all other protocols. 3. Require a valid hostname and reject URLs containing unexpected credentials or malformed authority components. 4. Resolve all destination hostnames and reject every address in loopback, private, link-local, multicast, reserved, and cloud metadata ranges for both IPv4 and IPv6. 5. Disable redirects or validate the scheme, hostname, and resolved IP address at every redirect hop. 6. Add strict request limits, such as: - `--connect-timeout` - `--max-time` - `--max-redirs` - A maximum response size 7. Run requests through an egress-restricted proxy or isolated fetch service that cannot access internal networks. 8. If arbitrary public websites are required, consider hostname allowlisting or require explicit administrator approval for destinations outside an established policy. 9. Do not rely on DNS validation performed only once, because DNS rebinding can change the resolved address between validation and connection. ]]>
