-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added error handling for file system errors, added match counter, add…
…ed text to show the end of the scanning
- Loading branch information
1 parent
6bc34fd
commit 1c513a9
Showing
1 changed file
with
77 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,17 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<meta charset="UTF-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>LOLDrivers-webclient</title> | ||
<script src="https://cdn.jsdelivr.net/npm/[email protected]/crypto-js.js"></script> | ||
<script src="assets/wasm_exec.js"></script> | ||
<script> | ||
const go = new Go(); | ||
WebAssembly.instantiateStreaming(fetch("assets/loldrivers-webclient.wasm"), go.importObject).then((result) => { | ||
WebAssembly.instantiateStreaming( | ||
fetch("assets/loldrivers-webclient.wasm"), | ||
go.importObject | ||
).then((result) => { | ||
go.run(result.instance); | ||
}); | ||
</script> | ||
|
@@ -17,12 +20,17 @@ | |
<h1>LOLDrivers-webclient</h1> | ||
<main> | ||
<p> | ||
Please press the button below and choose a folder to scan for known vulnerable and known malicious Windows drivers using <a href="https://loldrivers.io">loldrivers.io</a>. | ||
No data is being sent to any server. This scanning happens locally in your browser thanks to the <a href="https://developer.mozilla.org/en-US/docs/Web/API/File_System_API">File System API</a>. | ||
</p> | ||
<p> | ||
The default Windows driver directories are: | ||
Please press the button below and choose a folder to scan for | ||
known vulnerable and known malicious Windows drivers using | ||
<a href="https://loldrivers.io">loldrivers.io</a>. No data is | ||
being sent to any server. This scanning happens locally in your | ||
browser thanks to the | ||
<a | ||
href="https://developer.mozilla.org/en-US/docs/Web/API/File_System_API" | ||
>File System API</a | ||
>. | ||
</p> | ||
<p>The default Windows driver directories are:</p> | ||
<ul> | ||
<li>C:\Windows\System32\drivers</li> | ||
<li>C:\Windows\System32\DriverStore\FileRepository</li> | ||
|
@@ -31,64 +39,80 @@ <h1>LOLDrivers-webclient</h1> | |
<button id="select-folder-button" disabled>Loading...</button> | ||
<div id="results" style="display: none"> | ||
<h2>Results</h2> | ||
<p>Processed files: <span id=file-counter>0</span></p> | ||
<p>Matched:</p> | ||
<p>Processed files: <span id="file-counter">0</span></p> | ||
<p>Matches: <span id="match-counter">0</span></p> | ||
<ul id="match-list"></ul> | ||
</div> | ||
</main> | ||
<footer> | ||
<hr> | ||
<p>Made with ❤️ and Club-Mate by <a href="https://github.com/rtfmkiesel" target="_blank">@rtfmkiesel</a></p> | ||
<hr /> | ||
<p> | ||
Made with ❤️ and Club-Mate by | ||
<a href="https://github.com/rtfmkiesel" target="_blank" | ||
>@rtfmkiesel</a | ||
> | ||
</p> | ||
</footer> | ||
</body> | ||
<script> | ||
let fileCounter = 0; // To count how many file were processed | ||
let matchCounter = 0; // To count how many matches were found | ||
|
||
async function selectFolder() { | ||
const dirHandle = await window.showDirectoryPicker(); // File System API | ||
document.getElementById("results").style.display = "block"; | ||
await walkDirectory(dirHandle); | ||
await walkDirectory(dirHandle).then(() => { | ||
document.getElementById("file-counter").innerText = | ||
fileCounter + ", finished"; | ||
}); | ||
} | ||
|
||
// Walk the dir | ||
async function walkDirectory(dirHandle) { | ||
for await (const entry of dirHandle.values()) { | ||
if (entry.kind === 'file') { | ||
const file = await entry.getFile(); | ||
await lookupFile(file, entry.name); // Found a file, lookup file | ||
} else if (entry.kind === 'directory') { | ||
await walkDirectory(entry); // Found a directory, walk again | ||
} | ||
try { | ||
if (entry.kind === "file") { | ||
const file = await entry.getFile(); | ||
await lookupFile(file, entry.name); // Found a file, lookup file | ||
} else if (entry.kind === "directory") { | ||
await walkDirectory(entry); // Found a directory, walk again | ||
} | ||
} catch (error) { | ||
console.error(`Error processing ${entry.name}:`, error); | ||
// Optionally, display a message to the user or increment a counter for failed files | ||
} | ||
} | ||
} | ||
|
||
async function lookupFile(fileHandle, name) { | ||
const fileArrayBuffer = await fileHandle.arrayBuffer(); | ||
const fileContent = new Uint8Array(fileArrayBuffer); | ||
|
||
const md5Hash = CryptoJS.MD5(CryptoJS.lib.WordArray.create(fileContent)).toString(); | ||
const sha1Hash = CryptoJS.SHA1(CryptoJS.lib.WordArray.create(fileContent)).toString(); | ||
const sha256Hash = CryptoJS.SHA256(CryptoJS.lib.WordArray.create(fileContent)).toString(); | ||
|
||
|
||
const md5Hash = CryptoJS.MD5( | ||
CryptoJS.lib.WordArray.create(fileContent) | ||
).toString(); | ||
const sha1Hash = CryptoJS.SHA1( | ||
CryptoJS.lib.WordArray.create(fileContent) | ||
).toString(); | ||
const sha256Hash = CryptoJS.SHA256( | ||
CryptoJS.lib.WordArray.create(fileContent) | ||
).toString(); | ||
|
||
let response = await lookupHash(md5Hash); | ||
if (!response.ok) { | ||
// No MD5, try SHA1 | ||
response = await lookupHash(sha1Hash); | ||
if (!response.ok) { | ||
// No SHA1, try SHA256 | ||
response = await lookupHash(sha256Hash); | ||
} | ||
// No MD5, try SHA1 | ||
response = await lookupHash(sha1Hash); | ||
if (!response.ok) { | ||
// No SHA1, try SHA256 | ||
response = await lookupHash(sha256Hash); | ||
} | ||
} | ||
|
||
if (response.ok) { | ||
addFileToList(name, JSON.parse(response.driver)); | ||
} | ||
|
||
updateCounter(); | ||
} | ||
if (response.ok) { | ||
addFileToList(name, JSON.parse(response.driver)); | ||
} | ||
|
||
function updateCounter() { | ||
fileCounter++ | ||
fileCounter++; | ||
document.getElementById("file-counter").innerText = fileCounter; | ||
} | ||
|
||
|
@@ -97,15 +121,21 @@ <h2>Results</h2> | |
li.innerHTML = `${name} <a href="https://loldrivers.io/drivers/${driver.Id}" target="_blank">↗</a>`; | ||
li.className = "match-entry"; | ||
document.getElementById("match-list").appendChild(li); | ||
|
||
matchCounter++; | ||
document.getElementById("match-counter").innerText = matchCounter; | ||
} | ||
|
||
if ("showDirectoryPicker" in window) { | ||
document.getElementById("select-folder-button").addEventListener("click", selectFolder); | ||
document | ||
.getElementById("select-folder-button") | ||
.addEventListener("click", selectFolder); | ||
} else { | ||
document.querySelector("main").innerHTML = "<p>Your browser does not support the <a href='https://developer.mozilla.org/en-US/docs/Web/API/File_System_API'>File System API↗</a>. Please switch to a compatible browser like Chrome or Edge.</p>" | ||
document.querySelector("main").innerHTML = | ||
"<p>Your browser does not support the <a href='https://developer.mozilla.org/en-US/docs/Web/API/File_System_API'>File System API↗</a>. Please switch to a compatible browser like Chrome or Edge.</p>"; | ||
} | ||
</script> | ||
<style> | ||
</script> | ||
<style> | ||
body { | ||
max-width: 70ch; | ||
margin: 1rem auto; | ||
|
@@ -123,7 +153,7 @@ <h2>Results</h2> | |
|
||
a, | ||
a:active { | ||
color:aqua; | ||
color: aqua; | ||
} | ||
|
||
footer { | ||
|
@@ -145,5 +175,5 @@ <h2>Results</h2> | |
color: blue; | ||
} | ||
} | ||
</style> | ||
</html> | ||
</style> | ||
</html> |