-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
15 changed files
with
231 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# Fuzzing cockpit | ||
|
||
## Build cockpit fuzzer using libFuzzer. | ||
|
||
### Export flags for fuzzing. | ||
|
||
Note that in `CFLAGS` and `CXXFLAGS`, any type of sanitizers can be added. | ||
|
||
- [AddressSanitizer](https://clang.llvm.org/docs/AddressSanitizer.html), | ||
[ThreadSanitizer](https://clang.llvm.org/docs/ThreadSanitizer.html), | ||
[MemorySanitizer](https://clang.llvm.org/docs/MemorySanitizer.html), | ||
[UndefinedBehaviorSanitizer](https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html), | ||
[LeakSanitizer](https://clang.llvm.org/docs/LeakSanitizer.html). | ||
|
||
```shell | ||
$ export CC=clang | ||
$ export CXX=clang++ | ||
$ export CFLAGS="-g -DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION -fsanitize=address,undefined -fsanitize=fuzzer-no-link" | ||
$ export CXXFLAGS="-g -DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION -fsanitize=address,undefined -fsanitize=fuzzer-no-link" | ||
$ export LIB_FUZZING_ENGINE="-fsanitize=fuzzer" | ||
``` | ||
|
||
### Build cockpit for fuzzing. | ||
|
||
```shell | ||
$ ./autogen.sh --enable-fuzzing --disable-doc | ||
$ make -j$(nproc) | ||
``` | ||
|
||
### Running fuzzer. | ||
|
||
```shell | ||
$ mkdir -p fuzz_authorize_seed fuzz_base64_seed fuzz_websocket_seed | ||
|
||
$ ./fuzz_authorize fuzz_authorize_seed src/common/fuzz_authorize_seed_corpus | ||
$ ./fuzz_base64 fuzz_base64_seed src/common/fuzz_base64_seed_corpus | ||
$ ./fuzz_websocket fuzz_websocket_seed src/websocket/fuzz_websocket_seed_corpus | ||
``` | ||
|
||
Here is more information about [LibFuzzer](https://llvm.org/docs/LibFuzzer.html). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#include "config.h" | ||
|
||
#include "cockpitauthorize.h" | ||
|
||
#include <stdlib.h> | ||
#include <stdint.h> | ||
#include <string.h> | ||
|
||
#define kMinInputLength 2 | ||
#define kMaxInputLength 1024 | ||
|
||
extern int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size); | ||
|
||
int | ||
LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) | ||
{ | ||
char *data_in; | ||
|
||
if (size < kMinInputLength || size > kMaxInputLength) | ||
return 0; | ||
|
||
data_in = calloc(size + 1, sizeof(char)); | ||
if (data_in == NULL) | ||
return 0; | ||
|
||
memcpy(data_in, data, size); | ||
|
||
{ | ||
char *user = "a"; | ||
char *password = NULL; | ||
|
||
password = cockpit_authorize_parse_basic(data_in, &user); | ||
if (password != NULL) { | ||
free(password); | ||
free(user); | ||
} | ||
} | ||
{ | ||
void *result = NULL; | ||
|
||
result = cockpit_authorize_parse_negotiate(data_in, NULL); | ||
if (result != NULL) | ||
free(result); | ||
} | ||
{ | ||
void *result = NULL; | ||
char *conversation = NULL; | ||
|
||
result = cockpit_authorize_parse_x_conversation(data_in, &conversation); | ||
if (result != NULL) | ||
free(result); | ||
|
||
if (conversation != NULL) | ||
free(conversation); | ||
} | ||
|
||
free(data_in); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Basic c2NydWZmeTp6ZXJvZw== |
1 change: 1 addition & 0 deletions
1
src/common/fuzz_authorize_seed_corpus/parse_negotiate_fixtures.bin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Negotiate c2NydWZmeTp6ZXJvZw== |
1 change: 1 addition & 0 deletions
1
src/common/fuzz_authorize_seed_corpus/parse_x_conversation_fixtures.bin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
X-Conversation abcdefghi c2NydWZmeTp6ZXJvZw== |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#include "config.h" | ||
|
||
#include "cockpitbase64.h" | ||
|
||
#include <stdint.h> | ||
|
||
#define kMinInputLength 2 | ||
#define kMaxInputLength 1024 | ||
|
||
extern int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size); | ||
|
||
int | ||
LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) | ||
{ | ||
char encoded[2048]; | ||
uint8_t decoded[2048]; | ||
|
||
if (size < kMinInputLength || size > kMaxInputLength) | ||
return 0; | ||
|
||
cockpit_base64_ntop(data, size, encoded, sizeof(encoded)); | ||
cockpit_base64_pton((char *)data, size, decoded, sizeof(decoded)); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
QUFBQQ== |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
AAAA |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#include "config.h" | ||
|
||
#include "websocket.h" | ||
#include "websocketprivate.h" | ||
|
||
#include <stdint.h> | ||
|
||
#define kMinInputLength 2 | ||
#define kMaxInputLength 1024 | ||
|
||
extern int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size); | ||
|
||
int | ||
LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) | ||
{ | ||
char *data_in; | ||
|
||
if (size < kMinInputLength || size > kMaxInputLength) | ||
return 0; | ||
|
||
data_in = calloc(size + 1, sizeof(char)); | ||
if (data_in == NULL) | ||
return 0; | ||
|
||
memcpy(data_in, data, size); | ||
|
||
{ | ||
gchar *path = NULL; | ||
gchar *method = NULL; | ||
|
||
web_socket_util_parse_req_line((char *)data, size, &method, &path); | ||
if (method != NULL) | ||
g_free(method); | ||
|
||
if (path != NULL) | ||
g_free(path); | ||
} | ||
{ | ||
guint status; | ||
gchar *reason = NULL; | ||
|
||
web_socket_util_parse_status_line(data_in, size + 1, NULL, &status, &reason); | ||
if (reason != NULL) | ||
g_free(reason); | ||
} | ||
{ | ||
GHashTable *headers = NULL; | ||
|
||
web_socket_util_parse_headers(data_in, size + 1, &headers); | ||
if (headers != NULL) | ||
g_hash_table_unref(headers); | ||
} | ||
|
||
free(data_in); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Host:https://cockpit-project.org |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
GET /path/part HTTP/1.0 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
HTTP/1.0 101 Switching Protocols | ||
|