Clean
This commit is contained in:
parent
7f8974af44
commit
dd7370c784
7 changed files with 140 additions and 129 deletions
|
@ -1 +1 @@
|
|||
Subproject commit f1214cfd12d6735ba751f6f23dd61c79b92efe35
|
||||
Subproject commit 3a897af896eed6e9f856c6690e80a93e1ad6e112
|
|
@ -1 +1 @@
|
|||
Subproject commit b6f5abf852d3c35b48f409db7db3b3ef08e9aebf
|
||||
Subproject commit 25efac091c36369dcccf71b6c85a0af0acc5bf6e
|
|
@ -1 +1 @@
|
|||
Subproject commit 084df4937324620a3651538fcf065d36353245fe
|
||||
Subproject commit 510d9c2d6c0fa097dfc3c1d5713e2a0a05ab84bc
|
120
Makefile
120
Makefile
|
@ -1,61 +1,61 @@
|
|||
SOURCE=null
|
||||
QUOI=null
|
||||
WHAT=null
|
||||
|
||||
default:
|
||||
@echo "Specifiez une cible [secure|unsecure|compile|exec|exec_secure|exec_unsecure|clean]"
|
||||
@echo "Specify target [secure|unsecure|build|exec|exec_secure|exec_unsecure|clean]"
|
||||
|
||||
|
||||
|
||||
|
||||
secure:
|
||||
@sed -i 's/#define SECURISED (0)/#define SECURISED (1)/g' Interpreteur/Tables/tables.c InterpreteurRegistres/Tables/tables.c Compilateur/Lex_Yacc/as.y
|
||||
@sed -i 's/constant SECURISED : boolean := false;/constant SECURISED : boolean := true;/g' Processeur/Processeur.srcs/sources_1/new/System.vhd
|
||||
@sed -i 's/#define SECURED (0)/#define SECURED (1)/g' Interpreteur/Tables/tables.c InterpreteurRegistres/Tables/tables.c Compilateur/Lex_Yacc/as.y
|
||||
@sed -i 's/constant SECURED : boolean := false;/constant SECURED : boolean := true;/g' Processeur/Processeur.srcs/sources_1/new/System.vhd
|
||||
|
||||
|
||||
|
||||
|
||||
unsecure:
|
||||
@sed -i 's/#define SECURISED (1)/#define SECURISED (0)/g' Interpreteur/Tables/tables.c InterpreteurRegistres/Tables/tables.c Compilateur/Lex_Yacc/as.y
|
||||
@sed -i 's/constant SECURISED : boolean := true;/constant SECURISED : boolean := false;/g' Processeur/Processeur.srcs/sources_1/new/System.vhd
|
||||
@sed -i 's/#define SECURED (1)/#define SECURED (0)/g' Interpreteur/Tables/tables.c InterpreteurRegistres/Tables/tables.c Compilateur/Lex_Yacc/as.y
|
||||
@sed -i 's/constant SECURED : boolean := true;/constant SECURED : boolean := false;/g' Processeur/Processeur.srcs/sources_1/new/System.vhd
|
||||
|
||||
|
||||
|
||||
|
||||
compile:
|
||||
ifeq ($(QUOI),null)
|
||||
@echo "USAGE : make compile QUOI=\"[compilateur|interpreteur|interpreteur_registres|cross_assembleur|all]\""
|
||||
build:
|
||||
ifeq ($(WHAT),null)
|
||||
@echo "USAGE : make build WHAT=\"[compiler|interpreter|interpreter_registers|cross_assembler|all]\""
|
||||
else
|
||||
ifeq ($(QUOI),compilateur)
|
||||
@echo "Compilation du compilateur"
|
||||
ifeq ($(WHAT),compiler)
|
||||
@echo "Building compiler"
|
||||
$(MAKE) -C Compilateur build
|
||||
@echo "Compilation terminée"
|
||||
else ifeq ($(QUOI),cross_assembleur)
|
||||
@echo "Compilation du CrossAssembleur"
|
||||
@echo "Compiler built"
|
||||
else ifeq ($(WHAT),cross_assembler)
|
||||
@echo "Building CrossAssembler"
|
||||
$(MAKE) -C CrossAssembleur build
|
||||
@echo "Compilation terminée"
|
||||
else ifeq ($(QUOI),interpreteur)
|
||||
@echo "Compilation de l'interpreteur"
|
||||
@echo "CrossAssembler built"
|
||||
else ifeq ($(WHAT),interpreter)
|
||||
@echo "Building interpreter"
|
||||
$(MAKE) -C Interpreteur build
|
||||
@echo "Compilation terminée"
|
||||
else ifeq ($(QUOI),interpreteur_registres)
|
||||
@echo "Compilation de l'interpreteur_registres"
|
||||
@echo "Interpreter built"
|
||||
else ifeq ($(WHAT),interpreter_registers)
|
||||
@echo "Building interpreter_registers"
|
||||
$(MAKE) -C InterpreteurRegistres build
|
||||
@echo "Compilation terminée"
|
||||
else ifeq ($(QUOI),all)
|
||||
@echo "Compilation du compilateur"
|
||||
@echo "Interpreter_registers built"
|
||||
else ifeq ($(WHAT),all)
|
||||
@echo "Building compiler"
|
||||
$(MAKE) -C Compilateur build
|
||||
@echo "Compilation terminée"
|
||||
@echo "Compilation de l'interpreteur"
|
||||
@echo "Compiler built"
|
||||
@echo "Building interpreter"
|
||||
$(MAKE) -C Interpreteur build
|
||||
@echo "Compilation terminée"
|
||||
@echo "Compilation du CrossAssembleur"
|
||||
@echo "Interpreter built"
|
||||
@echo "Building CrossAssembler"
|
||||
$(MAKE) -C CrossAssembleur build
|
||||
@echo "Compilation terminée"
|
||||
@echo "Compilation de l'interpreteur_registres"
|
||||
@echo "CrossAssembler built"
|
||||
@echo "Building interpreter_registers"
|
||||
$(MAKE) -C InterpreteurRegistres build
|
||||
@echo "Compilation terminée"
|
||||
@echo "Interpreter_registers built"
|
||||
else
|
||||
@echo "USAGE : make compile QUOI=\"[compilateur|interpreteur|interpreteur_registres|cross_assembleur|all]\""
|
||||
@echo "USAGE : make build WHAT=\"[compiler|interpreter|interpreter_registers|cross_assembler|all]\""
|
||||
endif
|
||||
endif
|
||||
|
||||
|
@ -77,51 +77,51 @@ exec_unsecure: unsecure compile exec
|
|||
|
||||
exec:
|
||||
ifeq ($(SOURCE),null)
|
||||
@echo "USAGE : make exec SOURCE=\"file_name\" QUOI=\"[compile|interprete|interprete_registres|cross_assemble|load|all]\""
|
||||
@echo "USAGE : make exec SOURCE=\"file_name\" WHAT=\"[compile|interprete|interprete_registers|cross_assemble|load|all]\""
|
||||
else
|
||||
ifeq ($(QUOI),null)
|
||||
@echo "USAGE : make exec SOURCE=\"file_name\" QUOI=\"[compile|interprete|interprete_registres|cross_assemble|load|all]\""
|
||||
ifeq ($(WHAT),null)
|
||||
@echo "USAGE : make exec SOURCE=\"file_name\" WHAT=\"[compile|interprete|interprete_registers|cross_assemble|load|all]\""
|
||||
else
|
||||
ifeq ($(QUOI),compile)
|
||||
@echo "Compilation"
|
||||
ifeq ($(WHAT),compile)
|
||||
@echo "Building program"
|
||||
cat $(SOURCE).c | Compilateur/rondoudou_gcc
|
||||
@mv output.txt $(SOURCE).memasm
|
||||
@echo "Compilation terminée"
|
||||
else ifeq ($(QUOI),interprete)
|
||||
@echo "Interpretation"
|
||||
@echo "Program built"
|
||||
else ifeq ($(WHAT),interprete)
|
||||
@echo "Interpreting program"
|
||||
Interpreteur/rondoudou_interpreter $(SOURCE).memasm
|
||||
@echo "Interpretation terminée"
|
||||
else ifeq ($(QUOI),interprete_registres)
|
||||
@echo "Interpretation registres"
|
||||
InterpreteurRegistres/rondoudou_interpreter_registres $(SOURCE).regasm
|
||||
@echo "Interpretation registres terminée"
|
||||
else ifeq ($(QUOI),cross_assemble)
|
||||
@echo "CrossAssemblage"
|
||||
cat $(SOURCE).memasm | CrossAssembleur/rondoudou_cross_assembleur
|
||||
@echo "Program interpreted"
|
||||
else ifeq ($(WHAT),interprete_registers)
|
||||
@echo "Interpreting registers program"
|
||||
InterpreteurRegistres/rondoudou_interpreter_registers $(SOURCE).regasm
|
||||
@echo "Registers program interpreted"
|
||||
else ifeq ($(WHAT),cross_assemble)
|
||||
@echo "CrossAssembling program"
|
||||
cat $(SOURCE).memasm | CrossAssembleur/rondoudou_cross_assembler
|
||||
@mv output.asm $(SOURCE).regasm
|
||||
@mv output.bin $(SOURCE).bin
|
||||
@echo "CrossAssemblage terminé"
|
||||
else ifeq ($(QUOI),load)
|
||||
@echo "Chargement du binaire"
|
||||
@echo "Program CrossAssembled"
|
||||
else ifeq ($(WHAT),load)
|
||||
@echo "Loading binairy program"
|
||||
@sed -r "s/signal MEMORY : STD_LOGIC_VECTOR \(\(Mem_Size \* Nb_bits\)-1 downto 0\) := \"[01]*\";/signal MEMORY : STD_LOGIC_VECTOR \(\(Mem_Size \* Nb_bits\)-1 downto 0\) := $$(cat $(SOURCE).bin);/g" Processeur/Processeur.srcs/sources_1/new/MemoireInstructions.vhd > $(SOURCE).tmp.vhd
|
||||
@mv $(SOURCE).tmp.vhd Processeur/Processeur.srcs/sources_1/new/MemoireInstructions.vhd
|
||||
@echo "Chargement du binaire terminé"
|
||||
else ifeq ($(QUOI),all)
|
||||
@echo "Compilation"
|
||||
@echo "Binairy program loaded"
|
||||
else ifeq ($(WHAT),all)
|
||||
@echo "Building program"
|
||||
cat $(SOURCE).c | Compilateur/rondoudou_gcc
|
||||
@mv output.txt $(SOURCE).memasm
|
||||
@echo "Compilation terminée"
|
||||
@echo "CrossAssemblage"
|
||||
cat $(SOURCE).memasm | CrossAssembleur/rondoudou_cross_assembleur
|
||||
@echo "Program built"
|
||||
@echo "CrossAssembling program"
|
||||
cat $(SOURCE).memasm | CrossAssembleur/rondoudou_cross_assembler
|
||||
@mv output.asm $(SOURCE).regasm
|
||||
@mv output.bin $(SOURCE).bin
|
||||
@echo "CrossAssemblage terminé"
|
||||
@echo "Chargement du binaire"
|
||||
@echo "Program CrossAssembled"
|
||||
@echo "Loading binairy program"
|
||||
@sed -r "s/signal MEMORY : STD_LOGIC_VECTOR \(\(Mem_Size \* Nb_bits\)-1 downto 0\) := \"[01]*\";/signal MEMORY : STD_LOGIC_VECTOR \(\(Mem_Size \* Nb_bits\)-1 downto 0\) := $$(cat $(SOURCE).bin);/g" Processeur/Processeur.srcs/sources_1/new/MemoireInstructions.vhd > $(SOURCE).tmp.vhd
|
||||
@mv $(SOURCE).tmp.vhd Processeur/Processeur.srcs/sources_1/new/MemoireInstructions.vhd
|
||||
@echo "Chargement du binaire terminé"
|
||||
@echo "Binairy program loaded"
|
||||
else
|
||||
@echo "USAGE : make exec SOURCE=\"file_name\" QUOI=\"[compile|interprete|interprete_registres|cross_assemble|load|all]\""
|
||||
@echo "USAGE : make exec SOURCE=\"file_name\" WHAT=\"[compile|interprete|interprete_registers|cross_assemble|load|all]\""
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit 6eca866e4333a2352d638e7a4a42b7a789969bf7
|
||||
Subproject commit e46d1700b3e45fe7af436db2d03649a68b7af6ed
|
123
ReadMe.md
123
ReadMe.md
|
@ -1,106 +1,117 @@
|
|||
# Processeur sécurisé
|
||||
# Secured processor
|
||||
|
||||
This repository gathers the different components allowing to execute a program written in a language derived from C on a processor secured against the hijacking of the execution flow by buffer overflow.
|
||||
|
||||
The built and execution process is divided into 5 steps, 3 mandatory and 2 optional.
|
||||
|
||||
Ce dépot regroupe les différents composants permettant d'exécuter un programme écrit dans un langage dérivé du C sur un processeur sécurisé contre le détournement du flot d'exécution par buffer overflow.
|
||||
|
||||
La chaine est divisée en 5 étapes, 3 obligatoires et 2 facultatives.
|
||||
|
||||
- Compiler le code avec le module *Compilateur*, cela va généré un premier code assembleur sans registres.
|
||||
- Facultatif : Interpreter ce code assembleur avec le module *Interpreteur* pour vérifier le comportement du programme.
|
||||
- Intégrer les registres dans le code assembleur avec le module *CrossAssembleur*.
|
||||
- Facultatif : Interpreter ce code assembleur avec le module *InterpreteurRegistres* pour vérifier le comportement du programme.
|
||||
- Exécuter le code sur le processeur sur un FPGA
|
||||
- Build the program thanks to the *Compilateur* module, this will generate a first assembly code without registers.
|
||||
- Optional: Interpret this assembly code with the *Interpreteur* module to check the behaviour of the program.
|
||||
- Add registers management into the assembly code with the *CrossAssembleur* module.
|
||||
- Optional: Interpret this assembly code with the *InterpreteurRegistres* module to check the behaviour of the program
|
||||
- Run the program into the processor designed in VHDL
|
||||
|
||||
### Technologies :
|
||||
- Compilateur : Lex Yacc (flex et bison), C (gcc), Makefile (make)
|
||||
- Interpreteur : Lex Yacc (flex et bison), C (gcc), Makefile (make)
|
||||
- CrossAssembleur : Lex Yacc (flex et bison), C (gcc), Makefile (make)
|
||||
- CompilateurRegistre : Lex Yacc (flex et bison), C (gcc), Makefile (make)
|
||||
- Processeur : Digilent FPGA Basys3 Artix7, Vivado (2016.4)
|
||||
- Development OS : Ubuntu 20.04.4 LTS
|
||||
|
||||
### Mots clés :
|
||||
Sécurité, BufferOverflow, BOF, Processeur, Compilateur, FPGA.
|
||||
- Compilateur (Compiler) : Lex Yacc (flex et bison), C (gcc), Makefile (make)
|
||||
- Interpreteur (Interpreter) : Lex Yacc (flex et bison), C (gcc), Makefile (make)
|
||||
- CrossAssembleur (CrossAssembler) : Lex Yacc (flex et bison), C (gcc), Makefile (make)
|
||||
- InterpreteurRegistres (InterpreterRegisters) : Lex Yacc (flex et bison), C (gcc), Makefile (make)
|
||||
- Processeur (Processor) : Digilent FPGA Basys3 Artix7, Vivado (2018.2)
|
||||
|
||||
# Utilisation
|
||||
### Key words :
|
||||
Security, Secured, BufferOverflow, BOF, Processor, Compiler, FPGA; Basys3.
|
||||
|
||||
Pour cloner le GIT **ET** les sous modules, veuillez utiliser la commande :
|
||||
# Usage
|
||||
|
||||
To clone the project **including** submodules, use:
|
||||
``` bash
|
||||
git clone --recurse-submodules https://git.etud.insa-toulouse.fr/pfaure/PSI.git
|
||||
```
|
||||
|
||||
Si vous avez cloné le dépot de manière "classique", vous pouvez utiliser les commandes suivantes afin de télécharger les sous-modules :
|
||||
If you have cloned the repository in the "classic" way, to download submodules use:
|
||||
``` bash
|
||||
git submodule init
|
||||
git submodule update
|
||||
```
|
||||
|
||||
Un Makefile a été inclus afin de simplifier la chaine de compilation et d'exécution.
|
||||
A Makefile has been included to simplify build and usage of the project.
|
||||
|
||||
## Versions
|
||||
Attention, il existe deux versions du projet, une avec la sécurité implémentée, et une sans. Soyez vigilent a avoir les modules dans la même version. Pour compilateur, il faut juste changer la valeur du *#define SECURISED ()*. Pour les interpreteurs et le processeur il s'agit de branches différentes.
|
||||
Please note that there are two versions of the project, one with the security implemented, and one without.
|
||||
Be careful to have all modules in the same version. The best way is to use the following commands to change the version:
|
||||
|
||||
### Compilation du projet
|
||||
|
||||
#### Compilation de tout le projet :
|
||||
``` bash
|
||||
make compile QUOI="all"
|
||||
make secure
|
||||
```
|
||||
|
||||
#### Compilation du Compilateur uniquement :
|
||||
or
|
||||
|
||||
``` bash
|
||||
make compile QUOI="compilateur"
|
||||
make unsecure
|
||||
```
|
||||
|
||||
#### Compilation de l'Interpreteur uniquement :
|
||||
### Building the project
|
||||
|
||||
#### Building the whole project at once:
|
||||
``` bash
|
||||
make compile QUOI="interpreteur"
|
||||
make build WHAT="all"
|
||||
```
|
||||
|
||||
#### Compilation du CrossAssembleur uniquement :
|
||||
#### Building compiler only:
|
||||
``` bash
|
||||
make compile QUOI="cross_assembleur"
|
||||
make build WHAT="compilater"
|
||||
```
|
||||
|
||||
#### Compilation de l'InterpreteurRegistres uniquement :
|
||||
#### Building interpreter only:
|
||||
``` bash
|
||||
make compile QUOI="interpreteur_registres"
|
||||
make build WHAT="interpreter"
|
||||
```
|
||||
|
||||
### Exploitation du projet
|
||||
|
||||
#### Réalisation de toute la chaine :
|
||||
#### Building CrossAssembler only:
|
||||
``` bash
|
||||
make exec QUOI="all" SOURCE="prefixe_file"
|
||||
make compile WHAT="cross_assembler"
|
||||
```
|
||||
Ceci va compiler le fichier **prefixe_file.c**, générer les fichiers assembleur et binaire, et modifier le code du processeur pour charger le programme. (Ne réalise pas les étapes facultatives)
|
||||
|
||||
#### Compilation d'un fichier :
|
||||
#### Building interpreter registers only:
|
||||
``` bash
|
||||
make exec QUOI="compile" SOURCE="prefixe_file"
|
||||
make build WHAT="interpreter_registers"
|
||||
```
|
||||
Ceci va compiler le fichier **prefixe_file.c** et générer le fichier assembleur orienté mémoire **prefixe_file.memasm**
|
||||
|
||||
#### Interpretation d'un assembleur mémoire :
|
||||
``` bash
|
||||
make exec QUOI="interprete" SOURCE="prefixe_file"
|
||||
```
|
||||
Ceci va interpreter le fichier **prefixe_file.memasm**
|
||||
### Using the project
|
||||
|
||||
#### CrossAssemblage d'un assembleur mémoire :
|
||||
#### Build, crossassemble and load program at once:
|
||||
``` bash
|
||||
make exec QUOI="cross_assemble" SOURCE="prefixe_file"
|
||||
make exec WHAT="all" SOURCE="program_file_without_extension"
|
||||
```
|
||||
Ceci va transformer le fichier **prefixe_file.memasm** en fichier **prefixe_file.regasm** afin d'intégrer les registres
|
||||
This will build **program_file_without_extension.c**, generate the assembly and binary files, and modify the processor code to load the program. (Does not perform the optional steps)
|
||||
|
||||
#### Interpretation d'un assembleur registre :
|
||||
#### Build program only:
|
||||
``` bash
|
||||
make exec QUOI="interprete_registres" SOURCE="prefixe_file"
|
||||
make exec WHAT="compile" SOURCE="program_file_without_extension"
|
||||
```
|
||||
Ceci va interpreter le fichier **prefixe_file.regasm**
|
||||
This will build **program_file_without_extension.c** and generate the memory-oriented assembly file **prefixe_file.memasm**
|
||||
|
||||
#### Charger le programme dans le code VHDL du processeur :
|
||||
#### Interpret a memory-oriented assembly program:
|
||||
``` bash
|
||||
make exec QUOI="load" SOURCE="prefixe_file"
|
||||
make exec WHAT="interprete" SOURCE="program_file_without_extension"
|
||||
```
|
||||
Ceci va injecter le code du fichier **prefixe_file.bin** dans la mémoire d'instruction
|
||||
This will interpret the **program_file_without_extension.memasm**
|
||||
|
||||
#### CrossAssemble a memory-oriented assembly program:
|
||||
``` bash
|
||||
make exec WHAT="cross_assemble" SOURCE="program_file_without_extension"
|
||||
```
|
||||
This will transform **program_file_without_extension.memasm** into **program_file_without_extension.regasm** adding registers management
|
||||
|
||||
#### Interpret a registers-oriented assembly program:
|
||||
``` bash
|
||||
make exec WHAT="interprete_registers" SOURCE="program_file_without_extension"
|
||||
```
|
||||
This will interpret the **program_file_without_extension.regasm**
|
||||
|
||||
#### Load binary program into the processor:
|
||||
``` bash
|
||||
make exec WHAT="load" SOURCE="program_file_without_extension"
|
||||
```
|
||||
This will add binary file **program_file_without_extension.bin** into the processor's instructions memory
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
int lire_tableau() {
|
||||
int tab[5] = {0,0,0,0,0};
|
||||
int read_array() {
|
||||
int my_array[5] = {0,0,0,0,0};
|
||||
|
||||
print("Veuillez saisir \nune valeur :\n");
|
||||
print("Please enter \na value:\n");
|
||||
int val = get();
|
||||
|
||||
int i = 1;
|
||||
|
@ -11,7 +11,7 @@ int lire_tableau() {
|
|||
}
|
||||
}
|
||||
|
||||
int youVeBeenHacked() {
|
||||
int you_have_been_hacked() {
|
||||
print("\0\n\nYOU'VE BEEN HACKED\n\n");
|
||||
print(" (__)\n");
|
||||
print(" (|) (00)\n");
|
||||
|
@ -22,16 +22,16 @@ int youVeBeenHacked() {
|
|||
}
|
||||
}
|
||||
|
||||
int legitimeFunction() {
|
||||
print("Fonction legitime\n");
|
||||
int legitimate_function() {
|
||||
print("Legitimate function\n");
|
||||
}
|
||||
|
||||
int main() {
|
||||
print("Debut du programme\n\n");
|
||||
print("Program begin\n\n");
|
||||
int a = 0;
|
||||
int b = 0;
|
||||
lire_tableau();
|
||||
legitimeFunction();
|
||||
read_array();
|
||||
legitimate_function();
|
||||
print("a=");
|
||||
print(a);
|
||||
print("\n");
|
||||
|
|
Loading…
Reference in a new issue