SlideShare a Scribd company logo
1 of 23
Download to read offline
正規表現の脆弱性
ReDoS 攻撃
を簡単に説明する回
xryuseix
@ryusei_ishika
2021/5/17 Ritsumeikan Security Team
ここからが本題です
○CTF の問題をプレゼント🎉
2021/5/17 Ritsumeikan Security Team
3
(開発ソースコード: https://github.com/xryuseix/ReDoS_server)
https://redos-server.herokuapp.com/
正規表現とは
○⽂字列の集合を⼀つの⽂字列で表現する⽅法
○⾔語によらず基本的には⼀緒
2021/5/18 Ritsumeikan Security Team
4
https://murashun.jp/article/programming/regular-expression.html
正規表現はどう使うのか
○基本的にできること
l ⼤量の⽂字から特定の⽂字列を探す
l “This is a pen.”の中に”pen”があるかまた何⽂字⽬にあるか
l ⽂字列が正しい形式か判定する
l 電話番号に0-0-0-0みたいなものを⼊⼒されないように
l ⼊⼒に変な⽂字(制御⽂字など)を⼊⼒されないように
○↑を⽤いてすること
l ⽂字列の置換
l “This is a pen. I like pen”の中にある”pen”を全て”apple”に変える
l ⽂字列の分割
l ⽂字列をスペース,カンマ,タブのいずれかで分割
2021/5/18 Ritsumeikan Security Team
5
正規表現はどう使うのか
○基本的にできること(Python re モジュール)
l ⼤量の⽂字から特定の⽂字列を探す (re.search)
l “This is a pen.”の中に”pen”があるかまた何⽂字⽬にあるか
l ⽂字列が正しい形式か判定する (re.match)
l 電話番号に0-0-0-0みたいなものを⼊⼒されないように
l ⼊⼒に変な⽂字(制御⽂字など)を⼊⼒されないように
○↑を⽤いてすること
l ⽂字列の置換 (re.sub)
l “This is a pen. I like pen”の中にある”pen”を全て”apple”に変える
l ⽂字列の分割 (re.split)
l ⽂字列をスペース,カンマ,タブのいずれかで分割
2021/5/18 Ritsumeikan Security Team
6
実⾏の様⼦を確認する
2021/5/18 Ritsumeikan Security Team
7
https://regex101.com/
○ 正常1
実⾏の様⼦を確認する
2021/5/18 Ritsumeikan Security Team
8
https://regex101.com/
○ 正常1
実⾏の様⼦を確認する
2021/5/18 Ritsumeikan Security Team
9
https://regex101.com/
○ 正常2
実⾏の様⼦を確認する
2021/5/18 Ritsumeikan Security Team
10
https://regex101.com/
○ 正常2
実⾏の様⼦を確認する
2021/5/18 Ritsumeikan Security Team
11
https://regex101.com/
○ 異常
実⾏の様⼦を確認する
2021/5/18 Ritsumeikan Security Team
12
https://regex101.com/
○ 異常
最初の200⼿↓
2021/5/18 Ritsumeikan Security Team
13
aの個数 ステップ数
3 24
5 96
10 3072
15 98304
20 119987
実⾏の様⼦を確認する
○ aの個数が増えるとステップ数はどうなるのか
2021/5/18 Ritsumeikan Security Team
14
なぜこうなるのか
○ 正規表現はオートマトンによって⽂字列を評価しています
○ オートマトンとは︖ (↓こんな感じの)
https://www.momoyama-usagi.com/entry/info/automaton01
2021/5/18 Ritsumeikan Security Team
15
なぜこうなるのか
○ 正規表現はオートマトンによって⽂字列を評価しています
○ あの正規表現のオートマトンは︖
https://cyberzhg.github.io/toolbox/nfa2dfa
2021/5/18 Ritsumeikan Security Team
16
なぜこうなるのか
○ 正規表現はオートマトンによって⽂字列を評価しています
○ あの正規表現のオートマトンは︖
https://cyberzhg.github.io/toolbox/nfa2dfa?regex=XihhKykrYiQ=
https://cyberzhg.github.io/toolbox/regex2nfa?regex=XihhKykrYiQ=
⾮決定性オートマトン(NFA) 決定性オートマトン(DFA)
Pythonのreはこっち
2021/5/18 Ritsumeikan Security Team
17
なぜこうなるのか
○ 正規表現はオートマトンによって⽂字列を評価しています
○ あの正規表現のオートマトンは︖
https://cyberzhg.github.io/toolbox/regex2nfa?regex=XihhKykrYiQ=
⽂字列
の先頭
⽂字列
の末尾
ここに来れたら
マッチ︕
ここから
いつでも
遷移できる
2021/5/18 Ritsumeikan Security Team
18
なぜこうなるのか
○ 正規表現 : ^(a+)+b$
○ ⼊⼒: aaaaa
https://cyberzhg.github.io/toolbox/regex2nfa?regex=XihhKykrYiQ=
2021/5/18 Ritsumeikan Security Team
19
なぜこうなるのか
○ 正規表現 : ^(a+)+b$
○ ⼊⼒: aaaaa
https://cyberzhg.github.io/toolbox/regex2nfa?regex=XihhKykrYiQ=
ここで次の⽂字がaの時,
遷移先がない
遷移先がないとき,前にミスったのかなって考える
→ちょっと戻る
2021/5/18 Ritsumeikan Security Team
20
なぜこうなるのか
○ 正規表現 : ^(a+)+b$
○ ⼊⼒: aaaaa
https://cyberzhg.github.io/toolbox/regex2nfa?regex=XihhKykrYiQ=
ここで次の⽂字がaの時,
遷移先がない
遷移先がないとき,前にミスったのかなって考える
→ちょっと戻る
ちょっと待て,
なんでミスってんねん💢
2021/5/18 Ritsumeikan Security Team
21
なぜこうなるのか
○ 正規表現 : ^(a+)+b$
○ ⼊⼒: aaaaaa
a a a a a a
テーマ: +の適⽤範囲が難しい
問題:(a+)と+はどの部分を指しますか︖
(a+) +
(a+) +
(a+) +
→いっぱいあって難しいから,とりあえずいっぱい進んで,
ダメだったら少し戻る⽅針
2021/5/18 Ritsumeikan Security Team
22
なぜこうなるのか
→とりあえずいっぱい進んで,ダメだったら少し戻る⽅針
2021/5/18 Ritsumeikan Security Team
23
対策
決定性オートマトン(DFA)が使われるライブラリを使う
https://cyberzhg.github.io/toolbox/nfa2dfa?regex=XihhKykrYiQ=
2021/5/18 Ritsumeikan Security Team
24
対策
決定性オートマトン(DFA)
が使われるライブラリ
対策 予防
○ 正規表現はできるだけコピペ
○ メアド,電話番号などは拾える
○ ユーザの⼊⼒は信⽤しない
○ 繰り返し表現はできるだけ使わない
○ +や*
○ ⼊⼒⽂字数制限
○ 最⼤30⽂字までなど
○ タイムアウトを設定
○ 実⾏時間は最⼤10秒など

More Related Content

Recently uploaded

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 

Recently uploaded (20)

JohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptxJohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptx
 
WSO2 Micro Integrator for Enterprise Integration in a Decentralized, Microser...
WSO2 Micro Integrator for Enterprise Integration in a Decentralized, Microser...WSO2 Micro Integrator for Enterprise Integration in a Decentralized, Microser...
WSO2 Micro Integrator for Enterprise Integration in a Decentralized, Microser...
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Simplifying Mobile A11y Presentation.pptx
Simplifying Mobile A11y Presentation.pptxSimplifying Mobile A11y Presentation.pptx
Simplifying Mobile A11y Presentation.pptx
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
Stronger Together: Developing an Organizational Strategy for Accessible Desig...
Stronger Together: Developing an Organizational Strategy for Accessible Desig...Stronger Together: Developing an Organizational Strategy for Accessible Desig...
Stronger Together: Developing an Organizational Strategy for Accessible Desig...
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
Introduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDMIntroduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDM
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Modernizing Legacy Systems Using Ballerina
Modernizing Legacy Systems Using BallerinaModernizing Legacy Systems Using Ballerina
Modernizing Legacy Systems Using Ballerina
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 

Featured

How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
ThinkNow
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
 

Featured (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

正規表現の脆弱性 ReDoS 攻撃 を簡単に説明する回