AFLplusplus / LibAFL

Advanced Fuzzing Library - Slot your Fuzzer together in Rust! Scales across cores and machines. For Windows, Android, MacOS, Linux, no_std, ...
Other
2.03k stars 319 forks source link

Frida Windows Example in CI/Makefile.toml #576

Closed domenukk closed 2 years ago

domenukk commented 2 years ago

We now have a Makefile.toml that can build and run a frida-based fuzzer on Unix. https://github.com/AFLplusplus/LibAFL/blob/acba89b92a4b3e2478d87ee6ef489c07fbb5d20c/fuzzers/frida_libpng/Makefile.toml It would be great to also add targets to support. Windows For Win, in should be fine to download a precompiled binary, then run libafl frida (I guess)

syheliel commented 2 years ago

I'm currently working on it and have completed the download logic, one error appears:

......
successful message
......
warning: cc1.exe: sorry, unimplemented: 64-bit mode not compiled in
failed to run custom build command for `libafl_targets v0.7.1 

 error occurred: Command "gcc.exe" "-O3" "-ffunction-sections" "-fdata-sections" "-g" "-fno-omit-frame-pointer"
 "-m64" "-Wall" "-Wextra" "-DSANCOV_CMPLOG=1" "-DCMP_MAP_SIZE=65536" "-DCMPLOG_MAP_W=65536"
 "-DCMPLOG_MAP_H=32" "-o" "xxx\\LibAFL\\fuzzers\\libfuzzer_libpng\\target\\release\\build\\libafl_targets-2843fa410fa3622e\\out\\src\\sancov_cmp.o"
 "-c" "src\\sancov_cmp.c" with args "gcc.exe" did not execute successfully (status code exit code: 1).

Is it an environmental problem on my PC?

syheliel commented 2 years ago

The previous error is caused by using MinGW for i386. After fixing it, there is another error. Maybe we should write some documentation for the basic environment setting on windows 😢 .

warning: `libafl` (lib) generated 8 warnings
   Compiling frida-gum-sys v0.3.3
error[E0587]: type has conflicting packed and align representation hints
     --> E:\git\LibAFL\fuzzers\frida_libpng\target\release\build\frida-gum-sys-a24487c0c49b830c\out/bindings.rs:28665:1
      |
28665 | / pub struct _JUMP_BUFFER {
28666 | |     pub Frame: ::std::os::raw::c_ulonglong,
28667 | |     pub Rbx: ::std::os::raw::c_ulonglong,
28668 | |     pub Rsp: ::std::os::raw::c_ulonglong,
...     |
28689 | |     pub Xmm15: SETJMP_FLOAT128,
28690 | | }
      | |_^

For more information about this error, try `rustc --explain E0587`.
The following warnings were emitted during compilation:

warning: Frida gum devkit not found, downloading from https://github.com/frida/frida/releases/download/15.1.17/frida-gum-devkit-15.1.17-windows-x86_64.tar.xz...
warning: In file included from event_sink.h:9,
warning:                  from event_sink.c:7:
warning: E:\git\LibAFL\fuzzers\frida_libpng\target\release\build\frida-gum-sys-a24487c0c49b830c\out/frida-gum.h:5: warning: ignoring '#pragma comment ' [-Wunknown-pragmas]       
warning:     5 | #pragma comment(lib, "frida-gum.lib")
warning:       |
warning: E:\git\LibAFL\fuzzers\frida_libpng\target\release\build\frida-gum-sys-a24487c0c49b830c\out/frida-gum.h:7: warning: ignoring '#pragma comment ' [-Wunknown-pragmas]       
warning:     7 | #pragma comment(lib, "dnsapi.lib")
warning:       |
warning: E:\git\LibAFL\fuzzers\frida_libpng\target\release\build\frida-gum-sys-a24487c0c49b830c\out/frida-gum.h:8: warning: ignoring '#pragma comment ' [-Wunknown-pragmas]       
warning:     8 | #pragma comment(lib, "iphlpapi.lib")
warning:       |
warning: E:\git\LibAFL\fuzzers\frida_libpng\target\release\build\frida-gum-sys-a24487c0c49b830c\out/frida-gum.h:9: warning: ignoring '#pragma comment ' [-Wunknown-pragmas]       
warning:     9 | #pragma comment(lib, "psapi.lib")
warning:       |
warning: E:\git\LibAFL\fuzzers\frida_libpng\target\release\build\frida-gum-sys-a24487c0c49b830c\out/frida-gum.h:10: warning: ignoring '#pragma comment ' [-Wunknown-pragmas]      
warning:    10 | #pragma comment(lib, "winmm.lib")
warning:       |
warning: E:\git\LibAFL\fuzzers\frida_libpng\target\release\build\frida-gum-sys-a24487c0c49b830c\out/frida-gum.h:11: warning: ignoring '#pragma comment ' [-Wunknown-pragmas]      
warning:    11 | #pragma comment(lib, "ws2_32.lib")
warning:       |
warning: In file included from invocation_listener.h:9,
warning:                  from invocation_listener.c:7:
warning: E:\git\LibAFL\fuzzers\frida_libpng\target\release\build\frida-gum-sys-a24487c0c49b830c\out/frida-gum.h:5: warning: ignoring '#pragma comment ' [-Wunknown-pragmas]       
warning:     5 | #pragma comment(lib, "frida-gum.lib")
warning:       |
warning: E:\git\LibAFL\fuzzers\frida_libpng\target\release\build\frida-gum-sys-a24487c0c49b830c\out/frida-gum.h:7: warning: ignoring '#pragma comment ' [-Wunknown-pragmas]       
warning:     7 | #pragma comment(lib, "dnsapi.lib")
warning:       |
warning: E:\git\LibAFL\fuzzers\frida_libpng\target\release\build\frida-gum-sys-a24487c0c49b830c\out/frida-gum.h:8: warning: ignoring '#pragma comment ' [-Wunknown-pragmas]       
warning:     8 | #pragma comment(lib, "iphlpapi.lib")
warning:       |
warning: E:\git\LibAFL\fuzzers\frida_libpng\target\release\build\frida-gum-sys-a24487c0c49b830c\out/frida-gum.h:9: warning: ignoring '#pragma comment ' [-Wunknown-pragmas]       
warning:     9 | #pragma comment(lib, "psapi.lib")
warning:       |
warning: E:\git\LibAFL\fuzzers\frida_libpng\target\release\build\frida-gum-sys-a24487c0c49b830c\out/frida-gum.h:10: warning: ignoring '#pragma comment ' [-Wunknown-pragmas]      
warning:    10 | #pragma comment(lib, "winmm.lib")
warning:       |
warning: E:\git\LibAFL\fuzzers\frida_libpng\target\release\build\frida-gum-sys-a24487c0c49b830c\out/frida-gum.h:11: warning: ignoring '#pragma comment ' [-Wunknown-pragmas]      
warning:    11 | #pragma comment(lib, "ws2_32.lib")
warning:       |

error: could not compile `frida-gum-sys` due to previous error
andreafioraldi commented 2 years ago

use clang

syheliel commented 2 years ago

@andreafioraldi Is it the solution to the first cc1.exe error? It has been solved by installing mingw-w64-x86_64-toolchain in msys2. And the second error seems to be related to frida installation? Anyway, here is my gcc and clang's version. gcc --version

gcc.exe (Rev10, Built by MSYS2 project) 11.2.0

clang --version

clang version 13.0.1
Target: x86_64-w64-windows-gnu
Thread model: posix
InstalledDir: E:/msys64/mingw64/bin
tokatoka commented 2 years ago

You can simply install llvm (https://github.com/llvm/llvm-project/releases) and build it on your powershell on windows. I tried msys2 before but it just messed things up. plus ci is not for msys2 env either

tokatoka commented 2 years ago

IMO, the PUT does not have to be libpng... I did not tell the makefile.toml to build frida on windows because I can't figure out a CUI solution to build it. (I had to open visual studio and select some configs for it). It could be anything easier to build, or more simply, a precompiled dll file.