Skip to content

Commit

Permalink
added error handling for file system errors, added match counter, add…
Browse files Browse the repository at this point in the history
…ed text to show the end of the scanning
  • Loading branch information
rtfmkiesel committed Sep 10, 2024
1 parent 6bc34fd commit 1c513a9
Showing 1 changed file with 77 additions and 47 deletions.
124 changes: 77 additions & 47 deletions index.html
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>
Expand All @@ -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>
Expand All @@ -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;
}

Expand All @@ -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;
Expand All @@ -123,7 +153,7 @@ <h2>Results</h2>

a,
a:active {
color:aqua;
color: aqua;
}

footer {
Expand All @@ -145,5 +175,5 @@ <h2>Results</h2>
color: blue;
}
}
</style>
</html>
</style>
</html>

0 comments on commit 1c513a9

Please sign in to comment.