SlideShare a Scribd company logo
Client-Side HTTP Cookie Security:
Attack and Defense
David Wyde
DEF CON 22
Game Plan
•  Why are HTTP cookies valuable to attackers?
•  How do popular web browsers store cookies?
•  How can cookies be stolen?
•  How can cookies be protected?
Disclaimers
•  The opinions in this presentation are mine, and not my
employer’s.
•  The security issues I discuss are not specific to any one
website, and are not vulnerabilities in the conventional
sense.
What is an HTTP Cookie?
•  Cookies are transmitted as HTTP headers
•  Name-value pairs
•  HTTP clients store state using cookies
•  E.g., trade credentials for a session cookie
Cookies in Action
User-Readable Data
•  Any process that runs as your user can read:
•  Your private keys
•  Some software saves passwords as plaintext
•  Web browser cookies
•  Damage is done without privilege escalation
Cookies Are Valuable to Attackers
•  Cookies can be more valuable than passwords
•  Gmail: bypass two-factor authentication
•  Facebook: don't warn of login from a new device
•  Counterpoints
•  "Please re-enter your password”
•  Cookies expire
Gmail: Two-Factor Authentication
Facebook: New Login Email
Browser Cookie Storage
Cookie Storage: Intro
•  Almost all browsers store cookies as plaintext
•  The HttpOnly and Secure flags apply inside browsers
•  Malware need not respect them
Firefox
•  Stores cookies in an SQLite database
•  Cookies can be read using sqlite3, Python, etc.
Reading Firefox Cookies
$ sqlite3 ~/Library/Application Support/Firefox/Profiles/*/cookies.sqlite
SQLite version 3.7.13 2012-07-17 17:46:21
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> .schema
CREATE TABLE moz_cookies (id INTEGER PRIMARY KEY, baseDomain TEXT, appId
INTEGER DEFAULT 0, inBrowserElement INTEGER DEFAULT 0, name TEXT, value
TEXT, host TEXT, path TEXT, expiry INTEGER, lastAccessed INTEGER,
creationTime INTEGER, isSecure INTEGER, isHttpOnly INTEGER, CONSTRAINT
moz_uniqueid UNIQUE (name, host, path, appId, inBrowserElement));
CREATE INDEX moz_basedomain ON moz_cookies (baseDomain, appId,
inBrowserElement);
sqlite> SELECT value FROM moz_cookies WHERE name='GX';
DQAAAPEAAABWYmsr2PFvwQi4XhQWYcw_5coZVfjh-efmKTNeLjyLx04sHi_Ih-
xMOsSRaZ6J38QzDGyCt5v6DKYkkoc6TeX8QKuaOPSAqqGTEo4v2Y6kvmzlS-SvdU4zTcuJ-
z4uCf7uiZ7Ic-
H6U5Mt7leqmsDhQeEoL01z5OF6iLoxUeCHU_91eWrA2bOpU8ppqVjutpi4WVhyqLV7WX6hgSnE
kWnpsN-XwcDF84V7u0DrlKCQFupzmCfa3nt_tARY-SxbyNrmY_0rH4YF-
xBVvPFXBQpKqUZrW_zMdGmWgmPER_7mBTGXtlh9PM5nCP_bw09oIqXrQb_OhHe7c3AnnIg2EIq
g
Internet Explorer
•  Stores cookies as text files
•  The folder varies depending on IE version
•  Filenames are random: need to read the files
Reading Internet Explorer Cookies
Opera and Safari
•  Custom binary formats
•  Can be parsed by free software tools
•  Safari: Cookies.binarycookies
•  Opera: cookies4.dat
Reading Safari Cookies
$ python ~/Desktop/BinaryCookieReader.py ~/Library/
Cookies/Cookies.binarycookies | grep yahoo
Cookie :
hpc=d=ItIKgZXDu9Pkv2_sEb7ygoVyN9bHZ2mmjnr8eBC8z9Ynw88Tayw
7ixgQfT4vleMQ56bGUussxMNmYBusbq3RHgXIkea3DhM.Yzckc.y6GAQE
iJoPoK1DzyvYg1cyBoMWlZccOkvv7wvPUmDHnNk1uyiJwon3_YjfMMyCX
stKdmUKmePy_Wn04tFoVbui1wlLTuSpqTw-&v=2;
domain=.www.yahoo.com; path=/; expires=Wed, 15 Jul 2015;
Cookie : B=2b26v3t9s955p&b=3&s=oh; domain=.yahoo.com;
path=/; expires=Fri, 15 Jul 2016;
Cookie : CRZY=%7B%221048616551%22%3A%7B%22expires
%22%3A1405564858541%2C%22data%22%3A%7B%22nv%22%3A1%2C
%22bn%22%3A0%7D%7D%7D; domain=.yahoo.com; path=/;
expires=Thu, 17 Jul 2014;
Reading Opera Cookies
$ python opera_reader.py ~/.opera/cookies4.dat
file_version_number 4096
app_version_number 8193
idtag_length 1
length_length 2
domain record
[('0x1e', 'name of the domain part', 3, 'org')]
end of path record
domain record
[('0x1e', 'name of the domain part', 8, 'slashdot')]
cookie record
[('0x10', 'name of the cookie', 6, '__gads'), ('0x11',
'value of the cookie', 69,
'ID=2628549bf6c27042:T=1405392507:S=ALNI_Maix2zTTIQ4159AfUM0tH
p7h_ODgQ'), ('0x12', 'expiry', 8, '2016-07-13 21:48:27'),
('0x13', 'last used', 8, '2014-07-14 21:49:28'), ('0x28',
'unknown cookie data id', 8,
'x00x00x00x00x00x00x00x00'), ('0xa9', 'unknown cookie
data id', 0, '')]
Chromium
•  Encrypts cookies in recent versions
•  Implementation and security vary by platform
•  Stores cookies in an SQLite database
•  BLOB field for encrypted cookie values
Chromium on Linux
•  Linux has no single standard keyring mechanism
•  (KDE, Gnome, etc.)
•  Cookies encrypted with AES (symmetric key)
•  Hard-coded key and salt
•  Can be decrypted on any machine
•  Link against Chromium libs, call code to decrypt
Reading Chromium Cookies: Linux
Reading Chromium Cookies: Linux
[david@localhost Desktop]$ python chromium_b64_cookie_linux.py
djEwXgab42ZPnVqGRirZqEHsvEN8bC/
chT84CbmJxMSJDr6XA7mQLZdCuLwYSNA6srVf7NDn7rHdBOFJf8SX4jdCxlQhcrUGH
+0KzFz
+hUxUcgRzy6jWEZyAe4QDegh1YGtfdCGiZ2TgHkEifJ0Mojf4VpuKhFw7SVpCzCorz86JF
czNpco7LZwM/xng7UPmVEY4sIQwAGlTXoY9ThgaliP8HGviwkK0ozW9/FMUiGaxBIqDD
+FSfsGszckv9zRbK8XL2PbHVslRmG2ENQ8wESu2Czajb20BQ+L3dMRvOcVbW+gwt+H/
cBG23dnjnhFxGcvm9DSDyz87o5ssILocgMT+kddTBCG8ohvy7iNE3njT6WOFktK8Hd/
+rhSUarnCtZt9UB1EZtikWbpqn0PKrVCKn0wVpO4oyeDIe96xEesn/IM=
david@computer /d/code/snickerdoodle/chromium-linux $
LD_LIBRARY_PATH=/d/code/lib/chromium/src/out/Release/lib ./
base64_reader $(cat fedora-cookie.txt)
DQAAANMAAAD55DvOAnmlugeHzwGKs0asFxYtMfXl-
Xdg7MtLYmdj5GDI3iyPh70Ds6OKgogfATna2KV9d7JqZxJ5e7SA-
sbH1oxvQFs1WsFo_9WzEfj9VamEV5C0uml6tVuzhIGzrrKM0__0SI6QANb-y-
qyM3QJSKCB7QrXR_Ug7lFzjibDW7Fsfg15SUCTmfQz9YLBP4oYSOt_pJRVf5XZgbN_2J-
KQzBqtZznZwKVE4TatBaAucT-
R9jXnjM5aMdoJvr7ubghi0p1m7yvPevqNNRItPkeB5aV_cPXHKRMjwhAAk6_2w
Chromium on Windows
•  CryptProtectData is used to encrypt
•  A Windows cryptography API
•  Uses login credentials as part of the encryption
•  CryptUnprotectData is used to decrypt
•  Must be called by the user that encrypted, on the
same machine
Chromium on Mac
•  Store an encryption key in the system keychain
•  If no key exists, a random one is generated
•  AES is used to encrypt/decrypt
•  Keychain prompts when accessed from unsigned apps
Reading Chromium Cookies: Mac
Browser Cookie Storage: Summary
•  Chromium encrypts cookies on Windows and Mac
•  Chromium obfuscates cookies on Linux
•  Other popular browsers store cookies as plaintext
Attack Vectors
Physical Access
•  Cookies are there for the taking with most browsers
•  Chromium protects you on Windows and Mac
Social Engineering
•  Excel/Word macros
•  Malicious executables
•  Don't need to install anything - just run once
Malware
•  Drop and run an executable to extract cookies
•  Metasploit
•  Any process that runs as your user
•  HTTP POST cookies to a malicious server
Proof of Concept
Proof of Concept: Login
Defenses
Disk Encryption
•  Protect against physical access to plaintext cookies
Application Firewalls
•  Block/allow (server, port) pairs for each application
•  Chromium can access www.google.com on port 443
•  Examples
•  Mac: Little Snitch
•  Windows: NetLimiter?
•  Linux: ?
Little Snitch
SELinux
•  Security-Enhanced Linux
•  Separate from standard Unix permissions
•  Can isolate a user’s applications from each other
Idea: Master Password for Cookies
•  Type in a password to decrypt your cookies
•  Firefox has this to protect passwords
Firefox: Master Password
Server-Side Defenses
•  Tie a session cookie to the login IP
•  The cPanel web hosting tool can optionally enforce this
•  Kind of annoying in a world of mobile clients
•  Warn users, rather than force them to log in again
•  “You’ve logged in from X and Y countries this month”
Conclusions
•  Cookies should be handled with care
•  Client-side cookie security is not a solved problem
References
•  Opera reader:
https://gist.github.com/gwarser/1324501#file-readcookies-py
•  Safari reader:
http://www.securitylearn.net/2012/10/27/cookies-binarycookies-
reader/
•  Firefox master password:
http://kb.mozillazine.org/Master_password
•  cPanel cookie IP validation:
http://www.cpanelkb.net/cpanel-security-settings-checklist/
•  CryptProtectData (Microsoft documentation):
http://msdn.microsoft.com/en-us/library/aa922939.aspx

More Related Content

PDF
Defcon 22-adrian-crenshaw-dropping-docs-on-darknets-how-peop
PDF
Defcon 22-metacortex-grifter-darkside-of-the-internet
PDF
Defcon 22-wesley-mc grew-instrumenting-point-of-sale-malware
PDF
Internal Pentest: from z3r0 to h3r0
PDF
Zeronights 2015 - Big problems with big data - Hadoop interfaces security
PPTX
[ENG] OHM2013 - The Quest for the Client-Side Elixir Against Zombie Browsers -
PDF
Breaking Vaults - Stealing Lastpass Protected Secrets by Martin Vigo
PPTX
BSIDES-PR Keynote Hunting for Bad Guys
Defcon 22-adrian-crenshaw-dropping-docs-on-darknets-how-peop
Defcon 22-metacortex-grifter-darkside-of-the-internet
Defcon 22-wesley-mc grew-instrumenting-point-of-sale-malware
Internal Pentest: from z3r0 to h3r0
Zeronights 2015 - Big problems with big data - Hadoop interfaces security
[ENG] OHM2013 - The Quest for the Client-Side Elixir Against Zombie Browsers -
Breaking Vaults - Stealing Lastpass Protected Secrets by Martin Vigo
BSIDES-PR Keynote Hunting for Bad Guys

What's hot (20)

PDF
Web security for developers
PDF
DEFCON 22: Bypass firewalls, application white lists, secure remote desktops ...
PPTX
Заполучили права администратора домена? Игра еще не окончена
PPTX
Sticky Keys to the Kingdom
PDF
Fruit vs Zombies: Defeat Non-jailbroken iOS Malware by Claud Xiao
PDF
HackInTheBox - AMS 2011 , Spying on SpyEye - What Lies Beneath ?
PPTX
Offensive Python for Pentesting
PDF
1000 to 0
PPTX
Pentest Apocalypse - SANSFIRE 2016 Edition
PDF
Red Team Tactics for Cracking the GSuite Perimeter
PDF
CNIT 129S: Ch 12: Attacking Users: Cross-Site Scripting
PDF
BlueHat v18 || The matrix has you - protecting linux using deception
PDF
CSW2017 Geshev+Miller logic bug hunting in chrome on android
PDF
Wi-Fi Hotspot Attacks
PPTX
Lateral Movement - Phreaknik 2016
PDF
CSW2017 Yuhao song+Huimingliu cyber_wmd_vulnerable_IoT
PDF
Attacker's Perspective of Active Directory
PDF
TeelTech - Advancing Mobile Device Forensics (online version)
PPTX
Outlook and Exchange for the bad guys
PDF
CNIT 128: Android Implementation Issues (Part 2)
Web security for developers
DEFCON 22: Bypass firewalls, application white lists, secure remote desktops ...
Заполучили права администратора домена? Игра еще не окончена
Sticky Keys to the Kingdom
Fruit vs Zombies: Defeat Non-jailbroken iOS Malware by Claud Xiao
HackInTheBox - AMS 2011 , Spying on SpyEye - What Lies Beneath ?
Offensive Python for Pentesting
1000 to 0
Pentest Apocalypse - SANSFIRE 2016 Edition
Red Team Tactics for Cracking the GSuite Perimeter
CNIT 129S: Ch 12: Attacking Users: Cross-Site Scripting
BlueHat v18 || The matrix has you - protecting linux using deception
CSW2017 Geshev+Miller logic bug hunting in chrome on android
Wi-Fi Hotspot Attacks
Lateral Movement - Phreaknik 2016
CSW2017 Yuhao song+Huimingliu cyber_wmd_vulnerable_IoT
Attacker's Perspective of Active Directory
TeelTech - Advancing Mobile Device Forensics (online version)
Outlook and Exchange for the bad guys
CNIT 128: Android Implementation Issues (Part 2)
Ad

Viewers also liked (20)

PDF
Defcon 22-alex zacharis-nikolaos-tsagkarakis-po s-attacking-t
PDF
Defcon 22-nir-valtman-a-journey-to-protect-pos
PDF
Defcon 22-zoltan-balazs-bypass-firewalls-application-whiteli
PDF
Network Forensics and Practical Packet Analysis
PDF
Risk Analysis using open FAIR and Adoption of right Security Controls
PPTX
Practical Applications of Block Chain Technologies
PDF
Defcon 22-deviant-ollam-and-howard-payne-elevator hacking-fr
PDF
Defcon 22-cesar-cerrudo-hacking-traffic-control-systems
PDF
Defcon 22-jesus-molina-learn-how-to-control-every-room
PDF
Defcon 22-rmellendick-dakahuna-rf-penetration-testing-your-a
PDF
Defcon 22-philip-young-from-root-to-special-hacking-ibm-main
PDF
Defcon 22-paul-mcmillan-attacking-the-iot-using-timing-attac
PDF
Defcon 22-fatih-ozavci-vo ip-wars-attack-of-the-cisco-phones
PDF
Defcon 22-phil-polstra-cyber-hijacking-airplanes-truth-or-fi
PDF
Defcon 22-anton-sapozhnikov-acquire-current-user-hashes-with
PPTX
Keynote Session : The Non - Evolution of Security
PDF
Security Strategy and Tactic with Cyber Threat Intelligence (CTI)
PPTX
Keynote Session : Emerging Healthcare Tech & Future Security Impact
PDF
Workshop on Endpoint Memory Forensics
PDF
SOC Architecture - Building the NextGen SOC
Defcon 22-alex zacharis-nikolaos-tsagkarakis-po s-attacking-t
Defcon 22-nir-valtman-a-journey-to-protect-pos
Defcon 22-zoltan-balazs-bypass-firewalls-application-whiteli
Network Forensics and Practical Packet Analysis
Risk Analysis using open FAIR and Adoption of right Security Controls
Practical Applications of Block Chain Technologies
Defcon 22-deviant-ollam-and-howard-payne-elevator hacking-fr
Defcon 22-cesar-cerrudo-hacking-traffic-control-systems
Defcon 22-jesus-molina-learn-how-to-control-every-room
Defcon 22-rmellendick-dakahuna-rf-penetration-testing-your-a
Defcon 22-philip-young-from-root-to-special-hacking-ibm-main
Defcon 22-paul-mcmillan-attacking-the-iot-using-timing-attac
Defcon 22-fatih-ozavci-vo ip-wars-attack-of-the-cisco-phones
Defcon 22-phil-polstra-cyber-hijacking-airplanes-truth-or-fi
Defcon 22-anton-sapozhnikov-acquire-current-user-hashes-with
Keynote Session : The Non - Evolution of Security
Security Strategy and Tactic with Cyber Threat Intelligence (CTI)
Keynote Session : Emerging Healthcare Tech & Future Security Impact
Workshop on Endpoint Memory Forensics
SOC Architecture - Building the NextGen SOC
Ad

Similar to Defcon 22-david-wyde-client-side-http-cookie-security (20)

PPTX
Cookies and sessions
PDF
Cookie replay attack unit wise presentation
PPTX
Overview of Cookies in HTTP - Miran al Mehrab
PDF
OWASP AppSec USA 2017: Cookie Security – Myths and Misconceptions by David Jo...
PPTX
Cookies: HTTP state management mechanism
PPT
Presentation on Internet Cookies
PPT
Cookies and sessions
PPTX
Cookie testing
PPTX
Backend Technologies Notes ajef;asnfkndfdsa
PPTX
Cookies
PDF
BSides Rochester 2018: Chaim Sanders: How the Cookie Crumbles: Modern HTTP St...
PPTX
Internet Cookies
PPT
16 cookies
PPTX
WORKING WITH IN COOKIES JAVA SEMINAR.pptx
PDF
Active Https Cookie Stealing
PPTX
Carla Ollé Vera and Aida Pooladian - Cookies and privacy: What do they do wit...
PPT
Internet cookies
PPTX
Working with in cookies java seminar.pptx
PPTX
Advance java session 7
Cookies and sessions
Cookie replay attack unit wise presentation
Overview of Cookies in HTTP - Miran al Mehrab
OWASP AppSec USA 2017: Cookie Security – Myths and Misconceptions by David Jo...
Cookies: HTTP state management mechanism
Presentation on Internet Cookies
Cookies and sessions
Cookie testing
Backend Technologies Notes ajef;asnfkndfdsa
Cookies
BSides Rochester 2018: Chaim Sanders: How the Cookie Crumbles: Modern HTTP St...
Internet Cookies
16 cookies
WORKING WITH IN COOKIES JAVA SEMINAR.pptx
Active Https Cookie Stealing
Carla Ollé Vera and Aida Pooladian - Cookies and privacy: What do they do wit...
Internet cookies
Working with in cookies java seminar.pptx
Advance java session 7

More from Priyanka Aash (20)

PPTX
AI Code Generation Risks (Ramkumar Dilli, CIO, Myridius)
PDF
From Chatbot to Destroyer of Endpoints - Can ChatGPT Automate EDR Bypasses (1...
PDF
Cracking the Code - Unveiling Synergies Between Open Source Security and AI.pdf
PDF
Oh, the Possibilities - Balancing Innovation and Risk with Generative AI.pdf
PDF
Lessons Learned from Developing Secure AI Workflows.pdf
PDF
Cyber Defense Matrix Workshop - RSA Conference
PDF
A Constitutional Quagmire - Ethical Minefields of AI, Cyber, and Privacy.pdf
PDF
Securing AI - There Is No Try, Only Do!.pdf
PDF
GenAI Opportunities and Challenges - Where 370 Enterprises Are Focusing Now.pdf
PDF
Coordinated Disclosure for ML - What's Different and What's the Same.pdf
PDF
10 Key Challenges for AI within the EU Data Protection Framework.pdf
PDF
Techniques for Automatic Device Identification and Network Assignment.pdf
PDF
Keynote : Presentation on SASE Technology
PDF
Keynote : AI & Future Of Offensive Security
PDF
Redefining Cybersecurity with AI Capabilities
PDF
Demystifying Neural Networks And Building Cybersecurity Applications
PDF
Finetuning GenAI For Hacking and Defending
PDF
(CISOPlatform Summit & SACON 2024) Kids Cyber Security .pdf
PDF
(CISOPlatform Summit & SACON 2024) Regulation & Response In Banks.pdf
PDF
(CISOPlatform Summit & SACON 2024) Cyber Insurance & Risk Quantification.pdf
AI Code Generation Risks (Ramkumar Dilli, CIO, Myridius)
From Chatbot to Destroyer of Endpoints - Can ChatGPT Automate EDR Bypasses (1...
Cracking the Code - Unveiling Synergies Between Open Source Security and AI.pdf
Oh, the Possibilities - Balancing Innovation and Risk with Generative AI.pdf
Lessons Learned from Developing Secure AI Workflows.pdf
Cyber Defense Matrix Workshop - RSA Conference
A Constitutional Quagmire - Ethical Minefields of AI, Cyber, and Privacy.pdf
Securing AI - There Is No Try, Only Do!.pdf
GenAI Opportunities and Challenges - Where 370 Enterprises Are Focusing Now.pdf
Coordinated Disclosure for ML - What's Different and What's the Same.pdf
10 Key Challenges for AI within the EU Data Protection Framework.pdf
Techniques for Automatic Device Identification and Network Assignment.pdf
Keynote : Presentation on SASE Technology
Keynote : AI & Future Of Offensive Security
Redefining Cybersecurity with AI Capabilities
Demystifying Neural Networks And Building Cybersecurity Applications
Finetuning GenAI For Hacking and Defending
(CISOPlatform Summit & SACON 2024) Kids Cyber Security .pdf
(CISOPlatform Summit & SACON 2024) Regulation & Response In Banks.pdf
(CISOPlatform Summit & SACON 2024) Cyber Insurance & Risk Quantification.pdf

Recently uploaded (20)

PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Encapsulation theory and applications.pdf
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Unlocking AI with Model Context Protocol (MCP)
PPTX
Big Data Technologies - Introduction.pptx
PPTX
Understanding_Digital_Forensics_Presentation.pptx
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
MYSQL Presentation for SQL database connectivity
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PDF
Encapsulation_ Review paper, used for researhc scholars
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
KodekX | Application Modernization Development
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Review of recent advances in non-invasive hemoglobin estimation
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
The Rise and Fall of 3GPP – Time for a Sabbatical?
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Encapsulation theory and applications.pdf
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Unlocking AI with Model Context Protocol (MCP)
Big Data Technologies - Introduction.pptx
Understanding_Digital_Forensics_Presentation.pptx
The AUB Centre for AI in Media Proposal.docx
Reach Out and Touch Someone: Haptics and Empathic Computing
Network Security Unit 5.pdf for BCA BBA.
MYSQL Presentation for SQL database connectivity
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
Encapsulation_ Review paper, used for researhc scholars
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
20250228 LYD VKU AI Blended-Learning.pptx
KodekX | Application Modernization Development
Advanced methodologies resolving dimensionality complications for autism neur...
Review of recent advances in non-invasive hemoglobin estimation

Defcon 22-david-wyde-client-side-http-cookie-security

  • 1. Client-Side HTTP Cookie Security: Attack and Defense David Wyde DEF CON 22
  • 2. Game Plan •  Why are HTTP cookies valuable to attackers? •  How do popular web browsers store cookies? •  How can cookies be stolen? •  How can cookies be protected?
  • 3. Disclaimers •  The opinions in this presentation are mine, and not my employer’s. •  The security issues I discuss are not specific to any one website, and are not vulnerabilities in the conventional sense.
  • 4. What is an HTTP Cookie? •  Cookies are transmitted as HTTP headers •  Name-value pairs •  HTTP clients store state using cookies •  E.g., trade credentials for a session cookie
  • 6. User-Readable Data •  Any process that runs as your user can read: •  Your private keys •  Some software saves passwords as plaintext •  Web browser cookies •  Damage is done without privilege escalation
  • 7. Cookies Are Valuable to Attackers •  Cookies can be more valuable than passwords •  Gmail: bypass two-factor authentication •  Facebook: don't warn of login from a new device •  Counterpoints •  "Please re-enter your password” •  Cookies expire
  • 11. Cookie Storage: Intro •  Almost all browsers store cookies as plaintext •  The HttpOnly and Secure flags apply inside browsers •  Malware need not respect them
  • 12. Firefox •  Stores cookies in an SQLite database •  Cookies can be read using sqlite3, Python, etc.
  • 13. Reading Firefox Cookies $ sqlite3 ~/Library/Application Support/Firefox/Profiles/*/cookies.sqlite SQLite version 3.7.13 2012-07-17 17:46:21 Enter ".help" for instructions Enter SQL statements terminated with a ";" sqlite> .schema CREATE TABLE moz_cookies (id INTEGER PRIMARY KEY, baseDomain TEXT, appId INTEGER DEFAULT 0, inBrowserElement INTEGER DEFAULT 0, name TEXT, value TEXT, host TEXT, path TEXT, expiry INTEGER, lastAccessed INTEGER, creationTime INTEGER, isSecure INTEGER, isHttpOnly INTEGER, CONSTRAINT moz_uniqueid UNIQUE (name, host, path, appId, inBrowserElement)); CREATE INDEX moz_basedomain ON moz_cookies (baseDomain, appId, inBrowserElement); sqlite> SELECT value FROM moz_cookies WHERE name='GX'; DQAAAPEAAABWYmsr2PFvwQi4XhQWYcw_5coZVfjh-efmKTNeLjyLx04sHi_Ih- xMOsSRaZ6J38QzDGyCt5v6DKYkkoc6TeX8QKuaOPSAqqGTEo4v2Y6kvmzlS-SvdU4zTcuJ- z4uCf7uiZ7Ic- H6U5Mt7leqmsDhQeEoL01z5OF6iLoxUeCHU_91eWrA2bOpU8ppqVjutpi4WVhyqLV7WX6hgSnE kWnpsN-XwcDF84V7u0DrlKCQFupzmCfa3nt_tARY-SxbyNrmY_0rH4YF- xBVvPFXBQpKqUZrW_zMdGmWgmPER_7mBTGXtlh9PM5nCP_bw09oIqXrQb_OhHe7c3AnnIg2EIq g
  • 14. Internet Explorer •  Stores cookies as text files •  The folder varies depending on IE version •  Filenames are random: need to read the files
  • 16. Opera and Safari •  Custom binary formats •  Can be parsed by free software tools •  Safari: Cookies.binarycookies •  Opera: cookies4.dat
  • 17. Reading Safari Cookies $ python ~/Desktop/BinaryCookieReader.py ~/Library/ Cookies/Cookies.binarycookies | grep yahoo Cookie : hpc=d=ItIKgZXDu9Pkv2_sEb7ygoVyN9bHZ2mmjnr8eBC8z9Ynw88Tayw 7ixgQfT4vleMQ56bGUussxMNmYBusbq3RHgXIkea3DhM.Yzckc.y6GAQE iJoPoK1DzyvYg1cyBoMWlZccOkvv7wvPUmDHnNk1uyiJwon3_YjfMMyCX stKdmUKmePy_Wn04tFoVbui1wlLTuSpqTw-&v=2; domain=.www.yahoo.com; path=/; expires=Wed, 15 Jul 2015; Cookie : B=2b26v3t9s955p&b=3&s=oh; domain=.yahoo.com; path=/; expires=Fri, 15 Jul 2016; Cookie : CRZY=%7B%221048616551%22%3A%7B%22expires %22%3A1405564858541%2C%22data%22%3A%7B%22nv%22%3A1%2C %22bn%22%3A0%7D%7D%7D; domain=.yahoo.com; path=/; expires=Thu, 17 Jul 2014;
  • 18. Reading Opera Cookies $ python opera_reader.py ~/.opera/cookies4.dat file_version_number 4096 app_version_number 8193 idtag_length 1 length_length 2 domain record [('0x1e', 'name of the domain part', 3, 'org')] end of path record domain record [('0x1e', 'name of the domain part', 8, 'slashdot')] cookie record [('0x10', 'name of the cookie', 6, '__gads'), ('0x11', 'value of the cookie', 69, 'ID=2628549bf6c27042:T=1405392507:S=ALNI_Maix2zTTIQ4159AfUM0tH p7h_ODgQ'), ('0x12', 'expiry', 8, '2016-07-13 21:48:27'), ('0x13', 'last used', 8, '2014-07-14 21:49:28'), ('0x28', 'unknown cookie data id', 8, 'x00x00x00x00x00x00x00x00'), ('0xa9', 'unknown cookie data id', 0, '')]
  • 19. Chromium •  Encrypts cookies in recent versions •  Implementation and security vary by platform •  Stores cookies in an SQLite database •  BLOB field for encrypted cookie values
  • 20. Chromium on Linux •  Linux has no single standard keyring mechanism •  (KDE, Gnome, etc.) •  Cookies encrypted with AES (symmetric key) •  Hard-coded key and salt •  Can be decrypted on any machine •  Link against Chromium libs, call code to decrypt
  • 22. Reading Chromium Cookies: Linux [david@localhost Desktop]$ python chromium_b64_cookie_linux.py djEwXgab42ZPnVqGRirZqEHsvEN8bC/ chT84CbmJxMSJDr6XA7mQLZdCuLwYSNA6srVf7NDn7rHdBOFJf8SX4jdCxlQhcrUGH +0KzFz +hUxUcgRzy6jWEZyAe4QDegh1YGtfdCGiZ2TgHkEifJ0Mojf4VpuKhFw7SVpCzCorz86JF czNpco7LZwM/xng7UPmVEY4sIQwAGlTXoY9ThgaliP8HGviwkK0ozW9/FMUiGaxBIqDD +FSfsGszckv9zRbK8XL2PbHVslRmG2ENQ8wESu2Czajb20BQ+L3dMRvOcVbW+gwt+H/ cBG23dnjnhFxGcvm9DSDyz87o5ssILocgMT+kddTBCG8ohvy7iNE3njT6WOFktK8Hd/ +rhSUarnCtZt9UB1EZtikWbpqn0PKrVCKn0wVpO4oyeDIe96xEesn/IM= david@computer /d/code/snickerdoodle/chromium-linux $ LD_LIBRARY_PATH=/d/code/lib/chromium/src/out/Release/lib ./ base64_reader $(cat fedora-cookie.txt) DQAAANMAAAD55DvOAnmlugeHzwGKs0asFxYtMfXl- Xdg7MtLYmdj5GDI3iyPh70Ds6OKgogfATna2KV9d7JqZxJ5e7SA- sbH1oxvQFs1WsFo_9WzEfj9VamEV5C0uml6tVuzhIGzrrKM0__0SI6QANb-y- qyM3QJSKCB7QrXR_Ug7lFzjibDW7Fsfg15SUCTmfQz9YLBP4oYSOt_pJRVf5XZgbN_2J- KQzBqtZznZwKVE4TatBaAucT- R9jXnjM5aMdoJvr7ubghi0p1m7yvPevqNNRItPkeB5aV_cPXHKRMjwhAAk6_2w
  • 23. Chromium on Windows •  CryptProtectData is used to encrypt •  A Windows cryptography API •  Uses login credentials as part of the encryption •  CryptUnprotectData is used to decrypt •  Must be called by the user that encrypted, on the same machine
  • 24. Chromium on Mac •  Store an encryption key in the system keychain •  If no key exists, a random one is generated •  AES is used to encrypt/decrypt •  Keychain prompts when accessed from unsigned apps
  • 26. Browser Cookie Storage: Summary •  Chromium encrypts cookies on Windows and Mac •  Chromium obfuscates cookies on Linux •  Other popular browsers store cookies as plaintext
  • 28. Physical Access •  Cookies are there for the taking with most browsers •  Chromium protects you on Windows and Mac
  • 29. Social Engineering •  Excel/Word macros •  Malicious executables •  Don't need to install anything - just run once
  • 30. Malware •  Drop and run an executable to extract cookies •  Metasploit •  Any process that runs as your user •  HTTP POST cookies to a malicious server
  • 34. Disk Encryption •  Protect against physical access to plaintext cookies
  • 35. Application Firewalls •  Block/allow (server, port) pairs for each application •  Chromium can access www.google.com on port 443 •  Examples •  Mac: Little Snitch •  Windows: NetLimiter? •  Linux: ?
  • 37. SELinux •  Security-Enhanced Linux •  Separate from standard Unix permissions •  Can isolate a user’s applications from each other
  • 38. Idea: Master Password for Cookies •  Type in a password to decrypt your cookies •  Firefox has this to protect passwords
  • 40. Server-Side Defenses •  Tie a session cookie to the login IP •  The cPanel web hosting tool can optionally enforce this •  Kind of annoying in a world of mobile clients •  Warn users, rather than force them to log in again •  “You’ve logged in from X and Y countries this month”
  • 41. Conclusions •  Cookies should be handled with care •  Client-side cookie security is not a solved problem
  • 42. References •  Opera reader: https://gist.github.com/gwarser/1324501#file-readcookies-py •  Safari reader: http://www.securitylearn.net/2012/10/27/cookies-binarycookies- reader/ •  Firefox master password: http://kb.mozillazine.org/Master_password •  cPanel cookie IP validation: http://www.cpanelkb.net/cpanel-security-settings-checklist/ •  CryptProtectData (Microsoft documentation): http://msdn.microsoft.com/en-us/library/aa922939.aspx