我有一个使用 mitmproxy http 函数的代码,它在这里惨败:
def main(stdscr):
try:
parser = argparse.ArgumentParser(description='NetSour Network Analyzer')
parser.add_argument('--proxy', action='store_true', help='Enable HTTPS decryption (BETA)')
args = parser.parse_args()
if args.proxy:
print("WARNING: HTTPS decryption is in BETA. Use at your own risk.")
from mitmproxy.tools.main import mitmdump
>>>>mitmdump(['--scripts', __file__, '--set', 'block_global=false'])
return
if is_root():
stdscr.addstr(0, 0, "[+] You are root.")
else:
stdscr.addstr(0, 0, "[-] You are not root.")
stdscr.addstr(1, 0, "[+] Enter the interface name: ")
curses.echo()
interface = stdscr.getstr().decode()
curses.noecho()
packet_queue = Queue()
sniff_thread = Thread(target=sniff_packets, args=(packet_queue, interface))
sniff_thread.daemon = True
sniff_thread.start()
stdscr.addstr(3, 0, "[+] Starting NetSour...")
stdscr.refresh()
time.sleep(1)
display_packets(stdscr, packet_queue)
except Exception as e:
print(f"Error in main function: {str(e)}")
返回 return _signature_from_callable(obj, sigcls=cls, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 文件“/usr/lib/python3.11/inspect.py”,第 2447 行,在 _signature_from_callable 中 raise TypeError('{!r} 不是可调用对象'.format(obj)) 类型错误:不是可调用对象 [19:36:20.886] HTTP(S) 代理侦听 *:8080。 启动期间记录错误,退出...
我问 ChatGpt,它说它与一个名为 ColorTables 的未知函数有关,所以我搜索了它,但它什么也没做。
The error message you're encountering is a bit misleading because it doesn't directly point to the root cause within your code snippet. However, the traceback provides valuable clues:
Traceback Analysis
-
TypeError: '...' object is not callable
: This usually means you're trying to invoke a function, but the object you're using is not a function. -
File ".../inspect.py", line 2447, in _signature_from_callable
: The error originates deep within Python's introspection library (inspect
). This library is used to examine the properties of Python objects, including whether something is callable (like a function).
The Issue:
mitmdump(['--scripts', __file__, '--set', 'block_global=false'])
The problem lies in how you're attempting to use
mitmdump
.
mitmdump
is not a function designed to be called directly within your Python script. It's a command-line utility provided by
mitmproxy
.
Solution: Subprocess for External Commands
To run
mitmdump
correctly, you need to treat it as a separate process that your script launches:
import subprocess
def main(stdscr):
# ... your existing code ...
if args.proxy:
print("WARNING: HTTPS decryption is in BETA. Use at your own risk.")
# Launch mitmdump as a subprocess
subprocess.Popen(['mitmdump', '--scripts', __file__, '--set', 'block_global=false'])
return # Consider if you want your script to continue or wait
# ... your existing code ...
Explanation:
-
subprocess.Popen
: This function is used to start a new process. - Command List : You pass the command you want to execute as a list:
-
'mitmdump'
: The name of the mitmdump executable. -
'--scripts'
,__file__
, ...: Arguments passed to mitmdump. -
Subprocess Execution
:
mitmdump
will run as a separate process alongside (or in the background of) your Python script.
Important Considerations:
-
Blocking vs. Non-Blocking
: If you want your script to pause until
mitmdump
finishes, you can usesubprocess.call()
instead ofPopen()
. However, this might not be desirable in your case. -
Communication
: If you need to exchange data between your Python script and the running
mitmdump
process, you'll need to explore inter-process communication mechanisms (e.g., pipes, queues).
Let me know if you have any other questions!
标签:python,scapy,curses,mitmproxy From: 78776577