SlideShare a Scribd company logo
1 of 62
Soumitra Bhattacharyya 
Engineering Manager- Sling Media Ltd. 
website : www.slingmedia.com 
Email : soumitrab@slingmedia.com 
Linkedin : http://www.linkedin.com/in/soumitra001 
1
We live in un-trust worthy 
world of technology usage. 
Can we afford security like this? 
2
1986–1995 
• LAN environment 
• First PC virus 
• Motivation: damage 
1995–2003 
• Internet Era 
• “Big Worms” 
• Motivation: damage 
2004+ 
• OS, DB attacks 
• Spyware, Spam 
• Motivation: Financial 
2006+ 
• Targeted attacks 
• Social engineering 
• Financial + Political 
 Cost of U.S. 
cybercrime: 
About $70B 
Source: U.S. Government Accountability Office (GAO), FBI 
2009+ 
• Embedded devices 
• Virus , data theft , content theft 
• Damage , financial 
3
Trend of cyber crime reported over the years 
4
What are fraudsters looking for? 
5
Need for security in devices 
 Devices getting integrated into personal and 
commercial networks 
 Consumer devices are ubiquitous 
 Pervasive use of Wireless communication 
 Portable devices communicate with changing 
network conditions 
 Gadgets can get stolen making them physically 
accessible . 
6
7
8
An innocuous hack 
No device is secure 
9
Threats vary with the type of 
device and a single solution cannot 
be applied to all 
10
Need for Security 
The threats are endless 
11
Threats in a device 
 Theft of data ,keys and privacy 
 Loss of data consistency 
 Altering device firmware 
 Copy of digital content 
 Breaking access control 
12
Embedded devices have different 
challenges compared to their 
desktop counterparts. 
13
Design challenges 
 Devices are constrained on their 
resources and capabilities 
 Defense mechanisms should not alter the 
response time of their key function 
 Physical accessibility of devices call for 
solutions different from ones applied to 
traditional systems 
14
Design challenges 
 Security concerns cannot be solved in a 
single abstraction layer of software 
 Software on devices becoming complex 
 Quick time to market and increased cost 
need simple yet robust solutions 
15
Security should be part of product definition 
16
17 
Security requirements - Example 
 All password and user data should be encrypted 
using 128bit AES 
 User and device should be authenticated before 
allowing streaming session 
 Device should use https for all transactions with the 
server 
 XXX 128 bit encryption should be used for content 
security 
 ATSC channels need not be protected.
What are the weak links intruders 
looking for ? 
18
Areas prone to attack 
 Logical threats aiming to modify 
device firmware 
 Threats due to weakness in 
design and implementation 
 Unhandled system errors 
19
20
21
22
Consequences for the device 
Buffer 
Overflows 
Arithmetic 
error 
System 
crash 
Changed 
execution 
flow 
Data Theft 
Malware 
injection 
Consequences 
23
Business consequences 
Products 
out of 
market 
Loss of 
reputation 
Financial 
loss 
Lawsuits 
24
Basic solutions to security issues 
25
Core problems with ‘C’ language 
26 
 Language has no consideration for 
security 
 There are functions that can be used in 
unsecure way 
 Dynamic memory allocation needs careful 
manipulation
Core problems with ‘C’ language 
27 
Vulnerable 
Function 
Safe Version 
strcpy() strncpy() & explicit null 
termination 
strcat() strncat()(destination size–1) 
sprintf() snprintf() 
scanf() 
family 
scanf() (specify the maximum) 
length) 
getc() / 
getchar() 
This function can be 
vulnerable if used in a loop.
Unsecure program 
int func( char * input) 
{ 
char local [10]; 
int i=0; 
while (*input !=‘0’) 
{ 
local[i++]=*input++; 
} 
return 0; 
} 
NO “NULL” CHECK 
NO “Length of input “CHECK 
28
Secure programming 
A more appropriate program would be : 
int func( char * input) 
{ 
if((*input !=NULL) && (strlen(input) <=10)) 
{ 
…… 
……………. 
} 
} 
29 
Return appropriately based on error
Reducing attack at the entry 
point is as important as trying 
to get the code right 
30
Input parameter validation 
 Perform validation at all inputs across 
modules 
 Assume all inputs are malicious 
 Reject data when in doubt 
 Parse the characters , commands and 
escape sequences 
31
Input parameter validation 
 Check input data size 
 Validate email construct 
 Evaluate URL 
 Prevent attack from un- formatted strings 
32
Checking constructs 
void decode_file(char *buffer) { 
if(*buffer == 0xff && *(buffer+1)==0xd8) 
hw_decode_jpeg(buffer); 
else 
“ Invalid JPEG file” } 
If invalid jpeg file is passed , decoder will fail 
33
Arithmetic overflow 
int ConcatBuffers(char *buf1, char *buf2, 
size_t len1, size_t len2){ 
char buf[0xFF]; 
if((len1 + len2) > 0xFF) 
return -1; 
memcpy(buf, buf1, len1); 
memcpy(buf + len1, buf2, len2); 
// do stuff with buf 
return 0; 
len1 
len2 
0x103 
+ 0xFFFFFFFC 
0xFF 
Both memcpy functions 
attempt to copy >255 bytes 
34
Memory management 
 Always free() dynamically allocated memory 
after it is not needed 
 Set the free pointer to NULL 
 Failure to release memory is problematic 
on embedded devices with limited memory 
Attackers can use memory 
vulnerabilities to damage operation of 
device 35
Error handling principles 
 Every error should be handled in a graceful 
way 
 At lowest level (e.g. drivers) try to recover from 
error 
 Internal errors should not be reported to users 
 Disable core dumps , stack trace , diagnostic 
information 
36
Safe initialization 
 Initialize variables and file descriptors before 
using them. 
 Initialize and limit the use of env variables 
 Avoid passing data using env variables 
 Avoid execution of program at high privileges 
37
Safe initialization 
int vuln_fn(int a) { 
unsigned int result; 
if (a > 0) { 
result = 256 % result; 
} 
return result; 
} 
uninitialized 
variable 
Potential security bugs can creep in 
through uninitialized variable usage 
38
Compiler warnings 
 Warnings are first level of defense against any 
security flaw 
 Compiler warnings are effective at detecting 
programming flaws 
 It can catch bugs which are hard to find during 
testing. 
Compile with the highest level of 
warning set as error 
39
Flag setting for compilers 
GNU C compiler : 
-Wall : enable all compiler warnings 
-Werror : treat compiler warnings as errors 
ARM Developer Suite C compiler: 
-E+c : enable all implicit cast errors 
-E+l : errors on linkage disagreements 
-fv : reports unused declarations 
… 
Greenhills Embedded MIPS compiler: 
- check=all : enable all compile time error and warning 
-strict :enables strictest level of error checking 
40
Create your coding guidelines 
41
Basics of cryptography 
Encryption is used to encode message only the group 
communicating would understand 
Encryption : move alphabets one step up 
Decryption :move alphabets one step down 
“ A SECRET MESSAGE” encrypted as 
“ B TFDSFU NFTTBHF “ 
42
Keyed encryption algorithm 
KEY value = “No of steps rotated by position of English alphabet” 
Encryption : Move up the alphabet 
Encrypt : “A SECRET MESSAGE” 
Key : “C” 
Encrypted message “ C UGETGV OGUUCHG” 
Cryptographic strength is measured in the time and 
resource it would require to recover the plain content 
43
Advantages of keyed algorithm 
 Instead of communicating the algorithm , share 
the key in secret 
 With varying key sizes the encryption will get 
stronger (min 80 bits) 
44
Public key cryptography 
Asymmetric scheme using a pair of keys for encryption: 
 Public key is used to encrypt data 
 Private key is used for decryption 
 The public key is published to the world 
 The private and public keys are mathematically 
related but difficult to break 
45
46 
Other crypto mechanisms 
 Hash functions 
o Validate integrity of data by sending a digest 
 Digital signature 
o Checks authentication of origin 
o Non - repudiation 
RSA DSA DES MD5 SHA1 
Signature Encryption Hashing 
SSL 
Algorithm 
Mechanism 
Service
Protect data stored in device 
 Encrypt private and confidential data 
like password , address book, database. 
 Do not store data in contiguous location. 
 In your design identify critical and non critical 
memory areas based on data stored 
47
Securing Network transactions 
• SSL is Secure socket layer ,a global standard 
in transferring data 
• It creates encrypted link between server and 
web browser 
Secure communication goals are 
privacy, message integrity and 
authentication 48
Security within the device 
Architecture of a secure processor 
49 
Secure SoC 
Secure ROM 
Secure 
Bootloader 
ROM 
(Internal) 
RAM 
(Internal) 
Processor 
External 
RAM 
Signed Firmware (Ext. ROM/Flash/HDD)
Signed Firmware binary 
Secure boot loader 
Boot 
functionality 
Sign 
verification 
Public 
key 
Signed firmware 
App code + data Signature 
Private 
key 
 The Keys are generated by the device manufacturer 
 Firmware not signed by manufacturer will not work. 
50 
Key
Secure Boot 
 Secure boot loader contains critical code to configure 
the hardware for limited access. 
 Secret keys are loaded into the internal RAM only 
 Secure boot loader checks the validity of firmware 
code by verifying the signature 
 Abort loading of device firmware if signature 
verification fails 
51
Check for compliance 
52
Security audit 
Periodic audits will uncover security loopholes 
 Review the code for security violation 
 Review the system architecture 
 Look for unintended firmware installations 
 Check network and storage security 
53
Example audit report 
Module Audit step List Action required 
Kernel 
List and check if all 
x.ko , 
modules 
modules are needed 
y.ko. 
Remove modules 
not needed 
Kernel 
debug 
Is kernel debug enabled ? Yes Disable debug 
Installed 
software 
Is there any installed 
default software? 
Rpc , 
pop3 , 
telnet 
Remove these 
installed software 
Field debug Check logging protocol Clear Encrypt logging 
mechanism 
54
Example audit report (Contd..) 
Module Audit step List Action required 
Network 
Ports 
Check which ports 
are available for 
connection using 
nmap. 
Remove ports not 
reqd. 
Stored data Check stored data Clear in file Use encryption 
Media 
transmission 
Check security of 
transmission 
tiny 
encryption 
Weak , use 
stronger encrypt 
Services 
Any unintended 
services running? 
Httpd, telnet Remove the 
services. 
55
Rely on tools wherever possible 
56
Tools 
Some of the tools which un cover security issues 
Does software analysis in depth. 
Profiling and debugging tool 
Tool for port scanning 
Scans database server application 
http://www.securecoding.org/companion/tools.php 
57
Does hardware need to be 
secure too? 
58
59
60
Let us be safe 
61
62

More Related Content

What's hot

CODE BLUE 2014 : DeviceDisEnabler : A hypervisor which hides devices to prote...
CODE BLUE 2014 : DeviceDisEnabler : A hypervisor which hides devices to prote...CODE BLUE 2014 : DeviceDisEnabler : A hypervisor which hides devices to prote...
CODE BLUE 2014 : DeviceDisEnabler : A hypervisor which hides devices to prote...CODE BLUE
 
Protected Process Light will be Protected – MemoryRanger Fills the Gap Again
Protected Process Light will be Protected – MemoryRanger Fills the Gap AgainProtected Process Light will be Protected – MemoryRanger Fills the Gap Again
Protected Process Light will be Protected – MemoryRanger Fills the Gap AgainIgor Korkin
 
Undermining Diagnostics Security: Bypassing UDS Security Checks
Undermining Diagnostics Security: Bypassing UDS Security ChecksUndermining Diagnostics Security: Bypassing UDS Security Checks
Undermining Diagnostics Security: Bypassing UDS Security ChecksNiek Timmers
 
Kernel Memory Protection by an Insertable Hypervisor which has VM Introspec...
Kernel Memory Protection by an Insertable Hypervisor which has VM Introspec...Kernel Memory Protection by an Insertable Hypervisor which has VM Introspec...
Kernel Memory Protection by an Insertable Hypervisor which has VM Introspec...Kuniyasu Suzaki
 
Windows Internals: fuzzing, hijacking and weaponizing kernel objects
Windows Internals: fuzzing, hijacking and weaponizing kernel objectsWindows Internals: fuzzing, hijacking and weaponizing kernel objects
Windows Internals: fuzzing, hijacking and weaponizing kernel objectsNullbyte Security Conference
 
Analyzing the Security of Cars Efficiently
Analyzing the Security of Cars EfficientlyAnalyzing the Security of Cars Efficiently
Analyzing the Security of Cars EfficientlyNiek Timmers
 
Thesis presentation
Thesis presentationThesis presentation
Thesis presentationCHIACHE lee
 
Lucas apa pacsec slides
Lucas apa pacsec slidesLucas apa pacsec slides
Lucas apa pacsec slidesPacSecJP
 
MNSEC 2018 - Windows forensics
MNSEC 2018 - Windows forensicsMNSEC 2018 - Windows forensics
MNSEC 2018 - Windows forensicsMNCERT
 
Two Challenges of Stealthy Hypervisors Detection: Time Cheating and Data Fluc...
Two Challenges of Stealthy Hypervisors Detection: Time Cheating and Data Fluc...Two Challenges of Stealthy Hypervisors Detection: Time Cheating and Data Fluc...
Two Challenges of Stealthy Hypervisors Detection: Time Cheating and Data Fluc...Igor Korkin
 
Detect Kernel-Mode Rootkits via Real Time Logging & Controlling Memory Access
Detect Kernel-Mode Rootkits via Real Time Logging & Controlling Memory AccessDetect Kernel-Mode Rootkits via Real Time Logging & Controlling Memory Access
Detect Kernel-Mode Rootkits via Real Time Logging & Controlling Memory AccessIgor Korkin
 
A Stuxnet for Mainframes
A Stuxnet for MainframesA Stuxnet for Mainframes
A Stuxnet for MainframesCheryl Biswas
 
MIT Bitcoin Expo 2018 - Hardware Wallets Security
MIT Bitcoin Expo 2018 - Hardware Wallets SecurityMIT Bitcoin Expo 2018 - Hardware Wallets Security
MIT Bitcoin Expo 2018 - Hardware Wallets SecurityCharles Guillemet
 
Man in the middle attacks on IEC 60870-5-104
Man in the middle attacks on IEC 60870-5-104Man in the middle attacks on IEC 60870-5-104
Man in the middle attacks on IEC 60870-5-104pgmaynard
 
Controlling PC on ARM using Fault Injection
Controlling PC on ARM using Fault InjectionControlling PC on ARM using Fault Injection
Controlling PC on ARM using Fault InjectionRiscure
 
CONFidence 2014: Yaniv Miron: ATMs – We kick their ass
CONFidence 2014: Yaniv Miron: ATMs – We kick their assCONFidence 2014: Yaniv Miron: ATMs – We kick their ass
CONFidence 2014: Yaniv Miron: ATMs – We kick their assPROIDEA
 

What's hot (20)

CODE BLUE 2014 : DeviceDisEnabler : A hypervisor which hides devices to prote...
CODE BLUE 2014 : DeviceDisEnabler : A hypervisor which hides devices to prote...CODE BLUE 2014 : DeviceDisEnabler : A hypervisor which hides devices to prote...
CODE BLUE 2014 : DeviceDisEnabler : A hypervisor which hides devices to prote...
 
Protected Process Light will be Protected – MemoryRanger Fills the Gap Again
Protected Process Light will be Protected – MemoryRanger Fills the Gap AgainProtected Process Light will be Protected – MemoryRanger Fills the Gap Again
Protected Process Light will be Protected – MemoryRanger Fills the Gap Again
 
Careful Packing
Careful PackingCareful Packing
Careful Packing
 
Undermining Diagnostics Security: Bypassing UDS Security Checks
Undermining Diagnostics Security: Bypassing UDS Security ChecksUndermining Diagnostics Security: Bypassing UDS Security Checks
Undermining Diagnostics Security: Bypassing UDS Security Checks
 
Kernel Memory Protection by an Insertable Hypervisor which has VM Introspec...
Kernel Memory Protection by an Insertable Hypervisor which has VM Introspec...Kernel Memory Protection by an Insertable Hypervisor which has VM Introspec...
Kernel Memory Protection by an Insertable Hypervisor which has VM Introspec...
 
Windows Internals: fuzzing, hijacking and weaponizing kernel objects
Windows Internals: fuzzing, hijacking and weaponizing kernel objectsWindows Internals: fuzzing, hijacking and weaponizing kernel objects
Windows Internals: fuzzing, hijacking and weaponizing kernel objects
 
Stuxnet dc9723
Stuxnet dc9723Stuxnet dc9723
Stuxnet dc9723
 
Analyzing the Security of Cars Efficiently
Analyzing the Security of Cars EfficientlyAnalyzing the Security of Cars Efficiently
Analyzing the Security of Cars Efficiently
 
Thesis presentation
Thesis presentationThesis presentation
Thesis presentation
 
Lucas apa pacsec slides
Lucas apa pacsec slidesLucas apa pacsec slides
Lucas apa pacsec slides
 
MNSEC 2018 - Windows forensics
MNSEC 2018 - Windows forensicsMNSEC 2018 - Windows forensics
MNSEC 2018 - Windows forensics
 
Two Challenges of Stealthy Hypervisors Detection: Time Cheating and Data Fluc...
Two Challenges of Stealthy Hypervisors Detection: Time Cheating and Data Fluc...Two Challenges of Stealthy Hypervisors Detection: Time Cheating and Data Fluc...
Two Challenges of Stealthy Hypervisors Detection: Time Cheating and Data Fluc...
 
Detect Kernel-Mode Rootkits via Real Time Logging & Controlling Memory Access
Detect Kernel-Mode Rootkits via Real Time Logging & Controlling Memory AccessDetect Kernel-Mode Rootkits via Real Time Logging & Controlling Memory Access
Detect Kernel-Mode Rootkits via Real Time Logging & Controlling Memory Access
 
A Stuxnet for Mainframes
A Stuxnet for MainframesA Stuxnet for Mainframes
A Stuxnet for Mainframes
 
Ceh v5 module 05 system hacking
Ceh v5 module 05 system hackingCeh v5 module 05 system hacking
Ceh v5 module 05 system hacking
 
Ceh v5 module 04 enumeration
Ceh v5 module 04 enumerationCeh v5 module 04 enumeration
Ceh v5 module 04 enumeration
 
MIT Bitcoin Expo 2018 - Hardware Wallets Security
MIT Bitcoin Expo 2018 - Hardware Wallets SecurityMIT Bitcoin Expo 2018 - Hardware Wallets Security
MIT Bitcoin Expo 2018 - Hardware Wallets Security
 
Man in the middle attacks on IEC 60870-5-104
Man in the middle attacks on IEC 60870-5-104Man in the middle attacks on IEC 60870-5-104
Man in the middle attacks on IEC 60870-5-104
 
Controlling PC on ARM using Fault Injection
Controlling PC on ARM using Fault InjectionControlling PC on ARM using Fault Injection
Controlling PC on ARM using Fault Injection
 
CONFidence 2014: Yaniv Miron: ATMs – We kick their ass
CONFidence 2014: Yaniv Miron: ATMs – We kick their assCONFidence 2014: Yaniv Miron: ATMs – We kick their ass
CONFidence 2014: Yaniv Miron: ATMs – We kick their ass
 

Similar to Safe and secure programming practices for embedded devices

Chapter 09
Chapter 09Chapter 09
Chapter 09 Google
 
Op Sy 03 Ch 61
Op Sy 03 Ch 61Op Sy 03 Ch 61
Op Sy 03 Ch 61 Google
 
Embedded Security and the IoT
Embedded Security and the IoTEmbedded Security and the IoT
Embedded Security and the IoTteam-WIBU
 
Trusted Computing _plate form_ model.ppt
Trusted Computing _plate form_ model.pptTrusted Computing _plate form_ model.ppt
Trusted Computing _plate form_ model.pptnaghamallella
 
Remote security with Red Hat Enterprise Linux
Remote security with Red Hat Enterprise LinuxRemote security with Red Hat Enterprise Linux
Remote security with Red Hat Enterprise LinuxGiuseppe Paterno'
 
Information security & ethical hacking
Information security & ethical hackingInformation security & ethical hacking
Information security & ethical hackingeiti panchkula
 
Kunal - Introduction to BackTrack - ClubHack2008
Kunal - Introduction to BackTrack - ClubHack2008Kunal - Introduction to BackTrack - ClubHack2008
Kunal - Introduction to BackTrack - ClubHack2008ClubHack
 
Kunal - Introduction to backtrack - ClubHack2008
Kunal - Introduction to backtrack - ClubHack2008Kunal - Introduction to backtrack - ClubHack2008
Kunal - Introduction to backtrack - ClubHack2008ClubHack
 
Workshop on BackTrack live CD
Workshop on BackTrack live CDWorkshop on BackTrack live CD
Workshop on BackTrack live CDamiable_indian
 
[Codientu.org] design of a microcontroller based circuit for software protection
[Codientu.org] design of a microcontroller based circuit for software protection[Codientu.org] design of a microcontroller based circuit for software protection
[Codientu.org] design of a microcontroller based circuit for software protectionHieu Le Dinh
 
Piratng Avs to bypass exploit mitigation
Piratng Avs to bypass exploit mitigationPiratng Avs to bypass exploit mitigation
Piratng Avs to bypass exploit mitigationPriyanka Aash
 
CIS 2015 How to secure the Internet of Things? Hannes Tschofenig
CIS 2015 How to secure the Internet of Things? Hannes TschofenigCIS 2015 How to secure the Internet of Things? Hannes Tschofenig
CIS 2015 How to secure the Internet of Things? Hannes TschofenigCloudIDSummit
 
Secure Coding Practices for Middleware
Secure Coding Practices for MiddlewareSecure Coding Practices for Middleware
Secure Coding Practices for MiddlewareManuel Brugnoli
 
Embedded presentation
Embedded presentationEmbedded presentation
Embedded presentationrohancool
 
&lt;marquee>html title testfsdjk34254&lt;/marquee>
&lt;marquee>html title testfsdjk34254&lt;/marquee>&lt;marquee>html title testfsdjk34254&lt;/marquee>
&lt;marquee>html title testfsdjk34254&lt;/marquee>slideshareperson2
 
Software Protection Techniques
Software Protection TechniquesSoftware Protection Techniques
Software Protection TechniquesChaitanya Anpat
 
Confidential compute with hyperledger fabric .v17
Confidential compute with hyperledger fabric .v17Confidential compute with hyperledger fabric .v17
Confidential compute with hyperledger fabric .v17LennartF
 
Portakal Teknoloji Otc Lyon Part 1
Portakal Teknoloji Otc  Lyon Part 1Portakal Teknoloji Otc  Lyon Part 1
Portakal Teknoloji Otc Lyon Part 1bora.gungoren
 

Similar to Safe and secure programming practices for embedded devices (20)

Chapter 09
Chapter 09Chapter 09
Chapter 09
 
Op Sy 03 Ch 61
Op Sy 03 Ch 61Op Sy 03 Ch 61
Op Sy 03 Ch 61
 
Embedded Security and the IoT
Embedded Security and the IoTEmbedded Security and the IoT
Embedded Security and the IoT
 
Trusted Computing _plate form_ model.ppt
Trusted Computing _plate form_ model.pptTrusted Computing _plate form_ model.ppt
Trusted Computing _plate form_ model.ppt
 
Remote security with Red Hat Enterprise Linux
Remote security with Red Hat Enterprise LinuxRemote security with Red Hat Enterprise Linux
Remote security with Red Hat Enterprise Linux
 
Information security & ethical hacking
Information security & ethical hackingInformation security & ethical hacking
Information security & ethical hacking
 
Kunal - Introduction to BackTrack - ClubHack2008
Kunal - Introduction to BackTrack - ClubHack2008Kunal - Introduction to BackTrack - ClubHack2008
Kunal - Introduction to BackTrack - ClubHack2008
 
Kunal - Introduction to backtrack - ClubHack2008
Kunal - Introduction to backtrack - ClubHack2008Kunal - Introduction to backtrack - ClubHack2008
Kunal - Introduction to backtrack - ClubHack2008
 
Workshop on BackTrack live CD
Workshop on BackTrack live CDWorkshop on BackTrack live CD
Workshop on BackTrack live CD
 
[Codientu.org] design of a microcontroller based circuit for software protection
[Codientu.org] design of a microcontroller based circuit for software protection[Codientu.org] design of a microcontroller based circuit for software protection
[Codientu.org] design of a microcontroller based circuit for software protection
 
Piratng Avs to bypass exploit mitigation
Piratng Avs to bypass exploit mitigationPiratng Avs to bypass exploit mitigation
Piratng Avs to bypass exploit mitigation
 
CIS 2015 How to secure the Internet of Things? Hannes Tschofenig
CIS 2015 How to secure the Internet of Things? Hannes TschofenigCIS 2015 How to secure the Internet of Things? Hannes Tschofenig
CIS 2015 How to secure the Internet of Things? Hannes Tschofenig
 
Secure Coding Practices for Middleware
Secure Coding Practices for MiddlewareSecure Coding Practices for Middleware
Secure Coding Practices for Middleware
 
Embedded presentation
Embedded presentationEmbedded presentation
Embedded presentation
 
" onclick="alert(1)
" onclick="alert(1)" onclick="alert(1)
" onclick="alert(1)
 
&lt;marquee>html title testfsdjk34254&lt;/marquee>
&lt;marquee>html title testfsdjk34254&lt;/marquee>&lt;marquee>html title testfsdjk34254&lt;/marquee>
&lt;marquee>html title testfsdjk34254&lt;/marquee>
 
Software Protection Techniques
Software Protection TechniquesSoftware Protection Techniques
Software Protection Techniques
 
Confidential compute with hyperledger fabric .v17
Confidential compute with hyperledger fabric .v17Confidential compute with hyperledger fabric .v17
Confidential compute with hyperledger fabric .v17
 
Portakal Teknoloji Otc Lyon Part 1
Portakal Teknoloji Otc  Lyon Part 1Portakal Teknoloji Otc  Lyon Part 1
Portakal Teknoloji Otc Lyon Part 1
 
Cyber tooth
Cyber toothCyber tooth
Cyber tooth
 

Recently uploaded

Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfFerryKemperman
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Hr365.us smith
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfDrew Moseley
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsAhmed Mohamed
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作qr0udbr0
 
Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprisepreethippts
 
Sending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdfSending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdf31events.com
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...OnePlan Solutions
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Velvetech LLC
 
VK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web DevelopmentVK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web Developmentvyaparkranti
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaHanief Utama
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odishasmiwainfosol
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 
Software Coding for software engineering
Software Coding for software engineeringSoftware Coding for software engineering
Software Coding for software engineeringssuserb3a23b
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Cizo Technology Services
 
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...confluent
 

Recently uploaded (20)

Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdf
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdf
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 
2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML Diagrams
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作
 
Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprise
 
Sending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdfSending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdf
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...
 
Odoo Development Company in India | Devintelle Consulting Service
Odoo Development Company in India | Devintelle Consulting ServiceOdoo Development Company in India | Devintelle Consulting Service
Odoo Development Company in India | Devintelle Consulting Service
 
VK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web DevelopmentVK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web Development
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief Utama
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 
Software Coding for software engineering
Software Coding for software engineeringSoftware Coding for software engineering
Software Coding for software engineering
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
 
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
 

Safe and secure programming practices for embedded devices

  • 1. Soumitra Bhattacharyya Engineering Manager- Sling Media Ltd. website : www.slingmedia.com Email : soumitrab@slingmedia.com Linkedin : http://www.linkedin.com/in/soumitra001 1
  • 2. We live in un-trust worthy world of technology usage. Can we afford security like this? 2
  • 3. 1986–1995 • LAN environment • First PC virus • Motivation: damage 1995–2003 • Internet Era • “Big Worms” • Motivation: damage 2004+ • OS, DB attacks • Spyware, Spam • Motivation: Financial 2006+ • Targeted attacks • Social engineering • Financial + Political  Cost of U.S. cybercrime: About $70B Source: U.S. Government Accountability Office (GAO), FBI 2009+ • Embedded devices • Virus , data theft , content theft • Damage , financial 3
  • 4. Trend of cyber crime reported over the years 4
  • 5. What are fraudsters looking for? 5
  • 6. Need for security in devices  Devices getting integrated into personal and commercial networks  Consumer devices are ubiquitous  Pervasive use of Wireless communication  Portable devices communicate with changing network conditions  Gadgets can get stolen making them physically accessible . 6
  • 7. 7
  • 8. 8
  • 9. An innocuous hack No device is secure 9
  • 10. Threats vary with the type of device and a single solution cannot be applied to all 10
  • 11. Need for Security The threats are endless 11
  • 12. Threats in a device  Theft of data ,keys and privacy  Loss of data consistency  Altering device firmware  Copy of digital content  Breaking access control 12
  • 13. Embedded devices have different challenges compared to their desktop counterparts. 13
  • 14. Design challenges  Devices are constrained on their resources and capabilities  Defense mechanisms should not alter the response time of their key function  Physical accessibility of devices call for solutions different from ones applied to traditional systems 14
  • 15. Design challenges  Security concerns cannot be solved in a single abstraction layer of software  Software on devices becoming complex  Quick time to market and increased cost need simple yet robust solutions 15
  • 16. Security should be part of product definition 16
  • 17. 17 Security requirements - Example  All password and user data should be encrypted using 128bit AES  User and device should be authenticated before allowing streaming session  Device should use https for all transactions with the server  XXX 128 bit encryption should be used for content security  ATSC channels need not be protected.
  • 18. What are the weak links intruders looking for ? 18
  • 19. Areas prone to attack  Logical threats aiming to modify device firmware  Threats due to weakness in design and implementation  Unhandled system errors 19
  • 20. 20
  • 21. 21
  • 22. 22
  • 23. Consequences for the device Buffer Overflows Arithmetic error System crash Changed execution flow Data Theft Malware injection Consequences 23
  • 24. Business consequences Products out of market Loss of reputation Financial loss Lawsuits 24
  • 25. Basic solutions to security issues 25
  • 26. Core problems with ‘C’ language 26  Language has no consideration for security  There are functions that can be used in unsecure way  Dynamic memory allocation needs careful manipulation
  • 27. Core problems with ‘C’ language 27 Vulnerable Function Safe Version strcpy() strncpy() & explicit null termination strcat() strncat()(destination size–1) sprintf() snprintf() scanf() family scanf() (specify the maximum) length) getc() / getchar() This function can be vulnerable if used in a loop.
  • 28. Unsecure program int func( char * input) { char local [10]; int i=0; while (*input !=‘0’) { local[i++]=*input++; } return 0; } NO “NULL” CHECK NO “Length of input “CHECK 28
  • 29. Secure programming A more appropriate program would be : int func( char * input) { if((*input !=NULL) && (strlen(input) <=10)) { …… ……………. } } 29 Return appropriately based on error
  • 30. Reducing attack at the entry point is as important as trying to get the code right 30
  • 31. Input parameter validation  Perform validation at all inputs across modules  Assume all inputs are malicious  Reject data when in doubt  Parse the characters , commands and escape sequences 31
  • 32. Input parameter validation  Check input data size  Validate email construct  Evaluate URL  Prevent attack from un- formatted strings 32
  • 33. Checking constructs void decode_file(char *buffer) { if(*buffer == 0xff && *(buffer+1)==0xd8) hw_decode_jpeg(buffer); else “ Invalid JPEG file” } If invalid jpeg file is passed , decoder will fail 33
  • 34. Arithmetic overflow int ConcatBuffers(char *buf1, char *buf2, size_t len1, size_t len2){ char buf[0xFF]; if((len1 + len2) > 0xFF) return -1; memcpy(buf, buf1, len1); memcpy(buf + len1, buf2, len2); // do stuff with buf return 0; len1 len2 0x103 + 0xFFFFFFFC 0xFF Both memcpy functions attempt to copy >255 bytes 34
  • 35. Memory management  Always free() dynamically allocated memory after it is not needed  Set the free pointer to NULL  Failure to release memory is problematic on embedded devices with limited memory Attackers can use memory vulnerabilities to damage operation of device 35
  • 36. Error handling principles  Every error should be handled in a graceful way  At lowest level (e.g. drivers) try to recover from error  Internal errors should not be reported to users  Disable core dumps , stack trace , diagnostic information 36
  • 37. Safe initialization  Initialize variables and file descriptors before using them.  Initialize and limit the use of env variables  Avoid passing data using env variables  Avoid execution of program at high privileges 37
  • 38. Safe initialization int vuln_fn(int a) { unsigned int result; if (a > 0) { result = 256 % result; } return result; } uninitialized variable Potential security bugs can creep in through uninitialized variable usage 38
  • 39. Compiler warnings  Warnings are first level of defense against any security flaw  Compiler warnings are effective at detecting programming flaws  It can catch bugs which are hard to find during testing. Compile with the highest level of warning set as error 39
  • 40. Flag setting for compilers GNU C compiler : -Wall : enable all compiler warnings -Werror : treat compiler warnings as errors ARM Developer Suite C compiler: -E+c : enable all implicit cast errors -E+l : errors on linkage disagreements -fv : reports unused declarations … Greenhills Embedded MIPS compiler: - check=all : enable all compile time error and warning -strict :enables strictest level of error checking 40
  • 41. Create your coding guidelines 41
  • 42. Basics of cryptography Encryption is used to encode message only the group communicating would understand Encryption : move alphabets one step up Decryption :move alphabets one step down “ A SECRET MESSAGE” encrypted as “ B TFDSFU NFTTBHF “ 42
  • 43. Keyed encryption algorithm KEY value = “No of steps rotated by position of English alphabet” Encryption : Move up the alphabet Encrypt : “A SECRET MESSAGE” Key : “C” Encrypted message “ C UGETGV OGUUCHG” Cryptographic strength is measured in the time and resource it would require to recover the plain content 43
  • 44. Advantages of keyed algorithm  Instead of communicating the algorithm , share the key in secret  With varying key sizes the encryption will get stronger (min 80 bits) 44
  • 45. Public key cryptography Asymmetric scheme using a pair of keys for encryption:  Public key is used to encrypt data  Private key is used for decryption  The public key is published to the world  The private and public keys are mathematically related but difficult to break 45
  • 46. 46 Other crypto mechanisms  Hash functions o Validate integrity of data by sending a digest  Digital signature o Checks authentication of origin o Non - repudiation RSA DSA DES MD5 SHA1 Signature Encryption Hashing SSL Algorithm Mechanism Service
  • 47. Protect data stored in device  Encrypt private and confidential data like password , address book, database.  Do not store data in contiguous location.  In your design identify critical and non critical memory areas based on data stored 47
  • 48. Securing Network transactions • SSL is Secure socket layer ,a global standard in transferring data • It creates encrypted link between server and web browser Secure communication goals are privacy, message integrity and authentication 48
  • 49. Security within the device Architecture of a secure processor 49 Secure SoC Secure ROM Secure Bootloader ROM (Internal) RAM (Internal) Processor External RAM Signed Firmware (Ext. ROM/Flash/HDD)
  • 50. Signed Firmware binary Secure boot loader Boot functionality Sign verification Public key Signed firmware App code + data Signature Private key  The Keys are generated by the device manufacturer  Firmware not signed by manufacturer will not work. 50 Key
  • 51. Secure Boot  Secure boot loader contains critical code to configure the hardware for limited access.  Secret keys are loaded into the internal RAM only  Secure boot loader checks the validity of firmware code by verifying the signature  Abort loading of device firmware if signature verification fails 51
  • 53. Security audit Periodic audits will uncover security loopholes  Review the code for security violation  Review the system architecture  Look for unintended firmware installations  Check network and storage security 53
  • 54. Example audit report Module Audit step List Action required Kernel List and check if all x.ko , modules modules are needed y.ko. Remove modules not needed Kernel debug Is kernel debug enabled ? Yes Disable debug Installed software Is there any installed default software? Rpc , pop3 , telnet Remove these installed software Field debug Check logging protocol Clear Encrypt logging mechanism 54
  • 55. Example audit report (Contd..) Module Audit step List Action required Network Ports Check which ports are available for connection using nmap. Remove ports not reqd. Stored data Check stored data Clear in file Use encryption Media transmission Check security of transmission tiny encryption Weak , use stronger encrypt Services Any unintended services running? Httpd, telnet Remove the services. 55
  • 56. Rely on tools wherever possible 56
  • 57. Tools Some of the tools which un cover security issues Does software analysis in depth. Profiling and debugging tool Tool for port scanning Scans database server application http://www.securecoding.org/companion/tools.php 57
  • 58. Does hardware need to be secure too? 58
  • 59. 59
  • 60. 60
  • 61. Let us be safe 61
  • 62. 62

Editor's Notes

  1. Make it more visible
  2. Your blue tooth may be on without security making it accessible to a stranger sniffing t hem in market place. The total cost of Internet-related fraud complaints from consumers rose from $206 million in 2003 to $336 million in 2005, according to the U.S. Federal Trade Commission. Internet-related complains accounted for 46 percent of all fraud complaints to the agency.
  3. Provide details here
  4. https://mocana.com/blog/2010/04/08/medical-devices-hacked/
  5. Validate this data!!!
  6. With products ranging from security camera , medical devices , mobile , dish washer, an off the shelf software program cannot be used to protect devices. The devices have varied platforms with varying security needs. Processor limitations , memory constraints , battery life and host of other idiosyncrasies make security a non trivial thing
  7. Another burning issue is the identity theft of web applications. According to [JAV06], the amount lost to fraud over a one-year period for online applications (banking, shopping, etc.) is estimated at $54.4 billion in 2005 in the U.S. alone.
  8. Validate this data!!!
  9. Unlike traditional systems , they have less memory/ processing power and hence cannot add sophisticated algorithms. Hence more prone to attack) In PC , it is allowed to run virus scan, SSL checks etc in the background at the cost of foreground tasks. Mobile phones or TV need minimum latency for the primary function . security protocols are computationally intensive, and deploying them on resource-constrained embedded systems without appreciably degrading their performance is a challenging task.
  10. Unlike traditional systems , they have less memory/ processing power and hence cannot add sophisticated algorithms. Hence more prone to attack) In PC , it is allowed to run virus scan, SSL checks etc in the background at the cost of foreground tasks. Mobile phones or TV need minimum latency for the primary function .
  11. It cannot be an after thought. Product managers should define security requirements right at the beginning of product conceptualization.
  12. Validate this data!!!
  13. Validate this data!!!
  14. This whole section needs review
  15. The C programming language was engineered for speed and portability. At the time it was developed, there was no consideration given to security. As a result, many of the functions in the C language do no properly limit user input, which leads to problems like buffer overflows. There are other classes of security problems also, which can lead to logic bugs and exploitable security bugs. Examples include integer wrapping, signed/unsigned issues, type casting problems, format string bugs, and race conditions
  16. There are some functions that have no secure replacement in the standard library and an external library may be required
  17. What are the various problems in this piece of code
  18. 1.
  19. Do not just validate in some modules leaving it vulnerable. When you have to choose the first priority should be to check user inputs , data transactions over network or any other source external to your module deny access until specifically granted, not grant access until denied
  20. 1. Do not just validate in some modules leaving it vulnerable. When you have to choose the first priority should be to check user inputs , data transactions over network or any other source external to your module
  21. Validate the JPEG marker 0xffd8
  22. The addition of 0x103+0xFFFFFFFC = 0x1000000FF . Due to overflow , the result will be 0xFF . It would be good to check individual lengths as well.
  23. Basic principles of memory management
  24. Any error generated by internal components like system call fail ,database error , internal error should not be exposed.
  25. Attackers can easily take control of the system through environment variables even remotely like using CGI scripts
  26. This is a simple example where any one can enter un validated inputs that can lead to a system crash
  27. This is a simple example where any one can enter un validated inputs that can lead to a system crash
  28. 1. These algorithms are easily predictable. New algorithms have to be generated if secrecy is compromised. fixed algorithms cannot be revealed to anyone but the intended set of recipients.
  29. Taking a simple example to associate algorithm with key. The algorithm may be known . The effectiveness is in keeping the Key secret and complex. This is symmetric key cryptography.
  30. Alice wants to buy a book from Bob's online bookstore. In order to complete the process she'll need to transmit sensitive personal information, such as her credit card number. Alice wants to make sure that the information she sends to Bob is kept confidential (privacy), and cannot be altered along the way (message integrity). She also wants to make sure that she's really sending the information to Bob and not an imposter (authentication). Alice wants to send Bob private information, so Bob says, "Here Alice, use this public key to encrypt your message before sending it to me. When I receive your encrypted message I will use my private key to decrypt your message." It's okay for anyone to have a copy of the public key, but only Bob should have a copy of his private key
  31. Spread data across multiple files , memory location. In case of loss of storage device , such data should not be easily retrievable
  32. The security of the device is dependent on the secrecy of the keys
  33. Tools will help to bring out many security issues without manual intervention
  34. Scatter the pins , do not connect them to processor Attacks can alter or erase the flash firmware or get access to SIM locks , IMEI etc. 4. Removing external power source will halt clock and may corrupt memory