From 6a099f0813117494568d04beb01e4463221a09d3 Mon Sep 17 00:00:00 2001 From: h345983745 Date: Wed, 6 Feb 2019 20:20:20 +0000 Subject: [PATCH 1/7] Inital Commit --- src/core/operations/DNSOverHTTPS.mjs | 93 ++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 src/core/operations/DNSOverHTTPS.mjs diff --git a/src/core/operations/DNSOverHTTPS.mjs b/src/core/operations/DNSOverHTTPS.mjs new file mode 100644 index 00000000..70b779f1 --- /dev/null +++ b/src/core/operations/DNSOverHTTPS.mjs @@ -0,0 +1,93 @@ +/** + * @author h345983745 [] + * @copyright Crown Copyright 2019 + * @license Apache-2.0 + */ +import jpath from "jsonpath"; +import Operation from "../Operation"; +import OperationError from "../errors/OperationError"; + +/** + * HTTPS Over DNS operation + */ +class HTTPSOverDNS extends Operation { + + /** + * HTTPSOverDNS constructor + */ + constructor() { + super(); + + this.name = "DNS Over HTTPS"; + this.module = "Code"; + this.description = "Calls out to HTTPS Over DNS Resolvers"; + this.infoURL = "https://en.wikipedia.org/wiki/DNS_over_HTTPS"; + this.inputType = "string"; + this.outputType = "JSON"; + this.args = [ + { + name: "Resolver", + type: "editableOption", + value: [ + { + name: "Google", + value: "https://dns.google.com/resolve" + }, + { + name: "Cloudflare", + value: "https://cloudflare-dns.com/dns-query" + } + ] + }, + { + name: "Request Type", + type: "option", + value: [ + "A", + "AAAA", + "TXT", + "MX" + ] + }, + { + name: "Show Just Answer Data", + type: "boolean", + value: false + }, + { + name: "Validate DNSSEC", + type: "boolean", + value: true + } + ]; + } + + /** + * @param {string} input + * @param {Object[]} args + * @returns {JSON} + */ + run(input, args) { + const [resolver, requestType, justAnswer, DNSSEC] = args; + + var url = new URL(resolver); + var params = {name:input, type:requestType, cd:DNSSEC}; + + url.search = new URLSearchParams(params) + + console.log(url.toString()) + + return fetch(url, {headers:{'accept': 'application/dns-json'}}).then(response => {return response.json()}) + .then(data => { + if(justAnswer){ + return jpath.query(data, "$.Answer[*].data") + } + return data; + + }).catch(e => {throw new OperationError("Error making request to " + url + e.toString())}) + + } + +} + +export default HTTPSOverDNS; From d42075072b9a1ed192ee344d09fac6c02068da7c Mon Sep 17 00:00:00 2001 From: h345983745 Date: Wed, 6 Feb 2019 20:54:06 +0000 Subject: [PATCH 2/7] Small Updates --- src/core/operations/DNSOverHTTPS.mjs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/core/operations/DNSOverHTTPS.mjs b/src/core/operations/DNSOverHTTPS.mjs index 70b779f1..f2c7203a 100644 --- a/src/core/operations/DNSOverHTTPS.mjs +++ b/src/core/operations/DNSOverHTTPS.mjs @@ -24,6 +24,7 @@ class HTTPSOverDNS extends Operation { this.infoURL = "https://en.wikipedia.org/wiki/DNS_over_HTTPS"; this.inputType = "string"; this.outputType = "JSON"; + this.manualBake = true; this.args = [ { name: "Resolver", @@ -69,13 +70,16 @@ class HTTPSOverDNS extends Operation { */ run(input, args) { const [resolver, requestType, justAnswer, DNSSEC] = args; - - var url = new URL(resolver); + try{ + var url = new URL(resolver); + } catch (error) { + throw new OperationError(error.toString() + + "\n\nThis error could be caused by one of the following:\n" + + " - An invalid Resolver URL\n" ) + } var params = {name:input, type:requestType, cd:DNSSEC}; - url.search = new URLSearchParams(params) - console.log(url.toString()) return fetch(url, {headers:{'accept': 'application/dns-json'}}).then(response => {return response.json()}) .then(data => { @@ -84,7 +88,7 @@ class HTTPSOverDNS extends Operation { } return data; - }).catch(e => {throw new OperationError("Error making request to " + url + e.toString())}) + }).catch(e => {throw new OperationError("Error making request to :" + url + e.toString())}) } From 3e9c75f7350b2fcda481fc05d1c61416a42c96b9 Mon Sep 17 00:00:00 2001 From: h345983745 Date: Wed, 6 Feb 2019 22:34:43 +0000 Subject: [PATCH 3/7] Added to Categories --- src/core/config/Categories.json | 1 + src/core/operations/DNSOverHTTPS.mjs | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/core/config/Categories.json b/src/core/config/Categories.json index 3da6a5e0..8235ab10 100755 --- a/src/core/config/Categories.json +++ b/src/core/config/Categories.json @@ -155,6 +155,7 @@ "name": "Networking", "ops": [ "HTTP request", + "DNS over HTTPS", "Strip HTTP headers", "Dechunk HTTP response", "Parse User Agent", diff --git a/src/core/operations/DNSOverHTTPS.mjs b/src/core/operations/DNSOverHTTPS.mjs index f2c7203a..e0884430 100644 --- a/src/core/operations/DNSOverHTTPS.mjs +++ b/src/core/operations/DNSOverHTTPS.mjs @@ -18,9 +18,13 @@ class HTTPSOverDNS extends Operation { constructor() { super(); - this.name = "DNS Over HTTPS"; + this.name = "DNS over HTTPS"; this.module = "Code"; - this.description = "Calls out to HTTPS Over DNS Resolvers"; + this.description = ["Takes a single domain name and performs a DNS lookup using DNS vver HTTPS.", + "

", + "By default, Cloudflare and Google DNS over HTTPS services are supported.", + "

", + "Can be used with any service that supports the GET paramaters name and type."].join('\n'); this.infoURL = "https://en.wikipedia.org/wiki/DNS_over_HTTPS"; this.inputType = "string"; this.outputType = "JSON"; From 105090db60f2c6e83585691b0d0d2019b47052db Mon Sep 17 00:00:00 2001 From: h345983745 Date: Wed, 6 Feb 2019 22:50:46 +0000 Subject: [PATCH 4/7] Spelling Check --- src/core/operations/DNSOverHTTPS.mjs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/core/operations/DNSOverHTTPS.mjs b/src/core/operations/DNSOverHTTPS.mjs index e0884430..06519f48 100644 --- a/src/core/operations/DNSOverHTTPS.mjs +++ b/src/core/operations/DNSOverHTTPS.mjs @@ -20,11 +20,11 @@ class HTTPSOverDNS extends Operation { this.name = "DNS over HTTPS"; this.module = "Code"; - this.description = ["Takes a single domain name and performs a DNS lookup using DNS vver HTTPS.", + this.description = ["Takes a single domain name and performs a DNS lookup using DNS over HTTPS.", "

", "By default, Cloudflare and Google DNS over HTTPS services are supported.", "

", - "Can be used with any service that supports the GET paramaters name and type."].join('\n'); + "Can be used with any service that supports the GET parameters name and type."].join('\n'); this.infoURL = "https://en.wikipedia.org/wiki/DNS_over_HTTPS"; this.inputType = "string"; this.outputType = "JSON"; @@ -55,7 +55,7 @@ class HTTPSOverDNS extends Operation { ] }, { - name: "Show Just Answer Data", + name: "Answer Data Only", type: "boolean", value: false }, @@ -92,7 +92,8 @@ class HTTPSOverDNS extends Operation { } return data; - }).catch(e => {throw new OperationError("Error making request to :" + url + e.toString())}) + }).catch(e => {throw new OperationError("Error making request to : " + url + "\n" + + "Error Message: " + e.toString())}) } From 0d0a6342553091bc490f787a2dcf19c9c41468cf Mon Sep 17 00:00:00 2001 From: h345983745 Date: Wed, 6 Feb 2019 23:27:27 +0000 Subject: [PATCH 5/7] Added More Request Types --- src/core/operations/DNSOverHTTPS.mjs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/core/operations/DNSOverHTTPS.mjs b/src/core/operations/DNSOverHTTPS.mjs index 06519f48..2a4769ee 100644 --- a/src/core/operations/DNSOverHTTPS.mjs +++ b/src/core/operations/DNSOverHTTPS.mjs @@ -51,7 +51,9 @@ class HTTPSOverDNS extends Operation { "A", "AAAA", "TXT", - "MX" + "MX", + "DNSKEY", + "NS" ] }, { @@ -82,6 +84,7 @@ class HTTPSOverDNS extends Operation { " - An invalid Resolver URL\n" ) } var params = {name:input, type:requestType, cd:DNSSEC}; + url.search = new URLSearchParams(params) From 613cbaa556f98f17391805d7b8e3d29dec8408e3 Mon Sep 17 00:00:00 2001 From: h345983745 Date: Thu, 7 Feb 2019 08:28:23 +0000 Subject: [PATCH 6/7] Fixing Formating Issues --- src/core/operations/DNSOverHTTPS.mjs | 42 +++++++++++++++------------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/src/core/operations/DNSOverHTTPS.mjs b/src/core/operations/DNSOverHTTPS.mjs index 2a4769ee..178c0653 100644 --- a/src/core/operations/DNSOverHTTPS.mjs +++ b/src/core/operations/DNSOverHTTPS.mjs @@ -21,10 +21,10 @@ class HTTPSOverDNS extends Operation { this.name = "DNS over HTTPS"; this.module = "Code"; this.description = ["Takes a single domain name and performs a DNS lookup using DNS over HTTPS.", - "

", - "By default, Cloudflare and Google DNS over HTTPS services are supported.", - "

", - "Can be used with any service that supports the GET parameters name and type."].join('\n'); + "

", + "By default, Cloudflare and Google DNS over HTTPS services are supported.", + "

", + "Can be used with any service that supports the GET parameters name and type."].join("\n"); this.infoURL = "https://en.wikipedia.org/wiki/DNS_over_HTTPS"; this.inputType = "string"; this.outputType = "JSON"; @@ -76,27 +76,31 @@ class HTTPSOverDNS extends Operation { */ run(input, args) { const [resolver, requestType, justAnswer, DNSSEC] = args; - try{ - var url = new URL(resolver); + let url = URL; + try { + url = new URL(resolver); } catch (error) { - throw new OperationError(error.toString() + + throw new OperationError(error.toString() + "\n\nThis error could be caused by one of the following:\n" + - " - An invalid Resolver URL\n" ) + " - An invalid Resolver URL\n"); } - var params = {name:input, type:requestType, cd:DNSSEC}; + const params = {name: input, type: requestType, cd: DNSSEC}; - url.search = new URLSearchParams(params) + url.search = new URLSearchParams(params); - - return fetch(url, {headers:{'accept': 'application/dns-json'}}).then(response => {return response.json()}) - .then(data => { - if(justAnswer){ - return jpath.query(data, "$.Answer[*].data") - } - return data; + return fetch(url, {headers: {"accept": "application/dns-json"}}).then(response => { + return response.json(); + }) + .then(data => { + if (justAnswer) { + return jpath.query(data, "$.Answer[*].data"); + } + return data; - }).catch(e => {throw new OperationError("Error making request to : " + url + "\n" + - "Error Message: " + e.toString())}) + }).catch(e => { + throw new OperationError("Error making request to : " + url + "\n" + + "Error Message: " + e.toString()); + }); } From 75a58f465c18efc67a266cb34cfe89e598c6ec47 Mon Sep 17 00:00:00 2001 From: h345983745 Date: Thu, 7 Feb 2019 21:05:07 +0000 Subject: [PATCH 7/7] Removed jpath import --- src/core/operations/DNSOverHTTPS.mjs | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/src/core/operations/DNSOverHTTPS.mjs b/src/core/operations/DNSOverHTTPS.mjs index 178c0653..2cac79bf 100644 --- a/src/core/operations/DNSOverHTTPS.mjs +++ b/src/core/operations/DNSOverHTTPS.mjs @@ -3,7 +3,6 @@ * @copyright Crown Copyright 2019 * @license Apache-2.0 */ -import jpath from "jsonpath"; import Operation from "../Operation"; import OperationError from "../errors/OperationError"; @@ -19,7 +18,7 @@ class HTTPSOverDNS extends Operation { super(); this.name = "DNS over HTTPS"; - this.module = "Code"; + this.module = "Default"; this.description = ["Takes a single domain name and performs a DNS lookup using DNS over HTTPS.", "

", "By default, Cloudflare and Google DNS over HTTPS services are supported.", @@ -93,7 +92,7 @@ class HTTPSOverDNS extends Operation { }) .then(data => { if (justAnswer) { - return jpath.query(data, "$.Answer[*].data"); + return this.extractData(data.Answer); } return data; @@ -104,6 +103,25 @@ class HTTPSOverDNS extends Operation { } + + /** + * Construct an array of just data from a DNS Answer section + * @private + * @param {JSON} data + * @returns {JSON} + */ + extractData(data) { + if (typeof(data) == "undefined"){ + return []; + } else { + const dataValues = []; + data.forEach(element => { + dataValues.push(element.data); + }); + return dataValues; + + } + } } export default HTTPSOverDNS;