SlideShare a Scribd company logo
1 of 65
Download to read offline
Racing The Web
Security Consultant at Security Compass
Professor of Application Security at
Georgian College
Software developer
Former sysadmin
etc.
Aaron Hnatiw
twitter: @insp3ctre
Why am I here?
Race conditions
OWASP Definition
A race condition is a flaw that produces an unexpected
result when the timing of actions impact other actions.
An example may be seen on a multithreaded application
where actions are being performed on the same data.
Race conditions, by their very nature, are difficult to test
for.
https://www.owasp.org/index.php/Testing_for_Race_Conditions_%28OWASP-AT-010%29
CWE-362: Concurrent Execution
using Shared Resource with Improper
Synchronization ('Race Condition’)
https://cwe.mitre.org/data/definitions/362.html
Basically, when you bet on
the wrong horse.
(or even “bet” at all)
Assumption
Race Condition
When does this become a
security issue?
“One time use” coupon
codes
Bug bounty payouts
https://cobalt.io/cobalt/cobalt/reports/587
Balance transfer between
accounts
What does a race condition
look like?
Python
Go
Surprise…
PHP
Testing for race conditions in
web applications
Usual whitebox method
1. Identify all shared data
2. Identify where that shared data is accessed across
systems
3. Find where that data access is not synchronized
4. Make a TON of requests
There’s a better way…
Introducing: Race-The-Web
(RTW)
A tool that automates race condition discovery
Simple configuration (TOML)
Open-source
Written in Go
Demo time
Try it out yourself!
RaceTheWeb.io
Comparison vs Burp Intruder
Speed
• Intruder setup:
• 10 threads (default is 5)
• 3 retries after network failure (2000 ms pause before
retry)- default
• Redirect: always
• 1000 requests (withdraw $1 x 1000)
Speed (cont’d)
• RTW setup:
• Verbose logging
• Follow redirects
• 1000 requests (withdraw $1 x 1000)
Speed (cont’d)
• Results
• Intruder: ~3:10
• RTW: ~2:00
Speed (cont’d)
• Intruder optimizations:
• 999 threads (maximum possible)
• No retries on network failure
• Result: ~2:15
• RTW is still faster
Key difference:
Built-in response comparison in
RTW
// TODO
• Add “proxy” option to config file
• Clean up codebase
• Write Burp plugin
Be careful of DoS.
Most bug bounties have restrictions such as:
https://hackerone.com/airbnb
Useful tip: check for CRUD
functionality.
(especially with remote resources)
Let’s talk about defence
Most effective: Locks
Use with shared resources
Lock #1:
Application-level
Python
• threading.Lock
• acquire()
• release()
• Others:
• threading.RLock
• threading.Condition
• threading.Semaphore
• queue: handles locking automatically for resources in the queue.
More: https://docs.python.org/2/library/threading.html
Python- fix
Go
• sync.mutex
• Lock()
• Unlock()
• sync.RWMutex
• Rlock()
• RWLock()
• Unlock()
https://golang.org/pkg/sync/
Go
Channels:
“Do not communicate by sharing memory; instead,
share memory by communicating.”
Go- fix
PHP
• You could compile PHP with “--enable-sysvsem"...
• Not supported everywhere
• Not useful in a distributed environment
• May not be possible in a shared hosting
environment
• You’re pretty much stuck with implementing this at
the database or file level (more on that later)
• If you know of any other way, please let me know!
Lock #2:
Database-level
Database MUST be ACID-
compliant
ACID-Compliant Databases
• Atomicity: All or nothing. A transaction either succeeds or
rolls back.
• Consistency: On the completion of a transaction, the
database is structurally sound. Otherwise, it reverts back to
the previous sound state.
• Isolation: Transactions do not interfere with each other.
• This point is KEY.
• Durability: The results of applying a transaction are
permanent, even in the presence of failures.
Isolation
• Highest level: serializable.
• Transactions essentially occur serially (one after another), rather
than concurrently.
• Next level: repeatable read.
• Close, but still allows race conditions.
• Be prepared to retry transactions often, because in most cases, these
isolation levels can result in a large number of transaction failures.
• Obvious downside- using higher levels of isolation can slow down
your application.
Solution- MySQL
• From the documentation: "MySQL Server (version
3.23-max and all versions 4.0 and above) supports
transactions with the InnoDB transactional storage
engine. InnoDB provides full ACID compliance."
• Use SERIALIZABLE isolation level
• Default is REPEATABLE-READ
• Can be set globally, for a session, or for individual
transactions
More info: https://dev.mysql.com/doc/refman/5.5/en/innodb-transaction-isolation-
levels.html
MySQL (cont’d)
• System variable: 

SET GLOBAL @@GLOBAL.tx_isolation=`SERIALIZABLE`;
• Command-line option at mysqld startup: 

--transaction-isolation=SERIALIZABLE
• Option file:

[mysqld]

transaction-isolation = SERIALIZABLE
• Command-line, BEFORE starting a transaction:

SET TRANSACTION ISOLATION LEVEL SERIALIZABLE;
More Info: https://dev.mysql.com/doc/refman/5.5/en/set-transaction.html
Solution- PostgreSQL
• Use the SERIALIZABLE transaction isolation level
• Default is READ COMMITTED: all queries see a snapshot of
committed data at the time of the query.
• Command-line:
• START TRANSACTION;

SET TRANSACTION ISOLATION LEVEL SERIALIZABLE;
• START TRANSACTION ISOLATION LEVEL SERIALIZABLE;
• BEGIN TRANSACTION ISOLATION LEVEL SERIALIZABLE;
More info: https://www.postgresql.org/docs/9.3/static/sql-set-transaction.html
PostgreSQL (cont’d)
• Configuration file: postgresql.conf

default_transaction_isolation = ‘serializable’
• Command-line option with postgres command:

postgres -c
default_transaction_isolation=‘serializable’ ...
• Environment variable:

env PGOPTIONS=“-c
default_transaction_isolation=‘serializable’” psql
• Mid-session SQL:

SET SESSION default_transaction_isolation = ‘serializable’;
Realistic compromise
For most use cases:
• Optimize your queries
• Use a single query whenever possible (e.g. UPDATE xTable SET yValue = yValue+1
WHERE id = ‘zID’)
• Inserts instead of updates
• Use unique indexes
• Use an ORM for “optimistic locking”
• Most ORMs do their own optimizations and locking to prevent race conditions, as
opposed to relying on the database’s strict “pessimistic locking”
• Use the READ COMMITTED isolation level
• Not as strict as Serializable, but provides more speed, less locking errors, and more
consistency than REPEATABLE READ
Solution- MongoDB
• No serialization
• From 2.2 on, uses database-level read and write locks, depending on operation (https://
docs.mongodb.com/manual/faq/concurrency/#which-operations-lock-the-database)
• Single document writes are atomic (but not isolated) by default
• $isolated operator
• Acquires an exclusive lock to all documents being written to (only applies when writing to multiple
documents).
• Does not work on sharded clusters.
More info: https://docs.mongodb.com/v3.2/core/write-operations-atomicity/
Lock #3:
File-level
Native Methods
• Windows
• LockFile function of the Windows API: https://msdn.microsoft.com/en-us/library/
aa365202.aspx
• Unix
• flock()/lockf(): essentially the same function
• fcntl(): http://pubs.opengroup.org/onlinepubs/9699919799/functions/fcntl.html
• Some typical “gotchas”: http://0pointer.de/blog/projects/locking.html
• Lock file: create a temporary file (e.g. ~myfile.lck), which exists while a file needs to
be locked. Check for the lock file before accessing its associated file.
• Probably the best way to do this at the file-level.
Don’t overdo it though!
Avoid locking hell.
Don’t share resources unless you have to.
Best Practices
Ensure your database can
keep up
• Often the slowest point in the application logic chain
• Database speed should keep at pace with the speed
of users making requests to your web application
• Best bet- host on the same network
• Not the same server though- tiered architecture is
best
• This provides defence-in-depth; not a panacea
Fetch data only right as you
need it
Again, defence-in-depth. This is by no means a
complete solution on its own.
CSRF Tokens
• You can’t automate a bunch of requests if they require
a unique token every time
• More of a client-side solution, does not necessarily
address the root cause of a race condition
• Do this even for non-sensitive actions
• Attacker’s perspective- found a CSRF vuln? Try
leveraging that into a race condition as well!
Further Reading
• https://www.josipfranjkovic.com/blog/race-conditions-on-web
• http://sakurity.com/blog/2015/05/21/starbucks.html
• https://defuse.ca/race-conditions-in-web-applications.htm
• Web Application Hacker’s Handbook, 2nd Ed.; chapter 11, "Example 12:
Racing Against the Login" (page 426)
• http://www.hakim.ws/BHUSA08/speakers/
Stender_Vidergar_Concurrency_Attacks/
BH_US_08_Stender_Vidergar_Concurrency_Attacks_in_Web_Applications
_Presentation.pdf
• https://www.owasp.org/index.php/Reviewing_Code_for_Race_Conditions
You’ve got another tool in
your tool belt
Now go and race the web!
http://RaceTheWeb.io

More Related Content

What's hot

Waf bypassing Techniques
Waf bypassing TechniquesWaf bypassing Techniques
Waf bypassing TechniquesAvinash Thapa
 
A story of the passive aggressive sysadmin of AEM
A story of the passive aggressive sysadmin of AEMA story of the passive aggressive sysadmin of AEM
A story of the passive aggressive sysadmin of AEMFrans Rosén
 
SSRF For Bug Bounties
SSRF For Bug BountiesSSRF For Bug Bounties
SSRF For Bug BountiesOWASP Nagpur
 
Securing AEM webapps by hacking them
Securing AEM webapps by hacking themSecuring AEM webapps by hacking them
Securing AEM webapps by hacking themMikhail Egorov
 
The Secret Life of a Bug Bounty Hunter – Frans Rosén @ Security Fest 2016
The Secret Life of a Bug Bounty Hunter – Frans Rosén @ Security Fest 2016The Secret Life of a Bug Bounty Hunter – Frans Rosén @ Security Fest 2016
The Secret Life of a Bug Bounty Hunter – Frans Rosén @ Security Fest 2016Frans Rosén
 
Hacking Adobe Experience Manager sites
Hacking Adobe Experience Manager sitesHacking Adobe Experience Manager sites
Hacking Adobe Experience Manager sitesMikhail Egorov
 
HotPics 2021
HotPics 2021HotPics 2021
HotPics 2021neexemil
 
What’s wrong with WebSocket APIs? Unveiling vulnerabilities in WebSocket APIs.
What’s wrong with WebSocket APIs? Unveiling vulnerabilities in WebSocket APIs.What’s wrong with WebSocket APIs? Unveiling vulnerabilities in WebSocket APIs.
What’s wrong with WebSocket APIs? Unveiling vulnerabilities in WebSocket APIs.Mikhail Egorov
 
Attacking thru HTTP Host header
Attacking thru HTTP Host headerAttacking thru HTTP Host header
Attacking thru HTTP Host headerSergey Belov
 
How to steal and modify data using Business Logic flaws - Insecure Direct Obj...
How to steal and modify data using Business Logic flaws - Insecure Direct Obj...How to steal and modify data using Business Logic flaws - Insecure Direct Obj...
How to steal and modify data using Business Logic flaws - Insecure Direct Obj...Frans Rosén
 
X-XSS-Nightmare: 1; mode=attack XSS Attacks Exploiting XSS Filter
X-XSS-Nightmare: 1; mode=attack XSS Attacks Exploiting XSS FilterX-XSS-Nightmare: 1; mode=attack XSS Attacks Exploiting XSS Filter
X-XSS-Nightmare: 1; mode=attack XSS Attacks Exploiting XSS FilterMasato Kinugawa
 
Cross Site Scripting (XSS)
Cross Site Scripting (XSS)Cross Site Scripting (XSS)
Cross Site Scripting (XSS)Barrel Software
 
HTTP Request Smuggling via higher HTTP versions
HTTP Request Smuggling via higher HTTP versionsHTTP Request Smuggling via higher HTTP versions
HTTP Request Smuggling via higher HTTP versionsneexemil
 
OWASP AppSecEU 2018 – Attacking "Modern" Web Technologies
OWASP AppSecEU 2018 – Attacking "Modern" Web TechnologiesOWASP AppSecEU 2018 – Attacking "Modern" Web Technologies
OWASP AppSecEU 2018 – Attacking "Modern" Web TechnologiesFrans Rosén
 
Pentesting Modern Web Apps: A Primer
Pentesting Modern Web Apps: A PrimerPentesting Modern Web Apps: A Primer
Pentesting Modern Web Apps: A PrimerBrian Hysell
 
Understanding Cross-site Request Forgery
Understanding Cross-site Request ForgeryUnderstanding Cross-site Request Forgery
Understanding Cross-site Request ForgeryDaniel Miessler
 
XSS Attacks Exploiting XSS Filter by Masato Kinugawa - CODE BLUE 2015
XSS Attacks Exploiting XSS Filter by Masato Kinugawa - CODE BLUE 2015XSS Attacks Exploiting XSS Filter by Masato Kinugawa - CODE BLUE 2015
XSS Attacks Exploiting XSS Filter by Masato Kinugawa - CODE BLUE 2015CODE BLUE
 

What's hot (20)

Waf bypassing Techniques
Waf bypassing TechniquesWaf bypassing Techniques
Waf bypassing Techniques
 
A story of the passive aggressive sysadmin of AEM
A story of the passive aggressive sysadmin of AEMA story of the passive aggressive sysadmin of AEM
A story of the passive aggressive sysadmin of AEM
 
SSRF For Bug Bounties
SSRF For Bug BountiesSSRF For Bug Bounties
SSRF For Bug Bounties
 
Securing AEM webapps by hacking them
Securing AEM webapps by hacking themSecuring AEM webapps by hacking them
Securing AEM webapps by hacking them
 
The Secret Life of a Bug Bounty Hunter – Frans Rosén @ Security Fest 2016
The Secret Life of a Bug Bounty Hunter – Frans Rosén @ Security Fest 2016The Secret Life of a Bug Bounty Hunter – Frans Rosén @ Security Fest 2016
The Secret Life of a Bug Bounty Hunter – Frans Rosén @ Security Fest 2016
 
Hacking Adobe Experience Manager sites
Hacking Adobe Experience Manager sitesHacking Adobe Experience Manager sites
Hacking Adobe Experience Manager sites
 
HotPics 2021
HotPics 2021HotPics 2021
HotPics 2021
 
What’s wrong with WebSocket APIs? Unveiling vulnerabilities in WebSocket APIs.
What’s wrong with WebSocket APIs? Unveiling vulnerabilities in WebSocket APIs.What’s wrong with WebSocket APIs? Unveiling vulnerabilities in WebSocket APIs.
What’s wrong with WebSocket APIs? Unveiling vulnerabilities in WebSocket APIs.
 
Attacking thru HTTP Host header
Attacking thru HTTP Host headerAttacking thru HTTP Host header
Attacking thru HTTP Host header
 
How to steal and modify data using Business Logic flaws - Insecure Direct Obj...
How to steal and modify data using Business Logic flaws - Insecure Direct Obj...How to steal and modify data using Business Logic flaws - Insecure Direct Obj...
How to steal and modify data using Business Logic flaws - Insecure Direct Obj...
 
X-XSS-Nightmare: 1; mode=attack XSS Attacks Exploiting XSS Filter
X-XSS-Nightmare: 1; mode=attack XSS Attacks Exploiting XSS FilterX-XSS-Nightmare: 1; mode=attack XSS Attacks Exploiting XSS Filter
X-XSS-Nightmare: 1; mode=attack XSS Attacks Exploiting XSS Filter
 
Cross Site Scripting (XSS)
Cross Site Scripting (XSS)Cross Site Scripting (XSS)
Cross Site Scripting (XSS)
 
HTTP Request Smuggling via higher HTTP versions
HTTP Request Smuggling via higher HTTP versionsHTTP Request Smuggling via higher HTTP versions
HTTP Request Smuggling via higher HTTP versions
 
OWASP AppSecEU 2018 – Attacking "Modern" Web Technologies
OWASP AppSecEU 2018 – Attacking "Modern" Web TechnologiesOWASP AppSecEU 2018 – Attacking "Modern" Web Technologies
OWASP AppSecEU 2018 – Attacking "Modern" Web Technologies
 
Pentesting Modern Web Apps: A Primer
Pentesting Modern Web Apps: A PrimerPentesting Modern Web Apps: A Primer
Pentesting Modern Web Apps: A Primer
 
Offzone | Another waf bypass
Offzone | Another waf bypassOffzone | Another waf bypass
Offzone | Another waf bypass
 
Understanding Cross-site Request Forgery
Understanding Cross-site Request ForgeryUnderstanding Cross-site Request Forgery
Understanding Cross-site Request Forgery
 
XSS Attacks Exploiting XSS Filter by Masato Kinugawa - CODE BLUE 2015
XSS Attacks Exploiting XSS Filter by Masato Kinugawa - CODE BLUE 2015XSS Attacks Exploiting XSS Filter by Masato Kinugawa - CODE BLUE 2015
XSS Attacks Exploiting XSS Filter by Masato Kinugawa - CODE BLUE 2015
 
Frans Rosén Keynote at BSides Ahmedabad
Frans Rosén Keynote at BSides AhmedabadFrans Rosén Keynote at BSides Ahmedabad
Frans Rosén Keynote at BSides Ahmedabad
 
ZeroNights 2018 | I <"3 XSS
ZeroNights 2018 | I <"3 XSSZeroNights 2018 | I <"3 XSS
ZeroNights 2018 | I <"3 XSS
 

Similar to Racing The Web - Hackfest 2016

Node.js introduction
Node.js introductionNode.js introduction
Node.js introductionPrasoon Kumar
 
introduction to node.js
introduction to node.jsintroduction to node.js
introduction to node.jsorkaplan
 
[HES2013] Virtually secure, analysis to remote root 0day on an industry leadi...
[HES2013] Virtually secure, analysis to remote root 0day on an industry leadi...[HES2013] Virtually secure, analysis to remote root 0day on an industry leadi...
[HES2013] Virtually secure, analysis to remote root 0day on an industry leadi...Hackito Ergo Sum
 
What I learned from FluentConf and then some
What I learned from FluentConf and then someWhat I learned from FluentConf and then some
What I learned from FluentConf and then someOhad Kravchick
 
FIWARE Tech Summit - Docker Swarm Secrets for Creating Great FIWARE Platforms
FIWARE Tech Summit - Docker Swarm Secrets for Creating Great FIWARE PlatformsFIWARE Tech Summit - Docker Swarm Secrets for Creating Great FIWARE Platforms
FIWARE Tech Summit - Docker Swarm Secrets for Creating Great FIWARE PlatformsFIWARE
 
Performance Tuning - Memory leaks, Thread deadlocks, JDK tools
Performance Tuning -  Memory leaks, Thread deadlocks, JDK toolsPerformance Tuning -  Memory leaks, Thread deadlocks, JDK tools
Performance Tuning - Memory leaks, Thread deadlocks, JDK toolsHaribabu Nandyal Padmanaban
 
Metasploitation part-1 (murtuja)
Metasploitation part-1 (murtuja)Metasploitation part-1 (murtuja)
Metasploitation part-1 (murtuja)ClubHack
 
Hacking Tizen : The OS of Everything - Nullcon Goa 2015
Hacking Tizen : The OS of Everything - Nullcon Goa 2015Hacking Tizen : The OS of Everything - Nullcon Goa 2015
Hacking Tizen : The OS of Everything - Nullcon Goa 2015Ajin Abraham
 
Lions, Tigers and Deers: What building zoos can teach us about securing micro...
Lions, Tigers and Deers: What building zoos can teach us about securing micro...Lions, Tigers and Deers: What building zoos can teach us about securing micro...
Lions, Tigers and Deers: What building zoos can teach us about securing micro...Sysdig
 
Cloud Best Practices
Cloud Best PracticesCloud Best Practices
Cloud Best PracticesEric Bottard
 
Owning computers without shell access dark
Owning computers without shell access darkOwning computers without shell access dark
Owning computers without shell access darkRoyce Davis
 
NSC #2 - D3 02 - Peter Hlavaty - Attack on the Core
NSC #2 - D3 02 - Peter Hlavaty - Attack on the CoreNSC #2 - D3 02 - Peter Hlavaty - Attack on the Core
NSC #2 - D3 02 - Peter Hlavaty - Attack on the CoreNoSuchCon
 
Docker Swarm secrets for creating great FIWARE platforms
Docker Swarm secrets for creating great FIWARE platformsDocker Swarm secrets for creating great FIWARE platforms
Docker Swarm secrets for creating great FIWARE platformsFederico Michele Facca
 
StorageOS, Storage for Containers Shouldn't Be Annoying at Container Camp UK
StorageOS, Storage for Containers Shouldn't Be Annoying at Container Camp UKStorageOS, Storage for Containers Shouldn't Be Annoying at Container Camp UK
StorageOS, Storage for Containers Shouldn't Be Annoying at Container Camp UKStorageOS
 
How to secure your web applications with NGINX
How to secure your web applications with NGINXHow to secure your web applications with NGINX
How to secure your web applications with NGINXWallarm
 
No locked doors, no windows barred: hacking OpenAM infrastructure
No locked doors, no windows barred: hacking OpenAM infrastructureNo locked doors, no windows barred: hacking OpenAM infrastructure
No locked doors, no windows barred: hacking OpenAM infrastructureAndrew Petukhov
 
Security research over Windows #defcon china
Security research over Windows #defcon chinaSecurity research over Windows #defcon china
Security research over Windows #defcon chinaPeter Hlavaty
 
DDD17 - Web Applications Automated Security Testing in a Continuous Delivery...
 DDD17 - Web Applications Automated Security Testing in a Continuous Delivery... DDD17 - Web Applications Automated Security Testing in a Continuous Delivery...
DDD17 - Web Applications Automated Security Testing in a Continuous Delivery...Fedir RYKHTIK
 

Similar to Racing The Web - Hackfest 2016 (20)

Node.js introduction
Node.js introductionNode.js introduction
Node.js introduction
 
introduction to node.js
introduction to node.jsintroduction to node.js
introduction to node.js
 
[HES2013] Virtually secure, analysis to remote root 0day on an industry leadi...
[HES2013] Virtually secure, analysis to remote root 0day on an industry leadi...[HES2013] Virtually secure, analysis to remote root 0day on an industry leadi...
[HES2013] Virtually secure, analysis to remote root 0day on an industry leadi...
 
Us 17-krug-hacking-severless-runtimes
Us 17-krug-hacking-severless-runtimesUs 17-krug-hacking-severless-runtimes
Us 17-krug-hacking-severless-runtimes
 
What I learned from FluentConf and then some
What I learned from FluentConf and then someWhat I learned from FluentConf and then some
What I learned from FluentConf and then some
 
FIWARE Tech Summit - Docker Swarm Secrets for Creating Great FIWARE Platforms
FIWARE Tech Summit - Docker Swarm Secrets for Creating Great FIWARE PlatformsFIWARE Tech Summit - Docker Swarm Secrets for Creating Great FIWARE Platforms
FIWARE Tech Summit - Docker Swarm Secrets for Creating Great FIWARE Platforms
 
Performance Tuning - Memory leaks, Thread deadlocks, JDK tools
Performance Tuning -  Memory leaks, Thread deadlocks, JDK toolsPerformance Tuning -  Memory leaks, Thread deadlocks, JDK tools
Performance Tuning - Memory leaks, Thread deadlocks, JDK tools
 
Metasploitation part-1 (murtuja)
Metasploitation part-1 (murtuja)Metasploitation part-1 (murtuja)
Metasploitation part-1 (murtuja)
 
Hacking Tizen : The OS of Everything - Nullcon Goa 2015
Hacking Tizen : The OS of Everything - Nullcon Goa 2015Hacking Tizen : The OS of Everything - Nullcon Goa 2015
Hacking Tizen : The OS of Everything - Nullcon Goa 2015
 
Lions, Tigers and Deers: What building zoos can teach us about securing micro...
Lions, Tigers and Deers: What building zoos can teach us about securing micro...Lions, Tigers and Deers: What building zoos can teach us about securing micro...
Lions, Tigers and Deers: What building zoos can teach us about securing micro...
 
Cloud Best Practices
Cloud Best PracticesCloud Best Practices
Cloud Best Practices
 
JavaScript Event Loop
JavaScript Event LoopJavaScript Event Loop
JavaScript Event Loop
 
Owning computers without shell access dark
Owning computers without shell access darkOwning computers without shell access dark
Owning computers without shell access dark
 
NSC #2 - D3 02 - Peter Hlavaty - Attack on the Core
NSC #2 - D3 02 - Peter Hlavaty - Attack on the CoreNSC #2 - D3 02 - Peter Hlavaty - Attack on the Core
NSC #2 - D3 02 - Peter Hlavaty - Attack on the Core
 
Docker Swarm secrets for creating great FIWARE platforms
Docker Swarm secrets for creating great FIWARE platformsDocker Swarm secrets for creating great FIWARE platforms
Docker Swarm secrets for creating great FIWARE platforms
 
StorageOS, Storage for Containers Shouldn't Be Annoying at Container Camp UK
StorageOS, Storage for Containers Shouldn't Be Annoying at Container Camp UKStorageOS, Storage for Containers Shouldn't Be Annoying at Container Camp UK
StorageOS, Storage for Containers Shouldn't Be Annoying at Container Camp UK
 
How to secure your web applications with NGINX
How to secure your web applications with NGINXHow to secure your web applications with NGINX
How to secure your web applications with NGINX
 
No locked doors, no windows barred: hacking OpenAM infrastructure
No locked doors, no windows barred: hacking OpenAM infrastructureNo locked doors, no windows barred: hacking OpenAM infrastructure
No locked doors, no windows barred: hacking OpenAM infrastructure
 
Security research over Windows #defcon china
Security research over Windows #defcon chinaSecurity research over Windows #defcon china
Security research over Windows #defcon china
 
DDD17 - Web Applications Automated Security Testing in a Continuous Delivery...
 DDD17 - Web Applications Automated Security Testing in a Continuous Delivery... DDD17 - Web Applications Automated Security Testing in a Continuous Delivery...
DDD17 - Web Applications Automated Security Testing in a Continuous Delivery...
 

Recently uploaded

5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - InfographicHr365.us smith
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptkotipi9215
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxTier1 app
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...Christina Lin
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
cybersecurity notes for mca students for learning
cybersecurity notes for mca students for learningcybersecurity notes for mca students for learning
cybersecurity notes for mca students for learningVitsRangannavar
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfkalichargn70th171
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
XpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software SolutionsXpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software SolutionsMehedi Hasan Shohan
 

Recently uploaded (20)

Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - Infographic
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.ppt
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
cybersecurity notes for mca students for learning
cybersecurity notes for mca students for learningcybersecurity notes for mca students for learning
cybersecurity notes for mca students for learning
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
XpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software SolutionsXpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software Solutions
 

Racing The Web - Hackfest 2016

  • 2. Security Consultant at Security Compass Professor of Application Security at Georgian College Software developer Former sysadmin etc. Aaron Hnatiw twitter: @insp3ctre
  • 3. Why am I here?
  • 5. OWASP Definition A race condition is a flaw that produces an unexpected result when the timing of actions impact other actions. An example may be seen on a multithreaded application where actions are being performed on the same data. Race conditions, by their very nature, are difficult to test for. https://www.owasp.org/index.php/Testing_for_Race_Conditions_%28OWASP-AT-010%29
  • 6. CWE-362: Concurrent Execution using Shared Resource with Improper Synchronization ('Race Condition’) https://cwe.mitre.org/data/definitions/362.html
  • 7. Basically, when you bet on the wrong horse. (or even “bet” at all)
  • 10. When does this become a security issue?
  • 11. “One time use” coupon codes
  • 14. What does a race condition look like?
  • 15.
  • 17. Go
  • 19. PHP
  • 20. Testing for race conditions in web applications
  • 21. Usual whitebox method 1. Identify all shared data 2. Identify where that shared data is accessed across systems 3. Find where that data access is not synchronized 4. Make a TON of requests
  • 23. Introducing: Race-The-Web (RTW) A tool that automates race condition discovery Simple configuration (TOML) Open-source Written in Go
  • 25. Try it out yourself! RaceTheWeb.io
  • 26. Comparison vs Burp Intruder
  • 27. Speed • Intruder setup: • 10 threads (default is 5) • 3 retries after network failure (2000 ms pause before retry)- default • Redirect: always • 1000 requests (withdraw $1 x 1000)
  • 28. Speed (cont’d) • RTW setup: • Verbose logging • Follow redirects • 1000 requests (withdraw $1 x 1000)
  • 29. Speed (cont’d) • Results • Intruder: ~3:10 • RTW: ~2:00
  • 30. Speed (cont’d) • Intruder optimizations: • 999 threads (maximum possible) • No retries on network failure • Result: ~2:15 • RTW is still faster
  • 32. // TODO • Add “proxy” option to config file • Clean up codebase • Write Burp plugin
  • 33.
  • 34. Be careful of DoS. Most bug bounties have restrictions such as: https://hackerone.com/airbnb
  • 35. Useful tip: check for CRUD functionality. (especially with remote resources)
  • 37. Most effective: Locks Use with shared resources
  • 39. Python • threading.Lock • acquire() • release() • Others: • threading.RLock • threading.Condition • threading.Semaphore • queue: handles locking automatically for resources in the queue. More: https://docs.python.org/2/library/threading.html
  • 41. Go • sync.mutex • Lock() • Unlock() • sync.RWMutex • Rlock() • RWLock() • Unlock() https://golang.org/pkg/sync/
  • 42. Go Channels: “Do not communicate by sharing memory; instead, share memory by communicating.”
  • 44. PHP • You could compile PHP with “--enable-sysvsem"... • Not supported everywhere • Not useful in a distributed environment • May not be possible in a shared hosting environment • You’re pretty much stuck with implementing this at the database or file level (more on that later) • If you know of any other way, please let me know!
  • 46. Database MUST be ACID- compliant
  • 47. ACID-Compliant Databases • Atomicity: All or nothing. A transaction either succeeds or rolls back. • Consistency: On the completion of a transaction, the database is structurally sound. Otherwise, it reverts back to the previous sound state. • Isolation: Transactions do not interfere with each other. • This point is KEY. • Durability: The results of applying a transaction are permanent, even in the presence of failures.
  • 48. Isolation • Highest level: serializable. • Transactions essentially occur serially (one after another), rather than concurrently. • Next level: repeatable read. • Close, but still allows race conditions. • Be prepared to retry transactions often, because in most cases, these isolation levels can result in a large number of transaction failures. • Obvious downside- using higher levels of isolation can slow down your application.
  • 49. Solution- MySQL • From the documentation: "MySQL Server (version 3.23-max and all versions 4.0 and above) supports transactions with the InnoDB transactional storage engine. InnoDB provides full ACID compliance." • Use SERIALIZABLE isolation level • Default is REPEATABLE-READ • Can be set globally, for a session, or for individual transactions More info: https://dev.mysql.com/doc/refman/5.5/en/innodb-transaction-isolation- levels.html
  • 50. MySQL (cont’d) • System variable: 
 SET GLOBAL @@GLOBAL.tx_isolation=`SERIALIZABLE`; • Command-line option at mysqld startup: 
 --transaction-isolation=SERIALIZABLE • Option file:
 [mysqld]
 transaction-isolation = SERIALIZABLE • Command-line, BEFORE starting a transaction:
 SET TRANSACTION ISOLATION LEVEL SERIALIZABLE; More Info: https://dev.mysql.com/doc/refman/5.5/en/set-transaction.html
  • 51. Solution- PostgreSQL • Use the SERIALIZABLE transaction isolation level • Default is READ COMMITTED: all queries see a snapshot of committed data at the time of the query. • Command-line: • START TRANSACTION;
 SET TRANSACTION ISOLATION LEVEL SERIALIZABLE; • START TRANSACTION ISOLATION LEVEL SERIALIZABLE; • BEGIN TRANSACTION ISOLATION LEVEL SERIALIZABLE; More info: https://www.postgresql.org/docs/9.3/static/sql-set-transaction.html
  • 52. PostgreSQL (cont’d) • Configuration file: postgresql.conf
 default_transaction_isolation = ‘serializable’ • Command-line option with postgres command:
 postgres -c default_transaction_isolation=‘serializable’ ... • Environment variable:
 env PGOPTIONS=“-c default_transaction_isolation=‘serializable’” psql • Mid-session SQL:
 SET SESSION default_transaction_isolation = ‘serializable’;
  • 54. For most use cases: • Optimize your queries • Use a single query whenever possible (e.g. UPDATE xTable SET yValue = yValue+1 WHERE id = ‘zID’) • Inserts instead of updates • Use unique indexes • Use an ORM for “optimistic locking” • Most ORMs do their own optimizations and locking to prevent race conditions, as opposed to relying on the database’s strict “pessimistic locking” • Use the READ COMMITTED isolation level • Not as strict as Serializable, but provides more speed, less locking errors, and more consistency than REPEATABLE READ
  • 55. Solution- MongoDB • No serialization • From 2.2 on, uses database-level read and write locks, depending on operation (https:// docs.mongodb.com/manual/faq/concurrency/#which-operations-lock-the-database) • Single document writes are atomic (but not isolated) by default • $isolated operator • Acquires an exclusive lock to all documents being written to (only applies when writing to multiple documents). • Does not work on sharded clusters. More info: https://docs.mongodb.com/v3.2/core/write-operations-atomicity/
  • 57. Native Methods • Windows • LockFile function of the Windows API: https://msdn.microsoft.com/en-us/library/ aa365202.aspx • Unix • flock()/lockf(): essentially the same function • fcntl(): http://pubs.opengroup.org/onlinepubs/9699919799/functions/fcntl.html • Some typical “gotchas”: http://0pointer.de/blog/projects/locking.html • Lock file: create a temporary file (e.g. ~myfile.lck), which exists while a file needs to be locked. Check for the lock file before accessing its associated file. • Probably the best way to do this at the file-level.
  • 58. Don’t overdo it though! Avoid locking hell. Don’t share resources unless you have to.
  • 60. Ensure your database can keep up • Often the slowest point in the application logic chain • Database speed should keep at pace with the speed of users making requests to your web application • Best bet- host on the same network • Not the same server though- tiered architecture is best • This provides defence-in-depth; not a panacea
  • 61. Fetch data only right as you need it Again, defence-in-depth. This is by no means a complete solution on its own.
  • 62. CSRF Tokens • You can’t automate a bunch of requests if they require a unique token every time • More of a client-side solution, does not necessarily address the root cause of a race condition • Do this even for non-sensitive actions • Attacker’s perspective- found a CSRF vuln? Try leveraging that into a race condition as well!
  • 63. Further Reading • https://www.josipfranjkovic.com/blog/race-conditions-on-web • http://sakurity.com/blog/2015/05/21/starbucks.html • https://defuse.ca/race-conditions-in-web-applications.htm • Web Application Hacker’s Handbook, 2nd Ed.; chapter 11, "Example 12: Racing Against the Login" (page 426) • http://www.hakim.ws/BHUSA08/speakers/ Stender_Vidergar_Concurrency_Attacks/ BH_US_08_Stender_Vidergar_Concurrency_Attacks_in_Web_Applications _Presentation.pdf • https://www.owasp.org/index.php/Reviewing_Code_for_Race_Conditions
  • 64. You’ve got another tool in your tool belt
  • 65. Now go and race the web! http://RaceTheWeb.io