CyberChef/src/core/operations/DNSOverHTTPS.mjs

103 lines
3.1 KiB
JavaScript
Raw Normal View History

2019-02-06 21:20:20 +01:00
/**
* @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();
2019-02-06 23:34:43 +01:00
this.name = "DNS over HTTPS";
2019-02-06 21:20:20 +01:00
this.module = "Code";
2019-02-06 23:50:46 +01:00
this.description = ["Takes a single domain name and performs a DNS lookup using DNS over HTTPS.",
2019-02-06 23:34:43 +01:00
"<br><br>",
"By default, <a href='https://developers.cloudflare.com/1.1.1.1/dns-over-https/'>Cloudflare</a> and <a href='https://developers.google.com/speed/public-dns/docs/dns-over-https'>Google</a> DNS over HTTPS services are supported.",
"<br><br>",
2019-02-06 23:50:46 +01:00
"Can be used with any service that supports the GET parameters <code>name</code> and <code>type</code>."].join('\n');
2019-02-06 21:20:20 +01:00
this.infoURL = "https://en.wikipedia.org/wiki/DNS_over_HTTPS";
this.inputType = "string";
this.outputType = "JSON";
2019-02-06 21:54:06 +01:00
this.manualBake = true;
2019-02-06 21:20:20 +01:00
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"
]
},
{
2019-02-06 23:50:46 +01:00
name: "Answer Data Only",
2019-02-06 21:20:20 +01:00
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;
2019-02-06 21:54:06 +01:00
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" )
}
2019-02-06 21:20:20 +01:00
var params = {name:input, type:requestType, cd:DNSSEC};
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;
2019-02-06 23:50:46 +01:00
}).catch(e => {throw new OperationError("Error making request to : " + url + "\n" +
"Error Message: " + e.toString())})
2019-02-06 21:20:20 +01:00
}
}
export default HTTPSOverDNS;