Skip to content

Commit

Permalink
Add shellcraft.sleep template wrapping SYS_nanosleep (#2221)
Browse files Browse the repository at this point in the history
* Add shellcraft.sleep template wrapping SYS_nanosleep

Accepts the time in seconds as a float argument and calls SYS_nanosleep.

Fixes #1428

* Update CHANGELOG

* Use nanosleep wrapper

Co-authored-by: Arusekk <[email protected]>
  • Loading branch information
peace-maker and Arusekk committed Jul 9, 2023
1 parent 9c83fa1 commit 8d10485
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,11 @@ The table below shows which release corresponds to each branch, and what date th
## 4.12.0 (`dev`)
- [#2202][2202] Fix `remote` and `listen` in sagemath
- [#2117][2117] Add -p (--prefix) and -s (--separator) arguments to `hex` command
- [#2221][2221] Add shellcraft.sleep template wrapping SYS_nanosleep

[2202]: https://github.com/Gallopsled/pwntools/pull/2202
[2117]: https://github.com/Gallopsled/pwntools/pull/2117
[2221]: https://github.com/Gallopsled/pwntools/pull/2221

## 4.11.0 (`beta`)

Expand Down
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
Original file line number Diff line number Diff line change
@@ -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.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 8d10485

Please sign in to comment.