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
560
เก็บรหัสผ่านยังไงดี 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
82
gRPC load balancing with xDS
whs
0
960
ArgoCD
whs
0
430
Writing Babel Plugin
whs
0
190
What's new in Cloud Next 2019
whs
0
300
A Date with gRPC
whs
1
1.4k
ตีแผ่ Microservice ด้วย Tracing
whs
0
370
Next Generation Smart Home
whs
0
970
Istio and the Service Mesh Architecture
whs
3
1k
Other Decks in Programming
See All in Programming
Kiroで始めるAI-DLC
kaonash
2
630
testingを眺める
matumoto
1
140
Performance for Conversion! 分散トレーシングでボトルネックを 特定せよ
inetand
0
3.4k
Android 16 × Jetpack Composeで縦書きテキストエディタを作ろう / Vertical Text Editor with Compose on Android 16
cc4966
2
270
HTMLの品質ってなんだっけ? “HTMLクライテリア”の設計と実践
unachang113
4
2.9k
Cache Me If You Can
ryunen344
2
4k
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
420
概念モデル→論理モデルで気をつけていること
sunnyone
3
300
GitHubとGitLabとAWS CodePipelineでCI/CDを組み比べてみた
satoshi256kbyte
4
250
AI Coding Agentのセキュリティリスク:PRの自己承認とメルカリの対策
s3h
0
240
Updates on MLS on Ruby (and maybe more)
sylph01
1
180
もうちょっといいRubyプロファイラを作りたい (2025)
osyoyu
1
460
Featured
See All Featured
Designing Dashboards & Data Visualisations in Web Apps
destraynor
231
53k
Music & Morning Musume
bryan
46
6.8k
The Pragmatic Product Professional
lauravandoore
36
6.9k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
8
930
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
358
30k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
46
7.6k
Done Done
chrislema
185
16k
Navigating Team Friction
lara
189
15k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
48
9.7k
Building Applications with DynamoDB
mza
96
6.6k
Raft: Consensus for Rubyists
vanstee
140
7.1k
VelocityConf: Rendering Performance Case Studies
addyosmani
332
24k
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
จบ ถามไดไมกัด