I'm trying to attribute network traffic in a tshark dump with the logged in user that the respective traffic is associated with.
I'm running an Ubuntu server on a corporate network in which users log into either via RDP or SSH with x-forwarding. My application is written in bash and uses tshark to log all network traffic using the following command:
tshark -b filesize:1024 -w traffic.pcap
I then have a while loop that runs on a chron job to parse through the pcap files, extract the fields I want, and save them to json:
for f in *.pcap
do
tshark -r $f -T json > $f.json
cat $f.json | jq .[]._source.layers | jq -r '.frame_time_epoch[],.frame_number[],.tcp_stream[],.ip_src[],.tcp_srcport[],.ip_dst[],.tcp_dstport[],.frame_len[],.frame_protocols[],.http_host[],.http_request_uri[],.http_request_method[],.http_user_agent[],.http_referer[],.dns_qry_name[],.dns_resp_name[],.ssl_handshake_extensions_server_name[],.x509sat_uTF8String[],.x509ce_dNSName,"END"' > injest.json
done
The output json which looks like the following is then sent to an Elasticsearch cluster I have set up:
{
"layers": {
"frame.time_epoch": ["1579755811.545369005"],
"frame.number": ["3508"],
"tcp.stream": ["0"],
"ip.src": ["10.0.10.10"],
"tcp.srcport": ["22"],
"ip.dst": ["1.1.1.1"],
"tcp.dstport": ["54116"],
"frame.len": ["102"],
"frame.protocols": ["eth:ethertype:ip:tcp:ssh"]
}
}
I'd like to know if there is anyway I can have the Linux username added to the packet capture or as an additional field in the final json before it is sent to ELK.
In other words if 'user_a' and 'user_b' are both logged into the server I'd like their respective internet traffic to log there usernames. Is this at all possible with tshark? I've read that iptables can "tag" traffic but I'm not sure exactly how it works and if it would accomplish what I'm trying to do.