สวัสดีครับ! เริ่มต้นมาจากผมนั่งเล่นโซเชียล แล้วบังเอิญไปเจอประกาศใน LinkedIn เกี่ยวกับงาน STH Mini Web CTF 2025 ของ สยามถนัดแฮก น่าสนใจมากเลยต้องขอลองดูรายละเอียดสักหน่อย!

เว็บโจทย์การแข่งขัน:

https://web1.ctf.p7z.pw

เป้าหมายการเจาะระบบ:

โดย Flag จะมีรูปแบบ เช่น STH1{cff940beed74db5e1c7c63007223a6e6}

image.png

เริ่มต้น สิ่งแรกที่เจอคือ หน้าล็อกอิน

image.png

ถ้าเราลองสังเกตดี ๆ จะพบว่า Hard Code Credentials อยู่ในโค้ด! โดยการกด Ctrl + U เพื่อดู Page Source ก็จะเจอกับ test:test เลยครับ

image.png

หลังจากที่เราเข้าสู่ระบบเรียบร้อยแล้ว ระบบจะทำการ Redirect มายังหน้า Userinfo ซึ่งจะแสดงข้อมูลทั่วไปของผู้ใช้ที่เราเข้าสู่ระบบไว้

image.png

เช่นเคยครับ เราสามารถ กด View Page Source เพื่อดูรายละเอียดเพิ่มเติมได้ พอเข้าไปแล้วจะเจอกับไฟล์ script.js ซึ่งมีสคริปต์ที่น่าสนใจอยู่ ตัวสคริปต์นี้จะมี admin.php และ api.php เพื่อดึงข้อมูลต่าง ๆ ของผู้ใช้

document.addEventListener('DOMContentLoaded', () => {
  // Fetch the current user's information from the API
  fetch('api.php?action=get_userinfo')
    .then(response => response.json())
    .then(data => {
      if (data.username) {
        // Populate the page with user info
        document.getElementById('username').textContent = data.username;
        document.getElementById('role').textContent = data.role;
        document.getElementById('status').textContent = data.status;
      } else if (data.error) {
        console.error('API Error:', data.error);
      } else {
        console.error('Unexpected response format.');
      }
    })
    .catch(err => {
      console.error('Error fetching user info:', err);
    });
});

function debugFetchUserTest() {
  fetch('api.php?action=get_userinfo&user=test')
    .then(response => response.json())
    .then(data => {
      console.log('Debug get_userinfo for user=test:', data);
    })
    .catch(err => {
      console.error('Error in debugFetchUserTest:', err);
    });
}

function debugFetchAllUsers() {
  // admin.php
  fetch('api.php?action=get_alluser')
    .then(response => response.json())
    .then(data => {
      console.log('Debug get_alluser result:', data);
    })
    .catch(err => {
      console.error('Error in debugFetchAllUsers:', err);
    });
}

เมื่อเราเข้าไปดูที่ get_alluser จะเห็นว่าเราสามารถ ลิสต์ข้อมูลผู้ใช้ทั้งหมด ในระบบได้ ซึ่งในการนี้ ทำให้เราพบว่า admin-uat คือเป้าหมายของเรา

image.png