pwncat.manager module

The manager is the core object within pwncat. A manager is responsible for maintaining configuration, terminal state, and maintaining all active pwncat sessions. A manager can have zero or more sessions active at any given time. It is recommended to create a manager through the context manager syntax. In this way, pwncat will automatically disconnect from active sessions and perform any required cleanup prior to exiting even if there was an uncaught exception. The normal method of creating a manager is:

with pwncat.manager.Manager() as manager:
    # Do something with your manager, like set a configuration item
    # or open a connection
    session = manager.create_session(platform="linux", host="192.168.1.1", port=4444)
exception pwncat.manager.InteractiveExit

Bases: Exception

Indicates we should exit the interactive terminal

class pwncat.manager.Manager(config: str = None)

Bases: object

pwncat manager which is responsible for creating channels, and sessions, managing the database sessions. It provides the factory functions for generating platforms, channels, database sessions, and executing modules.

create_db_session()

Create a new SQLAlchemy database session and return it

create_session(platform: str, channel: pwncat.channel.Channel = None, **kwargs)

Open a new session from a new or existing platform. If the platform is a string, a new platform is created using create_platform and a session is built around the platform. In that case, the arguments are the same as for create_platform.

A new Session object is returned which contains the created or specified platform.

interactive()

Start interactive prompt

load_modules(*paths)

Dynamically load modules from the specified paths

If a module has the same name as an already loaded module, it will take it’s place in the module list. This includes built-in modules.

log(*args, **kwargs)

Output a log entry

open_database()

Create the internal engine and session builder for this manager based on the configured database

print(*args, **kwargs)
property target

Retrieve the currently focused target

class pwncat.manager.Session(manager, platform: Union[str, pwncat.platform.Platform], channel: Optional[pwncat.channel.Channel] = None, **kwargs)

Bases: object

This class represents the container by which pwncat references connections to victim machines. It glues together a connected Channel and an appropriate Platform implementation. It also provides generic access to the pwncat database and logging functionality.

close()

Close the session and remove from manager tracking

property config

Get the configuration object for this manager. This is simply a wrapper for session.manager.config to make accessing configuration a little easier.

current_user()pwncat.facts.User

Retrieve the current user object

died()
find_group(gid=None, name=None)

Locate a user object by name or ID

find_module(pattern: str, base=None, exact: bool = False)

Locate a module by a glob pattern. This is an generator which may yield multiple modules that match the pattern and base class.

find_user(uid=None, name=None)

Locate a user object by name or ID

iter_groups(members: Optional[List[Union[str, int]]] = None)

Iterate over groups for the target

iter_users()

Iterate over the users for the target

log(*args, **kwargs)

Log to the console. This utilizes the active sessions progress instance to log without messing up progress output from other sessions, if we aren’t active.

print(*args, **kwargs)

Log to the console. This utilizes the active sessions progress instance to log without messing up progress output from other sessions, if we aren’t active.

register_fact(fact: pwncat.db.Fact)

Register a fact with this session’s target. This is useful when a fact is generated during execution of a command or module, but is not associated with a specific enumeration module. It can still be queried with the base enumerate module by it’s type.

register_new_host()

Register a new host in the database. This assumes the hash has already been stored in self.hash

run(module: str, **kwargs)

Run a module on this session

property target

Retrieve the target object for this session

task(*args, **kwargs)

Get a new task in this session’s progress instance

update_task(task, *args, **kwargs)

Update an active task