Skip to content

Commit bb9ef10

Browse files
committed
feat: lab5
1 parent 70754a5 commit bb9ef10

File tree

7 files changed

+125
-0
lines changed

7 files changed

+125
-0
lines changed

lab5/Makefile

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
CC=gcc
2+
3+
.PHONY: all
4+
all: bss_overflow_asan
5+
6+
bss_overflow_asan: bss_overflow.c libantiasan.so
7+
$(CC) -fsanitize=address -Og -g -o $@ $< -lantiasan -L.
8+
9+
libantiasan.so: antiasan.c
10+
$(CC) -g -fPIC -c antiasan.c
11+
$(CC) -shared antiasan.o -o libantiasan.so
12+
13+
.PHINY: run
14+
run:
15+
LD_LIBRARY_PATH=. ./bss_overflow_asan
16+
17+
.PHONY: clean
18+
clean:
19+
rm bss_overflow_asan antiasan.o libantiasan.so

lab5/README.md

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Lab5
2+
3+
## Introduction
4+
5+
In this lab, you will write a function antoasan to bypass detection of ASan in `antiasan.c`.
6+
7+
## Preparation (Important!!!)
8+
9+
1. Sync fork your branch (e.g., `SQLab:311XXXXXX`)
10+
2. `git checkout -b lab5` (**NOT** your student ID !!!)
11+
12+
## Requirement
13+
14+
1. (100%) write a function antoasan to bypass detection of ASan in `antiasan.c`.
15+
You can run `validate.sh` in your local to test if you satisfy the requirements.
16+
17+
Please note that you must not alter files other than `antiasan.c`. You will get 0 points if
18+
19+
1. you modify other files to achieve requirements.
20+
2. you can't pass all CI on your PR.
21+
22+
## Submission
23+
24+
You need to open a pull request to your branch (e.g. 311XXXXXX, your student number) and contain the code that satisfies the abovementioned requirements.
25+
26+
Moreover, please submit the URL of your PR to E3. Your submission will only be accepted when you present at both places.

lab5/ans

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
LD_LIBRARY_PATH=. ./bss_overflow_asan
2+
gBadBuf = HAHAHAHAHAHAHAHAHAHAHAH
3+
gS = HAHAHAHAHAHAHAHAHAHAHAH
4+
gS = HAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAH

lab5/antiasan.c

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#include <string.h>
2+
3+
void antiasan(unsigned long addr)
4+
{
5+
6+
}

lab5/antiasan.h

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#ifndef HIJACK_H
2+
#define HIJACK_H
3+
4+
void antiasan(unsigned long);
5+
6+
#endif

lab5/bss_overflow.c

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#include <stdio.h>
2+
#include <string.h>
3+
#include "antiasan.h"
4+
5+
char gS[0x18];
6+
char gBadBuf[0x87];
7+
8+
int main(void)
9+
{
10+
strcpy(gBadBuf, "HAHAHAHAHAHAHAHAHAHAHAH");
11+
strcpy(gS, "HAHAHAHAHAHAHAHAHAHAHAH");
12+
printf("gBadBuf = %s\n", gBadBuf);
13+
printf("gS = %s\n", gS);
14+
antiasan((unsigned long)&gBadBuf);
15+
for (int i = 0; i < 0x10; i += 2) {
16+
gS[0x17 + i] = 'A';
17+
gS[0x17 + i + 1] = 'H';
18+
}
19+
printf("gS = %s\n", gS);
20+
return 0;
21+
}

lab5/validate.sh

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/bin/bash
2+
3+
# Check for unwanted files
4+
for file in *; do
5+
if [[ $file != "bss_overflow.c" && $file != "antiasan.c" && $file != "antiasan.h" && $file != "Makefile" && $file != "README.md" && $file != "validate.sh" && $file != "ans" ]]; then
6+
echo "[!] Unwanted file detected: $file."
7+
exit 1
8+
fi
9+
done
10+
11+
test_path="${BASH_SOURCE[0]}"
12+
solution_path="$(realpath .)"
13+
tmp_dir=$(mktemp -d -t lab5-XXXXXXXXXX)
14+
answer=""
15+
16+
cd $tmp_dir
17+
18+
rm -rf *
19+
cp $solution_path/Makefile .
20+
cp $solution_path/*.c .
21+
cp $solution_path/*.h .
22+
cp $solution_path/ans .
23+
24+
make
25+
make run > out 2>&1
26+
result=$(diff --strip-trailing-cr ans out)
27+
if [[ -n $result ]]; then
28+
echo "[!] Expected: "
29+
cat ans
30+
echo ""
31+
echo "[!] Actual: "
32+
cat out
33+
echo ""
34+
exit 1
35+
else
36+
echo "[V] Pass"
37+
fi
38+
39+
rm -rf $tmp_dir
40+
41+
exit 0
42+
43+
# vim: set fenc=utf8 ff=unix et sw=2 ts=2 sts=2:

0 commit comments

Comments
 (0)