Skip to content

Commit bfe00e6

Browse files
authored
Fixed Crash Bugs with Automations
Fixed Crash Bugs with Automations
2 parents 87a2011 + dfdfbd8 commit bfe00e6

File tree

9 files changed

+11115
-56
lines changed

9 files changed

+11115
-56
lines changed

Dockerfile

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,18 @@ RUN apt-get update && \
3838
apt-get install -y --no-install-recommends ripgrep && \
3939
apt-get clean && \
4040
rm -rf /var/lib/apt/lists/*
41+
4142
WORKDIR /app
4243

4344
COPY . .
4445

45-
RUN go mod download && \
46-
go build -o morf .
46+
RUN go mod download
47+
48+
ENV GOARCH=arm64
49+
ENV GOOS=linux
50+
ENV CGO_ENABLED=0
51+
52+
RUN go build -v -x -o morf .
4753

4854
EXPOSE 8888
4955

apk/analysis.go

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import (
2727
log "github.com/sirupsen/logrus"
2828

2929
"github.com/gin-gonic/gin"
30-
vip "github.com/spf13/viper"
3130
"gorm.io/gorm"
3231
)
3332

@@ -42,6 +41,7 @@ func StartCliExtraction(apkPath string, db *gorm.DB, is_db_req bool) {
4241
log.Info(json_data)
4342
}
4443
}
44+
4545
packageModel := ExtractPackageData(apkPath)
4646
metadata := StartMetaDataCollection(apkPath)
4747

@@ -54,7 +54,6 @@ func StartCliExtraction(apkPath string, db *gorm.DB, is_db_req bool) {
5454
}
5555

5656
scanner_data := StartSecScan(utils.GetInputDir() + fileName)
57-
scanner_data = utils.SanitizeSecrets(scanner_data)
5857
secret_data, secret_error := json.Marshal(scanner_data)
5958

6059
if secret_error != nil {
@@ -78,16 +77,11 @@ func StartCliExtraction(apkPath string, db *gorm.DB, is_db_req bool) {
7877
util.CreateBackUpDir(fs)
7978
}
8079

81-
util.WriteToFile(fs, vip.GetString("backup_path")+fileName+"_"+secret.APKVersion+".json", string(json_data))
82-
util.WriteToFile(fs, vip.GetString("backup_path")+fileName+"_"+"Secrets_"+secret.APKVersion+".json", string(secret_data))
83-
84-
util.WriteToFile(fs, "results"+"/"+fileName+"_"+secret.APKVersion+".json", string(json_data))
85-
util.WriteToFile(fs, "results"+"/"+fileName+"_"+"Secrets_"+secret.APKVersion+".json", string(secret_data))
86-
87-
log.Info("APK Data saved to: " + vip.GetString("backup_path") + "/" + fileName + "_" + secret.APKVersion + ".json")
80+
utils.CreateReport(fs, secret, json_data, secret_data, fileName)
8881
}
8982

9083
func StartJiraProcess(jiramodel models.JiraModel, db *gorm.DB, c *gin.Context) {
84+
9185
apk_path := util.DownloadFileUsingSlack(jiramodel, c)
9286
if apk_path == "" {
9387
return
@@ -114,6 +108,7 @@ func StartJiraProcess(jiramodel models.JiraModel, db *gorm.DB, c *gin.Context) {
114108
if secret_error != nil {
115109
log.Error(secret_error)
116110
}
111+
117112
secret := util.CreateSecretModel(apk_path, packageModel, metadata, scanner_data, secret_data)
118113
database.InsertSecrets(secret, db)
119114

@@ -158,17 +153,12 @@ func StartExtractProcess(apkPath string, db *gorm.DB, c *gin.Context, isSlack bo
158153
log.Error(json_error)
159154
}
160155

161-
//Check if backup folder exists
162156
//Check if backup folder exists
163157
if !util.CheckBackUpDirExists(fs) {
164158
util.CreateBackUpDir(fs)
165159
}
166160

167-
util.WriteToFile(fs, vip.GetString("backup_path")+apkPath+"_"+secret.APKVersion+".json", string(json_data))
168-
util.WriteToFile(fs, vip.GetString("backup_path")+apkPath+"_"+"Secrets_"+secret.APKVersion+".json", string(secret_data))
169-
170-
util.WriteToFile(fs, "results"+"/"+apkPath+"_"+secret.APKVersion+".json", string(json_data))
171-
util.WriteToFile(fs, "results"+"/"+apkPath+"_"+"Secrets_"+secret.APKVersion+".json", string(secret_data))
161+
utils.CreateReport(fs, secret, json_data, secret_data, apkPath)
172162

173163
if !isSlack {
174164
c.JSON(http.StatusOK, gin.H{

apk/metadata.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ func StartMetaDataCollection(apkPath string) models.MetaDataModel {
5050
}
5151

5252
// Move APK to input directory
53-
5453
apkPath = utils.CopyApktoInputDir(fs, apkPath)
5554
fmt.Println("Starting metadata collection for " + apkPath)
5655

apk/packageparse.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,10 @@ func ExtractPackageData(apkPath string) models.PackageDataModel {
3737
log.Error("AAPT not found in the system")
3838
log.Error("Please install AAPT or add it to the system path")
3939
aapt_success, aapt_error = exec.Command("tools/aapt", "dump", "badging", apkPath).Output()
40+
} else {
41+
aapt_success, aapt_error = exec.Command("aapt", "dump", "badging", apkPath).Output()
4042
}
4143

42-
aapt_success, aapt_error = exec.Command("aapt", "dump", "badging", apkPath).Output()
4344
aapt_byte_to_string := aapt_success[:]
4445

4546
if aapt_error != nil {

apk/scanner.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,7 @@ type PatternList struct {
5252
var secretPatterns SecretPatterns
5353
var secretModel []models.SecretModel
5454

55-
func CheckAPK(apkPath string) {
56-
PacakgeData := ExtractPackageData("scan.apk")
57-
log.Info(PacakgeData)
58-
}
59-
6055
func StartSecScan(apkPath string) []models.SecretModel {
61-
//Decompile the sources of the APK file
62-
6356
counter := 0
6457
log.Println("Decompiling the APK file for sources")
6558
fmt.Println(apkPath)
@@ -82,7 +75,7 @@ func StartSecScan(apkPath string) []models.SecretModel {
8275

8376
if counter == 2 {
8477
log.Println("Decompiling the APK file successful")
85-
return StartScan(utils.GetFilesDir())
78+
return utils.SanitizeSecrets(StartScan(utils.GetSourceDir()))
8679
}
8780

8881
return nil
@@ -95,6 +88,7 @@ func readPatternFile(patternFilePath string) []byte {
9588
}
9689

9790
func StartScan(apkPath string) []models.SecretModel {
91+
log.Info("Scanning for secrets in the code")
9892
files := utils.ReadDir(utils.GetAppFS(), "patterns")
9993

10094
var wg sync.WaitGroup

0 commit comments

Comments
 (0)