Dreamhack - [wargame.kr] login filtering

·2025년 8월 4일

Dreamhack-Writeups

목록 보기
33/52

[wargame.kr] login filtering

문제 링크

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

문제 설명

I have accounts. but, it's blocked.
can you login bypass filtering?

풀이과정

  1. get source에 접속해 소스코드를 확인해봅니다.
  2. 사용자 입력값을 필터링 하는 코드입니다.
    $id = mysqli_real_escape_string($conn, trim($_POST['id']));
    $ps = mysqli_real_escape_string($conn, trim($_POST['ps']));
    • trim: 입력값에 공백이 있다면, 제거합니다.
    • mysqli_real_escape_string: SQL 인젝션 방지용 이스케이핑입니다. (특수 문자 (예: ', ", \, NULL) 앞에 백슬래시(\)를 붙여 이스케이프 처리합니다.) 하지만, 논리적 취약점이나 다른 DB 설정에 따라 우회 가능성이 있는 함수입니다.
  3. 로그인 처리 코드입니다.
     if(isset($row['id'])){
        if($id=='guest' || $id=='blueh4g'){
            echo "your account is blocked";
        }else{
            echo "login ok"."<br />";
            echo "FLAG : ".$FLAG;
        }
     }else{
        echo "wrong..";
     }
    • id가 guestblueh4g 면 차단됩니다.
    • 그 외의 id로 로그인을 성공하면 플래그가 나옵니다.
    • 로그인에 실패하면 "wrong.." 을 출력합니다.
  4. 차단 id 관련 주석입니다.
     you have blocked accounts.
     
     guest / guest
     blueh4g / blueh4g1234ps
    차단 id의 비밀번호를 확인할 수 있습니다.
  5. MySQL 쿼리 안에 저장된 비밀번호를 확인하거나, 우회하기 위해서는 SQL 인젝션 공격을 먼저 떠올렸습니다. 하지만 mysqli_real_escape_string을 통해 거의 불가능 한 상태이고, 다른 접근이 필요함을 알 수 있었습니다.
  6. 현재 id 차단은 php에서 하고있습니다. 하지만 아이디와 비밀번호로 대조하여 로그인을 하는건 MySQL 입니다.
    두 언어의 차이점은, php는 대소문자 구별을 하지만, MySQL은 하지 않는 점입니다.
    그렇기에 id에 Guest(첫 글자만 대문자) 로 입력하면
    • PHP에서는 "Guest" != "guest" 이라 차단이 되지 않습니다. → 차단 우회 성공
    • 하지만 MySQL 쿼리에서는 대소문자 구분 없이 같다고 판단해서 로그인에 성공할 수 있습니다.
  1. 성공적으로 로그인 해 플래그를 획득할 수 있습니다.


배운점

  • mysqli_real_escape_string 이스케이핑에 대해 배웠습니다. 평범한 SQL 인젝션 공격을 막아줄 수 있기에 편리합니다. 하지만, 이 문제에서는 이용하지 않았지만, 다른 우회 방법도 존재하다고 하기에 조심해서 사용해야 함을 배웠습니다.
  • PHP와 MySQL 의 차이에 대해 배웠습니다. 특히, 언어에서 대소문자의 구별 유무는 보안상으로도 굉장히 중요함을 느꼈고, 취약점이 발생하지 않도록 주의해야함을 배웠습니다.
  • 사용자 인증을 DB결과에만 의존하면 취약점이 생길수도 있다는 것을 배웠습니다.

Summary (English)

  • The challenge involves bypassing account filtering during login.
  • User inputs are filtered using trim() (removing whitespace) and mysqli_real_escape_string() (escaping special characters) to prevent basic SQL injection.
  • The PHP code blocks logins for users with IDs "guest" and "blueh4g".
  • Authentication is performed via MySQL, while the filtering of blocked accounts is done in PHP.
  • PHP is case-sensitive, but MySQL is not case-sensitive by default when comparing strings.
  • By using Guest (capital "G") instead of guest, the PHP block does not trigger, but MySQL still treats it as matching the stored ID, allowing login.
  • This behavior is leveraged to bypass the restriction and retrieve the flag.
  • Key lesson: Security logic split between systems with different case sensitivity (PHP vs. MySQL) can lead to bypass vulnerabilities.
profile
CTF 풀이 및 실습 중심 학습을 기록합니다.

0개의 댓글