Integrate 0.9.8 NDS read-only lab, repair upstream hook and simplify setup guidance
This commit is contained in:
42
nds/tools/nds_trace.py
Normal file
42
nds/tools/nds_trace.py
Normal file
@@ -0,0 +1,42 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Summarize NDS metadata only, from a local capture or tshark TSV export."""
|
||||
import argparse, collections, csv, subprocess, sys
|
||||
VERBS={1:'Resolve Name',2:'Read Entry Information',3:'Read',4:'Compare',5:'List',6:'Search',50:'Close Iteration',53:'Get Server Address',54:'Set Keys',55:'Change Password',56:'Verify Password',57:'Begin Login',58:'Finish Login',59:'Begin Authentication',60:'Finish Authentication',61:'Logout',72:'Check Login Restrictions'}
|
||||
FIELDS=['frame.number','ncp.ndsverb','ncp.ndsreplyerror']
|
||||
def number(s):
|
||||
s=s.strip();return int(s,16 if s.lower().startswith('0x') else 10)
|
||||
def summarize(rows):
|
||||
verbs=collections.Counter(); errors=collections.Counter(); malformed=0; total=0
|
||||
for row in rows:
|
||||
if len(row)!=3:malformed+=1;continue
|
||||
try:
|
||||
frame=number(row[0]);vv=[number(x) for x in row[1].split(',') if x.strip()];ee=[number(x) for x in row[2].split(',') if x.strip()]
|
||||
if frame<1 or any(not 0<=v<=255 for v in vv):raise ValueError()
|
||||
if any(not -(2**31)<=e<2**32 for e in ee):raise ValueError()
|
||||
except ValueError:malformed+=1;continue
|
||||
total+=1;verbs.update(vv)
|
||||
for error in ee:
|
||||
if error>=2**31:error-=2**32
|
||||
if error:errors[error]+=1
|
||||
return total,verbs,errors,malformed
|
||||
|
||||
def main():
|
||||
p=argparse.ArgumentParser(description=__doc__);g=p.add_mutually_exclusive_group(required=True);g.add_argument('--pcap');g.add_argument('--tsv');a=p.parse_args()
|
||||
try:
|
||||
if a.pcap:
|
||||
cmd=['tshark','-n','-2','-r',a.pcap,'-Y','ncp.ndsverb || ncp.ndsreplyerror','-T','fields','-E','separator=/t','-E','occurrence=a']
|
||||
for f in FIELDS:cmd+=['-e',f]
|
||||
with subprocess.Popen(cmd,stdout=subprocess.PIPE,text=True,encoding='utf-8',errors='replace') as proc:
|
||||
result=summarize(csv.reader(proc.stdout,delimiter='\t'));rc=proc.wait()
|
||||
if rc:raise ValueError(f'tshark exit {rc}')
|
||||
else:
|
||||
with open(a.tsv,encoding='utf-8',newline='') as f:result=summarize(csv.reader(f,delimiter='\t'))
|
||||
except (OSError,ValueError) as e:p.exit(1,f'Fehler: {e}\n')
|
||||
total,verbs,errors,bad=result
|
||||
print(f'NDS-Metadatenzeilen: {total}; ungültig: {bad}')
|
||||
for v,n in sorted(verbs.items()):print(f'Verb {v:3} {VERBS.get(v,"Unbekannt")}: {n}')
|
||||
for e,n in sorted(errors.items()):print(f'NDS-Fehler {e}: {n}')
|
||||
if not total:print('Keine dekodierten NDS-Metadaten; Discovery/Transport/Dissektor separat prüfen.')
|
||||
print('Anzahlen sind Feldvorkommen, keine erfolgreichen Sitzungen. Keine Request/Reply-Zuordnung.')
|
||||
return int(bad>0)
|
||||
if __name__=='__main__':sys.exit(main())
|
||||
Reference in New Issue
Block a user