LineCTF(2023) - Adult Simple GoCurl
# Adult Simple GoCurl
์ด์ ๋ฌธ์ ์ธ Baby Simple GoCurl์์ ์ ๊ทธ๋ ์ด๋๋ ๋ฌธ์ ์ด๋ค.
์์ค์ฝ๋์ ๋ณ๊ฒฝ๋ ๋ถ๋ถ๋ง ์ดํด๋ณด๋ฉด flag ๋ฌธ์์ด์ ๊ฒ์ฌํ๋ ๋ก์ง์ด || ์ผ๋ก ๋ฐ๋์๊ณ , ClientIP() ํจ์๋ฅผ ์ฒดํฌํ๋ ๋ก์ง์ด ์์ด์ก๋ค.
reqUrl := strings.ToLower(c.Query("url"))
reqHeaderKey := c.Query("header_key")
reqHeaderValue := c.Query("header_value")
reqIP := strings.Split(c.Request.RemoteAddr, ":")[0]
fmt.Println("[+] " + reqUrl + ", " + reqIP + ", " + reqHeaderKey + ", " + reqHeaderValue)
if strings.Contains(reqUrl, "flag") || strings.Contains(reqUrl, "curl") || strings.Contains(reqUrl, "%") {
c.JSON(http.StatusBadRequest, gin.H{"message": "Something wrong"})
return
}
๋๋ฌธ์ Baby Simple GoCurl์์ ์ฌ์ฉํ๋ ๋ฐฉ๋ฒ์ผ๋ก๋ ๋ ์ด์ flag๋ฅผ ํ์ธํ ์ ๊ฐ ์๋ค.
์์ค์์ redirectChecker ํจ์๊ฐ ์กด์ฌํ๋ค.
func redirectChecker(req *http.Request, via []*http.Request) error {
reqIp := strings.Split(via[len(via)-1].Host, ":")[0]
if len(via) >= 2 || reqIp != "127.0.0.1" {
return errors.New("Something wrong")
}
return nil
}
์์ฒญํ๋ IP๊ฐ 127.0.0.1๊ฐ ์๋๋ฉด ์๋๋๋ก ํํฐ๋ง์ด ๋๊ณ ์๋ค.
gin์ ์์ค์ฝ๋๋ฅผ ๋ณด๋ฉด redirect์ ๊ด๋ จ๋ ์๋ ์ฝ๋๊ฐ ์๋ค.
// RedirectTrailingSlash enables automatic redirection if the current route can't be matched but a
// handler for the path with (without) the trailing slash exists.
// For example if /foo/ is requested but a route only exists for /foo, the
// client is redirected to /foo with http status code 301 for GET requests
// and 307 for all other request methods.
func redirectTrailingSlash(c *Context) {
req := c.Request
p := req.URL.Path
if prefix := path.Clean(c.Request.Header.Get("X-Forwarded-Prefix")); prefix != "." {
prefix = regSafePrefix.ReplaceAllString(prefix, "")
prefix = regRemoveRepeatedChar.ReplaceAllString(prefix, "/")
p = prefix + "/" + req.URL.Path
}
req.URL.Path = p + "/"
if length := len(p); length > 1 && p[length-1] == '/' {
req.URL.Path = p[:length-1]
}
redirectRequest(c)
}
trailing slash๊ฐ ๋ถ์ด์๋ URL์ ๊ฒฝ์ฐ redirect ์์ผ์ฃผ๋๋ฐ X-Forwarded-Prefix ํค๋๊ฐ์์ผ๋ฉด ํด๋น ํค๋์ value๋ฅผ URL path์ ๋ถ์ฌ์ ๋ฆฌ๋ค์ด๋ ํธ ์์ผ์ค๋ค.
ํด๋น ๊ธฐ๋ฅ์ ํตํด url์ ์ง์ /flag ๋ฌธ์์ด์ ์ ๋ ฅํ์ง ์๊ณ ๋ ์์ฒญ์ ๋ณด๋ผ ์ ์๋ค.
redirectTrailingSlash() ํจ์๋ฅผ ํธ์ถํ๊ธฐ ์ํด์ url์ // ๊ฐ์ ๋ถ์ฌ์ X-Forwarded-Prefix ํค๋๋ฅผ ์ค์ ํ์ฌ ์์ฒญ์ ํ๋ค.
์๋ ์ฒ๋ผ ๊ฐ์ ์
๋ ฅํ์ฌ ์์ฒญํ๋ฉด flag ๊ฐ์ ์ป์ ์ ์๋ค.
'๐ก๏ธCTF > LineCTF' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
LineCTF(2023) - Baby Simple GoCurl (0) | 2023.08.13 |
---|---|
LineCTF 2022 - memo drive (0) | 2022.04.13 |
LineCTF 2022 - gotm (0) | 2022.03.29 |
๋๊ธ
์ด ๊ธ ๊ณต์ ํ๊ธฐ
-
๊ตฌ๋
ํ๊ธฐ
๊ตฌ๋ ํ๊ธฐ
-
์นด์นด์คํก
์นด์นด์คํก
-
๋ผ์ธ
๋ผ์ธ
-
ํธ์ํฐ
ํธ์ํฐ
-
Facebook
Facebook
-
์นด์นด์ค์คํ ๋ฆฌ
์นด์นด์ค์คํ ๋ฆฌ
-
๋ฐด๋
๋ฐด๋
-
๋ค์ด๋ฒ ๋ธ๋ก๊ทธ
๋ค์ด๋ฒ ๋ธ๋ก๊ทธ
-
Pocket
Pocket
-
Evernote
Evernote
๋ค๋ฅธ ๊ธ
-
LineCTF(2023) - Baby Simple GoCurl
LineCTF(2023) - Baby Simple GoCurl
2023.08.13 -
LineCTF 2022 - memo drive
LineCTF 2022 - memo drive
2022.04.13 -
LineCTF 2022 - gotm
LineCTF 2022 - gotm
2022.03.29