Almon Dev

[Lord of SQL Injection] darkelf 풀이 본문

모의해킹/Lord of SQLi

[Lord of SQL Injection] darkelf 풀이

Almon 2025. 1. 6. 17:49

LOS 풀이

 

darkelf

 

 

풀이

1. 코드 분석

GET 메서드의 pw 파라미터가 쿼리에 삽입이 되고 쿼리 결과의 id가 admin인 경우 문제가 풀립니다.

$query = "select id from prob_darkelf where id='guest' and pw='{$_GET[pw]}'"; 
$result = @mysqli_fetch_array(mysqli_query($db,$query)); 
if($result['id'] == 'admin') solve("darkelf");

 

or과 and를 필터링합니다.

mysql에서는 or과 and를 대체할 ||나 &&를 이용하면 우회할 수 있습니다.

if(preg_match('/prob|_|\.|\(\)/i', $_GET[pw])) exit("No Hack ~_~"); 
if(preg_match('/or|and/i', $_GET[pw])) exit("HeHe");

 

2. 쿼리 삽입

or을 ||로 대체한 것 외에는 차이점이 없습니다.

select id from prob_darkelf where id='guest' and pw='' || id='admin'