青少年CTF练习平台 贪吃蛇

题目

Ctrl+U快捷键查看页面源代码

源码

html 复制代码
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>贪吃蛇游戏</title>
    <style>
        #gameCanvas {
            border: 1px solid black;
        }
    </style>
</head>
<body>
    <h1>贪吃蛇游戏</h1>
    <canvas id="gameCanvas" width="400" height="400"></canvas>
    <p>分数: <span id="score">0</span></p>
    <script>
        const canvas = document.getElementById('gameCanvas');
        const context = canvas.getContext('2d');
        const gridSize = 20;
        let snake = [{ x: 200, y: 200 }];
        let direction = { x: gridSize, y: 0 };
        let score = 0;
        let food = { x: Math.floor(Math.random() * 20) * gridSize, y: Math.floor(Math.random() * 20) * gridSize };

        document.addEventListener('keydown', changeDirection);
        setInterval(update, 100);

        function update() {
            const head = { x: snake[0].x + direction.x, y: snake[0].y + direction.y };

            snake.unshift(head);
            if (head.x === food.x && head.y === food.y) {
                score += 1; // 假设每次吃到食物加 1 分
                placeFood();
            } else {
                snake.pop();
            }

            if (head.x < 0 || head.x >= canvas.width || head.y < 0 || head.y >= canvas.height || collision(head, snake)) {
                alert('游戏结束');
                document.location.reload();
            }

            context.clearRect(0, 0, canvas.width, canvas.height);
            drawSnake();
            drawFood();
            document.getElementById('score').innerText = score;

            // 每秒向后端发送一次分数
            if (score >= 10000) {
                fetch(`check_score.php?score=${score}`)
                    .then(response => response.text())
                    .then(data => {
                        if (data === 'FLAG') {
                            alert('恭喜你,获得FLAG!');
                        }
                    });
            }
        }

        function changeDirection(event) {
            switch (event.keyCode) {
                case 37:
                    if (direction.x === 0) direction = { x: -gridSize, y: 0 };
                    break;
                case 38:
                    if (direction.y === 0) direction = { x: 0, y: -gridSize };
                    break;
                case 39:
                    if (direction.x === 0) direction = { x: gridSize, y: 0 };
                    break;
                case 40:
                    if (direction.y === 0) direction = { x: 0, y: gridSize };
                    break;
            }
        }

        function drawSnake() {
            context.fillStyle = 'green';
            snake.forEach(segment => {
                context.fillRect(segment.x, segment.y, gridSize, gridSize);
            });
        }

        function drawFood() {
            context.fillStyle = 'red';
            context.fillRect(food.x, food.y, gridSize, gridSize);
        }

        function placeFood() {
            food = {
                x: Math.floor(Math.random() * 20) * gridSize,
                y: Math.floor(Math.random() * 20) * gridSize,
            };
        }

        function collision(head, snake) {
            for (let i = 1; i < snake.length; i++) {
                if (head.x === snake[i].x && head.y === snake[i].y) {
                    return true;
                }
            }
            return false;
        }
    </script>
</body>
</html>

代码分析

check_score.php接口传参score当score >= 10000获取flag

payload

html 复制代码
/check_score.php?score=10000

成功获取flag

flag{10b89efdaa7a41bcaba698afdd96a5af}

相关推荐
Eason_LYC39 分钟前
【GetShell】DataEase H2 JDBC远程命令执行漏洞(CVE-2025-32966+CVE-2025-49001)
网络安全·漏洞复现·dataease·白帽子·cve-2025-32966·cve-2025-49001·远程命令执行
白猫不黑44 分钟前
运维如何转安全(个人经验篇)
运维·学习·安全·web安全·网络安全·信息安全
Demons_kirit2 小时前
PortSwigger网络缓存欺骗(4)
网络安全·缓存
白猫不黑3 小时前
网络空间安全/信息安全专业学习规划(超级详细版)
运维·学习·安全·web安全·网络安全·信息安全
2601_966377134 小时前
2026年教育数据安全研修班举办,数达安全发布密评工具箱与行业商用密码安全解决方案
网络安全·数据安全·2026年教育数据安全研修班
Sagittarius_A*4 小时前
【好靶场】报错注入-sql注入-字符型
数据库·sql·web安全·网络安全·sql注入
todoitbo4 小时前
PDF 合并、转换也能自己部署:极空间运行 Stirling PDF,文件交给自己的服务器处理
网络安全·pdf·文件·nas·极空间
小杨不想秃头17 小时前
信息安全工程师考试
学习·网络安全
Seraphina3617 小时前
记一次实验:利用路径分隔符进行网页缓存欺骗
经验分享·笔记·安全·网络安全·缓存
菩提小狗20 小时前
每日安全情报报告 · 2026-08-25
网络安全·漏洞·cve·安全情报·每日安全