Mercurial > dropbear
annotate fuzz-common.c @ 1374:4b1a807a3188 fuzz
Just use memset, it should'be be optimised out in a separate file
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Thu, 25 May 2017 22:19:46 +0800 |
parents | 9891bc31a1b3 |
children | d4cc85e6c569 |
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)); |
6b89eb92f872
glaring wrapfd problems fixed
Matt Johnston <matt@ucc.asn.au>
parents:
1357
diff
changeset
|
34 |
1356
3677a510f545
add wrapfd. improve fuzzer in makefile
Matt Johnston <matt@ucc.asn.au>
parents:
1353
diff
changeset
|
35 // get prefix. input format is |
3677a510f545
add wrapfd. improve fuzzer in makefile
Matt Johnston <matt@ucc.asn.au>
parents:
1353
diff
changeset
|
36 // string prefix |
1357 | 37 // uint32 wrapfd seed |
1356
3677a510f545
add wrapfd. improve fuzzer in makefile
Matt Johnston <matt@ucc.asn.au>
parents:
1353
diff
changeset
|
38 // ... to be extended later |
3677a510f545
add wrapfd. improve fuzzer in makefile
Matt Johnston <matt@ucc.asn.au>
parents:
1353
diff
changeset
|
39 // [bytes] ssh input stream |
3677a510f545
add wrapfd. improve fuzzer in makefile
Matt Johnston <matt@ucc.asn.au>
parents:
1353
diff
changeset
|
40 |
3677a510f545
add wrapfd. improve fuzzer in makefile
Matt Johnston <matt@ucc.asn.au>
parents:
1353
diff
changeset
|
41 // be careful to avoid triggering buffer.c assertions |
3677a510f545
add wrapfd. improve fuzzer in makefile
Matt Johnston <matt@ucc.asn.au>
parents:
1353
diff
changeset
|
42 if (fuzz.input->len < 8) { |
3677a510f545
add wrapfd. improve fuzzer in makefile
Matt Johnston <matt@ucc.asn.au>
parents:
1353
diff
changeset
|
43 return DROPBEAR_FAILURE; |
3677a510f545
add wrapfd. improve fuzzer in makefile
Matt Johnston <matt@ucc.asn.au>
parents:
1353
diff
changeset
|
44 } |
3677a510f545
add wrapfd. improve fuzzer in makefile
Matt Johnston <matt@ucc.asn.au>
parents:
1353
diff
changeset
|
45 size_t prefix_size = buf_getint(fuzz.input); |
3677a510f545
add wrapfd. improve fuzzer in makefile
Matt Johnston <matt@ucc.asn.au>
parents:
1353
diff
changeset
|
46 if (prefix_size != 4) { |
3677a510f545
add wrapfd. improve fuzzer in makefile
Matt Johnston <matt@ucc.asn.au>
parents:
1353
diff
changeset
|
47 return DROPBEAR_FAILURE; |
3677a510f545
add wrapfd. improve fuzzer in makefile
Matt Johnston <matt@ucc.asn.au>
parents:
1353
diff
changeset
|
48 } |
3677a510f545
add wrapfd. improve fuzzer in makefile
Matt Johnston <matt@ucc.asn.au>
parents:
1353
diff
changeset
|
49 uint32_t wrapseed = buf_getint(fuzz.input); |
3677a510f545
add wrapfd. improve fuzzer in makefile
Matt Johnston <matt@ucc.asn.au>
parents:
1353
diff
changeset
|
50 wrapfd_setup(wrapseed); |
3677a510f545
add wrapfd. improve fuzzer in makefile
Matt Johnston <matt@ucc.asn.au>
parents:
1353
diff
changeset
|
51 |
1369 | 52 fuzz_seed(); |
1356
3677a510f545
add wrapfd. improve fuzzer in makefile
Matt Johnston <matt@ucc.asn.au>
parents:
1353
diff
changeset
|
53 |
3677a510f545
add wrapfd. improve fuzzer in makefile
Matt Johnston <matt@ucc.asn.au>
parents:
1353
diff
changeset
|
54 return DROPBEAR_SUCCESS; |
3677a510f545
add wrapfd. improve fuzzer in makefile
Matt Johnston <matt@ucc.asn.au>
parents:
1353
diff
changeset
|
55 } |
3677a510f545
add wrapfd. improve fuzzer in makefile
Matt Johnston <matt@ucc.asn.au>
parents:
1353
diff
changeset
|
56 |
1373
9891bc31a1b3
fuzzers disable logging by default
Matt Johnston <matt@ucc.asn.au>
parents:
1369
diff
changeset
|
57 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
|
58 |
9891bc31a1b3
fuzzers disable logging by default
Matt Johnston <matt@ucc.asn.au>
parents:
1369
diff
changeset
|
59 char printbuf[1024]; |
9891bc31a1b3
fuzzers disable logging by default
Matt Johnston <matt@ucc.asn.au>
parents:
1369
diff
changeset
|
60 |
9891bc31a1b3
fuzzers disable logging by default
Matt Johnston <matt@ucc.asn.au>
parents:
1369
diff
changeset
|
61 #if DEBUG_TRACE |
9891bc31a1b3
fuzzers disable logging by default
Matt Johnston <matt@ucc.asn.au>
parents:
1369
diff
changeset
|
62 if (debug_trace) { |
9891bc31a1b3
fuzzers disable logging by default
Matt Johnston <matt@ucc.asn.au>
parents:
1369
diff
changeset
|
63 vsnprintf(printbuf, sizeof(printbuf), format, param); |
9891bc31a1b3
fuzzers disable logging by default
Matt Johnston <matt@ucc.asn.au>
parents:
1369
diff
changeset
|
64 fprintf(stderr, "%s\n", printbuf); |
9891bc31a1b3
fuzzers disable logging by default
Matt Johnston <matt@ucc.asn.au>
parents:
1369
diff
changeset
|
65 } |
9891bc31a1b3
fuzzers disable logging by default
Matt Johnston <matt@ucc.asn.au>
parents:
1369
diff
changeset
|
66 #endif |
9891bc31a1b3
fuzzers disable logging by default
Matt Johnston <matt@ucc.asn.au>
parents:
1369
diff
changeset
|
67 } |
1356
3677a510f545
add wrapfd. improve fuzzer in makefile
Matt Johnston <matt@ucc.asn.au>
parents:
1353
diff
changeset
|
68 |
1348 | 69 void svr_setup_fuzzer(void) { |
70 struct passwd *pw; | |
71 | |
72 common_setup_fuzzer(); | |
1353 | 73 |
74 _dropbear_exit = svr_dropbear_exit; | |
1348 | 75 |
76 char *argv[] = { | |
77 "-E", | |
78 }; | |
79 | |
80 int argc = sizeof(argv) / sizeof(*argv); | |
81 svr_getopts(argc, argv); | |
82 | |
83 /* user lookups might be slow, cache it */ | |
84 pw = getpwuid(getuid()); | |
85 dropbear_assert(pw); | |
86 fuzz.pw_name = m_strdup(pw->pw_name); | |
87 fuzz.pw_dir = m_strdup(pw->pw_dir); | |
88 fuzz.pw_shell = m_strdup(pw->pw_shell); | |
89 fuzz.pw_passwd = m_strdup("!!zzznope"); | |
90 | |
91 load_fixed_hostkeys(); | |
92 } | |
93 | |
94 static void load_fixed_hostkeys(void) { | |
95 #include "fuzz-hostkeys.c" | |
96 | |
97 buffer *b = buf_new(3000); | |
98 enum signkey_type type; | |
99 | |
100 TRACE(("load fixed hostkeys")) | |
101 | |
102 svr_opts.hostkey = new_sign_key(); | |
103 | |
104 buf_setlen(b, 0); | |
105 buf_putbytes(b, keyr, keyr_len); | |
106 buf_setpos(b, 0); | |
107 type = DROPBEAR_SIGNKEY_RSA; | |
108 if (buf_get_priv_key(b, svr_opts.hostkey, &type) == DROPBEAR_FAILURE) { | |
109 dropbear_exit("failed fixed rsa hostkey"); | |
110 } | |
111 | |
112 buf_setlen(b, 0); | |
113 buf_putbytes(b, keyd, keyd_len); | |
114 buf_setpos(b, 0); | |
115 type = DROPBEAR_SIGNKEY_DSS; | |
116 if (buf_get_priv_key(b, svr_opts.hostkey, &type) == DROPBEAR_FAILURE) { | |
117 dropbear_exit("failed fixed dss hostkey"); | |
118 } | |
119 | |
120 buf_setlen(b, 0); | |
121 buf_putbytes(b, keye, keye_len); | |
122 buf_setpos(b, 0); | |
123 type = DROPBEAR_SIGNKEY_ECDSA_NISTP256; | |
124 if (buf_get_priv_key(b, svr_opts.hostkey, &type) == DROPBEAR_FAILURE) { | |
125 dropbear_exit("failed fixed ecdsa hostkey"); | |
126 } | |
127 | |
128 buf_free(b); | |
129 } | |
130 | |
1357 | 131 void fuzz_kex_fakealgos(void) { |
132 ses.newkeys->recv.crypt_mode = &dropbear_mode_none; | |
133 } |