Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/gavinspearhead/passivedns
Browse files Browse the repository at this point in the history
…into gavinspearhead-master
  • Loading branch information
Edward Fjellskål committed Aug 27, 2015
2 parents 82b782c + ade8c97 commit 843ca79
Show file tree
Hide file tree
Showing 4 changed files with 182 additions and 27 deletions.
168 changes: 157 additions & 11 deletions src/dns.c
Expand Up @@ -325,13 +325,76 @@ int cache_dns_objects(packetinfo *pi, ldns_rdf *rdf_data,
for (j = 0; j < dns_answer_domain_cnt; j++)
{
int offset = -1;
int to_offset = -1;
int len;
ldns_rr *rr;
ldns_rdf *rname;
unsigned char *rdomain_name = 0;
unsigned char *rdomain_name = 0, *tmp1=NULL, *tmp2=NULL;

rr = ldns_rr_list_rr(dns_answer_domains, j);

switch (ldns_rr_get_type(rr)) {
case LDNS_RR_TYPE_LOC:
if (config.dnsf & DNS_CHK_LOC) {
offset = 0;
}
break;
case LDNS_RR_TYPE_GPOS:
if (config.dnsf & DNS_CHK_LOC) {
offset = 0;
to_offset = 3;
}
break;
case LDNS_RR_TYPE_RRSIG:
if (config.dnsf & DNS_CHK_DNSSEC) {
offset = 0;
to_offset = 9;
}
break;
case LDNS_RR_TYPE_DNSKEY:
if (config.dnsf & DNS_CHK_DNSSEC) {
offset = 0;
to_offset = 4;
}
break;

case LDNS_RR_TYPE_NSEC3PARAM:
if (config.dnsf & DNS_CHK_DNSSEC) {
offset = 0;
to_offset = 4;
}
break;
case LDNS_RR_TYPE_NSEC3:
if (config.dnsf & DNS_CHK_DNSSEC) {
offset = 0;
to_offset = 5;
}
break;

case LDNS_RR_TYPE_NSEC:
if (config.dnsf & DNS_CHK_DNSSEC) {
offset = 0;
to_offset = 2;
}
break;
case LDNS_RR_TYPE_HINFO:
if (config.dnsf & DNS_CHK_HINFO) {
offset = 0;
to_offset = 2;
}
break;
case LDNS_RR_TYPE_DS:
if (config.dnsf & DNS_CHK_DNSSEC) {
offset = 0;
to_offset = 4;
}
break;
case LDNS_RR_TYPE_SSHFP:
if (config.dnsf & DNS_CHK_SSHFP) {
offset = 0;
to_offset = 3;
}
break;
case LDNS_RR_TYPE_AAAA:
if (config.dnsf & DNS_CHK_AAAA)
offset = 0;
Expand All @@ -355,6 +418,7 @@ int cache_dns_objects(packetinfo *pi, ldns_rdf *rdf_data,
case LDNS_RR_TYPE_NAPTR:
if (config.dnsf & DNS_CHK_NAPTR)
offset = 0;
to_offset = 6;
break;
case LDNS_RR_TYPE_RP:
if (config.dnsf & DNS_CHK_RP)
Expand All @@ -368,6 +432,10 @@ int cache_dns_objects(packetinfo *pi, ldns_rdf *rdf_data,
if (config.dnsf & DNS_CHK_TXT)
offset = 0;
break;
case LDNS_RR_TYPE_SPF:
if (config.dnsf & DNS_CHK_SPF)
offset = 0;
break;
case LDNS_RR_TYPE_SOA:
if (config.dnsf & DNS_CHK_SOA)
offset = 0;
Expand All @@ -392,20 +460,41 @@ int cache_dns_objects(packetinfo *pi, ldns_rdf *rdf_data,
//data_offset = 0;
continue;
}
do {
/* Get the rdf data from the rr */
ldns_buffer_clear(buff);
rname = ldns_rr_rdf(rr, offset);

if (rname == NULL) {
dlog("[D] ldns_rr_rdf returned: NULL\n");
break;;
}

/* Get the rdf data from the rr */
rname = ldns_rr_rdf(rr, offset);

ldns_rdf2buffer_str(buff, rname);
rdomain_name = (unsigned char *) ldns_buffer2str(buff);
if (rdomain_name == NULL) continue;
len = strlen(rdomain_name) + 5;
if (tmp1 != NULL) len += strlen(tmp1);
tmp2 = malloc(len);
if (tmp1 != NULL) {
tmp2 = strcpy(tmp2, tmp1);
tmp2 = strcat(tmp2, " ");
}
else {
tmp2 = strcpy(tmp2, "");
}
free(tmp1);
tmp2 = strcat(tmp2, rdomain_name);
tmp1 = tmp2;
free(rdomain_name);
offset ++;
} while (offset < to_offset);
rdomain_name = tmp1;
if (rname == NULL) {
dlog("[D] ldns_rr_rdf returned: NULL\n");
continue;
}

ldns_buffer_clear(buff);
ldns_rdf2buffer_str(buff, rname);
rdomain_name = (unsigned char *) ldns_buffer2str(buff);

if (rdomain_name == NULL) {
if (rdomain_name == NULL && offset <= 1) {
dlog("[D] ldns_buffer2str returned: NULL\n");
continue;
}
Expand Down Expand Up @@ -616,7 +705,7 @@ void print_passet(pdns_record *l, pdns_asset *p, ldns_rr *rr,
}

rr_class = malloc(10);
rr_type = malloc(10);
rr_type = malloc(12);
rr_rcode = malloc(20);

switch (ldns_rr_get_class(rr)) {
Expand All @@ -641,6 +730,36 @@ void print_passet(pdns_record *l, pdns_asset *p, ldns_rr *rr,
}

switch (ldns_rr_get_type(rr)) {
case LDNS_RR_TYPE_HINFO:
snprintf(rr_type, 10, "HINFO");
break;
case LDNS_RR_TYPE_SSHFP:
snprintf(rr_type, 10, "SSHFP");
break;
case LDNS_RR_TYPE_GPOS:
snprintf(rr_type, 10, "GPOS");
break;
case LDNS_RR_TYPE_LOC:
snprintf(rr_type, 10, "LOC");
break;
case LDNS_RR_TYPE_DNSKEY:
snprintf(rr_type, 10, "DNSKEY");
break;
case LDNS_RR_TYPE_NSEC3PARAM:
snprintf(rr_type, 11, "NSEC3PARAM");
break;
case LDNS_RR_TYPE_NSEC3:
snprintf(rr_type, 10, "NSEC3");
break;
case LDNS_RR_TYPE_NSEC:
snprintf(rr_type, 10, "NSEC");
break;
case LDNS_RR_TYPE_RRSIG:
snprintf(rr_type, 10, "RRSIG");
break;
case LDNS_RR_TYPE_DS:
snprintf(rr_type, 10, "DS");
break;
case LDNS_RR_TYPE_PTR:
snprintf(rr_type, 10, "PTR");
break;
Expand Down Expand Up @@ -668,6 +787,9 @@ void print_passet(pdns_record *l, pdns_asset *p, ldns_rr *rr,
case LDNS_RR_TYPE_TXT:
snprintf(rr_type, 10, "TXT");
break;
case LDNS_RR_TYPE_SPF:
snprintf(rr_type, 10, "SPF");
break;
case LDNS_RR_TYPE_SOA:
snprintf(rr_type, 10, "SOA");
break;
Expand Down Expand Up @@ -1396,6 +1518,26 @@ void parse_dns_flags(char *args)

for (i = 0; i < len; i++){
switch(args[i]) {
case 'I': /* HINFO */
config.dnsf |= DNS_CHK_HINFO;
dlog("[D] Enabling flag: DNS_CHK_HINFO\n");
ok++;
break;
case 'H': /* SSHFP */
config.dnsf |= DNS_CHK_SSHFP;
dlog("[D] Enabling flag: DNS_CHK_SSHFP\n");
ok++;
break;
case 'L': /* LOC */
config.dnsf |= DNS_CHK_LOC;
dlog("[D] Enabling flag: DNS_CHK_LOC\n");
ok++;
break;
case 'd': /* DNSSEC */
config.dnsf |= DNS_CHK_DNSSEC;
dlog("[D] Enabling flag: DNS_CHK_DNSSEC\n");
ok++;
break;
case '4': /* A */
config.dnsf |= DNS_CHK_A;
dlog("[D] Enabling flag: DNS_CHK_A\n");
Expand Down Expand Up @@ -1436,6 +1578,10 @@ void parse_dns_flags(char *args)
dlog("[D] Enabling flag: DNS_CHK_SRV\n");
ok++;
break;
case 'F': /* SPF */
config.dnsf |= DNS_CHK_SPF;
dlog("[D] Enabling flag: DNS_CHK_SPF\n");
ok++;
case 'T': /* TXT */
config.dnsf |= DNS_CHK_TXT;
dlog("[D] Enabling flag: DNS_CHK_TXT\n");
Expand Down
31 changes: 18 additions & 13 deletions src/dns.h
Expand Up @@ -25,19 +25,24 @@
#include <ldns/ldns.h>

/* Default flags for types to handle */
#define DNS_CHK_AAAA 0x0001
#define DNS_CHK_A 0x0002
#define DNS_CHK_PTR 0x0004
#define DNS_CHK_CNAME 0x0008
#define DNS_CHK_DNAME 0x0010
#define DNS_CHK_NAPTR 0x0020
#define DNS_CHK_RP 0x0040
#define DNS_CHK_SRV 0x0080
#define DNS_CHK_TXT 0x0100
#define DNS_CHK_SOA 0x0200
#define DNS_CHK_MX 0x0400
#define DNS_CHK_NS 0x0800
#define DNS_CHK_ALL 0x8000
#define DNS_CHK_AAAA 0x00000001
#define DNS_CHK_A 0x00000002
#define DNS_CHK_PTR 0x00000004
#define DNS_CHK_CNAME 0x00000008
#define DNS_CHK_DNAME 0x00000010
#define DNS_CHK_NAPTR 0x00000020
#define DNS_CHK_RP 0x00000040
#define DNS_CHK_SRV 0x00000080
#define DNS_CHK_TXT 0x00000100
#define DNS_CHK_SOA 0x00000200
#define DNS_CHK_MX 0x00000400
#define DNS_CHK_NS 0x00000800
#define DNS_CHK_DNSSEC 0x00001000
#define DNS_CHK_LOC 0x00002000
#define DNS_CHK_SPF 0x00004000
#define DNS_CHK_SSHFP 0x00008000
#define DNS_CHK_HINFO 0x00010000
#define DNS_CHK_ALL 0x80000000
/* Default flags for Server Errors to handle */
#define DNS_SE_CHK_FORMERR 0x0001
#define DNS_SE_CHK_SERVFAIL 0x0002
Expand Down
7 changes: 5 additions & 2 deletions src/passivedns.c
Expand Up @@ -1098,8 +1098,11 @@ void usage()
olog(" FLAGS:\n");
olog("\n");
olog(" * For Record Types:\n");
olog(" 4:A 6:AAAA C:CNAME D:DNAME N:NAPTR O:SOA\n");
olog(" P:PTR R:RP S:SRV T:TXT M:MX n:NS\n");
olog(" 4:A 6:AAAA C:CNAME D:DNAME N:NAPTR O:SOA L:LOC F:SPF H:HINFO\n");
olog(" P:PTR R:RP S:SRV T:TXT M:MX n:NS d:DNSEC H:SSHFP\n");
olog(" L also enables GPOS\n");
olog(" d enables DS, DNSKEY, NSEC, NSEC3. NSEC3PARAM, RRSIG\n");

olog("\n");
olog(" * For Server Return Code (SRC) Errors:\n");
olog(" f:FORMERR s:SERVFAIL x:NXDOMAIN o:NOTIMPL r:REFUSED\n");
Expand Down
3 changes: 2 additions & 1 deletion src/passivedns.h
Expand Up @@ -502,7 +502,7 @@ typedef struct _globalconfig {
uint8_t daemon_flag; /* Flag for going daemon */
uint8_t logfile_all; /* Log everything in the same log file */
uint32_t fieldsf; /* flags for fields to print */
uint32_t dnsf; /* Flags for DNS RR Type checks to do */
uint64_t dnsf; /* Flags for DNS RR Type checks to do */
uint32_t dnsfe; /* Flags for DNS Server Error Types to check */
uint32_t payload; /* Dump how much of the payload ? */
uint32_t curcxt;
Expand Down Expand Up @@ -544,6 +544,7 @@ typedef struct _globalconfig {

#define plog(fmt, ...) do{ fprintf(stdout, (fmt), ##__VA_ARGS__); }while(0)
#define olog(fmt, ...) do{ if(!(ISSET_CONFIG_QUIET(config))) fprintf(stdout, (fmt), ##__VA_ARGS__); }while(0)
//#define DEBUG 1
#ifdef DEBUG
#define dlog(fmt, ...) do { fprintf(stderr, ("[%s:%d(%s)] " fmt), __FILE__, __LINE__, __PRETTY_FUNCTION__, ##__VA_ARGS__);} while(0)
#define vlog(v, fmt, ...) do{ if(DEBUG == v) fprintf(stderr, ("[%s:%d(%s)] " fmt), __FILE__, __LINE__, __PRETTY_FUNCTION__, ##__VA_ARGS__); }while(0)
Expand Down

0 comments on commit 843ca79

Please sign in to comment.