crchack

repository·master·Indexed 42 days ago

https://github.com/resilar/crchack

A tool to force input messages to result in a specific CRC checksum. It supports arbitrary-precision CRC algorithms with custom parameters and can modify non-contiguous bits using Python-style slices to achieve a target checksum.

Tokens
1.2K
Snippets
4
Records
4
Agent score
3%

What's inside crchack

  1. Configure mutable input bits with -b

    master

    To modify non-contiguous bits instead of appending bytes, use the -b flag. This allows you to specify which bits in the original message are allowed to be changed to reach the target checksum.

    Syntax: -b l:r:s (Python-style slices)

    • l: Start position (inclusive)
    • r: End position (exclusive)
    • s: Step (distance between bits)

    Bit Addressing: Positions can be specified as byte.bit (e.g., 0.32 is the 32nd bit in the 0th byte). Within a byte, bits are numbered 0 (LSB) to 7 (MSB).

    Advanced Selection:

    • Negative positions: Treated as offsets from the end of the input.
    • Arithmetic: Supports +, -, *, / and 0x hex prefixes.
    • Relative end: Use + to define end relative to start (e.g., +.8*32).
    • Brace expansion: Supports {start-end} syntax (e.g., .{0-2}:-1:1).

    Requirement: You must provide at least w mutable bits, where w is the CRC register size (e.g., 32 bits for CRC-32).

    # Select bits 1..2, 3..5, and 6..7
    echo "aXbXXcXd" | ./crchack -b1:2 -b3:5 -b6:7 - cafebabe
    
    # Select all bits starting from byte 4
    echo "1234PQPQ" | ./crchack -b 4: - 12345678
    
    # Use complex bit selection with arithmetic
    echo "A"*32 | ./crchack -b "0.5:+.8*32:.8" - 1337c0de
  2. Use crchack to force CRC checksums

    master

    Use crchack to modify an input file so that its CRC checksum matches a target value. By default, crchack appends 4 bytes to the input to achieve the target checksum. If no target_checksum is provided, the tool simply calculates and prints the CRC checksum of the input file to stdout.

    Basic Syntax: ./crchack [options] file [target_checksum]

    Note: Use - as the filename to read from stdin and write to stdout.

    # Calculate checksum of a file
    ./crchack foo
    
    # Force a file to have a specific checksum (appends 4 bytes)
    ./crchack foo 42424242 > bar
    
    # Use via pipes
    echo "hello" | ./crchack - DEADBEEF | ./crchack -
  3. Configure custom CRC algorithms

    master

    While crchack defaults to CRC-32, you can implement any CRC algorithm by providing its parameters. This is useful for matching specific protocols or file formats. You can find parameter sets in the CRC RevEng catalogue.

    Examples:

    • CRC-8: -w8 -p<poly>
    • CRC-16 (Standard): -w16 -p8005 -rR
    • MODBUS: -w16 -p8005 -iffff -rR
    • CRC-32 (Standard): -w32 -p04c11db7 -iffffffff -xffffffff -rR
    # Example: Forcing a CRC-8 checksum
    ./crchack -w8 -p7 msg
  4. Reference: CLI options and CRC parameters

    master

    The following options control bit selection and the CRC algorithm configuration.

    Bit Selection Options:

    • -o pos: Specify a single byte.bit position of mutable input bits.
    • -O pos: Position offset from the end of the input.
    • -b l:r:s: Specify bits at positions l..r with step s.
    • -v: Verbose mode.

    CRC Parameter Options (Defaults to CRC-32):

    • -p poly: Generator polynomial.
    • -w size: Register size in bits.
    • -i init: Initial register value.
    • -x xor: Final register XOR mask.
    • -r: Reverse input bytes.
    • -R: Reverse final register.
    usage: ./crchack [options] file [target_checksum]
    
    options:
      -o pos    byte.bit position of mutable input bits
      -O pos    position offset from the end of the input
      -b l:r:s  specify bits at positions l..r with step s
      -h        show this help
      -v        verbose mode
    
    CRC parameters (default: CRC-32):
      -p poly   generator polynomial    -w size   register size in bits
      -i init   initial register value  -x xor    final register XOR mask
      -r        reverse input bytes     -R        reverse final register