`scp` command crashes with `IndexError` when `-d` is given with no target directory
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:
- Run
scp -dwith no further arguments. - Observe an uncaught
IndexError: list index out of rangeinstead 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-dhandling now only readsargs[0]whenargsis non-empty).
Source: cowrie/cowrie