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
iptables を使って、 2回に1回 ping が落ちる サーバを作る / Use i...
Search
do-su-0805
September 25, 2019
Programming
1.5k
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
iptables を使って、 2回に1回 ping が落ちる サーバを作る / Use iptables to create a server that pings once every two times
ref :
https://do-su-dairyquestions.hatenablog.com/entry/2018/12/18/080000
do-su-0805
September 25, 2019
More Decks by do-su-0805
See All by do-su-0805
元SREのCREが伝えたい、Mackerelをもっと活用するための実践Tips集 / Mackerel Drink Up #11 do-su-0805
dosu0805
0
360
とある高専生の進路例/Example of a certain college student
dosu0805
1
1.3k
AWS IAM で MFA 有効でないユーザを awscli + Mackerel で監視する / Monitoring users who are not MFA enabled with AWS IAM with awscli + Mackerel
dosu0805
0
340
Webアプリケーション初心者が ISUCON 4 予選を通じてパフォーマンスの測定改善をした話 / newcomers of web application improvements in performance measurement through ISUCON 4 qualifying
dosu0805
0
1.4k
Other Decks in Programming
See All in Programming
速習iPhone Duo対応
yuukiw00w
2
910
wkhtmltopdfの次どうするか問題2026
willnet
2
1.8k
AWS CDKのカスタムリソースでContinuum(旧Security Agent)を実装した話 | Implementing Continuum (formerly Security Agent) via AWS CDK Custom Resource
akihisaikeda
1
100
20260914 AIエージェント時代のPlatform Engineering LLM基盤とプロダクトの責務境界線
kanfab1
7
2.3k
WebRTC映像をAirPlayに対応させる挑戦.pdf
monolithic_adam
0
330
[2026-09-26]空論ジェネリックプロセス~テスト資産とAIで紡ぐ、再現可能なパフォーマンスチューニングの話~
tosite
0
250
ソニーのクラウド共通基盤の変遷とAI時代の開発スタイルに合わせた進化 / The Journey of Sony’s Common Cloud Platform and Its Evolution for AI-Native Development
kenjiyoneyama
0
200
App Storeの外へ──日本のiOSサイドローディング入門 for iOSDC Japan 2026
yuukiw00w
0
280
パズルゲームの作り方 / how to make puzzle games
kaityo256
PRO
2
260
AHC070解法紹介
eijirou
0
150
App Intentsのビルドプロセスを支える技術
kntkymt
0
480
Go × SIMDで高速化するベクトル検索 ~ルーフラインモデルでSIMDが効く境界を探れ! ~
po3rin
1
5.4k
Featured
See All Featured
Optimising Largest Contentful Paint
csswizardry
37
4k
Product Roadmaps are Hard
iamctodd
55
13k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
31
3.4k
sira's awesome portfolio website redesign presentation
elsirapls
0
430
Data-driven link building: lessons from a $708K investment (BrightonSEO talk)
szymonslowik
1
1.3k
Neural Spatial Audio Processing for Sound Field Analysis and Control
skoyamalab
0
530
B2B Lead Gen: Tactics, Traps & Triumph
marketingsoph
0
250
New Earth Scene 8
popppiees
4
2.6k
Max Prin - Stacking Signals: How International SEO Comes Together (And Falls Apart)
techseoconnect
PRO
0
470
Writing Fast Ruby
sferik
630
63k
The Cost Of JavaScript in 2023
addyosmani
55
10k
Abbi's Birthday
coloredviolet
4
10k
Transcript
で 回に 回 が落ちる サーバを作る 株式会社はてな サービスシステム開発本部 システムプラットフォーム部 SRE do-su-0805
今日話すこと • ヘッダ ヘッダと について話をします • 別例などは以下で紹介 ◦ https://do-su-dairyquestions.hatenablog.com/entry/2018/12/18/080000
アジェンダ • について • が届かない範囲 • オプションの紹介 • 実例 パケットが
回に 回落ちるルール • 実演
について 簡単に言うと、こんな感じのことができる • パケットのフィルタリング/ロギング ◦ tcp / port 80 あての通信は
192.168.0.0/16 からのみ ◦ udp / port 53 あての通信をログに残す • NAT
について iptablesは、Linuxに実装されたパケットフィルタリングおよびネット ワークアドレス変換 (NAT) 機能であるNetfilter(複数のNetfilterモ ジュールとして実装されている)の設定を操作するコマンドのこと。 Netfilterは、いわゆるファイアウォールやルータとしての役割を果 たす。 https://ja.wikipedia.org/wiki/Iptables より
で使えるルール対象 • proto ◦ tcp / udp / icmp •
src / dist IP • port ◦ 80 (http) / 22 (ssh) • etc… IP ヘッダの情報 (+ tcp / ttl などの拡張) が使える
のルール指定で届かない範囲 • レイヤーのパケットヘッダ情報(一部除く) ◦ ヘッダで言うならシーケンス番号や確認応答番号 ◦ ヘッダで言うならコードやエコー要求・応答時のシー ケンスナンバー ◦ ヘッダで言うなら
セグメント長 ◦
オプションの紹介 • 自分でルールを書いて、パケット解析を行いルール適用 ◦ iptables -m u32 --u32 "6&0xFF=0x1 &&
0>>22&0x3C@0>>24=0x08 && 0>>22&0x3C@6>>16&0x01=0x01" -A INPUT -j DROP` ▪ ”6& … =0x01” までのルールに該当する INPUT パケットを DROP • ICMP echo 要求で seq が 奇数の時だけ DROP する ▪ $ ping 192.168.1.7 PING 192.168.1.7 (192.168.1.7) 56(84) bytes of data. 64 bytes from 192.168.1.7: icmp_seq=2 ttl=64 time=0.329 ms 64 bytes from 192.168.1.7: icmp_seq=4 ttl=64 time=0.325 ms 64 bytes from 192.168.1.7: icmp_seq=6 ttl=64 time=0.311 ms 64 bytes from 192.168.1.7: icmp_seq=8 ttl=64 time=0.320 ms
実例 パケットが 回に 回落ちるルール • iptables -m u32 --u32 "6&0xFF=0x1
&& 0>>22&0x3C@0>>24=0x08 && 0>>22&0x3C@6>>16&0x01=0x01" -A INPUT -j DROP を読み解きます
実例 パケットが 回に 回落ちるルール • iptables -m u32 --u32 "6&0xFF=0x1
&& まで ◦ iptables -m u32 --u32 : u32 拡張を呼び出す ◦ 6 : IPヘッダ先頭から 7 ~ 10byte までの 4 byte を呼び出す ▪ この 4 byte 列 = 1 オクテット ▪ "0 なら 1byte 目 ~ 4 byte 目までの 1 オクテットが呼び出される ◦ &0xFF=0x1 : 呼び出した 1オクテットに対して、マスクをかけて比較 ▪ つまり最後の 1byte のみ = 10 byte 目だけにします。ここは プロトコル番号 ▪ 抜き出した結果が 0x1 (ICMP) であれば真となる比較式 ◦ && : 左辺が真であれば継続してルール解釈
実例 パケットが 回に 回落ちるルール ネットワークエンジニアとして 「TCP/IP - IPとは」https://www.infraexpert.com/study/tcpip1.html
実例 パケットが 回に 回落ちるルール • 6 : IPヘッダ先頭から 7 ~
10byte までの 4 byte を呼び出す ◦ 「フラグ」から「プロトコル」までが取得される 資料中段図 : ネットワークエンジニアとして 「TCP/IP - IPとは」https://www.infraexpert.com/study/tcpip1.html より
実例 パケットが 回に 回落ちるルール • &0xFF=0x1 : 呼び出した 1オクテットに対して、
マスクをかけて比較 ◦ 最後の 1byte のみ = 10 byte 目 = プロトコル番号 ◦ 抜き出した結果が 0x1 (ICMP) であれば真となる比較式 ▪ ここが 0d6 だと TCP. 0d41 だと UDP だとわかる。
実例 パケットが 回に 回落ちるルール • 0>>22&0x3C@0>>24=0x08 &&まで ◦ 0>>22&0x3C :
1 ~ 4byte を呼び出し、22bit シフトして AND ▪ バージョン/ヘッダ長/サービス種別の先頭 2bit が取得できる ▪ その結果に 0x3C を AND することで、「ヘッダ長の 4 倍」が手に入る • 「32bit 列がいくつ分か」が入っているので、 4 倍すると byte になる ◦ @0>>24=0x08 : 上記結果を 0 とし 4byte 取得しシフト & 比較 ▪ ヘッダ長@ すると IP ヘッダを抜け出し、 ICMP ヘッダ先頭から 4byte 取得 ▪ >>24 し、先頭 1byte だけ(ICMPヘッダのtype) にし、0x08(エコー要求)か比較
実例 パケットが 回に 回落ちるルール • 0>>22&0x3C :1 ~ 4byte を呼び出し
22bit シフト して AND 資料中段図 : ネットワークエンジニアとして 「TCP/IP - IPとは」https://www.infraexpert.com/study/tcpip1.html より
実例 パケットが 回に 回落ちるルール • 0>>22 すると • &0x3C すると、ヘッダ長
* 4 された値 (5*4 = 20)
実例 パケットが 回に 回落ちるルール • @0>>24=0x08 : 20 byte 目を
0 とし 4byte 取得 しシフト & 比較 ◦ IP ヘッダ長を抜けた = ICMP ヘッダの先頭から 4byte ◦ ◦ ◦ 24 bit シフトすると
実例 パケットが 回に 回落ちるルール • 0>>22&0x3C@6>>16&0x01=0x01まで ◦ 0>>22&0x3C までは先ほどと同様のため省略 •
@6>>16&0x01=0x01 ◦ @6 : ICMP ヘッダの 7byte ~ 10byte 目を取得 ◦ >>16 :16bit シフトしシーケンス番号を取得。最後に奇偶判定
実例 パケットが 回に 回落ちるルール • 今までの説明をまとめると、こんな感じ ◦ 6&0xFF=0x1 && :
ICMP パケットかつ ◦ 0>>22&0x3C@0>>24=0x08 && : タイプがエコー要求かつ ◦ 0>>22&0x3C@6>>16&0x01=0x01 : シーケンス番号が奇数なら • 最後に -A INPUT -j DROP ◦ 上記のようなパケットをサーバが「受けたら」、「DROP する」
まとめ • の 拡張を紹介した • 複雑に見えるルールを一つ一つ追ってみた ◦ 6&0xFF=0x1 && :
ICMP パケットかつ ◦ 0>>22&0x3C@0>>24=0x08 && : タイプがエコー要求かつ ◦ 0>>22&0x3C@6>>16&0x01=0x01 : シーケンス番号が奇数なら ◦ -A INPUT -j DROP : そんなパケットをサーバが受けたら廃棄する