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

Made solve.py slightly more automated and added some default values #284

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 9 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,24 +95,22 @@ hunter hunter_patched ld-2.23.so libc.so.6 readme solve.py

from pwn import *

context.terminal = ['gnome-terminal', '--']
context.binary = binary = "./hunter_patched"
context.update(arch='x86_64')

exe = ELF("./hunter_patched")
libc = ELF("./libc.so.6")
ld = ELF("./ld-2.23.so")

context.binary = exe


def conn():
if args.LOCAL:
r = process([exe.path])
if args.DEBUG:
gdb.attach(r)
else:
if args.REMOTE:
r = remote("addr", 1337)

else:
r = process(binary)
gdb.attach(r)
return r


def main():
r = conn()

Expand All @@ -123,4 +121,5 @@ def main():

if __name__ == "__main__":
main()

```
24 changes: 24 additions & 0 deletions src/solvepy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,36 @@ fn make_bindings(opts: &Opts) -> String {
.join("\n")
}

fn make_bin_patched_path(opts: &Opts) -> String {
// Helper to make one binding line
fn bind<P: AsRef<Path>>(opt_path: Option<P>) -> Option<String> {
opt_path
.as_ref()
.map(|path| format!("\"{}\"", path.as_ref().display(),))
}
[
bind(
patch_bin::bin_patched_path(opts)
.as_ref()
.or_else(|| opts.bin.as_ref()),
)
]
.iter()
.filter_map(|x| x.as_ref())
.cloned()
.collect::<Vec<String>>()
.join("\n")
}


/// Make arguments to pwntools `process()` function
fn make_proc_args(opts: &Opts) -> String {
format!("[{}.path]", opts.template_bin_name)
}

/// Fill in template pwntools solve script with (binary, libc, linker) paths
fn make_stub(opts: &Opts) -> Result<String> {

let templ = match &opts.template_path {
Some(path) => {
let data = fs::read(path).context(ReadSnafu)?;
Expand All @@ -82,6 +105,7 @@ fn make_stub(opts: &Opts) -> Result<String> {
"bindings".to_string() => make_bindings(opts),
"proc_args".to_string() => make_proc_args(opts),
"bin_name".to_string() => opts.template_bin_name.clone(),
"bin_path".to_string() => make_bin_patched_path(opts),
},
)
.context(FmtSnafu)
Expand Down
18 changes: 8 additions & 10 deletions src/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,20 @@

from pwn import *

{bindings}

context.binary = {bin_name}
context.terminal = ['gnome-terminal', '--']
context.binary = binary = {bin_path}
context.update(arch='x86_64')

{bindings}

def conn():
if args.LOCAL:
r = process({proc_args})
if args.DEBUG:
gdb.attach(r)
if args.REMOTE:
r = remote("addr", 1234)
else:
r = remote("addr", 1337)

r = process(binary)
gdb.attach(r)
return r


def main():
r = conn()

Expand Down