Skip to content

Commit

Permalink
Add signal brute command
Browse files Browse the repository at this point in the history
  • Loading branch information
leonjza committed Oct 22, 2016
1 parent 098403d commit 198f4e4
Show file tree
Hide file tree
Showing 2 changed files with 114 additions and 0 deletions.
88 changes: 88 additions & 0 deletions ooktools/commands/signalling.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,3 +386,91 @@ def jam(frequency, data, baud, maxpower):
# Idle the radio
click.secho('Idling radio', fg='yellow')
d.setModeIDLE()


def bruteforce(frequency, baud, maxpower, start, end, repeat, prefix, suffix):
"""
Brute force an OOK signal by sending permutations of
a bitstring.
:param frequency:
:param baud:
:param maxpower:
:param start:
:param end:
:param repeat:
:param prefix:
:param suffix:
:return:
"""

start = bitstring.BitArray(bin=start)
end = bitstring.BitArray(bin=end)

click.secho('Start binary : \'{}\' or \'{}\' as an integer'.format(start.bin, start.uint), fg='green')
click.secho('End binary : \'{}\' or \'{}\' as an integer'.format(end.bin, end.uint), fg='green')

# Ensure that the start value is less than the end value
if start.uint > end.uint:
click.secho('Start position is larger than end position.', fg='red')
return

click.secho('Generating {} combinations...'.format(end.uint - start.uint), fg='green', bold=True)

# Placeholder for all of the PWM permutations that
# will be calculated.
permutations = []

# Set the current value to the start value as a starting
# point for the brute force
current_value = start.uint

# Loop over the range and generate PWM encoded strings to
# send along with the radio
while current_value < end.uint:

# Get a proper BitArray instance of the binary
binary = bitstring.BitArray(bin=bin(current_value))

# Calculate the PWM version of the binary
pwm_bits = [prefix]

for bit in binary.bin:
pwm_bits.append('100' if bit == '1' else '110')

# Add the suffix
pwm_bits.append(suffix)

pwm_data = ''.join(pwm_bits)

# Add the permutation and append the current value
permutations.append(pwm_data)
current_value += 1

click.secho('Configuring Radio', fg='yellow')
d = rflib.RfCat()
configure_dongle(d, frequency=frequency, pktflen=len(permutations[0]), baud=baud,
maxpower=maxpower)

click.secho('Running brute force with a total of ({} combinations * {} repeats) {} RF transmits.'.format(
len(permutations), repeat, len(permutations) * repeat), bold=True)

# Small function used to format a label for the progressbar
def show_current_data(data):
return '[Current PWM string: {}]'.format(data)

# Run the brute force
with click.progressbar(permutations,
show_pos=True,
item_show_func=show_current_data) as combinations:

for combination in combinations:
# Generate the bytes needed for the RFXmit
rf_data = bitstring.BitArray(bin=combination).tobytes()

# Send the data using the radio
d.RFxmit(data=rf_data, repeat=repeat)

# Idle the radio
click.secho('Idling radio', fg='yellow')
d.setModeIDLE()
26 changes: 26 additions & 0 deletions ooktools/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,32 @@ def jam(frequency, data, baud, maxpower):
return


@signal.command()
@click.option('--frequency', '-F', default=433920000, show_default=True,
help='Frequency to use.')
@click.option('--baud', '-b', default=4800, show_default=True,
help='Baud rate to use.')
@click.option('--maxpower', '-m', is_flag=True, default=False,
help='Set the radio to max output power.')
@click.option('--start', '-S', default='000000000000', help='Start sequence.',
callback=validate_binary_string, show_default=True)
@click.option('--end', '-E', default='111111111111', help='End sequence.',
callback=validate_binary_string, show_default=True)
@click.option('--repeat', '-r', default=5, show_default=True,
help='Number of times to repeat a frame.')
@click.option('--prefix', '-p', default='', help='Signal prefix.',
callback=validate_binary_string)
@click.option('--suffix', '-s', default='', help='Signal suffix.',
callback=validate_binary_string)
def brute(frequency, baud, maxpower, start, end, repeat, prefix, suffix):
"""
Bruteforce a binary range.
"""

signalling.bruteforce(**locals())
return


@send.command()
@click.option('--data', '-D', required=True, help='Source bitstring.',
callback=validate_binary_string)
Expand Down

0 comments on commit 198f4e4

Please sign in to comment.