Understanding the Challenge
CybersecurityBash ScriptingSystem CallsFile PermissionsChallenge
This content is an AI-generated summary. If you encounter any misinformation or problematic content, please report it to cyb.hub@proton.me.
This challenge builds upon the previous Bash - System 1 level, introducing additional complexity. The goal is to read the .passwd
file using the provided C code and a custom bash script.
Key Points
- Familiarize yourself with the functions
setreuid
andsystem
. - Objective: Read the
.passwd
file via the binarych12
. - Approach: Create a custom directory and script to manipulate the
ls
command.
Description of the Challenge
The provided C code is as follows:
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
int main(){
setreuid(geteuid(), geteuid());
system("ls -lA /challenge/app-script/ch12/.passwd");
return 0;
}
Mindset for the Approach
Understand Basic Concepts
- setreuid: Sets the real and effective user IDs of the calling process.
- system: Executes a command specified in the string by calling
/bin/sh
.
Understand the Problem
- The challenge is similar to the previous one but includes the
-lA
option in thels
command. - Objective: Read the
.passwd
file using the binarych12
.
Create the Attack
-
Create a Directory:
- Create a directory in
/tmp
. - Add this directory to the
$PATH
.
- Create a directory in
-
Copy
/bin/cat
:- Copy
/bin/cat
into the newly created directory. - Rename it to
ls
.
- Copy
-
Create a Bash Script:
- Create a bash script named
ls
to executecat
on.passwd
.
- Create a bash script named
Resolution
- The bash script
ls
should ignore the-lA
options by treating them as arguments. - Modify the script to display the contents of
.passwd
.
Learn More
For a deeper understanding, explore the following topics:
- Unix File Permissions: Learn about how file permissions work in Unix-based systems.
- Bash Scripting: Dive into the basics and advanced techniques of bash scripting.
- System Calls: Understand various system calls and their uses in programming.