Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
SCN - Environment Variable and Set-UID Lab
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
k2-colambatant
SCN - Environment Variable and Set-UID Lab
Commits
de270944
Commit
de270944
authored
3 years ago
by
k2-colambatant
Browse files
Options
Downloads
Patches
Plain Diff
- Code snippet used for Task 9;
parent
6e453b12
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
Task 9 - Capability Leaking/task9.c
+35
-0
35 additions, 0 deletions
Task 9 - Capability Leaking/task9.c
with
35 additions
and
0 deletions
Task 9 - Capability Leaking/task9.c
0 → 100644
+
35
−
0
View file @
de270944
#include
<stdio.h>
#include
<stdlib.h>
#include
<fcntl.h>
#include
<unistd.h>
void
main
()
{
int
fd
;
/* Assume that /etc/zzz is an important system file,
* and it is owned by root with permission 0644.
* Before running this program, you should create
* the file /etc/zzz first. */
setuid
(
getuid
());
fd
=
open
(
"/etc/zzz"
,
O_RDWR
|
O_APPEND
);
if
(
fd
==
-
1
)
{
printf
(
"Cannot open /etc/zzz
\n
"
);
exit
(
0
);
}
//setuid(getuid());
/* Simulate the tasks conducted by the program */
sleep
(
1
);
/* After the task, the root privileges are no longer
* needed, it’s time to relinquish the root privileges
* permanently. */
//setuid(getuid()); /* getuid() returns the real uid */
if
(
fork
())
{
/* In the parent process */
close
(
fd
);
exit
(
0
);
}
else
{
/* in the child process */
/* Now, assume that the child process is compromised,
* malicious attackers have injected the following
* statements into this process */
write
(
fd
,
"Malicious Data
\n
"
,
15
);
close
(
fd
);
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment