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

Support JSON output #225

Merged
merged 5 commits into from
Oct 4, 2024
Merged

Support JSON output #225

merged 5 commits into from
Oct 4, 2024

Conversation

david942j
Copy link
Owner

@david942j david942j commented Oct 4, 2024

Introduce a new CLI argument --output-format FORMAT (or -o FORMAT) with FORMAT can be one of pretty, raw, and json.

  • --raw is still available but it becomes an alias to -o raw.
  • --[no-]raw is removed.

Examples of JSON output:

$ one_gadget -b b417c0ba7cc5cf06d1d1bed6652cedb9253c60d0 -o json -l1
[{"value":324279,"effect":"execve(\"/bin/sh\", rsp+0x40, environ)","constraints":["rsp & 0xf == 0","writable: rsp+0x50","{\"sh\", \"-c\", r12, NULL} is a valid argv"]},{"value":324286,"effect":"execve(\"/bin/sh\", rsp+0x40, environ)","constraints":["rsp & 0xf == 0","writable: rsp+0x50","rcx == NULL || {rcx, \"-c\", r12, NULL} is a valid argv"]},{"value":324293,"effect":"execve(\"/bin/sh\", rsp+0x40, environ)","constraints":["rsp & 0xf == 0","writable: rsp+0x50","rcx == NULL || {rcx, rax, r12, NULL} is a valid argv"]},{"value":324386,"effect":"execve(\"/bin/sh\", rsp+0x40, environ)","constraints":["[rsp+0x40] == NULL || {[rsp+0x40], [rsp+0x48], [rsp+0x50], [rsp+0x58], ...} is a valid argv"]},{"value":939679,"effect":"execve(\"/bin/sh\", r14, r12)","constraints":["[r14] == NULL || r14 == NULL || r14 is a valid argv","[r12] == NULL || r12 == NULL || r12 is a valid envp"]},{"value":940120,"effect":"execve(\"/bin/sh\", [rbp-0x88], [rbp-0x70])","constraints":["[[rbp-0x88]] == NULL || [rbp-0x88] == NULL || [rbp-0x88] is a valid argv","[[rbp-0x70]] == NULL || [rbp-0x70] == NULL || [rbp-0x70] is a valid envp"]},{"value":940127,"effect":"execve(\"/bin/sh\", r10, [rbp-0x70])","constraints":["[r10] == NULL || r10 == NULL || r10 is a valid argv","[[rbp-0x70]] == NULL || [rbp-0x70] == NULL || [rbp-0x70] is a valid envp"]},{"value":940131,"effect":"execve(\"/bin/sh\", r10, rdx)","constraints":["[r10] == NULL || r10 == NULL || r10 is a valid argv","[rdx] == NULL || rdx == NULL || rdx is a valid envp"]},{"value":1090444,"effect":"execve(\"/bin/sh\", rsp+0x70, environ)","constraints":["[rsp+0x70] == NULL || {[rsp+0x70], [rsp+0x78], [rsp+0x80], [rsp+0x88], ...} is a valid argv"]},{"value":1090456,"effect":"execve(\"/bin/sh\", rsi, [rax])","constraints":["[rsi] == NULL || rsi == NULL || rsi is a valid argv","[[rax]] == NULL || [rax] == NULL || [rax] is a valid envp"]}]
$ one_gadget spec/data/libc-2.27-b417c0ba7cc5cf06d1d1bed6652cedb9253c60d0.so -o json --near exit,mkdir
[{"near":"exit","near_offset":274720,"gadgets":[{"value":324286,"effect":"execve(\"/bin/sh\", rsp+0x40, environ)","constraints":["rsp & 0xf == 0","writable: rsp+0x50","rcx == NULL || {rcx, \"-c\", r12, NULL} is a valid argv"]},{"value":324293,"effect":"execve(\"/bin/sh\", rsp+0x40, environ)","constraints":["rsp & 0xf == 0","writable: rsp+0x50","rcx == NULL || {rcx, rax, r12, NULL} is a valid argv"]},{"value":324386,"effect":"execve(\"/bin/sh\", rsp+0x40, environ)","constraints":["[rsp+0x40] == NULL || {[rsp+0x40], [rsp+0x48], [rsp+0x50], [rsp+0x58], ...} is a valid argv"]},{"value":1090444,"effect":"execve(\"/bin/sh\", rsp+0x70, environ)","constraints":["[rsp+0x70] == NULL || {[rsp+0x70], [rsp+0x78], [rsp+0x80], [rsp+0x88], ...} is a valid argv"]}]},{"near":"mkdir","near_offset":1113008,"gadgets":[{"value":1090444,"effect":"execve(\"/bin/sh\", rsp+0x70, environ)","constraints":["[rsp+0x70] == NULL || {[rsp+0x70], [rsp+0x78], [rsp+0x80], [rsp+0x88], ...} is a valid argv"]},{"value":324386,"effect":"execve(\"/bin/sh\", rsp+0x40, environ)","constraints":["[rsp+0x40] == NULL || {[rsp+0x40], [rsp+0x48], [rsp+0x50], [rsp+0x58], ...} is a valid argv"]},{"value":324293,"effect":"execve(\"/bin/sh\", rsp+0x40, environ)","constraints":["rsp & 0xf == 0","writable: rsp+0x50","rcx == NULL || {rcx, rax, r12, NULL} is a valid argv"]},{"value":324286,"effect":"execve(\"/bin/sh\", rsp+0x40, environ)","constraints":["rsp & 0xf == 0","writable: rsp+0x50","rcx == NULL || {rcx, \"-c\", r12, NULL} is a valid argv"]}]}]

Also confirmed the output can be parsed by Python3:

$ one_gadget spec/data/libc-2.27-b417c0ba7cc5cf06d1d1bed6652cedb9253c60d0.so -o json -l1 | python3  -c 'print(__import__("json").loads(__import__("sys").stdin.read()))'
[{'value': 324279, 'effect': 'execve("/bin/sh", rsp+0x40, environ)', 'constraints': ['rsp & 0xf == 0', 'writable: rsp+0x50', '{"sh", "-c", r12, NULL} is a valid argv']}, {'value': 324286, 'effect': 'execve("/bin/sh", rsp+0x40, environ)', 'constraints': ['rsp & 0xf == 0', 'writable: rsp+0x50', 'rcx == NULL || {rcx, "-c", r12, NULL} is a valid argv']}, {'value': 324293, 'effect': 'execve("/bin/sh", rsp+0x40, environ)', 'constraints': ['rsp & 0xf == 0', 'writable: rsp+0x50', 'rcx == NULL || {rcx, rax, r12, NULL} is a valid argv']}, {'value': 324386, 'effect': 'execve("/bin/sh", rsp+0x40, environ)', 'constraints': ['[rsp+0x40] == NULL || {[rsp+0x40], [rsp+0x48], [rsp+0x50], [rsp+0x58], ...} is a valid argv']}, {'value': 939679, 'effect': 'execve("/bin/sh", r14, r12)', 'constraints': ['[r14] == NULL || r14 == NULL || r14 is a valid argv', '[r12] == NULL || r12 == NULL || r12 is a valid envp']}, {'value': 940120, 'effect': 'execve("/bin/sh", [rbp-0x88], [rbp-0x70])', 'constraints': ['[[rbp-0x88]] == NULL || [rbp-0x88] == NULL || [rbp-0x88] is a valid argv', '[[rbp-0x70]] == NULL || [rbp-0x70] == NULL || [rbp-0x70] is a valid envp']}, {'value': 940127, 'effect': 'execve("/bin/sh", r10, [rbp-0x70])', 'constraints': ['[r10] == NULL || r10 == NULL || r10 is a valid argv', '[[rbp-0x70]] == NULL || [rbp-0x70] == NULL || [rbp-0x70] is a valid envp']}, {'value': 940131, 'effect': 'execve("/bin/sh", r10, rdx)', 'constraints': ['[r10] == NULL || r10 == NULL || r10 is a valid argv', '[rdx] == NULL || rdx == NULL || rdx is a valid envp']}, {'value': 1090444, 'effect': 'execve("/bin/sh", rsp+0x70, environ)', 'constraints': ['[rsp+0x70] == NULL || {[rsp+0x70], [rsp+0x78], [rsp+0x80], [rsp+0x88], ...} is a valid argv']}, {'value': 1090456, 'effect': 'execve("/bin/sh", rsi, [rax])', 'constraints': ['[rsi] == NULL || rsi == NULL || rsi is a valid argv', '[[rax]] == NULL || [rax] == NULL || [rax] is a valid envp']}]
 one_gadget spec/data/libc-2.27-b417c0ba7cc5cf06d1d1bed6652cedb9253c60d0.so -o json --near exit,mkdir | python3  -c 'print(__import__("json").loads(__import__("sys").stdin.read()))'
[{'near': 'exit', 'near_offset': 274720, 'gadgets': [{'value': 324286, 'effect': 'execve("/bin/sh", rsp+0x40, environ)', 'constraints': ['rsp & 0xf == 0', 'writable: rsp+0x50', 'rcx == NULL || {rcx, "-c", r12, NULL} is a valid argv']}, {'value': 324293, 'effect': 'execve("/bin/sh", rsp+0x40, environ)', 'constraints': ['rsp & 0xf == 0', 'writable: rsp+0x50', 'rcx == NULL || {rcx, rax, r12, NULL} is a valid argv']}, {'value': 324386, 'effect': 'execve("/bin/sh", rsp+0x40, environ)', 'constraints': ['[rsp+0x40] == NULL || {[rsp+0x40], [rsp+0x48], [rsp+0x50], [rsp+0x58], ...} is a valid argv']}, {'value': 1090444, 'effect': 'execve("/bin/sh", rsp+0x70, environ)', 'constraints': ['[rsp+0x70] == NULL || {[rsp+0x70], [rsp+0x78], [rsp+0x80], [rsp+0x88], ...} is a valid argv']}]}, {'near': 'mkdir', 'near_offset': 1113008, 'gadgets': [{'value': 1090444, 'effect': 'execve("/bin/sh", rsp+0x70, environ)', 'constraints': ['[rsp+0x70] == NULL || {[rsp+0x70], [rsp+0x78], [rsp+0x80], [rsp+0x88], ...} is a valid argv']}, {'value': 324386, 'effect': 'execve("/bin/sh", rsp+0x40, environ)', 'constraints': ['[rsp+0x40] == NULL || {[rsp+0x40], [rsp+0x48], [rsp+0x50], [rsp+0x58], ...} is a valid argv']}, {'value': 324293, 'effect': 'execve("/bin/sh", rsp+0x40, environ)', 'constraints': ['rsp & 0xf == 0', 'writable: rsp+0x50', 'rcx == NULL || {rcx, rax, r12, NULL} is a valid argv']}, {'value': 324286, 'effect': 'execve("/bin/sh", rsp+0x40, environ)', 'constraints': ['rsp & 0xf == 0', 'writable: rsp+0x50', 'rcx == NULL || {rcx, "-c", r12, NULL} is a valid argv']}]}]

Fixes #224

@david942j david942j merged commit 6946c1b into master Oct 4, 2024
7 checks passed
@david942j david942j deleted the json branch October 4, 2024 17:15
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.

Output in JSON format
1 participant