Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add PTR support #8

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
129 changes: 95 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,75 +3,97 @@
dns-axfr is a node.js module which extends dns core module to add support for AXFR type queries. It can be useful for pentesting tasks, automating recursive zone transfers, etc...

The following type of records are supported:
* A
* CNAME
* SOA
* MX
* NS
* TXT
* AAAA
* SPF
* SRV

- A
- CNAME
- SOA
- MX
- NS
- TXT
- AAAA
- SPF
- SRV
- PTR

## Usage

In otder to perform an AXFR query use `resolveAxfr()`
In order to perform an AXFR query use `resolveAxfr()`

### resolveAxfr(server, zone, callback)

```javascript
var dns = require("dns-axfr");
var util = require("util");

dns.resolveAxfr("dns01.acme.com", "acme.com", function (err, addr) {
if (err) {
console.error("Error ocurred: " + addr + " (" + err + ")");
return;
}

console.log(util.inspect(addr));
});
```

Reverse lookup example

```javascript
var dns = require('dns-axfr');
var util = require('util');
var dns = require("dns-axfr");
var util = require("util");

dns.resolveAxfr('dns01.acme.com', 'acme.com', function(err, addr) {
if (err) {
console.error('Error ocurred: ' + addr + ' (' + err + ')');
return;
}
dns.resolveAxfr("dns01.acme.com", "0.0.10.in-addr.arpa", function (err, addr) {
if (err) {
console.error("Error ocurred: " + addr + " (" + err + ")");
return;
}

console.log(util.inspect(addr));
console.log(util.inspect(addr));
});
```

If you need to setup a timeout for the request use `resolveAxfrTimeout()` and set the desired timeout in milliseconds.

### resolveAxfrTimeout(timeout)

```javascript
var dns = require('dns-axfr');
var util = require('util');
var dns = require("dns-axfr");
var util = require("util");

dns.resolveAxfrTimeout(1000);

dns.resolveAxfr('dns01.acme.com', 'acme.com', function(err, addr) {
if (err) {
console.error('Error ocurred: ' + addr + ' (' + err + ')');
return;
}
dns.resolveAxfr("dns01.acme.com", "acme.com", function (err, addr) {
if (err) {
console.error("Error ocurred: " + addr + " (" + err + ")");
return;
}

console.log(util.inspect(addr));
console.log(util.inspect(addr));
});
```



As this module extends the core dns module, you can access the original module without "requiring" it again:

```javascript
var dns = require('dns-axfr');
var util = require('util');
var dns = require("dns-axfr");
var util = require("util");

/* Extended function */
dns.resolveAxfr('dns01.acme.com', 'acme.com', function(err, addr) {
if (err) throw err;
console.log(util.inspect(addr));
dns.resolveAxfr("dns01.acme.com", "acme.com", function (err, addr) {
if (err) throw err;
console.log(util.inspect(addr));
});

/* Original dns module function */
dns.resolve4('www.google.com', function (err, addresses) {
dns.resolve4("www.google.com", function (err, addresses) {
if (err) throw err;
console.log(util.inspect(addresses));
});
```

## Sample results

Forward lookup example

```javascript
{
questions: [
Expand Down Expand Up @@ -150,3 +172,42 @@ dns.resolve4('www.google.com', function (err, addresses) {
]
}
```

Reverse lookup example

```javascript
{
questions: [
{
name: '0.0.10.in-addr.arpa.',
type: 'AXFR'
}
],
answers: [
{
name: '0.0.10.in-addr.arpa.',
type: 'SOA',
ttl: 21600,
dns: 'ns1.acme.es.',
mail: 'root.ns1.acme.es.',
serial: 2015012401,
refresInterval: 14400,
retryInterval: 7200,
expireLimit: 2592000,
minTTL: 28800
},
{
name: '1.0.0.10.in-addr.arpa.',
type: 'PTR',
ttl: 21600,
dns: 'gateway.acme.es.'
},
{
name: '2.0.0.10.in-addr.arpa.',
type: 'PTR',
ttl: 21600,
dns: 'ns1.acme.es.'
}
]
}
```
6 changes: 6 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,12 @@ function parseResponse(response, result) {
entry.mx = decompressLabel(response, (offset + 12)).name;
break;

/* PTR Record */
case 0x0c:
entry.type = 'PTR';
entry.dns = decompressLabel(response, (offset + 10)).name;
break;

/* TXT Record */
case 0x10:
entry.type = 'TXT';
Expand Down