Skip to content

Commit 9cd9eab

Browse files
committed
Adding Lab 1
1 parent 7b44fe0 commit 9cd9eab

8 files changed

+73
-0
lines changed

README.md

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,76 @@ Secure Programming
4242
- [Fix: Not in a hypervisor partition (HVP=0) (VERR_NEM_NOT_AVAILABLE) or VT-x is disabled in the BIOS for all CPU modes (VERR_VMX_MSR_ALL_VMX_DISABLED)](https://techsupportwhale.com/not-in-a-hypervisor-partition/)
4343
- [Fix: Cannot install Ubuntu in VirtualBox due to "this kernel requires an x86-64 CPU, but only detects an i686 CPU, unable to boot" error](https://askubuntu.com/questions/308937/cannot-install-ubuntu-in-virtualbox-due-to-this-kernel-requires-an-x86-64-cpu)
4444
- [Fix: Installation Step Failed (installing the system) - Kali Linux](https://unix.stackexchange.com/questions/208772/installation-step-failed-installing-the-system-kali-linux)
45+
46+
---
47+
48+
## Lab 1
49+
50+
**Lab 1: Format String
51+
Vulnerabilities and Attacks**
52+
53+
- **Aim:** Perform the following using programming
54+
1) Write a secure program by avoiding vulnerable programming factors
55+
like Eval and printf.
56+
2) Demonstrate Format string vulnerabilities with example
57+
3) Demonstrate Format String exploit with example
58+
59+
- **Format String Program**
60+
61+
<img src="./assets/exp1 program.png" alt="Format String Program" width="600px" >
62+
63+
- The format string program accepts the command line arguments and
64+
parses the input using printf function to display output.
65+
- Three types of payloads given as inputs in the following examples
66+
67+
- Payload 1:
68+
<img src="./assets/Secure Programming Exp1 01.PNG" alt="Format String Program" width="600px" >
69+
- Output of Payload 1
70+
<img src="./assets/Secure Programming Exp1 02.PNG" alt="Format String Program" width="600px" >
71+
- Payload 2:
72+
<img src="./assets/Secure Programming Exp1 11.PNG" alt="Format String Program" width="600px" >
73+
- Output of Payload 2
74+
<img src="./assets/Secure Programming Exp1 12.PNG" alt="Format String Program" width="600px" >
75+
- Payload 3:
76+
<img src="./assets/Secure Programming Exp1 21.PNG" alt="Format String Program" width="600px" >
77+
- Output of Payload 3
78+
<img src="./assets/Secure Programming Exp1 22.PNG" alt="Format String Program" width="600px" >
79+
80+
81+
- **Observation:**
82+
83+
- The Safe Code from the program
84+
- The line printf("%s", argv[1]); in the example is safe, if you compile the program and run it:
85+
- `./main "%s%s%s%s%s%s"`
86+
- The printf in the first line will not interpret the “%s%s%s%s%s%s” in
87+
the input string, and the output will be:
88+
- `“%s%s%s%s%s%s”`
89+
90+
- The Vulnerable Code from the program
91+
- The line printf(argv[1]); in the example is vulnerable, if you compile the program and run it:
92+
- `./main "%s%s%s%s%s%s"`
93+
- The printf in the second line will interpret the %s%s%s%s%s%s in the input string as a reference to string pointers, so it will try to interpret every %s as a pointer to a string, starting from the location of the buffer (probably on the Stack).
94+
- At some point, it will get to an invalid address, and attempting to access it will cause the program to crash.
95+
96+
- Different Payloads
97+
- An attacker can also use this to get information, not just crash the software.
98+
- For example, running:
99+
- `./main "%p %p %p %p %p %p"`
100+
- Will print the lines:
101+
- `%p%p%p%p%p%p
102+
0x7fd084a750000x7fd08484f9e00x7fd08457a3c00xffffffff(nil)0x7ffdcd
103+
0948e8`
104+
- Another example:
105+
- `./main "%x%x%x%x%x%x"`
106+
- Will print the lines:
107+
- `%x%x%x%x%x%x
108+
18bfb000189d59e0187003c0ffffffff0e09496f8`
109+
- The first line is printed from the non-vulnerable version of printf, and the second line from the vulnerable line. The values printed are the values on the stack of my computer at the moment of running this example.
110+
- Also reading and writing to any memory location is possible in some conditions, and even code execution
111+
112+
- **Result:**
113+
- Format string vulnerabilities and exploits are successfully demonstrated by writing a C program with a secure code and a vulnerable code using printf function and string parameters
114+
115+
116+
117+
---

assets/Secure Programming Exp1 01.PNG

32 KB
Loading

assets/Secure Programming Exp1 02.PNG

37.9 KB
Loading

assets/Secure Programming Exp1 11.PNG

32.2 KB
Loading

assets/Secure Programming Exp1 12.PNG

44.8 KB
Loading

assets/Secure Programming Exp1 21.PNG

32.2 KB
Loading

assets/Secure Programming Exp1 22.PNG

45.2 KB
Loading

assets/exp1 program.png

150 KB
Loading

0 commit comments

Comments
 (0)