diff --git a/hashkitty-server/src/lib/API/RouteHandler.ts b/hashkitty-server/src/lib/API/RouteHandler.ts index 14306c3..b535a4b 100644 --- a/hashkitty-server/src/lib/API/RouteHandler.ts +++ b/hashkitty-server/src/lib/API/RouteHandler.ts @@ -316,7 +316,7 @@ export class RouteHandler { ): void => { try { const listString = FsUtils.listFileInDir(Constants.rulesPath); - const list = this.buildListBase(listString); + const list = this.buildListBase(['* (All Rules)', ...listString]); this.getFileInDirResp(res, list); } catch (e) { this.getFileInDirResp(res, [], Constants.rulesPath, e); diff --git a/hashkitty-server/src/lib/API/Sanitizer.ts b/hashkitty-server/src/lib/API/Sanitizer.ts index d4f5c6b..3924987 100644 --- a/hashkitty-server/src/lib/API/Sanitizer.ts +++ b/hashkitty-server/src/lib/API/Sanitizer.ts @@ -376,13 +376,18 @@ export class Sanitizer { for (const ruleFileName of rules) { try { if (ruleFileName.length > 0) { - const files = FsUtils.listFileInDir(Constants.rulesPath); - const fileHasBeenFound = files.find(file => { - return file === ruleFileName; - }); - if (!fileHasBeenFound) { - fileExists = false; - this.setError('wrongData', 'rules'); + const isWildCardRule = ruleFileName.includes('*'); + if (isWildCardRule) { + rules = ['* (All Rules)']; + } else { + const files = FsUtils.listFileInDir(Constants.rulesPath); + const fileHasBeenFound = files.find(file => { + return file === ruleFileName; + }); + if (!fileHasBeenFound) { + fileExists = false; + this.setError('wrongData', 'rules'); + } } } } catch (error) { diff --git a/hashkitty-server/src/lib/ORM/Factory.ts b/hashkitty-server/src/lib/ORM/Factory.ts deleted file mode 100644 index 3a1271f..0000000 --- a/hashkitty-server/src/lib/ORM/Factory.ts +++ /dev/null @@ -1,215 +0,0 @@ -import path = require('path'); -import { DataSource, EntityTarget, ObjectLiteral } from 'typeorm'; - -import { Hashlist } from './entity/Hashlist'; -import { Options } from './entity/Options'; -import { Task } from './entity/Task'; -import { TemplateTask } from './entity/TemplateTask'; -import { Wordlist } from './entity/Wordlist'; -import { AttackMode } from './entity/AttackMode'; -import { WorkloadProfile } from './entity/WorkloadProfile'; -import { Migration } from './Migration'; -import { HashType } from './entity/HashType'; - -export class Factory { - private appDataSource: DataSource; - private migration: Migration; - - constructor(appDataSource: DataSource) { - this.appDataSource = appDataSource; - this.migration = new Migration(appDataSource); - } - - public async fakeAll(numberOfFakes: number): Promise { - await this.fakeTasks(numberOfFakes); - await this.fakeTemplateTasks(numberOfFakes % 2); - } - - public async fakeTasks(numberOfFakeTasks: number): Promise { - for (const i in [...Array(numberOfFakeTasks).keys()]) { - const task = new Task(); - if (Math.random() < 0) { - const options = await this.createFakeOption(); - this.appDataSource.manager.save(options); - task.options = options; - } else { - const templateTasks = await this.createListIfNotExist( - TemplateTask, - this.fakeTemplateTasks, - { - relations: { - options: true, - }, - } - ); - const templateTask = - templateTasks[this.getRandomValueInRange(templateTasks.length)]; - task.templateTaskId = templateTask.id; - task.options = templateTask.options; - } - const hashlists = await this.createListIfNotExist( - Hashlist, - this.fakeHashLists - ); - task.hashlistId = - hashlists[this.getRandomValueInRange(hashlists.length)].id; - task.name = `${this.makeFakeString(5)}-${i}`; - task.description = Math.random() < 0.5 ? this.makeFakeString(50) : ''; - task.isfinished = Math.random() < 0.5; - task.lastestModification = this.randomDate(); - task.createdAt = this.randomDate(); - if (Math.random() < 0.5) task.endeddAt = this.randomDate(2022); - this.appDataSource.manager.save(task); - } - } - - public fakeTemplateTasks = async ( - numberOfFakeTasks: number - ): Promise => { - for (let i = 0; i < numberOfFakeTasks; i++) { - const options = await this.createFakeOption(); - this.appDataSource.manager.save(options); - const templateTask = new TemplateTask(); - templateTask.name = `${this.makeFakeString(5)}`; - templateTask.description = this.makeFakeString(50); - templateTask.lastestModification = this.randomDate(); - templateTask.createdAt = this.randomDate(); - templateTask.options = options; - this.appDataSource.manager.save(templateTask); - } - }; - - private randomDate(year = 2021) { - const start = new Date(year, 0, 1); - return new Date( - start.getTime() + - Math.floor(Math.random() * (new Date().getTime() - start.getTime())) - ); - } - - private makeFakeString(length: number): string { - let result = ''; - const characters = - 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; - for (let i = 0; i < length; i++) { - result += characters.charAt( - this.getRandomValueInRange(characters.length) - ); - result += Math.random() < 0.15 ? ' ' : ''; - } - return result; - } - - private async createFakeOption(): Promise { - const options = new Options(); - const attackModes = await this.createListIfNotExist( - AttackMode, - this.migration.migrateAttackModes - ); - const workloadProfile = await this.createListIfNotExist( - WorkloadProfile, - this.fakeWorkloadProfile - ); - options.attackModeId = - attackModes[this.getRandomValueInRange(attackModes.length)].id; - options.CPUOnly = Math.random() < 0.3; - options.breakpointGPUTemperature = Math.floor(Math.random() * 50 + 40); - options.kernelOpti = Math.random() < 0.3; - options.rules = this.makeFakeString(20); - options.potfileName = this.makeFakeString(20); - options.maskQuery = this.makeFakeString(20); - options.maskFilename = this.makeFakeString(20); - options.workloadProfileId = - workloadProfile[this.getRandomValueInRange(workloadProfile.length)].id; - const wordlists = await this.createListIfNotExist( - Wordlist, - this.fakeWordLists - ); - options.wordlistId = - wordlists[this.getRandomValueInRange(wordlists.length)].id; - return options; - } - - private async createListIfNotExist( - EntityList: EntityTarget, - creationListFn: (numberOfFakeToCreate: number) => Promise, - findObject = {}, - tryAgainCount = 0 - ): Promise { - let req: T[] = []; - try { - req = await this.appDataSource - .getRepository(EntityList) - .find(findObject); - } catch (e) { - if (tryAgainCount > 0) { - throw e; - } - } finally { - if (req.length === 0) { - creationListFn(1); - await this.createListIfNotExist( - EntityList, - creationListFn, - findObject, - 1 - ); - } - } - return req; - } - - private getRandomValueInRange(range: number): number { - return Math.floor(Math.random() * range); - } - - private fakeWordLists = async ( - numberOfFakeToCreate: number - ): Promise => { - for (const i in [...Array(numberOfFakeToCreate).keys()]) { - const wordlist = new Wordlist(); - wordlist.name = `${this.makeFakeString(5)}-${i}`; - wordlist.description = this.makeFakeString(50); - wordlist.path = path.join( - `/${this.makeFakeString(5)}`, - this.makeFakeString(5), - this.makeFakeString(5), - this.makeFakeString(5) - ); - await this.appDataSource.manager.save(wordlist); - } - }; - - private fakeHashLists = async ( - numberOfFakeToCreate: number - ): Promise => { - for (const i in [...Array(numberOfFakeToCreate).keys()]) { - const hashTypes = await this.createListIfNotExist( - HashType, - this.migration.migrateHashTypes - ); - const hashlist = new Hashlist(); - hashlist.hashTypeId = - hashTypes[this.getRandomValueInRange(hashTypes.length)].id; - hashlist.name = `${this.makeFakeString(5)}-${i}`; - hashlist.description = this.makeFakeString(50); - hashlist.numberOfCrackedPasswords = Math.random() * 20; - hashlist.crackedOutputFileName = `${hashlist.name}-${hashlist.id}`; - hashlist.lastestModification = this.randomDate(); - hashlist.createdAt = this.randomDate(); - await this.appDataSource.manager.save(hashlist); - } - }; - - private fakeWorkloadProfile = async ( - numberOfFakeToCreate: number - ): Promise => { - for (let i = 0; i < numberOfFakeToCreate; i++) { - const workloadProfile = new WorkloadProfile(); - workloadProfile.profileId = this.getRandomValueInRange(4); - workloadProfile.powerConsumation = this.makeFakeString(10); - workloadProfile.desktopImpact = this.makeFakeString(10); - await this.appDataSource.manager.save(workloadProfile); - } - }; -} diff --git a/hashkitty-server/src/lib/ORM/entity/Options.ts b/hashkitty-server/src/lib/ORM/entity/Options.ts index 23a7cc3..90579ea 100644 --- a/hashkitty-server/src/lib/ORM/entity/Options.ts +++ b/hashkitty-server/src/lib/ORM/entity/Options.ts @@ -43,7 +43,7 @@ export class Options { @JoinColumn({ name: 'wordlist_id', referencedColumnName: 'id' }) wordlistId?: number; - @Column('varchar', { name: 'rule_name', default: '' }) + @Column('text', { name: 'rule_name', default: '' }) rules?: string; @Column('varchar', { name: 'potfile_name', default: '' }) diff --git a/hashkitty-server/src/lib/hashcat/HashcatGenerator.ts b/hashkitty-server/src/lib/hashcat/HashcatGenerator.ts index 09a377d..7c6e915 100644 --- a/hashkitty-server/src/lib/hashcat/HashcatGenerator.ts +++ b/hashkitty-server/src/lib/hashcat/HashcatGenerator.ts @@ -118,7 +118,7 @@ export class HashcatGenerator { if (this.task.options.rules) { flags.push({ key: 'rulesFile', - value: this.task.options.rules.split(','), + value: this.createRulesPaths(this.task.options.rules.split(',')), }); } if (this.task.options.workloadProfileId) { @@ -140,6 +140,14 @@ export class HashcatGenerator { return this.buildFlags(flags); } + private createRulesPaths(rules: string[]): string[] { + const hasWildCardRule = rules.some(rule => rule.includes('*')); + if (hasWildCardRule) { + rules = FsUtils.listFileInDir(Constants.rulesPath); + } + return rules.map(rule => path.join(Constants.rulesPath, rule)); + } + private prepareRestoreFlags(): CmdData[] { const flags = this.defaultFlags; const restoreFlag: PartialCmdData = { key: 'restore' };