Jika Anda sedang mengembangkan aplikasi yang berjalan melalui jaringan, atau sedang men-debug pengoperasian aplikasi semacam itu, pengetahuan menyeluruh tentang cara kerja protokol jaringan akan sangat memudahkan tugas Anda. Sumber utama dari pengetahuan tersebut adalah RFC dan, untungnya, mereka telah berada di domain publik untuk waktu yang lama. Selain itu, Anda dapat membacanya bahkan dengan tautan browser konsol, karena tidak berisi apa pun selain teks.
Namun demikian, kemungkinan besar sebagian besar pembaca Habr belum pernah membaca keseluruhan teks setidaknya satu RFC, bahkan RFC-2616... Selain gaya birokratis yang ganas, kendala bahasa bisa menjadi penghalang. Selain itu, paling sering Anda perlu memahami beberapa aspek spesifik dari arsitektur protokol: panjang dan jenis bidang, kode pengembalian, lokasi di dalam header. Anda tidak perlu membaca semuanya dari sampul ke sampul untuk melakukan ini.
Hanya untuk kasus ini, Protokol ditulis , aplikasi konsol yang cukup sederhana yang ditulis dengan Python. Ini memiliki tujuan ganda.
- Memberikan pengembang dan insinyur kemampuan untuk dengan mudah dan mudah melihat diagram header dari protokol jaringan yang paling umum langsung dari baris perintah.
- Berikan peneliti dan insinyur kemampuan untuk dengan cepat membuat diagram header ASCII untuk protokol kustom mereka sendiri.
Instalasi dan konfigurasi
Kode sumber ada di GitHub , Anda dapat mengunduhnya dengan cara standar.
git clone https://github.com/luismartingarcia/protocol.git
Konfigurasi dilakukan oleh perintah dengan hak pengguna root.
setup.py install
Karena program saat ini tidak memiliki mekanisme instalasi standar untuk distribusi Linux atau Python, lebih baik mengingat di mana file disalin.
running install running build running build_scripts creating build creating build/scripts-3.9 copying and adjusting protocol -> build/scripts-3.9 copying constants.py -> build/scripts-3.9 copying specs.py -> build/scripts-3.9 changing mode of build/scripts-3.9/protocol from 644 to 755 changing mode of build/scripts-3.9/constants.py from 644 to 755 changing mode of build/scripts-3.9/specs.py from 644 to 755 running install_scripts copying build/scripts-3.9/protocol -> /usr/bin copying build/scripts-3.9/constants.py -> /usr/bin copying build/scripts-3.9/specs.py -> /usr/bin changing mode of /usr/bin/protocol to 755 changing mode of /usr/bin/constants.py to 755 changing mode of /usr/bin/specs.py to 755 running install_egg_info Writing /usr/lib/python3.9/site-packages/protocol-0.1-py3.9.egg-info
Jalankan protokol
Program ini memiliki dua mode operasi utama:
- protokol <nama protokol yang ada>;
- protokol <spesifikasi protokol asli>.
Protokol standar berikut tersedia:
ethernet : Ethernet
8021q : IEEE 802.1q
dot1q : IEEE 802.1q
tcp : Transmission Control Protocol (TCP)
udp : User Datagram Protocol (TCP)
ip : Internet Protocol (IP), version 4.
ipv6 : Internet Protocol (IP), version 6.
icmp : Internet Control Message Protocol (ICMP)
icmp-destination: : ICMP Destination Unreachable
icmp-time : ICMP Time Exceeded
icmp-parameter : ICMP Parameter Problem
icmp-source : ICMP Source Quench
icmp-redirect : ICMP Redirect
icmp-echo : ICMP Echo Request/Reply
icmp-timestamp : ICMP Timestamp Request/Reply
icmp-information : ICMP Information Request/Reply
icmpv6 : ICMP for IPv6 (ICMPv6)
icmpv6-destination : ICMPv6 Destination Unreachable
icmpv6-big : ICMPv6 Packet Too Big
icmpv6-time : ICMPv6 Time Exceeded
icmpv6-parameter : ICMPv6 Parameter Problem
icmpv6-echo : ICMPv6 Echo Request/Reply
icmpv6-rsol : ICMPv6 Router Solicitation
icmpv6-radv : ICMPv6 Router Advertisement
icmpv6-nsol : ICMPv6 Neighbor Solicitation
icmpv6-nadv : ICMPv6 Neighbor Advertisement
icmpv6-redirect : ICMPv6 Redirect
Berikut adalah contoh penggunaan utilitas.
|12:09:41|admin@redeye:[~]> protocol ip 0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |Version| IHL |Type of Service| Total Length | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Identification |Flags| Fragment Offset | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Time to Live | Protocol | Header Checksum | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Source Address | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Destination Address | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Options | Padding | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |12:09:45|admin@redeye:[~]> protocol ipv6 0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |Version| Traffic Class | Flow Label | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Payload Length | Next Header | Hop Limit | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | | + + | | + Source Address + | | + + | | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | | + + | | + Destination Address + | | + + | | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Dalam satu perintah, Anda dapat menentukan beberapa protokol sekaligus, memisahkannya dengan spasi.
|12:34:16|admin@redeye:[~]> protocol icmp-time icmp-timestamp 0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Type | Code | Checksum | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Unused | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | | + Internet Header + 64 bits of Original Data Datagram + | | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Type | Code | Checksum | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Identifier | Sequence Number | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Originate Timestamp | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Receive Timestamp | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Transmit Timestamp | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Protokol cerdas, tidak perlu mengetik nama protokol secara lengkap, jika Anda benar-benar malas Anda bisa, misalnya, ketik dot bukan dot1q. Namun, seperti dalam kasus pelengkapan otomatis, dalam kasus pilihan yang ambigu, diusulkan untuk memilih salah satu alternatif.
|12:43:25|admin@redeye:[~]> protocol icmpv6-r
Ambiguous protocol specifier 'icmpv6-r'. Did you mean any of these?
icmpv6-radv
icmpv6-redirect
icmpv6-rsol
Perkembangan sendiri
Fitur paling penting dari spesifikasi protokol adalah daftar bidang. Anda dapat menentukannya untuk protokol Anda sendiri sebagai berikut.
|12:55:16|mikayel@redeye:[~]> protocol «Source:16,Reserved:40,RTT:8» 0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Source | | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+ | Reserved | RTT | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Opsi tambahan memperluas kemampuan pemformatan bagan ASCII. Anda dapat menentukan jumlah bit per baris, mengatur karakter untuk pemisah dan grafik semu. Perintah sebelumnya dengan opsi pseudo-grafik akan memberikan yang berikut ini.
|16:02:05|mikayel@redeye:[~]> protocol «Source:16,Reserved:40,RTT:8?\ numbers=y,startchar=*,endchar=*,evenchar=-,oddchar=-,sepchar=|» 0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 *---------------------------------------------------------------* | Source | | *-------------------------------* *---------------* | Reserved | RTT | *---------------------------------------------------------------*
Protokol + tshark
Informasi lebih lengkap tentang struktur protokol jaringan dapat diperoleh dengan membuka file pcap/pcapng lalu lintas jaringan yang disimpan di tshark . Jika Anda hanya melihat di tshark, Anda tidak dapat melihat hutan untuk pohon, dan bersama-sama dengan Protokol - apa yang Anda butuhkan.
|16:08:05|admin@redeye:[~]> sudo tshark -r /tmp/exmp.pcap -V
Transmission Control Protocol, Src Port: 48378, Dst Port: 443, Seq: 1, Ack: 1, Len: 0
Source Port: 48378
Destination Port: 443
[Stream index: 0]
[TCP Segment Len: 0]
Sequence Number: 1 (relative sequence number)
Sequence Number (raw): 1120003294
[Next Sequence Number: 1 (relative sequence number)]
Acknowledgment Number: 1 (relative ack number)
Acknowledgment number (raw): 4090007166
1000 .... = Header Length: 32 bytes (8)
Flags: 0x010 (ACK)
000. .... .... = Reserved: Not set
...0 .... .... = Nonce: Not set
.... 0... .... = Congestion Window Reduced (CWR): Not set
.... .0.. .... = ECN-Echo: Not set
.... ..0. .... = Urgent: Not set
.... ...1 .... = Acknowledgment: Set
.... .... 0... = Push: Not set
.... .... .0.. = Reset: Not set
.... .... ..0. = Syn: Not set
.... .... ...0 = Fin: Not set
[TCP Flags: ·······A····]
Window: 501
[Calculated window size: 501]
[Window size scaling factor: -1 (unknown)]
Checksum: 0xfbe8 [unverified]
[Checksum Status: Unverified]
Urgent Pointer: 0
Options: (12 bytes), No-Operation (NOP), No-Operation (NOP), Timestamps
TCP Option — No-Operation (NOP)
Kind: No-Operation (1)
TCP Option — No-Operation (NOP)
Kind: No-Operation (1)
TCP Option — Timestamps: TSval 2014817649, TSecr 2606727549
Kind: Time Stamp Option (8)
Length: 10
Timestamp value: 2014817649
Timestamp echo reply: 2606727549
|16:28:51|admin@redeye:[~]> protocol tcp
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Source Port | Destination Port |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Sequence Number |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Acknowledgment Number |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Offset| Res. | Flags | Window |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Checksum | Urgent Pointer |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Options | Padding |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Tentu saja, program seperti Protocol dan tshark tidak dapat dan tidak boleh menggantikan membaca sumber utama, karena e RFC, bagaimanapun, mereka dapat menghemat banyak waktu untuk programmer dan administrator sistem.
Server cloud dari Macleod cepat dan aman.
Daftar menggunakan tautan di atas atau dengan mengklik spanduk dan dapatkan diskon 10% untuk bulan pertama menyewa server dengan konfigurasi apa pun!