Skip to content

Commit

Permalink
Add malware download test
Browse files Browse the repository at this point in the history
  • Loading branch information
not-a-rootkit committed Nov 12, 2024
1 parent c0d476c commit 57801cf
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
1 change: 1 addition & 0 deletions security/badware/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ <h1>Phishing Detection Test Pages</h1>
<ul>
<li><a href="./phishing.html">Standard Phishing Test</a></li>
<li><a href="./malware.html">Standard Malware Test</a></li>
<li><a href="./malware-download.html">Malware Download Test</a></li>
<li><a href="./phishing-iframe-loader.html">Phishing iFrame Loader</a></li>
<li><a href="./phishing-js-redirector-helper.html">Phishing JS Redirector (Direct)</a></li>
<li><a href="./phishing-js-redirector.html">Phishing JS Redirector (Indirect)</a></li>
Expand Down
31 changes: 31 additions & 0 deletions security/badware/malware-download.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<!DOCTYPE html>
<html>

<head>
<meta charset="utf-8">
<title>Malware download page</title>
<script>
// eslint-disable-next-line no-unused-vars
function run() {
const url = "/security/badware/phishing-redirect/download";
const link = document.createElement('a');
link.href = url;
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
}
</script>
</head>

<body>
<p><a href="/security/badware/">[Back]</a></p>

<h1>Malware download page</h1>

<p>This is an example malware page that DuckDuckGo clients intend to block. If you arrive here by mistake; there's
nothing to worry about, we just use this page to test if our client blocking is working.</p>

<button id="run" onclick="run()">Download</button>
</body>

</html>
17 changes: 17 additions & 0 deletions security/badware/server/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,21 @@ router.post('/form', (req, res) => {
res.send('Form submitted');
});

// Serves an arbitrary executable file to test download detection
router.get('/download', (req, res) => {
// Create a buffer with a minimal valid PE header

Check failure on line 66 in security/badware/server/routes.js

View workflow job for this annotation

GitHub Actions / build (16)

Expected indentation of 4 spaces but found 2
const fileData = Buffer.alloc(64);

Check failure on line 67 in security/badware/server/routes.js

View workflow job for this annotation

GitHub Actions / build (16)

Expected indentation of 4 spaces but found 2
// MZ header (magic bytes)

Check failure on line 68 in security/badware/server/routes.js

View workflow job for this annotation

GitHub Actions / build (16)

Expected indentation of 4 spaces but found 2
const magicBytes = [0x4d, 0x5a];

Check failure on line 69 in security/badware/server/routes.js

View workflow job for this annotation

GitHub Actions / build (16)

Expected indentation of 4 spaces but found 2
// DOS stub filled with zeros

Check failure on line 70 in security/badware/server/routes.js

View workflow job for this annotation

GitHub Actions / build (16)

Expected indentation of 4 spaces but found 2
const dosStub = new Uint8Array(58).fill(0);

Check failure on line 71 in security/badware/server/routes.js

View workflow job for this annotation

GitHub Actions / build (16)

Expected indentation of 4 spaces but found 2
fileData.set(magicBytes, 0);

Check failure on line 72 in security/badware/server/routes.js

View workflow job for this annotation

GitHub Actions / build (16)

Expected indentation of 4 spaces but found 2
fileData.set(dosStub, 2);

Check failure on line 73 in security/badware/server/routes.js

View workflow job for this annotation

GitHub Actions / build (16)

Expected indentation of 4 spaces but found 2

res.setHeader("Content-Type", "application/octet-stream");

Check failure on line 75 in security/badware/server/routes.js

View workflow job for this annotation

GitHub Actions / build (16)

Expected indentation of 4 spaces but found 2

Check failure on line 75 in security/badware/server/routes.js

View workflow job for this annotation

GitHub Actions / build (16)

Strings must use singlequote
res.setHeader("Content-Disposition", 'attachment; filename="test.exe"');
res.send(fileData);
});


module.exports = router;

0 comments on commit 57801cf

Please sign in to comment.