Login Panel

2025. 10. 31. 23:24·

Đề bài


Giải

Khi vào trang web nó sẽ bắt mình nhập username:passwd

Mình nhập bừa và bắt thử xem có những request nào

Thấy có request login sau

Mình sẽ phân tích source code của nó

  <script>
    async function toHex(buffer) {
      const bytes = new Uint8Array(buffer);
      let hex = '';
      for (let i = 0; i < bytes.length; i++) {
        hex += bytes[i].toString(16).padStart(2, '0');
      }
      return hex;
    }

    async function sha256Hex(str) {
      const enc = new TextEncoder();
      const data = enc.encode(str);
      const digest = await crypto.subtle.digest('SHA-256', data);
      return toHex(digest);
    }

    function timingSafeEqualHex(a, b) {
      if (a.length !== b.length) return false;
      let diff = 0;
      for (let i = 0; i < a.length; i++) {
        diff |= a.charCodeAt(i) ^ b.charCodeAt(i);
      }
      return diff === 0;
    }

    (async () => {
      const ajnsdjkamsf = 'ba773c013e5c07e8831bdb2f1cee06f349ea1da550ef4766f5e7f7ec842d836e'; // replace
      const lanfffiewnu = '48d2a5bbcf422ccd1b69e2a82fb90bafb52384953e77e304bef856084be052b6'; // replace

      const username = prompt('Enter username:');
      const password = prompt('Enter password:');

      if (username === null || password === null) {
        alert('Missing username or password');
        return;
      }

      const uHash = await sha256Hex(username);
      const pHash = await sha256Hex(password);

      if (timingSafeEqualHex(uHash, ajnsdjkamsf) && timingSafeEqualHex(pHash, lanfffiewnu)) {
        alert(username+ '{'+password+'}');
      } else {
        alert('Invalid credentials');
      }
    })();
  </script>

Nhận thấy nó nhận vào username:passwd của mình và sau đó băm với thuật toán SHA256

const uHash = await sha256Hex(username);
const pHash = await sha256Hex(password);

Tiếp tục là nó sẽ kiểm tra với hash gốc của nó

if (timingSafeEqualHex(uHash, ajnsdjkamsf) && timingSafeEqualHex(pHash, lanfffiewnu)) {
    alert(username+ '{'+password+'}');
} else {
    alert('Invalid credentials');
}

Nếu đúng username và password sẽ in ra flag, ở đây có thể biết luôn username là v1t rồi

Mình sử dụng hashcat để crack bài này

$ printf "48d2a5bbcf422ccd1b69e2a82fb90bafb52384953e77e304bef856084be052b6\n" > pass.sha256
hashcat -m 1400 -a 0 pass.sha256 /usr/share/wordlists/rockyou.txt -O

Lý do chỉ crack mật khẩu là vì biết trước username rồi


Flag

Flag: v1t{p4ssw0rd}

'WriteUp > Web' 카테고리의 다른 글

Tiny Flag  (0) 2025.11.01
Stylish Flag  (0) 2025.11.01
[Web] GameCloud - POC CTF 2025  (0) 2025.10.13
[Web] devtools-sources - Dreamhack  (0) 2025.10.11
[Web] cookie - Dreamhack  (0) 2025.10.11
'WriteUp/Web' Other posts in category
  • Tiny Flag
  • Stylish Flag
  • [Web] GameCloud - POC CTF 2025
  • [Web] devtools-sources - Dreamhack
longhd
longhd
Longhd's Blog
  • longhd
    Ha Duy Long - InfosecPTIT
    longhd
  • Total
    Today
    Yesterday
  • About me

    • Hello I'm Duy Long 👋🏻
    • View all categories (117) N
      • Certificates (4)
      • CTF (3)
      • WriteUp (94) N
        • Forensics (44) N
        • Steganography (5)
        • RE (9) N
        • OSINT (8)
        • Web (17)
        • MISC (6)
        • Crypto (3)
        • Pwn (2)
      • Love Story (0)
      • Labs (15)
        • Information Gathering (10)
        • Vulnerability Scanning (2)
        • Introduction to Web Applica.. (1)
        • Common Web Application Atta.. (1)
        • SQL Injection Attacks (1)
  • Blog Menu

    • Home
    • Tag
    • GuestBook
  • Popular Posts

  • Tags

    htb
    Steganography
    Dreamhack
    BuckeyeCTF2025
    OSINT
    CHH
    POCCTF2025
    misc
    CSCV2025
    PTITCTF2025
    Web
    THM
    EnigmaXplore3.0
    V1tCTF2025
    picoCTF
    writeup
    SunshineCTF2025
    Forensics
    Re
    CTF
  • Recent Comments

  • Recent Posts

  • hELLO· Designed ByLong.v4.10.4
longhd
Login Panel
Go to Top

티스토리툴바