-
Notifications
You must be signed in to change notification settings - Fork 29
/
utility_linux.go
113 lines (101 loc) · 3.28 KB
/
utility_linux.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package main
import (
"crypto/md5"
"io"
"io/ioutil"
"os"
"os/exec"
"os/user"
"strconv"
)
// readFile (Linux) wraps ioutil's ReadFile function.
func readFile(fileName string) (string, error) {
fileContent, err := ioutil.ReadFile(fileName)
return string(fileContent), err
}
// decodeString (linux) strictly does nothing, however it's here
// for compatibility with Windows ANSI/UNICODE/etc.
func decodeString(fileContent string) (string, error) {
return fileContent, nil
}
// sendNotification sends a notification to the end user.
func sendNotification(messageString string) {
if conf.User == "" {
fail("User not specified in configuration, can't send notification.")
} else {
err := shellCommand(`
user="` + conf.User + `"
uid="$(id -u $user)" # Ubuntu >= 18
if [ -e /run/user/$uid/bus ]; then
display="unix:path=/run/user/$uid/bus"
else # Ubuntu <= 16
display="unix:abstract=$(cat /run/user/$uid/dbus-session | cut -d '=' -f3)"
fi
sudo -u $user DISPLAY=:0 DBUS_SESSION_BUS_ADDRESS=$display notify-send -i ` + dirPath + `assets/img/logo.png "Aeacus SE" "` + messageString + `"`)
if err != nil {
fail("Sending notification failed. Is the user in the configuration correct, and are they logged in to a desktop environment?")
}
}
}
func checkTrace() {
result, err := cond{
Path: "/proc/self/status",
Value: `^TracerPid:\s+0$`,
regex: true,
}.FileContains()
// If there was an error reading the file, the user may be restricting access to /proc for the phocus binary
// through tools such as AppArmor. In this case, the engine should error out.
if !result || err != nil {
fail("Try harder instead of ptracing the engine, please.")
os.Exit(1)
}
}
// createFQs is a quality of life function that creates Forensic Question files
// on the Desktop, pre-populated with a template.
func CreateFQs(numFqs int) {
for i := 1; i <= numFqs; i++ {
fileName := "'Forensic Question " + strconv.Itoa(i) + ".txt'"
shellCommand("echo 'QUESTION:' > /home/" + conf.User + "/Desktop/" + fileName)
shellCommand("echo 'ANSWER:' >> /home/" + conf.User + "/Desktop/" + fileName)
info("Wrote " + fileName + " to Desktop")
}
}
// rawCmd returns a exec.Command object for Linux shell commands.
func rawCmd(commandGiven string) *exec.Cmd {
return exec.Command("/bin/sh", "-c", commandGiven)
}
// playAudio plays a .wav file with the given path.
func playAudio(wavPath string) {
info("Playing audio:", wavPath)
commandText := "aplay " + wavPath
shellCommand(commandText)
}
// hashFileMD5 generates the MD5 Hash of a file with the given path.
func hashFileMD5(filePath string) (string, error) {
var returnMD5String string
file, err := os.Open(filePath)
if err != nil {
return returnMD5String, err
}
defer file.Close()
hash := md5.New()
if _, err := io.Copy(hash, file); err != nil {
return returnMD5String, err
}
hashInBytes := hash.Sum(nil)[:16]
return hexEncode(string(hashInBytes)), err
}
func adminCheck() bool {
currentUser, err := user.Current()
uid, _ := strconv.Atoi(currentUser.Uid)
if err != nil {
fail("Error for checking if running as root: " + err.Error())
return false
} else if uid != 0 {
return false
}
return true
}
func getInfo(infoType string) {
warn("Info gathering is not supported for Linux-- there's always a better, easier command-line tool.")
}