Tshark http, ftp ve dhcp başlık bilgilerini yakalamak,ayrıştırmak ve analiz etmek
Tshark, komut satırıdan çalışan çok esnek bir network sniffer yazılımıdır.Yerel ağınızdaki trafiği izlemek, kaydetmek ve analiz çalışmaları yapmak için linux,windows ve bsd’lerde çalıştırabileceğiniz ender yazılımlardan biridir.
Bu yazıda anlatılanları, yerel ağın tamamını dinleyebileceğiniz yönetilebilir switch’in monitor portu, hub (kaldı mı artık) veya ağ geçidiniz üzerinde denerseniz, yerel ağınızdaki http, ftp ve dhcp kayıtlarını takip edebilir, analiz ve istatistlik için kayıt altına alabilirsiniz.
Tshark kullanım parameteleri için;
coslat@ubuntucuk:~/Masaüstü/network forensic$ tshark -h
TShark 1.2.2
Dump and analyze network traffic.
See http://www.wireshark.org for more information.Copyright 1998-2009 Gerald Combs <[email protected]> and contributors.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.Usage: tshark [options] …
Capture interface:
-i <interface> name or idx of interface (def: first non-loopback)
-f <capture filter> packet filter in libpcap filter syntax
-s <snaplen> packet snapshot length (def: 65535)
-p don’t capture in promiscuous mode
-y <link type> link layer type (def: first appropriate)
-D print list of interfaces and exit
-L print list of link-layer types of iface and exit
Kullanım parametrelerini ve açıklamalarını örnekler üzerinden inceleyelim, gerekli olanlar;
Tüm isim çözme işlemlerini kapatsın,zaman kaybetmeyelim = -nn
eth0 ağ arabirimini dinlesin = -i eth0
HTTP isteklerini yakalamak istiyorum = -R http.request
TCP 80 ve 3128 portlarından akan trafiği analiz etsin = tcp.port == 3128,http
ARP ve DNS isteklerini yakalamakla, sniffer yorulmasın = no arp and port not 53
coslat@ubuntucuk:~/Masaüstü/network forensic$ sudo tshark -nn -i eth0 not arp and port not 53 -d tcp.port==3128,http -R http.request
[sudo] password for coslat:
Running as user “root” and group “root”. This could be dangerous.
Capturing on eth0
4.092491 192.168.5.205 -> 188.124.8.106 HTTP GET / HTTP/1.1
4.776588 192.168.5.205 -> 188.124.8.106 HTTP GET /wp-content/plugins/dynamic-subpages/dynamic-subpages.css?ver=0.50 HTTP/1.1
4.776611 192.168.5.205 -> 188.124.8.106 HTTP GET /wp-includes/js/jquery/jquery.js?ver=1.4.2 HTTP/1.1
7.932276 192.168.5.205 -> 212.175.15.89 HTTP GET /rds/data.asp?1286798927370 HTTP/1.1
7.935070 192.168.5.205 -> 212.175.15.89 HTTP GET /live/v.asp?1286798927370 HTTP/1.1
^C5 packets captured
“Kaynak IP -> Hedef IP HTTP METHOD İstenilen Sayfa” şeklinde çıktı aldık. HOST kısmı nerede ?
Tshark field’larına bakıp, istediğimiz formatta kayıt üretmesini sağlayabiliriz.
İhtiyacımız olan http fields bilgileri, http://www.wireshark.org/docs/dfref/h/http.html adresinde mevcut.
İstediğimiz HTTP kayıt türü;
Paketin zaman bilgisi = -e frame.time
Kaynak IP adresi = -e ip.src
Kaynak MAC adresi = -e eth.src
Hedef IP adresi = -e ip.dst
Hedef PORT numarası= -e tcp.dstport
HTTP HOST adresi = -e http.host
İstenilen URL= -e http.request.uri
HTTP Method = -e http.request.method
Ve bunların arasına birer boşluk bırakarak yaz = -E separator=’ ‘
coslat@ubuntucuk:~/Masaüstü/network forensic$ sudo tshark -nn -i eth0 not arp and port not 53 -d tcp.port==3128,http -R http.request –
T fields -e frame.time -e ip.src -e eth.src -e ip.dst -e tcp.dstport -e http.host -e http.request.uri -e http.request.method -E separator=’ ‘
Running as user “root” and group “root”. This could be dangerous.
Capturing on eth0
Oct 11, 2010 15:15:14.295646000 192.168.5.205 aa:00:04:00:0a:04 212.175.15.89 80 www.kralfm.com.tr /rds/data.asp?1286799314294 GET
Oct 11, 2010 15:15:14.298198000 192.168.5.205 aa:00:04:00:0a:04 212.175.15.89 80 www.kralfm.com.tr /live/v.asp?1286799314294 GET
Oct 11, 2010 15:15:15.211332000 192.168.5.205 aa:00:04:00:0a:04 188.124.8.106 80 www.cehturkiye.com / GET
Oct 11, 2010 15:15:16.111661000 192.168.5.205 aa:00:04:00:0a:04 188.124.8.106 80 www.cehturkiye.com /wp-content/themes/monochrome/style.css GET
Oct 11, 2010 15:15:16.111690000 192.168.5.205 aa:00:04:00:0a:04 188.124.8.106 80 www.cehturkiye.com /wp-content/themes/monochrome/comment-style.css GET
Oct 11, 2010 15:15:16.117018000 192.168.5.205 aa:00:04:00:0a:04 188.124.8.106 80 www.cehturkiye.com /wp-content/themes/monochrome/width_1100px.css GET
Görüldüğü gibi, tshark istediğimiz formata uygun kayıt üretti. Bunları bir .pcap formatında yazdırmak isterseniz “-w dosyaadı.pcap” parametresini eklemeniz yeterli olur.
Tshark ile FTP Trafiğinin Analiz;
Gerekli olanlar;
Tüm isim çözme işlemlerini kapatsın,zaman kaybetmeyelim = -nn
eth0 ağ arabirimini dinlesin = -i eth0
FTP isteklerini yakalamak istiyorum = -R ftp
ARP ve DNS isteklerini yakalamakla, sniffer yorulmasın = no arp and port not 53
coslat@ubuntucuk:~/Masaüstü/network forensic$ sudo tshark -nn -i eth0 not arp and port not 53 -R ftp
Running as user “root” and group “root”. This could be dangerous.
Capturing on eth0
24.517872 89.19.25.155 -> 192.168.5.205 FTP Response: 220-FileZilla Server version 0.9.24 beta
24.518872 192.168.5.205 -> 89.19.25.155 FTP Request: USER 123test123
24.534616 89.19.25.155 -> 192.168.5.205 FTP Response: 331 Password required for ozanucar.com
24.542414 192.168.5.205 -> 89.19.25.155 FTP Request: PASS testtesttest
24.556472 89.19.25.155 -> 192.168.5.205 FTP Response: 230 Logged on
24.556781 192.168.5.205 -> 89.19.25.155 FTP Request: SYST
24.587262 89.19.25.155 -> 192.168.5.205 FTP Response: 215 UNIX emulated by FileZilla
24.587643 192.168.5.205 -> 89.19.25.155 FTP Request: FEAT
24.604810 89.19.25.155 -> 192.168.5.205 FTP Response: 211-Features:
24.609672 192.168.5.205 -> 89.19.25.155 FTP Request: PWD
24.623543 89.19.25.155 -> 192.168.5.205 FTP Response: 257 “/” is current directory.
24.645130 192.168.5.205 -> 89.19.25.155 FTP Request: TYPE I
24.658481 89.19.25.155 -> 192.168.5.205 FTP Response: 200 Type set to I
24.658689 192.168.5.205 -> 89.19.25.155 FTP Request: PASV
24.673951 89.19.25.155 -> 192.168.5.205 FTP Response: 227 Entering Passive Mode (89,19,25,155,207,107)
24.675724 192.168.5.205 -> 89.19.25.155 FTP Request: MLSD
24.705870 89.19.25.155 -> 192.168.5.205 FTP Response: 150 Connection accepted
24.742915 89.19.25.155 -> 192.168.5.205 FTP Response: 226 Transfer OK
25.995154 192.168.5.205 -> 89.19.25.155 FTP Request: CWD www
26.009518 89.19.25.155 -> 192.168.5.205 FTP Response: 250 CWD successful. “/www” is current directory.
26.009734 192.168.5.205 -> 89.19.25.155 FTP Request: PWD
26.023492 89.19.25.155 -> 192.168.5.205 FTP Response: 257 “/www” is current directory.
26.034783 192.168.5.205 -> 89.19.25.155 FTP Request: PASV
26.050368 89.19.25.155 -> 192.168.5.205 FTP Response: 227 Entering Passive Mode (89,19,25,155,216,88)
26.051748 192.168.5.205 -> 89.19.25.155 FTP Request: MLSD
26.083209 89.19.25.155 -> 192.168.5.205 FTP Response: 150 Connection accepted
26.123210 89.19.25.155 -> 192.168.5.205 FTP Response: 226 Transfer OK
^C27 packets captured
Trafiğin çıktısını şu şekilde istiyorum;
Paketin oluşturma zamanı = -e frame.time
Kaynak IP adresi = -e ip.src
Kaynak MAC adresi = -e eth.src
Kaynak Port numarası = -e tcp.srcport
Hedef IP adresi= -e ip.dst
Hedef Port Numarası= -e tcp.dstport
FTP Komutu -e ftp.request.command -e ftp.request.arg
Yanıt Kodu(başarılı mı değil mi ?) = -e ftp.response.code -e ftp.response.arg
Ve araya bir boşluk bırakarak yaz -E separator=’ ‘
coslat@ubuntucuk:~/Masaüstü/network forensic$ sudo tshark -nn -i eth0 not arp and port not 53 -R ftp -T fields -e frame.time_relative -e ip.src -e eth.src -e
tcp.srcport -e ip.dst -e tcp.dstport -e ftp.request.command -e ftp.request.arg -e ftp.response.code -e ftp.response.arg -E separator=’ ‘
Running as user “root” and group “root”. This could be dangerous.
Capturing on eth0
5.464582000 89.19.25.155 00:11:bb:e0:7b:10 21 192.168.5.205 38023 220 FileZilla Server version 0.9.24 beta
5.464808000 192.168.5.205 aa:00:04:00:0a:04 38023 89.19.25.155 21 USER 123test123
5.478353000 89.19.25.155 00:11:bb:e0:7b:10 21 192.168.5.205 38023 331 Password required for ozanucar.com
5.478738000 192.168.5.205 aa:00:04:00:0a:04 38023 89.19.25.155 21 PASS testtestest
5.491656000 89.19.25.155 00:11:bb:e0:7b:10 21 192.168.5.205 38023 230 Logged on
5.493490000 192.168.5.205 aa:00:04:00:0a:04 38023 89.19.25.155 21 PWD
5.506212000 89.19.25.155 00:11:bb:e0:7b:10 21 192.168.5.205 38023 257 \”/\” is current directory.
29.195757000 89.19.25.155 00:11:bb:e0:7b:10 21 192.168.5.205 38026 220 FileZilla Server version 0.9.24 beta
29.195968000 192.168.5.205 aa:00:04:00:0a:04 38026 89.19.25.155 21 USER ozanucar.com
29.229878000 89.19.25.155 00:11:bb:e0:7b:10 21 192.168.5.205 38026 331 Password required for ozanucar.com
29.230095000 192.168.5.205 aa:00:04:00:0a:04 38026 89.19.25.155 21 PASS 123test
29.244368000 89.19.25.155 00:11:bb:e0:7b:10 21 192.168.5.205 38026 230 Logged on
29.245917000 192.168.5.205 aa:00:04:00:0a:04 38026 89.19.25.155 21 CWD /www
29.259459000 89.19.25.155 00:11:bb:e0:7b:10 21 192.168.5.205 38026 250 CWD successful. \”/www\” is current directory.
29.259827000 192.168.5.205 aa:00:04:00:0a:04 38026 89.19.25.155 21 PWD
29.272723000 89.19.25.155 00:11:bb:e0:7b:10 21 192.168.5.205 38026 257 \”/www\” is current directory.
29.273288000 192.168.5.205 aa:00:04:00:0a:04 38026 89.19.25.155 21 TYPE I
29.286747000 89.19.25.155 00:11:bb:e0:7b:10 21 192.168.5.205 38026 200 Type set to I
29.287069000 192.168.5.205 aa:00:04:00:0a:04 38026 89.19.25.155 21 PASV
29.302256000 89.19.25.155 00:11:bb:e0:7b:10 21 192.168.5.205 38026 227 Entering Passive Mode (89,19,25,155,250,228)
29.303553000 192.168.5.205 aa:00:04:00:0a:04 38026 89.19.25.155 21 RETR fw.jpg
29.330897000 89.19.25.155 00:11:bb:e0:7b:10 21 192.168.5.205 38026 150 Connection accepted
30.566250000 89.19.25.155 00:11:bb:e0:7b:10 21 192.168.5.205 38026 226 Transfer OK
^C23 packets captured
ozanucar.com sunucusuna bağlanılıp “www” dizininden “fw.jpg” dosyası istenmiş ve dosya transferi başarılı olmuş : ))
DHCP Trafiğinin izlenmesi,
Yukarıdaki iki güzel örneği geniş anlatımlı yaptıkdan sonra DHCP fields paremetreleri için şu adrese http://www.wireshark.org/docs/dfref/d/dhcpfo.html bakabilirsiniz.
tshark -i eth0 port not 53 -R bootp -T fields -e bootp.ip.client -e bootp.hw.mac_addr -e bootp.ip.your
tshark-http-ftp-dhcp.sh scriptini yazdım, tüm bu işlemleri sizin yerinize itina ile yapar 🙂
“root” yetkileri ile çalıştırmanız gerekli !
# ./tshark-http-ftp-dhcp.sh
Kullanimi: {ag arayuzu http|ftp|dhcp}
# ./tshark-http-ftp-dhcp.sh eth0 http ftp dhcp
Running as user “root” and group “root”. This could be dangerous.
Capturing on eth0
4.032617000 192.168.5.205 aa:00:04:00:0a:04 174.120.208.67 80 freeos.com /guides/lsst/scripts/q1 GET
gibi gibi.