在尝试将 sqlmap 与我的自动化工具集成时,当尝试运行命令并将输出保存到文件中时,需要用户输入的行不会打印在控制台上;它在参数传递后被打印出来。需要在两个位置(终端和输出文件)上打印控制台输出。由于sqlmap在执行过程中需要用户输入不能使用subprocess.check_output()
image
代码片段:
[try:
cmd = cmd.rstrip()
process = subprocess.Popen(cmd,shell=True,stdout=subprocess.PIPE,stderr=subprocess.STDOUT)
while True:
out = process.stdout.readline()\[0:\]
if out == '' and process.poll() is not None:
break
if out:
output += out
print(out.strip())
except Exception as e:
exception_message = str(e)
output += exception_message
if 'exit status 1' not in exception_message:
self.utilities.print_color("\[!\] Error executing the command: " + cmd,'red')
output += '\r\n'
print(output)
return output][1]