We found some domain names associated with infections. Now we have a list of DNS names in the .json file, and I would like to get a generalized result showing: a list of users, the unique domains they visited, the total. Bonus points if I can get a domain name bill.
Here is an example file:
{"machine": "possible_victim01", "domain": "evil.com", "timestamp":1435071870} {"machine": "possible_victim01", "domain": "evil.com", "timestamp":1435071875} {"machine": "possible_victim01", "domain": "soevil.com", "timestamp":1435071877} {"machine": "possible_victim02", "domain": "bad.com", "timestamp":1435071877} {"machine": "possible_victim03", "domain": "soevil.com", "timestamp":1435071879}
Ideally, I would like the result to be something like:
{"possible_victim01": "total": 3, {"evil.com": 2, "soevil.com": 1}} {"possible_victim02": "total": 1, {"bad.com": 1}} {"possible_victim03": "total": 1, {"soevil.com": 1}}
I would gladly agree to:
{"possible_victim01": "total": 3, ["evil.com", "soevil.com"]} {"possible_victim02": "total": 1, ["bad.com"]} {"possible_victim03": "total": 1, ["soevil.com"]}
I can get the total number of entries for each user, but I am losing the list of domains:
cat sample.json | jq -s 'group_by(.machine) | map({machine:.[0].machine,domain:.[0].domain, count:length}) ' [{"machine": "possible_victim01", "domain": "evil.com", "count": 3}, {"machine": "possible_victim02", "domain": "bad.com", "count": 1}, {"machine": "possible_victim03", "domain": "soevil.com", "count": 1}]
This post describes how to solve the second half of the problem ... JQ Aggregations and Crosstabs . I have not found anything that describes the first half, get to:
{"machine": "possible_victim01", "domain": "evil.com", "count":2} {"machine": "possible_victim01", "domain": "soevil.com", "count":1} {"machine": "possible_victim02", "domain": "bad.com", "count":1} {"machine": "possible_victim03", "domain": "soevil.com", "count":1}