r/ExploitDev • • Dec 17 '24

Secure context from http page

hey guys, I have the following snippet here where I can try to execute a javascript payload in a new window that regains secure context if the origin page was http:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Secure Script Execution</title>
    <script>
        window.onload = function () {
            // URL of a secure blank page (use your own HTTPS domain)
            const secureWindowUrl = 'https://your-https-domain.com/secure_blank.html';

            // Open the secure window
            const secureWindow = window.open(secureWindowUrl, '_blank', 'noopener,noreferrer');

            // JavaScript payload to execute
            const scriptPayload = `
                console.log('Running script in a secure context');
                alert('This script is running securely!');
            `;

            // Send the payload to the new window
            window.addEventListener('message', function(event) {
                if (event.data === 'ready') {
                    secureWindow.postMessage({ script: scriptPayload }, '*'); // Replace '*' with specific origin for security
                }
            });
        };
    </script>
</head>
<body>
    <h1>Secure Script Execution</h1>
    <p>Opening a secure window to execute JavaScript independently.</p>
</body>
</html>

I was wondering if there is a way to modify this payload, or use a different technique that would allow me to execute an https page in a secure context THAT ORIGINATED from an http page, without opening a new popup window

7 Upvotes

10 comments sorted by

View all comments

Show parent comment

1

u/TastyRobot21 Dec 17 '24 edited Dec 17 '24

I honestly don’t want to be rude but the w3 explains how this is being done today. I think my comment is sound. Your response is telling me you still haven’t read it. It takes 10 minutes, do the work.

Read ancestry section. Read the fact their aware of the gaps that exist. They explain how Netflix is bypassing it with postMessssge in an iframe. (Method 1) Then read this:

The secure context definition in this document does not completely isolate a “secure” view on an origin from a “non-secure” view on the same origin. Exfiltration will still be possible via increasingly esoteric mechanisms such as the contents of localStorage/sessionStorage, storage events, BroadcastChannel, and others.

Your on the same origin based on your question so you’ve got method 2,3,4 listed out.

If you need more the beef project is open source. They do this too.

So, yes someone has done this.