Mercurial > dropbear
annotate fuzz-common.c @ 1377:d4cc85e6c569 fuzz
rearrange, all fuzzers now call fuzzer_set_input()
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Thu, 25 May 2017 22:21:49 +0800 |
parents | 9891bc31a1b3 |
children | f03cfe9c76ac |
rev | line source |
---|---|
1348 | 1 #include "includes.h" |
2 | |
3 #include "includes.h" | |
4 #include "fuzz.h" | |
5 #include "dbutil.h" | |
6 #include "runopts.h" | |
1353 | 7 #include "crypto_desc.h" |
8 #include "session.h" | |
1356
3677a510f545
add wrapfd. improve fuzzer in makefile
Matt Johnston <matt@ucc.asn.au>
parents:
1353
diff
changeset
|
9 #include "dbrandom.h" |
3677a510f545
add wrapfd. improve fuzzer in makefile
Matt Johnston <matt@ucc.asn.au>
parents:
1353
diff
changeset
|
10 #include "fuzz-wrapfd.h" |
1348 | 11 |
12 struct dropbear_fuzz_options fuzz; | |
13 | |
1373
9891bc31a1b3
fuzzers disable logging by default
Matt Johnston <matt@ucc.asn.au>
parents:
1369
diff
changeset
|
14 static void fuzz_dropbear_log(int UNUSED(priority), const char* format, va_list param); |
1348 | 15 static void load_fixed_hostkeys(void); |
16 | |
1369 | 17 void common_setup_fuzzer(void) { |
1348 | 18 fuzz.fuzzing = 1; |
1357 | 19 fuzz.wrapfds = 1; |
1356
3677a510f545
add wrapfd. improve fuzzer in makefile
Matt Johnston <matt@ucc.asn.au>
parents:
1353
diff
changeset
|
20 fuzz.input = m_malloc(sizeof(buffer)); |
1373
9891bc31a1b3
fuzzers disable logging by default
Matt Johnston <matt@ucc.asn.au>
parents:
1369
diff
changeset
|
21 _dropbear_log = fuzz_dropbear_log; |
1350 | 22 crypto_init(); |
1348 | 23 } |
24 | |
1356
3677a510f545
add wrapfd. improve fuzzer in makefile
Matt Johnston <matt@ucc.asn.au>
parents:
1353
diff
changeset
|
25 int fuzzer_set_input(const uint8_t *Data, size_t Size) { |
3677a510f545
add wrapfd. improve fuzzer in makefile
Matt Johnston <matt@ucc.asn.au>
parents:
1353
diff
changeset
|
26 |
3677a510f545
add wrapfd. improve fuzzer in makefile
Matt Johnston <matt@ucc.asn.au>
parents:
1353
diff
changeset
|
27 fuzz.input->data = (unsigned char*)Data; |
3677a510f545
add wrapfd. improve fuzzer in makefile
Matt Johnston <matt@ucc.asn.au>
parents:
1353
diff
changeset
|
28 fuzz.input->size = Size; |
3677a510f545
add wrapfd. improve fuzzer in makefile
Matt Johnston <matt@ucc.asn.au>
parents:
1353
diff
changeset
|
29 fuzz.input->len = Size; |
3677a510f545
add wrapfd. improve fuzzer in makefile
Matt Johnston <matt@ucc.asn.au>
parents:
1353
diff
changeset
|
30 fuzz.input->pos = 0; |
3677a510f545
add wrapfd. improve fuzzer in makefile
Matt Johnston <matt@ucc.asn.au>
parents:
1353
diff
changeset
|
31 |
1358
6b89eb92f872
glaring wrapfd problems fixed
Matt Johnston <matt@ucc.asn.au>
parents:
1357
diff
changeset
|
32 memset(&ses, 0x0, sizeof(ses)); |
6b89eb92f872
glaring wrapfd problems fixed
Matt Johnston <matt@ucc.asn.au>
parents:
1357
diff
changeset
|
33 memset(&svr_ses, 0x0, sizeof(svr_ses)); |
1377
d4cc85e6c569
rearrange, all fuzzers now call fuzzer_set_input()
Matt Johnston <matt@ucc.asn.au>
parents:
1373
diff
changeset
|
34 wrapfd_setup(); |
1356
3677a510f545
add wrapfd. improve fuzzer in makefile
Matt Johnston <matt@ucc.asn.au>
parents:
1353
diff
changeset
|
35 |
1369 | 36 fuzz_seed(); |
1356
3677a510f545
add wrapfd. improve fuzzer in makefile
Matt Johnston <matt@ucc.asn.au>
parents:
1353
diff
changeset
|
37 |
3677a510f545
add wrapfd. improve fuzzer in makefile
Matt Johnston <matt@ucc.asn.au>
parents:
1353
diff
changeset
|
38 return DROPBEAR_SUCCESS; |
3677a510f545
add wrapfd. improve fuzzer in makefile
Matt Johnston <matt@ucc.asn.au>
parents:
1353
diff
changeset
|
39 } |
3677a510f545
add wrapfd. improve fuzzer in makefile
Matt Johnston <matt@ucc.asn.au>
parents:
1353
diff
changeset
|
40 |
1373
9891bc31a1b3
fuzzers disable logging by default
Matt Johnston <matt@ucc.asn.au>
parents:
1369
diff
changeset
|
41 static void fuzz_dropbear_log(int UNUSED(priority), const char* format, va_list param) { |
9891bc31a1b3
fuzzers disable logging by default
Matt Johnston <matt@ucc.asn.au>
parents:
1369
diff
changeset
|
42 |
9891bc31a1b3
fuzzers disable logging by default
Matt Johnston <matt@ucc.asn.au>
parents:
1369
diff
changeset
|
43 char printbuf[1024]; |
9891bc31a1b3
fuzzers disable logging by default
Matt Johnston <matt@ucc.asn.au>
parents:
1369
diff
changeset
|
44 |
9891bc31a1b3
fuzzers disable logging by default
Matt Johnston <matt@ucc.asn.au>
parents:
1369
diff
changeset
|
45 #if DEBUG_TRACE |
9891bc31a1b3
fuzzers disable logging by default
Matt Johnston <matt@ucc.asn.au>
parents:
1369
diff
changeset
|
46 if (debug_trace) { |
9891bc31a1b3
fuzzers disable logging by default
Matt Johnston <matt@ucc.asn.au>
parents:
1369
diff
changeset
|
47 vsnprintf(printbuf, sizeof(printbuf), format, param); |
9891bc31a1b3
fuzzers disable logging by default
Matt Johnston <matt@ucc.asn.au>
parents:
1369
diff
changeset
|
48 fprintf(stderr, "%s\n", printbuf); |
9891bc31a1b3
fuzzers disable logging by default
Matt Johnston <matt@ucc.asn.au>
parents:
1369
diff
changeset
|
49 } |
9891bc31a1b3
fuzzers disable logging by default
Matt Johnston <matt@ucc.asn.au>
parents:
1369
diff
changeset
|
50 #endif |
9891bc31a1b3
fuzzers disable logging by default
Matt Johnston <matt@ucc.asn.au>
parents:
1369
diff
changeset
|
51 } |
1356
3677a510f545
add wrapfd. improve fuzzer in makefile
Matt Johnston <matt@ucc.asn.au>
parents:
1353
diff
changeset
|
52 |
1348 | 53 void svr_setup_fuzzer(void) { |
54 struct passwd *pw; | |
55 | |
56 common_setup_fuzzer(); | |
1353 | 57 |
58 _dropbear_exit = svr_dropbear_exit; | |
1348 | 59 |
60 char *argv[] = { | |
61 "-E", | |
62 }; | |
63 | |
64 int argc = sizeof(argv) / sizeof(*argv); | |
65 svr_getopts(argc, argv); | |
66 | |
67 /* user lookups might be slow, cache it */ | |
68 pw = getpwuid(getuid()); | |
69 dropbear_assert(pw); | |
70 fuzz.pw_name = m_strdup(pw->pw_name); | |
71 fuzz.pw_dir = m_strdup(pw->pw_dir); | |
72 fuzz.pw_shell = m_strdup(pw->pw_shell); | |
73 fuzz.pw_passwd = m_strdup("!!zzznope"); | |
74 | |
75 load_fixed_hostkeys(); | |
76 } | |
77 | |
78 static void load_fixed_hostkeys(void) { | |
79 #include "fuzz-hostkeys.c" | |
80 | |
81 buffer *b = buf_new(3000); | |
82 enum signkey_type type; | |
83 | |
84 TRACE(("load fixed hostkeys")) | |
85 | |
86 svr_opts.hostkey = new_sign_key(); | |
87 | |
88 buf_setlen(b, 0); | |
89 buf_putbytes(b, keyr, keyr_len); | |
90 buf_setpos(b, 0); | |
91 type = DROPBEAR_SIGNKEY_RSA; | |
92 if (buf_get_priv_key(b, svr_opts.hostkey, &type) == DROPBEAR_FAILURE) { | |
93 dropbear_exit("failed fixed rsa hostkey"); | |
94 } | |
95 | |
96 buf_setlen(b, 0); | |
97 buf_putbytes(b, keyd, keyd_len); | |
98 buf_setpos(b, 0); | |
99 type = DROPBEAR_SIGNKEY_DSS; | |
100 if (buf_get_priv_key(b, svr_opts.hostkey, &type) == DROPBEAR_FAILURE) { | |
101 dropbear_exit("failed fixed dss hostkey"); | |
102 } | |
103 | |
104 buf_setlen(b, 0); | |
105 buf_putbytes(b, keye, keye_len); | |
106 buf_setpos(b, 0); | |
107 type = DROPBEAR_SIGNKEY_ECDSA_NISTP256; | |
108 if (buf_get_priv_key(b, svr_opts.hostkey, &type) == DROPBEAR_FAILURE) { | |
109 dropbear_exit("failed fixed ecdsa hostkey"); | |
110 } | |
111 | |
112 buf_free(b); | |
113 } | |
114 | |
1357 | 115 void fuzz_kex_fakealgos(void) { |
116 ses.newkeys->recv.crypt_mode = &dropbear_mode_none; | |
117 } |