35
Security Regression Addressing Security Regression by Unit Testing Christopher Grayson @_lavalamp

security regression 06262017 2 - QCon New YorkDynamic Security Test Generation 3. Non-dynamic Security Test Generation 4. Conclusion Agenda 5. ... • Written in Django (standard framework,

  • Upload
    others

  • View
    1

  • Download
    0

Embed Size (px)

Citation preview

Page 1: security regression 06262017 2 - QCon New YorkDynamic Security Test Generation 3. Non-dynamic Security Test Generation 4. Conclusion Agenda 5. ... • Written in Django (standard framework,

SecurityRegressionAddressingSecurityRegressionbyUnitTesting

ChristopherGrayson@_lavalamp

Page 2: security regression 06262017 2 - QCon New YorkDynamic Security Test Generation 3. Non-dynamic Security Test Generation 4. Conclusion Agenda 5. ... • Written in Django (standard framework,

Introduction

Page 3: security regression 06262017 2 - QCon New YorkDynamic Security Test Generation 3. Non-dynamic Security Test Generation 4. Conclusion Agenda 5. ... • Written in Django (standard framework,

WHOAMI

3

• ATL• Webdevelopment• Academicresearcher• Haxin’allthethings• (butIrlllly likenetworks)

• Founder• Redteam

@_lavalamp

Page 4: security regression 06262017 2 - QCon New YorkDynamic Security Test Generation 3. Non-dynamic Security Test Generation 4. Conclusion Agenda 5. ... • Written in Django (standard framework,

• Securityregressionisahugeproblem• Lotsofinfrastructurebuiltaroundregressiontestingalready• Let’sleverageallofthatexistinginfrastructuretoimproveapplicationsecuritypostureataminimalcosttodevelopmentteams

WHY’S DIS

4

Page 5: security regression 06262017 2 - QCon New YorkDynamic Security Test Generation 3. Non-dynamic Security Test Generation 4. Conclusion Agenda 5. ... • Written in Django (standard framework,

1. Background

2. DynamicSecurityTestGeneration

3. Non-dynamicSecurityTestGeneration

4. Conclusion

Agenda

5

Page 6: security regression 06262017 2 - QCon New YorkDynamic Security Test Generation 3. Non-dynamic Security Test Generation 4. Conclusion Agenda 5. ... • Written in Django (standard framework,

Background

Page 7: security regression 06262017 2 - QCon New YorkDynamic Security Test Generation 3. Non-dynamic Security Test Generation 4. Conclusion Agenda 5. ... • Written in Django (standard framework,

• I’vealwayslovedbreakingintothings,havebeendoingthisprofessionallysince2012• Goin,breakapp,helpclientwithremediation,checkthatremediationworked– great!• Comeback3-6monthslaterandtestagain,samevulns areback(commonlyinthesameplaces)• Offensivetestingisgoodatdiagnosing- notsolving

A Bit More on Motivation…

7

Page 8: security regression 06262017 2 - QCon New YorkDynamic Security Test Generation 3. Non-dynamic Security Test Generation 4. Conclusion Agenda 5. ... • Written in Django (standard framework,

• Standardtoolinanydevelopmentteam’stoolbox• Unitteststoensurecodedoesnotregresstoapriorstateofinstability• Lotsofgreattools(especiallyintheCI/CDchain)forensuringtestsarepassingbeforedeployment

Regression Testing

8

Page 9: security regression 06262017 2 - QCon New YorkDynamic Security Test Generation 3. Non-dynamic Security Test Generation 4. Conclusion Agenda 5. ... • Written in Django (standard framework,

Whynottaketheproblemofsecurityregressionanduseallofthetoolsalreadybuiltforregressiontestingtoimprovethesecuritypostureoftestedapplications?

Putting it All Together

9

Page 10: security regression 06262017 2 - QCon New YorkDynamic Security Test Generation 3. Non-dynamic Security Test Generation 4. Conclusion Agenda 5. ... • Written in Django (standard framework,

• StreetArtAroundtheWorld!• WritteninDjango(standardframework,noAPI,fullpost-back)• Sametechniquesworkforanyprogramminglanguageandframeworkthatsupportintrospection• TheseexamplesrequireaframeworkthathasexplicitURLmapping

The Demo Application

10

https://github.com/lavalamp-/security-unit-testing

Page 11: security regression 06262017 2 - QCon New YorkDynamic Security Test Generation 3. Non-dynamic Security Test Generation 4. Conclusion Agenda 5. ... • Written in Django (standard framework,

Dynamic Generation

Page 12: security regression 06262017 2 - QCon New YorkDynamic Security Test Generation 3. Non-dynamic Security Test Generation 4. Conclusion Agenda 5. ... • Written in Django (standard framework,

• DjangorequiresuserstowriteviewsandthenexplicitlymaptheseviewstoURLrouteswheretheyareservedfrom• Viewscomefromasetofpre-definedbaseclassesthatsupportdefaultfunctionality(UpdateView,DeleteView,DetailView,FormView,etc)

Django Registered Routes

12

Page 13: security regression 06262017 2 - QCon New YorkDynamic Security Test Generation 3. Non-dynamic Security Test Generation 4. Conclusion Agenda 5. ... • Written in Django (standard framework,

• Wecanuseintrospectiontoenumeratealloftheviewsregisteredwithinanapplication• Nowthatweknowtheviews,howcanwesupporttestingfunctionalitythatissuesrequeststoalloftheviewfunctionality?• EntertheRequestor class

Testing Registered Routes

13

Page 14: security regression 06262017 2 - QCon New YorkDynamic Security Test Generation 3. Non-dynamic Security Test Generation 4. Conclusion Agenda 5. ... • Written in Django (standard framework,

• RequestorsmappedtoviewstheyaremeanttosendrequeststoviaPythondecorators• Singletonregistrycontainsmappingofviewstorequestors• Importingalloftheviewsautomaticallyestablishesallofthemappings

Requestor Registry Architecture

14

Page 15: security regression 06262017 2 - QCon New YorkDynamic Security Test Generation 3. Non-dynamic Security Test Generation 4. Conclusion Agenda 5. ... • Written in Django (standard framework,

• Wenowcanenumeratealloftheviewsandaccessclassesthataredesignedtosubmitrequeststotheviews• Withthiscapabilitywecandynamicallygeneratetestcasesforalloftheviewsinanapplication• TestcasestakeviewclassesandHTTPverbsasargumentstoconstructors

Dynamic Test Generation

15

Page 16: security regression 06262017 2 - QCon New YorkDynamic Security Test Generation 3. Non-dynamic Security Test Generation 4. Conclusion Agenda 5. ... • Written in Django (standard framework,

Ifwearerelyingonrequestorclassesbeingdefinedforallviews,thenlet’stestforit!

Testing for Requestors

16

Page 17: security regression 06262017 2 - QCon New YorkDynamic Security Test Generation 3. Non-dynamic Security Test Generation 4. Conclusion Agenda 5. ... • Written in Django (standard framework,

We’vegottheabilitytotesteveryknownHTTPverbofeveryregisteredview,solet’stestforsuccessfulHTTPresponses.

Testing for Denial of Service

17

Page 18: security regression 06262017 2 - QCon New YorkDynamic Security Test Generation 3. Non-dynamic Security Test Generation 4. Conclusion Agenda 5. ... • Written in Django (standard framework,

TesttoensurethatthemethodssupportedbyrequestorsmatchthemethodsreturnedbyOPTIONSrequest.

Testing for Unknown Methods

18

Page 19: security regression 06262017 2 - QCon New YorkDynamic Security Test Generation 3. Non-dynamic Security Test Generation 4. Conclusion Agenda 5. ... • Written in Django (standard framework,

• Telltherequestorswhetherornotthetestedviewrequiresauthentication• Canimproveuponthisdemobycheckingforinheritanceofthe

LoginRequiredMixin• Checkthatunauthenticatedrequestisdenied

Testing for Auth Enforcement

19

Page 20: security regression 06262017 2 - QCon New YorkDynamic Security Test Generation 3. Non-dynamic Security Test Generation 4. Conclusion Agenda 5. ... • Written in Django (standard framework,

Response Header Inclusion

20

Page 21: security regression 06262017 2 - QCon New YorkDynamic Security Test Generation 3. Non-dynamic Security Test Generation 4. Conclusion Agenda 5. ... • Written in Django (standard framework,

WealreadybuiltoutrequestorsbasedontheOPTIONSresponse,sonowlet’smakesurethattheOPTIONSresponseincludedthecorrectHTTP

verbs.

Testing for OPTIONS Accuracy

21

Page 22: security regression 06262017 2 - QCon New YorkDynamic Security Test Generation 3. Non-dynamic Security Test Generation 4. Conclusion Agenda 5. ... • Written in Django (standard framework,

TesttoensurethatCSRFtokensarerequiredforfunctioninvocationonnon-idempotentviewfunctionality.

Testing for CSRF Enforcement

22

Page 23: security regression 06262017 2 - QCon New YorkDynamic Security Test Generation 3. Non-dynamic Security Test Generation 4. Conclusion Agenda 5. ... • Written in Django (standard framework,

• Wenowhaveguaranteesthat• Ourappcontainsnohiddenfunctionality• Allofourviewsareworkingasintendedgivenexpectedinput• Authenticationisbeingproperlyenforced• Securityheadersarepresent• CSRFisproperlyprotectedagainst

What Have We Gained?

23

Page 24: security regression 06262017 2 - QCon New YorkDynamic Security Test Generation 3. Non-dynamic Security Test Generation 4. Conclusion Agenda 5. ... • Written in Django (standard framework,

• Thoseguaranteesaregreatandall,butcan’twejustwriteindividualunitteststotestforthem?• Inadevelopmentteamwehavemultiplepeoplecontributingcodeallthetime• Throughdynamicgeneration,thesetestswillautomaticallybeappliedtoallnewviews,providingthesameguaranteestocodethathasn’tevenbeenwrittenyet

Why Dynamic Generation?

24

Page 25: security regression 06262017 2 - QCon New YorkDynamic Security Test Generation 3. Non-dynamic Security Test Generation 4. Conclusion Agenda 5. ... • Written in Django (standard framework,

• Otherthingsthatwecouldwritedynamictestsfor• Rate-limiting• FuzzingofallinputvaluestoPOST/PUT/PATCH/DELETE(introspectionintoformsusedtopowertheviews)• Properupdating,creation,anddeletionofnewmodelsbasedoninputdata

Where Can We Go?

25

Page 26: security regression 06262017 2 - QCon New YorkDynamic Security Test Generation 3. Non-dynamic Security Test Generation 4. Conclusion Agenda 5. ... • Written in Django (standard framework,

Testing Other Vulns

Page 27: security regression 06262017 2 - QCon New YorkDynamic Security Test Generation 3. Non-dynamic Security Test Generation 4. Conclusion Agenda 5. ... • Written in Django (standard framework,

Testforproperencodingofoutputdata!

Testing for Cross-site Scripting

27

Page 28: security regression 06262017 2 - QCon New YorkDynamic Security Test Generation 3. Non-dynamic Security Test Generation 4. Conclusion Agenda 5. ... • Written in Django (standard framework,

Submittworequeststotheserver,onemakingtheSQLquerymatchnoneandanothermakingtheSQLquerymatchall,testtoseeiftheresultsmatchthe

none andall expectedresponses

Testing for SQL Injection

28

Page 29: security regression 06262017 2 - QCon New YorkDynamic Security Test Generation 3. Non-dynamic Security Test Generation 4. Conclusion Agenda 5. ... • Written in Django (standard framework,

SubmitmaliciousinputandseeifHTTPredirectresponseredirectstofullURL

Testing for Open Redirects

29

Page 30: security regression 06262017 2 - QCon New YorkDynamic Security Test Generation 3. Non-dynamic Security Test Generation 4. Conclusion Agenda 5. ... • Written in Django (standard framework,

Conclusion

Page 31: security regression 06262017 2 - QCon New YorkDynamic Security Test Generation 3. Non-dynamic Security Test Generation 4. Conclusion Agenda 5. ... • Written in Django (standard framework,

• Initialoverheadisgreaterthanwritingindividualunittests,butnewviewsaddedtotheapplicationalsobenefitfromthetests• ProvideuswithstrongguaranteesaboutknownapplicationfunctionalityandbasicHTTP-basedsecuritycontrols

Benefits of Dynamic Generation

31

Page 32: security regression 06262017 2 - QCon New YorkDynamic Security Test Generation 3. Non-dynamic Security Test Generation 4. Conclusion Agenda 5. ... • Written in Django (standard framework,

• SecurityguaranteesnowenforcedbyCI/CDintegration• TestDrivenDevelopment?Great –haveyoursecuritytesterswritefailingunitteststhatyouthenincorporateintoyourtestsuite• Anewinterfaceforhowsecurityanddevelopmentteamscanworktogetherinharmony

Benefits of Sec. Unit Testing

32

Page 33: security regression 06262017 2 - QCon New YorkDynamic Security Test Generation 3. Non-dynamic Security Test Generation 4. Conclusion Agenda 5. ... • Written in Django (standard framework,

• Securityregressionisabigproblem• Wecanusethedevelopmentparadigmofregressiontestingtoaddresssecurityregression• Dynamictestgenerationcantakeusalongway• Individualtestsforindividualcasesfurtheraugmentdynamictestgenerationcapabilities

Recap

33

Page 34: security regression 06262017 2 - QCon New YorkDynamic Security Test Generation 3. Non-dynamic Security Test Generation 4. Conclusion Agenda 5. ... • Written in Django (standard framework,

• SecurityUnitTestingProjecthttps://github.com/lavalamp-/security-unit-testing• Lavalamp’s PersonalBloghttps://l.avala.mp/• DjangoWebFrameworkhttps://www.djangoproject.com/

Resources

34

Page 35: security regression 06262017 2 - QCon New YorkDynamic Security Test Generation 3. Non-dynamic Security Test Generation 4. Conclusion Agenda 5. ... • Written in Django (standard framework,

THANK YOU!

@_lavalampchris [AT] websight [DOT] io

github.com/lavalamp-