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
%sの話
Search
NV
September 15, 2018
Technology
1
1.3k
%sの話
@IoTSecJP東京 Version4.0
NV
September 15, 2018
Tweet
Share
More Decks by NV
See All by NV
ゲームのボツデータを見てみよう
nvsofts
1
490
eMMCの話
nvsofts
2
2.1k
DOOMに関するあれこれ
nvsofts
0
470
よくあるバックドアの話(公開版)
nvsofts
2
530
IoTハックに使える買って良かったと思うもの
nvsofts
0
2.1k
BLEな()おもちゃを調べてみる
nvsofts
3
1.2k
Other Decks in Technology
See All in Technology
The road to green code (with Sonar)
bluehats
0
150
Covariance, Contravariance & Diamond
alexdaubois
1
110
Microsoft 365 でデータセキュリティを強化しよう
sophiakunii
2
470
40代後半で開発エンジニアからクラウドインフラエンジニアにキャリアチェンジし、生き残れる自信がようやく持てた話
iwamot
9
8.1k
KubeVirt Networking ONIC 2024
orimanabu
4
730
まだ間に合う! 生成AIトレンド一挙おさらい & AWSのBedrockに入門しよう
minorun365
PRO
4
220
RAG: from dumb implementation to serious results
glaforge
0
640
プログラミング写経のすすめ
natsutan
0
160
AIとともに歩んだライブラリアップデートの道のり/ vue-fes-japan-2024-link-and-motivation
lmi
2
1.4k
XSS攻撃から考察するAWS設定不備の恐怖/20241012 Hironobu Otaki
shift_evolve
0
130
From LibreOffice to « La Suite » : providing civil servants with Free Software sovereign tools
bluehats
0
120
RDS for Db2 データ移行編 - Part2:S3経由のバックアップ・リストアでデータ移行 /20241011-RDSforDb2-dojo
mayumihirano
0
140
Featured
See All Featured
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
225
22k
For a Future-Friendly Web
brad_frost
174
9.4k
Building Adaptive Systems
keathley
38
2.2k
Code Review Best Practice
trishagee
63
17k
Visualization
eitanlees
143
15k
Statistics for Hackers
jakevdp
796
220k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
43
6.6k
Done Done
chrislema
181
16k
What's new in Ruby 2.0
geeforr
342
31k
How To Stay Up To Date on Web Technology
chriscoyier
788
250k
Building Better People: How to give real-time feedback that sticks.
wjessup
363
19k
Fashionably flexible responsive web design (full day workshop)
malarkey
404
65k
Transcript
%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”などで検索すると、脆弱性が見つかるかも? ◦ 今回はこれが言いたかった