推荐学习书目
› Learn Python the Hard Way
Python Sites
› PyPI - Python Package Index
› http://diveintopython.org/toc/index.html
› Pocoo
值得关注的项目
› PyPy
› Celery
› Jinja2
› Read the Docs
› gevent
› pyenv
› virtualenv
› Stackless Python
› Beautiful Soup
› 结巴中文分词
› Green Unicorn
› Sentry
› Shovel
› Pyflakes
› pytest
Python 编程
› pep8 Checker
Styles
› PEP 8
› Google Python Style Guide
› Code Style from The Hitchhiker's Guide
kevinmissu
V2EX  ›  Python

正则正则正则 求求求大佬

  •  
  •   kevinmissu · Jun 14, 2019 · 4865 views
    This topic created in 2701 days ago, the information mentioned may be changed or developed.

    有个这样的文件全是这样的格式 我需要把这样的规格提出来 用正则怎么写 求助大神!!!

    rule fire2013 : webshell { meta: xxx strings: XXX{XXXXXXX}XXXXX condition: all of them }

    35 replies  •  2019-06-19 16:42:42 +08:00
    Yggdroot
    Yggdroot
    Jun 14, 2019❤️6
    1
    你这个提问要能问到答案才怪。
    kevinmissu
    kevinmissu
    OP
    Jun 14, 2019
    2
    rule Trojan_Malware_Win32_NSAnti_C
    {
    meta:
    judge = "black"
    threatname = "Trojan[Malware]/Win32.NSAnti.C"
    threattype = "Malware"
    family = "NSAnti"
    hacker = "None"
    refer = "5c64e6879a9746a0d65226706e0edc7a"
    comment = "None"
    description = "Chinese Hacktool Set - file svu.exe"
    author = "Florian Roth -lz"
    date = "2015-06-13"

    strings:
    $s0 = "MZKERNEL32.DLL" fullword ascii
    $s1 = "UpackByDwing@" fullword ascii
    $s2 = "GetProcAddress" fullword ascii
    $s3 = "WriteFile" fullword ascii
    condition:
    $s0 at 0 and filesize < 50KB and all of them
    }
    kevinmissu
    kevinmissu
    OP
    Jun 14, 2019
    3
    里面全是这种
    kevinmissu
    kevinmissu
    OP
    Jun 14, 2019
    4
    怎么把一条一条的提取出来呢
    kevinmissu
    kevinmissu
    OP
    Jun 14, 2019
    5
    求求求大佬
    Loner233
    Loner233
    Jun 14, 2019 via Android
    6
    括号,空格,引号
    zdnyp
    zdnyp
    Jun 14, 2019
    7
    看不懂...
    index90
    index90
    Jun 14, 2019
    8
    如果没有嵌套大括号的话:
    /^rule\s\w+.\{.+\}$/m

    测试地址:
    https://rubular.com/
    linyinma
    linyinma
    Jun 14, 2019
    9
    描述个问题都表达不清楚~~ 文件格式是什么,需要提取什么,好好表达很困难吗?
    index90
    index90
    Jun 14, 2019
    10
    仔细看题目应该是有嵌套大括号的:
    /^rule\s\w+.{0,1}\{.{0,1}meta:.+strings:.+condition:.+all of them.{0,1}\}$/m

    PS: /m 是正则 options,代表允许以“.”匹配换行
    Cooky
    Cooky
    Jun 14, 2019 via Android
    12
    [以下内容 vip 用户可见]
    limuyan44
    limuyan44
    Jun 14, 2019 via Android
    13
    《提问的艺术》
    weixiangzhe
    weixiangzhe
    Jun 14, 2019 via iPhone
    14
    没看懂 问啥子
    andy1ee11o2
    andy1ee11o2
    Jun 14, 2019
    15
    这不是 yara 规则吗
    HatMatrix
    HatMatrix
    Jun 14, 2019
    16
    这样写
    pkookp8
    pkookp8
    Jun 14, 2019 via Android
    17
    正则是表达了一种规则
    只有一个例子,没有额外说明
    我直接把原文贴一遍,特殊的字符加个转义,x 的地方我改成.*,你肯定又不高兴
    hoyixi
    hoyixi
    Jun 14, 2019
    18
    原来都是这样的格式啊,简单,好写,就用那样的正则
    IsaacYoung
    IsaacYoung
    Jun 14, 2019
    19
    Hilong
    Hilong
    Jun 14, 2019 via Android
    20
    以下内容仅回复后可见
    vinew
    vinew
    Jun 14, 2019 via iPhone
    21
    可以尝试转换成 json 标准格式,然后用 jq 处理
    unicloud
    unicloud
    Jun 14, 2019 via iPhone
    22
    用正则工具试呗
    jdhao
    jdhao
    Jun 14, 2019 via Android
    23
    这样弄一下,然后那样再弄一下,就好了。什么?没听懂?你问的都不清楚,让我怎么回到你
    jdhao
    jdhao
    Jun 14, 2019 via Android
    24
    @jdhao 回答
    saulshao
    saulshao
    Jun 15, 2019
    25
    这东西应该一行行分析,直到你用简单的逻辑无法分析再考虑正则。
    问问题的正确方式应该是:我这个输入是...(你写出来了)
    我想要的结果是:(这个你没写)
    然后再说你尝试过什么方法。
    最后说你想要得到一个什么样的解决办法
    saulshao
    saulshao
    Jun 15, 2019
    26
    还需要知道你用的是什么样的语言。
    sbw
    sbw
    Jun 15, 2019
    27
    你的 xxxx 部分应该是没有标准的吧,如果有符号的话那用正则很麻烦,不如解析 json 或者动手写个 parser
    kingfly
    kingfly
    Jun 15, 2019 via Android
    28
    终于见识了传说中的:提问者把所有人都问蒙了!
    mumbler
    mumbler
    Jun 15, 2019
    29
    你把要处理的文件内容贴一部分出来如何? 再贴一下你想从这部分提取的结果

    很简单就能说清楚的事,别让大家猜,提问也要注意用户体验
    zifangsky
    zifangsky
    Jun 15, 2019
    30
    终于见识了传说中的:提问者把所有人都问蒙了! +1
    senghoo
    senghoo
    Jun 15, 2019 via iPad
    31
    解析这种东西,一般都是直接做词法分析和语法分析。正则表达式很难写出来。就算写出来了也是复杂度太高,没有维护性。
    asadegg
    asadegg
    Jun 15, 2019
    32
    我告诉你吧,先这样,这样,再那样,再这样,就行了
    XxxxD
    XxxxD
    Jun 15, 2019
    33
    《提问的艺术》
    way2create
    way2create
    Jun 15, 2019
    34
    建议描述清楚,或者截个图,这提问...
    kevinmissu
    kevinmissu
    OP
    Jun 19, 2019
    35
    感觉这样正则提不出来 我就换了一种 方法 对 这就是 yara 规则的格式
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2473 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 86ms · UTC 15:00 · PVG 23:00 · LAX 07:00 · JFK 10:00
    ♥ Do have faith in what you're doing.