mirror of
https://github.com/Lissy93/web-check.git
synced 2025-06-20 03:37:41 +02:00
🚧 Work in progress
This commit is contained in:
parent
9018f6fdd1
commit
a745e28388
@ -7,7 +7,6 @@ exports.handler = function (event, context, callback) {
|
|||||||
.replaceAll('https://', '')
|
.replaceAll('https://', '')
|
||||||
.replaceAll('http://', '');
|
.replaceAll('http://', '');
|
||||||
dns.lookup(address, (err, ip, family) => {
|
dns.lookup(address, (err, ip, family) => {
|
||||||
console.log(err);
|
|
||||||
if (err) {
|
if (err) {
|
||||||
callback(null, {
|
callback(null, {
|
||||||
statusCode: 405,
|
statusCode: 405,
|
||||||
|
71
server/lambda/web-check.js
Normal file
71
server/lambda/web-check.js
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
const fetch = require('node-fetch');
|
||||||
|
|
||||||
|
|
||||||
|
const endpoints = {
|
||||||
|
dnsRecords: 'https://api.securitytrails.com/v1/domain/{address}',
|
||||||
|
subDomains: 'https://api.securitytrails.com/v1/domain/{address}/subdomains?include_inactive=true',
|
||||||
|
};
|
||||||
|
|
||||||
|
const apiKeys = {
|
||||||
|
shodan: process.env.SHODAN_API_KEY,
|
||||||
|
securityTrails: process.env.SECURITY_TRAILS_API_KEY,
|
||||||
|
};
|
||||||
|
|
||||||
|
const makeEndpoint = (endpoint, address) => endpoint.replace('{address}', address);
|
||||||
|
|
||||||
|
const errorObject = (msg, status) => {
|
||||||
|
return {
|
||||||
|
statusCode: status || 500,
|
||||||
|
body: JSON.stringify({ error: true, errorMsg: msg }),
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/* Fetches list of DNS records for a given URL from SecurityTrails API */
|
||||||
|
const getDnsInfo = async (url) => {
|
||||||
|
const stOptions = {
|
||||||
|
method: 'GET',
|
||||||
|
headers: { Accept: 'application/json', APIKEY: apiKeys.securityTrails }
|
||||||
|
};
|
||||||
|
const dnsInfoRequest = await fetch(makeEndpoint(endpoints.dnsRecords, url), stOptions);
|
||||||
|
const dnsInfoResponse = await dnsInfoRequest.json();
|
||||||
|
if (dnsInfoResponse) return null;
|
||||||
|
return dnsInfoResponse?.current_dns;
|
||||||
|
};
|
||||||
|
|
||||||
|
/* Fetches a list of a domain's sub-domains from SecurityTrails API */
|
||||||
|
const getSubDomains = async (url) => {
|
||||||
|
const stOptions = {
|
||||||
|
method: 'GET',
|
||||||
|
headers: { Accept: 'application/json', APIKEY: apiKeys.securityTrails }
|
||||||
|
};
|
||||||
|
const subDomainRequest = await fetch(makeEndpoint(endpoints.subDomains, url), stOptions);
|
||||||
|
const subDomainResponse = await subDomainRequest.json();
|
||||||
|
if (!subDomainResponse.subdomains) return null;
|
||||||
|
return {
|
||||||
|
count: subDomainResponse?.subdomain_count,
|
||||||
|
list: subDomainResponse?.subdomains,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.handler = async (event, context) => {
|
||||||
|
const addressParam = event.queryStringParameters.address;
|
||||||
|
if (!addressParam) return errorObject('An address must be specified');
|
||||||
|
const address = decodeURIComponent(addressParam)
|
||||||
|
.replaceAll('https://', '')
|
||||||
|
.replaceAll('http://', '');
|
||||||
|
|
||||||
|
try {
|
||||||
|
const results = {};
|
||||||
|
if (apiKeys.securityTrails) {
|
||||||
|
results.dnsRecords = await getDnsInfo(address);
|
||||||
|
results.subDomains = await getSubDomains(address);
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
statusCode: 200,
|
||||||
|
body: JSON.stringify(results),
|
||||||
|
};
|
||||||
|
} catch (error) {
|
||||||
|
return errorObject('Failed to fetch data');
|
||||||
|
}
|
||||||
|
};
|
@ -118,6 +118,26 @@ const Results = (): JSX.Element => {
|
|||||||
}
|
}
|
||||||
}, [ipAddress]);
|
}, [ipAddress]);
|
||||||
|
|
||||||
|
/* Get WhoIs info for a given domain name */
|
||||||
|
useEffect(() => {
|
||||||
|
const applyWhoIsResults = (response: any) => {
|
||||||
|
console.log('WhoIs Response', response);
|
||||||
|
}
|
||||||
|
const fetchWhoIsData = () => {
|
||||||
|
const apiKey = keys.whoApi;
|
||||||
|
fetch(`https://api.whoapi.com/?domain=${address}&r=whois&apikey=${apiKey}`)
|
||||||
|
.then(response => response.json())
|
||||||
|
.then(response => {
|
||||||
|
if (!response.error) applyWhoIsResults(response)
|
||||||
|
})
|
||||||
|
.catch(err => console.error(err));
|
||||||
|
};
|
||||||
|
|
||||||
|
if (addressType === 'url') {
|
||||||
|
fetchWhoIsData();
|
||||||
|
}
|
||||||
|
}, [addressType, address]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ResultsOuter>
|
<ResultsOuter>
|
||||||
<Header as="header">
|
<Header as="header">
|
||||||
|
@ -8,7 +8,7 @@ export type AddressType = 'ipV4' | 'ipV6' | 'url' | 'err' | 'empt';
|
|||||||
/* Checks if a given string looks like a URL */
|
/* Checks if a given string looks like a URL */
|
||||||
const isUrl = (value: string):boolean => {
|
const isUrl = (value: string):boolean => {
|
||||||
const urlRegex= new RegExp(''
|
const urlRegex= new RegExp(''
|
||||||
+ /(?:(?:(https?|ftp):)?\/\/)/.source
|
// + /(?:(?:(https?|ftp):)?\/\/)/.source
|
||||||
+ /(?:([^:\n\r]+):([^@\n\r]+)@)?/.source
|
+ /(?:([^:\n\r]+):([^@\n\r]+)@)?/.source
|
||||||
+ /(?:(?:www\.)?([^/\n\r]+))/.source
|
+ /(?:(?:www\.)?([^/\n\r]+))/.source
|
||||||
+ /(\/[^?\n\r]+)?/.source
|
+ /(\/[^?\n\r]+)?/.source
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
|
|
||||||
const keys = {
|
const keys = {
|
||||||
shodan: process.env.SHODAN_API_KEY,
|
shodan: process.env.SHODAN_API_KEY,
|
||||||
|
whoApi: process.env.WHO_API_KEY,
|
||||||
};
|
};
|
||||||
|
|
||||||
export default keys;
|
export default keys;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user