]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
dns: add support for sshfp records
authorVictor Julien <victor@inliniac.net>
Wed, 23 Sep 2015 14:34:40 +0000 (16:34 +0200)
committerVictor Julien <victor@inliniac.net>
Fri, 20 May 2016 16:49:46 +0000 (18:49 +0200)
Update parser to process the records.

Update json output to log it.

src/app-layer-dns-common.c
src/app-layer-dns-common.h
src/output-json-dns.c

index 16a2252b4cb9d8ea95bbcd88f122adcab38cf56d..cfb441451bf399d62e2911678102240ca11dd922 100644 (file)
@@ -1005,6 +1005,21 @@ const uint8_t *DNSReponseParse(DNSState *dns_state, const DNSHeader * const dns_
             data += ntohs(head->len);
             break;
         }
+        case DNS_RECORD_TYPE_SSHFP:
+        {
+            /* data here should be:
+             * [1 byte algo][1 byte type][var bytes fingerprint]
+             * As we currently can't store each of those in the state,
+             * we just store the raw data an let the output/detect
+             * code figure out what to do with it. */
+
+            DNSStoreAnswerInState(dns_state, list, fqdn, fqdn_len,
+                    ntohs(head->type), ntohs(head->class), ntohl(head->ttl),
+                    data, ntohs(head->len), ntohs(dns_header->tx_id));
+
+            data += ntohs(head->len);
+            break;
+        }
         default:    /* unsupported record */
         {
             DNSStoreAnswerInState(dns_state, list, NULL, 0,
index a3bdd9351d8b1935090de1902bfdf5987ac54f3a..184fb26408d736cddb63323bac752d1f939c7841 100644 (file)
@@ -92,7 +92,6 @@
 #define DNS_RECORD_TYPE_ANY         255
 #define DNS_RECORD_TYPE_URI         256
 
-
 #define DNS_RCODE_NOERROR       0
 #define DNS_RCODE_FORMERR       1
 #define DNS_RCODE_SERVFAIL      2
index 87b276521bfcc49d581d56d7632f3d736e6fc52b..db8ae40f17d5133bf75b9523335bc3526bc76f9e 100644 (file)
@@ -172,6 +172,34 @@ static void OutputAnswer(LogDnsLogThread *aft, json_t *djs, DNSTransaction *tx,
             } else {
                 json_object_set_new(js, "rdata", json_string(""));
             }
+        } else if (entry->type == DNS_RECORD_TYPE_SSHFP) {
+            if (entry->data_len > 2) {
+                /* get algo and type */
+                uint8_t algo = *ptr;
+                uint8_t fptype = *(ptr+1);
+
+                /* turn fp raw buffer into a nice :-separate hex string */
+                uint16_t fp_len = (entry->data_len - 2);
+                uint8_t *dptr = ptr+2;
+                uint32_t output_len = fp_len * 2 + 1; // create c-string, so add space for 0.
+                char hexstring[output_len], *p = hexstring;
+                memset(hexstring, 0x00, output_len);
+
+                uint16_t x;
+                for (x = 0; x < fp_len; x++, p += 3) {
+                    snprintf(p, 4, x == fp_len - 1 ? "%02x" : "%02x:", dptr[x]);
+                }
+
+                /* wrap the whole thing in it's own structure */
+                json_t *hjs = json_object();
+                if (hjs != NULL) {
+                    json_object_set_new(hjs, "fingerprint", json_string(hexstring));
+                    json_object_set_new(hjs, "algo", json_integer(algo));
+                    json_object_set_new(hjs, "type", json_integer(fptype));
+
+                    json_object_set_new(js, "sshfp", hjs);
+                }
+            }
         }
     }