Skip to content

Added hashcat and speedtest workflow #90

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions examples/Hashcat/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Hashcat dictionary:
npm install
hflow run .

Workflow diagram:
![img.png](hashcat.png)
28 changes: 28 additions & 0 deletions examples/Hashcat/filter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
const fs = require('fs');

function filterHashes() {
const hashes = fs.readFileSync("hashes.txt", 'utf8').trim().split('\n');

const groupedHashes = {
md5: [],
sha1: [],
sha256: [],
sha512: [],
'sha3-256': []
};

hashes.forEach(line => {
const [hash, algorithm] = line.split(' ');
if (groupedHashes[algorithm]) {
groupedHashes[algorithm].push(hash);
}
});

// Write hashes to separate files by algorithm
Object.keys(groupedHashes).forEach(algorithm => {
const filename = `${algorithm}_hashes.txt`;
fs.writeFileSync(filename, groupedHashes[algorithm].join('\n'), 'utf8');
});
}

filterHashes()
83 changes: 83 additions & 0 deletions examples/Hashcat/functions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
var spawn = require('child_process').spawn;
var log4js = require('log4js');
var createJobMessage = require('../../common/jobMessage.js').createJobMessage;


// Spawns a job "node handler.js" and waits for the notification of its
// completion using the Redis job status notification mechanism
async function submitRemoteJob(ins, outs, context, cb) {
let fname='wftrace-' + context.hfId + '-' + context.appId + '.log';
log4js.configure({
appenders: { hftrace: { type: 'file', filename: fname } },
categories: { default: { appenders: ['hftrace'], level: 'error' } }
});

var logger = log4js.getLogger();

logger.level = 'debug';
console.log("Spawning process...");

//console.log(ins.map(i => i));

var input_dir = context.executor.input_dir,
work_dir = context.executor.work_dir,
output_dir = context.executor.output_dir;

let jobMessage = JSON.stringify(createJobMessage(ins, outs, context));

var cmd;

// if 'container' is present, run through Docker, mounting all directories if necessary
if (context.container) {
cmd = 'docker run ';
if (input_dir) cmd += ' -v ' + input_dir + ':/input_dir ';
if (work_dir) cmd += ' -v ' + work_dir + ':/work_dir ';
if (output_dir) cmd += ' -v ' + output_dir + ':/output_dir ';
cmd += container + ' node';
} else cmd = 'node'

try {
if (work_dir) { process.chdir(work_dir); }
} catch (error) {
throw error;
}

// "submit" job (start the handler process)
var proc = spawn(cmd, ['../../../hyperflow-job-executor/jobexec.js', context.taskId, context.redis_url], {shell: true});

proc.stderr.on('data', function(data) {
logger.debug(data.toString());
console.log(data.toString());
});

proc.stdout.on('data', function(data) {
logger.debug(data.toString());
console.log(data.toString());
});

proc.on('exit', function(code) {
logger.debug('Process exited with code', code);
});

// send message to the job (command to be executed)
try {
await context.sendMsgToJob(jobMessage, context.taskId);
logger.info('[' + context.taskId + '] job message sent');
} catch(err) {
console.error(err);
throw err;
}

// wait for the job to finish (timeout=0 means indefinite)
try {
var jobResult = await context.jobResult(0, context.taskId);
logger.info('[' + context.taskId + '] job result received:', jobResult);
console.log('Received job result:', jobResult);
cb(null, outs);
} catch(err) {
console.error(err);
throw err;
}
}

exports.submitRemoteJob = submitRemoteJob;
35 changes: 35 additions & 0 deletions examples/Hashcat/generate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
const fs = require('fs');
const crypto = require('crypto');

function randomString(maxLength) {
const chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
let result = '';
for (let i = 0; i < maxLength; i++) {
result += chars[Math.floor(Math.random() * chars.length)];
}
return result;
}

function generateHashes() {
const algorithms = ['md5', 'sha1', 'sha256', 'sha512', 'sha3-256'];
const proportions = [35, 25, 15, 15, 10]; // Percentages for each algorithm

const totalHashes = 100;
const hashCounts = proportions.map(p => Math.floor((p / 100) * totalHashes));

const hashes = [];

for (let i = 0; i < algorithms.length; i++) {
for (let j = 0; j < hashCounts[i]; j++) {
const randomStr = randomString(5);
const hash = crypto.createHash(algorithms[i]).update(randomStr).digest('hex');
hashes.push({ hash, algorithm: algorithms[i] });
}
}

// Write all hashes to a single file
const allHashes = hashes.map(h => `${h.hash} ${h.algorithm}`).join('\n');
fs.writeFileSync('hashes.txt', allHashes, 'utf8');
}

generateHashes()
76 changes: 76 additions & 0 deletions examples/Hashcat/handler.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
// Executor of 'jobs' using the Redis task status notification mechanism
const redis = require('redis');
const { spawn } = require('child_process');

if (process.argv.length < 4) {
console.error("Usage: node handler.js <taskId> <redis_url>");
process.exit(1);
}

// 'taskId' is the name of the Redis list to use for the notification
var taskId = process.argv[2],
redis_url = process.argv[3];

//console.log("taskId", taskId);
//console.log("redis_url", redis_url);

var rcl = redis.createClient(redis_url);

// get job message from Redis
var getJobMessage = async function (timeout) {
return new Promise(function (resolve, reject) {
const jobMsgKey = taskId + "_msg";
rcl.brpop(jobMsgKey, timeout, function (err, reply) {
err ? reject(err): resolve(reply)
});
});
}

// send notification about job completion to Redis
var notifyJobCompletion = async function () {
return new Promise(function (resolve, reject) {
rcl.rpush(taskId, "OK", function (err, reply) {
err ? reject(err): resolve(reply)
});
});
}


async function executeJob() {

// 1. get job message
try {
var jobMessage = await getJobMessage(10);
} catch (err) {
console.error(err);
throw err;
}
//console.log("Received job message:", jobMessage);

// 2. Execute job
var jm = JSON.parse(jobMessage[1]);

const cmd = spawn(jm["executable"], jm["args"]);

cmd.stdout.on('data', (data) => {
console.log(`stdout: ${data}`);
});

cmd.stderr.on('data', (data) => {
console.error(`stderr: ${data}`);
});

cmd.on('close', async(code) => {
console.log(`child process exited with code ${code}`);
// 3. Notify job completion
try {
await notifyJobCompletion();
} catch (err) {
console.error("Redis notification failed", err);
throw err;
}
process.exit(0);
});
}

executeJob()
44 changes: 44 additions & 0 deletions examples/Hashcat/hashcat.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
const { exec } = require('child_process');

function runHashcat(algorithm) {
const hashesFile = algorithm + '_hashes.txt'; // Hashes file // Algorithm name (e.g., 'md5', 'sha1')
const crackedFile = 'cracked.txt'; // Output file for cracked hashes

// Map algorithms to Hashcat mode IDs
const algorithmModeMap = {
md5: 0,
sha1: 100,
sha256: 1400,
sha512: 1700,
'sha3-256': 17400
};

const hashcatMode = algorithmModeMap[algorithm];
if (hashcatMode === undefined) {
const error = new Error(`Unsupported algorithm: ${algorithm}`);
console.error(error.message);
return;
}

const mask = '?a?a?a?a?a';
console.log(`Running Hashcat for ${algorithm}...`);

// Construct the Hashcat command
const command = `hashcat --potfile-disable -m ${hashcatMode} -a 3 -o ${crackedFile} ${hashesFile} ${mask}`;

// Execute the Hashcat command
exec(command, (error, stdout, stderr) => {
if (error) {
console.error(`Hashcat Error: ${error.message}`);
return;
}
if (stderr) {
console.error(`Hashcat Stderr: ${stderr}`);
}

console.log(`Hashcat Output:\n${stdout}`);
});
}

const args = process.argv.slice(2);
runHashcat(args[0]);
Binary file added examples/Hashcat/hashcat.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading