Skip to content

Commit

Permalink
files update
Browse files Browse the repository at this point in the history
  • Loading branch information
zzzteph committed Nov 12, 2024
1 parent 12adb6f commit 61756e3
Show file tree
Hide file tree
Showing 4 changed files with 126 additions and 46 deletions.
11 changes: 9 additions & 2 deletions tools/kraker-js/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions tools/kraker-js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"dependencies": {
"bulma": "^1.0.2",
"crack-js": "^1.0.5",
"hashcat-rules-js": "^1.0.8",
"mitt": "^3.0.1",
"vue": "^3.5.12"
},
Expand Down
19 changes: 4 additions & 15 deletions tools/kraker-js/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const hashesInput = ref('');
const hashEntries = computed(() => {
return hashesInput.value.split('\n').filter(entry => entry.trim() !== '');
return hashesInput.value.split('\n').map(entry => entry.trim()).filter(entry => entry !== '');
});
const foundEntries = ref([]);
Expand Down Expand Up @@ -116,7 +116,7 @@ const runCrackWorker = () => {
}
else if(attackTab.value=="files")
{
crackWorker.value.postMessage({ action: 'start', useRules: useRules.value, wordlistFile: wordlistFile.value, rulesFile: rulesFile.value});
crackWorker.value.postMessage({ action: 'start', useRules: useRules.value, wordlistFile: wordlistFile.value, hashEntries: hashEntries.value, rulesFile: rulesFile.value, selectedHashType:selectedHashType.value});
}
else
{
Expand Down Expand Up @@ -223,6 +223,7 @@ function handleWordlistSelect(event) {
function handleRulesSelect(event) {
rulesFile.value = event.target.files[0];
console.log(rulesFile.value.name );
rulesName.value = rulesFile.value ? rulesFile.value.name : '';
}
Expand Down Expand Up @@ -373,18 +374,6 @@ function handleRulesSelect(event) {
</div>
</div>
<div class="column is-12 ml-auto">
<div class="notification is-primary" id="notify">Done!</div>
</div>
<div class="column is-12 ml-auto">
<div class="field has-addons" id="div_progress">
<p class="control is-expanded">
<progress class="progress is-medium" id="progress" value="0" max="100"></progress>
</p>
</div>
</div>
</div>
Expand Down Expand Up @@ -433,7 +422,7 @@ function handleRulesSelect(event) {
<label class="file-label">
<input class="file-input" type="file" @change="handleRulesSelect" />
<span class="file-cta">
<span class="file-label" v-if="ruleName">{{ ruleName }}</span>
<span class="file-label" v-if="rulesName">{{ rulesName }}</span>
<span class="file-label" v-else> Choose a file… </span>
</span>
Expand Down
141 changes: 112 additions & 29 deletions tools/kraker-js/src/workers/files.js
Original file line number Diff line number Diff line change
@@ -1,49 +1,132 @@
import hashcat from 'crack-js';
import hashcatRule from 'hashcat-rules-js';
self.onmessage = async (event) => {
if (event.data.action === 'start') {
console.log("START");

const wordlistFile = event.data.wordlistFile;
const useRules = event.data.useRules;
const rulesFile = event.data.wordlistFile;
const rulesFile = event.data.rulesFile;
const selectedHashType=event.data.selectedHashType;
let hashEntries=event.data.hashEntries;

if(!hashcat.availableHashTypes.includes(selectedHashType))
{
postMessage({ type:"log", message: 'Undefined hashtype - ('+selectedHashType+')' });
postMessage({ type:"status", status: "done"});
self.close();
return;
}

if (!Array.isArray(hashEntries) || hashEntries.length == 0) {
postMessage({ type:"log", message: 'Hash entries is empty - ('+hashEntries+')' });
postMessage({ type:"status", status: "done"});
self.close();
return;
}










const chunkSize=64 * 1024;
let countLines=0;
postMessage({ type:"log", message: "wordlistFile:"+wordlistFile.name});
postMessage({ type:"log", message: "wordlistFile to use:"+wordlistFile.name});

let offset = 0;
let remainder = '';

let fileContent =false;
if(useRules) fileContent=await loadRules(rulesFile);

readChunk(wordlistFile,0,'');
console.log(countLines);
let reader = new FileReader();
while (offset < wordlistFile.size) {
let blob = wordlistFile.slice(offset, offset + chunkSize);

const readPromise = new Promise((resolve) => {
reader.onload = (event) => {
const text = remainder + event.target.result;
const lines = text.split('\n');
remainder = lines.pop();

lines.forEach((line) => {
console.log(line);
if(useRules)
{

for (const rule of fileContent) {
let modifiedLine=hashcatRule.applyRule(line.trim(),rule);
processHashes(hashEntries,modifiedLine,selectedHashType)
}
}
else
{
processHashes(hashEntries,line.trim(),selectedHashType)
}

});

resolve();
};
});


reader.readAsText(blob);
await readPromise;
offset += chunkSize;
}
if (remainder) {
console.log(remainder);
}

console.log(countLines);


postMessage({ type:"status", status: "done"});

}
};

function readChunk(wordlistFile,offset, remainder) {
const chunkSize=64 * 1024;
console.log(wordlistFile.size);
console.log(wordlistFile.name);
if (offset >= wordlistFile.size) {
self.close();
return;
}

const blob = wordlistFile.slice(offset, offset + chunkSize);
const reader = new FileReader();

reader.onload = (event) => {
const text = remainder + event.target.result;
const lines = text.split('\n');
remainder = lines.pop();

lines.forEach((line) => {
function loadRules(file) {
return new Promise((resolve, reject) => {
const reader = new FileReader();

reader.onload = (event) => {
const content = event.target.result;
const lines = content.split('\n').map(line => line.trim()).filter(line => line !== '');//trim and skip empty lines
const uniqueLines = Array.from(new Set(lines));
resolve(uniqueLines); // return only uniq rules
};

reader.onerror = (error) => {
reject(error);
};

reader.readAsText(file);
});
}
function processHashes(hashEntries, line, selectedHashType) {
for (let i = 0; i < hashEntries.length; i++) {
const hash = hashEntries[i];
console.log(hash);
console.log(line);
console.log(selectedHashType);
console.log(hashcat.verifyHash(line, hash, selectedHashType));
if (hashcat.verifyHash(line, hash, selectedHashType) === true) {
postMessage({
type: "found",
hash: hash,
password: line,
type: selectedHashType
});
console.log(line);
});

offset += chunkSize;
readChunk(wordlistFile,offset, remainder);
};

reader.readAsText(blob);
hashEntries.splice(i, 1);
i--;
}
}
}

0 comments on commit 61756e3

Please sign in to comment.