Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detect challenge binary and libc in pwn template #2309

Merged
merged 7 commits into from
Dec 12, 2023

Conversation

peace-maker
Copy link
Member

When the args.exe or args.libc arguments are missing, look for the files in the current working directory.
This allows to quickly get a template by just running pwn template (and maybe --host+--port for remote instances) and have the arguments filled in automatically. Less typing - more pwning!

This is inspired by https://github.com/io12/pwninit

Related #2276

When the `args.exe` or `args.libc` arguments are missing, look for the
files in the current working directory.
This allows to quickly get a template by just running `pwn template`
(and maybe --host --port for remote instances).

This is inspired by https://github.com/io12/pwninit
@peace-maker peace-maker force-pushed the template_detect_files branch from 6f40ef3 to ab2ef24 Compare November 27, 2023 20:15
Allow to keep the old static template behavior.
Inform the user that we're looking for the binaries and if we found one.
@peace-maker
Copy link
Member Author

We could use the pwnlib.filesystem abstraction to look for the files on the ssh server too, but I see even more potential in automatically grabbing the used libc from the remote wherever it is instead. That can be done in a separate PR.

pwnlib/commandline/template.py Outdated Show resolved Hide resolved
pwnlib/commandline/template.py Outdated Show resolved Hide resolved
parser.add_argument('--path', help='Remote path of file on SSH server')
parser.add_argument('--quiet', help='Less verbose template comments', action='store_true')
parser.add_argument('--color', help='Print the output in color', choices=['never', 'always', 'auto'], default='auto')
parser.add_argument('--template', help='Path to a custom template. Tries to use \'~/.config/pwntools/templates/pwnup.mako\', if it exists. '
'Check \'%s\' for the default template shipped with pwntools.' %
os.path.join(printable_data_path, "templates", "pwnup.mako"))
parser.add_argument('--no-auto', help='Do not automatically detect missing binaries', action='store_true')

def detect_missing_binaries(args):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Idea for the future: more and more challenges ship a Dockerfile or even docker-compose. We could use it to detect needed libraries and a binary as well maybe (using API like we do with ADB or shelling out to docker cli).

peace-maker and others added 2 commits December 4, 2023 12:08
Check about common name patterns instead of plainly the presence of "libc" in the name.

Co-authored-by: Arusekk <[email protected]>
@peace-maker peace-maker merged commit 5f5554f into Gallopsled:dev Dec 12, 2023
10 checks passed
@peace-maker peace-maker deleted the template_detect_files branch December 12, 2023 18:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants