Special HTTP headers

Support HackTricks

Wordlists & Tools

Headers to Change Location

Rewrite IP source:

  • X-Originating-IP: 127.0.0.1

  • X-Forwarded-For: 127.0.0.1

  • X-Forwarded: 127.0.0.1

  • Forwarded-For: 127.0.0.1

  • X-Forwarded-Host: 127.0.0.1

  • X-Remote-IP: 127.0.0.1

  • X-Remote-Addr: 127.0.0.1

  • X-ProxyUser-Ip: 127.0.0.1

  • X-Original-URL: 127.0.0.1

  • Client-IP: 127.0.0.1

  • X-Client-IP: 127.0.0.1

  • X-Host: 127.0.0.1

  • True-Client-IP: 127.0.0.1

  • Cluster-Client-IP: 127.0.0.1

  • Via: 1.0 fred, 1.1 127.0.0.1

  • Connection: close, X-Forwarded-For (Check hop-by-hop headers)

Rewrite location:

  • X-Original-URL: /admin/console

  • X-Rewrite-URL: /admin/console

Hop-by-Hop headers

A hop-by-hop header is a header which is designed to be processed and consumed by the proxy currently handling the request, as opposed to an end-to-end header.

  • Connection: close, X-Forwarded-For

hop-by-hop headers

HTTP Request Smuggling

  • Content-Length: 30

  • Transfer-Encoding: chunked

HTTP Request Smuggling / HTTP Desync Attack

Cache Headers

Server Cache Headers:

  • X-Cache in the response may have the value miss when the request wasn't cached and the value hit when it is cached

  • Similar behaviour in the header Cf-Cache-Status

  • Cache-Control indicates if a resource is being cached and when will be the next time the resource will be cached again: Cache-Control: public, max-age=1800

  • Vary is often used in the response to indicate additional headers that are treated as part of the cache key even if they are normally unkeyed.

  • Age defines the times in seconds the object has been in the proxy cache.

  • Server-Timing: cdn-cache; desc=HIT also indicates that a resource was cached

Cache Poisoning and Cache Deception

Local Cache headers:

  • Clear-Site-Data: 캐시를 제거해야 함을 나타내는 헤더: Clear-Site-Data: "cache", "cookies"

  • Expires: 응답이 만료되어야 하는 날짜/시간을 포함: Expires: Wed, 21 Oct 2015 07:28:00 GMT

  • Pragma: no-cache Cache-Control: no-cache와 동일

  • Warning: Warning 일반 HTTP 헤더는 메시지 상태와 관련된 가능한 문제에 대한 정보를 포함합니다. 응답에 여러 개의 Warning 헤더가 나타날 수 있습니다. Warning: 110 anderson/1.3.37 "Response is stale"

Conditionals

  • Requests using these headers: If-Modified-Since and If-Unmodified-Since will be responded with data only if the response header**Last-Modified** contains a different time.

  • Conditional requests using If-Match and If-None-Match use an Etag value so the web server will send the content of the response if the data (Etag) has changed. The Etag is taken from the HTTP response.

  • The Etag value is usually calculated based on the content of the response. For example, ETag: W/"37-eL2g8DEyqntYlaLp5XLInBWsjWI" indicates that the Etag is the Sha1 of 37 bytes.

Range requests

  • Accept-Ranges: 서버가 범위 요청을 지원하는지 여부를 나타내며, 지원하는 경우 범위를 표현할 수 있는 단위를 나타냅니다. Accept-Ranges: <range-unit>

  • Range: 서버가 반환해야 하는 문서의 부분을 나타냅니다.

  • If-Range: 주어진 etag 또는 날짜가 원격 리소스와 일치하는 경우에만 이행되는 조건부 범위 요청을 생성합니다. 리소스의 호환되지 않는 버전에서 두 범위를 다운로드하는 것을 방지하는 데 사용됩니다.

  • Content-Range: 전체 본문 메시지에서 부분 메시지가 속하는 위치를 나타냅니다.

Message body information

  • Content-Length: 리소스의 크기, 바이트의 10진수 수.

  • Content-Type: 리소스의 미디어 유형을 나타냅니다.

  • Content-Encoding: 압축 알고리즘을 지정하는 데 사용됩니다.

  • Content-Language: 청중을 위한 의도된 인간 언어를 설명하여 사용자가 자신의 선호하는 언어에 따라 구별할 수 있도록 합니다.

  • Content-Location: 반환된 데이터의 대체 위치를 나타냅니다.

From a pentest point of view this information is usually "useless", but if the resource is protected by a 401 or 403 and you can find some way to get this info, this could be interesting. For example a combination of Range and Etag in a HEAD request can leak the content of the page via HEAD requests:

  • A request with the header Range: bytes=20-20 and with a response containing ETag: W/"1-eoGvPlkaxxP4HqHv6T3PNhV9g3Y" is leaking that the SHA1 of the byte 20 is ETag: eoGvPlkaxxP4HqHv6T3PNhV9g3Y

Server Info

  • Server: Apache/2.4.1 (Unix)

  • X-Powered-By: PHP/5.3.3

Controls

  • Allow: 이 헤더는 리소스가 처리할 수 있는 HTTP 메서드를 전달하는 데 사용됩니다. 예를 들어, Allow: GET, POST, HEAD로 지정될 수 있으며, 이는 리소스가 이러한 메서드를 지원함을 나타냅니다.

  • Expect: 클라이언트가 요청이 성공적으로 처리되기 위해 서버가 충족해야 하는 기대를 전달하는 데 사용됩니다. 일반적인 사용 사례는 클라이언트가 대량의 데이터 페이로드를 전송할 의도가 있음을 나타내는 Expect: 100-continue 헤더입니다. 클라이언트는 전송을 진행하기 전에 100 (Continue) 응답을 찾습니다. 이 메커니즘은 서버 확인을 기다림으로써 네트워크 사용을 최적화하는 데 도움이 됩니다.

Downloads

  • The Content-Disposition header in HTTP responses directs whether a file should be displayed inline (within the webpage) or treated as an attachment (downloaded). For instance:

Content-Disposition: attachment; filename="filename.jpg"

이것은 "filename.jpg"라는 이름의 파일이 다운로드되고 저장되도록 의도되었음을 의미합니다.

보안 헤더

콘텐츠 보안 정책 (CSP)

Content Security Policy (CSP) Bypass

신뢰할 수 있는 유형

CSP를 통해 신뢰할 수 있는 유형을 강제함으로써, 애플리케이션은 DOM XSS 공격으로부터 보호될 수 있습니다. 신뢰할 수 있는 유형은 특정 보안 정책을 준수하는 특별히 제작된 객체만이 위험한 웹 API 호출에 사용될 수 있도록 보장하여, 기본적으로 JavaScript 코드를 안전하게 만듭니다.

// Feature detection
if (window.trustedTypes && trustedTypes.createPolicy) {
// Name and create a policy
const policy = trustedTypes.createPolicy('escapePolicy', {
createHTML: str => str.replace(/\</g, '&lt;').replace(/>/g, '&gt;');
});
}
// Assignment of raw strings is blocked, ensuring safety.
el.innerHTML = 'some string'; // Throws an exception.
const escaped = policy.createHTML('<img src=x onerror=alert(1)>');
el.innerHTML = escaped;  // Results in safe assignment.

X-Content-Type-Options

이 헤더는 MIME 타입 스니핑을 방지하며, 이는 XSS 취약점으로 이어질 수 있는 행위입니다. 이 헤더는 브라우저가 서버에서 지정한 MIME 타입을 준수하도록 보장합니다.

X-Content-Type-Options: nosniff

X-Frame-Options

클릭재킹을 방지하기 위해, 이 헤더는 문서가 <frame>, <iframe>, <embed>, 또는 <object> 태그에 어떻게 포함될 수 있는지를 제한하며, 모든 문서가 자신의 포함 권한을 명시적으로 지정할 것을 권장합니다.

X-Frame-Options: DENY

Cross-Origin Resource Policy (CORP) 및 Cross-Origin Resource Sharing (CORS)

CORP는 웹사이트가 어떤 리소스를 로드할 수 있는지를 지정하는 데 중요하며, 교차 사이트 누수를 완화합니다. 반면 CORS는 특정 조건 하에 동일 출처 정책을 완화하여 보다 유연한 교차 출처 리소스 공유 메커니즘을 허용합니다.

Cross-Origin-Resource-Policy: same-origin
Access-Control-Allow-Origin: https://example.com
Access-Control-Allow-Credentials: true

Cross-Origin Embedder Policy (COEP) 및 Cross-Origin Opener Policy (COOP)

COEP와 COOP는 교차 출처 격리를 가능하게 하는 데 필수적이며, Spectre와 유사한 공격의 위험을 크게 줄입니다. 이들은 각각 교차 출처 리소스의 로딩과 교차 출처 창과의 상호작용을 제어합니다.

Cross-Origin-Embedder-Policy: require-corp
Cross-Origin-Opener-Policy: same-origin-allow-popups

HTTP Strict Transport Security (HSTS)

마지막으로, HSTS는 브라우저가 서버와 오직 안전한 HTTPS 연결을 통해서만 통신하도록 강제하는 보안 기능으로, 개인 정보 보호와 보안을 강화합니다.

Strict-Transport-Security: max-age=3153600

References

Support HackTricks

Last updated