SlideShare a Scribd company logo
1 of 35
Security Regression
Addressing Security Regression by Unit Testing
Christopher Grayson
@_lavalamp
Introduction
WHOAMI
3
• ATL
• Web development
• Academic researcher
• Haxin’ all the things
• (but I rlllly like networks)
• Founder
• Red team
@_lavalamp
• Security regression is a huge
problem
• Lots of infrastructure built around
regression testing already
• Let’s leverage all of that existing
infrastructure to improve
application security posture at a
minimal cost to development teams
WHY’S DIS
4
1. Background
2. Dynamic Security Test Generation
3. Non-dynamic Security Test
Generation
4. Conclusion
Agenda
5
Background
• I’ve always loved breaking into
things, have been doing this
professionally since 2012
• Go in, break app, help client with
remediation, check that
remediation worked – great!
• Come back 3-6 months later and
test again, same vulns are back
(commonly in the same places)
• Offensive testing is good at
diagnosing - not solving
A Bit More on Motivation…
7
• Standard tool in any development
team’s toolbox
• Unit tests to ensure code does not
regress to a prior state of instability
• Lots of great tools (especially in the
CI/CD chain) for ensuring tests are
passing before deployment
Regression Testing
8
Why not take the problem of security
regression and use all of the tools
already built for regression testing to
improve the security posture of
tested applications?
Putting it All Together
9
• Street Art Around the World!
• Written in Django (standard
framework, no API, full post-back)
• Same techniques work for any
programming language and
framework that support
introspection
• These examples require a
framework that has explicit URL
mapping
The Demo Application
10
https://github.com/lavalamp-/security-unit-testing
Dynamic Generation
• Django requires users to write views
and then explicitly map these views
to URL routes where they are
served from
• Views come from a set of pre-
defined base classes that support
default functionality (UpdateView,
DeleteView, DetailView, FormView,
etc)
Django Registered Routes
12
• We can use introspection to
enumerate all of the views
registered within an application
• Now that we know the views, how
can we support testing functionality
that issues requests to all of the
view functionality?
• Enter the Requestor class
Testing Registered Routes
13
• Requestors mapped to views they
are meant to send requests to via
Python decorators
• Singleton registry contains mapping
of views to requestors
• Importing all of the views
automatically establishes all of the
mappings
Requestor Registry Architecture
14
• We now can enumerate all of the
views and access classes that are
designed to submit requests to the
views
• With this capability we can
dynamically generate test cases for
all of the views in an application
• Test cases take view classes and
HTTP verbs as arguments to
constructors
Dynamic Test Generation
15
If we are relying on requestor classes being defined for all
views, then let’s test for it!
Testing for Requestors
16
We’ve got the ability to test every known HTTP verb of every
registered view, so let’s test for successful HTTP responses.
Testing for Denial of Service
17
Test to ensure that the methods supported by requestors match
the methods returned by OPTIONS request.
Testing for Unknown Methods
18
• Tell the requestors whether or not the tested view requires authentication
• Can improve upon this demo by checking for inheritance of the
LoginRequiredMixin
• Check that unauthenticated request is denied
Testing for Auth Enforcement
19
Response Header Inclusion
20
We already built out requestors based on the OPTIONS response, so now
let’s make sure that the OPTIONS response included the correct HTTP
verbs.
Testing for OPTIONS Accuracy
21
Test to ensure that CSRF tokens are required for function
invocation on non-idempotent view functionality.
Testing for CSRF Enforcement
22
• We now have guarantees that
• Our app contains no hidden
functionality
• All of our views are working as
intended given expected input
• Authentication is being properly
enforced
• Security headers are present
• CSRF is properly protected against
What Have We Gained?
23
• Those guarantees are great and all,
but can’t we just write individual
unit tests to test for them?
• In a development team we have
multiple people contributing code
all the time
• Through dynamic generation, these
tests will automatically be applied
to all new views, providing the
same guarantees to code that
hasn’t even been written yet
Why Dynamic Generation?
24
• Other things that we could write
dynamic tests for
• Rate-limiting
• Fuzzing of all input values to
POST/PUT/PATCH/DELETE
(introspection into forms used to
power the views)
• Proper updating, creation, and
deletion of new models based on
input data
Where Can We Go?
25
Testing Other Vulns
Test for proper encoding of output data!
Testing for Cross-site Scripting
27
Submit two requests to the server, one making the SQL query match none and
another making the SQL query match all, test to see if the results match the
none and all expected responses
Testing for SQL Injection
28
Submit malicious input and see if HTTP redirect
response redirects to full URL
Testing for Open Redirects
29
Conclusion
• Initial overhead is greater than
writing individual unit tests, but
new views added to the application
also benefit from the tests
• Provide us with strong guarantees
about known application
functionality and basic HTTP-based
security controls
Benefits of Dynamic Generation
31
• Security guarantees now enforced
by CI/CD integration
• Test Driven Development? Great –
have your security testers write
failing unit tests that you then
incorporate into your test suite
• A new interface for how security
and development teams can work
together in harmony
Benefits of Sec. Unit Testing
32
• Security regression is a big problem
• We can use the development paradigm of regression testing to address
security regression
• Dynamic test generation can take us a long way
• Individual tests for individual cases further augment dynamic test generation
capabilities
Recap
33
• Security Unit Testing Project
https://github.com/lavalamp-/security-unit-testing
• Lavalamp’s Personal Blog
https://l.avala.mp/
• Django Web Framework
https://www.djangoproject.com/
Resources
34
THANK YOU!
@_lavalamp
chris [AT] websight [DOT] io
github.com/lavalamp-

More Related Content

What's hot

Functional & Performance Test Automation with CI
Functional & Performance Test Automation with CI Functional & Performance Test Automation with CI
Functional & Performance Test Automation with CI Leonard Fingerman
 
Automation Tools Overview
Automation Tools OverviewAutomation Tools Overview
Automation Tools OverviewMurageppa-QA
 
ATAGTR2017 Cost-effective Security Testing Approaches for Web, Mobile & Enter...
ATAGTR2017 Cost-effective Security Testing Approaches for Web, Mobile & Enter...ATAGTR2017 Cost-effective Security Testing Approaches for Web, Mobile & Enter...
ATAGTR2017 Cost-effective Security Testing Approaches for Web, Mobile & Enter...Agile Testing Alliance
 
Continuous Test Automation via CI (CodeMash 2012) - Automating the Agile way
Continuous Test Automation via CI (CodeMash 2012) - Automating the Agile wayContinuous Test Automation via CI (CodeMash 2012) - Automating the Agile way
Continuous Test Automation via CI (CodeMash 2012) - Automating the Agile wayLeonard Fingerman
 
The Amazing Bug Story
The Amazing Bug StoryThe Amazing Bug Story
The Amazing Bug StoryLiviuLupei1
 
#1 unit testing
#1 unit testing#1 unit testing
#1 unit testingeleksdev
 
Tools for Software Testing
Tools for Software TestingTools for Software Testing
Tools for Software TestingMohammed Moishin
 
How do you implement Continuous Delivery? Part 3: All about Pipelines
How do you implement Continuous Delivery? Part 3: All about PipelinesHow do you implement Continuous Delivery? Part 3: All about Pipelines
How do you implement Continuous Delivery? Part 3: All about PipelinesThoughtworks
 
Test driven development
Test driven developmentTest driven development
Test driven developmentnamkha87
 
Code review process with JetBrains UpSource
Code review process with JetBrains UpSourceCode review process with JetBrains UpSource
Code review process with JetBrains UpSourceOleksii Prohonnyi
 
Performance Testing | Instamojo
Performance Testing | InstamojoPerformance Testing | Instamojo
Performance Testing | InstamojoMohit Shukla
 

What's hot (20)

Agile test practices
Agile test practicesAgile test practices
Agile test practices
 
Functional & Performance Test Automation with CI
Functional & Performance Test Automation with CI Functional & Performance Test Automation with CI
Functional & Performance Test Automation with CI
 
Automation Tools Overview
Automation Tools OverviewAutomation Tools Overview
Automation Tools Overview
 
ATAGTR2017 Cost-effective Security Testing Approaches for Web, Mobile & Enter...
ATAGTR2017 Cost-effective Security Testing Approaches for Web, Mobile & Enter...ATAGTR2017 Cost-effective Security Testing Approaches for Web, Mobile & Enter...
ATAGTR2017 Cost-effective Security Testing Approaches for Web, Mobile & Enter...
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
Continuous Test Automation via CI (CodeMash 2012) - Automating the Agile way
Continuous Test Automation via CI (CodeMash 2012) - Automating the Agile wayContinuous Test Automation via CI (CodeMash 2012) - Automating the Agile way
Continuous Test Automation via CI (CodeMash 2012) - Automating the Agile way
 
The Amazing Bug Story
The Amazing Bug StoryThe Amazing Bug Story
The Amazing Bug Story
 
Continuous testing for devops
Continuous testing for devopsContinuous testing for devops
Continuous testing for devops
 
Testing Tools
Testing ToolsTesting Tools
Testing Tools
 
Testing
TestingTesting
Testing
 
#1 unit testing
#1 unit testing#1 unit testing
#1 unit testing
 
Automation With A Tool Demo
Automation With A Tool DemoAutomation With A Tool Demo
Automation With A Tool Demo
 
Tools for Software Testing
Tools for Software TestingTools for Software Testing
Tools for Software Testing
 
Continuous testing
Continuous testing Continuous testing
Continuous testing
 
How do you implement Continuous Delivery? Part 3: All about Pipelines
How do you implement Continuous Delivery? Part 3: All about PipelinesHow do you implement Continuous Delivery? Part 3: All about Pipelines
How do you implement Continuous Delivery? Part 3: All about Pipelines
 
Test driven development
Test driven developmentTest driven development
Test driven development
 
Code review process with JetBrains UpSource
Code review process with JetBrains UpSourceCode review process with JetBrains UpSource
Code review process with JetBrains UpSource
 
How to Introduce Continuous Delivery
How to Introduce Continuous DeliveryHow to Introduce Continuous Delivery
How to Introduce Continuous Delivery
 
Performance Testing | Instamojo
Performance Testing | InstamojoPerformance Testing | Instamojo
Performance Testing | Instamojo
 
Test automation within a scrum process
Test automation within a scrum processTest automation within a scrum process
Test automation within a scrum process
 

Similar to Addressing Security Regression Through Unit Testing

No Devops Without Continuous Testing
No Devops Without Continuous TestingNo Devops Without Continuous Testing
No Devops Without Continuous TestingParasoft
 
Agile and Continuous Delivery for Audits and Exams - DC Continuous Delivery M...
Agile and Continuous Delivery for Audits and Exams - DC Continuous Delivery M...Agile and Continuous Delivery for Audits and Exams - DC Continuous Delivery M...
Agile and Continuous Delivery for Audits and Exams - DC Continuous Delivery M...Simon Storm
 
Are your DevOps and Security teams friends or foes?
Are your DevOps and Security teams friends or foes?Are your DevOps and Security teams friends or foes?
Are your DevOps and Security teams friends or foes?Reuven Harrison
 
Software Testing Strategy
Software Testing StrategySoftware Testing Strategy
Software Testing StrategyAjeng Savitri
 
software testing
 software testing software testing
software testingSara shall
 
Application Lifecycle Management
Application Lifecycle ManagementApplication Lifecycle Management
Application Lifecycle ManagementAmazon Web Services
 
Scaling security in a cloud environment v0.5 (Sep 2017)
Scaling security in a cloud environment  v0.5 (Sep 2017)Scaling security in a cloud environment  v0.5 (Sep 2017)
Scaling security in a cloud environment v0.5 (Sep 2017)Dinis Cruz
 
Wellington MuleSoft Meetup 2021-02-18
Wellington MuleSoft Meetup 2021-02-18Wellington MuleSoft Meetup 2021-02-18
Wellington MuleSoft Meetup 2021-02-18Mary Joy Sabal
 
Software testing methods, levels and types
Software testing methods, levels and typesSoftware testing methods, levels and types
Software testing methods, levels and typesConfiz
 
How to go from waterfall app dev to secure agile development in 2 weeks
How to go from waterfall app dev to secure agile development in 2 weeks How to go from waterfall app dev to secure agile development in 2 weeks
How to go from waterfall app dev to secure agile development in 2 weeks Ulf Mattsson
 
5 Steps to Jump Start Your Test Automation
5 Steps to Jump Start Your Test Automation5 Steps to Jump Start Your Test Automation
5 Steps to Jump Start Your Test AutomationSauce Labs
 
DevOps Overview in my own words
DevOps Overview in my own wordsDevOps Overview in my own words
DevOps Overview in my own wordsSUBHENDU KARMAKAR
 
Automated testing overview
Automated testing overviewAutomated testing overview
Automated testing overviewAlex Pop
 
Quality assuarance bharath anche (1)
Quality assuarance bharath anche (1)Quality assuarance bharath anche (1)
Quality assuarance bharath anche (1)bharathanche
 
SplunkLive! London 2016 Splunk for Devops
SplunkLive! London 2016 Splunk for DevopsSplunkLive! London 2016 Splunk for Devops
SplunkLive! London 2016 Splunk for DevopsSplunk
 
Continuous Testing of Cloud Applications
Continuous Testing of Cloud ApplicationsContinuous Testing of Cloud Applications
Continuous Testing of Cloud ApplicationsTechWell
 
Create code confidence for better application security
Create code confidence for better application security Create code confidence for better application security
Create code confidence for better application security Rogue Wave Software
 

Similar to Addressing Security Regression Through Unit Testing (20)

Different Types Of Testing
Different Types Of TestingDifferent Types Of Testing
Different Types Of Testing
 
No Devops Without Continuous Testing
No Devops Without Continuous TestingNo Devops Without Continuous Testing
No Devops Without Continuous Testing
 
Agile and Continuous Delivery for Audits and Exams - DC Continuous Delivery M...
Agile and Continuous Delivery for Audits and Exams - DC Continuous Delivery M...Agile and Continuous Delivery for Audits and Exams - DC Continuous Delivery M...
Agile and Continuous Delivery for Audits and Exams - DC Continuous Delivery M...
 
Are your DevOps and Security teams friends or foes?
Are your DevOps and Security teams friends or foes?Are your DevOps and Security teams friends or foes?
Are your DevOps and Security teams friends or foes?
 
Software Testing Strategy
Software Testing StrategySoftware Testing Strategy
Software Testing Strategy
 
software testing
 software testing software testing
software testing
 
Application Lifecycle Management
Application Lifecycle ManagementApplication Lifecycle Management
Application Lifecycle Management
 
Scaling security in a cloud environment v0.5 (Sep 2017)
Scaling security in a cloud environment  v0.5 (Sep 2017)Scaling security in a cloud environment  v0.5 (Sep 2017)
Scaling security in a cloud environment v0.5 (Sep 2017)
 
Wellington MuleSoft Meetup 2021-02-18
Wellington MuleSoft Meetup 2021-02-18Wellington MuleSoft Meetup 2021-02-18
Wellington MuleSoft Meetup 2021-02-18
 
Software testing methods, levels and types
Software testing methods, levels and typesSoftware testing methods, levels and types
Software testing methods, levels and types
 
How to go from waterfall app dev to secure agile development in 2 weeks
How to go from waterfall app dev to secure agile development in 2 weeks How to go from waterfall app dev to secure agile development in 2 weeks
How to go from waterfall app dev to secure agile development in 2 weeks
 
5 Steps to Jump Start Your Test Automation
5 Steps to Jump Start Your Test Automation5 Steps to Jump Start Your Test Automation
5 Steps to Jump Start Your Test Automation
 
DevOps on AWS
DevOps on AWSDevOps on AWS
DevOps on AWS
 
DevOps Overview in my own words
DevOps Overview in my own wordsDevOps Overview in my own words
DevOps Overview in my own words
 
Automated testing overview
Automated testing overviewAutomated testing overview
Automated testing overview
 
Quality assuarance bharath anche (1)
Quality assuarance bharath anche (1)Quality assuarance bharath anche (1)
Quality assuarance bharath anche (1)
 
SplunkLive! London 2016 Splunk for Devops
SplunkLive! London 2016 Splunk for DevopsSplunkLive! London 2016 Splunk for Devops
SplunkLive! London 2016 Splunk for Devops
 
SDLCTesting
SDLCTestingSDLCTesting
SDLCTesting
 
Continuous Testing of Cloud Applications
Continuous Testing of Cloud ApplicationsContinuous Testing of Cloud Applications
Continuous Testing of Cloud Applications
 
Create code confidence for better application security
Create code confidence for better application security Create code confidence for better application security
Create code confidence for better application security
 

More from Christopher Grayson

CableTap - Wirelessly Tapping Your Home Network
CableTap - Wirelessly Tapping Your Home NetworkCableTap - Wirelessly Tapping Your Home Network
CableTap - Wirelessly Tapping Your Home NetworkChristopher Grayson
 
You, and Me, and Docker Makes Three
You, and Me, and Docker Makes ThreeYou, and Me, and Docker Makes Three
You, and Me, and Docker Makes ThreeChristopher Grayson
 
Started In Security Now I'm Here
Started In Security Now I'm HereStarted In Security Now I'm Here
Started In Security Now I'm HereChristopher Grayson
 
Cloudstone - Sharpening Your Weapons Through Big Data
Cloudstone - Sharpening Your Weapons Through Big DataCloudstone - Sharpening Your Weapons Through Big Data
Cloudstone - Sharpening Your Weapons Through Big DataChristopher Grayson
 
Security Compensation - How to Invest in Start-Up Security
Security Compensation - How to Invest in Start-Up SecuritySecurity Compensation - How to Invest in Start-Up Security
Security Compensation - How to Invest in Start-Up SecurityChristopher Grayson
 
Introduction to LavaPasswordFactory
Introduction to LavaPasswordFactoryIntroduction to LavaPasswordFactory
Introduction to LavaPasswordFactoryChristopher Grayson
 
Root the Box - An Open Source Platform for CTF Administration
Root the Box - An Open Source Platform for CTF AdministrationRoot the Box - An Open Source Platform for CTF Administration
Root the Box - An Open Source Platform for CTF AdministrationChristopher Grayson
 
Grey H@t - Academic Year 2012-2013 Recap
Grey H@t - Academic Year 2012-2013 RecapGrey H@t - Academic Year 2012-2013 Recap
Grey H@t - Academic Year 2012-2013 RecapChristopher Grayson
 
Grey H@t - Cross-site Request Forgery
Grey H@t - Cross-site Request ForgeryGrey H@t - Cross-site Request Forgery
Grey H@t - Cross-site Request ForgeryChristopher Grayson
 

More from Christopher Grayson (11)

CableTap - Wirelessly Tapping Your Home Network
CableTap - Wirelessly Tapping Your Home NetworkCableTap - Wirelessly Tapping Your Home Network
CableTap - Wirelessly Tapping Your Home Network
 
You, and Me, and Docker Makes Three
You, and Me, and Docker Makes ThreeYou, and Me, and Docker Makes Three
You, and Me, and Docker Makes Three
 
Started In Security Now I'm Here
Started In Security Now I'm HereStarted In Security Now I'm Here
Started In Security Now I'm Here
 
Cloudstone - Sharpening Your Weapons Through Big Data
Cloudstone - Sharpening Your Weapons Through Big DataCloudstone - Sharpening Your Weapons Through Big Data
Cloudstone - Sharpening Your Weapons Through Big Data
 
Security Compensation - How to Invest in Start-Up Security
Security Compensation - How to Invest in Start-Up SecuritySecurity Compensation - How to Invest in Start-Up Security
Security Compensation - How to Invest in Start-Up Security
 
So You Want to be a Hacker?
So You Want to be a Hacker?So You Want to be a Hacker?
So You Want to be a Hacker?
 
Introduction to LavaPasswordFactory
Introduction to LavaPasswordFactoryIntroduction to LavaPasswordFactory
Introduction to LavaPasswordFactory
 
Root the Box - An Open Source Platform for CTF Administration
Root the Box - An Open Source Platform for CTF AdministrationRoot the Box - An Open Source Platform for CTF Administration
Root the Box - An Open Source Platform for CTF Administration
 
Grey H@t - Academic Year 2012-2013 Recap
Grey H@t - Academic Year 2012-2013 RecapGrey H@t - Academic Year 2012-2013 Recap
Grey H@t - Academic Year 2012-2013 Recap
 
Grey H@t - DNS Cache Poisoning
Grey H@t - DNS Cache PoisoningGrey H@t - DNS Cache Poisoning
Grey H@t - DNS Cache Poisoning
 
Grey H@t - Cross-site Request Forgery
Grey H@t - Cross-site Request ForgeryGrey H@t - Cross-site Request Forgery
Grey H@t - Cross-site Request Forgery
 

Recently uploaded

TRENDS Enabling and inhibiting dimensions.pptx
TRENDS Enabling and inhibiting dimensions.pptxTRENDS Enabling and inhibiting dimensions.pptx
TRENDS Enabling and inhibiting dimensions.pptxAndrieCagasanAkio
 
『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书
『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书
『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书rnrncn29
 
『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书
『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书
『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书rnrncn29
 
Top 10 Interactive Website Design Trends in 2024.pptx
Top 10 Interactive Website Design Trends in 2024.pptxTop 10 Interactive Website Design Trends in 2024.pptx
Top 10 Interactive Website Design Trends in 2024.pptxDyna Gilbert
 
办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书
办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书
办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书zdzoqco
 
Unidad 4 – Redes de ordenadores (en inglés).pptx
Unidad 4 – Redes de ordenadores (en inglés).pptxUnidad 4 – Redes de ordenadores (en inglés).pptx
Unidad 4 – Redes de ordenadores (en inglés).pptxmibuzondetrabajo
 
Company Snapshot Theme for Business by Slidesgo.pptx
Company Snapshot Theme for Business by Slidesgo.pptxCompany Snapshot Theme for Business by Slidesgo.pptx
Company Snapshot Theme for Business by Slidesgo.pptxMario
 
IP addressing and IPv6, presented by Paul Wilson at IETF 119
IP addressing and IPv6, presented by Paul Wilson at IETF 119IP addressing and IPv6, presented by Paul Wilson at IETF 119
IP addressing and IPv6, presented by Paul Wilson at IETF 119APNIC
 
SCM Symposium PPT Format Customer loyalty is predi
SCM Symposium PPT Format Customer loyalty is prediSCM Symposium PPT Format Customer loyalty is predi
SCM Symposium PPT Format Customer loyalty is predieusebiomeyer
 
Film cover research (1).pptxsdasdasdasdasdasa
Film cover research (1).pptxsdasdasdasdasdasaFilm cover research (1).pptxsdasdasdasdasdasa
Film cover research (1).pptxsdasdasdasdasdasa494f574xmv
 
ETHICAL HACKING dddddddddddddddfnandni.pptx
ETHICAL HACKING dddddddddddddddfnandni.pptxETHICAL HACKING dddddddddddddddfnandni.pptx
ETHICAL HACKING dddddddddddddddfnandni.pptxNIMMANAGANTI RAMAKRISHNA
 

Recently uploaded (11)

TRENDS Enabling and inhibiting dimensions.pptx
TRENDS Enabling and inhibiting dimensions.pptxTRENDS Enabling and inhibiting dimensions.pptx
TRENDS Enabling and inhibiting dimensions.pptx
 
『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书
『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书
『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书
 
『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书
『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书
『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书
 
Top 10 Interactive Website Design Trends in 2024.pptx
Top 10 Interactive Website Design Trends in 2024.pptxTop 10 Interactive Website Design Trends in 2024.pptx
Top 10 Interactive Website Design Trends in 2024.pptx
 
办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书
办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书
办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书
 
Unidad 4 – Redes de ordenadores (en inglés).pptx
Unidad 4 – Redes de ordenadores (en inglés).pptxUnidad 4 – Redes de ordenadores (en inglés).pptx
Unidad 4 – Redes de ordenadores (en inglés).pptx
 
Company Snapshot Theme for Business by Slidesgo.pptx
Company Snapshot Theme for Business by Slidesgo.pptxCompany Snapshot Theme for Business by Slidesgo.pptx
Company Snapshot Theme for Business by Slidesgo.pptx
 
IP addressing and IPv6, presented by Paul Wilson at IETF 119
IP addressing and IPv6, presented by Paul Wilson at IETF 119IP addressing and IPv6, presented by Paul Wilson at IETF 119
IP addressing and IPv6, presented by Paul Wilson at IETF 119
 
SCM Symposium PPT Format Customer loyalty is predi
SCM Symposium PPT Format Customer loyalty is prediSCM Symposium PPT Format Customer loyalty is predi
SCM Symposium PPT Format Customer loyalty is predi
 
Film cover research (1).pptxsdasdasdasdasdasa
Film cover research (1).pptxsdasdasdasdasdasaFilm cover research (1).pptxsdasdasdasdasdasa
Film cover research (1).pptxsdasdasdasdasdasa
 
ETHICAL HACKING dddddddddddddddfnandni.pptx
ETHICAL HACKING dddddddddddddddfnandni.pptxETHICAL HACKING dddddddddddddddfnandni.pptx
ETHICAL HACKING dddddddddddddddfnandni.pptx
 

Addressing Security Regression Through Unit Testing

  • 1. Security Regression Addressing Security Regression by Unit Testing Christopher Grayson @_lavalamp
  • 3. WHOAMI 3 • ATL • Web development • Academic researcher • Haxin’ all the things • (but I rlllly like networks) • Founder • Red team @_lavalamp
  • 4. • Security regression is a huge problem • Lots of infrastructure built around regression testing already • Let’s leverage all of that existing infrastructure to improve application security posture at a minimal cost to development teams WHY’S DIS 4
  • 5. 1. Background 2. Dynamic Security Test Generation 3. Non-dynamic Security Test Generation 4. Conclusion Agenda 5
  • 7. • I’ve always loved breaking into things, have been doing this professionally since 2012 • Go in, break app, help client with remediation, check that remediation worked – great! • Come back 3-6 months later and test again, same vulns are back (commonly in the same places) • Offensive testing is good at diagnosing - not solving A Bit More on Motivation… 7
  • 8. • Standard tool in any development team’s toolbox • Unit tests to ensure code does not regress to a prior state of instability • Lots of great tools (especially in the CI/CD chain) for ensuring tests are passing before deployment Regression Testing 8
  • 9. Why not take the problem of security regression and use all of the tools already built for regression testing to improve the security posture of tested applications? Putting it All Together 9
  • 10. • Street Art Around the World! • Written in Django (standard framework, no API, full post-back) • Same techniques work for any programming language and framework that support introspection • These examples require a framework that has explicit URL mapping The Demo Application 10 https://github.com/lavalamp-/security-unit-testing
  • 12. • Django requires users to write views and then explicitly map these views to URL routes where they are served from • Views come from a set of pre- defined base classes that support default functionality (UpdateView, DeleteView, DetailView, FormView, etc) Django Registered Routes 12
  • 13. • We can use introspection to enumerate all of the views registered within an application • Now that we know the views, how can we support testing functionality that issues requests to all of the view functionality? • Enter the Requestor class Testing Registered Routes 13
  • 14. • Requestors mapped to views they are meant to send requests to via Python decorators • Singleton registry contains mapping of views to requestors • Importing all of the views automatically establishes all of the mappings Requestor Registry Architecture 14
  • 15. • We now can enumerate all of the views and access classes that are designed to submit requests to the views • With this capability we can dynamically generate test cases for all of the views in an application • Test cases take view classes and HTTP verbs as arguments to constructors Dynamic Test Generation 15
  • 16. If we are relying on requestor classes being defined for all views, then let’s test for it! Testing for Requestors 16
  • 17. We’ve got the ability to test every known HTTP verb of every registered view, so let’s test for successful HTTP responses. Testing for Denial of Service 17
  • 18. Test to ensure that the methods supported by requestors match the methods returned by OPTIONS request. Testing for Unknown Methods 18
  • 19. • Tell the requestors whether or not the tested view requires authentication • Can improve upon this demo by checking for inheritance of the LoginRequiredMixin • Check that unauthenticated request is denied Testing for Auth Enforcement 19
  • 21. We already built out requestors based on the OPTIONS response, so now let’s make sure that the OPTIONS response included the correct HTTP verbs. Testing for OPTIONS Accuracy 21
  • 22. Test to ensure that CSRF tokens are required for function invocation on non-idempotent view functionality. Testing for CSRF Enforcement 22
  • 23. • We now have guarantees that • Our app contains no hidden functionality • All of our views are working as intended given expected input • Authentication is being properly enforced • Security headers are present • CSRF is properly protected against What Have We Gained? 23
  • 24. • Those guarantees are great and all, but can’t we just write individual unit tests to test for them? • In a development team we have multiple people contributing code all the time • Through dynamic generation, these tests will automatically be applied to all new views, providing the same guarantees to code that hasn’t even been written yet Why Dynamic Generation? 24
  • 25. • Other things that we could write dynamic tests for • Rate-limiting • Fuzzing of all input values to POST/PUT/PATCH/DELETE (introspection into forms used to power the views) • Proper updating, creation, and deletion of new models based on input data Where Can We Go? 25
  • 27. Test for proper encoding of output data! Testing for Cross-site Scripting 27
  • 28. Submit two requests to the server, one making the SQL query match none and another making the SQL query match all, test to see if the results match the none and all expected responses Testing for SQL Injection 28
  • 29. Submit malicious input and see if HTTP redirect response redirects to full URL Testing for Open Redirects 29
  • 31. • Initial overhead is greater than writing individual unit tests, but new views added to the application also benefit from the tests • Provide us with strong guarantees about known application functionality and basic HTTP-based security controls Benefits of Dynamic Generation 31
  • 32. • Security guarantees now enforced by CI/CD integration • Test Driven Development? Great – have your security testers write failing unit tests that you then incorporate into your test suite • A new interface for how security and development teams can work together in harmony Benefits of Sec. Unit Testing 32
  • 33. • Security regression is a big problem • We can use the development paradigm of regression testing to address security regression • Dynamic test generation can take us a long way • Individual tests for individual cases further augment dynamic test generation capabilities Recap 33
  • 34. • Security Unit Testing Project https://github.com/lavalamp-/security-unit-testing • Lavalamp’s Personal Blog https://l.avala.mp/ • Django Web Framework https://www.djangoproject.com/ Resources 34
  • 35. THANK YOU! @_lavalamp chris [AT] websight [DOT] io github.com/lavalamp-

Editor's Notes

  1. Show an example of a View (CreatePostView) Show the base requestor class (BaseRequestor) Show an implementation of a requestor class (CreatePostViewRequestor)
  2. Checkout HEAD of master branch (git checkout master) Show the registry class (TestRequestorRegistry) Show the decorator (requested_by in tests/registry.py) Show the add_mapping method in TestRequestorRegistry Show the implementation of requested_by (CreatePostView) Run the following code to show the mapping: python manage.py shell -c "from sectesting import urls; from streetart.tests import TestRequestorRegistry; registry = TestRequestorRegistry.instance(); registry.print_mappings()"
  3. Checkout HEAD of master branch (git checkout master) Show contents of build_suite method in StreetArtTestRunner Show contents of __get_requestor_class_tests in StreetArtTestRunner Show contents of url_patterns property in StreetArtTestRunner Point out the anonymous subclassing thing
  4. Ensure that TEST_FOR_REQUESTOR_CLASSES is the only True value in settings Check out tag v0.1 (git checkout tags/v0.1) Show contents of ViewHasRequestorTestCase Show contents of __get_requestor_class_tests in StreetArtTestRunner Comment out a requested_by on one of the views Run tests and show failing (python manage.py test) Uncomment out requested_by Run tests and show all passing
  5. Ensure that TEST_FOR_DENIAL_OF_SERVICE is the only True value in settings Check out tag v0.1 (git checkout tags/v0.1) Show contents of RegularViewRequestIsSuccessfulTestCase Show contents of ____get_dos_class_tests in StreetArtTestRunner Add raise PermissionDenied to EditPostView GET Run tests and show failing (python manage.py test) Remove the PermissionDenied raise Run tests and show passing (python manage.py test)
  6. Ensure that TEST_FOR_UNKNOWN_METHODS is the only True value in settings Check out tag v0.1 (git checkout tags/v0.1) Show contents of RegularUnknownMethodsTestCase Run tests and show failing (python manage.py test) Checkout the next tag (git checkout tags/v0.2) Show contents of DeletePostViewRequestor with new verbs Run tests and show passing (python manage.py test) Unknown functionality is a constant problem with web apps (especially in frameworks that provide significant amounts of functionality out of the box)
  7. Ensure that TEST_FOR_AUTHENTICATION_ENFORCEMENT is the only True value in settings Check out tag v0.3 (git checkout tags/v0.3) Show contents of AuthenticationEnforcementTestCase Run tests and show failing (python manage.py test) Checkout the next tag (git checkout tags/v0.4) Show contents of MyPostsListView with new auth check Run tests and show passing (python manage.py test)
  8. Ensure that TEST_FOR_RESPONSE_HEADERS is the only True value in settings Check out tag v0.5 (git checkout tags/v0.5) Ensure that streetart.middleware.SecurityHeadersMiddleware is commented out in settings.py Show contents of HeaderKeyExistsTestCase and HeaderValueAccurateTestCase Run tests and show failing (python manage.py test) Checkout the next tag (git checkout tags/v0.6) Uncomment streetart.middleware.SecurityHeadersMiddleware in settings.py Run tests and show passing (python manage.py test)
  9. Ensure that TEST_FOR_OPTIONS_ACCURACYis the only True value in settings Check out tag v0.9 (git checkout tags/v0.9) Show contents of RegularVerbNotSupportedTestCase and AdminVerbNotSupportedTestCase Show contents of MyPostsListView trace method Run tests and show failing (python manage.py test) Checkout the next tag (git checkout tags/v0.10) Show contents of MyPostsListView Run tests and show passing (python manage.py test)
  10. Ensure that TEST_FOR_CSRF_ENFORCEMENT is the only True value in settings Check out tag v0.11 (git checkout tags/v0.11) Show contents of CsrfEnforcementTestCase Show contents of CreatePostView with reference to csrf_exempt Run tests and show failing (python manage.py test) Checkout the next tag (git checkout tags/v0.12) Show contents of CreatePostView with no reference to csrf_exempt Run tests and show passing (python manage.py test) Just because CSRF values are present doesn’t mean they are properly enforced
  11. Ensure that all test cases are enabled Check out tag v0.15 (git checkout tags/v0.15) Show contents of NewCreatePostView Run tests and show failing (python manage.py test) Talk about how author neglected to add requestor Checkout the next tag (git checkout tags/v0.16) Show that requestor has been added to NewCreatePostView Run tests and show failing (python manage.py test)
  12. Check out tag v0.13 (git checkout tags/v0.13) Show contents of ErrorDetailsXSSTestCase Show contents of error_details.html and point out |safe pipe Run tests and show failing (python manage.py test) Checkout the next tag (git checkout tags/v0.14) Show contents of error_details.html and point out lack of pipe Run tests and show failing (python manage.py test)
  13. Check out tag v0.19 (git checkout tags/v0.19) Show contents of SQLInjectionGetPostsByViewTestCase Show contents of GetPostsByTitleView Run tests and show failing (python manage.py test) Checkout the next tag (git checkout tags/v0.20) Show contents of GetPostsByTitleView and point out parameter binding Run tests and show failing (python manage.py test)
  14. Check out tag v0.21 (git checkout tags/v0.21) Show contents of RedirectViewTestCase Show contents of RedirectView Run tests and show failing (python manage.py test) Checkout the next tag (git checkout tags/v0.21) Show contents of RedirectView and point out parameter sanitization Run tests and show failing (python manage.py test)