mirror of
https://github.com/Lissy93/web-check.git
synced 2025-06-19 19:28:00 +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('http://', '');
|
||||
dns.lookup(address, (err, ip, family) => {
|
||||
console.log(err);
|
||||
if (err) {
|
||||
callback(null, {
|
||||
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');
|
||||
}
|
||||
};
|
@ -117,6 +117,26 @@ const Results = (): JSX.Element => {
|
||||
fetchShodanData();
|
||||
}
|
||||
}, [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 (
|
||||
<ResultsOuter>
|
||||
|
@ -8,7 +8,7 @@ export type AddressType = 'ipV4' | 'ipV6' | 'url' | 'err' | 'empt';
|
||||
/* Checks if a given string looks like a URL */
|
||||
const isUrl = (value: string):boolean => {
|
||||
const urlRegex= new RegExp(''
|
||||
+ /(?:(?:(https?|ftp):)?\/\/)/.source
|
||||
// + /(?:(?:(https?|ftp):)?\/\/)/.source
|
||||
+ /(?:([^:\n\r]+):([^@\n\r]+)@)?/.source
|
||||
+ /(?:(?:www\.)?([^/\n\r]+))/.source
|
||||
+ /(\/[^?\n\r]+)?/.source
|
||||
|
@ -1,6 +1,7 @@
|
||||
|
||||
const keys = {
|
||||
shodan: process.env.SHODAN_API_KEY,
|
||||
whoApi: process.env.WHO_API_KEY,
|
||||
};
|
||||
|
||||
export default keys;
|
||||
|
Loading…
x
Reference in New Issue
Block a user