跟流量相关的日常测试,就是 根据条件查找 pcap, 修改 pcap, 然后利用修改后的 pcap 执行某些软件命令的过程
- 在指定的目录内查找
- 按照 平均包大小 范围查找
- 按照 PPS 范围查找
- 按照 文件名称 模糊查找
- 按照 包数量 范围查找
- 是否修改 pcap 内的 packet 时间, 修改到什么时候
- 是否修改 pcap 内的 IP 地址, 修改到什么范围, 多大的范围
- 命令执行主要是靠相关软件本身的命令行参数, 比如 zeek -r 支持从 pcap 读取数据工作, 此时最需要的就是待测 pcap 的路径
- 有时候可能需要使用不同的 pcap 执行不同的命令, 且有先后顺序关系, 甚至中间需要进行一定时长的等待
typeFinderstruct {
// finder 的 ID, 默认是 default, 用于 Job 和 Command 引用Idstring`mapstructure:"id"`// 从哪个目录查找Directorystring`mapstructure:"directory"`// from user// 文件名的模式Patterns []string`mapstructure:"patterns"`// 使用的 modifier 的 ID, 默认为 defaultModifierIdstring`mapstructure:"modifier"`// pps 小于 xxx, 默认为 0 无限制PpsLEfloat64`mapstructure:"pps_le"`// pps 大于 xxx, 默认为 0 无限制PpsGEfloat64`mapstructure:"pps_ge"`// packet count 小于 xxx, 默认为 0 无限制PacketCountLeint64`mapstructure:"packet_count_le"`// packet count 大于 xxx, 默认为 0 无限制PacketCountGeint64`mapstructure:"packet_count_ge"`// avg packet size 小于 xxx, 默认为 0 无限制AvgPacketSizeLEfloat64`mapstructure:"avg_packet_size_le"`// avg packet size 大于 xxx, 默认为 0 无限制AvgPacketSizeGEfloat64`mapstructure:"avg_packet_size_ge"`// ModifierId 找到的 modifiermodifier*Modifier
}typeModifierstruct {
// modifier 的 ID, 默认是 default, 用于 Finder 引用Idstring`mapstructure:"id"`// 定义是否修改时间AdjustTimebool`mapstructure:"adjust_time"`// 将时间修改到什么时候, 采用 go time.Duration 表示, 可以使用诸如 1h3m5s 等语法表示TimeOffset time.Duration`mapstructure:"time_offset"`// 是否要保持 IP, 默认是 false, 即 修改 IPKeepIpbool`mapstructure:"keep_ip"`// 自定义客户端 IP 的 第 1 段C1int`mapstructure:"c1"`// 自定义客户端 IP 的 第 2 段C2int`mapstructure:"c2"`// 自定义客户端 IP 的 第 3 段C3int`mapstructure:"c3"`// 自定义客户端 IP 的 第 4 段C4int`mapstructure:"c4"`// 自定义服务端 IP 的 第 1 段S1int`mapstructure:"s1"`// 自定义服务端 IP 的 第 2 段S2int`mapstructure:"s2"`// 自定义服务端 IP 的 第 3 段S3int`mapstructure:"s3"`// 自定义服务端 IP 的 第 4 段S4int`mapstructure:"s4"`// 是否使用自定义的第 3 段UsePart3bool`mapstructure:"use_part_3"`// 是否使用自定义的第 4 段UsePart4bool`mapstructure:"use_part_4"`
}typeCommandstruct {
// 命令的名称, 主要用于人可读Namestring`mapstructure:"name"`// 要执行的命令, 包含必要的参数在内Commandstring`mapstructure:"command"`// 执行命令前 chroot 到指定目录, 可以为空Directorystring`mapstructure:"directory"`// 命令类型, 当前主要是两种类型: shell 和 pcap(默认值)// 区别是 pcap 类型的会使用 finder 找到的每一个 pcap 执行该命令(所以正常来讲, 命令内应该存在预定义变量占位符)Typestring`mapstructure:"type"`// 命令执行的超时时间, 默认 30s, 允许自定义, 使用 1h2m3s 的语法Timeout time.Duration`mapstructure:"timeout"`// 使用的 finder ID, 如果无定义从 Job 继承FinderIdstring`mapstructure:"finder"`// if not provide, use Job's// 所属任务job*Job// FinderId 对应的 finderfinder*Finder
}typeJobstruct {
// job 的 ID, 主要用于命令行筛选Idstring`mapstructure:"id"`// job 的名称, 主要用于人可读Namestring`mapstructure:"name"`// job 内的命令列表, 顺序执行Commands []*Command`mapstructure:"commands"`// 是否启用Enablebool`mapstructure:"enable"`// 使用的 Finder ID, 默认为 defaultFinderIdstring`mapstructure:"finder"`finder*Finder
}prsdata 支持从配置文件读取配置(可以无配置文件工作, 但是 Job 为内置硬编码, 仅可通过命令行修改 默认的 finder 和 modifier, 以及控制参数)
配置文件格式采用 YAML, 默认的配置路径为 ~/.prsdata.yml, 但是可以采用 -f 参数明确指定为其他路径
支持的参数列表如下:
[root@prs-sensor ~]# prsdata -h
Usage:
prsdata [flags]
Flags:
// 可以通过 -f 使用指定的配置文件
-f, --config-file string 配置文件路径 (default "/root/.prsdata.yml")
-C, --concurrency-jobs int 并发 job 数量 (default 6)
-c, --concurrency-commands int 并发 command 数量 (default 6)
// job 的循环执行次数
-T, --test-times int 测试轮数 (default 1)
--debug debug mode
// 控制 prsdata 的最大运行时长, 通常配合 -T 使用
-D, --duration duration 最大运行时长, 0 表示不限制, 可以使用诸如 1h3m5s 的表达式
// 命令的执行超时时间, 可以在命令定义处使用 timeout 覆盖
-S, --command-timeout duration 默认的单个命令执行时长 (default 30s)
// prsdata 工作过程中产生的所有临时文件均保存在该处
-w, --temporary-directory string 默认的临时文件夹 (default "/data/.prsdata/history/")
// 仅打印 job 列表, 常用于调试配置文件内容
-J, --just-show-jobs 仅打印加载的 job 列表
// 仅打印加载到的 pcap 列表, 常用于测试配置的 finder 是否符合预期
-j, --just-show-pcaps 仅打印加载的 pcap 列表
--show-command 打印正在执行的命令
--show-stdout 打印正在执行的命令及其输出
--show-why 展示 pcap 未被加载的原因
--keep-data 是否保留数据
-O, --jobs strings 仅执行指定的 ID 对应的 job, 逗号分割指定多个
--daemon 后台运行
--pingback string daemon 模式下的 pingback 地址, 请勿手动指定
// 默认的 modifier 配置
-a, --adjust-time adjust time or not (default true)
-t, --time-offset duration time offset
--keep-ip keep ip or not
--c1 int c1 (default 192)
--c2 int c2 (default 168)
--c3 int c3 (default 186)
--c4 int c4 (default 11)
--s1 int s1 (default 10)
--s2 int s2 (default 132)
--s3 int s3 (default 123)
--s4 int s4 (default 22)
-3, --use-part-3 use part 3 or not
-4, --use-part-4 use part 4 or not
// 默认的 finder 配置
-d, --directory string pcap search directory (default "/data/.prsdata/pcaps/")
-p, --patterns strings patterns for filter pcap
--pps-le int pps less than or equal to given value
--pps-ge int pps greater than or equal to given value
--packet-count-le int packet count less than or equal to given value
--packet-count-ge int packet count greater than or equal to given value
--avg-packet-size-le int avg packet size less than or equal to given value
--avg-packet-size-ge int avg packet size greater than or equal to given value
// 以下用于配置使用到的相关工具路径(仅填写名称会使用 $PATH 环境变量进行查找)
--bash string bash path (default "bash")
--capinfos string capinfos path (default "capinfos")
--editcap string editcap path (default "editcap")
--tcpdump string tcpdump path (default "tcpdump")
--tcprewrite string tcprewrite path (default "tcprewrite")
--tcpprep string tcpprep path (default "tcpprep")
-V, --version show version
-h, --help help for prsdata
对应的配置文件样例:
config:
concurrency_jobs: 2concurrency_commands: 6test_times: 1duration: 0command_timeout: 30sdebug: falsetool:
bash: bashcapinfos: capinfoseditcap: editcaptcpdump: tcpdumptcprewrite: tcprewritetcpprep: tcpprepp426: p426modifier:
adjust_time: true # default is false, you must set it explicittime_offset: 0skeep_ip: falsec1: 192c2: 168c3: 186c4: 11s1: 10s2: 132s3: 123s4: 22use_part_3: falseuse_part_4: falsefinder:
directory: /data/.prsdata/pcaps/jobs:
- id: zeekname: zeekenable: truecommands:
- name: zeekcommand: /opt/zeek/bin/zeek -r {{.RelativePath}} -C /opt/zeek-scripts/tophant.entrypoint.zeekdirectory: "{{.FinderDirectory}}"
- id: suricataname: suricataenable: truecommands:
- name: suricatacommand: /opt/suricata/bin/suricata -c /opt/suricata/etc/suricata/suricata.yaml -r {{.RelativePath}} -k none --runmode autofpdirectory: "{{.FinderDirectory}}"
- id: fpcname: fpcenable: falsecommands:
- name: molochcommand: /data/moloch/bin/moloch-capture --insecure -c /data/moloch/etc/config.ini -r {{.RelativePath}}directory: "{{.FinderDirectory}}"丰富的配置文件样例:
config:
concurrency_jobs: 2concurrency_commands: 6test_times: 1debug: falseduration: 0tool:
bash: bashcapinfos: capinfoseditcap: editcaptcpdump: tcpdumptcprewrite: tcprewritetcpprep: tcpprepmodifier:
adjust_time: true # default is false, you must set it explicittime_offset: 0skeep_ip: falsec1: 192c2: 168c3: 186c4: 11s1: 10s2: 132s3: 123s4: 22use_part_3: falseuse_part_4: falsefinder:
directory: /data/.prsdata/pcaps/modifiers:
- id: pvskeep_ip: true
- id: dgatime_offset: 1hfinders:
- id: pvsdirectory: /data/.prsdata/pcaps/pvsmodifier: pvs
- id: dgadirectory: /data/.prsdata/pcaps/dgamodifier: dgajobs:
- id: zeekname: zeek pvsenable: truefinder: pvscommands:
- name: zeekcommand: /opt/zeek/bin/zeek -r {{.RelativePath}} -C /opt/zeek-scripts/tophant.entrypoint.zeekdirectory: "{{.FinderDirectory}}"
- id: suricataname: suricataenable: truecommands:
- name: suricata# 因为 job 和 command 都没有定义明确定义 finder, 那么用的就是默认的 finder# finder: defaultcommand: /opt/suricata/bin/suricata -c /opt/suricata/etc/suricata/suricata.yaml -r {{.RelativePath}} -k none --runmode autofpdirectory: "{{.FinderDirectory}}"
- name: test sleepcommand: sleep 1000timeout: 1002s
- name: zeek dgafinder: dgacommand: /opt/zeek/bin/zeek -r {{.RelativePath}} -C /opt/zeek-scripts/tophant.entrypoint.zeekdirectory: "{{.FinderDirectory}}"type 为 pcap 类型的 command, 其 command 内容可以包含预定义的变量. 预定义变量列表如下:
WorkingDirectory-prsdata本次的临时工作目录路径FinderDirectory-当前pcap使用的finder对应的目录路径PcapDirectory-当前pcap所在目录路径RelativeDirectory-当前pcap所在目录基于WorkingDirectory的相对路径信息RelativePath-当前pcap路径基于WorkingDirectory的相对路径Path-当前pcap的完整路径BaseName-当前pcap的文件名称Name-当前pcap不包含后缀的文件名称Ext-当前pcap的后缀信息样例数据如下:
WorkingDirectory - /data/.prsdata/history/prsdata-2020_09_29_17_19_31-14696
FinderDirectory - /data/.prsdata/history/prsdata-2020_09_29_17_19_31-14696/finder-default
PcapDirectory - /data/.prsdata/history/prsdata-2020_09_29_17_19_31-14696/finder-default/all-pcap/vulnerability/tunnel/dns_tunnel
RelativeDirectory - all-pcap/vulnerability/tunnel/dns_tunnel
RelativePath - all-pcap/vulnerability/tunnel/dns_tunnel/dns_oob.pcap
Path - /data/.prsdata/history/prsdata-2020_09_29_17_19_31-14696/finder-default/all-pcap/vulnerability/tunnel/dns_tunnel/dns_oob.pcap
BaseName - dns_oob.pcap
Name - dns_oob
Ext - .pcap
