Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
83fab5dbd3 | |||
174ba7f153 | |||
be520e9dac | |||
fd9211393b | |||
5abf3bc0aa | |||
9eb81694c7 |
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@apiclient.xyz/abuse.ch",
|
"name": "@apiclient.xyz/abuse.ch",
|
||||||
"version": "1.0.9",
|
"version": "1.0.12",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "an unofficial client to retrieve abuse.ch data",
|
"description": "an unofficial client to retrieve abuse.ch data",
|
||||||
"main": "dist_ts/index.js",
|
"main": "dist_ts/index.js",
|
||||||
|
@ -17,7 +17,7 @@ tap.test('should deal with FeodoTracker data', async () => {
|
|||||||
const feodoTracker = new abuseCh.FeodoTracker();
|
const feodoTracker = new abuseCh.FeodoTracker();
|
||||||
const data = await feodoTracker.getData();
|
const data = await feodoTracker.getData();
|
||||||
console.log(data.length);
|
console.log(data.length);
|
||||||
console.log(data[0]);
|
console.log(data[1]);
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.start();
|
tap.start();
|
||||||
|
@ -3,6 +3,6 @@
|
|||||||
*/
|
*/
|
||||||
export const commitinfo = {
|
export const commitinfo = {
|
||||||
name: '@apiclient.xyz/abuse.ch',
|
name: '@apiclient.xyz/abuse.ch',
|
||||||
version: '1.0.9',
|
version: '1.0.12',
|
||||||
description: 'an unofficial client to retrieve abuse.ch data'
|
description: 'an unofficial client to retrieve abuse.ch data'
|
||||||
}
|
}
|
||||||
|
@ -3,61 +3,50 @@ import * as paths from './paths.js';
|
|||||||
import * as helpers from './helpers.js';
|
import * as helpers from './helpers.js';
|
||||||
|
|
||||||
export interface IFeodoTrackerData {
|
export interface IFeodoTrackerData {
|
||||||
ID: string;
|
ip_address: string;
|
||||||
Dateadded: string;
|
port: number;
|
||||||
DestinationIP: string;
|
status: string;
|
||||||
DestinationPort: string;
|
hostname: string | null;
|
||||||
Malware: string;
|
as_number: number;
|
||||||
Reporter: string;
|
as_name: string;
|
||||||
|
country: string;
|
||||||
|
first_seen: string;
|
||||||
|
last_online: string;
|
||||||
|
malware: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export class FeodoTracker {
|
export class FeodoTracker {
|
||||||
private static readonly FEODO_TRACKER_API_URL: string = 'https://feodotracker.abuse.ch/downloads/ipblocklist_recommended.txt';
|
private static readonly FEODO_TRACKER_API_URL: string = 'https://feodotracker.abuse.ch/downloads/ipblocklist.json';
|
||||||
|
|
||||||
public async getData(): Promise<IFeodoTrackerData[]> {
|
public async getData(): Promise<IFeodoTrackerData[]> {
|
||||||
plugins.smartfile.fs.ensureDirSync(paths.feodoTrackerTmp);
|
|
||||||
const txtPath = plugins.path.join(paths.feodoTrackerTmp, 'feodo.txt');
|
|
||||||
|
|
||||||
const response = await plugins.nodeFetch(FeodoTracker.FEODO_TRACKER_API_URL, {
|
const response = await plugins.nodeFetch(FeodoTracker.FEODO_TRACKER_API_URL, {
|
||||||
...(helpers.findProxy() ? {
|
...(helpers.findProxy() ? {
|
||||||
agent: helpers.getAgent(),
|
agent: helpers.getAgent(),
|
||||||
} : {})
|
} : {})
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
throw new Error(`HTTP error! status: ${response.status}`);
|
throw new Error(`HTTP error! status: ${response.status}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
await new Promise((resolve, reject) => {
|
const data: IFeodoTrackerData[] = await response.json() as IFeodoTrackerData[];
|
||||||
const fileStream = plugins.fs.createWriteStream(txtPath);
|
|
||||||
// @ts-ignore
|
|
||||||
const readable = plugins.stream.Readable.from(response.body);
|
|
||||||
plugins.stream.pipeline(readable, fileStream, (err) => {
|
|
||||||
if (err) reject(err);
|
|
||||||
else resolve(null);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
let data: IFeodoTrackerData[] = [];
|
// Ensure the data is an array and has the expected structure
|
||||||
await new Promise((resolve, reject) => {
|
if (!Array.isArray(data) || !data.every(item =>
|
||||||
plugins.stream.pipeline(
|
typeof item.ip_address === 'string' &&
|
||||||
plugins.fs.createReadStream(txtPath),
|
typeof item.port === 'number' &&
|
||||||
plugins.csv({
|
(typeof item.hostname === 'string' || item.hostname === null) &&
|
||||||
headers: ['ID', 'Dateadded', 'DestinationIP', 'DestinationPort', 'Malware', 'Reporter'],
|
typeof item.as_number === 'number' &&
|
||||||
mapValues: ({ header, value }) => value.trim()
|
typeof item.as_name === 'string' &&
|
||||||
}),
|
typeof item.country === 'string' &&
|
||||||
(err) => {
|
typeof item.first_seen === 'string' &&
|
||||||
if (err) reject(err);
|
typeof item.last_online === 'string' &&
|
||||||
|
typeof item.malware === 'string'
|
||||||
|
)) {
|
||||||
|
throw new Error(`Invalid data structure!`);
|
||||||
}
|
}
|
||||||
)
|
|
||||||
.on('data', (row) => {
|
|
||||||
data.push(row);
|
|
||||||
})
|
|
||||||
.on('end', resolve)
|
|
||||||
.on('error', reject);
|
|
||||||
});
|
|
||||||
|
|
||||||
plugins.smartfile.fs.removeSync(paths.feodoTrackerTmp);
|
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user