From 87934553af39dd6618f6de8ab36d2f97e730939d Mon Sep 17 00:00:00 2001 From: Himadri Bhattacharjee Date: Mon, 12 Jun 2023 08:26:46 +0530 Subject: [PATCH] feat: add function to run boot script --- src/code.py | 4 ++++ src/ducky.py | 13 ++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/code.py b/src/code.py index b7598c0..70d3083 100644 --- a/src/code.py +++ b/src/code.py @@ -11,6 +11,7 @@ from adafruit_httpserver import POST, FileResponse, Request, Server from api import handle +from ducky import run_boot_script async def main(): @@ -25,6 +26,9 @@ async def main(): pool = socketpool.SocketPool(wifi.radio) server = Server(pool) + # Run the boot script immediately after spawing the wifi network + asyncio.run(run_boot_script()) + @server.route("/") def base(request: Request): return FileResponse(request, "index.html", root_path="/static") diff --git a/src/ducky.py b/src/ducky.py index 9babdac..fbad496 100644 --- a/src/ducky.py +++ b/src/ducky.py @@ -1,6 +1,7 @@ """ Logic to interpret and execute user defined ducky script payloads. """ +import os import time import usb_hid @@ -117,4 +118,14 @@ def run_script_file(path: str): with open(path, "r", encoding="utf-8") as handle: run_script(handle.read()) except OSError as error: - warn(f"unable to open file {path}: {error}") + warn(f"unable to run script {path}: {error}") + + +async def run_boot_script(): + """ + Try reading and running the boot.dd script if defined by the user + """ + path = "payloads/boot.dd" + if not os.path.exists(path): + return + run_script_file(path)