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

libafl_frida: Make cmplog work on x64 #1713

Merged
merged 6 commits into from
Jan 19, 2024

Conversation

expend20
Copy link
Contributor

@expend20 expend20 commented Dec 5, 2023

#823

Currently it stuck on not producing expected values to the input, despite call to __libafl_targets_cmplog_instructions seems correct at first glance

libafl_frida/Cargo.toml Outdated Show resolved Hide resolved
@tokatoka
Copy link
Member

tokatoka commented Dec 5, 2023

I tried this on linux. and from what I observed, the recorded metadata is not correct.

For example, I changed the harness (in frida_libpng) to

HARNESS_EXPORTS extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data,
                                                      size_t         size) {
  if (size >= 8 && *(uint32_t *)data == 0x11112222) { abort(); }
  if (size < kPngHeaderSize) { return 0; }

  return 0;
}

but then the recorded metadata is

 meta: Some(CmpValuesMetadata { list: [U64((474e5089, da))] })

@domenukk
Copy link
Member

domenukk commented Dec 5, 2023

Did you consider https://github.com/iximeow/yaxpeax-x86 ? If we do need more dependencies we might as well go with something that's potentially cross architecture?

@expend20
Copy link
Contributor Author

expend20 commented Dec 19, 2023

I tried this on linux. and from what I observed, the recorded metadata is not correct

could you try again please? @tokatoka

Did you consider https://github.com/iximeow/yaxpeax-x86 ? If we do need more dependencies we might as well go with something that's potentially cross architecture?

Thanks for the suggestion @domenukk 👍 however, I also need to generate instructions with registers taken from disassembly. Frida InstructionWriter lacks support for lower registers and dynasm seems not a good fit for it. iced seems a perfect fit since it can do both, decoding and encoding at the same time. Never the less, I completely understand your request not to inject additional depencies and I'm happy to explore any other options, if any.

@tokatoka
Copy link
Member

i'll check this soon

@tokatoka
Copy link
Member

tokatoka commented Dec 29, 2023

but do you have any idea for resolving register collision?
if not i think we can simply handle every corner cases.

because now you hide the register name behind arg1, arg2, ... , so it would be not too hard to enumerate every cases

@expend20
Copy link
Contributor Author

expend20 commented Dec 29, 2023 via email

@tokatoka
Copy link
Member

no i haven't got a machine to test yet 😅

@domenukk domenukk marked this pull request as draft January 1, 2024 14:32
@domenukk
Copy link
Member

domenukk commented Jan 1, 2024

This is still a draft, right?

@expend20
Copy link
Contributor Author

expend20 commented Jan 1, 2024

This is still a draft, right?

yeah, need to craft fuzz targets in assembly to cover all the edge cases of instrumentation

@tokatoka
Copy link
Member

tokatoka commented Jan 2, 2024

works for me 👍

@tokatoka
Copy link
Member

tokatoka commented Jan 3, 2024

look good.
ready to merge?

@expend20
Copy link
Contributor Author

expend20 commented Jan 4, 2024

ready to merge?

I'm pretty close to removing the draft mark, just getting some bugs with more testing

@domenukk
Copy link
Member

domenukk commented Jan 4, 2024

Some tiny clippy nags remain:

error: casting `u64` to `i64` may wrap around the value
   --> libafl_frida/src/cmplog_rt.rs:671:17
    |
671 |                 instruction.memory_displacement64() as i64,
    |                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#cast_possible_wrap
note: the lint level is defined here
   --> libafl_frida/src/lib.rs:10:9
    |
10  | #![deny(clippy::pedantic)]
    |         ^^^^^^^^^^^^^^^^
    = note: `#[deny(clippy::cast_possible_wrap)]` implied by `#[deny(clippy::pedantic)]`

error: could not compile `libafl_frida` (lib test) due to 1 previous error

/edit: removed unrelated warnings from this comment.
For the i64, either use try_from, or if speed is an issue here, allow it with #[allow(clippy:...)] (and maybe add a debug_assert)

@expend20
Copy link
Contributor Author

expend20 commented Jan 4, 2024

Some tiny clippy nags remain:

yeah I'll fix that, I also have some tests which are not yet commited but failing on my machine

For the i64, either use try_from, or if speed is an issue here, allow it with #[allow(clippy:...)] (and maybe add a debug_assert)

in that specific case I need to cast unsigned to signed and try_ gives me a panic, so I removed it

PS: bear with me guys, I'll remove Draft mark, squash commits and let you know explicitly when it's ready for final review

@domenukk
Copy link
Member

domenukk commented Jan 4, 2024

Sorry, just tried to be helpful :)
Just add a clippy allow in this case (and maybe a comment)

@domenukk
Copy link
Member

domenukk commented Jan 4, 2024

No need to squash btw, we squash everything when we merge anyway

@expend20 expend20 changed the title DRAFT: POC attempt to make cmplog work on x64 POC attempt to make cmplog work on x64 Jan 16, 2024
windows POC seems working

unix POC seems working :)

* no register collisions
* rsp-related ref support

iced optional dep

iced depends on cmplog

warnings

one more warning

comments cleanup

ci unbreak

rebase windows unbreak

rebase unix unbreak

unix only

fmt check

clang formatting

clang formatting again

make clippy happy

formatting

double import

windows unbreak

hashmap is conditional

leftover definition

tutorial related formatter

review fixes

comments

.asm fuzz targets for cmplog on Windows

more tests

rip-relative reference support without index register form

proper ignore rip-related references and ignore 8 bit comparisons

another try_into packing
@expend20
Copy link
Contributor Author

Should be ready for final review now (with the exception of iced dependency). cc @tokatoka @domenukk

@expend20 expend20 marked this pull request as ready for review January 16, 2024 03:40
@domenukk domenukk requested a review from s1341 January 18, 2024 17:56
@domenukk
Copy link
Member

domenukk commented Jan 18, 2024

Diff in /home/runner/work/LibAFL/LibAFL/libafl_frida/src/cmplog_rt.rs at line 879:
         Self::new()
     }
 }

This will need a cargo +nightly fmt, otherwise looks good! :)

@expend20
Copy link
Contributor Author

This will need a cargo +nightly fmt, otherwise looks good! :)

Hm, I didn't write that code, and it's how it is in main branch, I guess during one of the rebases I enabled clippy, but it's actually disabled in main. Leaving as-is for now.

@expend20
Copy link
Contributor Author

CI is 🟢 and there is no open conversations at the moment ✅

@tokatoka tokatoka merged commit 72c8621 into AFLplusplus:main Jan 19, 2024
26 checks passed
@tokatoka
Copy link
Member

thanks @expend20

@expend20 expend20 deleted the cmplog-windows-x64 branch January 19, 2024 15:15
@domenukk
Copy link
Member

Aweseome! :)

@domenukk domenukk changed the title POC attempt to make cmplog work on x64 libafl_frida: Make cmplog work on x64 Jan 19, 2024
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.

4 participants