This guide consists of two segmenets.
- Making DNS dashboard as a means of monitoring for peculiar DNS tunnels or C2 traffic.
- Using Sigma rules to detect malware.
- Go to the Opensearch Dashboards web interface.
- Click on the "Visualize" tab in the left top area.
- Click on "Create visualization".
- Select "Data table" as the visualization type.
- Select the index pattern (logstash*) and click "Next step".
- Select "Split rows" and then "Aggregation" as "Terms".
- Select "Field" as
dest_ip
and click "Apply". - Increase the "Size" to 1000 to show all the destination IPs.
- Set filters to
event_type.keyword:dns
anddns.type.keyword:query
. - Save the visualization as "Data Table - Destination DNS Servers".
- Go to the Opensearch Dashboards web interface.
- Click on the "Visualize" tab in the left top area.
- Click on "Create visualization".
- Select "Tag cloud" as the visualization type.
- Select the index pattern (logstash*) and click "Next step".
- Select "Aggregation" as "Terms".
- Select "Field" as
src_ip.keyword
and click "Apply". - Increase the "Size" to 20 to show the top 20 source IPs.
- Set filters to
event_type.keyword:dns
anddns.type.keyword:query
. - Save the visualization as "Tag Cloud - Source IP DNS Queries".
- Go to the Opensearch Dashboards web interface.
- Click on the "Visualize" tab in the left top area.
- Click on "Create visualization".
- Select "Pie" as the visualization type.
- Select the index pattern (logstash*) and click "Next step".
- Select "Split slices" and then "Aggregation" as "Terms".
- Select "Field" as
dns.rcode.keyword
and click "Apply". - Set filters to
event_type.keyword:dns
anddns.type.keyword:answer
. - Save the visualization as "Pie - DNS Query Response Types".
- Go to the Opensearch Dashboards web interface.
- Click on the "Visualize" tab in the left top area.
- Click on "Create visualization".
- Select "Timeline" as the visualization type.
- Then on the right hand side, type the following:
.es(index=logstash-*, q='event_type:dns AND dns.rcode:NXDOMAIN').title('NXDOMAIN Instances')
- Save the visualization as "Timeline - NXDOMAIN Responses".
- Go to the Opensearch Dashboards web interface.
- Click on the "Visualize" tab in the left top area.
- Click on "Create visualization".
- Select "Timeline" as the visualization type.
- Then on the right hand side, type the following:
.es(index=logstash*, q='event_type:DNS AND dns.type=query', metric=count, timefield=@timestamp, offset=-1w).label('Last Week DNS Queries').color(orange),
.es(index=logstash*, q='event_type:DNS AND dns.type=query', metric=count, timefield=@timestamp).label('This Week DNS Queries').color(green)
- Save the visualization as "Timeline - DNS Queries Week to Week".
- Go to the Opensearch Dashboards web interface.
- Click on the "Discover" tab in the left top area.
- Select the following fields from the left hand side and add them:
dns.rrname
dns.rrtype
dns.answers.rrname
dns.answers.rrtype
- Add filters for
event_type.keyword:dns
anddns.type.keyword:answer
. - Save the search as "DNS Queries Discover".
- Go to the Opensearch Dashboards web interface.
- Click on the "Visualize" tab in the left top area.
- Click on "Create visualization".
- Select "Coordinate Map" as the visualization type.
- Select the index pattern (logstash*) and click "Next step".
- Select "Geohash" as the aggregation and then "Field" as
geoip.geohash
. - Add a filter for
event_type.keyword:dns
anddns.type.keyword:query
. - Save the visualization as "Coordinate Map - DNS Geo Map".
You'll need scripted fields for this.
- Go to the Opensearch Dashboards web interface.
- Click on the "Dashboards Management" tab in the left top area.
- Click on "Index Patterns".
- Click on the index pattern you're using (logstash*).
- Click on the "Scripted fields" tab.
- Click on "Add scripted field".
- Name the field "dns_rrname_shannon_entropy" and scroll all the way down to "Script" and type the following:
if (!doc.containsKey('dns.rrname.keyword') || doc['dns.rrname.keyword'].empty) {
return null;
}
String rrname = doc['dns.rrname.keyword'].value;
int[] counts = new int[256]; // Assuming ASCII characters
for (int i = 0; i < rrname.length(); i++) {
int charValue = (int) rrname.charAt(i);
counts[charValue]++;
}
double entropy = 0;
int rrnameLength = rrname.length();
for (int count : counts) {
if (count != 0) {
double p = (double) count / rrnameLength;
entropy -= p * Math.log(p) / Math.log(2);
}
}
return entropy;
- Set "Type" as "Number" and click on "Create field".
- Go to the Opensearch Dashboards web interface.
- Click on the "Visualize" tab in the left top area.
- Click on "Create visualization".
- Select "Data table" as the visualization type.
- Select the index pattern (logstash*) and click "Next step".
- Select "Split rows" and then "Aggregation" as "Terms".
- Select "Field" as
dns.rrname.keyword
and click "Apply". - Increase the "Size" to 1000 to show all the DNS queries.
- Add a filter for
event_type.keyword:dns
anddns.type.keyword:query
. - Set "Metric" as "Max" and then "Field" as
dns_rrname_shannon_entropy
. - Save the visualization as "Data Table - High Entropy DNS Queries".
- Go to the Opensearch Dashboards web interface.
- Click on the "Visualize" tab in the left top area.
- Click on "Create visualization".
- Select "Data table" as the visualization type.
- Select the index pattern (logstash*) and click "Next step".
- Select "Split rows" and then "Aggregation" as "Terms".
- Select "Field" as
dns.rrname.keyword
and click "Apply". - Increase the "Size" to 50 to show all the DNS queries.
- Add a filter for
event_type.keyword:dns
anddns.type.keyword:query
. - Save the visualization as "Data Table - Rare Domain Names".
You can create a dashboard and add all these visualizations to it. This will give you a comprehensive view of your DNS traffic.
- Go to the Opensearch Dashboards web interface.
- Click on the "Dashboard" tab in the left top area.
- Click on "Create dashboard".
- Click on "Add" and select the visualizations you've created.
- Save the dashboard.
Here's how it look like:
Visit the Sigma repository Sigma Repository. There are several rules that may or may not apply to your network or context (e.g., compliance is typically for organizations). You can browse through them and evaluate which ones you'd like to use. Keep an eye out for rules with network traffic. Some involve operating system logs that the book's setup does not collect. You'll need a Host IDS (HIDS) for that.
Let's look at a rule for Telegram traffic: Telegram Traffic
Hit the download icon ("download raw file") to download the yml file. Also have a look at the rule itself. It's a simple rule that looks for DNS queries to Telegram's API. Good news! You have DNS data available from your IDS. You can use this rule to detect Telegram traffic on your network.
- Go to the Opensearch Dashboards web interface.
- Click on the "Security Analytics" tab in the left top area.
- Click on "Detection rules".
- Click on "Import detection rule".
- Click on "Select a file" and select the Sigma rule you downloaded.
- Click on "Import".
- You'll see a visual editor to evaluate the rule. If there are any errors (meaning Dashboards cannot find your corresponding data), here's where you can fix them.
- Key points to keep an eye out for:
- "Rule Status" is set for default as "test". You can change it to "stable" when you're ready.
- Then click on "Create detection rule".
Detection rules also contains a bunch of pre-built rules that you can use. For example, you can also use the search bar to search for "Wannacry Killswitch Domain" and you'll find a rule that detects the presense of Wannacry domain requests.
- Go to the Opensearch Dashboards web interface.
- Click on the "Index Management" tab in the left top area.
- Click on "Aliases".
- Click "Create Alias".
- Type "logstash-*" in the "Index pattern" field.
- Type "logstash" in the "Alias" field.
- Click "Create index alias".
- In "Security Analytics" click on "Detectors".
- Click on "Create detector".
- Type "Threat Huntin" in the "Name" and feel free to write a description for it.
- For "Data Source" type "logstash" (the alias) and hit enter.
- "Log type" is "DNS". Different rules are listed under a different log type and you need to make a separate detector for each.
- In "Selected detection rules", expand it and use the slide bar next to the "Rule name" to disable them all. Then search and enable only the two rules from above.
- Underneath, at "Field Mapping", map the Available fields that are found from the rules to your data fields.
dns.question.name
todns.query.rrname
timestamp
to@timestamp
- Set the detector schedule on how frequently you want it to run.
- Click "Next"
- Leave everything as default in the "Trigger" section.
- Click "Create detector".
Now if you click on "Overview" under "Security Analytics" you'll see the detector at the bottom. You should see no alerts but if you want to verify that everything works, open your browser and navigate to api.telegram.org
. Then in about a minute you should see alerts generated in the "Overview" panel. Here's how it looks:
You can click on the findings ("View all findings") on the right hand side to see the details of the alert. Then click in any alert and you should see additional information about it including the json record that triggered it. Here it is:
Feel free to ignore in_i_face since that is the network interface of your IDS, not of the machine that did the query to telegraph (through the browser in this case). The rest of the information should be valid though to the time you queried and from the computer that you did.
Since we are working on setting up a threat hunting environment, it would be useful to have also threat intelligence.
- Go to the Opensearch Dashboards web interface.
- Click on the "Security Analytics" tab in the left top area.
- Click on "Threat Intelligence".
- You should see an alienvault source reputation rule set there but if not you could manually add it.
- Click on "Add threat intel source".
- Give it a name and description.
- Type is "remote data store location".
- In the "Specify a directory or file" type
https://reputation.alienvault.com/reputation.generic
. - Select IPv4-Address from the "Types of malicious indicators" and click "Add threat intel source".
Then you need to configure a periodic scanner on your data.
- Click "Configure scan".
- Select any alias you have (logstash) and click "Next". This will select the alias not the index.
- In the fields to scan, select IPv4-Address and click "Add fields" and add
src_ip
anddest_ip
. - Set the scan for every minute and hit "Next".
- Click "Save and start monitoring".