mirror of
https://github.com/portbuster1337/ArachneC2
synced 2026-06-14 08:40:53 +00:00
c9fb32fbcd
- Renamed protobuf packages: arachnepb→apb, commonpb→cpb, rpcpb→rpb - Renamed protobuf types to opaque Z-series (BeaconRegister→Z1, etc.) - Renamed RPC from ArachneRPC→S, methods GetVersion→M0, etc. - Changed protocol IDs: /arachne/shell/1.0.0 → /x/sh/1.0.0, etc. - Changed pubsub topic prefixes: /arachne/ → /c/, /beacons/ → /b/ - Per-implant task routing (TaskTopic) instead of shared CommandTopic - Fixed Windows shell: HideWindow, merged stderr, LF→CRLF conversion - Fixed io.Copy Write contract violation in shell stdin path - Fixed ListImplants() sorting for stable select ordering - Added garble -literals -tiny flags, PATH propagation for generate - Added bootstrap IP fallbacks for bypassing DNS blocking - Updated all docs to reflect new wire format
104 lines
2.2 KiB
Go
104 lines
2.2 KiB
Go
package core
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"os/exec"
|
|
"path/filepath"
|
|
"runtime"
|
|
"strconv"
|
|
"strings"
|
|
|
|
cpb "github.com/portbuster1337/ArachneC2/protobuf/cpb"
|
|
)
|
|
|
|
func listProcesses() []*cpb.Process {
|
|
switch runtime.GOOS {
|
|
case "linux":
|
|
return listProcessesLinux()
|
|
case "windows":
|
|
return listProcessesWindows()
|
|
default:
|
|
return listProcessesDummy()
|
|
}
|
|
}
|
|
|
|
func listProcessesWindows() []*cpb.Process {
|
|
cmd := exec.Command("tasklist", "/FO", "CSV", "/NH")
|
|
out, err := cmd.Output()
|
|
if err != nil {
|
|
return listProcessesDummy()
|
|
}
|
|
var procs []*cpb.Process
|
|
lines := strings.Split(string(out), "\n")
|
|
for _, line := range lines {
|
|
line = strings.TrimSpace(line)
|
|
if line == "" {
|
|
continue
|
|
}
|
|
parts := strings.Split(line, ",")
|
|
if len(parts) < 2 {
|
|
continue
|
|
}
|
|
name := strings.Trim(parts[0], `"`)
|
|
pidStr := strings.Trim(parts[1], `"`)
|
|
pid, _ := strconv.Atoi(pidStr)
|
|
owner := ""
|
|
if len(parts) >= 8 {
|
|
owner = strings.Trim(parts[7], `"`)
|
|
}
|
|
procs = append(procs, &cpb.Process{Pid: int32(pid), Name: name, Owner: owner})
|
|
}
|
|
return procs
|
|
}
|
|
|
|
func listProcessesLinux() []*cpb.Process {
|
|
entries, err := os.ReadDir("/proc")
|
|
if err != nil {
|
|
return listProcessesDummy()
|
|
}
|
|
|
|
var procs []*cpb.Process
|
|
for _, e := range entries {
|
|
if !e.IsDir() {
|
|
continue
|
|
}
|
|
pid, err := strconv.Atoi(e.Name())
|
|
if err != nil {
|
|
continue
|
|
}
|
|
|
|
p := &cpb.Process{Pid: int32(pid)}
|
|
|
|
stat, _ := os.ReadFile(filepath.Join("/proc", e.Name(), "stat"))
|
|
if len(stat) > 0 {
|
|
var unused string
|
|
fmt.Sscanf(string(stat), "%d %s %s", &unused, &p.Name, &unused)
|
|
}
|
|
|
|
status, _ := os.ReadFile(filepath.Join("/proc", e.Name(), "status"))
|
|
if len(status) > 0 {
|
|
for _, line := range strings.Split(string(status), "\n") {
|
|
if strings.HasPrefix(line, "Name:") {
|
|
val := strings.TrimSpace(strings.TrimPrefix(line, "Name:"))
|
|
if p.Name == "" {
|
|
p.Name = val
|
|
}
|
|
} else if strings.HasPrefix(line, "Uid:") {
|
|
p.Owner = strings.TrimSpace(strings.TrimPrefix(line, "Uid:"))
|
|
}
|
|
}
|
|
}
|
|
|
|
procs = append(procs, p)
|
|
}
|
|
return procs
|
|
}
|
|
|
|
func listProcessesDummy() []*cpb.Process {
|
|
return []*cpb.Process{
|
|
{Pid: 1, Name: "init", Owner: "root"},
|
|
{Pid: 2, Name: "kthreadd", Owner: "root"},
|
|
}
|
|
}
|