@@ -195,6 +195,13 @@ def save_file(self, sessionID, path, data, append=False):
195195 savePath = self.installPath + "/downloads/"+str(sessionID)+"/" + "/".join(parts[0:-1])
196196 filename = parts[-1]
197197
198+ # fix for 'skywalker' exploit by @zeroSteiner
199+ safePath = os.path.abspath("%s/downloads/%s/" %(self.installPath, sessionID))
200+ if not os.path.abspath(savePath+"/"+filename).startswith(safePath):
201+ dispatcher.send("[!] WARNING: agent %s attempted skywalker exploit!" %(sessionID), sender="Agents")
202+ dispatcher.send("[!] attempted overwrite of %s with data %s" %(path, data), sender="Agents")
203+ return
204+
198205 # make the recursive directory structure if it doesn't already exist
199206 if not os.path.exists(savePath):
200207 os.makedirs(savePath)
@@ -210,7 +217,7 @@ def save_file(self, sessionID, path, data, append=False):
210217 f.close()
211218
212219 # notify everyone that the file was downloaded
213- dispatcher.send("[+] Part of file "+filename+" from "+str( sessionID)+" saved" , sender="Agents")
220+ dispatcher.send("[+] Part of file %s from %s saved" %(filename, sessionID), sender="Agents")
214221
215222
216223 def save_module_file(self, sessionID, path, data):
@@ -227,6 +234,13 @@ def save_module_file(self, sessionID, path, data):
227234 savePath = self.installPath + "/downloads/"+str(sessionID)+"/" + "/".join(parts[0:-1])
228235 filename = parts[-1]
229236
237+ # fix for 'skywalker' exploit by @zeroSteiner
238+ safePath = os.path.abspath("%s/downloads/%s/" %(self.installPath, sessionID))
239+ if not os.path.abspath(savePath+"/"+filename).startswith(safePath):
240+ dispatcher.send("[!] WARNING: agent %s attempted skywalker exploit!" %(sessionID), sender="Agents")
241+ dispatcher.send("[!] attempted overwrite of %s with data %s" %(path, data), sender="Agents")
242+ return
243+
230244 # make the recursive directory structure if it doesn't already exist
231245 if not os.path.exists(savePath):
232246 os.makedirs(savePath)
0 commit comments