def __init__(self,
                 stdout: bool,
                 log_location: str,
                 image_name: str,
                 host_name: str,
                 container_name: str = "corecpro_shell"):
        super().__init__(stdout, log_location, container_name)
        if log_location:
            self.log: Logger = Logger(location_shell=log_location)
        else:
            self.log: Logger = Logger()
        self.log.stdout = stdout
        self.image_name: str = image_name
        self.host_name: str = host_name
        self.container_name: str = container_name + "_" + str(time.time())

        docker_init = subprocess.run([
            'docker', 'run', '-dit', '-h', self.host_name, '--name',
            self.container_name, self.image_name, self.shell
        ],
                                     stdout=subprocess.PIPE,
                                     stderr=subprocess.PIPE)
        if docker_init.stderr:
            Out.err("Docker container failed to initialize.")
            Out.err("SYSTEM: " + docker_init.stderr.decode("UTF-8"))
            raise ChildProcessError()
        else:
            self.container_id: str = docker_init.stdout[0:len(docker_init.
                                                              stdout) -
                                                        1].decode("UTF-8")
            Out.norm("Docker container ID  : " + self.container_id)
            Out.norm("Docker container name: " + self.container_name)
            Out.good("Docker container successfully initialized.")
    def __init__(self, hostname: str, workgroup_name: str):
        self.logged_in: list = list()
        self.failed_login: bool = False
        self.session_key: int = 1
        self.packet: bytes = b''
        self.client_port: int = -1  # Used for Metasploit shell deception
        try:
            self.hostname: str = hostname
            self.workgroup_name: str = workgroup_name
        except (AttributeError, TypeError):
            Out.err(
                "Samba: The workgroup and host names must be strings. Shutting down."
            )
            sys.exit(1)

        self.current_dir: str = ""
        self.bind: bool = False  # If false, NetShareEnumAll is requested; if true, Bind packet was received.
        self.info: str = ""  # Used for NetShareGetInfo; if data, will give info on data; if ipc, info on ipc, etc.
        self.files: dict = dict()
        self.call_id: bytes = b''  # Used for NetShare-messages; Default--Nmap 'AAAA', Metasploit '0000'
        self.payload: bytes = b''  # Stores malicious payloads sent by Nmap/Metasploit; stored to verify later
        self.packet_to_reassemble: bytes = b''  # Stores packets that may be fragmented and sent out of order
        self.exploited: list = list(
        )  # This is used to deceive Metasploit shell and is tied to a specific client port
        self.log_interaction = LogData(
            "interaction", "info", "N/A",
            "unknown")  # Default log, used frequently
        self.log_nmap = LogData("vulnerability scan", "medium", "confirmed",
                                "nmap")  # Default log, used frequently
        self.log_metasploit = LogData(
            "exploitation", "high", "confirmed",
            "metasploit")  # Default log, used frequently
Exemplo n.º 3
0
 def rand_num_gen(length: int = 8) -> bytes:
     """Generates a random number in bytes (default length 8 bytes); used for SMB challenge and User ID generation.
     """
     try:
         output = os.urandom(length)
     except NotImplementedError:
         Out.err("Samba: Your OS does not support crypto-safe random number generation. "
                 "Samba deception will not function. Shutting down.")
         sys.exit(1)
     return bytes(output)
    def __init__(self,
                 stdout: bool,
                 log_location: str,
                 container_name: str = "corecpro_shell"):
        super().__init__(stdout, log_location, container_name)

        rand: bytes = ''.join(
            choice(digits + ascii_letters) for n in range(20)).encode()
        docker_run = self._raw_cmd(b'echo ' + rand)
        if docker_run[0] != b'':
            Out.err("Failed to connect to Docker container " +
                    self.container_name + ".")
            Out.err("SYSTEM: " + docker_run[0].decode('UTF-8'))
            raise ChildProcessError()
        elif docker_run[1][:-1] != rand:
            Out.err("Failed to verify connectivity, but no error is thrown.")
            Out.err("We sent the following command: echo " +
                    rand.decode('UTF-8'))
            Out.err("We expected to receive: " + rand.decode('UTF-8'))
            Out.err("Instead we got: " + docker_run[1].decode('UTF-8'))
            Out.err("Please report this error.")
            raise ChildProcessError()
        else:
            Out.good("Successfully connected to Docker container " +
                     self.container_name)