forked from open-education-hub/hardware-software-interface
-
Notifications
You must be signed in to change notification settings - Fork 55
labs/lab-10: Add checker infrastructure #57
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,11 @@ | ||
# SPDX-License-Identifier: BSD-3-Clause | ||
import subprocess | ||
|
||
|
||
def run_executable(): | ||
argument = 32 * "A" + "\x50\x52\x30\x4e" | ||
subprocess.run(["./overflow_in_binary", argument]) | ||
|
||
|
||
if __name__ == "__main__": | ||
run_executable() |
This file contains hidden or 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,11 @@ | ||
# SPDX-License-Identifier: BSD-3-Clause | ||
import subprocess | ||
|
||
|
||
def run_executable(): | ||
argument = "" # TODO: Put here the payload you have discovered | ||
subprocess.run(["./overflow_in_binary", argument]) | ||
|
||
|
||
if __name__ == "__main__": | ||
run_executable() |
Empty file modified
0
labs/lab-10/tasks/overflow-for-binary/support/overflow_in_binary
100644 → 100755
Empty file.
This file contains hidden or 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,6 @@ | ||
# SPDX-License-Identifier: BSD-3-Clause | ||
|
||
check: | ||
./run_all_tests.sh | ||
|
||
.PHONY: check |
30 changes: 30 additions & 0 deletions
30
labs/lab-10/tasks/overflow-for-binary/tests/graded_test.inc.sh
This file contains hidden or 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,30 @@ | ||
#!/bin/bash | ||
# SPDX-License-Identifier: BSD-3-Clause | ||
|
||
print_test() | ||
{ | ||
desc="$1" | ||
res="$2" | ||
|
||
dots="........................................" | ||
|
||
printf "%-12.12s%s" "$desc" "$dots" | ||
|
||
if [ "$res" -eq 1 ]; then | ||
printf "passed" | ||
else | ||
printf "failed" | ||
fi | ||
|
||
printf "\n" | ||
} | ||
|
||
run_test() | ||
{ | ||
func="$1" | ||
|
||
( eval "$func" ) | ||
ret=$? | ||
|
||
print_test "$func" "$ret" | ||
} |
20 changes: 20 additions & 0 deletions
20
labs/lab-10/tasks/overflow-for-binary/tests/run_all_tests.sh
This file contains hidden or 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,20 @@ | ||
#!/bin/bash | ||
# SPDX-License-Identifier: BSD-3-Clause | ||
|
||
echo "" | ||
( | ||
bash test.sh | ||
) | tee results.txt | ||
echo "" | ||
|
||
if tail -n 1 results.txt | grep -q 'passed$'; then | ||
total=100 | ||
else | ||
total=0 | ||
fi | ||
|
||
echo -n "Total: " | ||
echo -n " " | ||
LC_ALL=C printf "%3d/100\n" "$total" | ||
|
||
rm results.txt |
This file contains hidden or 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,15 @@ | ||
#!/bin/bash | ||
# SPDX-License-Identifier: BSD-3-Clause | ||
# shellcheck disable=SC1091 | ||
|
||
source ./graded_test.inc.sh | ||
|
||
test_exploit() { | ||
if ( cd ../support && python3 exploit.py | grep -q "Great success!" ); then | ||
return 1 | ||
else | ||
return 0 | ||
fi | ||
} | ||
|
||
run_test test_exploit |
This file contains hidden or 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 hidden or 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,11 @@ | ||
# SPDX-License-Identifier: BSD-3-Clause | ||
import subprocess | ||
|
||
|
||
def run_executable(): | ||
payload = 73 * "A" + "\x4d\x49\x41\x55" | ||
subprocess.run(["../support/do_overflow"], input=payload, universal_newlines=True) | ||
|
||
|
||
if __name__ == "__main__": | ||
run_executable() |
115 changes: 0 additions & 115 deletions
115
labs/lab-10/tasks/overflow-in-c/support/do_overflow.asm
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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,11 @@ | ||
# SPDX-License-Identifier: BSD-3-Clause | ||
import subprocess | ||
|
||
|
||
def run_executable(): | ||
payload = "" # TODO: Put here the payload you have discovered | ||
subprocess.run(["../support/do_overflow"], input=payload, universal_newlines=True) | ||
|
||
|
||
if __name__ == "__main__": | ||
run_executable() |
This file contains hidden or 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,24 @@ | ||
CC = gcc | ||
CFLAGS = -Wall -Wextra -O2 | ||
TARGET = test_overflow_in_C | ||
|
||
SRCS = test_overflow_in_C.c graded_test.c | ||
|
||
OBJS = $(SRCS:.c=.o) | ||
|
||
all: $(TARGET) | ||
|
||
$(TARGET): $(OBJS) | ||
$(CC) $(CFLAGS) $(OBJS) -o $@ | ||
|
||
%.o: %.c | ||
$(CC) $(CFLAGS) -c $< -o $@ | ||
|
||
clean: | ||
rm -f $(TARGET) $(OBJS) | ||
|
||
check: all | ||
./run_all_tests.sh | ||
$(MAKE) clean | ||
|
||
.PHONY: all clean test |
This file contains hidden or 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,72 @@ | ||
// SPDX-License-Identifier: BSD-3-Clause | ||
|
||
#include <string.h> | ||
#include <stdlib.h> | ||
#include <unistd.h> | ||
#include <sys/param.h> | ||
|
||
#include "./graded_test.h" | ||
|
||
/* | ||
* Print test result. Printed message should fit in 72 characters. | ||
* | ||
* Print format is: | ||
* | ||
* description ...................... passed ... NNN | ||
* description ...................... failed ... NNN | ||
* 32 chars 24 chars 6 3 3 | ||
*/ | ||
|
||
static void print_test(const char *description, int result) | ||
{ | ||
/* Make these global linkage, so it's only allocated once. */ | ||
static char print_buffer[74]; | ||
static const char failed[] = "failed"; | ||
static const char passed[] = "passed"; | ||
size_t i; | ||
size_t len; | ||
|
||
/* Collect description in print_buffer. */ | ||
len = MIN(strlen(description), 32); | ||
for (i = 0; i < len; i++) | ||
print_buffer[i] = description[i]; | ||
|
||
/* Collect dots in print_buffer. */ | ||
for (i = 0; i < 40; i++) | ||
print_buffer[12+i] = '.'; | ||
|
||
/* Collect passed / failed. */ | ||
for (i = 0; i < 6; i++) { | ||
if (result == 1) | ||
print_buffer[52+i] = passed[i]; | ||
else | ||
print_buffer[52+i] = failed[i]; | ||
} | ||
|
||
/* Collect newline. */ | ||
print_buffer[59] = '\n'; | ||
|
||
int ret = write(1, print_buffer, 58); | ||
|
||
if (ret == -1) | ||
return; | ||
} | ||
|
||
void run_test(struct graded_test *test) | ||
{ | ||
int res; | ||
|
||
res = test->function(); | ||
print_test(test->description, res); | ||
#ifdef EXIT_IF_FAIL | ||
exit(EXIT_FAILURE); | ||
#endif | ||
} | ||
|
||
void run_tests(struct graded_test *tests, size_t count) | ||
{ | ||
size_t i; | ||
|
||
for (i = 0; i < count; i++) | ||
run_test(&tests[i]); | ||
} |
This file contains hidden or 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,20 @@ | ||
/* SPDX-License-Identifier: BSD-3-Clause */ | ||
|
||
#include <stddef.h> | ||
|
||
#ifndef GRADED_TEST_H_ | ||
#define GRADED_TEST_H_ 1 | ||
|
||
/* test function prototype */ | ||
typedef int (*test_f)(void); | ||
|
||
struct graded_test { | ||
test_f function; /* test/evaluation function */ | ||
char *description; /* test description */ | ||
size_t points; /* points for each test */ | ||
}; | ||
|
||
void run_test(struct graded_test *test); | ||
void run_tests(struct graded_test *tests, size_t count); | ||
|
||
#endif /* GRADED_TEST_H_ */ |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.