青少年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}

相关推荐
2401_8734794011 小时前
企业安全团队如何配合公安协查?IP查询在电子取证中的技术实践
tcp/ip·安全·网络安全·php
网安情报局13 小时前
如何选择合适的AI大模型:快快云安全AI大模型聚合平台全解析
人工智能·网络安全·ai大模型
忡黑梨15 小时前
eNSP_从直连到BGP全网互通
c语言·网络·数据结构·python·算法·网络安全
其实防守也摸鱼16 小时前
带你了解与配置phpmyadmin
笔记·安全·网络安全·pdf·编辑器·工具·调试
菩提小狗16 小时前
每日安全情报报告 · 2026-04-27
网络安全·漏洞·cve·安全情报·每日安全
Chengbei1118 小时前
面向红队的 AI 赋能全场景流量分析仪 网页 / APP / 终端 / IoT 全域 HTTPS 抓包解密利器
人工智能·物联网·网络协议·web安全·网络安全·https·系统安全
菩提小狗19 小时前
每日安全情报报告 · 2026-04-29
网络安全·漏洞·cve·安全情报·每日安全
FORCECON120 小时前
力控船舶智能运营,机舱监控IEWS/能效管理IEES/网络安全IACS,软硬件一体化解决方案
网络安全·scada·船舶·能效管理·机舱监控
漠月瑾-西安1 天前
软件忘了“擦黑板”:一次内核信息泄露事件(CVE-2024-49997)的深度剖析
网络安全·linux内核·内核安全·信息泄露·内存安全·cve漏洞分析
枷锁—sha2 天前
【CTFshow-pwn系列】03_栈溢出【pwn 073】详解:静态编译下的自动化 ROP 链构建
网络·汇编·笔记·安全·网络安全·自动化