#40473·cowrie

`scp` command crashes with `IndexError` when `-d` is given with no target directory

Author: vbontchevCreated Aug 4, 2026Updated Aug 4, 2026

Describe the bug src/cowrie/commands/scp.py's Command_scp.start() parses -d as a flag that takes no getopt argument of its own, and then reads the target directory from the first positional argument with self.out_dir = args[0]. If -d is given with no positional arguments at all (bare scp -d), args is empty and args[0] raises IndexError, uncaught, ending the session.

To Reproduce Steps to reproduce the behavior:

  1. Run scp -d with no further arguments.
  2. Observe an uncaught IndexError: list index out of range instead of a clean usage/error message.

Reproduced directly against the option-handling loop with an empty args list, confirming the IndexError; after the fix the same input no longer raises.

Expected behavior scp -d with no target directory should be handled gracefully (e.g. falling through without setting out_dir), not crash the command.

Server (please complete the following information):

  • OS: This bug is OS-independent (pure Python list indexing, no OS-specific code involved).
  • Python: Python 3.14.2
  • Twisted: Twisted 26.4.0

Additional context

  • Cowrie Mode: Shell (default), SCP file transfer.
  • Patched file: src/cowrie/commands/scp.py (Command_scp.start(): the -d handling now only reads args[0] when args is non-empty).

scp.py