:func:`DNSName:toDNSString` is convenient for converting names to wire format for passing to ``SpoofRawAction``.
+ ``sdig dumpluaraw`` and ``pdnsutil raw-lua-from-content`` from PowerDNS can generate raw answers for you:
+
+ .. code-block:: Shell
+
+ $ pdnsutil raw-lua-from-content SRV '0 0 65535 srv.powerdns.com.'
+ "\000\000\000\000\255\255\003srv\008powerdns\003com\000"
+ $ sdig 127.0.0.1 53 open-xchange.com MX recurse dumpluaraw
+ Reply to question for qname='open-xchange.com.', qtype=MX
+ Rcode: 0 (No Error), RD: 1, QR: 1, TC: 0, AA: 0, opcode: 0
+ 0 open-xchange.com. IN MX "\000c\004mx\049\049\012open\045xchange\003com\000"
+ 0 open-xchange.com. IN MX "\000\010\003mx\049\012open\045xchange\003com\000"
+ 0 open-xchange.com. IN MX "\000\020\003mx\050\012open\045xchange\003com\000"
+
:param string rawAnswer: The raw record data
:param {string} rawAnswers: A table of raw record data to spoof
:param table options: A table with key: value pairs with options.
#include "signingpipe.hh"
#include "dns_random.hh"
#include "ipcipher.hh"
+#include "misc.hh"
#include <fstream>
#include <utility>
#include <termios.h> //termios, TCSANOW, ECHO, ICANON
cout<<"unset-publish-cdnskey ZONE Disable sending CDNSKEY responses for ZONE"<<endl;
cout<<"unset-publish-cds ZONE Disable sending CDS responses for ZONE"<<endl;
cout<<"test-schema ZONE Test DB schema - will create ZONE"<<endl;
+ cout<<"raw-lua-from-content TYPE CONTENT Display record contents in a form suitable for dnsdist's `SpoofRawAction`"<<endl;
cout<<desc<<endl;
return 0;
}
#endif
}
+ if (cmds[0] == "raw-lua-from-content") {
+ if (cmds.size() < 3) {
+ cerr<<"Usage: raw-lua-from-content TYPE CONTENT"<<endl;
+ return 1;
+ }
+
+ // DNSResourceRecord rr;
+ // rr.qtype = DNSRecordContent::TypeToNumber(cmds[1]);
+ // rr.content = cmds[2];
+ auto drc = DNSRecordContent::mastermake(DNSRecordContent::TypeToNumber(cmds[1]), QClass::IN, cmds[2]);
+ cout<<makeLuaString(drc->serialize(DNSName(), true))<<endl;
+
+ return 0;
+ }
+
DNSSECKeeper dk;
if (cmds[0] == "test-schema") {
"[tcp] [dot] [insecure] [fastOpen] [subjectName name] [caStore file] [tlsProvider openssl|gnutls] "
"[xpf XPFDATA] [class CLASSNUM] "
"[proxy UDP(0)/TCP(1) SOURCE-IP-ADDRESS-AND-PORT DESTINATION-IP-ADDRESS-AND-PORT]"
+ "dumpluaraw"
<< endl;
}
pw.getHeader()->id = htons(qid);
}
-static void printReply(const string& reply, bool showflags, bool hidesoadetails)
+static void printReply(const string& reply, bool showflags, bool hidesoadetails, bool dumpluaraw)
{
MOADNSParser mdp(false, reply);
if (!s_expectedIDs.count(ntohs(mdp.d_header.id))) {
cout << i->first.d_place - 1 << "\t" << i->first.d_name.toString() << "\t"
<< nameForClass(i->first.d_class, i->first.d_type) << "\t"
<< DNSRecordContent::NumberToType(i->first.d_type);
+ if (dumpluaraw) {
+ cout<<"\t"<< makeLuaString(i->first.d_content->serialize(DNSName(), true))<<endl;
+ continue;
+ }
if (i->first.d_class == QClass::IN) {
if (i->first.d_type == QType::RRSIG) {
string zoneRep = i->first.d_content->getZoneRepresentation();
string subjectName;
string caStore;
string tlsProvider = "openssl";
+ bool dumpluaraw = false;
for (int i = 1; i < argc; i++) {
if ((string)argv[i] == "--help") {
ComboAddress dest(argv[++i]);
proxyheader = makeProxyHeader(ptcp, src, dest, {});
}
+ else if (strcmp(argv[i], "dumpluaraw") == 0) {
+ dumpluaraw = true;
+ }
else {
cerr << argv[i] << ": unknown argument" << endl;
exit(EXIT_FAILURE);
string question(packet.begin(), packet.end());
// FIXME: how do we use proxyheader here?
reply = mc.postURL(argv[1], question, mch, timeout, fastOpen);
- printReply(reply, showflags, hidesoadetails);
+ printReply(reply, showflags, hidesoadetails, dumpluaraw);
#else
throw PDNSException("please link sdig against libcurl for DoH support");
#endif
reply = reply.substr(2);
}
- printReply(reply, showflags, hidesoadetails);
+ printReply(reply, showflags, hidesoadetails, dumpluaraw);
} else if (tcp) {
std::shared_ptr<TLSCtx> tlsCtx{nullptr};
if (dot) {
if (handler.read(&reply[0], len, timeout) != len) {
throw PDNSException("tcp read failed");
}
- printReply(reply, showflags, hidesoadetails);
+ printReply(reply, showflags, hidesoadetails, dumpluaraw);
}
} else // udp
{
if (!result)
throw std::runtime_error("Timeout waiting for data");
sock.recvFrom(reply, dest);
- printReply(reply, showflags, hidesoadetails);
+ printReply(reply, showflags, hidesoadetails, dumpluaraw);
}
} catch (std::exception& e) {