2016年11月23日 星期三

libpcap - Dump TCP segment and UDP datagram(11)



  • Source Port:2 bytes。
  • Destination Port:2 bytes。
  • Sequence Number:4 bytes。
  • Acknowledgement Number:4 bytes。
  • Header Length:4 bits。
  • Reserved:4 bits。
  • Flags:8 bits。
  • Window Size:2 bytes。
  • Checksum:2 bytes。
  • Urgent Pointer:2 bytes。
  • TCP Option + Padding:0 ~ 40 bytes。
  • 長度:20 ~ 60 bytes。

Flags由左到右分別為:CWR、ECE、URG、ACK、PUSH、RST、SYN以及FIN,共8個bit。



  • Source Port:2 bytes。
  • Destination Port:2 bytes。
  • Length:2 bytes。
  • Checksum:2 bytes。
  • 長度:8 bytes。


2016年11月18日 星期五

libpcap - Dump IP packet(10)



  • Version:4 bits。
  • Header Length:4 bits。
  • Type of Service:1 byte。
  • Total Length:2 bytes。
  • Identification:2 bytes。
  • Flags:3 bits。
  • Fragment Offset:13 bits。
  • Time to Live:1 byte。
  • Protocol:1 byte。
  • Header Checksum:2 bytes。
  • Source IP Address:4 bytes。
  • Destination IP Address:4 bytes。
  • IP Option + Padding:0 ~ 40 bytes。
  • 長度:20 ~ 60 bytes。

2016年11月17日 星期四

CentOS 7 建立 service unit file


在Linux/Unix系統上,背景執行的程式叫做daemon,在CentOS上可以透過指令systemctl或指令chkconfig讓除了在背景執行外,也可以開機時自動執行。

像是:

[root@localhost ~]# systemctl start network.service  # 啟動network.service
[root@localhost ~]# systemctl enable network.service # 設定開機自動執行


2016年11月9日 星期三

libpcap - Dump ARP frame(9)



  • Hardware Type:2 bytes。
  • Protocol Type:2 bytes。
  • Hardware Length:1 byte。
  • Protocol Length:1 byte。
  • Operation Code:2 bytes。
  • Sender Hardware Address:硬體地址長度 bytes。
  • Sender Protocol Address:協定地址長度 bytes。
  • Target Hardware Address:硬體地址長度 bytes。
  • Target Protocol Address:協定地址長度 bytes。
  • 長度:8 + 硬體地址長度×2 + 協定地址長度×2 bytes。


2016年11月8日 星期二

libpcap - Dump Ethernet frame(8)


封包解析要從最底層解析上去,先從乙太網路的Ethernet frame開始。


  • Destination MAC Address:6 bytes。
  • Source MAC Address:6 bytes。
  • Type:2 bytes。
  • 長度:14 bytes。

2016年11月5日 星期六

libpcap - Save frames to file(6)


libpcap能夠將封包儲存成檔案,可以之後用Wireshark或其他工具再打開。


libpcap - Capture using pcap_next_ex(5)


libpcap除了提供callback方式抓封包,也提供一般呼叫函數的方式一次抓一個封包,函數pcap_next_ex()是函數pcap_next()改良版,函數pcap_next()基本上已經棄用了,所以只講函數pcap_next_ex()



2016年11月4日 星期五

libpcap - Capture using pcap_loop and pcap_dispatch(4)


那麼就來教libpcap主要用途:抓封包,libpcap提供了四個函數抓封包:


  1. pcap_loop()
  2. pcap_dispatch()
  3. pcap_next()(最好別用)
  4. pcap_next_ex()

libpcap - Default device(3)


抓封包的時候必須指定device,如果不確定要選擇哪個device,libpcap提供了可以傳回預設的device。


CentOS 7 安裝 Open vSwitch


之前在CentOS 6上安裝Open vSwitch(OVS)一直失敗,這次要在CentOS 7上安裝。

CentOS 7 安裝 VNC server


最近工作需要做一些遠端管理,除了ssh以外還需要能夠遠端桌面的環境,在CentOS上可以用VNC(Virtual Network Computing)方式登入,Centos 6和7的安裝方式不太一樣,所以來記錄一下。


2016年11月3日 星期四

libpcap - List devices(2)


libpcap可以列出所有網卡deivce、地址資訊。

先看一下自己主機上有哪些device:
~ % ifconfig -l
lo0 gif0 stf0 en0 en1 en2 p2p0 awdl0 bridge0
目前可用的網卡有這些,不同系統上有不同的名稱,以Ethernet來說:Mac OS X是en*,Linux是eth*,而Windows是\Device\NPF_{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}

libpcap - Installation(1)


libpcap是網路世界中抓取封包最重要的Library之一,Wireshark、tcpdump或是著名的入侵偵測系統(IDS)Snort都是透過libpcap完成的,各個系統都可以使用libpcap(Windows使用Winpcap,差不多的東西)。