Skip to content
This repository has been archived by the owner on Sep 6, 2024. It is now read-only.

Commit

Permalink
tab autocomplete and stability changes
Browse files Browse the repository at this point in the history
NO MORE RACE CONDITION LOL
  • Loading branch information
gatariee committed Dec 10, 2023
1 parent 7bacf89 commit 9f3404e
Show file tree
Hide file tree
Showing 14 changed files with 340 additions and 101 deletions.
Binary file modified client/UserInterface/widgets/__pycache__/agent.cpython-311.pyc
Binary file not shown.
Binary file modified client/UserInterface/widgets/__pycache__/winton.cpython-311.pyc
Binary file not shown.
53 changes: 50 additions & 3 deletions client/UserInterface/widgets/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
import sys
import threading
import tkinter as tk
import glob

from tkinter import ttk, scrolledtext, END, font

from Winton.client import Client
from Winton.standalone import get_task_response
from Winton.types import ResultList
from Winton.globals import Tasks

from UserInterface.globals import colors
from Utils.print import pretty_print_ls, handle_help__str__, handle_winton, handle_usage
Expand All @@ -23,8 +25,7 @@
class AgentTab(ttk.Frame):
def __init__(self, container: ttk.Notebook, agent_name: str, **kwargs):
super().__init__(container, **kwargs)
self.agent_name = agent_name
self.uid = agent_name.split(" | ")[-1]
self.uid = agent_name.split("[")[1].split("]")[0] # lol this is so bad
self.prompt = f"winton>> "
self.setup_style()
self.initialize_client()
Expand Down Expand Up @@ -125,6 +126,52 @@ def create_widgets(self):
self.command_history = []
self.history_index = 0

self.tasks = [task["name"] for task in Tasks]
self.command_entry.bind("<Tab>", self.tab_complete)

def tab_complete(self, event):
current_text = self.command_entry.get()

if "cat" in current_text or "execute-assembly" in current_text:
parts = current_text.split(" ")
if len(parts) > 1:
file_path_fragment = parts[-1]
matches = glob.glob(file_path_fragment + "*")
if len(matches) == 1:
self.command_entry.delete(0, tk.END)
self.command_entry.insert(0, " ".join(parts[:-1] + [matches[0]]))
self.command_entry.icursor(tk.END)
return "break"
elif len(matches) > 1:
self.output_text.insert(tk.END, "\n")
for match in matches:
self.output_text.insert(tk.END, f"{match}\n")
self.output_text.insert(tk.END, "\n")
self.scroll_to_end()
return "break"

if current_text.startswith(self.prompt):
current_text = current_text[len(self.prompt) :]
if current_text == "":
return "break"

matching_tasks = [task for task in self.tasks if task.startswith(current_text)]
if len(matching_tasks) == 1:
self.command_entry.delete(len(self.prompt), tk.END)
self.command_entry.insert(len(self.prompt), matching_tasks[0])
self.command_entry.icursor(tk.END)
return "break"
elif len(matching_tasks) > 1:
self.output_text.insert(tk.END, "\n")
for task in matching_tasks:
self.output_text.insert(tk.END, f"{task}\n")
self.output_text.insert(tk.END, "\n")
self.scroll_to_end()
return "break"
else:
return "break"


def prev_command(self, event):
if self.command_history and self.history_index > 0:
self.history_index -= 1
Expand Down Expand Up @@ -280,7 +327,7 @@ def handle_cat(self, command: str):
def handle_ls(self):
self.output_text.insert(tk.END, f"[*] Tasked beacon to list files in .\n")
task_response = get_task_response(self.client, "ls")
files = json.loads(base64.b64decode(task_response[0]['Result']).decode())
files = json.loads(base64.b64decode(task_response[0]["Result"]).decode())
package = pretty_print_ls(files, self.client)
self.output_text.insert(tk.END, package)

Expand Down
15 changes: 7 additions & 8 deletions client/UserInterface/widgets/winton.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,16 +98,14 @@ def setup_notebook(self):

def populate_agents(self, agents: list[Agent]):
self.agent_listbox.delete(0, END)
if agents is None:
self.agent_listbox.insert(END, "No agents registered")
return

if len(agents) == 0:
self.agent_listbox.insert(END, "TS Dead?")

if agents is None or len(agents) == 0:
self.agent_listbox.insert(END, "Error fetching agents")
return

for agent in agents:
self.agent_listbox.insert(
END, f"{agent['Hostname']} @ {agent['IP']} | {agent['UID']}"
END, f"[{agent['UID']}] {agent['Hostname']} @ {agent['IP']} | {agent['OS']} | Sleep: {agent['Sleep']} | PID: {agent['PID']}"
)

def schedule_agent_update(self):
Expand All @@ -126,5 +124,6 @@ def open_agent_tab(self, agent_name: str):
tab_names = [self.notebook.tab(tab, "text") for tab in self.notebook.tabs()]
if agent_name not in tab_names:
agent_tab = AgentTab(self.notebook, agent_name)
self.notebook.add(agent_tab, text=agent_name)
agent_text = agent_name[:agent_name.find("@")]
self.notebook.add(agent_tab, text=agent_text)
self.notebook.select(agent_tab)
Binary file modified client/Winton/__pycache__/standalone.cpython-311.pyc
Binary file not shown.
Binary file modified client/Winton/__pycache__/types.cpython-311.pyc
Binary file not shown.
1 change: 0 additions & 1 deletion client/Winton/standalone.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ def get_task_response(client: Client, task: str, args: str = ""):

time.sleep(int(client.Beacon_Sleep) + 2)


while True:
if time.time() - PACKAGE_START > int(KILL_TIME):
print("[!] Beacon died, clearing queue and awaiting next task")
Expand Down
24 changes: 23 additions & 1 deletion client/Winton/types.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,34 @@
from dataclasses import dataclass

"""
type Agent struct {
IP string
ExtIP string
Hostname string
Sleep string
Jitter string
OS string
UID string
PID string
}
"""


@dataclass
class Agent:
IP: str
ExtIP: str
Hostname: str
Sleep: str
Jitter: str
OS: str
UID: str
PID: str

def winton(self) -> dict:
return self.__dict__


@dataclass
class File:
Filename: str
Expand All @@ -29,6 +48,7 @@ class CommandData:
def winton(self) -> dict:
return self.__dict__


@dataclass
class Command:
name: str
Expand All @@ -38,6 +58,7 @@ class Command:
def __str__(self):
return f"{self.name}\t\t{self.description}\nUsage: {self.usage}"


@dataclass
class Result:
CommandID: str
Expand All @@ -46,9 +67,10 @@ class Result:
def winton(self) -> dict:
return self.__dict__


@dataclass
class ResultList:
results: list[Result]

def winton(self) -> dict:
return self.__dict__
return self.__dict__
37 changes: 36 additions & 1 deletion implant/cmd/handler/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,47 @@ package handler

type Agent struct {
IP string
ExtIP string
Hostname string
Sleep string
Jitter string
OS string
UID string
PID string
}

type TaskResult struct {
CommandID string `json:"CommandID"`
Result string `json:"Result"`
}
}

type Task struct {
UID string
CommandID string
Command string
}

type CommandData struct {
CommandID string
Command string
}

type Result struct {
CommandID string
Result string
}

type Callback struct {
AgentUID string
LastCallback int
}

type TeamServer struct {
IP string
Port string
Password string
AgentList []Agent
AgentTasks []Task
AgentResults []Result
AgentCallbacks []Callback
}
87 changes: 87 additions & 0 deletions implant/cmd/utils/info.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package utils

import (
"fmt"
"net"
"runtime"

)

func fallback() (string) {
addrs, err := net.InterfaceAddrs()
if err != nil {
return "-"
}

for _, addr := range addrs {
ipNet, ok := addr.(*net.IPNet)
if ok && !ipNet.IP.IsLoopback() {
if ipNet.IP.To4() != nil {
return ipNet.IP.String()
}
}
}

return "-"
}

func GetInternalIP() (string, error) {
interfaces, err := net.Interfaces()
if err != nil {
return "", err
}

for _, iface := range interfaces {
if iface.Name == "Ethernet" {
addrs, err := iface.Addrs()
if err != nil {
return "", err
}

for _, addr := range addrs {
ipNet, ok := addr.(*net.IPNet)
if ok && !ipNet.IP.IsLoopback() {
if ipNet.IP.To4() != nil {
return ipNet.IP.String(), nil
}
}
}
}
}

return fallback(), nil
}

func GetSystemInfo() string {
os := runtime.GOOS
arch := runtime.GOARCH

switch os {
case "darwin":
os = "macOS"
case "windows":
os = "Windows"
case "linux":
os = "Linux"
}

switch arch {
case "amd64":
arch = "x64"
case "386":
arch = "x86"
}

return fmt.Sprintf("%s (%s)", os, arch)
}

func main() {
ip, err := GetInternalIP()
if err != nil {
fmt.Println(err)
}
fmt.Println(ip)

OS := GetSystemInfo()
fmt.Println(OS)
}
Loading

0 comments on commit 9f3404e

Please sign in to comment.