Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Cookie Theft and Session Hijacking
Search
shawn0102
August 16, 2014
Programming
140
2
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Cookie Theft and Session Hijacking
shawn0102
August 16, 2014
Transcript
32 slides
Cookie Theft & Session Hijacking 邵帅 twitter@shawn0102 weibo@shaoshuai0102 http://shaoshuai.me
None
cookie有关的术语 • session cookie • persistent cookie/tracking cookie • secure
cookie • httpOnly cookie • third-party cookie • supercookie • zombie cookie/evercookie
httponly cookie 被声明为httponly的cookie只有在 执⾏行http/https请求时会带上,在js中⽆无 法获取到 Set-Cookie: JSESSIONID=xx88bss008; Domain=.foo.com; Path=/; HttpOnly
secure cookie 被声明为secure的cookie只有在使 ⽤用https时会加密传输,不会在http请求 中传输 Set-Cookie: JSESSIONID=xx88bss008; Domain=.foo.com; Path=/; Secure
cookie的⽤用途 • session管理! • 个性化 • user tracking
session cookie被窃取 的危害演⽰示
“怎么偷⾛走session cookie?”
利⽤用xss漏洞获取cookie
我把session cookie设置为httpOnly,xss漏洞就 ⽆无法拿到session cookie了吧?
如果是php,如果开放了phpinfo权限,攻击就可 ⾏行了:xss发起异步请求,分析response拿到 httpOnly的cookie
设置httpOnly,关闭phpinfo,还有办法吗
XST!
XST • XST = Cross Site Tracing = XSS +
http trace • http trace是让我们的web服务器将客户端的所有请求信 息返回给客户端的⽅方法。其中包含了httpOnly的 cookie。 • 最佳实践是关闭服务器的trace功能。 • 但是当使⽤用代理的时候,代理可以被配置成⽀支持trace, 从⽽而⼜又可以进⾏行xst攻击了,所以代理要慎⽤用! • 还好现代浏览器禁⽤用了异步发送trace请求的功能。
设置httpOnly,关闭phpinfo,关闭trace⽀支持,⽤用 户使⽤用的是现代浏览器,还有办法偷⾛走session吗
以上⽅方式只防⽌止通过浏览器拿到 session cookie,但是可以通过拿 到实际的⺴⽹网络请求,所有cookie都 ⽆无法隐藏!
⽅方式⼀一⺴⽹网络监听(network eavsdropping) • 只要是未使⽤用https加密的⺴⽹网站都可以抓包 分析,其中包含session cookie • 未保护的wifi,对同⼀一⺴⽹网络下的请求进⾏行 监听 •
⼯工具firesheep http://codebutler.com/ firesheep/
⽅方式⼆二 DNS缓存投毒 • 把要攻击的域名的⼀一个⼦子域映射到攻击者 的server,然后想办法让被攻击者访问这 个server,请求中会带过来所有cookie (包括httpOnly)
⽅方式三 中间⼈人攻击 • 搭建免费wifi,把DHCP服务器指定为攻击 者ip,在攻击者机器上可以收到所有请 求,不仅可以获取session cookie,还可 以进⾏行脚本注⼊入 • 未使⽤用https才可以
⽅方式四 代理服务器/VPN等 • 翻墙⽤用免费VPN?⼩小⼼心你的session cookie
使⽤用https协议,是不是中间⼈人就⽆无法攻击了
如果同时⽀支持http和https,那么 还是可以使⽤用⺴⽹网络监听http请求获 取session cookie
只⽀支持https,不⽀支持http
如果输⼊入example.com发起请 求,会有⼀一次301重定向,这次请 求是http的,也会带上cookie!
把 session cookie设置成secure,只允 许在https上加密传输
其他cookie(⾮非secure)在这次301 请求中还是可以拿到,就看有没 有有⽤用信息了
设置header Strict-Transport- Security,直接省略这个http请求! http://www.wooyun.org/bugs/wooyun-2010-0498 36b625b1c47b40b270c6a390a0fb9525
现实 • ⼀一个https的⺴⽹网站,有某些⼦子域名使⽤用http提供服 务,通常为了统⼀一session,会不设置session cookie为secure,可以通过中间⼈人攻击劫持 session。
如果偷取cookie失败,⽆无 法session劫持,攻击者 如何再发起攻击?
劫持session的⺫⽬目的是拿到登录态,从⽽而获得服务器授权做很多 请求,例如账户变更。如果劫持不到session,也能够做授权请 求不是也达到攻击的⺫⽬目的了? ! ⽆无需拿到session cookie,跨站发起请求就可以了,这就是 CSRF! ! server通过把⽤用户凭证存储在cookie以维持session,http/https 协议每次访问都会⾃自动传输cookie,协议上的缺陷是导致可进⾏行
CSRF攻击的根本原因! ! 防御⽅方式:使⽤用anti-forgery token ! CSRF
“⼤大部分攻击都是提权⾏行为,最基本的提权通过偷 取⽤用户名密码,不成功转⽽而窃取session,窃取不 成转⽽而跨站攻击,实在不⾏行重放也可以造成危害” 总结
谢谢
More Decks by shawn0102
See All by shawn0102
Cookie Theft and Session Hijacking
shawn0102
0
970
Generators in ES6
shawn0102
2
160
Other Decks in Programming
See All in Programming
Engineering Biometric UX Across Android Versions | DroidKnights 2026
ryunen344
1
210
Debian JP Projectのサーバー構成
uwabami
1
130
Materialが消えた日 〜真っ白なFlutterキャンバスにRenderObjectで絵を描く〜
umigishiaoi
0
170
手の動かし方がわからなかった私が個人開発者になるまで
usagi0920_pochi
0
270
学びを記事・スライド・Xへ高速展開する― AI-assisted Learning Loopで回すコンテンツ生成術
ochtum
0
210
GraphQL の onError と Nullability のこれから
quramy
0
220
クラウドエージェントは、 何がそんなに便利なのか / what makes cloud agents so useful
rkaga
5
930
protojson における文字化けの扱い
kazuki1023
0
450
Web3Dライブラリを作ってVue Custom Rendererの仕組みを理解しよう / lets learn vue custom renderer by making 3d library
drumath2237
1
140
AI時代のTerminal環境を UNIX哲学で設計・運用する
yasunori0418
1
360
RaspberryPi 5で軽くはじめるk3sとtailscaleを用いたホームサーバー構築 (1)
nasum
0
410
graphql-ruby を Spinel で速くしようとした話
mtsmfm
0
150
Featured
See All Featured
Collaborative Software Design: How to facilitate domain modelling decisions
baasie
1
380
Self-Hosted WebAssembly Runtime for Runtime-Neutral Checkpoint/Restore in Edge–Cloud Continuum
chikuwait
0
960
Information Architects: The Missing Link in Design Systems
soysaucechin
1
1.3k
Highjacked: Video Game Concept Design
rkendrick25
PRO
2
580
Jamie Indigo - Trashchat’s Guide to Black Boxes: Technical SEO Tactics for LLMs
techseoconnect
PRO
0
760
Automating Front-end Workflow
addyosmani
1370
210k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
162
16k
svc-hook: hooking system calls on ARM64 by binary rewriting
retrage
2
680
Getting science done with accelerated Python computing platforms
jacobtomlinson
2
580
Documentation Writing (for coders)
carmenintech
77
5.6k
SEO for Brand Visibility & Recognition
aleyda
0
4.9k
The AI Revolution Will Not Be Monopolized: How open-source beats economies of scale, even for LLMs
inesmontani
PRO
3
3.8k