-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
371 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import dns from 'dns'; | ||
import whois from 'whois'; | ||
import Test, { TestParameters, Result } from '../Test'; | ||
import logger from '../logger'; | ||
|
||
class A extends Test { | ||
public name = 'A'; | ||
|
||
public async test({ url }: TestParameters): Promise<Result> { | ||
logger.info(`Starting ${this.constructor.name} test...`); | ||
|
||
const response = await new Promise((resolve, reject) => { | ||
dns.lookup((new URL(url).hostname), { all: true }, (err, addresses) => { | ||
if (err) { | ||
reject(err); | ||
} | ||
|
||
resolve(addresses); | ||
}); | ||
}); | ||
|
||
const addresses = await Promise.all((response as any).map(async (address: any) => { | ||
const organization = await this.getOrganization(address.address); | ||
|
||
return `${address.address} - ${organization}`; | ||
})); | ||
|
||
return { | ||
status: 'SUCCESS', | ||
title: this.constructor.name, | ||
description: addresses.join('\n'), | ||
}; | ||
} | ||
|
||
protected async getOrganization(ip: string): Promise<string> { | ||
const organization: string = await new Promise((resolve, reject) => { | ||
whois.lookup(ip, function(err, data) { | ||
if (err) { | ||
reject(err); | ||
} | ||
|
||
const organization = data.split('\n') | ||
.filter((line: string) => line.includes('OrgName')) | ||
.map((line: string) => line.split(':')[1].trim()) | ||
.pop(); | ||
|
||
resolve(organization); | ||
}); | ||
}); | ||
|
||
return organization; | ||
} | ||
} | ||
|
||
export default A; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import dns from 'dns'; | ||
import Test, { TestParameters, Result } from '../Test'; | ||
import logger from '../logger'; | ||
|
||
class DMARC extends Test { | ||
public name = 'DMARC'; | ||
|
||
public async test({ url }: TestParameters): Promise<Result> { | ||
logger.info(`Starting ${this.constructor.name} test...`); | ||
|
||
const response: any = await new Promise((resolve, reject) => { | ||
dns.resolveTxt(`_dmarc.${(new URL(url).hostname)}`, (err, records) => { | ||
if (err) { | ||
reject(err); | ||
} | ||
|
||
resolve(records); | ||
}); | ||
}); | ||
|
||
if (response.length === 0) { | ||
return { | ||
status: 'WARNING', | ||
title: this.constructor.name, | ||
description: 'No DMARC record found for this domain.', | ||
} | ||
} | ||
|
||
const record = response.shift().shift(); | ||
|
||
if (record.includes('p=none')) { | ||
return { | ||
status: 'ERROR', | ||
title: this.constructor.name, | ||
description: 'Email that fails DMARC Compliance tests will be delivered to the recipient\'s inbox.', | ||
}; | ||
} | ||
|
||
if (record.includes('p=quarantine')) { | ||
return { | ||
status: 'WARNING', | ||
title: this.constructor.name, | ||
description: 'Email that fails DMARC Compliance tests will be marked as spam.', | ||
}; | ||
} | ||
|
||
if (record.includes('p=reject')) { | ||
return { | ||
status: 'SUCCESS', | ||
title: this.constructor.name, | ||
description: 'Email that fails DMARC Compliance tests will be rejected.', | ||
}; | ||
} | ||
|
||
return { | ||
status: 'ERROR', | ||
title: this.constructor.name, | ||
description: 'Invalid DMARC policy found!', | ||
}; | ||
} | ||
} | ||
|
||
export default DMARC; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import whois from 'whois'; | ||
import Test, { TestParameters, Result } from '../Test'; | ||
import logger from '../logger'; | ||
|
||
class NS extends Test { | ||
public name = 'NS'; | ||
|
||
public async test({ url }: TestParameters): Promise<Result> { | ||
logger.info(`Starting ${this.constructor.name} test...`); | ||
|
||
const nameServers = await this.getNameServers((new URL(url).hostname)); | ||
|
||
return { | ||
status: 'SUCCESS', | ||
title: this.constructor.name, | ||
description: nameServers.join('\n'), | ||
}; | ||
} | ||
|
||
protected async getNameServers(domain: string): Promise<string[]> { | ||
const nameServers: string[] = await new Promise((resolve, reject) => { | ||
whois.lookup(domain, function(err, data) { | ||
if (err) { | ||
reject(err); | ||
} | ||
|
||
const nameServers = data.split('\n') | ||
.filter((line: string) => line.includes('Name Server')) | ||
.map((line: string) => line.split(':')[1].trim()); | ||
|
||
resolve(nameServers); | ||
}); | ||
}); | ||
|
||
return nameServers; | ||
} | ||
} | ||
|
||
export default NS; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import whois from 'whois'; | ||
import Test, { TestParameters, Result } from '../Test'; | ||
import logger from '../logger'; | ||
|
||
class RegistrationDate extends Test { | ||
public name = 'RegistrationDate'; | ||
|
||
public async test({ url }: TestParameters): Promise<Result> { | ||
logger.info(`Starting ${this.constructor.name} test...`); | ||
|
||
const registrationDate = await this.getRegistrationDate((new URL(url).hostname)); | ||
|
||
const diffInMs = (new Date(registrationDate)).getTime() - (new Date()).getTime(); | ||
const diffInDays = diffInMs / (1000 * 60 * 60 * 24); | ||
|
||
return { | ||
status: diffInDays < 7 ? 'ERROR' : diffInDays < 30 ? 'WARNING' : 'SUCCESS', | ||
title: this.constructor.name, | ||
description: `Approximately ${Math.floor(diffInDays)} days until domain expires.`, | ||
}; | ||
} | ||
|
||
protected async getRegistrationDate(domain: string): Promise<string> { | ||
const date: string = await new Promise((resolve, reject) => { | ||
whois.lookup(domain, function(err, data) { | ||
if (err) { | ||
reject(err); | ||
} | ||
|
||
const d = data.split('\n') | ||
.filter((line: string) => line.includes('Expiration Date')) | ||
.map((line: string) => line.split(': ')[1].trim()) | ||
.shift(); | ||
|
||
resolve(d); | ||
}); | ||
}); | ||
|
||
return date; | ||
} | ||
} | ||
|
||
export default RegistrationDate; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import Test, { TestParameters, Result } from '../Test'; | ||
import A from './A'; | ||
import NS from './NS'; | ||
import DMARC from './DMARC'; | ||
import RegistrationDate from './RegistrationDate'; | ||
|
||
export default class DNS extends Test { | ||
public name = 'DNS'; | ||
|
||
constructor() { | ||
super(); | ||
this.tests = [ | ||
new RegistrationDate(), | ||
new NS(), | ||
new A(), | ||
new DMARC(), | ||
]; | ||
} | ||
|
||
public async test(params: TestParameters): Promise<Result> { | ||
const tests = this.getTests(); | ||
const results = []; | ||
|
||
for (const test of tests) { | ||
let result = null; | ||
|
||
try { | ||
result = await test.run(params); | ||
} catch (error) { | ||
result = { | ||
status: 'ERROR', | ||
title: test.name, | ||
description: 'Test failed or cannot be run!', | ||
} | ||
} | ||
|
||
results.push(result); | ||
} | ||
|
||
return { | ||
status: this.getStatus(results.map(result => result.status)), | ||
title: this.name, | ||
description: '', | ||
results, | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.