From cd2513ec16e25aa24a2d52078b7634f6cbf4018a Mon Sep 17 00:00:00 2001 From: ed Date: Tue, 15 Nov 2022 21:28:27 +0000 Subject: [PATCH] logging fixes --- copyparty/__main__.py | 6 ++++-- copyparty/ftpd.py | 2 +- copyparty/multicast.py | 3 ++- copyparty/smbd.py | 19 ++++++++++++------- copyparty/svchub.py | 2 +- copyparty/tcpsrv.py | 3 +++ copyparty/util.py | 4 +++- 7 files changed, 26 insertions(+), 13 deletions(-) diff --git a/copyparty/__main__.py b/copyparty/__main__.py index 4672a10f..6f0528a8 100755 --- a/copyparty/__main__.py +++ b/copyparty/__main__.py @@ -678,7 +678,7 @@ def run_argparse( ap2 = ap.add_argument_group('FTP options') ap2.add_argument("--ftp", metavar="PORT", type=int, help="enable FTP server on PORT, for example \033[32m3921") ap2.add_argument("--ftps", metavar="PORT", type=int, help="enable FTPS server on PORT, for example \033[32m3990") - ap2.add_argument("--ftp-dbg", action="store_true", help="enable debug logging") + ap2.add_argument("--ftpv", action="store_true", help="verbose") ap2.add_argument("--ftp-nat", metavar="ADDR", type=u, help="the NAT address to use for passive connections") ap2.add_argument("--ftp-pr", metavar="P-P", type=u, help="the range of TCP ports to use for passive connections, for example \033[32m12000-13000") @@ -692,8 +692,10 @@ def run_argparse( ap2.add_argument("--smbw", action="store_true", help="enable write support (please dont)") ap2.add_argument("--smb1", action="store_true", help="disable SMBv2, only enable SMBv1 (CIFS)") ap2.add_argument("--smb-port", metavar="PORT", type=int, default=445, help="port to listen on -- if you change this value, you must NAT from TCP:445 to this port using iptables or similar") - ap2.add_argument("--smb-dbg", action="store_true", help="show debug messages") ap2.add_argument("--smb-nwa-1", action="store_true", help="disable impacket#1433 workaround (truncate directory listings to 64kB)") + ap2.add_argument("--smbv", action="store_true", help="verbose") + ap2.add_argument("--smbvv", action="store_true", help="verboser") + ap2.add_argument("--smbvvv", action="store_true", help="verbosest") ap2 = ap.add_argument_group('opt-outs') ap2.add_argument("-nw", action="store_true", help="never write anything to disk (debug/benchmark)") diff --git a/copyparty/ftpd.py b/copyparty/ftpd.py index 133a91e6..4becbbc8 100644 --- a/copyparty/ftpd.py +++ b/copyparty/ftpd.py @@ -401,7 +401,7 @@ class Ftpd(object): h2.masquerade_address = self.args.ftp_nat lgr = logging.getLogger("pyftpdlib") - lgr.setLevel(logging.DEBUG if self.args.ftp_dbg else logging.INFO) + lgr.setLevel(logging.DEBUG if self.args.ftpv else logging.INFO) ioloop = IOLoop() for ip in self.args.i: diff --git a/copyparty/multicast.py b/copyparty/multicast.py index 6ab339fd..a7e9f1f9 100644 --- a/copyparty/multicast.py +++ b/copyparty/multicast.py @@ -185,7 +185,8 @@ class MCast(object): sck = srv.sck if srv.v6: if self.args.zmv: - self.log("v6({}) idx({}) {}".format(srv.ip, srv.idx, srv.ips), 6) + zsl = list(srv.ips.keys()) + self.log("v6({}) idx({}) {}".format(srv.ip, srv.idx, zsl), 6) for ip in srv.ips: bip = socket.inet_pton(socket.AF_INET6, ip) diff --git a/copyparty/smbd.py b/copyparty/smbd.py index 2a07ed85..8f9c9ed2 100644 --- a/copyparty/smbd.py +++ b/copyparty/smbd.py @@ -21,6 +21,10 @@ if TYPE_CHECKING: from .svchub import SvcHub +lg = logging.getLogger("smb") +debug, info, warning, error = (lg.debug, lg.info, lg.warning, lg.error) + + class SMB(object): def __init__(self, hub: "SvcHub") -> None: self.hub = hub @@ -29,9 +33,10 @@ class SMB(object): self.log = hub.log self.files: dict[int, tuple[float, str]] = {} + lg.setLevel(logging.DEBUG if self.args.smbvvv else logging.INFO) for x in ["impacket", "impacket.smbserver"]: lgr = logging.getLogger(x) - lgr.setLevel(logging.DEBUG if self.args.smb_dbg else logging.INFO) + lgr.setLevel(logging.DEBUG if self.args.smbvv else logging.INFO) try: from impacket import smbserver @@ -109,7 +114,7 @@ class SMB(object): # cf = inspect.currentframe().f_back # c1 = cf.f_back.f_code.co_name # c2 = cf.f_code.co_name - logging.debug('%s("%s", %s)\033[K\033[0m', caller, vpath, str(a)) + debug('%s("%s", %s)\033[K\033[0m', caller, vpath, str(a)) # TODO find a way to grab `identity` in smbComSessionSetupAndX and smb2SessionSetup vfs, rem = self.asrv.vfs.get(vpath, LEELOO_DALLAS, True, True) @@ -118,7 +123,7 @@ class SMB(object): def _listdir(self, vpath: str, *a: Any, **ka: Any) -> list[str]: vpath = vpath.replace("\\", "/").lstrip("/") # caller = inspect.currentframe().f_back.f_code.co_name - logging.debug('listdir("%s", %s)\033[K\033[0m', vpath, str(a)) + debug('listdir("%s", %s)\033[K\033[0m', vpath, str(a)) vfs, rem = self.asrv.vfs.get(vpath, LEELOO_DALLAS, False, False) _, vfs_ls, vfs_virt = vfs.ls( rem, LEELOO_DALLAS, not self.args.no_scandir, [[False, False]] @@ -135,7 +140,7 @@ class SMB(object): for n, fn in enumerate(ls): if sz >= 64000: t = "listing only %d of %d files (%d byte); see impacket#1433" - logging.warning(t, n, len(ls), sz) + warning(t, n, len(ls), sz) break nsz = len(fn.encode("utf-16", "replace")) @@ -168,7 +173,7 @@ class SMB(object): oldest = min([x[0] for x in self.files.values()]) cutoff = oldest + (now - oldest) / 2 self.files = {k: v for k, v in self.files.items() if v[0] > cutoff} - logging.info("was tracking %d files, now %d", nf, len(self.files)) + info("was tracking %d files, now %d", nf, len(self.files)) vpath = vpath.replace("\\", "/").lstrip("/") self.files[ret] = (now, vpath) @@ -269,7 +274,7 @@ class SMB(object): def _hook(self, *a: Any, **ka: Any) -> None: src = inspect.currentframe().f_back.f_code.co_name - logging.error("\033[31m%s:hook(%s)\033[0m", src, a) + error("\033[31m%s:hook(%s)\033[0m", src, a) raise Exception("nope") def _disarm(self) -> None: @@ -303,5 +308,5 @@ class SMB(object): def yeet(msg: str) -> None: - logging.info(msg) + info(msg) raise Exception(msg) diff --git a/copyparty/svchub.py b/copyparty/svchub.py index 85adb781..8bf48a4f 100644 --- a/copyparty/svchub.py +++ b/copyparty/svchub.py @@ -111,7 +111,7 @@ class SvcHub(object): lg = logging.getLogger() lh = HLog(self.log) lg.handlers = [lh] - lg.setLevel(logging.INFO) + lg.setLevel(logging.DEBUG) if args.stackmon: start_stackmon(args.stackmon, 0) diff --git a/copyparty/tcpsrv.py b/copyparty/tcpsrv.py index f41ea5c0..9fae7430 100644 --- a/copyparty/tcpsrv.py +++ b/copyparty/tcpsrv.py @@ -125,6 +125,9 @@ class TcpSrv(object): title_vars = [x[1:] for x in self.args.wintitle.split(" ") if x.startswith("$")] t = "available @ {}://{}:{}/ (\033[33m{}\033[0m)" for ip, desc in sorted(eps.items(), key=lambda x: x[1]): + if ip.startswith("fe80"): + continue + for port in sorted(self.args.p): if ( port not in ok.get(ip, []) diff --git a/copyparty/util.py b/copyparty/util.py index c889f062..52b1d6c7 100644 --- a/copyparty/util.py +++ b/copyparty/util.py @@ -179,7 +179,9 @@ IMPLICATIONS = [ ["e2v", "e2d"], ["smbw", "smb"], ["smb1", "smb"], - ["smb_dbg", "smb"], + ["smbvvv", "smbvv"], + ["smbvv", "smbv"], + ["smbv", "smb"], ["zmvv", "zmv"], ["zmv", "zm"], ["zms", "zm"],