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

Update ioc extractor #584

Merged
merged 2 commits into from
Jul 4, 2021
Merged
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
87 changes: 52 additions & 35 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"@github/mini-throttle": "^2.1.0",
"axios": "^0.21.1",
"bulma": "^0.9.2",
"ioc-extractor": "2.7.7",
"ioc-extractor": "3.0.0",
"js-base64": "^3.6.1",
"js-sha256": "^0.9.0",
"mustache": "^4.2.0",
Expand Down
11 changes: 5 additions & 6 deletions src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,8 @@ export async function saveApiKeys(): Promise<void> {
export async function saveSearcherStates(): Promise<void> {
const searcherStates: SearcherStates = {};
const searcherList = document.getElementById("searcher-list") as HTMLElement;
const radios = searcherList.querySelectorAll<HTMLInputElement>(
'[type="checkbox"]'
);
const radios =
searcherList.querySelectorAll<HTMLInputElement>('[type="checkbox"]');
for (const radio of radios) {
const name = radio.getAttribute("name");
if (name === null) {
Expand Down Expand Up @@ -115,9 +114,9 @@ export async function restoreGeneralSettings(): Promise<void> {
"general-settings"
) as HTMLElement;
const fragment: DocumentFragment = document.createDocumentFragment();
const template = (document.getElementById(
"general-settings-template"
) as HTMLElement).innerHTML;
const template = (
document.getElementById("general-settings-template") as HTMLElement
).innerHTML;

const elem = document.createElement("div");
elem.innerHTML = Mustache.render(template, generalSettings);
Expand Down
79 changes: 35 additions & 44 deletions src/selector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,64 +43,66 @@ export class Selector {
}

public getIP(): string | null {
return this.getFirstValueFromArray(extractIPv4(this.input));
return extractIPv4(this.input);
}

public getDomain(): string | null {
return this.getFirstValueFromArray(
extractDomain(this.input, this.enableIDN, this.strictTLD)
);
return extractDomain(this.input, this.enableIDN, this.strictTLD);
}

public getURL(): string | null {
return this.getFirstValueFromArray(
extractURL(this.input, this.enableIDN, this.strictTLD)
);
return extractURL(this.input, this.enableIDN, this.strictTLD);
}

public getEmail(): string | null {
return this.getFirstValueFromArray(
extractEmail(this.input, this.enableIDN, this.strictTLD)
);
return extractEmail(this.input, this.enableIDN, this.strictTLD);
}

public getASN(): string | null {
return this.getFirstValueFromArray(extractASN(this.input));
return extractASN(this.input);
}

public getHash(): string | null {
let hashes: string[] = [];
hashes = this.concat(hashes, extractSHA256(this.input));
hashes = this.concat(hashes, extractSHA1(this.input));
hashes = this.concat(hashes, extractMD5(this.input));
if (hashes.length === 0) {
return null;
const sha256 = extractSHA256(this.input);
if (sha256 !== null) {
return sha256;
}

const sha1 = extractSHA1(this.input);
if (sha1 !== null) {
return sha1;
}

const md5 = extractMD5(this.input);
if (md5 !== null) {
return md5;
}
return hashes[0];

return null;
}

public getCVE(): string | null {
return this.getFirstValueFromArray(extractCVE(this.input));
return extractCVE(this.input);
}

public getBTC(): string | null {
return this.getFirstValueFromArray(extractBTC(this.input));
return extractBTC(this.input);
}

public getXMR(): string | null {
return this.getFirstValueFromArray(extractXMR(this.input));
return extractXMR(this.input);
}

public getGATrackID(): string | null {
return this.getFirstValueFromArray(extractGATrackID(this.input));
return extractGATrackID(this.input);
}

public getGAPubID(): string | null {
return this.getFirstValueFromArray(extractGAPubID(this.input));
return extractGAPubID(this.input);
}

public getETH(): string | null {
return this.getFirstValueFromArray(extractETH(this.input));
return extractETH(this.input);
}

public getSearchersByType(type: SearchableType): Searcher[] {
Expand All @@ -116,7 +118,7 @@ export class Selector {
}

public IsPossibleNetworkIndicator(): boolean {
return this.input.includes(".") || this.input.includes("dot");
return this.input.includes(".");
}

private getSelectorSlots(): SelectorSlot[] {
Expand Down Expand Up @@ -156,9 +158,10 @@ export class Selector {
const result = func.apply(this);
if (result !== null) {
console.debug(`Mitaka: ${type} is selected. value = ${result}.`);
return this.concat(
entries,
this.makeAnalyzerEntries(this.getSearchersByType(type), type, result)
return this.makeAnalyzerEntries(
this.getSearchersByType(type),
type,
result
);
}
}
Expand All @@ -181,29 +184,17 @@ export class Selector {

const result = func.apply(this);
if (result !== null) {
return entries.concat(
this.makeAnalyzerEntries(this.getScannersByType(type), type, result)
return this.makeAnalyzerEntries(
this.getScannersByType(type),
type,
result
);
}
}

return entries;
}

private getFirstValueFromArray<T>(array: T[] | null): T | null {
if (array !== null && array[0]) {
return array[0];
}
return null;
}

private concat<T>(target: T[], input: T[] | null): T[] {
if (input !== null) {
return target.concat(input);
}
return target;
}

private makeAnalyzerEntries(
analyzers: Scanner[] | Searcher[],
type: SearchableType | ScannableType,
Expand Down