Working With Trafic
#Capturing Trafic with tcpdump
# Capturing Trafic on Interface
ifconfig -a # Gen Interface to capture
# capture udp trafic on specific network and save it to udp_capture
sudo tcpdump -i <iface> -s 0 -nn udp and net 192.168.0.0/24 -w udp_capture.pcap
#Capture TLS trafic
# sync_tls_keylog_client.py
import socket, ssl
HOST = "server.example.com" # або IP
PORT = 61238
KEYLOG = "/tmp/sslkeys.log" # файл для Wireshark
def run_once(host, port, keylog_file):
# Створюємо SSLContext і вказуємо файл для логування ключів
ctx = ssl.create_default_context()
ctx.keylog_filename = keylog_file # Python 3.8+
with socket.create_connection((host, port)) as sock:
with ctx.wrap_socket(sock, server_hostname=host) as ssock:
print("TLS version:", ssock.version())
try:
ssock.sendall(b"GET / HTTP/1.1\r\nHost: %b\r\nConnection: close\r\n\r\n" % host.encode())
data = ssock.recv(4096)
print("First chunk:", data[:200])
except Exception as e:
print("I/O error (maybe server uses custom binary protocol):", e)
if __name__ == "__main__":
run_once(HOST, PORT, KEYLOG)
print("Keylog written to", KEYLOG)
# Save Kys
export SSLKEYLOGFILE=/tmp/sslkeys.log
firefox "https://192.168.0.100:61238"
# pcap with rotation
sudo tcpdump -i en0 -s 0 -nn 'tcp port 61238 and host 192.168.0.100' -W 10 -w /tmp/tls_capture.pcap
# Install tshark first
brew isntall wireshark
# checking for handshake
tshark -o tls.keylog_file:./sslkeys.log -r Final_usleep.pcap -Y "tls.handshake.type==1" -V
# finsing stream number.
tshark -o tls.keylog_file:./sslkeys.log -r Final_usleep.pcap -T fields -e tcp.stream -e ip.src -e ip.dst -e tcp.srcport -e tcp.dstport | sort | uniq -c
tshark -o tls.keylog_file:./key3.tls -r tls.pcap -Y tls
# info about ceritficates
tshark -o tls.keylog_file:./key3.tls -r tls.pcap -Y tls -V
# Show conversations (who talked to whom) — TCP/IP/UDP
tshark -r capture.pcap -q -z conv,ip
tshark -r capture.pcap -q -z conv,tcp
tshark -r capture.pcap -q -z conv,udp
# Endpoints / top talkers
tshark -r capture.pcap -q -z endpoints,ip
#Viewing Trafic with Wireshark
#Display Filter Operators
| Operation |
Operator |
Operation |
Operator |
| Equal to |
== or eq |
Not equal to |
!= or ne |
| Greater than |
> or gt |
Less than |
< or lt |
| Greater than/Equal to |
>= or ge |
Less than / Equal to |
<= or le |
| Logical AND |
and or && |
Logical OR |
or or || |
| Logical NOT |
not or ! |
|
|
#Examples of Filters
# Destination Port 5000
udp.dstport==5000
# Eny Port (Destination or Source)
udp.port==5000
tshark -r udp_capture.pcap -Y "udp && (ip.src==192.168.0.100 || ip.dst==192.168.0.113)" | tail
47036 990.104060 192.168.0.100 → 192.168.0.1 DNS 79 Standard query 0xa7b9 AAAA foobar.domain.com
47040 990.218790 192.168.0.100 → 192.168.0.113 UDP 68 1222 → 5656 Len=26