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
GoでTCPパケットを読む / Fukuoka.go #12
Search
Ken’ichiro Oyama
October 07, 2018
Technology
1.5k
14
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
GoでTCPパケットを読む / Fukuoka.go #12
Fukuoka.go #12
Ken’ichiro Oyama
October 07, 2018
Transcript
51 slides
খࢁ݈Ұ(.01FQBCP *OD 'VLVPLBHP (PͰ5$1ύέοτΛಡΉ
γχΞΤϯδχΞ খࢁ݈Ұ!L-P8 ϗεςΟϯάࣄۀ෦ϗεςΟϯάάϧʔϓϚωʔδυΫϥυνʔϜ IUUQTHJUIVCDPNL-P8
UDQEVNQ
UDQEVNQͱɺίϚϯυϥΠϯ্Ͱར༻͢Δ Ұൠతͳܭࢉػωο τϫʔΫௐࠪ πʔϧͰ͋ΔɻUDQEVNQʹΑΓɺར༻ऀίϚϯ υΛ࣮ߦͨ͠ܭࢉػ͕ͭͳ͕͍ͬͯΔωοτϫʔΫ্ΛྲྀΕΔ5$1*1ͳ ͲͷύέοτΛԣऔͬͯɺදࣔͤ͞Δ͜ͱ͕ग़དྷΔɻ͜ͷϓϩάϥϜ ։ൃ࣌ʹϩʔϨϯεɾόʔΫϦʔݚڀॴωοτϫʔΫݚڀάϧʔϓʹॴ ଐ͍ͯͨ͠όϯɾδΣΠίϒιϯɺ$SBJH-FSFTɺ4UFWFO.D$BOOFʹ Αͬͯॻ͔Εͨɻ ग़యϑϦʔඦՊࣄయʰΟΩϖσΟΞʢ8JLJQFEJBʣʱ
ҰൠతͳπʔϧͰ͋Δ
None
UDQEVNQͱΘͨ͠ wશͬͨ͘͜ͱ͋Γ·ͤΜͰͨ͠ wʮϦΫΤετΛ͛ΕϨεϙϯε͕ฦͬͯ͘Δ͠ɺ ΫΤϦΛ͛Ε݁Ռ͕ฦͬͯ͘Δʯͦ͏ࢥ͍ͬͯͨ ࣌ظ͕ࢲʹ͋Γ·ͨ͠ʢ͍ͭ࠷ۙ·Ͱʣ wࠓͰ·ͱʹ͑ͳ͍Ͱ͢ wҰํɺνʔϜϝϯόʔۭؾͷΑ͏ʹ͍·͢
5$1ύέοτͱ͔όΠφϦΛ ಡΉͳΜͯ SZ
IUUQTTQFBLFSEFDLDPNFEWBLGHPUFIBJOBSJXPEVNVQMVTB
None
None
͍ʂʂʂ
ͦΕͰ ؆୯ͳUDQEVNQΛ ࡞ͬͯΈ·͠ΐ͏
ࠓճ࣮͢ΔUDQEVNQͷίϚϯυ $ tcpdump -X -i eth0 tcp and port 80
ࠓճ࣮͢ΔUDQEVNQͷίϚϯυ $ tcpdump -X -i eth0 tcp and port 80
ग़ྗϑΥʔϚοτ ωοτϫʔΫΠϯλʔϑΣʔεͷࢦఆ ϑΟϧλϦϯά
ग़ྗ͜Μͳײ͡
Ͱ࡞͍͖ͬͯ·͠ΐ͏
·ͣϓϩδΣΫτσΟϨΫτϦΛ࡞ $ go version go version go1.11 darwin/amd64 $ mkdir
mydump $ cd mydump/ $ echo 'module "github.com/k1LoW/mydump"' > go.mod
NBJOHP 1 package main 2 3 import ( 4 "encoding/hex"
5 "fmt" 6 "log" 7 8 "github.com/google/gopacket" 9 "github.com/google/gopacket/pcap" 10 ) 11 12 func main() { 13 device := "eth0" 14 filter := "tcp and port 80" 15 16 handle, err := pcap.OpenLive( 17 device, int32(0xFFFF), true, pcap.BlockForever, 18 ) 19 if err != nil { 20 log.Fatal(err) 21 } 22 defer handle.Close() 23 if err := handle.SetBPFFilter(filter); err != nil { 24 log.Fatal(err) 25 } 26 27 packetSource := gopacket.NewPacketSource(handle, handle.LinkType()) 28 for packet := range packetSource.Packets() { 29 fmt.Printf(“%s\n", packet) 30 fmt.Printf("%s", hex.Dump(packet.Data())) 31 } 32 }
࣮ߦ $ sudo go run main.go
Ͱ͖ͨ
Ͱ͖ͨ
Ͱ͖ͨ
ιʔείʔυղઆ
NBJOHP- 1 package main 2 3 import ( 4 "encoding/hex"
5 "fmt" 6 "log" 7 8 "github.com/google/gopacket" 9 "github.com/google/gopacket/pcap" 10 )
HPPHMFHPQBDLFU
HPPHMFHPQBDLFU w(PPHMFͷύέοτॲཧ༻ͷϥΠϒϥϦ wIUUQTHJUIVCDPNHPPHMFHPQBDLFU wύέοτ͕ಡΊΔͷ͜ͷϥΠϒϥϦͷ͓͔͛ wQDBQϑΝΠϧͷಡΈࠐΈՄೳʹͳΔ wMJCQDBQΛར༻͍ͯ͠ΔDHP
NBJOHP- 12 func main() { 13 device := "eth0" 14
filter := "tcp and port 80" 15 16 handle, err := pcap.OpenLive( 17 device, int32(0xFFFF), true, pcap.BlockForever, 18 ) 19 if err != nil { 20 log.Fatal(err) 21 } 22 defer handle.Close() ࠓճݻఆɻҾͰ༩͑ΒΕΔΑ͏ʹͳͬͨΒ ΑΓUDQEVNQͬΆ͍ ΠϯλʔϑΣʔεʹΞλον
NBJOHP- 23 if err := handle.SetBPFFilter(filter); err != nil {
24 log.Fatal(err) 25 } #1' #FSLFMFZ1BDLFU'JMUFS Λઃఆ
#1'
IUUQTTQFBLFSEFDLDPNUBLVNBLVNFFCQGHFUUJOHTUBSUFE
NBJOHP- 27 packetSource := gopacket.NewPacketSource( handle, handle.LinkType()) 28 for packet
:= range packetSource.Packets() { 29 fmt.Printf(“%s\n", packet) 30 fmt.Printf("%s", hex.Dump(packet.Data())) 31 } 32 } ύέοτ͕νϟϯωϧΛ௨ͯͬͯ͘͡ΔͷͰGPSͰड͚औΔ ग़ྗ
ιʔείʔυղઆऴྃ
fmt.Printf(“%s\n", packet)
PACKET: 450 bytes, wire length 450 cap length 450 @
2018-10-04 19:02:36.200155 +0900 JST - Layer 1 (14 bytes) = Ethernet {Contents=[..14..] Payload=[..436..] SrcMAC=8c:85:90:ae:ae:c2 DstMAC=2c:33:11:ca:c8:be EthernetType=IPv4 Length=0} - Layer 2 (20 bytes) = IPv4 {Contents=[..20..] Payload=[..416..] Version=4 IHL=5 TOS=0 Length=436 Id=0 Flags=DF FragOffset=0 TTL=64 Protocol=TCP Checksum=24376 SrcIP=192.168.75.96 DstIP=108.177.97.82 Options=[] Padding=[]} - Layer 3 (32 bytes) = TCP {Contents=[..32..] Payload=[..384..] SrcPort=51190 DstPort=80(http) Seq=1867296718 Ack=2345355645 DataOffset=8 FIN=false SYN=false RST=false PSH=true ACK=true URG=false ECE=false CWR=false NS=false Window= 4096 Checksum=19074 Urgent=0 Options=[TCPOption(NOP:), TCPOption(NOP:), TCPOption(Timestamps:958590780/3024242800 0x3922ef3cb4424870)] Padding=[]} - Layer 4 (384 bytes) ^C1 63 69 6e 74 6f 73 |la/5.0 (Macintos|
PACKET: 450 bytes, wire length 450 cap length 450 @
2018-10-04 19:02:36.200155 +0900 JST - Layer 1 (14 bytes) = Ethernet {Contents=[..14..] Payload=[..436..] SrcMAC=8c:85:90:ae:ae:c2 DstMAC=2c:33:11:ca:c8:be EthernetType=IPv4 Length=0} - Layer 2 (20 bytes) = IPv4 {Contents=[..20..] Payload=[..416..] Version=4 IHL=5 TOS=0 Length=436 Id=0 Flags=DF FragOffset=0 TTL=64 Protocol=TCP Checksum=24376 SrcIP=192.168.75.96 DstIP=108.177.97.82 Options=[] Padding=[]} - Layer 3 (32 bytes) = TCP {Contents=[..32..] Payload=[..384..] SrcPort=51190 DstPort=80(http) Seq=1867296718 Ack=2345355645 DataOffset=8 FIN=false SYN=false RST=false PSH=true ACK=true URG=false ECE=false CWR=false NS=false Window= 4096 Checksum=19074 Urgent=0 Options=[TCPOption(NOP:), TCPOption(NOP:), TCPOption(Timestamps:958590780/3024242800 0x3922ef3cb4424870)] Padding=[]} - Layer 4 (384 bytes) ^C1 63 69 6e 74 6f 73 |la/5.0 (Macintos|
None
4USJOHFS͕ઃఆ͞Ε͍ͯΔͧʂ func(* p) String()͕ఆٛ͞Ε͍ͯΔ
࣮ମQBDLFUFBHFS1BDLFUͳͷͰ HJUIVCDPNHPPHMFHPQBDLFUQBDLFUHP- ͔ΒίʔυΛ८ΕΔ
ͭ·Γ HPPHMFHPQBDLFUͷ͍ํ͕ Θ͔Δ
ੋඇ͓͏ͪͰಡΜͰΈ͍ͯͩ͘͞
HPPHMFHPQBDLFUͰ 5$1ύέοτΛಡΉ
5$1ύέοτͬ͘͟Γ &UIFSOFU CZUF *1ϔομ CZUF 5$1ϔομ CZUF Γ 5$1Φϓγϣϯ /CZUF
σʔλ ྫ͑)551.Z42-ͷϓϩτίϧ͔͜͜Β ελʔτ͍ͯ͠Δ
HPPHMFHPQBDLFU
HPPHMFHPQBDLFU &UIFSOFU CZUF *1ϔομ CZUF 5$1ϔομ CZUF Γ 5$1Φϓγϣϯ /CZUF
σʔλ -BZFS -BZFS*1W -BZFS5$1 -BZFS1BZMPBE
-BZFS1BZMPBE ΛಡΊ͍͍ͷͰศར tcpLayer := packet.Layer(layers.LayerTypeTCP) data := tcpLayer.LayerPayload() fmt.Printf(“%s”, hex.Dump(data))
w)551.Z42-1PTUHSF42-͔͜͜ΒCZUFͮͭ ղੳ͢Ε·ͣ0,
͜ΕͰ҆৺ͯ͠ 5$1ύέοτղੳΛ͡ΊΒΕ·͢Ͷʂ
࠷ۙΘͨ͠ 5$1ύέοτղੳΛ͡Ί·ͨ͠
(PͰ5$1ύέοτղੳΛͯ͠Έ·͠ΐ͏ʂ ίʔυʹམͱ͠ࠐΊͨΒͬͪ͜ͷͷʂ
Έͳ͞Μੋඇ 5$1ύέοτΛCZUFͮͭಡΜͰ ʮͳΜͰ͜ͷόΠτྻ͕͋ΔΜͩΑʜʯ ʮ)551ͩͱ͜Μͳ͜ͱͳ͍ͷʹʜʯ ͱϯϯ͏ͳΓ·͠ΐ͏
5IBOLZPV ࠷৽ͷ࠾༻ใΛνΣοΫˠ !QC@SFDSVJU
More Decks by Ken’ichiro Oyama
See All by Ken’ichiro Oyama
Introducing RFC9111 / YAPC::Fukuoka 2025
k1low
2
5.9k
Design and implementation of "Markdown to Google Slides" / phpconfuk 2025
k1low
1
1.2k
analysis パッケージの仕組みの上でMulti linter with configを実現する / Go Conference 2025
k1low
1
950
Flight recorder at the application layer (NOT the FlightRecoder newly added at Go 1.25) / Fukuoka.go #22
k1low
0
210
ソフトウェア開発におけるインターフェイスという考え方 / PHPerKaigi 2025
k1low
12
6.6k
Parsing HCL/CUE / Fukuoka.go #21
k1low
0
11k
実践 net/http Middleware パターン / Kizuku.go Vol.1
k1low
2
510
Cleanup handling in Go / Go Conference 2024
k1low
7
4.3k
CI/CDがあたりまえの今の時代にAPIテスティングツールに求められていること / CI/CD Test Night #7
k1low
18
12k
Other Decks in Technology
See All in Technology
Well, that’s weird…
csswizardry
1
220
Test Impact Analysis を武器に立ち向かう、AI 時代のテスト増加に対するヌーラボのアプローチ / getting-started-datadog-test-impact-analysis
k6s4i53rx
3
870
NutanixへのSSHアクセスの今後について
shadowhat
0
180
コーディングできない僕にBobが舞い降りた
shumpei3
0
210
人の努力に頼らないセキュリティをエンジニアリングする在り方 / An approach to engineering security that does not rely on human effort
carta_engineering
0
240
Platform Engineering をベースとした Agentic Software Factory の実践
110y
3
1k
gradle-best-practices 使ってみた
mikanichinose
0
230
PHPで家庭用ゲーム機の専用コントローラーをMIDIデバイスとして扱ってみる
wind111
0
200
OpenTelemetryで変わった 新時代のCloudWatchメトリクス監視
tsukuboshi
0
510
Amazon EFS のマルウェアスキャンをClamAV で自前実装したら苦労した話
mtmtfactory01
0
120
AIエージェントのアーキテクチャ設計
nsatoh
0
550
その修正で本当に速くなったのか? k6とOpenTelemetryで確かめる性能改善 / Performance review with k6 and OpenTelemetry
ymotongpoo
3
450
Featured
See All Featured
Being A Developer After 40
akosma
PRO
92
590k
What the history of the web can teach us about the future of AI
inesmontani
PRO
3
830
30 Presentation Tips
portentint
PRO
1
480
Agile that works and the tools we love
rasmusluckow
331
22k
The Hidden Cost of Media on the Web [PixelPalooza 2025]
tammyeverts
2
590
コードの90%をAIが書く世界で何が待っているのか / What awaits us in a world where 90% of the code is written by AI
rkaga
63
48k
Navigating the Design Leadership Dip - Product Design Week Design Leaders+ Conference 2024
apolaine
2
530
Six Lessons from altMBA
skipperchong
29
4.6k
エンジニアに許された特別な時間の終わり
watany
109
250k
The agentic SEO stack - context over prompts
schlessera
0
1k
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
10
1.4k
Java REST API Framework Comparison - PWX 2021
mraible
34
9.8k