#安装Pcre 1. Pcre官网,到官网下载安装包 2. 转到root用户[普通用户会报错],并确保安装有mac命令行工具[Xcode带有这个工具][具体方法请百度] 3. 解压下载的Pcre工具,打开终端,跳转到对应目录 4. 执行命令./configure --prefix=/opt/pcre会进行相关检查。 5.
php中PCRE2的使用 说明 1、PHP7.3开始,PCRE2将作为新的正则引擎使用。 2、需要将现有的正则表达式迁移到符合PCRE2的规则。这些规则比以前更具侵入性。 特性 相对后向引用 \g{+2}(等效于已存在的 \g{-2}) PCRE2版本检查(?(VERSION>=x)...) .]+/', ''); 以上就是php中PCRE2的使用,希望对大家有所帮助。
PHP的PCRE库使用的正则引擎是NFA,不同于根据正则一步步匹配确定下一个转移状态的DFA,NFA会在正则表达式匹配不上时进行回溯,尝试其他的状态。 举一个简单的例子。 ? PHP也早就考虑到了这一点所以给pcre设定了一个回溯上限pcre.backtrack_limit, 可以通过var_dump(ini_get('pcre.backtrack_limit'));查询,回溯上限为 $input='UNION/*aaa*/SELECT' 正则匹配的回溯次数也会随着a的数量而增加从而突破pcre.backtrack_limit的限制,进而绕过WAF。 ? ?
大多数程序语言都使用了 NFA 作为正则引擎,其中也包括 PHP 使用的 PCRE 库。 0x02 回溯的过程是怎样的 所以,我们题目中的正则 <\?.[(`;?>].,假设匹配的输入是 <? 0x03 PHP 的 pcre.backtrack_limit 限制利用 PHP 为了防止正则表达式的拒绝服务攻击(reDOS),给 pcre 设定了一个回溯次数上限 pcre.backtracklimit 我们可以通过 vardump(iniget('pcre.backtracklimit'));的方式查看当前环境下的上限: ? requests.post('http://51.158.75.42:8088/index.php', files=files, allow_redirects=False) print(res.headers) 0x04 PCRE 所以,我们仍然可以通过发送大量 a,来使回溯次数超出 pcre.backtrack_limit 限制,进而绕过 WAF: ? 0x05 修复方法 那么,如何修复这个问题呢?
/pcre/files/pcre/8.45/(版本:pcre-8.45.tar.gz) zlib:http://www.zlib.net/(版本:zlib-1.2.13.tar.gz) oppenssl 和pcre2下载网址:https://ftp.pcre.org/pub/pcre/) 2、安装OpenSSL 解压:tar -zxvf openssl-1.1.1g.tar.gz 进入解压目录:cd --with-pcre: 指定PCRE库的路径,PCRE是Perl Compatible Regular Expressions的缩写,用于nginx的正则表达式匹配。 before ‘pcre’ 解决方法: 此时很有可能是pcre版本太高或者你装的是pcre2,去上边手动下载换低版本pcre即可. 2.nginx完全卸载 find / -name nginx 或者 find / -name nginx* rm -rf 上边找到nginx路径 3.pcre卸载 在pcre解压目录下执行: sudo make uninstall 然后rm -rf pcre解压目录(或者直接手动右键删除
解决: 安装pcre-devel解决问题,运行命令 yum -y install pcre-devel 3.安装成功:
二.下载与安装 1.下载 通过下列地址下载 [root@haopython~]# wget ftp://ftp.pcre.org/pub/pcre/pcre2-10.35.tar.gz --2020 -06-18 11:57:02-- ftp://ftp.pcre.org/pub/pcre/pcre2-10.35.tar.gz => “pcre2-10.35.tar.gz ” 正在解析主机 ftp.pcre.org (ftp.pcre.org)... 131.111.8.88 正在连接 ftp.pcre.org (ftp.pcre.org)|131.111.8.88 pcre2-10.35/ pcre2-10.35/LICENCE pcre2-10.35/PrepareRelease pcre2-10.35/RunTest.bat … 3. chartables.c ln -s /root/pcre2-10.35/src/pcre2_chartables.c.dist /root/pcre2-10.35/src/pcre2_chartables.c
例如pcre用了JIT动态生成代码并JIT代码引用里自己线程的JIT Stack数据.
(adsbygoogle = window.adsbygoogle || []).push({});
3.3 使用 PCRE 的编程语言 PCRE 是现代编程语言中广泛使用的正则表达式库,以下是常用的编程语言及其对 PCRE 的支持: Perl:PCRE 的发源地,Perl 是处理文本和字符串操作的强大工具 5.2 选择 PCRE 的场景 PCRE 正则表达式适用于以下情况: 复杂的文本操作:如果需要使用递归匹配、捕获组、断言等高级特性,PCRE 是首选。 以下是获取 PCRE 正则表达式规范的主要参考途径: 7.2.1 PCRE 官方文档 PCRE 库 是最权威的 PCRE 正则表达式实现,其官方文档详细描述了 PCRE 的语法、特性和使用方法: PCRE 官方文档 提供了 PCRE 最新的语法和匹配行为说明。 7.2.4 PCRE 库源代码 PCRE 库的源代码是深入了解其实现原理的重要资源,您可以从以下 GitHub 仓库获取: PCRE GitHub 仓库 提供了 PCRE 库的最新源代码及其相关文档
可是国内的几款常见的在线测试工具,不支持PCRE,这里列举几个,如下: http://tool.chinaz.com/regex/ https://c.runoob.com/front-end/854
doc/pcre32.3 doc/pcre_assign_jit_stack.3 doc/pcre_compile.3 doc/pcre_compile2.3 doc/pcre_config.3 doc .3 ln -sf pcre_compile.3 /data/pcre/share/man/man3/pcre16_compile.3 ln -sf pcre_compile2.3 /data/pcre /pcre16_dfa_exec.3 ln -sf pcre_exec.3 /data/pcre/share/man/man3/pcre16_exec.3 ln -sf pcre_free_study.3 pcre/share/man/man3/pcre32_dfa_exec.3 ln -sf pcre_exec.3 /data/pcre/share/man/man3/pcre32_exec.3 ln - sf pcre_refcount.3 /data/pcre/share/man/man3/pcre32_refcount.3 ln -sf pcre_study.3 /data/pcre/share/man
path variables PCRE_URL=http://mirrors.yangxingzhen.com/pcre PCRE_FILES=pcre-8.41.tar.gz PCRE_FILES_DIR =pcre-8.41 PCRE_PREFIX=/usr/local/pcre #Define Apache path variables APACHE_URL=http://mirrors.yangxingzhen.com (){ #Install PCRE if [ ! -d ${PCRE_PREFIX} ];then wget -c ${PCRE_URL}/${PCRE_FILES} tar zxf ${PCRE_FILES} cd ${PCRE_FILES_DIR /configure --prefix=${PCRE_PREFIX} if [ $?
报错1 the HTTP rewrite module requires the PCRE library 缺少 PCRE 库 解决办法是: 1.使用 –without-http_rewrite_module 不添加此模块 2.安装 PCRE 模块到系统中(其实是安装此模块的开发包) 解决依赖 由此可见 pcre 已经在系统中有安装,只是它的开发包没有 [root@h102 nginx-1.9.5]# yum list all | grep -i pcre pcre.x86_64 7.8-6.el6 @anaconda-CentOS base pcre-devel.i686 7.8-7.el6 base pcre-devel.x86 _64 0:7.8-6.el6 will be updated ---> Package pcre.x86_64 0:7.8-7.el6 will be an update ---> Package pcre-devel.x86
/configure 如果出现下面报错 checking for PCRE library ... not found checking for PCRE library in /usr/local/ ... not found checking for PCRE library in /usr/include/pcre/ ... not found checking for PCRE library in /usr/pkg/ ... not found checking for PCRE library in /opt/local/ ... not found 安装pcre依赖 $ wget https ://nchc.dl.sourceforge.net/project/pcre/pcre/8.43/pcre-8.43.tar.gz $ cd pcre-8.43 $ .
.3 /data/pcre/share/man/man3/pcre16_free_substring.3 ln -sf pcre_free_substring_list.3 /data/pcre/ .3 ln -sf pcre_refcount.3 /data/pcre/share/man/man3/pcre16_refcount.3 ln -sf pcre_study.3 /data pcre32_compile2.3 ln -sf pcre_config.3 /data/pcre/share/man/man3/pcre32_config.3 ln -sf pcre_copy_named_substring .3 ln -sf pcre_exec.3 /data/pcre/share/man/man3/pcre32_exec.3 ln -sf pcre_free_study.3 /data/pcre /pcre32_refcount.3 ln -sf pcre_study.3 /data/pcre/share/man/man3/pcre32_study.3 ln -sf pcre_utf32_
(1)下载解压到本地 进入pcre 官网下载页面,选择合适的版本下载。 我选择的是 8.35 版本: wget -O /opt/pcre/pcre-8.35.tar.gz http://downloads.sourceforge.net/project/pcre/pcre/ 8.35/pcre-8.35.tar.gz cd /opt/pcre tar zxvf pcre-8.35.tar.gz (2)编译安装 执行以下命令: cd /opt/pcre/pcre-8.35 . 我选择的是 1.12.2 版本:http://downloads.sourceforge.net/project/pcre/pcre/8.35/pcre-8.35.tar.gz wget -O /opt /configure --with-http_stub_status_module --with-http_ssl_module --with-pcre=/opt/pcre/pcre-8.35 (3)关闭防火墙
/configure: error: the HTTP rewrite module requires the PCRE library. You can either disable the module by using --without-http_rewrite_module option, or install the PCRE library into the system, or build the PCRE library statically from the source with nginx by using --with-pcre 重新编译,指定 --with-pcre, 其中 --with-pcre=/linuxidc/download/pcre-8.35 是pcre是的源码目录,不是安装目录 [www.linuxidc.com /configure --prefix=/usr/local/nginx --with-pcre=/linuxidc/download/pcre-8.35 这样就不报错了。
Alternatively, you may set the environment variables PCRE_CFLAGS and PCRE_LIBS to avoid the need to 经验告诉我,看到 pcre 字眼,就立即想到了是不是要安装支持正则表达式的 pcre 8?? 于是又找到 pcre8 开始安装: unzip pcre-8.30.zip cd pcre-8.30 . 看来不是 pcre 8 的问题了,在百思不得其解时,我打开了 RedHat 的软件包,搜了一下 pcre 关键字,结果发现还有个名为 pcre-devel-6.6-2.el5_1.7.x86_64.rpm 的软件包,好吧,就尝试安装一下看看: [root@TEST-HOST ~]# rpm -ivh pcre-devel-6.6-2.el5_1.7.x86_64.rpm warning: pcre-devel
/pcre/files/pcre/ openssl下载地址: http://www.openssl.org/ apr(Apache Protable Runtime)下载地址: http://apr.apache.org/ 2.安装pcre # tar zxvf pcre-8.35.tar.gz # cd pcre-8.35 # . /configure -prefix=/usr/local/apr -with-pcre=/usr/local/pcre # make # make install 4.安装apr-util /configure -prefix=/usr/local/httpd -with-pcre=/usr/local/pcre -with-apr-util=/usr/local/apr-util /configure -prefix=/usr/local/httpd -with-pcre=/usr/local/pcre # make # make install 6.运行apache