]> granicus.if.org Git - pdns/commitdiff
add tool dnsscan (mostly for internal use)
authorBert Hubert <bert.hubert@netherlabs.nl>
Thu, 13 Apr 2006 19:49:56 +0000 (19:49 +0000)
committerBert Hubert <bert.hubert@netherlabs.nl>
Thu, 13 Apr 2006 19:49:56 +0000 (19:49 +0000)
make dist-recursor package a version number
improve stats, add some logging

git-svn-id: svn://svn.powerdns.com/pdns/trunk/pdns@691 d19b8d6e-7fed-0310-83ef-9ca221ded41b

pdns/Makefile.am
pdns/dist-recursor
pdns/dnsscan.cc [new file with mode: 0644]
pdns/lwres.cc
pdns/lwres.hh
pdns/syncres.hh

index f143f7ea3fa39fcc52b32f0dedadda420edb5619..edbfbf283dbd008a8edcb35ed9f3e208e6ac3e38 100644 (file)
@@ -20,7 +20,7 @@ endif
 
 
 
-EXTRA_PROGRAMS=pdns_recursor sdig dnspbench pdns_control qgen dnsscope dnsreplay_mindex dnswasher dnsreplay 
+EXTRA_PROGRAMS=pdns_recursor sdig dnspbench pdns_control qgen dnsscope dnsreplay_mindex dnswasher dnsreplay dnsscan
 
 pdns_server_SOURCES=dnspacket.cc nameserver.cc tcpreceiver.hh \
 qtype.cc logger.cc arguments.cc packethandler.cc tcpreceiver.cc \
@@ -72,6 +72,12 @@ dnsreplay_SOURCES=dnsreplay.cc misc.cc  qtype.cc anadns.hh \
 
 dnsreplay_LDFLAGS= @DYNLINKFLAGS@ @THREADFLAGS@
 
+dnsscan_SOURCES=dnsscan.cc misc.cc  qtype.cc anadns.hh \
+       logger.cc statbag.cc  dnspcap.cc dnspcap.hh dnsparser.cc dnsrecords.cc dnsparser.hh  \
+       rcpgenerator.cc rcpgenerator.hh base64.cc base64.hh dnswriter.cc dnswriter.hh \
+       unix_utility.cc utility.hh              
+
+
 dnsreplay_mindex_SOURCES=dnsreplay-mindex.cc misc.cc  qtype.cc anadns.hh \
        logger.cc statbag.cc  dnspcap.cc dnspcap.hh dnsparser.cc dnsrecords.cc dnsparser.hh  \
        rcpgenerator.cc rcpgenerator.hh base64.cc base64.hh dnswriter.cc dnswriter.hh \
index e69ad53630abdb5c63926f1630a887f267637c54..630b8d4ff113a5e794e846e7e339b018e83ee4e0 100755 (executable)
@@ -1,3 +1,5 @@
+VERSION=3.0-pre1
+
 INCLUDES="iputils.hh arguments.hh base64.hh zoneparser-tng.hh \
 rcpgenerator.hh lock.hh dnswriter.hh  dnsrecords.hh dnsparser.hh utility.hh \
 recursor_cache.hh rec_channel.hh qtype.hh misc.hh dns.hh syncres.hh \
@@ -8,20 +10,20 @@ logger.cc arguments.cc  lwres.cc pdns_recursor.cc  \
 recursor_cache.cc  dnsparser.cc dnswriter.cc  dnsrecords.cc  rcpgenerator.cc  \
 base64.cc  zoneparser-tng.cc  rec_channel.cc rec_channel_rec.cc rec_control.cc"
 
-cat $INCLUDES $CFILES | wc 
 
-rm -rf pdns-recursor
-mkdir  pdns-recursor
-cp $INCLUDES $CFILES pdns-recursor
-cp Makefile-recursor pdns-recursor/Makefile
-cp README-recursor pdns-recursor/README
-cp COPYING pdns-recursor/
-cp config-recursor.h pdns-recursor/config.h
-mkdir pdns-recursor/rrd
-cp tools/rrd/{create,update,makegraphs,index.html} pdns-recursor/rrd
-cp ext/nedmalloc/malloc.c pdns-recursor
-tar cf pdns-recursor.tar pdns-recursor
-bzip2 -f pdns-recursor.tar # .. solaris
+DIRNAME=pdns-recursor-$VERSION
+rm -rf $DIRNAME
+mkdir  $DIRNAME
+cp $INCLUDES $CFILES $DIRNAME
+cp Makefile-recursor $DIRNAME/Makefile
+cp README-recursor $DIRNAME/README
+cp COPYING $DIRNAME/
+cp config-recursor.h $DIRNAME/config.h
+mkdir $DIRNAME/rrd
+cp tools/rrd/{create,update,makegraphs,index.html} $DIRNAME/rrd
+cp ext/nedmalloc/malloc.c $DIRNAME
+tar cf $DIRNAME.tar $DIRNAME
+bzip2 -f $DIRNAME.tar # .. solaris
 
 
 
diff --git a/pdns/dnsscan.cc b/pdns/dnsscan.cc
new file mode 100644 (file)
index 0000000..6431ab6
--- /dev/null
@@ -0,0 +1,64 @@
+#include <bitset>
+#include "statbag.hh"
+#include "dnspcap.hh"
+#include "sstuff.hh"
+#include "anadns.hh"
+
+// this is needed because boost multi_index also uses 'L', as do we (which is sad enough)
+#undef L
+
+#include <arpa/nameser.h>
+#include <set>
+#include <deque>
+
+#include <boost/format.hpp>
+#include <boost/utility.hpp>
+#include <boost/multi_index_container.hpp>
+#include <boost/multi_index/ordered_index.hpp>
+#include <boost/multi_index/key_extractors.hpp>
+#include <cctype>
+
+using namespace boost;
+using namespace ::boost::multi_index;
+using namespace std;
+StatBag S;
+
+int main(int argc, char** argv)
+try
+{
+  PcapPacketReader pr(argv[1]);
+  Socket sock(InterNetwork, Datagram);
+
+  IPEndpoint remote(argc > 2 ? argv[2] : "127.0.0.1", 
+                   argc > 3 ? atoi(argv[3]) : 5300);
+
+
+  while(pr.getUDPPacket()) {
+    try {
+      MOADNSParser mdp((const char*)pr.d_payload, pr.d_len);
+      for(int i=0; i < mdp.d_qname.length(); ++i)
+       if(!isalnum(mdp.d_qname[i]) && mdp.d_qname[i]!='.' && mdp.d_qname[i]!='-' && mdp.d_qname[i]!='_') {
+         cout<<mdp.d_qname<<"|"<<mdp.d_qtype<<"|"<<mdp.d_qclass<<"\n";
+         sock.sendTo(string(pr.d_payload, pr.d_payload + pr.d_len), remote);
+         break;
+       }
+      if(mdp.d_qtype > 256 || mdp.d_qclass!=1 ) {
+       //      sock.sendTo(string(pr.d_payload, pr.d_payload + pr.d_len), remote);
+
+      }
+      for(MOADNSParser::answers_t::const_iterator i=mdp.d_answers.begin(); i!=mdp.d_answers.end(); ++i) {          
+
+      }
+
+    }
+    catch(MOADNSException &e) {
+      cerr<<"Error: "<<e.what()<<"\n";
+      sock.sendTo(string(pr.d_payload, pr.d_payload + pr.d_len), remote);
+    }
+  }
+}
+catch(exception& e)
+{
+  cerr<<"Fatal: "<<e.what()<<endl;
+}
+
index bcab581961f5f2a262cf49b1d77de14b83e8a0bd..dee5974671176a3ed710f9bf592cb453a5a9c966 100644 (file)
@@ -57,6 +57,7 @@ LWRes::~LWRes()
 /** Never throws! */
 int LWRes::asyncresolve(uint32_t ip, const char *domain, int type, bool doTCP, struct timeval* now)
 {
+  d_ip=ip;
   vector<uint8_t> vpacket;
   DNSPacketWriter pw(vpacket, domain, type);
 
@@ -67,6 +68,7 @@ int LWRes::asyncresolve(uint32_t ip, const char *domain, int type, bool doTCP, s
   d_inaxfr=false;
   d_rcode=0;
 
+
   struct sockaddr_in toaddr;
   Utility::socklen_t addrlen=sizeof(toaddr);
   toaddr.sin_addr.s_addr=htonl(ip);
@@ -139,6 +141,12 @@ LWRes::res_t LWRes::result()
     d_tcbit=mdp.d_header.tc;
     d_rcode=mdp.d_header.rcode;
 
+    if(d_domain  != mdp.d_qname) {
+      L<<Logger::Error<<"Packet purporting to come from remote server "<<U32ToIP(d_ip)<<" contained wrong answer: '" << d_domain << "' != '" << mdp.d_qname << "'" << endl;
+      g_stats.spoofedCount++;
+      goto out;
+    }
+
     LWRes::res_t ret;
     for(MOADNSParser::answers_t::const_iterator i=mdp.d_answers.begin(); i!=mdp.d_answers.end(); ++i) {          
       //      cout<<i->first.d_place<<"\t"<<i->first.d_label<<"\tIN\t"<<DNSRecordContent::NumberToType(i->first.d_type);
@@ -162,7 +170,10 @@ LWRes::res_t LWRes::result()
   catch(...) {
     L<<Logger::Error<<"Unknown error parsing packet from remote server"<<endl;
   }
+
   g_stats.serverParseError++; 
+
+ out:
   d_rcode=RCode::ServFail;
   LWRes::res_t empty;
   return empty;
index d693715555d8d396bbc77f72054428e2526d46bb..d1367cc8893e1bf2f76e824d9c4354b9e6ddae62 100644 (file)
@@ -22,6 +22,7 @@
 #include <string>
 #include <vector>
 #include <sys/types.h>
+#include "misc.hh"
 
 #ifndef WIN32
 
index 53a1aa1def57e728532b2570096912643c332e51..f20a33d9e393367a9a7a1897079926f796bfdb23 100644 (file)
@@ -358,6 +358,7 @@ struct RecursorStats
   uint64_t tcpClientOverflow;
   uint64_t clientParseError;
   uint64_t serverParseError;
+  uint64_t spoofedCount;
 };
 
 extern RecursorStats g_stats;