Newer
Older
Hardware / FaultInjection / prereqs / FaultyCat / faultycmd.py
0xRoM on 11 Feb 4 KB initial commit
  1. import typer
  2. import platform
  3. import signal
  4. import threading
  5. import sys
  6. from rich.console import Console
  7. from rich.table import Table
  8.  
  9. from Modules import CmdInterface
  10. from Modules.CmdInterface import is_valid_number
  11. from Modules import Worker
  12.  
  13. if platform.system() == "Windows":
  14. DEFAULT_COMPORT = "COM1"
  15. else:
  16. DEFAULT_COMPORT = "/dev/ttyACM0"
  17.  
  18.  
  19. app = typer.Typer(
  20. name="FaultyCat",
  21. help="Script to control the FaultyCat and launch faulty attacks.",
  22. add_completion=False,
  23. no_args_is_help=True,
  24. )
  25.  
  26. faulty_worker = Worker.FaultyWorker()
  27. workers = []
  28.  
  29.  
  30. def signal_handler(sig, frame):
  31. print("You pressed Ctrl+C!")
  32. faulty_worker.stop_workers()
  33. for work in workers:
  34. work.join()
  35. sys.exit(0)
  36.  
  37.  
  38. @app.command("config")
  39. def config():
  40. """Get the current configuration of the FaultyCat."""
  41. table_config = Table(title="Board configuration")
  42. table_config.add_column("Parameter", style="cyan")
  43. table_config.add_column("Value", style="magenta")
  44. table_config.add_row(
  45. "Pulse time", f"{faulty_worker.board_configurator.BOARD_CONFIG['pulse_time']}"
  46. )
  47. table_config.add_row(
  48. "Pulse power", f"{faulty_worker.board_configurator.BOARD_CONFIG['pulse_power']}"
  49. )
  50.  
  51. Console().print(table_config)
  52.  
  53.  
  54. @app.command("devices")
  55. def devices():
  56. """Get the list of available devices."""
  57. table_devices = Table(title="Available devices")
  58. table_devices.add_column("Device", style="cyan")
  59. table_devices.add_column("Description", style="magenta")
  60. for device in faulty_worker.board_uart.get_serial_ports():
  61. table_devices.add_row(f"{device.device}", f"{device.description}")
  62.  
  63. Console().print(table_devices)
  64.  
  65.  
  66. @app.command("fault")
  67. def faulty(
  68. comport: str = typer.Argument(
  69. default=DEFAULT_COMPORT,
  70. help="Serial port to use for uploading.",
  71. ),
  72. pulse_count: int = typer.Option(
  73. 1, "--pulse-count", "-p", help="Number of pulses to send.", show_default=True
  74. ),
  75. pulse_timeout: float = typer.Option(
  76. 1.0,
  77. "--pulse-timeout",
  78. "-t",
  79. help="Time in seconds between pulses.",
  80. show_default=True,
  81. ),
  82. cmd: bool = typer.Option(
  83. False, "--cmd", "-c", help="Launch the CMD Interface.", show_default=True
  84. ),
  85. ):
  86. """Setting up the FaultyCat. With this command you can configure the FaultyCat and launch faulty attacks."""
  87. typer.echo("Configuring the FaultyCat...")
  88. table_config = Table(title="Board configuration")
  89. table_config.add_column("Parameter", style="cyan")
  90. table_config.add_column("Value", style="magenta")
  91. table_config.add_row("Serial port", f"{comport}")
  92. table_config.add_row(
  93. "Pulse time", f"{faulty_worker.board_configurator.BOARD_CONFIG['pulse_time']}"
  94. )
  95. table_config.add_row(
  96. "Pulse power", f"{faulty_worker.board_configurator.BOARD_CONFIG['pulse_power']}"
  97. )
  98. table_config.add_row("Pulse count", f"{pulse_count}")
  99. table_config.add_row("Pulse timeout", f"{pulse_timeout}")
  100.  
  101. Console().print(table_config)
  102.  
  103. faulty_worker.set_serial_port(comport)
  104. if cmd:
  105. CmdInterface.CMDInterface(faulty_worker).cmdloop()
  106. return
  107.  
  108. if not faulty_worker.validate_serial_connection():
  109. typer.secho(
  110. f"FaultyCMD could not stablish connection withe the board on: {comport}.",
  111. fg=typer.colors.RED,
  112. )
  113. return
  114.  
  115. faulty_worker.set_pulse_count(is_valid_number(pulse_count))
  116. faulty_worker.set_pulse_time(is_valid_number(pulse_timeout))
  117.  
  118. faulty_worker.start_faulty_attack()
  119.  
  120.  
  121. if __name__ == "__main__":
  122. print(
  123. """\x1b[36;1m
  124. .@@@%@*%+ -@@+ #@@: @@% =@@@@%- %@% %+ @= |
  125. .@@-.-.#@+=@@* %@@- .@@@.@@%:@@@ @@@ %+ :+++- @*+++- | FaultyCat v0.0.1
  126. .@*.=.+@@:=@@* %@@- .@@@.@@% @@@ @@@ %+ #%:.:## @%:.:## | by JahazielLem
  127. .@@%*+*=. :@@%==@@@#-*@@#.@@% @@@-@@@ %+ @+ =@.@+ =@. | Company: PWNLabs - Electronics Cats
  128. %@% :#@@@%*#@@@%+ %@* :#@@@#: =%#**=.*####@..*####: |
  129. \x1b[0m"""
  130. )
  131. signal.signal(signal.SIGINT, signal_handler)
  132. app()
Buy Me A Coffee