Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
เก็บรหัสผ่านยังไงดี 2017
Search
Manatsawin Hanmongkolchai
March 11, 2017
Programming
0
550
เก็บรหัสผ่านยังไงดี 2017
YWC Programmer Meetup #4
Manatsawin Hanmongkolchai
March 11, 2017
Tweet
Share
More Decks by Manatsawin Hanmongkolchai
See All by Manatsawin Hanmongkolchai
Nix: Declarative OS
whs
0
51
gRPC load balancing with xDS
whs
0
860
ArgoCD
whs
0
390
Writing Babel Plugin
whs
0
170
What's new in Cloud Next 2019
whs
0
280
A Date with gRPC
whs
1
1.3k
ตีแผ่ Microservice ด้วย Tracing
whs
0
330
Next Generation Smart Home
whs
0
920
Istio and the Service Mesh Architecture
whs
3
1k
Other Decks in Programming
See All in Programming
sappoRo.R #12 初心者セッション
kosugitti
0
260
Rails アプリ地図考 Flush Cut
makicamel
1
120
コミュニティ駆動 AWS CDK ライブラリ「Open Constructs Library」 / community-cdk-library
gotok365
2
140
Unity Android XR入門
sakutama_11
0
160
Writing documentation can be fun with plugin system
okuramasafumi
0
120
PHPのバージョンアップ時にも役立ったAST
matsuo_atsushi
0
120
Grafana Loki によるサーバログのコスト削減
mot_techtalk
1
130
社内フレームワークとその依存性解決 / in-house framework and its dependency management
vvakame
1
560
Software Architecture
hschwentner
6
2.1k
ARA Ansible for the teams
kksat
0
150
Domain-Driven Transformation
hschwentner
2
1.9k
Linux && Docker 研修/Linux && Docker training
forrep
24
4.5k
Featured
See All Featured
Docker and Python
trallard
44
3.3k
Git: the NoSQL Database
bkeepers
PRO
427
64k
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.1k
Side Projects
sachag
452
42k
4 Signs Your Business is Dying
shpigford
182
22k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
129
19k
jQuery: Nuts, Bolts and Bling
dougneiner
63
7.6k
The Straight Up "How To Draw Better" Workshop
denniskardys
232
140k
Automating Front-end Workflow
addyosmani
1368
200k
GraphQLの誤解/rethinking-graphql
sonatard
68
10k
A Philosophy of Restraint
colly
203
16k
A Modern Web Designer's Workflow
chriscoyier
693
190k
Transcript
เก็บรหัสผานยังไงดี 2017 YWC Programmer Meetup
คั่นเวลา • ขอรหัสผานหนอย • 6 ตัว อักษรอังกฤษ ตัวเลข • เดี๋ยวจะทําอะไรใหดู
• ไมตองใสรหัสจริงมานะ • https://madoka.whs.in.th/pwcrack.html ◦ HTTPS ดวย!!
Who? • Manatsawin Hanmongkolchai (@awkwin) • ถาไมไดกดรับเฟรนก็สงขอความมาถามไดไมกัด • แตถาเขียนโคด insecure
นี่กัด
Why? • ทํา Freelance มาหลาย project • ทุก project ที่ตองไปยุง
code เดิมมีชองโหวพื้นๆ หมด ◦ SQL Injection ◦ Insecure Password Hashing • ถาใหพูดทุกประเด็นคงไดเปนชั่วโมง
ขออาง • "ใชคนเดียว ไมเปนไรหรอก" • "เดี๋ยวคอยแกก็ได"
There are two primary causes for the unintentional creation of
insecure web applications, regardless of the language being used: 1. A lack of knowledge about security 2. Bad development habits — ParagonIE
เก็บรหัสผานยังไงดี? • สมัยผมหัดเขียนเว็บเคาใช MD5 $hashed = md5($_POST['password']);
อยาใช MD5 • SHA1 จาย 5 แสนเหรียญ collision ได •
แต MD5 รันไวสักวันสองวันก็ collision ได
เก็บรหัสผานยังไงดี? • แลวเคาก็วา SHA1 $hashed = sha1($_POST['password']);
อยาใช SHA1 • มี harddisk เหลือ ทําตาราง SHA1 (Rainbow Table)
ไวก็ crack SHA1 ไดในพริบตา
เก็บรหัสผานยังไงดี? • แลวเคาก็วาใส salt สิ จะไดปลอดภัย $salt = uniqid(); $hashed
= sha1($_POST['password'] . $salt);
ยินดีตอนรับสูยุคของ Cloud computing • เมื่อกี้ขอรหัสผาน ใสกันหรือยัง • ถาพรอมแลว ลุย!
ยินดีตอนรับสูยุคของ Cloud computing • Google Cloud เชา K80 ชั่วโมงละ 30
บาทเทานั้น!!! • งัด MD5 ได 4 พันลานครั้งตอวินาที • งัด SHA256 ได 642.1 ลานครั้งตอวินาที ◦ = รหัส 8 ตัว เสร็จใน 2 นาที • เชาไดถึง 8 ใบตอเครื่อง !!
แลวเอาไงดี???? • ใช Algorithm "ชา" (>100ms) มีการดจอก็งัดไมทันหรอก ◦ Argon2 ◦
bcrypt ◦ scrypt ◦ PBKDF2 (iPhone ใชอยู)
PHP • PHP 5.5+ มี password hash function มาใหแลว ชวยใชหนอยเถอะ
• $hash = password_hash($_POST['password'] PASSWORD_DEFAULT); • แลว Salt? มันจัดการใหหมดแลวไมตองไปยุง • (ตอนนี้) ใช algorithm bcrypt
PHP • เวลาเช็ครหัสผานทําแบบนี้ • if(!password_verify($_POST['password'], $db_password)){ die('Wrong!'); } if(password_needs_rehash($db_password, PASSWORD_DEFAULT)){
$db_password = password_hash($_POST['password'] PASSWORD_DEFAULT); } • password_verify จะเทียบรหัสผานโดยไมโดน timing attack • password_needs_rehash จะเช็ควารหัสใช algorithm ลาสุดหรือเปลา ถาไมใชก็ upgrade ได (ในกรณีที่ในอนาคต PHP เปลี่ยน default algorithm)
PHP • ถาไมมี PHP5.5? • https://github.com/ircmaxell/password_compat • API เดียวกับเมื่อกี้ จบปง
PHP • ถาไมมี PHP5.3.7??? • ไมยอมอัพเกรดขนาดนั้นก็สมควรโดน hack
ใช Framework เถอะ • งงมั้ย? • Security งายนิดเดียว แคใช Framework
◦ Django (Python) ลง Argon2/Bcrypt เพิ่มได (อานใน Docs) หรือ default จะใช PBKDF2 ◦ อยาเขียนสิ่งที่ framework มันมีใหอยูแลว
Paragonie Blog • เขียนสนุก เขาใจงาย สําหรับคนเขียน PHP • https://paragonie.com/blog/category/security-engineering
จบ ถามไดไมกัด