Exploit database

GH-662ed41a43a58ae76a6048c17dea9a64

mehdiboukhobza/sandbox_cve-2021-23358

GitHubNot listedPoC
Download repository ZIP

Sources for CVE-2021-23358

4 sources

Preferred order: Exploit-DB, Metasploit, then GitHub repositories by stars. Open preferred source

Repository files12
mehdiboukhobza/sandbox_cve-2021-23358Revision edd06ded5f4f

Files from this repository share one source choice. Supporting files may cover other vulnerabilities.

app.js

JavaScript · 6,573 bytes
const express = require('express');
const bodyParser = require('body-parser');
const mongoose = require('mongoose');
const _ = require('underscore');

const app = express();
const port = 3000;

// Connect to MongoDB
mongoose.connect('mongodb://localhost:27017/formDataDB', {
    // Options are no longer needed for Mongoose v6 and above
});

const formDataSchema = new mongoose.Schema({
    input1: String,
    input2: String
});

const FormData = mongoose.model('FormData', formDataSchema);

app.use(bodyParser.urlencoded({ extended: false }));

// Function to escape potentially harmful characters
const escapeInput = (input) => {
    return input.replace(/['"`\\]/g, '\\$&');
};

app.get('/', (req, res) => {
    const formHTML = `
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Simple Form</title>
        <style>
            body {
                font-family: Arial, sans-serif;
                background-color: #f4f6f8;
                color: #333;
                display: flex;
                justify-content: center;
                align-items: center;
                height: 100vh;
                margin: 0;
            }
            .container {
                background: white;
                padding: 20px;
                border-radius: 10px;
                box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
            }
            form {
                display: flex;
                flex-direction: column;
            }
            label {
                margin: 10px 0 5px;
            }
            input {
                padding: 10px;
                margin-bottom: 10px;
                border: 1px solid #ccc;
                border-radius: 5px;
            }
            button {
                padding: 10px;
                background-color: #d4af37;
                border: none;
                border-radius: 5px;
                cursor: pointer;
            }
            button:hover {
                background-color: #b8860b;
            }
        </style>
    </head>
    <body>
        <div class="container">
            <h1>Simple Form</h1>
            <form action="/process" method="post">
                <label for="input1">Input 1 (vulnerable):</label>
                <input type="text" id="Idinput1" name="input1" required>
                <label for="input2">Input 2 (sanitized):</label>
                <input type="text" id="Idinput2" name="input2" required>
                <button type="submit">Submit</button>
            </form>
        </div>
    </body>
    </html>
    `;
    res.send(formHTML);
});

app.post('/process', (req, res) => {
    const input1 = req.body.input1;
    let input2 = req.body.input2;

    // Vulnerable code injection for input1
    _.templateSettings.variable = input1;

    try {
        const templateFunction1 = _.template("")();
    } catch (error) {
        console.error('Error processing template:', error);
    }

    // Escape input2 to prevent code execution
    const escapedInput2 = escapeInput(input2);
    _.templateSettings.variable = escapedInput2;

    try {
        const templateFunction2 = _.template("")();
    } catch (error) {
        console.error('Error processing template:', error);
    }

    // Save the data to the database
    const formData = new FormData({
        input1: input1,
        input2: input2
    });

    formData.save()
        .then(() => {
            console.log('Data saved successfully!');
            const resultHTML = `
            <!DOCTYPE html>
            <html lang="en">
            <head>
                <meta charset="UTF-8">
                <meta name="viewport" content="width=device-width, initial-scale=1.0">
                <title>Simple Form</title>
                <style>
                    body {
                        font-family: Arial, sans-serif;
                        background-color: #f4f6f8;
                        color: #333;
                        display: flex;
                        justify-content: center;
                        align-items: center;
                        height: 100vh;
                        margin: 0;
                    }
                    .container {
                        background: white;
                        padding: 20px;
                        border-radius: 10px;
                        box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
                        text-align: center;
                    }
                    form {
                        display: flex;
                        flex-direction: column;
                    }
                    label {
                        margin: 10px 0 5px;
                    }
                    input {
                        padding: 10px;
                        margin-bottom: 10px;
                        border: 1px solid #ccc;
                        border-radius: 5px;
                    }
                    button {
                        padding: 10px;
                        background-color: #d4af37;
                        border: none;
                        border-radius: 5px;
                        cursor: pointer;
                    }
                    button:hover {
                        background-color: #b8860b;
                    }
                    p {
                        margin-top: 20px;
                        font-size: 1.2em;
                        font-weight: bold;
                    }
                </style>
            </head>
            <body>
                <div class="container">
                    <h1>Simple Form</h1>
                    <form action="/process" method="post">
                        <label for="input1">Input 1 (vulnerable):</label>
                        <input type="text" id="Idinput1" name="input1" required>
                        <label for="input2">Input 2 (sanitized):</label>
                        <input type="text" id="Idinput2" name="input2" required>
                        <button type="submit">Submit</button>
                    </form>
                    <p>Result: ${input1} ${input2}</p>
                </div>
            </body>
            </html>
            `;
            res.send(resultHTML);
        })
        .catch(err => {
            console.error('Error saving data:', err);
            res.status(500).send('Error saving data.');
        });
});

app.listen(port, () => {
    console.log(`App running at http://localhost:${port}`);
});