Welcome to the final part of Module-1 of YoS!!
Finally on to something cooler and sounds like hacking, we will study C programming and x86 assembly for this week (and a half more).
C is a general-purpose programming language like Python. C is compiled language, unlike Python, which is interpreted.
The difference between compiled and interpreted languages is in their methods of execution.
First, a bit of background...
Computers can understand and run only machine instructions, but programmers usually code in high–level programming languages, such as C, Python, or Javascript. This is because high–level programming languages are easier to work with and resemble human languages and mathematical notation. However, computers cannot run the code written in a high–level language and hence, there is a need to translate it into simple machine instructions.
As an aside, an ELF file essentially only stores these machine instructions!! and runs them on your CPU when you execute it through the command line. Assembly, which is also a part of this week's content, is just these machine instructions written down in a human-readable format.
Coming back to the point, to do this translation from programming language to machine instructions, we use compilers and interpreters.
Compilers take a whole program as input and translate it to an executable binary code. The compilation step is required only once. Afterwards, we can run the binary code any number of times. Interpreters read and execute the program at hand instruction by instruction. After being read, each instruction is translated into the machine's binary code and run. Unlike compilers, the interpreters do not produce a binary executable file. Each time we run a program, we invoke the interpreter. It then reads and executes the program one instruction at a time.
C is one of the earliest programming languages but is still in use today. As we have seen in the previous weeks, Linux and Python were both written in C! This makes learning C worthwhile. Also, C provides constructs that map directly to machine instructions, so it is better to learn C alongside Assembly.
Comparison of "Hello world" programs in Python, C and Assembly respectively
NOTE : Do not worry if you don't understand all the details of C and Assembly right away.
A complete understanding is challenging to achieve in a week and a half. We have
two modules [Reverse Engineering and Binary Exploitation] coming up later, which
will deal with these topics again, and you will have a much clearer picture by
then. This week's content aims to teach you only the very basics.
You may choose to watch videos in the crash course playlist or the CS50 videos (longer in duration, but each subtopic is elaborated on and filled with relevant examples)
Crash Course:
- Introduction to C playlist [3 hr 45 mins]
CS50 Introduction to C:
- CS50 - Intro to C [2 hrs 30 mins]
- CS50 - Arrays [2 hrs]
- CS50 - Pointers and Memory [2 hrs 25 mins]
- x86 Assembly: Hello World! [14 mins]
- Comparing C to machine language [10 mins]
- CSeC - Introduction to Assembly | Slides and other files [2 hr 10 mins]
- picoCTF - Flag Shop [15 mins]
- 247 CTF - Impossible Number [4 min]
- picoCTF - Assembly 1 [6 mins]
- picoCTF - Programmers Assemble [10 mins]
We have designed 3 challenges for this part:
- emulator [C programming challenge]
- challenge-asm [2 challenges in this folder]
- *challenge_tail_recursion [1 assembly challenge in this folder] Note that you must use unicorn Version: 2.0.0rc7 for running this locally because other unicorn versions seem to behave differently for some reason!
* Solving this challenge successfully makes you eligible for one free treat from Owl-A
All in all, you would need to solve atleast 2 challenges throughtout the module but we encourage that you solve all of these, for things are more fun that way 😊.
Make sure you go through the respective README.md
files before jumping into the challenge. Have fun! 😁
Discussions among mentees are encouraged and we request you to use our Discord Server for the same.
Created with ❤️ by CSec