From 83fb5081229e94174748e3faa8d4cfeb06e21f2d Mon Sep 17 00:00:00 2001 From: Che4ter Date: Mon, 24 Apr 2023 14:37:32 +0200 Subject: [PATCH 1/3] Create Generic.Remediation.UploadFile.Glob.yaml Create an artifact to upload a file to the target destination. If the target already exists, it will be overridden. The artefact uses the glob, so you can upload the file to multiple locations at once. --- .../Generic.Remediation.UploadFile.Glob.yaml | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 content/exchange/artifacts/Generic.Remediation.UploadFile.Glob.yaml diff --git a/content/exchange/artifacts/Generic.Remediation.UploadFile.Glob.yaml b/content/exchange/artifacts/Generic.Remediation.UploadFile.Glob.yaml new file mode 100644 index 00000000000..c49cb943eea --- /dev/null +++ b/content/exchange/artifacts/Generic.Remediation.UploadFile.Glob.yaml @@ -0,0 +1,34 @@ +name: Generic.Remediation.UploadFile.Glob +description: | + This artefact lets you upload a file to the target system. If the target file exists, it will be overridden. + It uses glob to define the destination path. You can upload the file to multiple destinations at once. + +type: CLIENT + +parameters: + - name: TargetGlob + description: Destination Path, if the destination already exists, it will be overridden + - name: ReallyDoIt + description: When selected, it will really override the targets! + type: bool + +tools: + - name: RemediationFile + url: + +sources: + - query: | + LET targets = SELECT * FROM glob(globs=TargetGlob) + WHERE NOT if(condition=TRUE, + then= IsDir, + else= FALSE) + ORDER BY OSPath DESC + + LET UploadedFile <= SELECT FullPath FROM Artifact.Generic.Utils.FetchBinary(ToolName="RemediationFile", IsExecutable=FALSE, TemporaryOnly=TRUE) + + LET upload_targets = SELECT *, copy(filename=UploadedFile.FullPath[0], accessor="file", dest=OSPath) as Overridden FROM targets + + SELECT OSPath,Overridden,Size,Mtime,Ctime,Btime,IsDir,IsLink + FROM if(condition=ReallyDoIt, + then= upload_targets, + else= { SELECT *, FALSE as Overridden FROM upload_targets } ) From 3bfe5ef34600f2c3d87a790685bf68bb031d8493 Mon Sep 17 00:00:00 2001 From: Che4ter Date: Thu, 27 Apr 2023 07:15:48 +0200 Subject: [PATCH 2/3] Update Generic.Remediation.UploadFile.Glob.yaml Fix copy past error in the directory exclusion --- .../artifacts/Generic.Remediation.UploadFile.Glob.yaml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/content/exchange/artifacts/Generic.Remediation.UploadFile.Glob.yaml b/content/exchange/artifacts/Generic.Remediation.UploadFile.Glob.yaml index c49cb943eea..de9b62d14ac 100644 --- a/content/exchange/artifacts/Generic.Remediation.UploadFile.Glob.yaml +++ b/content/exchange/artifacts/Generic.Remediation.UploadFile.Glob.yaml @@ -19,9 +19,7 @@ tools: sources: - query: | LET targets = SELECT * FROM glob(globs=TargetGlob) - WHERE NOT if(condition=TRUE, - then= IsDir, - else= FALSE) + WHERE NOT IsDir ORDER BY OSPath DESC LET UploadedFile <= SELECT FullPath FROM Artifact.Generic.Utils.FetchBinary(ToolName="RemediationFile", IsExecutable=FALSE, TemporaryOnly=TRUE) From 7c26096ebfb1b8af790ac9b5ad3878c4aca17c47 Mon Sep 17 00:00:00 2001 From: Che4ter Date: Fri, 12 May 2023 14:56:48 +0200 Subject: [PATCH 3/3] Update Generic.Remediation.UploadFile.Glob.yaml Fixed unsafe override protection. --- .../Generic.Remediation.UploadFile.Glob.yaml | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/content/exchange/artifacts/Generic.Remediation.UploadFile.Glob.yaml b/content/exchange/artifacts/Generic.Remediation.UploadFile.Glob.yaml index de9b62d14ac..83aa92ee088 100644 --- a/content/exchange/artifacts/Generic.Remediation.UploadFile.Glob.yaml +++ b/content/exchange/artifacts/Generic.Remediation.UploadFile.Glob.yaml @@ -1,8 +1,8 @@ name: Generic.Remediation.UploadFile.Glob description: | - This artefact lets you upload a file to the target system. If the target file exists, it will be overridden. + This artefact lets you upload a file to the target system. If the target file exists, it will be overritten. It uses glob to define the destination path. You can upload the file to multiple destinations at once. - +author: Philipp Leu type: CLIENT parameters: @@ -24,9 +24,7 @@ sources: LET UploadedFile <= SELECT FullPath FROM Artifact.Generic.Utils.FetchBinary(ToolName="RemediationFile", IsExecutable=FALSE, TemporaryOnly=TRUE) - LET upload_targets = SELECT *, copy(filename=UploadedFile.FullPath[0], accessor="file", dest=OSPath) as Overridden FROM targets - - SELECT OSPath,Overridden,Size,Mtime,Ctime,Btime,IsDir,IsLink - FROM if(condition=ReallyDoIt, - then= upload_targets, - else= { SELECT *, FALSE as Overridden FROM upload_targets } ) + LET upload_targets = SELECT *, if(condition=ReallyDoIt, then=copy(filename=UploadedFile.FullPath[0], accessor="file", dest=OSPath), else=FALSE) AS Overwritten FROM targets + + SELECT OSPath,Overwritten,Size,Mtime,Ctime,Btime + FROM upload_targets