koi-handler 0.12.6__tar.gz → 0.12.7__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {koi_handler-0.12.6/src/koi_handler.egg-info → koi_handler-0.12.7}/PKG-INFO +1 -1
- {koi_handler-0.12.6 → koi_handler-0.12.7}/pyproject.toml +1 -1
- {koi_handler-0.12.6 → koi_handler-0.12.7}/src/koi/main.py +34 -7
- {koi_handler-0.12.6 → koi_handler-0.12.7}/src/koi/utils/logger.py +43 -29
- {koi_handler-0.12.6 → koi_handler-0.12.7/src/koi_handler.egg-info}/PKG-INFO +1 -1
- {koi_handler-0.12.6 → koi_handler-0.12.7}/LICENSE +0 -0
- {koi_handler-0.12.6 → koi_handler-0.12.7}/setup.cfg +0 -0
- {koi_handler-0.12.6 → koi_handler-0.12.7}/src/koi/listener.py +0 -0
- {koi_handler-0.12.6 → koi_handler-0.12.7}/src/koi/mcp/__init__.py +0 -0
- {koi_handler-0.12.6 → koi_handler-0.12.7}/src/koi/mcp/schema.py +0 -0
- {koi_handler-0.12.6 → koi_handler-0.12.7}/src/koi/mcp/server.py +0 -0
- {koi_handler-0.12.6 → koi_handler-0.12.7}/src/koi/modules/blueprint.py +0 -0
- {koi_handler-0.12.6 → koi_handler-0.12.7}/src/koi/modules/download.py +0 -0
- {koi_handler-0.12.6 → koi_handler-0.12.7}/src/koi/modules/duplicate.py +0 -0
- {koi_handler-0.12.6 → koi_handler-0.12.7}/src/koi/modules/get_processes.py +0 -0
- {koi_handler-0.12.6 → koi_handler-0.12.7}/src/koi/modules/get_users.py +0 -0
- {koi_handler-0.12.6 → koi_handler-0.12.7}/src/koi/modules/ligolo.py +0 -0
- {koi_handler-0.12.6 → koi_handler-0.12.7}/src/koi/modules/loader.py +0 -0
- {koi_handler-0.12.6 → koi_handler-0.12.7}/src/koi/modules/network_enum.py +0 -0
- {koi_handler-0.12.6 → koi_handler-0.12.7}/src/koi/modules/peas.py +0 -0
- {koi_handler-0.12.6 → koi_handler-0.12.7}/src/koi/modules/populate_win.py +0 -0
- {koi_handler-0.12.6 → koi_handler-0.12.7}/src/koi/modules/secrets_dump.py +0 -0
- {koi_handler-0.12.6 → koi_handler-0.12.7}/src/koi/modules/sharphound.py +0 -0
- {koi_handler-0.12.6 → koi_handler-0.12.7}/src/koi/modules/ssh_persist.py +0 -0
- {koi_handler-0.12.6 → koi_handler-0.12.7}/src/koi/modules/sysinfo.py +0 -0
- {koi_handler-0.12.6 → koi_handler-0.12.7}/src/koi/modules/upload.py +0 -0
- {koi_handler-0.12.6 → koi_handler-0.12.7}/src/koi/modules/upload64.py +0 -0
- {koi_handler-0.12.6 → koi_handler-0.12.7}/src/koi/modules/wifi_enum.py +0 -0
- {koi_handler-0.12.6 → koi_handler-0.12.7}/src/koi/modules/winscalate.py +0 -0
- {koi_handler-0.12.6 → koi_handler-0.12.7}/src/koi/session.py +0 -0
- {koi_handler-0.12.6 → koi_handler-0.12.7}/src/koi/tunnel/__init__.py +0 -0
- {koi_handler-0.12.6 → koi_handler-0.12.7}/src/koi/tunnel/agent_payload.py +0 -0
- {koi_handler-0.12.6 → koi_handler-0.12.7}/src/koi/tunnel/engine/__init__.py +0 -0
- {koi_handler-0.12.6 → koi_handler-0.12.7}/src/koi/tunnel/engine/__main__.py +0 -0
- {koi_handler-0.12.6 → koi_handler-0.12.7}/src/koi/tunnel/engine/agent.py +0 -0
- {koi_handler-0.12.6 → koi_handler-0.12.7}/src/koi/tunnel/engine/packet.py +0 -0
- {koi_handler-0.12.6 → koi_handler-0.12.7}/src/koi/tunnel/engine/proxy.py +0 -0
- {koi_handler-0.12.6 → koi_handler-0.12.7}/src/koi/tunnel/engine/stack.py +0 -0
- {koi_handler-0.12.6 → koi_handler-0.12.7}/src/koi/tunnel/engine/tcp.py +0 -0
- {koi_handler-0.12.6 → koi_handler-0.12.7}/src/koi/tunnel/engine/transport.py +0 -0
- {koi_handler-0.12.6 → koi_handler-0.12.7}/src/koi/tunnel/engine/tun.py +0 -0
- {koi_handler-0.12.6 → koi_handler-0.12.7}/src/koi/tunnel/manager.py +0 -0
- {koi_handler-0.12.6 → koi_handler-0.12.7}/src/koi/utils/__init__.py +0 -0
- {koi_handler-0.12.6 → koi_handler-0.12.7}/src/koi/utils/bash_obfuscate.py +0 -0
- {koi_handler-0.12.6 → koi_handler-0.12.7}/src/koi/utils/cache.py +0 -0
- {koi_handler-0.12.6 → koi_handler-0.12.7}/src/koi/utils/cli.py +0 -0
- {koi_handler-0.12.6 → koi_handler-0.12.7}/src/koi/utils/config.py +0 -0
- {koi_handler-0.12.6 → koi_handler-0.12.7}/src/koi/utils/config_ui.py +0 -0
- {koi_handler-0.12.6 → koi_handler-0.12.7}/src/koi/utils/connect/__init__.py +0 -0
- {koi_handler-0.12.6 → koi_handler-0.12.7}/src/koi/utils/connect/base.py +0 -0
- {koi_handler-0.12.6 → koi_handler-0.12.7}/src/koi/utils/connect/ntlm.py +0 -0
- {koi_handler-0.12.6 → koi_handler-0.12.7}/src/koi/utils/connect/ssh.py +0 -0
- {koi_handler-0.12.6 → koi_handler-0.12.7}/src/koi/utils/connect/winrm.py +0 -0
- {koi_handler-0.12.6 → koi_handler-0.12.7}/src/koi/utils/connect/wsman.py +0 -0
- {koi_handler-0.12.6 → koi_handler-0.12.7}/src/koi/utils/constants.py +0 -0
- {koi_handler-0.12.6 → koi_handler-0.12.7}/src/koi/utils/detect.py +0 -0
- {koi_handler-0.12.6 → koi_handler-0.12.7}/src/koi/utils/interact.py +0 -0
- {koi_handler-0.12.6 → koi_handler-0.12.7}/src/koi/utils/models.py +0 -0
- {koi_handler-0.12.6 → koi_handler-0.12.7}/src/koi/utils/obfuscate_ui.py +0 -0
- {koi_handler-0.12.6 → koi_handler-0.12.7}/src/koi/utils/payloads.py +0 -0
- {koi_handler-0.12.6 → koi_handler-0.12.7}/src/koi/utils/powerupgrade.py +0 -0
- {koi_handler-0.12.6 → koi_handler-0.12.7}/src/koi/utils/ps_obfuscate.py +0 -0
- {koi_handler-0.12.6 → koi_handler-0.12.7}/src/koi/utils/tcp.py +0 -0
- {koi_handler-0.12.6 → koi_handler-0.12.7}/src/koi/utils/terminal.py +0 -0
- {koi_handler-0.12.6 → koi_handler-0.12.7}/src/koi/utils/tls.py +0 -0
- {koi_handler-0.12.6 → koi_handler-0.12.7}/src/koi/utils/ui.py +0 -0
- {koi_handler-0.12.6 → koi_handler-0.12.7}/src/koi_handler.egg-info/SOURCES.txt +0 -0
- {koi_handler-0.12.6 → koi_handler-0.12.7}/src/koi_handler.egg-info/dependency_links.txt +0 -0
- {koi_handler-0.12.6 → koi_handler-0.12.7}/src/koi_handler.egg-info/entry_points.txt +0 -0
- {koi_handler-0.12.6 → koi_handler-0.12.7}/src/koi_handler.egg-info/top_level.txt +0 -0
|
@@ -88,23 +88,50 @@ class _ArtHelpAction(argparse.Action):
|
|
|
88
88
|
parser.exit()
|
|
89
89
|
|
|
90
90
|
|
|
91
|
-
def
|
|
92
|
-
|
|
93
|
-
|
|
91
|
+
def _latest_apt() -> str | None:
|
|
92
|
+
import subprocess
|
|
93
|
+
try:
|
|
94
|
+
out = subprocess.check_output(
|
|
95
|
+
["apt-cache", "policy", "koi"],
|
|
96
|
+
stderr=subprocess.DEVNULL, timeout=5, text=True,
|
|
97
|
+
)
|
|
98
|
+
for line in out.splitlines():
|
|
99
|
+
if "Candidate:" in line:
|
|
100
|
+
raw = line.split("Candidate:", 1)[1].strip()
|
|
101
|
+
return raw.split("-")[0]
|
|
102
|
+
except Exception:
|
|
103
|
+
pass
|
|
104
|
+
return None
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
def _latest_github() -> str | None:
|
|
108
|
+
from urllib.request import urlopen, Request
|
|
109
|
+
import json
|
|
94
110
|
try:
|
|
95
|
-
from urllib.request import urlopen, Request
|
|
96
|
-
import json
|
|
97
111
|
req = Request(
|
|
98
112
|
"https://api.github.com/repos/b3rt1ng/Koi/releases/latest",
|
|
99
113
|
headers={"User-Agent": "koi/update-check", "Accept": "application/json"},
|
|
100
114
|
)
|
|
101
115
|
with urlopen(req, timeout=3) as resp:
|
|
102
|
-
|
|
116
|
+
return json.loads(resp.read())["tag_name"].lstrip("vV")
|
|
117
|
+
except Exception:
|
|
118
|
+
return None
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
def _print_version() -> None:
|
|
122
|
+
from koi.utils.ui import accent, bold, dim
|
|
123
|
+
print(f"koi {bold(__version__)}")
|
|
124
|
+
try:
|
|
125
|
+
is_apt = _PKG_NAME == "koi"
|
|
126
|
+
latest = _latest_apt() if is_apt else _latest_github()
|
|
127
|
+
if latest is None:
|
|
128
|
+
print(dim(" could not check for updates"))
|
|
129
|
+
return
|
|
103
130
|
local = __version__.lstrip("vV")
|
|
104
131
|
if latest == local:
|
|
105
132
|
print(dim("up to date"))
|
|
106
133
|
else:
|
|
107
|
-
if
|
|
134
|
+
if is_apt:
|
|
108
135
|
hint = dim("sudo apt update && sudo apt upgrade koi")
|
|
109
136
|
else:
|
|
110
137
|
hint = dim("pipx upgrade koi-handler")
|
|
@@ -23,6 +23,7 @@ if TYPE_CHECKING:
|
|
|
23
23
|
_LOG_DIR = Path.home() / ".koi" / "logs"
|
|
24
24
|
_CTRL = re.compile(r"[\x00-\x08\x0b-\x0c\x0e-\x1f\x7f]")
|
|
25
25
|
_PROMPT_SUFFIXES = ("$", "#", "❯", "% ")
|
|
26
|
+
_PROMPT_FRAGMENTS = ("└─$", "└─#", "┌──(", "PS C:\\", "PS>")
|
|
26
27
|
_MAX_LOG_BYTES = 50 * 1024 * 1024
|
|
27
28
|
|
|
28
29
|
|
|
@@ -46,7 +47,10 @@ def _printable(text: str) -> bool:
|
|
|
46
47
|
|
|
47
48
|
|
|
48
49
|
def _is_prompt(line: str) -> bool:
|
|
49
|
-
|
|
50
|
+
s = line.strip()
|
|
51
|
+
if any(s.endswith(sfx) for sfx in _PROMPT_SUFFIXES):
|
|
52
|
+
return True
|
|
53
|
+
return any(frag in s for frag in _PROMPT_FRAGMENTS)
|
|
50
54
|
|
|
51
55
|
|
|
52
56
|
def _dim_ts(entry: dict) -> str:
|
|
@@ -226,14 +230,30 @@ def review(name: str) -> None:
|
|
|
226
230
|
notify("error", f"Log not found: {name}")
|
|
227
231
|
sys.exit(1)
|
|
228
232
|
|
|
229
|
-
encoding
|
|
230
|
-
input_buf
|
|
231
|
-
|
|
233
|
+
encoding = "utf-8"
|
|
234
|
+
input_buf = b""
|
|
235
|
+
output_buf = ""
|
|
236
|
+
accepting_output = False
|
|
237
|
+
last_cmd = ""
|
|
238
|
+
|
|
239
|
+
def _flush_output(ts_str: str) -> None:
|
|
240
|
+
nonlocal output_buf
|
|
241
|
+
for line in output_buf.splitlines():
|
|
242
|
+
stripped = _CTRL.sub("", line).strip()
|
|
243
|
+
if (not stripped or not _printable(stripped)
|
|
244
|
+
or stripped.lower() == last_cmd.lower()
|
|
245
|
+
or _is_prompt(stripped)
|
|
246
|
+
or "__KOI_" in stripped):
|
|
247
|
+
continue
|
|
248
|
+
_render_output_line(ts_str, stripped)
|
|
249
|
+
output_buf = ""
|
|
232
250
|
|
|
233
|
-
def
|
|
234
|
-
nonlocal input_buf
|
|
251
|
+
def _flush_all(ts_str: str) -> None:
|
|
252
|
+
nonlocal input_buf, accepting_output, last_cmd
|
|
253
|
+
_flush_output(ts_str)
|
|
235
254
|
input_buf = b""
|
|
236
|
-
|
|
255
|
+
accepting_output = False
|
|
256
|
+
last_cmd = ""
|
|
237
257
|
|
|
238
258
|
print()
|
|
239
259
|
with open(path, encoding="utf-8") as f:
|
|
@@ -246,7 +266,7 @@ def review(name: str) -> None:
|
|
|
246
266
|
except json.JSONDecodeError:
|
|
247
267
|
continue
|
|
248
268
|
|
|
249
|
-
kind
|
|
269
|
+
kind = entry.get("type")
|
|
250
270
|
ts_str = _dim_ts(entry)
|
|
251
271
|
|
|
252
272
|
if kind == "meta":
|
|
@@ -254,33 +274,27 @@ def review(name: str) -> None:
|
|
|
254
274
|
_render_meta(entry)
|
|
255
275
|
|
|
256
276
|
elif kind == "input":
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
((i, s) for i, s in positions if i != -1),
|
|
262
|
-
key=lambda t: (t[0], -len(t[1])),
|
|
263
|
-
)
|
|
264
|
-
cmd_bytes, input_buf = input_buf.split(sep, 1)
|
|
265
|
-
cmd = _CTRL.sub("", _clean(cmd_bytes, encoding)).strip()
|
|
277
|
+
chunk = base64.b64decode(entry["data"])
|
|
278
|
+
if chunk in (b"\r", b"\n", b"\r\n"):
|
|
279
|
+
_flush_output(ts_str)
|
|
280
|
+
cmd = _CTRL.sub("", _clean(input_buf, encoding)).strip()
|
|
266
281
|
if cmd and _printable(cmd):
|
|
267
282
|
_render_cmd(ts_str, cmd)
|
|
268
|
-
|
|
283
|
+
last_cmd = cmd
|
|
284
|
+
input_buf = b""
|
|
285
|
+
accepting_output = True
|
|
286
|
+
else:
|
|
287
|
+
input_buf += chunk
|
|
269
288
|
|
|
270
289
|
elif kind == "output":
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
if (not stripped or not _printable(stripped)
|
|
275
|
-
or stripped.lower() in recent_cmds
|
|
276
|
-
or _is_prompt(stripped)
|
|
277
|
-
or "__KOI_" in stripped):
|
|
278
|
-
continue
|
|
279
|
-
_render_output_line(ts_str, stripped)
|
|
280
|
-
recent_cmds.clear()
|
|
290
|
+
if not accepting_output:
|
|
291
|
+
continue
|
|
292
|
+
output_buf += _clean(base64.b64decode(entry["data"]), encoding)
|
|
281
293
|
|
|
282
294
|
elif kind == "event":
|
|
283
|
-
|
|
295
|
+
_flush_all(ts_str)
|
|
296
|
+
accepting_output = True
|
|
284
297
|
_render_event(entry)
|
|
285
298
|
|
|
299
|
+
_flush_output(_dim_ts({"ts": time.time()}))
|
|
286
300
|
print()
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|