Skip to content

Add support for keyboard layout mapping files (.hckmap) in dictionary attacks #659

Description

@unclesp1d3r

Overview

Hashcat supports keyboard layout mapping files (.hckmap) that transform candidate passwords as if they were typed on a different keyboard layout. This is particularly useful for handling scenarios where users type passwords using non-US keyboard layouts (e.g., German DE, French FR, Russian Cyrillic) but the system interprets them as US layout characters—a common issue with TrueCrypt/VeraCrypt pre-boot authentication.

Background

When users create passwords on a non-US keyboard layout, the physical key presses may be interpreted differently depending on the active layout. For example, a German user typing qwertz on a DE keyboard would produce qwerty if the system was in US layout mode. Hashcat's --keyboard-layout-mapping option addresses this by applying layout transformations to dictionary wordlists during attacks.

Hashcat ships with example mapping files in its layouts/ directory (e.g., us.hckmap, de.hckmap, ru.hckmap, etc.). Each .hckmap file contains tab-separated mappings between the target layout characters and US layout equivalents.

Current State

CipherSwarm currently supports:

  • Word lists (dictionary files)
  • Rule lists (transformation rules)
  • Mask lists (pattern-based attacks)

However, there is no UI support for selecting and applying keyboard layout files to dictionary attacks.

Proposed Solution

1. Create KeyboardLayout Model

Create a new resource model similar to WordList, RuleList, and MaskList:

  • Include the AttackResource concern for consistent file handling
  • Support file attachment for .hckmap files
  • Add validation for file content type (text/plain or application/octet-stream)
  • Belong to a creator (User)
  • Support project associations (HABTM relationship)
  • Support sensitive/shared visibility scoping

2. Database Migration

Add keyboard_layouts table with columns:

  • name (string, unique, required)
  • description (text)
  • sensitive (boolean, required)
  • processed (boolean, default: false)
  • creator_id (foreign key to users)
  • Standard timestamps

Add association to attacks table:

  • keyboard_layout_id (foreign key to keyboard_layouts, optional)

3. Update Attack Model

  • Add belongs_to :keyboard_layout, optional: true
  • Add validation that keyboard_layout can only be used with:
    • Dictionary attacks (attack_mode: :dictionary)
    • Hybrid dictionary attacks (attack_mode: :hybrid_dictionary)
    • Hybrid mask attacks (attack_mode: :hybrid_mask)
  • Add validation to ensure keyboard_layout is absent for pure mask attacks

4. Update AttackHashcatParameters Concern

Modify the hashcat_parameters method to include:

parameters << "--keyboard-layout-mapping #{keyboard_layout.file.filename}" if keyboard_layout.present?

5. UI Updates

  • Add KeyboardLayoutDashboard for Administrate admin interface
  • Add keyboard layout selector to attack forms (dictionary, hybrid_dictionary, hybrid_mask sections)
  • Add keyboard layout display to attack show pages
  • Add CRUD views for managing keyboard layouts similar to word lists/rule lists

6. API Updates

  • Add keyboard layout endpoints to API (following existing patterns for word_lists, rule_lists)
  • Update attack API serialization to include keyboard_layout_id
  • Update API documentation (Swagger)

Acceptance Criteria

  • Administrators can upload and manage .hckmap files through the UI
  • Users can select a keyboard layout when configuring dictionary-based attacks
  • The hashcat command parameters include --keyboard-layout-mapping when a layout is selected
  • Keyboard layout option is only available for applicable attack modes
  • API supports CRUD operations for keyboard layouts
  • Documentation is updated

Technical Notes

  • Hashcat command syntax: hashcat -a 0 --keyboard-layout-mapping layouts/de.hckmap hashes.txt wordlist.txt
  • Compatible with rules: hashcat -a 0 -r rules/best64.rule --keyboard-layout-mapping layouts/de.hckmap hashes.txt wordlist.txt
  • Layout files are simple text files with tab-separated character mappings

Related Files

  • app/models/word_list.rb - Reference implementation for file-based attack resource
  • app/models/concerns/attack_resource.rb - Shared functionality for attack resources
  • app/models/concerns/attack_hashcat_parameters.rb - Hashcat parameter generation
  • app/models/attack.rb - Attack model with resource associations

References

  • Hashcat keyboard layout mapping documentation
  • Example layouts in hashcat's layouts/ directory

Metadata

Metadata

Assignees

Projects

Status
Backlog

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions