Binary Exploitation 201
Binary Exploitation 201
Exploitation
201
Step 2: After registering for a picoCTF account, log in to your account and
register for CanHack 2021 event as a teacher.
PicoCTF Registration - For teachers/supervisors
Method 1: Select “Batch Register Users”, this open will generate accounts (usernames,
passwords) for the number of students you specify. The usernames can then be shared
with your students and they can use this information to login.
Method 2: Students can create their own usernames and you can share an invite code
with them to join your classroom.
PicoCTF Registration - For teachers/supervisors
Step 4: Collect all usernames and teams that your students will be using on the PicoCTF
platform and fill out this excel template here: This template will have all the team names
and the corresponding student's usernames.
Step 5: Upload the excel sheet with the team names and usernames.
Step 1: After registering for a picoCTF account, log in to your account and register for CanHack
2021 event as a student. If your teacher will be providing the usernames use the username and
temporary password provided and update it.
Step 2: Once you have decided on the team you will join, allocate one teammate to create the
team on the picoCTF platform. Under the profile section, students should see the team
management section. ONE student from the team should create the desired team name and
password.
Step 3: Once the team is created, other students can then go on their own profiles and sign into
that team as well. (Once a team is joined you cannot leave the team or join another)
Step 4: Teams should inform their teachers, parents or supervisors of the usernames, and team
names so their teacher, parent or supervisor can complete Step 4 above.
What is Binary Exploitation
8 bytes
P A S S W O R D 1 2
0 1 2 3 4 5 6 7 8 9
Buffer Overflow Continued..
● If an attacker understands how memory and binary works then they can craft a
code that can be interpreted by the computer and executed
● If it overflows into an instruction, the computer might begin executing it
● Many programs that are written in C, C++ and in other languages are susceptible
to these attacks
● They lack built-in protection against accessing data anywhere in memory space
● Don’t automatically check whether inputted data is within its bounds
Dangerous C functions
1. strcpy (does not specify a maximum length while copying)
2. strncpy
3. strcat
4. printf
5. sprint (format string vulnerability)
6. scanf
7. fgets
8. gets
9. getws
10. memcpy
11. memmove
Attacker has
overwritten the return
address, which now
goes to the location
specified and
executes the
attackers code
Source: Wikipedia
NOP Sled
char buf[BUFSIZE];
return 0;
}
Shell code
\x31\xc0\x50\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x89\xc1\x89\xc2\xb0\x
0b\xcd\x80\x31\xc0\x40\xcd\x80
Slippery Shellcode Solution
Write a program to print out NOP so it overrides the offset and executes the
shellcode
DB, the GNU Project debugger, allows you to see what is going on `inside' another program while it
executes -- or what another program was doing at the moment it crashed.
GDB can do four main kinds of things (plus other things in support of these) to help you catch bugs in the
act:
● Start your program, specifying anything that might affect its behavior.
● Make your program stop on specified conditions.
● Examine what has happened, when your program has stopped.
● Change things in your program, so you can experiment with correcting the effects of one bug and go
on to learn about another.
Source: https://www.gnu.org/software/gdb/
GDB commands
Overflow 1 }
fgets(buf,FLAGSIZE,f);
printf(buf);
Setvbuff - Buffer is set up
● IDS/IPS
● Secure code (boundary checking,
input validation)
● Canary
● Mark areas of memory as NX/XD
(No execution/execute disable),
processor will not execute any code
residing in any of these areas
Resources
https://dmz.ryerson.ca/canhack-resource-hub
https://owasp.org/www-community/vulnerabilities/Buffer_Overflow
https://www.tenouk.com/Bufferoverflowc/Bufferoverflow2a.html
https://www.exploit-db.com/docs/english/13019-shell-code-for-beginners.pdf
https://github.com/Gallopsled/pwntools
https://tcode2k16.github.io/blog/posts/picoctf-2019-writeup/binary-exploitation/#solution
https://ctf.samsongama.com/ctf/index.html
Thank You
Questions?