在最近的工作回顾过程中,发现Peach Tech在2020年被gitlab给收购了,而且在gitlab上释放出一份有删减的基于Pro版本的开源代码,供游客使用。鉴于以前Pro强大的功能和文档在3.x community版本中的缺失,怎么能不试用一下呢。花费了一天的时间进行构建,虽然最终没有得到理想的结果,但也算迈出了一小步,简单记录下过程和几个小坑,期待后期gitlab可以将整个版本升级使用最新的组件进行编译,否则build起来还是相当的费劲。
gitlab官方地址:https://gitlab.com/gitlab-org/security-products/protocol-fuzzer-ce/-/tree/main/
1、准备一个代理或者外网主机
因为当前版本要通过nuget下载v2版本的包,目前原厂加速和其他镜像网站大都是基于v3版本,网络不畅会卡在这里止步不前
2、安装一些必须的包
mono:这也是一个坑,官方描述构建需要使用4.8.1版本,但是在ubuntu20以及centos8上死活build不成功,拷贝其他环境上已经build好的版本,在执行paket.exe时又提示缺失netstandard依赖,总之这里问题比较多,所以直接通过源安装最新6.8.0版本
# yum install mono-devel.x86_64 mono-core.x86_64
npm和tcs:npm比较好安装,tcs这里写的比较隐晦,其实是typescript
# sudo apt install npm
# 国内可以配置一下,否则下载慢
# sudo npm set registry https://mirrors.huaweicloud.com/repository/npm/
# sudo npm install -g typescript
Inter Pin:这个只要下载源码包,按照目录名称放置即可
# wget https://software.intel.com/sites/landingpage/pintool/downloads/pin-3.19-98425-gd666b2bee-gcc-linux.tar.gz
# tar zxf pin-3.19-98425-gd666b2bee-gcc-linux.tar.gz
# mv pin-3.19-98425-gd666b2bee-gcc-linux pin-3.19-98425-gcc-linux
问题多的就这几个,其他包可以待configure的时候提示缺哪个就安装哪个,通过源基本都可以解决
3、修改源码文件
这块不确定是环境问题还是源码包有问题,build的时候会返回几个错误,提前修改一下
# vi ./core/BasicBlocks/bblocks.cpp,添加一行宏定义在STATIC_ASSERT被调用之前
#define STATIC_ASSERT(expr) typedef char __static_assert[expr ? 1 : -1] __attribute__((__unused__));
# vi pro/PitTester/wscript_build
# vi pro/Core/wscript_build
修改这两个文件,将Facades/*都改成绝对路径,例如:
'/usr/lib/mono/4.5/Facades/System.Runtime.dll',
'/usr/lib/mono/4.5/Facades/System.Collections.dll',
4、编译
# python2 waf configure --buildtag=4.3.300 --variant=linux_x86_64_release
# python2 waf build --buildtag=4.3.300 --variant=linux_x86_64_release
# python2 waf build --buildtag=4.3.300 --variant=linux_x86_64_release
如果不指定release,默认会编译debug和release两个版本,但是install的时候默认只输出debug版本
install之后,在当前output目录下,便会成linux_x86_64_release/bin,里面便是构建成功的peach
5、运行
这一步没有办法避开mono 4.8.1的版本依赖,不过先前编译好的mono环境,却可以支撑新构建版本的运行,运行方式和以前一样。
此处还有个小坑,我是直接在外网服务器上build好之后,拉到本地Ubuntu上运行,起初总是抛一些初始化失败的异常,还以为还是版本编译问题,后来经过查找是mono自己的一个bug,配置一下终端环境即可变量解决
1 2 3 4 5 6 7 8 |
# 抛错异常 Unhandled Exception: System.TypeInitializationException: The type initializer for 'Peach.Pro.Core.Runtime.ConsoleProgram' threw an exception. ---> System.TypeInitializationException: The type initializer for 'System.Console' threw an exception. ---> System.TypeInitializationException: The type initializer for 'System.ConsoleDriver' threw an exception. ---> System.Exception: Magic number is wrong: 542 # 处理方法(修改前的默认值是xterm-256color) export TERM=xterm |
6、遗留问题:
a.“Peach Pro Developer Guide”文档没有build出来,configure环节doc一项一直提示缺少组件,虽然已经安装了gem install asciidoctor-pdf
1 2 3 4 5 6 7 8 9 |
Configuring variant linux_x86 : Not Available - Cross compilation failed Configuring variant linux_x86_64 : Not Available - Command ['/usr/bin/mono', '/materials/software/peach/protocol-fuzzer-ce/paket/.paket/paket.exe', 'restore'] returned 1 Configuring variant doc : Available - Missing Features: asciidoctor-pdf,webhelp Configuring variant win_x86 : Not Available - Unsupported build host Configuring variant win_x64 : Not Available - Unsupported build host Configuring variant osx : Not Available - Unsupported build host 'configure' finished successfully (7m48.300s) |
b.之前一直通过<Action type="output" onStart="auth.set_password(self)">修改发包数据的逻辑,现在返回Stream does not support writing的错误
1 2 3 4 5 6 7 8 |
2021-08-21 21:10:39.9150 Peach.Core.Scripting Failed to execute expression [auth.set_password(self)], Stream does not support writing.. System.NotSupportedException: Stream does not support writing. at Peach.Core.IO.BitStream.Write (System.Byte[] buffer, System.Int32 offset, System.Int32 count) [0x0019f] in /root/protocol-fuzzer-ce/core/Core/IO/BitStream.cs:382 at System.IO.Stream.WriteByte (System.Byte value) [0x0000b] in /root/ft_local/mono-4.8.1/mcs/class/referencesource/mscorlib/system/io/stream.cs:770 at (wrapper delegate-invoke) <Module>:invoke_callvirt_void_Stream_byte (System.IO.Stream,byte) at Microsoft.Scripting.Interpreter.ActionCallInstruction`2[T0,T1].Run (Microsoft.Scripting.Interpreter.InterpretedFrame frame) [0x00000] in <1692edc3d9374a59981f388604782b84>:0 at Microsoft.Scripting.Interpreter.Interpreter.Run (Microsoft.Scripting.Interpreter.InterpretedFrame frame) [0x00015] in <1692edc3d9374a59981f388604782b84>:0 |
7、其他
无意中找到一篇在windows上build的经验
后续补充:
1、解决Stream does not support writing
修改protocol-fuzzer-ce/core/Core/IO/BitStream.cs文件,将全局参数从CanWrite函数中哦功能移除
1 2 3 4 5 6 7 8 9 10 11 12 |
//修改前 public override bool CanWrite { get { return _canWrite && _stream.CanWrite; } } //修改后 public override bool CanWrite { get { return _stream.CanWrite; } } |
你好 我现在在国内,然后编译peach 4版本时遇到问题,请教下你,出现了如下问题
root@ubuntu:/home/wowotoupi/protocol-fuzzer-ce# python2 waf configure –buildtag=0.0.2
Configuring variant win_x86 : Not Available – Unsupported build host
Configuring variant win_x64 : Not Available – Unsupported build host
Configuring variant linux_x86 : Not Available – Cross compilation failed
Configuring variant linux_x86_64 : Not Available – Command [‘/usr/local/bin/mono’, ‘/home/wowotoupi/protocol-fuzzer-ce/paket/.paket/paket.exe’, ‘restore’] returned 1
Configuring variant doc : Available – Missing Features: asciidoctor-pdf,webhelp
Configuring variant osx : Not Available – Unsupported build host
‘configure’ finished successfully (22.392s)
root@ubuntu:/home/wowotoupi/protocol-fuzzer-ce# /usr/local/bin/mono /home/wowotoupi/protocol-fuzzer-ce/paket/.paket/paket.exe restore^C
root@ubuntu:/home/wowotoupi/protocol-fuzzer-ce# /usr/local/bin/mono /home/wowotoupi/protocol-fuzzer-ce/paket/.paket/paket.exe restore
Paket version 5.258.1
Performance:
– Runtime: 33 milliseconds
Paket failed with
-> Could not find ‘paket.dependencies’. To use Paket with this solution, please run ‘paket init’ first.
If you have already run ‘paket.init’ then ensure that ‘paket.dependencies’ is located in the top level directory of your repository.
Like this:
MySourceDir
.paket
paket.dependencies
看这个错误信息是没有找到对应的编译平台,可以试试换个centos虚拟机或者根据错误定位一下平台检查的逻辑,修改符合自己的系统再跑跑看
nuget的问题,要挂代理