SlideShare a Scribd company logo
Secure Coding in C and C++
ch8 - File I/O (1)
cmj
Outline
● 8.1 File I/O Basic
● 8.2 File I/O Interfaces
● 8.3 Access Control
● 8.4 File Identification
● 8.5 Race Conditions
● 8.6 Mitigation Strategies
File I/O Basic
● What’s the file system?
○ A hierarchical structure which non-terminal nodes
are directory and terminal nodes are files.
● Many file systems
○ Older system: MS-DOS, ext2
○ journaling file system: ext4
○ Distributed File System: gluster, GFS, Ceph
○ Network File System: SMB, AFP
● Special Files
○ Regular File / Directory / Link
○ Pipe / Socket
○ Char device / Block device
File I/O Interfaces
● File I/O need <stdio.h> in C
○ Byte or char type I/O
○ Wide-character type I/O
● Using <iostream> in C++
○ Wide-character use
wifstream/wofstream/wiofstream/wfstream
File I/O Interfaces (Cont’d)
● Data Stream
○ FILE *
○ fopen: mode (r/w/a/b/+)
○ w is added in C11
■ Failed if file is already existed.
● POSIX way
○ File descriptor, from 0 to OPEN_MAX
■ sysconf(_SC_OPEN_MAX);
○ fopen is wrappered as open
Access Control
● File in UNIX system has UID and GID
○ Read(r) / Write(w) / Execute(x)
○ std.id(s): /usr/bin/passwd
■ Execute as the owner/group.
○ sticky(t): usually used in /tmp
■ Only owner or root can remove.
■ Should run on physical memory only.
IDs
● ID
○ RUID (real user ID)
○ EUID (effective user ID)
○ SSUID (saved set-user-ID)
● setuid()
○ Need root but cannot su -
○ setuid workable for RUID/SSUID
● Processes instantiated by
○ system / fork / exec
○ Inherit RUID and EUID
IDs (Cont’d)
● wall
○ -rwxr-sr-x 1 root tty /usr/bin/wall
○ crw--w---- 1 root tty /dev/tty1
● passwd
○ -rwsr-xr-x 1 root root /usr/bin/passwd
Vulnerabilities
● Run with elevated privileges and access
files
○ Chance to exploit you program.
○ OpenSSH:
■ open copyright file with root privileges.
■ copyright=/etc/shadow
● setuid program carry significant risk
○ Do anything the owner of file is allowed
○ If owner is root, everything is possible.
To Be Continue...

More Related Content

Viewers also liked

HoneyCon 2014
HoneyCon 2014HoneyCon 2014
HoneyCon 2014
Chia-Hao Tsai
 
Passwd crack introduction
Passwd crack   introductionPasswd crack   introduction
Passwd crack introduction
Chia-Hao Tsai
 
Security coding c and c++ ch8(2)
Security coding c and c++   ch8(2)Security coding c and c++   ch8(2)
Security coding c and c++ ch8(2)
Chia-Hao Tsai
 
Build web server
Build web serverBuild web server
Build web server
Chia-Hao Tsai
 
Learn Python in 30 min - 4
Learn Python in 30 min - 4Learn Python in 30 min - 4
Learn Python in 30 min - 4
Chia-Hao Tsai
 
Rootkit 102 - Kernel-Based Rootkit
Rootkit 102 - Kernel-Based RootkitRootkit 102 - Kernel-Based Rootkit
Rootkit 102 - Kernel-Based Rootkit
Chia-Hao Tsai
 
Learn python 1
Learn python 1Learn python 1
Learn python 1
Chia-Hao Tsai
 
ELF 101
ELF 101ELF 101
ELF 101
Chia-Hao Tsai
 
State of the Word 2011
State of the Word 2011State of the Word 2011
State of the Word 2011
photomatt
 

Viewers also liked (9)

HoneyCon 2014
HoneyCon 2014HoneyCon 2014
HoneyCon 2014
 
Passwd crack introduction
Passwd crack   introductionPasswd crack   introduction
Passwd crack introduction
 
Security coding c and c++ ch8(2)
Security coding c and c++   ch8(2)Security coding c and c++   ch8(2)
Security coding c and c++ ch8(2)
 
Build web server
Build web serverBuild web server
Build web server
 
Learn Python in 30 min - 4
Learn Python in 30 min - 4Learn Python in 30 min - 4
Learn Python in 30 min - 4
 
Rootkit 102 - Kernel-Based Rootkit
Rootkit 102 - Kernel-Based RootkitRootkit 102 - Kernel-Based Rootkit
Rootkit 102 - Kernel-Based Rootkit
 
Learn python 1
Learn python 1Learn python 1
Learn python 1
 
ELF 101
ELF 101ELF 101
ELF 101
 
State of the Word 2011
State of the Word 2011State of the Word 2011
State of the Word 2011
 

Similar to Security coding c and c++ ch8 (1)

Prog ii
Prog iiProg ii
Prog ii
Sanchit Patil
 
TLPI Chapter 14 File Systems
TLPI Chapter 14 File SystemsTLPI Chapter 14 File Systems
TLPI Chapter 14 File Systems
Shu-Yu Fu
 
An Introduction To Linux
An Introduction To LinuxAn Introduction To Linux
An Introduction To Linux
Ishan A B Ambanwela
 
When ACLs Attack
When ACLs AttackWhen ACLs Attack
When ACLs Attack
andy_leonard
 
Linux tech talk
Linux tech talkLinux tech talk
Linux tech talk
Prince Raj
 
Integrity and Security in Filesystems
Integrity and Security in FilesystemsIntegrity and Security in Filesystems
Integrity and Security in Filesystems
Conferencias FIST
 
CS50x Permissions, Files, Users
CS50x Permissions, Files, UsersCS50x Permissions, Files, Users
CS50x Permissions, Files, Users
Fábio Emilio Costa
 
Tips and Tricks for Increased Development Efficiency
Tips and Tricks for Increased Development EfficiencyTips and Tricks for Increased Development Efficiency
Tips and Tricks for Increased Development Efficiency
Olivier Bourgeois
 
Linux fundamental - Chap 10 fs
Linux fundamental - Chap 10 fsLinux fundamental - Chap 10 fs
Linux fundamental - Chap 10 fs
Kenny (netman)
 
FreeBSD Portscamp, Kuala Lumpur 2016
FreeBSD Portscamp, Kuala Lumpur 2016FreeBSD Portscamp, Kuala Lumpur 2016
FreeBSD Portscamp, Kuala Lumpur 2016
Muhammad Moinur Rahman
 
Fun with FUSE
Fun with FUSEFun with FUSE
Fun with FUSE
Kernel TLV
 
Automotive Grade Linux and systemd
Automotive Grade Linux and systemdAutomotive Grade Linux and systemd
Automotive Grade Linux and systemd
Alison Chaiken
 
Native Android Userspace part of the Embedded Android Workshop at Linaro Conn...
Native Android Userspace part of the Embedded Android Workshop at Linaro Conn...Native Android Userspace part of the Embedded Android Workshop at Linaro Conn...
Native Android Userspace part of the Embedded Android Workshop at Linaro Conn...
Opersys inc.
 
What you most likely did not know about sudo…
What you most likely did not know about sudo…What you most likely did not know about sudo…
What you most likely did not know about sudo…
All Things Open
 
Description of GRUB 2
Description of GRUB 2Description of GRUB 2
Description of GRUB 2
iamumr
 
Linux redhat final
Linux redhat finalLinux redhat final
Linux redhat final
chbashir22268
 
Intro to linux systems administration
Intro to linux systems administrationIntro to linux systems administration
Intro to linux systems administration
Padam Banthia
 
SFO15-200: Linux kernel generic TEE driver
SFO15-200: Linux kernel generic TEE driverSFO15-200: Linux kernel generic TEE driver
SFO15-200: Linux kernel generic TEE driver
Linaro
 
Bsdtw17: george neville neil: realities of dtrace on free-bsd
Bsdtw17: george neville neil: realities of dtrace on free-bsdBsdtw17: george neville neil: realities of dtrace on free-bsd
Bsdtw17: george neville neil: realities of dtrace on free-bsd
Scott Tsai
 
Diy containers
Diy containersDiy containers
Diy containers
Georgi Sabev
 

Similar to Security coding c and c++ ch8 (1) (20)

Prog ii
Prog iiProg ii
Prog ii
 
TLPI Chapter 14 File Systems
TLPI Chapter 14 File SystemsTLPI Chapter 14 File Systems
TLPI Chapter 14 File Systems
 
An Introduction To Linux
An Introduction To LinuxAn Introduction To Linux
An Introduction To Linux
 
When ACLs Attack
When ACLs AttackWhen ACLs Attack
When ACLs Attack
 
Linux tech talk
Linux tech talkLinux tech talk
Linux tech talk
 
Integrity and Security in Filesystems
Integrity and Security in FilesystemsIntegrity and Security in Filesystems
Integrity and Security in Filesystems
 
CS50x Permissions, Files, Users
CS50x Permissions, Files, UsersCS50x Permissions, Files, Users
CS50x Permissions, Files, Users
 
Tips and Tricks for Increased Development Efficiency
Tips and Tricks for Increased Development EfficiencyTips and Tricks for Increased Development Efficiency
Tips and Tricks for Increased Development Efficiency
 
Linux fundamental - Chap 10 fs
Linux fundamental - Chap 10 fsLinux fundamental - Chap 10 fs
Linux fundamental - Chap 10 fs
 
FreeBSD Portscamp, Kuala Lumpur 2016
FreeBSD Portscamp, Kuala Lumpur 2016FreeBSD Portscamp, Kuala Lumpur 2016
FreeBSD Portscamp, Kuala Lumpur 2016
 
Fun with FUSE
Fun with FUSEFun with FUSE
Fun with FUSE
 
Automotive Grade Linux and systemd
Automotive Grade Linux and systemdAutomotive Grade Linux and systemd
Automotive Grade Linux and systemd
 
Native Android Userspace part of the Embedded Android Workshop at Linaro Conn...
Native Android Userspace part of the Embedded Android Workshop at Linaro Conn...Native Android Userspace part of the Embedded Android Workshop at Linaro Conn...
Native Android Userspace part of the Embedded Android Workshop at Linaro Conn...
 
What you most likely did not know about sudo…
What you most likely did not know about sudo…What you most likely did not know about sudo…
What you most likely did not know about sudo…
 
Description of GRUB 2
Description of GRUB 2Description of GRUB 2
Description of GRUB 2
 
Linux redhat final
Linux redhat finalLinux redhat final
Linux redhat final
 
Intro to linux systems administration
Intro to linux systems administrationIntro to linux systems administration
Intro to linux systems administration
 
SFO15-200: Linux kernel generic TEE driver
SFO15-200: Linux kernel generic TEE driverSFO15-200: Linux kernel generic TEE driver
SFO15-200: Linux kernel generic TEE driver
 
Bsdtw17: george neville neil: realities of dtrace on free-bsd
Bsdtw17: george neville neil: realities of dtrace on free-bsdBsdtw17: george neville neil: realities of dtrace on free-bsd
Bsdtw17: george neville neil: realities of dtrace on free-bsd
 
Diy containers
Diy containersDiy containers
Diy containers
 

More from Chia-Hao Tsai

[2019.05] HST - RegEx 101 ~ 1001
[2019.05] HST - RegEx 101 ~ 1001[2019.05] HST - RegEx 101 ~ 1001
[2019.05] HST - RegEx 101 ~ 1001
Chia-Hao Tsai
 
[2019.02.16] hst - orm
[2019.02.16] hst  - orm[2019.02.16] hst  - orm
[2019.02.16] hst - orm
Chia-Hao Tsai
 
[2019.01.12] hst iptables 101 to 301
[2019.01.12] hst   iptables 101 to 301[2019.01.12] hst   iptables 101 to 301
[2019.01.12] hst iptables 101 to 301
Chia-Hao Tsai
 
[2018.12.15] hst python object 102
[2018.12.15] hst   python object 102[2018.12.15] hst   python object 102
[2018.12.15] hst python object 102
Chia-Hao Tsai
 
[2018.11.16] Python Object 101
[2018.11.16]  Python Object 101[2018.11.16]  Python Object 101
[2018.11.16] Python Object 101
Chia-Hao Tsai
 
[2017.03.18] hst binary training part 1
[2017.03.18] hst binary training   part 1[2017.03.18] hst binary training   part 1
[2017.03.18] hst binary training part 1
Chia-Hao Tsai
 
Rootkit 101 - 2nd Edition
Rootkit 101 - 2nd EditionRootkit 101 - 2nd Edition
Rootkit 101 - 2nd Edition
Chia-Hao Tsai
 
Maker - WiFi AP
Maker - WiFi APMaker - WiFi AP
Maker - WiFi AP
Chia-Hao Tsai
 
Learn python in 30 min - 3
Learn python in 30 min - 3Learn python in 30 min - 3
Learn python in 30 min - 3
Chia-Hao Tsai
 
Learn python 2 - Real World Case
Learn python 2 - Real World CaseLearn python 2 - Real World Case
Learn python 2 - Real World Case
Chia-Hao Tsai
 

More from Chia-Hao Tsai (11)

[2019.05] HST - RegEx 101 ~ 1001
[2019.05] HST - RegEx 101 ~ 1001[2019.05] HST - RegEx 101 ~ 1001
[2019.05] HST - RegEx 101 ~ 1001
 
[2019.02.16] hst - orm
[2019.02.16] hst  - orm[2019.02.16] hst  - orm
[2019.02.16] hst - orm
 
[2019.01.12] hst iptables 101 to 301
[2019.01.12] hst   iptables 101 to 301[2019.01.12] hst   iptables 101 to 301
[2019.01.12] hst iptables 101 to 301
 
[2018.12.15] hst python object 102
[2018.12.15] hst   python object 102[2018.12.15] hst   python object 102
[2018.12.15] hst python object 102
 
[2018.11.16] Python Object 101
[2018.11.16]  Python Object 101[2018.11.16]  Python Object 101
[2018.11.16] Python Object 101
 
[2017.03.18] hst binary training part 1
[2017.03.18] hst binary training   part 1[2017.03.18] hst binary training   part 1
[2017.03.18] hst binary training part 1
 
Rootkit 101 - 2nd Edition
Rootkit 101 - 2nd EditionRootkit 101 - 2nd Edition
Rootkit 101 - 2nd Edition
 
Maker - WiFi AP
Maker - WiFi APMaker - WiFi AP
Maker - WiFi AP
 
Learn python in 30 min - 3
Learn python in 30 min - 3Learn python in 30 min - 3
Learn python in 30 min - 3
 
Learn python 2 - Real World Case
Learn python 2 - Real World CaseLearn python 2 - Real World Case
Learn python 2 - Real World Case
 
Rootkit tw(0224)
Rootkit tw(0224)Rootkit tw(0224)
Rootkit tw(0224)
 

Recently uploaded

“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
Edge AI and Vision Alliance
 
[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
Jason Yip
 
A Deep Dive into ScyllaDB's Architecture
A Deep Dive into ScyllaDB's ArchitectureA Deep Dive into ScyllaDB's Architecture
A Deep Dive into ScyllaDB's Architecture
ScyllaDB
 
Dandelion Hashtable: beyond billion requests per second on a commodity server
Dandelion Hashtable: beyond billion requests per second on a commodity serverDandelion Hashtable: beyond billion requests per second on a commodity server
Dandelion Hashtable: beyond billion requests per second on a commodity server
Antonios Katsarakis
 
Demystifying Knowledge Management through Storytelling
Demystifying Knowledge Management through StorytellingDemystifying Knowledge Management through Storytelling
Demystifying Knowledge Management through Storytelling
Enterprise Knowledge
 
Biomedical Knowledge Graphs for Data Scientists and Bioinformaticians
Biomedical Knowledge Graphs for Data Scientists and BioinformaticiansBiomedical Knowledge Graphs for Data Scientists and Bioinformaticians
Biomedical Knowledge Graphs for Data Scientists and Bioinformaticians
Neo4j
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
ssuserfac0301
 
What is an RPA CoE? Session 1 – CoE Vision
What is an RPA CoE?  Session 1 – CoE VisionWhat is an RPA CoE?  Session 1 – CoE Vision
What is an RPA CoE? Session 1 – CoE Vision
DianaGray10
 
Christine's Product Research Presentation.pptx
Christine's Product Research Presentation.pptxChristine's Product Research Presentation.pptx
Christine's Product Research Presentation.pptx
christinelarrosa
 
"Choosing proper type of scaling", Olena Syrota
"Choosing proper type of scaling", Olena Syrota"Choosing proper type of scaling", Olena Syrota
"Choosing proper type of scaling", Olena Syrota
Fwdays
 
Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024
Jason Packer
 
Northern Engraving | Nameplate Manufacturing Process - 2024
Northern Engraving | Nameplate Manufacturing Process - 2024Northern Engraving | Nameplate Manufacturing Process - 2024
Northern Engraving | Nameplate Manufacturing Process - 2024
Northern Engraving
 
AppSec PNW: Android and iOS Application Security with MobSF
AppSec PNW: Android and iOS Application Security with MobSFAppSec PNW: Android and iOS Application Security with MobSF
AppSec PNW: Android and iOS Application Security with MobSF
Ajin Abraham
 
"Frontline Battles with DDoS: Best practices and Lessons Learned", Igor Ivaniuk
"Frontline Battles with DDoS: Best practices and Lessons Learned",  Igor Ivaniuk"Frontline Battles with DDoS: Best practices and Lessons Learned",  Igor Ivaniuk
"Frontline Battles with DDoS: Best practices and Lessons Learned", Igor Ivaniuk
Fwdays
 
GNSS spoofing via SDR (Criptored Talks 2024)
GNSS spoofing via SDR (Criptored Talks 2024)GNSS spoofing via SDR (Criptored Talks 2024)
GNSS spoofing via SDR (Criptored Talks 2024)
Javier Junquera
 
Essentials of Automations: Exploring Attributes & Automation Parameters
Essentials of Automations: Exploring Attributes & Automation ParametersEssentials of Automations: Exploring Attributes & Automation Parameters
Essentials of Automations: Exploring Attributes & Automation Parameters
Safe Software
 
9 CEO's who hit $100m ARR Share Their Top Growth Tactics Nathan Latka, Founde...
9 CEO's who hit $100m ARR Share Their Top Growth Tactics Nathan Latka, Founde...9 CEO's who hit $100m ARR Share Their Top Growth Tactics Nathan Latka, Founde...
9 CEO's who hit $100m ARR Share Their Top Growth Tactics Nathan Latka, Founde...
saastr
 
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development ProvidersYour One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
akankshawande
 
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdfHow to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
Chart Kalyan
 
Session 1 - Intro to Robotic Process Automation.pdf
Session 1 - Intro to Robotic Process Automation.pdfSession 1 - Intro to Robotic Process Automation.pdf
Session 1 - Intro to Robotic Process Automation.pdf
UiPathCommunity
 

Recently uploaded (20)

“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
 
[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
 
A Deep Dive into ScyllaDB's Architecture
A Deep Dive into ScyllaDB's ArchitectureA Deep Dive into ScyllaDB's Architecture
A Deep Dive into ScyllaDB's Architecture
 
Dandelion Hashtable: beyond billion requests per second on a commodity server
Dandelion Hashtable: beyond billion requests per second on a commodity serverDandelion Hashtable: beyond billion requests per second on a commodity server
Dandelion Hashtable: beyond billion requests per second on a commodity server
 
Demystifying Knowledge Management through Storytelling
Demystifying Knowledge Management through StorytellingDemystifying Knowledge Management through Storytelling
Demystifying Knowledge Management through Storytelling
 
Biomedical Knowledge Graphs for Data Scientists and Bioinformaticians
Biomedical Knowledge Graphs for Data Scientists and BioinformaticiansBiomedical Knowledge Graphs for Data Scientists and Bioinformaticians
Biomedical Knowledge Graphs for Data Scientists and Bioinformaticians
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
 
What is an RPA CoE? Session 1 – CoE Vision
What is an RPA CoE?  Session 1 – CoE VisionWhat is an RPA CoE?  Session 1 – CoE Vision
What is an RPA CoE? Session 1 – CoE Vision
 
Christine's Product Research Presentation.pptx
Christine's Product Research Presentation.pptxChristine's Product Research Presentation.pptx
Christine's Product Research Presentation.pptx
 
"Choosing proper type of scaling", Olena Syrota
"Choosing proper type of scaling", Olena Syrota"Choosing proper type of scaling", Olena Syrota
"Choosing proper type of scaling", Olena Syrota
 
Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024
 
Northern Engraving | Nameplate Manufacturing Process - 2024
Northern Engraving | Nameplate Manufacturing Process - 2024Northern Engraving | Nameplate Manufacturing Process - 2024
Northern Engraving | Nameplate Manufacturing Process - 2024
 
AppSec PNW: Android and iOS Application Security with MobSF
AppSec PNW: Android and iOS Application Security with MobSFAppSec PNW: Android and iOS Application Security with MobSF
AppSec PNW: Android and iOS Application Security with MobSF
 
"Frontline Battles with DDoS: Best practices and Lessons Learned", Igor Ivaniuk
"Frontline Battles with DDoS: Best practices and Lessons Learned",  Igor Ivaniuk"Frontline Battles with DDoS: Best practices and Lessons Learned",  Igor Ivaniuk
"Frontline Battles with DDoS: Best practices and Lessons Learned", Igor Ivaniuk
 
GNSS spoofing via SDR (Criptored Talks 2024)
GNSS spoofing via SDR (Criptored Talks 2024)GNSS spoofing via SDR (Criptored Talks 2024)
GNSS spoofing via SDR (Criptored Talks 2024)
 
Essentials of Automations: Exploring Attributes & Automation Parameters
Essentials of Automations: Exploring Attributes & Automation ParametersEssentials of Automations: Exploring Attributes & Automation Parameters
Essentials of Automations: Exploring Attributes & Automation Parameters
 
9 CEO's who hit $100m ARR Share Their Top Growth Tactics Nathan Latka, Founde...
9 CEO's who hit $100m ARR Share Their Top Growth Tactics Nathan Latka, Founde...9 CEO's who hit $100m ARR Share Their Top Growth Tactics Nathan Latka, Founde...
9 CEO's who hit $100m ARR Share Their Top Growth Tactics Nathan Latka, Founde...
 
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development ProvidersYour One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
 
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdfHow to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
 
Session 1 - Intro to Robotic Process Automation.pdf
Session 1 - Intro to Robotic Process Automation.pdfSession 1 - Intro to Robotic Process Automation.pdf
Session 1 - Intro to Robotic Process Automation.pdf
 

Security coding c and c++ ch8 (1)

  • 1. Secure Coding in C and C++ ch8 - File I/O (1) cmj
  • 2. Outline ● 8.1 File I/O Basic ● 8.2 File I/O Interfaces ● 8.3 Access Control ● 8.4 File Identification ● 8.5 Race Conditions ● 8.6 Mitigation Strategies
  • 3. File I/O Basic ● What’s the file system? ○ A hierarchical structure which non-terminal nodes are directory and terminal nodes are files. ● Many file systems ○ Older system: MS-DOS, ext2 ○ journaling file system: ext4 ○ Distributed File System: gluster, GFS, Ceph ○ Network File System: SMB, AFP ● Special Files ○ Regular File / Directory / Link ○ Pipe / Socket ○ Char device / Block device
  • 4. File I/O Interfaces ● File I/O need <stdio.h> in C ○ Byte or char type I/O ○ Wide-character type I/O ● Using <iostream> in C++ ○ Wide-character use wifstream/wofstream/wiofstream/wfstream
  • 5. File I/O Interfaces (Cont’d) ● Data Stream ○ FILE * ○ fopen: mode (r/w/a/b/+) ○ w is added in C11 ■ Failed if file is already existed. ● POSIX way ○ File descriptor, from 0 to OPEN_MAX ■ sysconf(_SC_OPEN_MAX); ○ fopen is wrappered as open
  • 6. Access Control ● File in UNIX system has UID and GID ○ Read(r) / Write(w) / Execute(x) ○ std.id(s): /usr/bin/passwd ■ Execute as the owner/group. ○ sticky(t): usually used in /tmp ■ Only owner or root can remove. ■ Should run on physical memory only.
  • 7. IDs ● ID ○ RUID (real user ID) ○ EUID (effective user ID) ○ SSUID (saved set-user-ID) ● setuid() ○ Need root but cannot su - ○ setuid workable for RUID/SSUID ● Processes instantiated by ○ system / fork / exec ○ Inherit RUID and EUID
  • 8. IDs (Cont’d) ● wall ○ -rwxr-sr-x 1 root tty /usr/bin/wall ○ crw--w---- 1 root tty /dev/tty1 ● passwd ○ -rwsr-xr-x 1 root root /usr/bin/passwd
  • 9. Vulnerabilities ● Run with elevated privileges and access files ○ Chance to exploit you program. ○ OpenSSH: ■ open copyright file with root privileges. ■ copyright=/etc/shadow ● setuid program carry significant risk ○ Do anything the owner of file is allowed ○ If owner is root, everything is possible.