mirror of https://github.com/secdev/scapy.git
Fallback on CMD when powershell is not available
This commit is contained in:
parent
e0db7edb0c
commit
9d13deef6f
|
@ -78,28 +78,38 @@ class _PowershellManager(Thread):
|
||||||
"""
|
"""
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
# Start & redirect input
|
# Start & redirect input
|
||||||
self.process = sp.Popen([conf.prog.powershell,
|
if conf.prog.powershell:
|
||||||
"-NoLogo", "-NonInteractive", # Do not print headers
|
self.process = sp.Popen([conf.prog.powershell,
|
||||||
"-Command", "-"], # Listen commands from stdin
|
"-NoLogo", "-NonInteractive", # Do not print headers
|
||||||
stdout=sp.PIPE,
|
"-Command", "-"], # Listen commands from stdin
|
||||||
stdin=sp.PIPE,
|
stdout=sp.PIPE,
|
||||||
stderr=sp.STDOUT,
|
stdin=sp.PIPE,
|
||||||
universal_newlines=True)
|
stderr=sp.STDOUT)
|
||||||
|
self.cmd = False
|
||||||
|
else: # Fallback on CMD (powershell-only commands will fail, but scapy use the VBS fallback)
|
||||||
|
self.process = sp.Popen([conf.prog.cmd],
|
||||||
|
stdout=sp.PIPE,
|
||||||
|
stdin=sp.PIPE,
|
||||||
|
stderr=sp.STDOUT)
|
||||||
|
self.cmd = True
|
||||||
self.buffer = []
|
self.buffer = []
|
||||||
self.running = True
|
self.running = True
|
||||||
self.query_complete = Event()
|
self.query_complete = Event()
|
||||||
Thread.__init__(self)
|
Thread.__init__(self)
|
||||||
self.daemon = True
|
self.daemon = True
|
||||||
self.start()
|
self.start()
|
||||||
self.query(["$FormatEnumerationLimit=-1"]) # Do not crop long IP lists
|
if self.cmd:
|
||||||
|
self.query(["echo @off"]) # Remove header
|
||||||
|
else:
|
||||||
|
self.query(["$FormatEnumerationLimit=-1"]) # Do not crop long IP lists
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
while self.running:
|
while self.running:
|
||||||
read_line = self.process.stdout.readline().strip()
|
read_line = self.process.stdout.readline().strip()
|
||||||
if read_line == "scapy_end":
|
if read_line == b"scapy_end":
|
||||||
self.query_complete.set()
|
self.query_complete.set()
|
||||||
else:
|
else:
|
||||||
self.buffer.append(read_line)
|
self.buffer.append(read_line.decode("utf8", "ignore") if six.PY3 else read_line)
|
||||||
|
|
||||||
def query(self, command):
|
def query(self, command):
|
||||||
self.query_complete.clear()
|
self.query_complete.clear()
|
||||||
|
@ -108,8 +118,8 @@ class _PowershellManager(Thread):
|
||||||
# Call powershell query using running process
|
# Call powershell query using running process
|
||||||
self.buffer = []
|
self.buffer = []
|
||||||
# 'scapy_end' is used as a marker of the end of execution
|
# 'scapy_end' is used as a marker of the end of execution
|
||||||
query = " ".join(command) + "; echo scapy_end\n"
|
query = " ".join(command) + ("&" if self.cmd else ";") + " echo scapy_end\n"
|
||||||
self.process.stdin.write(query)
|
self.process.stdin.write(query.encode())
|
||||||
self.process.stdin.flush()
|
self.process.stdin.flush()
|
||||||
self.query_complete.wait()
|
self.query_complete.wait()
|
||||||
return self.buffer[1:] # Crops first line: the command
|
return self.buffer[1:] # Crops first line: the command
|
||||||
|
|
Loading…
Reference in New Issue