r/ExploitDev • u/ansolo00 • 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
View all comments
Show parent comment
1
u/TastyRobot21 Dec 17 '24 edited Dec 17 '24
I’m surprised you’ve gotten this far in school without being able to answer some of these questions with your own research. Maybe LLMs have had a bigger impact in education then I thought.
I’d suggest reading the Mozilla and W3 article on secure context. It answers your questions specifically regarding window, tabs and Iframe contexts as well as ancestry.
https://www.w3.org/TR/secure-contexts/#is-origin-trustworthy
If you truly need secure context (for example to get certain APIs) I would explore the interesting note regarding local host bypassing the need for https.
If you don’t need secure context specially, just use JavaScript to smuggle securely. Ie: encrypt client side, decrypt server side. It’s pretty common in attacks. You could also explore alternate streams like webrtc to achieve same goal.