推荐学习书目
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 · 4482 views
    This topic created in 2549 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
        1
    Yggdroot  
       Jun 14, 2019   ❤️ 6
    你这个提问要能问到答案才怪。
    kevinmissu
        2
    kevinmissu  
    OP
       Jun 14, 2019
    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
        3
    kevinmissu  
    OP
       Jun 14, 2019
    里面全是这种
    kevinmissu
        4
    kevinmissu  
    OP
       Jun 14, 2019
    怎么把一条一条的提取出来呢
    kevinmissu
        5
    kevinmissu  
    OP
       Jun 14, 2019
    求求求大佬
    Loner233
        6
    Loner233  
       Jun 14, 2019 via Android
    括号,空格,引号
    zdnyp
        7
    zdnyp  
       Jun 14, 2019
    看不懂...
    index90
        8
    index90  
       Jun 14, 2019
    如果没有嵌套大括号的话:
    /^rule\s\w+.\{.+\}$/m

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

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

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