Skip to content

Commit

Permalink
Add shellcraft.sleep template wrapping SYS_nanosleep
Browse files Browse the repository at this point in the history
Accepts the time in seconds as a float argument and calls SYS_nanosleep.

Fixes #1428
  • Loading branch information
peace-maker committed Jul 9, 2023
1 parent f1d5afe commit 80334e8
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 0 deletions.
1 change: 1 addition & 0 deletions pwnlib/shellcraft/templates/aarch64/linux/sleep.asm
1 change: 1 addition & 0 deletions pwnlib/shellcraft/templates/amd64/linux/sleep.asm
1 change: 1 addition & 0 deletions pwnlib/shellcraft/templates/arm/linux/sleep.asm
28 changes: 28 additions & 0 deletions 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.
</%docstring>
<%
# 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)}
1 change: 1 addition & 0 deletions pwnlib/shellcraft/templates/i386/linux/sleep.asm
1 change: 1 addition & 0 deletions pwnlib/shellcraft/templates/mips/linux/sleep.asm
1 change: 1 addition & 0 deletions pwnlib/shellcraft/templates/thumb/linux/sleep.asm

0 comments on commit 80334e8

Please sign in to comment.