From c9332fe024e4ce7c9c014dd6840a04aa9ba160d2 Mon Sep 17 00:00:00 2001 From: Fernando Guisso Date: Mon, 18 Jul 2022 20:43:01 +0000 Subject: [PATCH] utils: adding parse flags function Thanks to @roziscoding and @pauloricardokoch for the regex help. --- dist/index.js | 9 ++++++++- src/index.js | 4 +++- src/utils.js | 4 ++++ 3 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 src/utils.js diff --git a/dist/index.js b/dist/index.js index 1c73120..cb44d9a 100644 --- a/dist/index.js +++ b/dist/index.js @@ -9867,12 +9867,18 @@ async function generateGithubReportFile(token) { reject(err); }); } +;// CONCATENATED MODULE: ./src/utils.js +function parseFlagsToArray(rawFlags) { + const re = /(?:(?:^|\s)-[-a-z]+)(?:(?:\s|=)(?:[^-][0-9a-z-\S]+))?/g; + return rawFlags.match(re).map(token => token.trim()).map(token => token.replace(' ', '=')); +} ;// CONCATENATED MODULE: ./src/index.js + const target = core.getInput('target', { required: false }); const urls = core.getInput('urls', { required: false }); const templates = core.getInput('templates', { required: false }); @@ -9925,11 +9931,12 @@ async function run() { if (reportConfig) params.push(`-rc=${reportConfig}`); if (config) params.push(`-config=${config}`); if (userAgent) params.push(`-H=${userAgent}`); - if (flags) params.push(flags); params.push(`-o=${ output ? output : 'nuclei.log' }`); if (src_json) params.push('-json'); if (includeRR) params.push('-irr'); + if (flags) params.push(...parseFlagsToArray(flags)); + // If everything is fine and github-report is set, generate the yaml config file. if (githubRepot) { await generateGithubReportFile(githubToken); diff --git a/src/index.js b/src/index.js index 1562f5e..eb2d1a0 100644 --- a/src/index.js +++ b/src/index.js @@ -2,6 +2,7 @@ import * as core from '@actions/core'; import * as exec from '@actions/exec'; import * as installer from './installer'; import { generateGithubReportFile } from './yaml'; +import { parseFlagsToArray } from './utils'; const target = core.getInput('target', { required: false }); const urls = core.getInput('urls', { required: false }); @@ -55,11 +56,12 @@ async function run() { if (reportConfig) params.push(`-rc=${reportConfig}`); if (config) params.push(`-config=${config}`); if (userAgent) params.push(`-H=${userAgent}`); - if (flags) params.push(flags); params.push(`-o=${ output ? output : 'nuclei.log' }`); if (json) params.push('-json'); if (includeRR) params.push('-irr'); + if (flags) params.push(...parseFlagsToArray(flags)); + // If everything is fine and github-report is set, generate the yaml config file. if (githubRepot) { await generateGithubReportFile(githubToken); diff --git a/src/utils.js b/src/utils.js new file mode 100644 index 0000000..78147b2 --- /dev/null +++ b/src/utils.js @@ -0,0 +1,4 @@ +export function parseFlagsToArray(rawFlags) { + const re = /(?:(?:^|\s)-[-a-z]+)(?:(?:\s|=)(?:[^-][0-9a-z-\S]+))?/g; + return rawFlags.match(re).map(token => token.trim()).map(token => token.replace(' ', '=')); +} \ No newline at end of file