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
%sの話
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
NV
September 15, 2018
Technology
1.4k
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
%sの話
@IoTSecJP東京 Version4.0
NV
September 15, 2018
Transcript
24 slides
%sの話 NV (@nvsofts)
自己紹介 名前:NV ◦ Twitter: @nvsofts 個人サークル「えぬえす工房」代表 ◦ https://www.ns-koubou.com/ ◦ 最近は市販機器をハックする同人誌を書いています
普段は都内にあるセキュリティ会社でIoTセキュリティなどをやっています
%s
お察しの通り 今回は、sprintf()などで使用する書式文字列である”%s”に関する話です
これ、IoT関係あるの??
これ、IoT関係あるの?? あります!
これ、IoT関係あるの?? あります! 実は特定の使われ方で見かけることがあるからです ◦ 何度も見かけているので、偶然ではないはずです
使われ方 1. どこかから入力を取ってくる 2. 入力と書式文字列を元にsprintf()系関数でコマンドを作成する 3. 作成したコマンドをsystem()関数で実行する
コード例 ARM Linuxで、以下のコードをコンパイルした際のアセンブリコードを見る int main(int argc, char *argv[]) { char
buf[1024]; if (argc != 2) { return 1; } snprintf(buf, sizeof(buf), "cp %s data", argv[1]); system(buf); return 0; }
アセンブリコード
アセンブリコード
アセンブリコード
プログラムの動作 引数に与えられたファイル名をdataというファイル名でコピーする 例:/etc/hoge.datをdataというファイル名でコピーする $ ./test /etc/hoge.dat
これって・・・ 脆弱性あるのでは?って思った人
これって・・・ 脆弱性あるのでは?って思った人 → 正解!
これって・・・ 脆弱性あるのでは?って思った人 → 正解! OSコマンドインジェクションの脆弱性があります
脆弱性を突く 例えば、こういうコマンドにしたら? $ ./test '; echo Hello!; /bin/true '
脆弱性を突く 例えば、こういうコマンドにしたら? $ ./test '; echo Hello!; /bin/true ' 実際に実行されるコマンドは
cp ; echo Hello!; /bin/true data となる
なんでこんなのがあるのか? (独断と偏見が多分に入っています)
なんでこんなのがあるのか? (独断と偏見が多分に入っています) → C言語を「すごいシェルスクリプト」として使っている可能性? ◦ 組み込みLinuxを「面倒なことをやってくれるやつ」的な扱いをしている? ◦ 単にコマンドを実行する用途にsystem()関数を使うあたり、そういう感じがする
なんでこんなのがあるのか? (独断と偏見が多分に入っています) → C言語を「すごいシェルスクリプト」として使っている可能性? ◦ 組み込みLinuxを「面倒なことをやってくれるやつ」的な扱いをしている? ◦ 単にコマンドを実行する用途にsystem()関数を使うあたり、そういう感じがする → sprintf()系関数は入門者でも知っているくらい有名
◦ とりあえずこれ使えばやりたいことを実現できる、的な考え?
対策 入力をサニタイズする ◦ 一般的な対策
対策 入力をサニタイズする ◦ 一般的な対策 そもそもsystem()関数を使わない ◦ system()関数はシェルを通すため、’;’などのシェルで意味を持つ文字が使える ◦ fork()してexec()するならそういうことはない ◦
もちろん、/bin/sh –c ~をexec()したらダメ ◦ 加えて、想定外の文字種が入っていないかの検査もするべき
まとめ sprintf()系関数とsystem()関数の組み合わせは、脆弱性を生む可能性 が高い 実行ファイルの文字列を”%s”などで検索すると、脆弱性が見つかるかも? ◦ 今回はこれが言いたかった
More Decks by NV
See All by NV
ゲームのボツデータを見てみよう
nvsofts
1
570
eMMCの話
nvsofts
2
2.4k
DOOMに関するあれこれ
nvsofts
0
530
よくあるバックドアの話(公開版)
nvsofts
2
570
IoTハックに使える買って良かったと思うもの
nvsofts
0
2.3k
BLEな()おもちゃを調べてみる
nvsofts
3
1.4k
Other Decks in Technology
See All in Technology
RAGの改善を速く回すための評価基盤
yosukeyoshida
6
3.2k
LLM 基盤と kagent v0 を全部 k8s に入れてみた / Deploy both LLM and kagent v0 in k8s
kota2and3kan
0
240
閉域網でのAPI公開の選択肢全部比較!
takano0131
4
560
常時稼働エージェントの作り方(Claude公式ブログを資料化)
minorun365
PRO
16
28k
変更差分を読むために環境を整備しよう
pipepasta
1
470
ラクスル会社紹介資料|エンジニア向け / RAKSUL Introduction for Engineers
raksulrecruiting
0
140
属人化したISMS運用をGitHubとAIで仕組み化した1年間の記録
sioncojp
4
2.8k
Go初心者のクラウドエンジニアが、デプロイを通して旨味を知っていく話
ryudai
1
240
落とし穴にハマってわかった 開発生産性を測るときに気をつけたいこと
munakata
3
420
マネジメントされる側の仕事は「文句」を言うこと
riyaamemiya
7
5.8k
あの日、見つかっていなかったらどうなっていたか
kazzpapa3
2
260
PHPで家庭用ゲーム機の専用コントローラーをMIDIデバイスとして扱ってみる
wind111
0
150
Featured
See All Featured
What does AI have to do with Human Rights?
axbom
PRO
1
2.5k
brightonSEO & MeasureFest 2025 - Winning Strategies for Black Friday CRO & PPC - Christian Goodrich
cargoodrich
3
900
Keith and Marios Guide to Fast Websites
keithpitt
413
23k
Utilizing Notion as your number one productivity tool
mfonobong
4
650
Marketing Yourself as an Engineer | Alaka | Gurzu
gurzu
0
380
What the history of the web can teach us about the future of AI
inesmontani
PRO
3
810
Intergalactic Javascript Robots from Outer Space
tanoku
273
28k
Joys of Absence: A Defence of Solitary Play
codingconduct
1
580
Agile that works and the tools we love
rasmusluckow
331
22k
Conquering PDFs: document understanding beyond plain text
inesmontani
PRO
4
3.3k
How to train your dragon (web standard)
notwaldorf
96
6.9k
Organizational Design Perspectives: An Ontology of Organizational Design Elements
kimpetersen
PRO
1
880