1

我想使用 python 字典创建 yml 文件如何制作字典格式,我可以得到低于格式 yml 文件

responses:
  utter_greet:
  - text: Hey! How are you?
    buttons:
    - title: "good"
      payload: "/greet"
    - title: "bad"
      payload: "/health"

4

2 回答 2

1

您可以使用此包转换为dict https://github.com/Infinidat/munch

pip3 install munch

转换为字典

import yaml
from munch import Munch
mydict = yaml.safe_load("""
responses:
  utter_greet:
  - text: Hey! How are you?
    buttons:
    - title: "good"
      payload: "/greet"
    - title: "bad"
      payload: "/health"
""")
print(mydict)

将字典转换为 yaml

with open('output.yml', 'w') as yaml_file:
    yaml.dump(mydict, yaml_file, default_flow_style=False)
于 2021-04-12T06:44:04.863 回答
0

如何使用 python 获取这个 yml 模板:

它必须UUID为一个文件生成一个,并且生成的文件应该有这个yml template

import uuid
print(uuid.uuid1())
u = str(uuid.uuid1())
u
open(u+".yml", "a+")

YML模板格式:

- id: 7049e3ec-b822-4fdf-a4ac-18190f9b66d1
  name: Powerkatz (Staged)
  description: Use Invoke-Mimikatz
  tactic: credential-access
  technique:
    attack_id: T1003.001
    name: "OS Credential Dumping: LSASS Memory"
  privilege: Elevated
  platforms:
    windows:
      psh:
        command: |
          Import-Module .\invoke-mimi.ps1;
          Invoke-Mimikatz -DumpCreds
        parsers:
          plugins.stockpile.app.parsers.katz:
          - source: domain.user.name
            edge: has_password
            target: domain.user.password
          - source: domain.user.name
            edge: has_hash
            target: domain.user.ntlm
          - source: domain.user.name
            edge: has_hash
            target: domain.user.sha1
        payloads:
        - invoke-mimi.ps1
于 2021-06-17T18:32:19.353 回答