Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
    clean up eval scripts
    add cluster size check
    fix of a number of typos
    fix dhcp.secs type. closes #28
    fix segment match calculation for templates, closes #29
    fix cluster labels with 0 values
    a bit of code cleanup
    some default imports for nemere package
    fix element length tests
    fix type hints and toTikz return
    make eps statistics part of plots
    fix distance plot labels
    small fixes
    fix groundtruth
    fix support for empty (None) labels in DistancesPlotter
    fix disproportional axes in distance plots
    use internal figure instance
    assert input parameters of plotManifoldDistances
    fall back to scapy on pcapy errror
    fix minor wlan parser inaccuracies
    consolidate labels for large topology plots
    fix DistanceCalculator cache file name
    fix nemetyl eval script
    multi-process
    add more wlan.mgt fields and workarounds for faulty dissectors of vendor extensions
    add print of pcap in process
    fix double protocol import in message parser and add workaround for faulty value representation (non-conformance to 2-byte-hex)
    match regexes of field nodes in the json which should be descended into
    redesign of ParsingConstants class hierarchy
    all known l2/le protos in eval scripts
    fix #7
    append terminal log of netzob-fms
    prepare layer select in netzob-fms
    best similarity thresholds
    refactor class hierarchy of nemere.visualization.simplePrint.SegmentPrinter
    enumerate symbol names in symbolsFromSegments
    TypeIdentificationByAlignment in nemetyl main scripts
    encapsulate the whole NEMETYL process in TypeIdentificationByAlignment
    replace parameter comparator by specimens
    Introduce SegmentPrinter and clean up related code
    centrally provide analyzer conversion in MessageAnalyzer.convertAnalyzers
    different placement of text in empty ax
    consolidate labels in distance plot of tft and make plot of segment values optional
    introduce ComparingPrinter and AbstractDissectorMatcher
    report detail improvements
    libpcap fixes #15
    fail gratiously if no spd-say is available
    improve clustered symbol CSV format
    message type discriminator search utils
    check plot toolbar before update
    reorganize input
    cleanup cluster report writing
    nemetyl main script: use CachedDistances, StartupFilecheck
    enhanced tikz output
    refactor cacheAndLoadDC to a class
    pin empty cache and reports folders
    fully integrated dynamic protocol importing
    introduce watchdog for Netzob message parsing
    comments on tshark timeout
    increase timeout to wait for tshark output
    + networkx in requirements
    pcapy linktype conversion
    bugfixes and features about dot11 import, eval script improvements, tshark 3 support
    fix length check and dummy segments
    add interactive switch
    evaluation script for netzob output measured in FMS
    test Netzob compatibility
    overlapping test independent of class
    Target layer selection parameters consolidated
    add check for non-negative lengths in segments
    ensure tuples. closes #14
    started support for tshark version 3.x
    Integrate ScaPyCAPimporter into specimen loader
  • Loading branch information
skleber committed Jun 16, 2021
1 parent f232645 commit 285607f
Show file tree
Hide file tree
Showing 93 changed files with 4,906 additions and 2,753 deletions.
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
__pycache__
/cache*
reports/
__pycache__/
workspace.xml
usage.statistics.xml
shelf/
*.iml
gradle.xml
11 changes: 0 additions & 11 deletions .idea/NEMESYS.iml

This file was deleted.

2 changes: 2 additions & 0 deletions .idea/dictionaries/stephan.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 0 additions & 13 deletions .idea/nemesys.iml

This file was deleted.

570 changes: 0 additions & 570 deletions .idea/workspace.xml

This file was deleted.

1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ This is highly experimental software and by no means guaranteed to be fit for pr

## Requirements
* Python 3
* libpcap for pcapy: `apt-get install libpcap-dev libpq-dev`
* Install packages listed in requirements.txt: `pip install -r requirements.txt`
* This necessitates to install libpcap for pcapy: `sudo apt-get install libpcap-dev`
* Manual install of Netzob from the ["fix-layer-build" branch]([email protected]:skleber/netzob.git)
Expand Down
108 changes: 85 additions & 23 deletions eval-nemetyl-messagetype.sh
Original file line number Diff line number Diff line change
@@ -1,45 +1,107 @@
#!/bin/bash

#input=input/*-100.pcap
input=input/*-1000.pcap
#input=input/*-1000.pcap
#input="input/*-100.pcap input/*-1000.pcap"
#input="input/ntp_SMIA-20111010_deduped-1000.pcap input/smb_SMIA20111010-one_deduped-1000.pcap"

sigmas="0.6 0.8 1.0 1.2"
#sigmas="0.9"
input="input/maxdiff-fromOrig/ntp_SMIA-20111010_maxdiff-100.pcap"
#input="input/maxdiff-fromOrig/*-100*.pcap"

refines="base original"
#refines="base"

#sigmas="0.6 0.8 1.0 1.2"
# default
#sigmas="0.9 1.2"
sigmas="1.2"

# full
#segmenters="nemesys"
segmenters="nemesys"

cftnext=$(expr 1 + $(ls -d reports/nemetyl-* | sed "s/^.*nemetyl-\([0-9]*\)-.*$/\1/" | sort | tail -1))
cftnpad=$(printf "%03d" ${cftnext})
currcomm=$(git log -1 --format="%h")
report=reports/nemetyl-${cftnpad}-clustering-${currcomm}
mkdir ${report}
# full
#refines="none original base nemetyl"

# Nemesys options
# refines="original nemetyl"
# default
# refines="original nemetyl"
refines="nemetyl"


L2PROTOS="input/awdl-* input/au-* input/wlan-beacons-*"

for fn in ${input} ; do python src/nemetyl_align-segments.py $fn -t tshark --with-plots ; done;
for fn in ${input} ; do python src/nemetyl_align-segments.py $fn -t 4bytesfixed --with-plots ; done;
prefix="nemetyl"

mv reports/*.pdf ${report}/
mv reports/*.csv ${report}/
cftnpad="229"
for f in reports/${prefix}-* ; do
if [ -e "$f" ] ; then
cftnext=$(expr 1 + $(ls -d reports/${prefix}-* | sed "s/^.*${prefix}-\([0-9]*\)-.*$/\1/" | sort | tail -1))
cftnpad=$(printf "%03d" ${cftnext})
fi
break
done
currcomm=$(git log -1 --format="%h")
report=reports/${prefix}-${cftnpad}-clustering-${currcomm}
#echo ${report}
#exit
mkdir ${report}

for sig in ${sigmas} ; do
for ref in ${refines} ; do
for fn in ${input} ; do
python src/nemetyl_align-segments.py ${fn} -r ${ref} -t nemesys --with-plots
done

mkdir ${report}/sig${sig}-${ref}
mv reports/*.pdf ${report}/sig${sig}-${ref}/
mv reports/*.csv ${report}/sig${sig}-${ref}/
for fn in ${input} ; do
optargs="-r" # relative to IP layer
for proto in ${L2PROTOS} ; do
if [[ "${fn}" == ${proto} ]] ; then
# replace
optargs="-l 2"
fi
done
echo -e "\n\ntshark: ${fn}"
# echo "$fn -t tshark ${optargs} --with-plots"
# exit
python src/nemetyl_align-segments.py $fn -t tshark ${optargs} --with-plots
done
for fn in ${input} ; do
optargs="-r"
for proto in ${L2PROTOS} ; do
if [[ "${fn}" == ${proto} ]] ; then
# replace
optargs="-l 2"
fi
done
echo -e "\n\n4bytesfixed: ${fn}"
python src/nemetyl_align-segments.py $fn -t 4bytesfixed ${optargs} --with-plots
done

for seg in ${segmenters} ; do
for sig in ${sigmas} ; do
for ref in ${refines} ; do
if [[ ${seg} == "zeros" ]] && [[ ! ${ref} =~ ^(none|PCA1|PCAmocoSF)$ ]] ; then
echo ${ref} not suited for zeros segmenter. Ignoring.
continue
fi
for fn in ${input} ; do
optargs="-r"
for proto in ${L2PROTOS} ; do
if [[ "${fn}" == ${proto} ]] ; then
# replace
optargs="-l 2"
fi
done
echo -e "\n${seg}, sigma ${sig} (${refines}): ${fn}"
python src/nemetyl_align-segments.py ${fn} -f ${ref} -t ${seg} -s ${sig} ${optargs} --with-plots
done
done
done
done
for fn in ${input} ; do
bn=$(basename -- ${fn})
strippedname="${bn%.*}"
mv reports/${strippedname}/ ${report}/
done
mv reports/*.csv ${report}/

# collect the "messagetype-combined-cluster-statistics.csv" of multiple independent nemetyl-runs
# We don't need this anymore, after the enhancement of the reportWriter module!
# python reports/combine-nemetyl-results.py ${report}

spd-say "Bin fertig!"
spd-say "Bin fertig!"
57 changes: 57 additions & 0 deletions eval-netzob-fms.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/usr/bin/env bash

#input=input/*-100.pcap
#input=input/*-1000.pcap
#input="input/*-100.pcap input/*-1000.pcap"
#input=input/maxdiff-filtered/*-1000.pcap
#input=input/maxdiff-fromOrig/*-1000.pcap

input=input/maxdiff-fromOrig/ntp_SMIA-20111010_maxdiff-100.pcap
#input="input/maxdiff-fromOrig/smb_SMIA20111010-one-rigid1_maxdiff-1000.pcap"

L2PROTOS="input/awdl-* input/au-*"

prefix="netzob-format"

# AWDL
numpad="206"
for f in reports/${prefix}-* ; do
if [ -e "$f" ] ; then
numnext=$(expr 1 + $(ls -d reports/${prefix}-* | sed "s/^.*${prefix}-\([0-9]*\)-.*$/\1/" | sort | tail -1))
numpad=$(printf "%03d" ${numnext})
fi
break
done
currcomm=$(git log -1 --format="%h")
report=reports/${prefix}-${numpad}-fms-${currcomm}
mkdir ${report}

smin=50

pids=()
for fn in ${input} ; do
# relative to IP layer
optargs="-r" # --smax 80
for proto in ${L2PROTOS} ; do
if [[ "${fn}" == ${proto} ]] ; then
# replace at layer 2 absolute
optargs="-l 2"
# optargs="-l 2 --smax 75"
fi
done
# python src/netzob_fms.py --smin ${smin} ${optargs} ${fn} > "${report}/$(basename -s .pcap ${fn}).log" &
python src/netzob_fms.py ${optargs} ${fn} >> "${report}/$(basename -s .pcap ${fn}).log" &
pids+=( $! )
done

for pid in "${pids[@]}"; do
printf 'Waiting for %d...' "$pid"
wait $pid
echo 'done.'
done

mv reports/*clByAlign* ${report}/
python reports/combine-nemesys-fms.py ${report}/


spd-say "Bin fertig!"
57 changes: 44 additions & 13 deletions eval-netzob-messagetype.sh
Original file line number Diff line number Diff line change
@@ -1,24 +1,55 @@
#!/bin/bash

# dhcp_SMIA2011101X_deduped-1000.pcap
python src/netzob_messagetypes.py input/dhcp_SMIA2011101X_deduped-1000.pcap -r --smin 77 --smax 77
python src/netzob_messagetypes.py input/dhcp_SMIA2011101X_deduped-1000.pcap -r --smin 78 --smax 78
python src/netzob_messagetypes.py input/dhcp_SMIA2011101X_deduped-1000.pcap -r --smin 79 --smax 79

prefix="netzob_messagetype"

# dns_ictf2010_deduped-982-1000.pcap
python src/netzob_messagetypes.py input/dns_ictf2010_deduped-982-1000.pcap -r --smin 49 --smax 51
numpad="200"
for f in reports/${prefix}-* ; do
if [ -e "$f" ] ; then
numnext=$(expr 1 + $(ls -d reports/${prefix}-* | sed "s/^.*${prefix}-\([0-9]*\)-.*$/\1/" | sort | tail -1))
numpad=$(printf "%03d" ${numnext})
fi
break
done
currcomm=$(git log -1 --format="%h")
report=reports/${prefix}-${numpad}-${currcomm}
mkdir ${report}


# nbns_SMIA20111010-one_deduped-1000.pcap
python src/netzob_messagetypes.py input/nbns_SMIA20111010-one_deduped-1000.pcap -r --smin 57 --smax 59
## dhcp_SMIA2011101X_deduped-1000.pcap
#python src/netzob_messagetypes.py input/dhcp_SMIA2011101X_deduped-1000.pcap -r --smin 77 --smax 77
#python src/netzob_messagetypes.py input/dhcp_SMIA2011101X_deduped-1000.pcap -r --smin 78 --smax 78
#python src/netzob_messagetypes.py input/dhcp_SMIA2011101X_deduped-1000.pcap -r --smin 79 --smax 79
#
#
## dns_ictf2010_deduped-982-1000.pcap
#python src/netzob_messagetypes.py input/dns_ictf2010_deduped-982-1000.pcap -r --smin 49 --smax 51
#
#
## nbns_SMIA20111010-one_deduped-1000.pcap
#python src/netzob_messagetypes.py input/nbns_SMIA20111010-one_deduped-1000.pcap -r --smin 57 --smax 59
#
#
## ntp_SMIA-20111010_deduped-1000.pcap
#python src/netzob_messagetypes.py input/ntp_SMIA-20111010_deduped-1000.pcap -r --smin 56 --smax 58

# ntp_SMIA-20111010_deduped-100.pcap
python src/netzob_messagetypes.py input/maxdiff-fromOrig/ntp_SMIA-20111010_maxdiff-100.pcap -r --smin 56 --smax 58

# ntp_SMIA-20111010_deduped-1000.pcap
python src/netzob_messagetypes.py input/ntp_SMIA-20111010_deduped-1000.pcap -r --smin 56 --smax 58
#
#
## smb_SMIA20111010-one_deduped-1000.pcap
#python src/netzob_messagetypes.py input/nbns_SMIA20111010-one_deduped-1000.pcap -r --smin 54 --smax 55
#python src/netzob_messagetypes.py input/nbns_SMIA20111010-one_deduped-1000.pcap -r --smin 56 --smax 56


# smb_SMIA20111010-one_deduped-1000.pcap
python src/netzob_messagetypes.py input/nbns_SMIA20111010-one_deduped-1000.pcap -r --smin 54 --smax 55
python src/netzob_messagetypes.py input/nbns_SMIA20111010-one_deduped-1000.pcap -r --smin 56 --smax 56






mv reports/*.csv ${report}/
mv reports/*.pdf ${report}/

spd-say "Bin fertig!"
12 changes: 8 additions & 4 deletions input/Sources.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,12 @@ with parameters:
```
* with `mergecap -F pcap -w binaryprotocols_merged_XXX.pcap INFILES`





## Private/Own recordings

* wlan monitor captures wardriving through Biberach
* C_SEEMOO/wlan-mgt-priv.pcapng merged from C_SEEMOO/wlan-mgt by mergecap
* from this is filtered: wlan-beacons-priv.pcapng
* `wlan.fc.type_subtype == 0x0008 && !_ws.expert`
* (very common SSIDs could be reduced by `!(wlan.ssid == "HZN241577234" || wlan.ssid == "Fritzle")` ) but we didn't
* `python ~/Dokumente/git.lab-vs/REUP/nemesys/src/prep_filter-maxdiff-trace.py -l2 -p100[|0|00] wlan-beacons-priv.pcapng`

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 6 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,9 @@ matplotlib
pandas
scipy
tabulate
networkx
gitpython
colorhash

pcapy
xlwt
38 changes: 38 additions & 0 deletions src/Contents.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Script Content Overview




## Prep/Utils

### check_parse-pcap.py
### check_pcap-info.py

### prep_deduplicate-trace.py




## Segmentation: NEMESYS, Zeros

### netzob_fms.py
baseline

### Original
WOOT 2018
#### nemesys_field-deviation-plot.py
#### nemesys_fms.py
#### nemesys.py



## NEMETYL

### netzob_messagetypes.py
baseline

### nemetyl_align-segments.py




1 change: 1 addition & 0 deletions src/check_parse-pcap.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
specimens = SpecimenLoader(args.pcapfilename, args.targetlayer, args.relativeToIP)
else:
specimens = SpecimenLoader(args.pcapfilename)
print('Loaded PCAP file:', specimens.pcapFileName)
pkt = list(specimens.messagePool.values())

st = time.time()
Expand Down
Loading

0 comments on commit 285607f

Please sign in to comment.