forked from Gallopsled/pwntools
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add cat2 to shellcraft (Gallopsled#1995)
* Introduce shellcraft.linux.cat2 to avoid sendfile Fixes Gallopsled#1871 * Switch CAT_PROC_MAPS_EXIT to shellcraft.linux.cat2
- Loading branch information
Showing
14 changed files
with
150 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<% | ||
from pwnlib import shellcraft | ||
%> | ||
<%page args="filename, fd=1, length=0x4000"/> | ||
<%docstring> | ||
Opens a file and writes its contents to the specified file descriptor. | ||
Uses an extra stack buffer and must know the length. | ||
|
||
Example: | ||
|
||
>>> f = tempfile.mktemp() | ||
>>> write(f, 'This is the flag\n') | ||
>>> shellcode = shellcraft.cat2(f) + shellcraft.exit(0) | ||
>>> run_assembly(shellcode).recvline() | ||
b'This is the flag\n' | ||
</%docstring> | ||
<% | ||
if fd == 'x0': | ||
raise Exception("File descriptor cannot be x0, it will be overwritten") | ||
%> | ||
${shellcraft.open(filename)} | ||
${shellcraft.mov('x2', length)} | ||
sub sp, sp, x2 | ||
${shellcraft.read('x0', 'sp', 'x2')} | ||
${shellcraft.write(fd, 'sp', 'x0')} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<% | ||
from pwnlib.shellcraft.amd64 import syscall, pushstr | ||
from pwnlib.shellcraft import common | ||
%> | ||
<%page args="filename, fd=1, length=0x4000"/> | ||
<%docstring> | ||
Opens a file and writes its contents to the specified file descriptor. | ||
Uses an extra stack buffer and must know the length. | ||
</%docstring> | ||
|
||
${pushstr(filename)} | ||
${syscall('SYS_open', 'rsp', 'O_RDONLY', length)} | ||
sub rsp, rdx | ||
${syscall('SYS_read', 'rax', 'rsp', 'rdx')} | ||
${syscall('SYS_write', fd, 'rsp', 'rax')} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<% | ||
from pwnlib import constants | ||
from pwnlib.shellcraft import arm | ||
%> | ||
<%page args="filename, fd=1, length=0x4000"/> | ||
<%docstring> | ||
Opens a file and writes its contents to the specified file descriptor. | ||
Uses an extra stack buffer and must know the length. | ||
|
||
Example: | ||
|
||
>>> f = tempfile.mktemp() | ||
>>> write(f, 'FLAG\n') | ||
>>> run_assembly(shellcraft.arm.linux.cat2(f)).recvline() | ||
b'FLAG\n' | ||
|
||
</%docstring> | ||
${arm.pushstr(filename)} | ||
${arm.linux.open('sp', int(constants.O_RDONLY), length)} | ||
sub sp, r2 | ||
${arm.linux.read('r0', 'sp', 'r2')} | ||
${arm.linux.write(fd, 'sp', 'r0')} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<% | ||
import pwnlib.shellcraft as sc | ||
from pwnlib.shellcraft import common | ||
%> | ||
<%page args="filename, fd=1, length=0x4000"/> | ||
<%docstring> | ||
Opens a file and writes its contents to the specified file descriptor. | ||
Uses an extra stack buffer and must know the length. | ||
|
||
Example: | ||
|
||
>>> f = tempfile.mktemp() | ||
>>> write(f, 'FLAG') | ||
>>> run_assembly(shellcraft.i386.linux.cat2(f)).recvall() | ||
b'FLAG' | ||
|
||
</%docstring> | ||
|
||
${sc.pushstr(filename)} | ||
${sc.open('esp', 'O_RDONLY', length)} | ||
sub esp, edx | ||
${sc.read('eax', 'esp', 'edx')} | ||
${sc.write(fd, 'esp', 'eax')} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<% | ||
from pwnlib import constants | ||
from pwnlib.shellcraft import mips | ||
from pwnlib.shellcraft import common | ||
%> | ||
<%page args="filename, fd=1, length=0x4000"/> | ||
<%docstring> | ||
Opens a file and writes its contents to the specified file descriptor. | ||
Uses an extra stack buffer and must know the length. | ||
|
||
Example: | ||
|
||
>>> f = tempfile.mktemp() | ||
>>> write(f, 'FLAG') | ||
>>> sc = shellcraft.mips.linux.cat2(f) | ||
>>> sc += shellcraft.mips.linux.exit(0) | ||
>>> run_assembly(sc).recvall() | ||
b'FLAG' | ||
|
||
</%docstring> | ||
|
||
${mips.pushstr(filename)} | ||
${mips.open('$sp', int(constants.O_RDONLY), length)} | ||
sub $sp, $a2 | ||
${mips.read('$v0', '$sp', '$a2')} | ||
${mips.write(fd, '$sp', '$v0')} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<% | ||
from pwnlib import constants | ||
from pwnlib.shellcraft import thumb | ||
from pwnlib.shellcraft import common | ||
%> | ||
<%page args="filename, fd=1, length=0x4000"/> | ||
<%docstring> | ||
Opens a file and writes its contents to the specified file descriptor. | ||
Uses an extra stack buffer and must know the length. | ||
|
||
Example: | ||
|
||
>>> f = tempfile.mktemp() | ||
>>> write(f, 'FLAG\n') | ||
>>> run_assembly(shellcraft.arm.to_thumb()+shellcraft.thumb.linux.cat2(f)).recvline() | ||
b'FLAG\n' | ||
|
||
</%docstring> | ||
|
||
${thumb.pushstr(filename)} | ||
${thumb.linux.open('sp', constants.O_RDONLY, length)} | ||
sub sp, r2 | ||
${thumb.linux.read('r0', 'sp', 'r2')} | ||
${thumb.linux.write(fd, 'sp', 'r0')} |