개발 블로그

[DreamHeck] Hello, go! 본문

Study/Web Hacking

[DreamHeck] Hello, go!

얀 짱 2026. 9. 17. 20:17

https://dreamhack.io/wargame/challenges/1999

 

로그인 | Dreamhack

 

dreamhack.io

 

[go 언어랑 친해지기]

코드를 분석해보니, name 이라는 쿼리 스트링이 있었음. ian을 넣고 확인해봄.

 

사용자가 입력한 name을 모두 소문자로 바꾸고 flag라는 단어가 포함되어 있는지 검사하고 flag가 있다면 에러.

 

package main

import (
	"html/template"
	"net/http"
	"bytes"
	"fmt"
	"strings"
	"github.com/labstack/echo/v4"
)


func greetHandler(c echo.Context) error {
	// 쿼리 스트링으로 name 받아옴 
	name := c.QueryParam("name")

	if name == "" {		// name 부분에 아무것도 없으면 default로 go 
		name = "go"
	}

	// 사용자가 입력한 name을 모두 소문자로 바꾸고 flag라는 단어가 포함되어 있는지 검사
	if strings.Contains(strings.ToLower(name),"flag"){
		return c.String(http.StatusBadRequest, "flag is not allowed.")
	}

	// 취약한 부분이라고 하면 이 부분 코드일듯....?
	t, err := template.New("page").Parse(
		fmt.Sprintf(`
			<html>
			<body>
				<h1>Hello, %s!</h1>
			</body>
			</html>`, name))
	if err != nil {
		return c.String(http.StatusInternalServerError, "Template parse error: "+err.Error())
	}

	buf := new(bytes.Buffer)
	err = t.Execute(buf, c) 
	if err != nil {
		return c.String(http.StatusInternalServerError, "Template execution error: "+err.Error())
	}

	return c.HTMLBlob(http.StatusOK, buf.Bytes())
}

func main() {
	e := echo.New()
	e.GET("/", greetHandler)
	e.Start(":8000")
}

 

아무리 코드를 톺아봐도 26번째 줄에서 밖에 취약한 부분이 나오지 않을 것 같아 go +html 을 구글링하였음.

다음과 같은 템플릿 문법을 확인하였다.

 

https://www.gyuray.dev/golang-template-package

 

[Golang] template 패키지 이해하기 (+HTML layout composition)

Last update: ‣

www.gyuray.dev

 

https://blog.jae-sung.com/134689

 

 

음.. 뭐 이런 식으로 쓰는듯? {{.}}

 

 

name 파라미터 값으로 일단 {{.}}를 넣어봤는데 다음과 같이 확인됨. {{}} 이런거.. 약간 SSTI랑 비슷한 것 같아보였음.

 

번외. 전에 분명 스터디에서 ssti 문제를 풀었던 거 같은데... 내 기억 속에 {{7*7}} 는 49 이거만 남아있음.. 병규형한테 물어보기...... 라업 조금 뒤적거려봤는데 모르겠음.

 

https://velog.io/@silver35/Web-Server-Side-Template-InjectionSSTI

 

[Web] Server-Side Template Injection(SSTI)

SSTI(Server Side Template Injection) 취약점은 웹 어플리케이션에 적용되어 있는 웹 템플릿 엔진(Web Template Engine)에 악의적인 사용자의 입력을 통해 임의의 템플릿 기능을 실행하는 공격이다. 템플릿 기

velog.io

 

 

/flag에서 찾으면 될듯

 

flag를 16진수로 하면 666c6167

 

https://payatu.com/blog/ssti-in-golang/

 

Exploring ways to exploit SSTI in Golang Frameworks

How server-side template injection (SSTI) works in Golang applications - how to detect and exploit it in Go templates, with examples and fixes.

payatu.com

 

 

오! 탈취 성공! 

넣어볼 페이로드는

{{.File "/\u0066\u006C\u0061\u0067"}}

 

유니코드를 사용하여 flag 필터링 우회

'Study > Web Hacking' 카테고리의 다른 글

[DreamHack] web-deserialize-python  (0) 2026.09.18
[DreamHeck] 슉슉 버거 🌱  (0) 2026.09.18
[DreamHeck] YAML Deserialization  (0) 2026.09.17
[DreamHeck] Grand Theft Auto  (0) 2026.09.17
[DreamHeck] 콩 심기🌱  (0) 2026.09.16