1. 软件需求
(1) C/C++编译器
hyperscan使用C开发,且需要C99和C11支持,目前支持的编译器有
GCC, v4.8.1 or higherClang, v3.4 or higher (with libstdc++ or libc++)Intel C++ Compiler v15 or higher
(2) 第三方依赖库
依赖项 版本 说明-------------------------------------------------CMake >=2.8.11Ragel 6.9Python 2.7Boost >=1.57 仅需要regexPcap >=0.8 Optional: 仅用于示例程序
注1:boost不需要编译安装,要下载源码包,解压后执行类似
# ln -s /root/zhn/software/boost_1_58_0/boost ../hyperscan-5.0.0/include/boost
的命令创建符号链接,注意boost路径需要是绝对路径,否则可能找不到
注2:pcap库会依赖flex和bison
2. 编译过程
# cd hyperscan-5.0.0# mkdir build# cd build# cmake .. -DBUILD_STATIC_AND_SHARED=on -DCMAKE_BUILD_TYPE=Release# make -j 20# ll libtotal 22452-rw-r--r--. 1 root root 174930 May 8 16:22 libcorpusomatic.a-rw-r--r--. 1 root root 13598 May 8 15:50 libcrosscompileutil.a-rw-r--r--. 1 root root 12624 May 8 15:50 libdatabaseutil.a-rw-r--r--. 1 root root 38770 May 8 15:56 libexpressionutil.a-rw-r--r--. 1 root root 17232358 May 8 16:25 libhs.a-rw-r--r--. 1 root root 5502018 May 8 16:17 libhs_runtime.a# make installInstall the project...-- Install configuration: "RELWITHDEBINFO"-- Installing: /usr/local/lib64/pkgconfig/libhs.pc-- Installing: /usr/local/include/hs/hs.h-- Installing: /usr/local/include/hs/hs_common.h-- Installing: /usr/local/include/hs/hs_compile.h-- Installing: /usr/local/include/hs/hs_runtime.h-- Installing: /usr/local/lib64/libhs_runtime.a-- Installing: /usr/local/lib64/libhs.a-- Installing: /usr/local/share/doc/hyperscan/examples/simplegrep.c-- Installing: /usr/local/share/doc/hyperscan/examples/pcapscan.cc-- Installing: /usr/local/share/doc/hyperscan/examples/patbench.cc-- Installing: /usr/local/share/doc/hyperscan/examples/README.md
3. 出现问题
(1) 汇编程序太老,无法汇编gcc发出的指令
/tmp/ccmMtaRQ.s:12011: Error: no such instruction: `shrx %r8d,%eax,%eax'/tmp/ccmMtaRQ.s:12064: Error: no such instruction: `shlx %rax,%rsi,%rax'/tmp/ccmMtaRQ.s:12134: Error: no such instruction: `shlx %rsi,%rax,%rax'...当前指令集:# gcc -march=native -Q --help=target | grep march
需要安装binutils
# wget https://ftp.gnu.org/gnu/binutils/binutils-2.27.tar.gz# tar -zxvf binutils-2.27.tar.gz# cd binutils-2.27# ./configure --prefix=/usr# make# make install
4. demo程序
(1) simplegrep
# pwd/root/zhn/software/hyperscan-5.0.0/examples# ../build/bin/simplegrep int simplegrep.cScanning 8051 bytes with HyperscanMatch for pattern "int" at offset 1774Match for pattern "int" at offset 2244Match for pattern "int" at offset 2707Match for pattern "int" at offset 2730Match for pattern "int" at offset 2756Match for pattern "int" at offset 2845Match for pattern "int" at offset 2875Match for pattern "int" at offset 3152Match for pattern "int" at offset 3228Match for pattern "int" at offset 3524Match for pattern "int" at offset 3732Match for pattern "int" at offset 3889Match for pattern "int" at offset 4101Match for pattern "int" at offset 4249Match for pattern "int" at offset 4347Match for pattern "int" at offset 4528Match for pattern "int" at offset 4873Match for pattern "int" at offset 5048Match for pattern "int" at offset 5086Match for pattern "int" at offset 5095Match for pattern "int" at offset 5153Match for pattern "int" at offset 5869Match for pattern "int" at offset 6090Match for pattern "int" at offset 6121Match for pattern "int" at offset 7099Match for pattern "int" at offset 7146Match for pattern "int" at offset 7322Match for pattern "int" at offset 7484Match for pattern "int" at offset 7661
(2) pcapscan
准备一个规则文件matchFile和pcap文件baidu_image.pcap
matchFile内容
123:/baidu/456:/[f|F]ile/
执行
# ./pcapscan matchFile baidu_image.pcapPattern file: matchFileCompiling Hyperscan databases with 2 patterns.Hyperscan streaming mode database compiled in 0.00116827 seconds.Hyperscan block mode database compiled in 0.000731925 seconds.PCAP input file: baidu_image.pcap449 packets in 130 streams, totalling 364977 bytes.Average packet length: 812 bytes.Average stream length: 2807 bytes.Streaming mode Hyperscan database size : 4904 bytes.Block mode Hyperscan database size : 4904 bytes.Streaming mode Hyperscan stream state size: 22 bytes (per stream).Streaming mode:Total matches: 266Match rate: 0.7463 matches/kilobyteThroughput (with stream overhead): 12860.81 megabits/secThroughput (no stream overhead): 14072.15 megabits/secBlock mode:Total matches: 264Match rate: 0.7407 matches/kilobyteThroughput: 17829.85 megabits/secWARNING: Input PCAP file is less than 2MB in size.This test may have been too short to calculate accurate results.
(3) patbench
# ./patbench matchFile baidu_image.pcapBase signatures: matchFile PCAP input file: baidu_image.pcap Repeat count: 1 Mode: streamingScan time 0.008 sec, Scanned 364977 bytes, Throughput 381.597 Mbps, Matches 266Number of signatures: 2Base performance: 12379.131 Megabits/sCutting signatures cumulatively for 1 generationsGeneration 0 . Performance: 23840.098 Megabits/s (1.926x) after cutting:456:/[f|F]ile/
