Banned APIs and Sin Within!

Slides:



Advertisements
Similar presentations
MFA for Business Banking – Security Code Multifactor Authentication: Quick Tip Sheets Note to Financial Institutions: We are providing these QT sheets.
Advertisements

Welcome to Bible Baptist Church Ballincollig, Cork Celebrating 12 Years Today is the Lords Day Sunday, 3 rd September, 2006.
Buffer Overflows Nick Feamster CS 6262 Spring 2009 (credit to Vitaly S. from UT for slides)
Security Development Lifecycle: Development Practices
Copyright © The OWASP Foundation Permission is granted to copy, distribute and/or modify this document under the terms of the Creative Commons Attribution-ShareAlike.
C Programming lecture 2 Beautiful programs Greek algorithms
A C++ Crash Course Part II UW Association for Computing Machinery Questions & Feedback.
Basics of Secure Design, Development, and Test
CS 11 C track: lecture 7 Last week: structs, typedef, linked lists This week: hash tables more on the C preprocessor extern const.
Microsoft ® Office 2007 Training Security II: Turn off the Message Bar and run code safely P J Human Resources Pte Ltd presents:
Functions, Varargs, and Stack Smashing Using the Stack for Good And Evil Before You Sit Down Please Get The Handout at the Entrance This file is called.
Dynamic Memory Allocation in C.  What is Memory What is Memory  Memory Allocation in C Memory Allocation in C  Difference b\w static memory allocation.
Exploring Security Vulnerabilities by Exploiting Buffer Overflow using the MIPS ISA Andrew T. Phillips Jack S. E. Tan Department of Computer Science University.
Character String Manipulation. Overview Character string functions sscanf() function snprintf() function.
Lecture 9. Lecture 9: Outline Strings [Kochan, chap. 10] –Character Arrays/ Character Strings –Initializing Character Strings. The null string. –Escape.
What is a pointer? First of all, it is a variable, just like other variables you studied So it has type, storage etc. Difference: it can only store the.
Chapter 1  Introduction 1 Chapter 1: Introduction.
Communications of the ACM (CACM), Vol. 32, No. 6, June 1989
CSc 352 Programming Hygiene Saumya Debray Dept. of Computer Science The University of Arizona, Tucson
Buffer Overflow Intro. ©2002, Jedidiah R. Crandall, Susan L. Gerhart, Jan G. Hogle. Preventing Buffer Overflows (for C programmers)
‘Love your neighbour’ Making it happen... Cafe Church 2 nd November 2014.
Test Your Memory! Opening Put each picture in your mind, and it will remind you of each commandment.
Buffer Overflow Exploits CS-480b Dick Steflik. What is a buffer overflow? Memory global static heap malloc( ), new Stack non-static local variabled value.
Teaching Buffer Overflow Ken Williams NC A&T State University.
Class on Security Raghu. Current state of Security Cracks appear all the time Band Aid solutions Applications are not designed properly OS designs are.
Teaching Buffer Overflow Ken Williams NC A&T State University.
CSSE221: Software Dev. Honors Day 29 Announcements Announcements Any questions on strings? Any questions on strings? Section 2: pass in quiz after question.
Great is Your Love I will praise You, Oh Lord my God
Assessing the Threat How much money is lost due to cyber crimes? –Estimates range from $100 million to $100s billions –Why the discrepancy? Companies don’t.
Control hijacking attacks Attacker’s goal: – Take over target machine (e.g. web server) Execute arbitrary code on target by hijacking application control.
C-Strings Joe Meehean. C-style Strings String literals (e.g., “foo”) in C++ are stored as const char[] C-style strings characters (e.g., ‘f’) are stored.
 The ultimate purpose for the church is to glorify God.  Once a person is redeemed, his/her mission is to join Christ “on mission” to fulfill the Great.
Exodus 20/ Deuteronomy 5.
Static Analysis for Security Amir Bazine Per Rehnberg.
The ten commandments By Isabella Tighello.
ETIQUETTE AND EVIDENCE
Test Your Memory! Opening Put each picture in your mind, and it will remind you of each commandment.
Security Exploiting Overflows. Introduction r See the following link for more info: operating-systems-and-applications-in-
An anti-hacking guide.  Hackers are kindred of expert programmers who believe in freedom and spirit of mutual help. They are not malicious. They may.
Introduction to C programming
Lesson 20. What is God impressing on us by telling us not to covet?
© 2011 wheresjenny.com Repair a car. © 2011 wheresjenny.com Repair a car Teachers guide to lead a session This is a new way of taking a session: 1.The.
FrmModule-SY. Change #1 When you change the New Company Code more than once, it stack the company codes in the Destination Path Y05 = c:\cmswin11.2\y05.
Copyright © Microsoft Corp 2006 Pragmatic Secure Design: Attack Surface Reduction Shawn Hernan Security Program Manager Security Engineering and Communication.
Chapter 6 Buffer Overflow. Buffer Overflow occurs when the program overwrites data outside the bounds of allocated memory It was one of the first exploited.
Confirmation Class The Giving and Summary of the Law Lesson 2.
“LOVING OUR NEIGBOR” CW All-Church Retreat 2014 Session 1What Will the Neighbors Say? —Getting off the Performance Track Session 2The Crazy Neighbor —When.
The Deepest Longing the longing to be loved Copyright © Simon G. Harris Scripture quotations taken from the HOLY BIBLE, NEW INTERNATIONAL VERSION. Copyright.
Chapter 0.2 – Pointers and Memory. Type Specifiers  const  may be initialised but not used in any subsequent assignment  common and useful  volatile.
Second of Three (What Am I Doing?)
Building Hope Class Living Hope Lutheran Church Reunion, CO PowerPoint presentations prepared by Vicar Rob Guenther.
Character Arrays Based on the original work by Dr. Roger deBry Version 1.0.
1 File Systems: Consistency Issues. 2 File Systems: Consistency Issues File systems maintains many data structures  Free list/bit vector  Directories.
Crash Course in Web Hacking
Overflow Examples 01/13/2012. ACKNOWLEDGEMENTS These slides where compiled from the Malware and Software Vulnerabilities class taught by Dr Cliff Zou.
Or Why the Doctrine of Sin is Good News 1 John 1:8-9.
Buffer Overflow Group 7Group 8 Nathaniel CrowellDerek Edwards Punna ChalasaniAxel Abellard Steven Studniarz.
Good News Club November 18, Sign up, show up, join forces with God! He’s the biggest hero of them all. Stand out, give a shout. Show the world.
NTFS 5.0 By Jeffrey Richter and Luis Felipe Cabrera From the Microsoft Systems Journal Presented by Stylianos Paparizos.
MAN UP BIBLE SERIES Living a Life that Counts Lesson Five.
Copyright ©: Nahrstedt, Angrave, Abdelzaher1 C Basics Tarek Abdelzaher and Vikram Adve.
John 10: Therefore Jesus said again, “Very truly I tell you, I am the gate for the sheep. 8 All who have come before me are thieves and robbers,
1988 Morris Worm … estimated 10% penetration 2001 Code Red … 300,00 computers breached 2003 Slammer/Sapphire … 75,00 infections in 10 min Zotob …
1988 Morris Worm … estimated 10% penetration 2001 Code Red … 300,00 computers breached 2003 Slammer/Sapphire … 75,00 infections in 10 min Zotob …
Secure Transactions Chapter 17. The user's machine No control over security of user's machine –Might be in very insecure: library, school, &c. Users disable.
1 Adding a Model. We have created an MVC web app project Added a controller class. Added a view class. Next we will add some classes for managing movies.
Content Coverity Static Analysis Use cases of Coverity Examples
Writing safer code with the Visual C Libraries
CS 465 Buffer Overflow Slides by Kent Seamons and Tim van der Horst
CS31 Discussion 1H Fall18: week 6
Presentation transcript:

Banned APIs and Sin Within! Michael Howard mikehow@microsoft.com

Who Is This Guy? mikehow@microsoft.com Christian (imperfect in every possible way!) Microsoft employee for 20 years Always in security Worked on the Microsoft SDL since inception

Goals and Non-Goals I am not one for drawing analogies “Security Analogies are usually Wrong” http://blogs.msdn.com/b/michael_howard/archive/2006/03/09/547575.aspx I use quotes from the Bible to compare/contrast software security “The Bible is correct, your code is not.” :-)

If cars operated in an environment like the Internet, they would… Be driven by people with little regard for safe automobile operation. Have their windshields shot out every 60 secs. Once you have bullet-proof glass, the bad guys place nails at freeway off-ramps next to signs like, “free coffee this way” and someone is always trying to steal your keys and pull out your sparkplugs and siphon your gas Talking of gas, you fill up at a Shell station, only to realize the gas really isn’t gas, it’s vegetable oil and sand Oh, that gas station isn’t a Shell station, it certainly looked like one, but they took your credit card details anyway As this all goes on, you can’t see the adversary And the adversaries are sharing new weapons with each other

The SDL A set of process changes that help improve software security Over 100 requirements and recommendations About 30 deal with memory corruption Removing banned APIs is one such requirement

What Are The Banned APIs? Mostly memory corruption APIs strcpy … strcat … strncpy … strncat … sprintf … gets …

Banned APIs strcpy, strcpyA, strcpyW, wcscpy, _tcscpy, _mbscpy, StrCpy, StrCpyA, StrCpyW, lstrcpy, lstrcpyA, lstrcpyW, _tccpy, _mbccpy strcat, strcatA, strcatW, wcscat, _tcscat, _mbscat, StrCat, StrCatA, StrCatW, lstrcat, lstrcatA, lstrcatW, StrCatBuff, StrCatBuffA, StrCatBuffW, StrCatChainW, _tccat, _mbccat strncpy, wcsncpy, _tcsncpy, _mbsncpy, _mbsnbcpy, StrCpyN, StrCpyNA, StrCpyNW, StrNCpy, strcpynA, StrNCpyA, StrNCpyW, lstrcpyn, lstrcpynA, lstrcpynW strncat, wcsncat, _tcsncat, _mbsncat, _mbsnbcat, StrCatN, StrCatNA, StrCatNW, StrNCat, StrNCatA, StrNCatW, lstrncat, lstrcatnA, lstrcatnW, lstrcatn CharToOem, CharToOemA, CharToOemW, OemToChar, OemToCharA, OemToCharW, CharToOemBuffA, CharToOemBuffW wnsprintf, wnsprintfA, wnsprintfW, sprintfW, sprintfA, wsprintf, wsprintfW, wsprintfA, sprintf, swprintf, _stprintf, _snwprintf, _snprintf, _sntprintf, wvsprintf, wvsprintfA, wvsprintfW, vsprintf, _vstprintf, vswprintf, _vsnprintf, _vsnwprintf, _vsntprintf, wvnsprintf, wvnsprintfA, wvnsprintfW strtok, _tcstok, wcstok, _mbstok makepath, _tmakepath, _makepath, _wmakepath, _splitpath, _tsplitpath, _wsplitpath scanf, wscanf, _tscanf, sscanf, swscanf, _stscanf, snscanf, snwscanf, _sntscanf _itoa, _itow, _i64toa, _i64tow, _ui64toa, _ui64tot, _ui64tow, _ultoa, _ultot, _ultow gets, _getts, _gettws IsBadWritePtr, IsBadHugeWritePtr, IsBadReadPtr, IsBadHugeReadPtr, IsBadCodePtr, IsBadStringPtr memcpy

PnP MS05-039 Zotob CONFIGRET ResDesToNtResource( IN PCVOID ResourceData, IN RESOURCEID ResourceType, IN ULONG ResourceLen, IN PCM_PARTIAL_RESOURCE_DESCRIPTOR pResDes, IN ULONG ulTag ) { case ResType_ClassSpecific: { PCS_RESOURCE pCsData = (PCS_RESOURCE)ResourceData; LPBYTE ptr = NULL; ptr = (LPBYTE)((LPBYTE)pResDes + sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR)); memcpy(ptr, pCsData->CS_Header.CSD_Signature + pCsData->CS_Header.CSD_LegacyDataOffset, pCsData->CS_Header.CSD_LegacyDataSize);

PCT SChannel MS04-011 #define SSL2_MAX_CHALLENGE_LEN 32 typedef struct _Ssl2_Client_Hello { DWORD dwVer; DWORD cCipherSpecs; DWORD cbSessionID; DWORD cbChallenge; UCHAR SessionID[SSL3_SESSION_ID_LEN]; UCHAR Challenge[SSL2_MAX_CHALLENGE_LEN]; Ssl2_Cipher_Kind CipherSpecs[MAX_UNI_CIPHERS]; } Ssl2_Client_Hello, * PSsl2_Client_Hello; SP_STATUS Pct1SrvHandleUniHello(..., PSsl2_Client_Hello pHello,...) { Pct1_Client_Hello ClientHello; ... CopyMemory( ClientHello.Challenge, pHello->Challenge, pHello->cbChallenge); http://www.microsoft.com/technet/security/Bulletin/MS04-011.mspx

NNTP MS05-030 HRESULT CNewsStore::OnResponse(LPNNTPRESPONSE pResponse) { ... if (pResponse->state == NS_LIST) hr = _HandleListResponse(pResponse, FALSE) } HRESULT CNewsStore::_HandleListResponse(LPNNTPRESPONSE pResp, BOOL fNew) { LPSTR psz, pszCount; int nSize; char szGroupName[CCHMAX_FOLDER_NAME]; LPNNTPLIST pnl = &pResp->rList; for (DWORD i = 0; i < pnl->cLines; i++, m_op.dwProgress++) { psz = pnl->rgszLines[i]; while (*psz && !IsSpace(psz)) psz = CharNext(psz); nSize = (int)(psz - pnl->rgszLines[i]); if (nSize >= CCHMAX_FOLDER_NAME) nSize = CCHMAX_FOLDER_NAME - 1; CopyMemory(szGroupName, pnl->rgszLines[i], nSize); Last Updated 20060103

LSASS MS04-011 Sasser VOID DsRolepDebugDumpRoutine( IN DWORD DebugFlag, IN LPWSTR Format, va_list arglist ) { #define DsRolepDebugDumpRoutine_BUFFERSIZE 1024 WCHAR OutputBuffer[DsRolepDebugDumpRoutine_BUFFERSIZE]; ... length += (ULONG) wvsprintfW(&OutputBuffer[length], Format, arglist); }

How Do you Find Them? #include <banned.h> C4996 warnings

The Replacements Don’t use C++ as a glorified C! Use std::string Use strsafe.h Use strcpy_s etc

Auto-replacement of Banned Functions If the compiler knows the destination buffer size at compile time, it can automatically generate secure code Add the following to auto-migrate functions to safe functions #define _CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES (1) char buf[32]; strcpy(buf,src); char buf[32]; strcpy_s(buf,src,32);

But Isn’t C dead? http://www.tiobe.com/index.php/content/paperinfo/tpci/index.html

The Leap of Faith What about regressions? In ten years, I have seen only one regression at Microsoft

Effectiveness? Over 25% of MSRC memory corruption vulns did not affect newer products simply because we banned the API(s) in question and replaced them with a more secure version That’s low cost engineering at its best!

Pop Quiz What’s in an 8oz glass of wine? What’s in an 8oz glass of poison? What’s in an 8oz glass of wine with a drop of poison?

Sin and Insecure Code Righteous Man + One Sin Sinful Man Well-Written Code + One Vulnerability Insecure System

All Sin is the Same … There is no “good” or “bad” sin, it’s all sin in God’s eyes. There is no “Security Bulletin” scale for sin Critical: Adultery, Murder Important: Bearing False Witness Moderate: Stealing Low: Coveting

… but insecure Code is not the Same An anonymously accessible remote code execution vulnerability that gives you root is *way* worse than a local information disclosure vuln accessibly only by admins Critical: Remote code execution Important: Server DoS Moderate: Temporary Server DoS Low: Client DoS

Banned APIs We have banned over 120 APIs at Microsoft They are great examples of “One-line” Sins

Removing Sin How do you remove Sin? By replacing Sin with something not Sinful! Easy to say, very hard to do. How do you remove banned APIs? By replacing them with something less dangerous! Easy to say, easy to do. And I know that nothing good lives in me, that is, in my sinful nature. I want to do what is right, but I can't. Romans 7:18

Removal takes a Leap of Faith Trust that God forgives your Sins Trust that the banned API replacements don’t introduce regressions! Praise the Lord, … who forgives all your sins. Psalm 103:3

How Do you Remove Banned APIs? Admit you have banned APIs (admit you sin!) Do something about it (admit the Lord into your heart) Don’t repeat!

Banned APIs and the Sin Within Summary Admit you sin In life and in code Do something about it Study Romans Remove Banned APIs Put steps in place to help prevent Sin and banned APIs Think!! Use banned.h in all your C/C++ code

Questions!?