Skip to content

Commit 6870cd7

Browse files
committed
Lab7: merge
1 parent 25bf7ae commit 6870cd7

File tree

6 files changed

+101
-1
lines changed

6 files changed

+101
-1
lines changed

.github/workflows/lab-autograding.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ jobs:
4545
const files = await github.rest.pulls.listFiles({ owner, repo, pull_number: issue_number });
4646
const changedFiles = files.data.map((file) => file.filename);
4747
const allowedFileRegex = /^lab\d+\/main_test.js$/;
48-
const specialChangedFiles = ["lab5/Answer.md", "lab5/antiasan.c", "lab6/Answer.md"];
48+
const specialChangedFiles = ["lab5/Answer.md", "lab5/antiasan.c", "lab6/Answer.md", "lab7/sol.py"];
4949
if (!changedFiles.every((file) => (allowedFileRegex.test(file) || specialChangedFiles.includes(file)))) {
5050
core.setFailed('The PR contains changes to files other than the allowed files.');
5151
}

lab7/Makefile

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
login: login.o
2+
3+
login.o: login.c
4+
5+
.PHONY: clean
6+
clean:
7+
rm login login.o

lab7/README.md

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Lab7
2+
3+
## Introduction
4+
5+
In this lab, you will write a python script with Angr to find the password in executalbe file named 'login'.
6+
7+
## Preparation (Important!!!)
8+
9+
1. Sync fork your branch (e.g., `SQLab:311XXXXXX`)
10+
2. `git checkout -b lab7` (**NOT** your student ID !!!)
11+
12+
## Requirement
13+
14+
1. (100%) Detect the condition that login will print 'Login successful' if login success and print 'Login failed' if login fail, find the input of successful condition by Angr.
15+
16+
Please note that you must not alter files other than `sol.py` or just print the input. You will get 0 points if
17+
18+
1. you modify other files to achieve requirements.
19+
2. you can't pass all CI on your PR.
20+
21+
## Submission
22+
23+
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.
24+
25+
Moreover, please submit the URL of your PR to E3. Your submission will only be accepted when you present at both places.

lab7/login.c

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#include <stdio.h>
2+
#include <stdlib.h>
3+
#include <string.h>
4+
5+
int encrypt(int a1, int a2) {
6+
if ( a1 <= 0x40 || a1 > 90 ) {
7+
puts("Login failed");
8+
exit(1);
9+
}
10+
return (0x1F * a2 + a1 - 65) % 26 + 65;
11+
}
12+
13+
int main(void) {
14+
char secret[0x20] = "VXRRJEURXDASBFHM";
15+
char pwd[0x20] = {0};
16+
17+
printf("Enter the password: ");
18+
scanf("%16s", pwd);
19+
for ( int j = 0; j < 0x10; ++j )
20+
pwd[j] = encrypt(pwd[j], j + 8);
21+
if ( !strcmp(secret, pwd) )
22+
puts("Login successful");
23+
else
24+
puts("Login failed");
25+
return 0;
26+
}

lab7/sol.py

Whitespace-only changes.

lab7/validate.sh

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/bin/bash
2+
3+
# Check for unwanted files
4+
for file in *; do
5+
if [[ $file != "login.c" && $file != "sol.py" && $file != "Makefile" && $file != "README.md" && $file != "validate.sh" ]]; 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 lab7-XXXXXXXXXX)
14+
answer=""
15+
16+
cd $tmp_dir
17+
18+
pip install angr
19+
rm -rf *
20+
cp $solution_path/Makefile .
21+
cp $solution_path/*.c .
22+
cp $solution_path/sol.py .
23+
24+
make
25+
result=$(python3 sol.py)
26+
if [[ $result != "b'HETOBRCUVWOBFEBB'" ]]; then
27+
echo "[!] Expected: "
28+
echo "b'HETOBRCUVWOBFEBB'"
29+
echo ""
30+
echo "[!] Actual: "
31+
echo $result
32+
echo ""
33+
exit 1
34+
else
35+
echo "[V] Pass"
36+
fi
37+
38+
rm -rf $tmp_dir
39+
40+
exit 0
41+
42+
# vim: set fenc=utf8 ff=unix et sw=2 ts=2 sts=2:

0 commit comments

Comments
 (0)