CTF-web: YAML是什么

YAML(YAML Ain’t Markup Language)是一种常见的序列化数据格式,主要用于配置文件和数据交换。它的设计目标是简洁、易读,并且易于与编程语言交互。YAML 使用缩进来表示层次结构,类似于 Python 的语法。:

基本语法结构

  1. 键值对

    • YAML 中最基本的结构是键值对,用于表示映射(类似于 Python 的字典)。
    name: John Doe
    age: 30
    
  2. 列表

    • 用破折号(-)表示列表项。
    items:
      - item1
      - item2
      - item3
    
  3. 嵌套结构

    • 使用缩进表示嵌套的层次结构。
    person:
      name: John Doe
      age: 30
      address:
        street: 123 Main St
        city: Anytown
        zip: 12345
    
  4. 多行字符串

    • 使用 | 保留换行符。
    • 使用 > 折叠换行符。
    description: |
      This is a
      multi-line string
      that preserves newlines.
    
    summary: >
      This is a
      multi-line string
      that folds newlines.
    
  5. 注释

    • # 开头的行是注释。
    # This is a comment
    name: John Doe  # Inline comment
    
  6. 数据类型

    • YAML 支持多种数据类型,包括字符串、整数、浮点数、布尔值、null、日期、时间等。
    string: "hello"
    integer: 42
    float: 3.14
    boolean: true
    null_value: null
    date: 2023-01-28
    datetime: 2023-01-28T13:45:00Z
    

示例

下面是一个更复杂的 YAML 示例,涵盖了大部分常见的结构:

# Sample YAML configuration
server:
  host: localhost
  port: 8080
  ssl: true

database:
  engine: postgresql
  host: db.example.com
  port: 5432
  name: mydatabase
  credentials:
    username: dbuser
    password: dbpassword

logging:
  level: DEBUG
  file: /var/log/app.log

features:
  - authentication
  - logging
  - caching

thresholds:
  warning: 75
  critical: 90

# Multi-line strings
description: |
  This is a sample application configuration file.
  It contains multiple sections and nested structures.

summary: >
  This is a summary
  that spans multiple lines
  but will be folded into a single paragraph.

你可能感兴趣的:(网络安全)