Skip to content

Commit a60daa6

Browse files
committed
artifact detection cleanup
Signed-off-by: Kyle Quest <kcq.public@gmail.com>
1 parent ff8c378 commit a60daa6

File tree

2 files changed

+25
-9
lines changed

2 files changed

+25
-9
lines changed

pkg/app/sensor/artifact/artifact.go

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -191,15 +191,25 @@ func isAppMetadataFile(filePath string) bool {
191191
}
192192

193193
var binDataReplace = []fsutil.ReplaceInfo{
194+
{
195+
PathSuffix: "/curl",
196+
Match: "curl/",
197+
Replace: "kerl/",
198+
},
194199
{
195200
PathSuffix: "/node",
196201
Match: "node.js/v",
197202
Replace: "done,xu/v",
198203
},
199204
{
200-
PathSuffix: "/curl",
201-
Match: "curl/",
202-
Replace: "kerl/",
205+
PathSuffix: "/bash",
206+
Match: "@(#)Bash version",
207+
Replace: "@(#)Nash wersion",
208+
},
209+
{
210+
PathSuffix: "/nginx",
211+
Match: "nginx version: ",
212+
Replace: "xginn wersion: ",
203213
},
204214
}
205215

@@ -223,6 +233,10 @@ const (
223233
OMPObfuscateAPN = "obfuscate_apn"
224234
)
225235

236+
var (
237+
BinFileExtra = []byte("OFH")
238+
)
239+
226240
func init() {
227241
rand.Seed(time.Now().UnixNano())
228242
}
@@ -2192,16 +2206,17 @@ copyFiles:
21922206
} else {
21932207
//NOTE: this covers the main file set (doesn't cover the extra includes)
21942208
binProps, err := binfile.Detected(filePath)
2195-
if err == nil && binProps != nil && binProps.IsBin && binProps.IsExe {
2196-
if err := fsutil.AppendToFile(filePath, []byte("KCQ"), true); err != nil {
2209+
if err == nil && binProps != nil && binProps.IsBin {
2210+
//not checking binProps.IsExe because Go's ELF header type decoding is unreliable...
2211+
if err := fsutil.AppendToFile(filePath, BinFileExtra, true); err != nil {
21972212
logger.Debugf("[%s,%s] - fsutil.AppendToFile error => %v", srcFileName, filePath, err)
21982213
} else {
21992214
logger.Tracef("binfile.Detected[IsExe]/fsutil.AppendToFile - %s", filePath)
2215+
}
22002216

2201-
err := fsutil.ReplaceFileData(filePath, binDataReplace, true)
2202-
if err != nil {
2203-
logger.Debugf("[%s,%s] - fsutil.ReplaceFileData error => %v", srcFileName, filePath, err)
2204-
}
2217+
err := fsutil.ReplaceFileData(filePath, binDataReplace, true)
2218+
if err != nil {
2219+
logger.Debugf("[%s,%s] - fsutil.ReplaceFileData error => %v", srcFileName, filePath, err)
22052220
}
22062221
}
22072222
}

pkg/app/sensor/detector/binfile/binfile.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ func Detected(filePath string) (*BinProps, error) {
2020
IsBin: true,
2121
}
2222

23+
//note: Go elf header decoding bug... ET_EXEC gets decoded as ET_DYN sometimes
2324
switch binFile.Type {
2425
case elf.ET_EXEC:
2526
binProps.IsExe = true

0 commit comments

Comments
 (0)