From 80334e8e4f8f2d68afcd9013ef901c53e9e781e0 Mon Sep 17 00:00:00 2001 From: Peace-Maker Date: Sun, 9 Jul 2023 18:31:09 +0200 Subject: [PATCH] Add shellcraft.sleep template wrapping SYS_nanosleep Accepts the time in seconds as a float argument and calls SYS_nanosleep. Fixes #1428 --- .../templates/aarch64/linux/sleep.asm | 1 + .../templates/amd64/linux/sleep.asm | 1 + .../shellcraft/templates/arm/linux/sleep.asm | 1 + .../templates/common/linux/sleep.asm | 28 +++++++++++++++++++ .../shellcraft/templates/i386/linux/sleep.asm | 1 + .../shellcraft/templates/mips/linux/sleep.asm | 1 + .../templates/thumb/linux/sleep.asm | 1 + 7 files changed, 34 insertions(+) create mode 120000 pwnlib/shellcraft/templates/aarch64/linux/sleep.asm create mode 120000 pwnlib/shellcraft/templates/amd64/linux/sleep.asm create mode 120000 pwnlib/shellcraft/templates/arm/linux/sleep.asm create mode 100644 pwnlib/shellcraft/templates/common/linux/sleep.asm create mode 120000 pwnlib/shellcraft/templates/i386/linux/sleep.asm create mode 120000 pwnlib/shellcraft/templates/mips/linux/sleep.asm create mode 120000 pwnlib/shellcraft/templates/thumb/linux/sleep.asm diff --git a/pwnlib/shellcraft/templates/aarch64/linux/sleep.asm b/pwnlib/shellcraft/templates/aarch64/linux/sleep.asm new file mode 120000 index 0000000000..5949528ed8 --- /dev/null +++ b/pwnlib/shellcraft/templates/aarch64/linux/sleep.asm @@ -0,0 +1 @@ +../../common/linux/sleep.asm \ No newline at end of file diff --git a/pwnlib/shellcraft/templates/amd64/linux/sleep.asm b/pwnlib/shellcraft/templates/amd64/linux/sleep.asm new file mode 120000 index 0000000000..5949528ed8 --- /dev/null +++ b/pwnlib/shellcraft/templates/amd64/linux/sleep.asm @@ -0,0 +1 @@ +../../common/linux/sleep.asm \ No newline at end of file diff --git a/pwnlib/shellcraft/templates/arm/linux/sleep.asm b/pwnlib/shellcraft/templates/arm/linux/sleep.asm new file mode 120000 index 0000000000..5949528ed8 --- /dev/null +++ b/pwnlib/shellcraft/templates/arm/linux/sleep.asm @@ -0,0 +1 @@ +../../common/linux/sleep.asm \ No newline at end of file diff --git a/pwnlib/shellcraft/templates/common/linux/sleep.asm b/pwnlib/shellcraft/templates/common/linux/sleep.asm new file mode 100644 index 0000000000..cc2fc09821 --- /dev/null +++ b/pwnlib/shellcraft/templates/common/linux/sleep.asm @@ -0,0 +1,28 @@ +<% + import pwnlib.abi + from pwnlib import shellcraft +%> +<%page args="seconds"/> +<%docstring> +Sleeps for the specified amount of seconds. + +Uses SYS_nanosleep under the hood. + +Args: + seconds (int,float): The time to sleep in seconds. + +<% + # struct timespec { + # time_t tv_sec; /* Seconds */ + # long tv_nsec; /* Nanoseconds */ + # }; + tv_sec = int(seconds) + tv_nsec = int((seconds % 1) * 1000000000) + + abi = pwnlib.abi.ABI.syscall() + stack = abi.stack +%> + /* sleep(${seconds}) */ + ${shellcraft.push(tv_nsec)} + ${shellcraft.push(tv_sec)} + ${shellcraft.syscall('SYS_nanosleep', stack, 0)} diff --git a/pwnlib/shellcraft/templates/i386/linux/sleep.asm b/pwnlib/shellcraft/templates/i386/linux/sleep.asm new file mode 120000 index 0000000000..5949528ed8 --- /dev/null +++ b/pwnlib/shellcraft/templates/i386/linux/sleep.asm @@ -0,0 +1 @@ +../../common/linux/sleep.asm \ No newline at end of file diff --git a/pwnlib/shellcraft/templates/mips/linux/sleep.asm b/pwnlib/shellcraft/templates/mips/linux/sleep.asm new file mode 120000 index 0000000000..5949528ed8 --- /dev/null +++ b/pwnlib/shellcraft/templates/mips/linux/sleep.asm @@ -0,0 +1 @@ +../../common/linux/sleep.asm \ No newline at end of file diff --git a/pwnlib/shellcraft/templates/thumb/linux/sleep.asm b/pwnlib/shellcraft/templates/thumb/linux/sleep.asm new file mode 120000 index 0000000000..5949528ed8 --- /dev/null +++ b/pwnlib/shellcraft/templates/thumb/linux/sleep.asm @@ -0,0 +1 @@ +../../common/linux/sleep.asm \ No newline at end of file