2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

LINE CTF 2023 Writeup

Last updated at Posted at 2023-03-28

LINE CTF 2023 Writeup

LINEがCTFを開催すると聞いて興味本位で参加。
めちゃくちゃ難しくて1問しか解けなかったです。
ちなみに順位は160位/477位でした。

目次

  • Welcome(1pt)
  • baby-simple-gocurl(100pt)
  • 最後に

Welcome(1pt)

discordの#announcementで2023/03/25の8時59分に答えが張られました。

welcomeflag.png
LINECTF{e305dbd3a5893f92701ef9d125a9f77b}

baby-simple-gocurl(100pt)

まず、問題文から
「http://34.146.230.233:11000/flag」にflagがありそうなので
飛んでみるとこのようなメッセージが。

{"message":"You are a Guest, This is only for Host"}

Hostじゃないと見れないみたいです。main.goの中身を見てみましょう。

	r.GET("/flag/", func(c *gin.Context) {
		reqIP := strings.Split(c.Request.RemoteAddr, ":")[0]

		log.Println("[+] IP : " + reqIP)
		if reqIP == "127.0.0.1" {
			c.JSON(http.StatusOK, gin.H{
				"message": flag,
			})
			return
		}

		c.JSON(http.StatusBadRequest, gin.H{
			"message": "You are a Guest, This is only for Host",
		})
	})

つまり、クライアントIPが「127.0.0.1」であればflagが出るようです。

IPアドレスを偽装してアクセスする方法は思いつかなかったのでおとなしく
「http://34.146.230.233:11000/」に飛ぶとこんな感じのサイトが。

baby1.png

Welcomeの後に自分のグローバルIPアドレスが来ます。

試しにここで「http://34.146.230.233:11000」と入力してcurlすると

Welcome, <sapn id=\"client-ip\">34.146.230.233</sapn>\r\n <br/>\r\n

なぜかIPアドレスがURLのIPアドレスと全く同じなことがわかります。

ローカルホストの「127.0.0.1:8080」ならいけるのでは?と思い
「http://127.0.0.1:8080/」を入力してcurlすると(ここに至るまでかなり苦戦した)

Welcome, <sapn id=\"client-ip\">127.0.0.1</sapn>\r\n <br/>\r\n

いけそうです。じゃあ、「http://127.0.0.1:8080/flag/」で・・・

Something Wrong

だめでした。

main.goの中身に弾くコードがあるか見てみます。

        if c.ClientIP() != "127.0.0.1" && (strings.Contains(reqUrl, "flag") || strings.Contains(reqUrl, "curl") || strings.Contains(reqUrl, "%")) {
			c.JSON(http.StatusBadRequest, gin.H{"message": "Something wrong"})
			return
		}

ここだけ見ると問題はなさそうですが実は「c.clientIP()」はその前に書き換えられています。

	r.GET("/", func(c *gin.Context) {
		c.HTML(http.StatusOK, "index.html", gin.H{
			"a": c.ClientIP(),
		})
	})

Burp Suiteでリクエストの1行目を見ると実はこのようになっています。

GET /curl?url=http://127.0.0.1:8080/&header_key=&header_value= HTTP/1.1

ここで私はmain.goのコードも踏まえて以下のように推測しました。

curlを行って結果取得

→「/」で「c.clientIP()」を書き換え

→「/curl/」で(「?」は「/」と同じようにみている?)「c.clientIP()」が「127.0.0.1」と同じか判断

→ほかにもいろいろあるけど特に問題なければ結果表示

ここでもだいぶ苦戦。

どうやらHTTPヘッダに「X-Forwarded-For:127.0.0.1」を「Accept-Encoding」の前に入れると

「c.clientIP()」が優先的に「127.0.0.1」と判定するようです。

したがって以下の手順でflagを獲得しました。

1.「http://127.0.0.1:8080/flag/」と入力してcurlする

2.Brup Suiteで以下のように「X-Forwarded-For: 127.0.0.1」を入力して、送信する

baby2.png

3.flagゲット

babyflag.png

LINECTF{6a22ff56112a69f9ba1bfb4e20da5587}

推測なので間違っている可能性がありますが参考までに。

最後に

今まで初心者向けじゃない外部CTFの問題は1問も解けなかったので、今回のCTFで1問解けて良かったです。

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?