Skip to content

Commit f93883b

Browse files
authored
Merge pull request #256 from slimm609/add_fortifyProc
add fortifyProc
2 parents aeb249e + 7c8a21c commit f93883b

File tree

5 files changed

+62
-32
lines changed

5 files changed

+62
-32
lines changed

.github/workflows/pull_request.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,7 @@ jobs:
1919
exit 1
2020
fi
2121
- name: ubuntu checksec
22-
run: docker-compose run checksec-ubuntu
22+
run: |
23+
curl -L "https://github.com/docker/compose/releases/download/v2.29.2/docker-compose-linux-x86_64" -o /usr/local/bin/docker-compose
24+
chmod +x /usr/local/bin/docker-compose
25+
docker-compose run checksec-ubuntu

cmd/fortifyFile.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package cmd
33
import (
44
"checksec/pkg/checksec"
55
"checksec/pkg/utils"
6+
"fmt"
7+
"os"
68

79
"github.com/spf13/cobra"
810
)
@@ -12,6 +14,10 @@ var fortifyFileCmd = &cobra.Command{
1214
Use: "fortifyFile",
1315
Short: "Check Fortify for binary file",
1416
Run: func(cmd *cobra.Command, args []string) {
17+
if len(args) != 1 {
18+
fmt.Printf("Error: no filename provided")
19+
os.Exit(1)
20+
}
1521
file := args[0]
1622

1723
utils.CheckElfExists(file)

cmd/fortifyProc.go

Lines changed: 52 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
package cmd
22

33
import (
4+
"checksec/pkg/checksec"
5+
"checksec/pkg/utils"
46
"fmt"
7+
"os"
8+
"path/filepath"
59

610
"github.com/spf13/cobra"
711
)
@@ -11,20 +15,57 @@ var fortifyProcCmd = &cobra.Command{
1115
Use: "fortifyProc",
1216
Short: "Check Fortify for running process",
1317
Run: func(cmd *cobra.Command, args []string) {
14-
fmt.Println("fortifyProc called")
18+
if len(args) != 1 {
19+
fmt.Printf("Error: no process id provided")
20+
os.Exit(1)
21+
}
22+
proc := args[0]
23+
24+
file, err := os.Readlink(filepath.Join("/proc", proc, "exe"))
25+
if err != nil {
26+
fmt.Printf("Error: Pid %s not found", proc)
27+
os.Exit(1)
28+
}
29+
30+
utils.CheckElfExists(file)
31+
binary := utils.GetBinary(file)
32+
fortify := checksec.Fortify(file, binary)
33+
output := []interface{}{
34+
map[string]interface{}{
35+
"name": file,
36+
"checks": map[string]interface{}{
37+
"fortify_source": fortify.Output,
38+
"fortified": fortify.Fortified,
39+
"fortifyable": fortify.Fortifiable,
40+
"noFortify": fortify.NoFortify,
41+
"libcSupport": fortify.LibcSupport,
42+
"numLibcFunc": fortify.NumLibcFunc,
43+
"numFileFunc": fortify.NumFileFunc,
44+
},
45+
},
46+
}
47+
color := []interface{}{
48+
map[string]interface{}{
49+
"name": file,
50+
"checks": map[string]interface{}{
51+
"fortified": fortify.Fortified,
52+
"fortifiedColor": "unset",
53+
"noFortify": fortify.NoFortify,
54+
"fortifyable": fortify.Fortifiable,
55+
"fortifyableColor": "unset",
56+
"fortify_source": fortify.Output,
57+
"fortify_sourceColor": fortify.Color,
58+
"libcSupport": fortify.LibcSupport,
59+
"libcSupportColor": fortify.LibcSupportColor,
60+
"numLibcFunc": fortify.NumLibcFunc,
61+
"numFileFunc": fortify.NumFileFunc,
62+
},
63+
},
64+
}
65+
utils.FortifyPrinter(outputFormat, output, color)
1566
},
1667
}
1768

1869
func init() {
1970
rootCmd.AddCommand(fortifyProcCmd)
20-
21-
// Here you will define your flags and configuration settings.
22-
23-
// Cobra supports Persistent Flags which will work for this command
24-
// and all subcommands, e.g.:
25-
// fortifyProcCmd.PersistentFlags().String("foo", "", "A help for foo")
26-
27-
// Cobra supports local flags which will only run when this command
28-
// is called directly, e.g.:
29-
// fortifyProcCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
3071
}

cmd/kernel.go

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,4 @@ var kernelCmd = &cobra.Command{
2727

2828
func init() {
2929
rootCmd.AddCommand(kernelCmd)
30-
31-
// Here you will define your flags and configuration settings.
32-
33-
// Cobra supports Persistent Flags which will work for this command
34-
// and all subcommands, e.g.:
35-
// kernelCmd.PersistentFlags().String("foo", "", "A help for foo")
36-
37-
// Cobra supports local flags which will only run when this command
38-
// is called directly, e.g.:
39-
// kernelCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
4030
}

cmd/procLibs.go

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,4 @@ var procLibsCmd = &cobra.Command{
1717

1818
func init() {
1919
rootCmd.AddCommand(procLibsCmd)
20-
21-
// Here you will define your flags and configuration settings.
22-
23-
// Cobra supports Persistent Flags which will work for this command
24-
// and all subcommands, e.g.:
25-
// procLibsCmd.PersistentFlags().String("foo", "", "A help for foo")
26-
27-
// Cobra supports local flags which will only run when this command
28-
// is called directly, e.g.:
29-
// procLibsCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
3020
}

0 commit comments

Comments
 (0)