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

Draft: add support for unicorn engine #1

Closed
wants to merge 27 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
db13fa3
feat: init
henri2h Dec 14, 2022
dde3d3e
feat: update dep
henri2h Dec 15, 2022
6381be7
feat: make it run
henri2h Dec 15, 2022
d49fa88
feat: print read access
henri2h Dec 15, 2022
706a8ad
feat: properly register memory
henri2h Dec 15, 2022
7307b5b
feat: display block hook and write correctly memory data
henri2h Dec 21, 2022
579295d
fix: properly hook and display memory reads
henri2h Dec 21, 2022
2a57bf1
feat: added location tracker
henri2h Jan 3, 2023
ad3e69e
feat: added edge coverage
henri2h Jan 8, 2023
6a1a60c
feat: startingq hooking the fuzzer
henri2h Jan 8, 2023
79e6ddf
feat: discard state
henri2h Jan 9, 2023
022584a
Fix compilation
andreafioraldi Jan 10, 2023
e98f753
feat: rewritten the emulator to be less verbose and remove code dupli…
henri2h Jan 10, 2023
e09dda7
feat: reduce code duplication (again)
henri2h Jan 19, 2023
9f68628
feat: allow to run emulator only
henri2h Jan 19, 2023
5da5b93
feat: crash on wrong value
henri2h Jan 19, 2023
d3458ef
feat: replace debug and reset EDGES_MAP to 0 at start
henri2h Jan 19, 2023
c826fbf
fix: change generator type
henri2h Jan 19, 2023
71e579c
fix: set MAX_EDGES_NUM and reduce verbosity
henri2h Jan 19, 2023
97539ee
fix: properly initialize input
henri2h Jan 19, 2023
00cbe7f
Fix OOM
andreafioraldi Jan 19, 2023
20d70e3
feat: code re write
henri2h Feb 3, 2023
43f21bf
feat: add multiple architectures
henri2h Feb 3, 2023
e1a0e2c
feat: provide disassembly and fuzz x86 code
henri2h Feb 5, 2023
4a6e7f2
fix: add possibility to fuzz different CPU platform
henri2h Feb 5, 2023
6384d95
feat: change signal
henri2h Feb 6, 2023
cf92098
feat: clean library
henri2h Feb 9, 2023
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
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ members = [
"libafl_tinyinst",
"libafl_sugar",
"libafl_nyx",
"libafl_unicorn",
"libafl_concolic/symcc_runtime",
"libafl_concolic/symcc_libafl",
"libafl_concolic/test/dump_constraints",
Expand Down
12 changes: 12 additions & 0 deletions fuzzers/unicorn/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[package]
name = "unicorn"
version = "0.1.0"
edition = "2021"

[dependencies]
libafl = { path = "../../libafl/" }
libafl_unicorn = { path = "../../libafl_unicorn/" }
libafl_targets = { path = "../../libafl_targets", version = "0.8.2" }

unicorn-engine = "2.0.1"
iced-x86 = "1.18.0"
31 changes: 31 additions & 0 deletions fuzzers/unicorn/libafl_unicorn_test/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
arm64="aarch64-linux-gnu"
arm="arm-linux-gnueabihf"
x64="x86_64-linux-gnu"
assembly_arm64:
$(arm64)-gcc -O2 -S -c foo.c -o foo_arm64.s

binary_arm64:
$(arm64)-as foo_arm64.s -o foo_arm64

assembly_arm:
$(arm)-gcc -O2 -S -c foo.c -o foo_arm.s

binary_arm:
$(arm)-as foo_arm.s -o foo_arm

assembly_x86:
$(x64)-gcc -O2 -S -c foo.c -o foo_x86.s

binary_x86:
$(x64)-as foo_x86.s -o foo_x86

build_arm: assembly_arm binary_arm
build_arm64: assembly_arm64 binary_arm64
build_x86: assembly_x86 binary_x86

clean:
rm foo_*


all: build_arm build_arm64 build_x86
# sudo apt install gcc-arm-linux-gnueabihf gcc-aarch64-linux-gnu
31 changes: 31 additions & 0 deletions fuzzers/unicorn/libafl_unicorn_test/foo.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include <stdint.h>
#define len 2

int main() {
volatile unsigned char a; // = 0x1;
volatile unsigned char b; // = 0x0;
volatile unsigned char c = 0; // The result, so should be initialized at 0;

/*volatile unsigned char f[len];

for(int i = 0; i< len; i++){
f[i] = i;
}*/
c = 0x1;
if (a > b) {
c = 0x2;
if (a > 0x20) {
c = 0x3;
if (a == 0x50) {
c = 0x4;
if (b == 0x24) { c = 0x5; }
}
}
}
/*
a = 0xDE;
b = 0xEA;
c = 0xBE;
*/
return c;
}
Binary file added fuzzers/unicorn/libafl_unicorn_test/foo_arm
Binary file not shown.
62 changes: 62 additions & 0 deletions fuzzers/unicorn/libafl_unicorn_test/foo_arm.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
.arch armv7-a
.fpu vfpv3-d16
.eabi_attribute 28, 1
.eabi_attribute 20, 1
.eabi_attribute 21, 1
.eabi_attribute 23, 3
.eabi_attribute 24, 1
.eabi_attribute 25, 1
.eabi_attribute 26, 2
.eabi_attribute 30, 2
.eabi_attribute 34, 1
.eabi_attribute 18, 4
.file "foo.c"
.text
.section .text.startup,"ax",%progbits
.align 1
.p2align 2,,3
.global main
.syntax unified
.thumb
.thumb_func
.type main, %function
main:
@ args = 0, pretend = 0, frame = 8
@ frame_needed = 0, uses_anonymous_args = 0
@ link register save eliminated.
sub sp, sp, #8
movs r2, #0
movs r3, #1
strb r2, [sp, #7]
strb r3, [sp, #7]
ldrb r2, [sp, #5] @ zero_extendqisi2
ldrb r3, [sp, #6] @ zero_extendqisi2
cmp r2, r3
bls .L3
movs r3, #2
strb r3, [sp, #7]
ldrb r3, [sp, #5] @ zero_extendqisi2
cmp r3, #32
bls .L3
movs r3, #3
strb r3, [sp, #7]
ldrb r3, [sp, #5] @ zero_extendqisi2
cmp r3, #80
beq .L7
.L3:
ldrb r0, [sp, #7] @ zero_extendqisi2
add sp, sp, #8
@ sp needed
bx lr
.L7:
movs r3, #4
strb r3, [sp, #7]
ldrb r3, [sp, #6] @ zero_extendqisi2
cmp r3, #36
itt eq
moveq r3, #5
strbeq r3, [sp, #7]
b .L3
.size main, .-main
.ident "GCC: (Ubuntu 12.2.0-3ubuntu1) 12.2.0"
.section .note.GNU-stack,"",%progbits
Binary file added fuzzers/unicorn/libafl_unicorn_test/foo_arm64
Binary file not shown.
56 changes: 56 additions & 0 deletions fuzzers/unicorn/libafl_unicorn_test/foo_arm64.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
.arch armv8-a
.file "foo.c"
.text
.section .text.startup,"ax",@progbits
.align 2
.p2align 4,,11
.global main
.type main, %function
main:
.LFB0:
.cfi_startproc
sub sp, sp, #16
.cfi_def_cfa_offset 16
mov w0, 1
strb wzr, [sp, 15]
strb w0, [sp, 15]
ldrb w1, [sp, 13]
ldrb w0, [sp, 14]
and w0, w0, 255
cmp w0, w1, uxtb
bcs .L3
mov w0, 2
strb w0, [sp, 15]
ldrb w0, [sp, 13]
and w0, w0, 255
cmp w0, 32
bls .L3
mov w0, 3
strb w0, [sp, 15]
ldrb w0, [sp, 13]
and w0, w0, 255
cmp w0, 80
beq .L7
.L3:
ldrb w0, [sp, 15]
add sp, sp, 16
.cfi_remember_state
.cfi_def_cfa_offset 0
and w0, w0, 255
ret
.L7:
.cfi_restore_state
mov w0, 4
strb w0, [sp, 15]
ldrb w0, [sp, 14]
and w0, w0, 255
cmp w0, 36
bne .L3
mov w0, 5
strb w0, [sp, 15]
b .L3
.cfi_endproc
.LFE0:
.size main, .-main
.ident "GCC: (Ubuntu 12.2.0-3ubuntu1) 12.2.0"
.section .note.GNU-stack,"",@progbits
Binary file added fuzzers/unicorn/libafl_unicorn_test/foo_x86
Binary file not shown.
55 changes: 55 additions & 0 deletions fuzzers/unicorn/libafl_unicorn_test/foo_x86.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
.file "foo.c"
.text
.section .text.startup,"ax",@progbits
.p2align 4
.globl main
.type main, @function
main:
.LFB0:
.cfi_startproc
endbr64
movb $0, -1(%rsp)
movb $1, -1(%rsp)
movzbl -3(%rsp), %eax
movzbl -2(%rsp), %edx
cmpb %al, %dl
jnb .L3
movb $2, -1(%rsp)
movzbl -3(%rsp), %eax
cmpb $32, %al
jbe .L3
movb $3, -1(%rsp)
movzbl -3(%rsp), %eax
cmpb $80, %al
je .L6
.L3:
movzbl -1(%rsp), %eax
ret
.L6:
movb $4, -1(%rsp)
movzbl -2(%rsp), %eax
cmpb $36, %al
jne .L3
movb $5, -1(%rsp)
jmp .L3
.cfi_endproc
.LFE0:
.size main, .-main
.ident "GCC: (Ubuntu 12.2.0-3ubuntu1) 12.2.0"
.section .note.GNU-stack,"",@progbits
.section .note.gnu.property,"a"
.align 8
.long 1f - 0f
.long 4f - 1f
.long 5
0:
.string "GNU"
1:
.align 8
.long 0xc0000002
.long 3f - 2f
2:
.long 0x3
3:
.align 8
4:
Loading