Skip to content

[feature] Adding environment variable support using helper functions #643

Closed

Description

@ehsandeep

Is your feature request related to a problem? Please describe.
For regression testing and authenticated tests, it's helpful to read system variables to replace values into templates at run time.

for example:-

export USER=admin
export PASSWORD=admin_token
source ~/.bashrc

Describe the solution you'd like

requests:
  - method: POST
    path:
      - "{{BaseURL}}/apps"

    body: username={{ENV_USER}}&password={{ENV_TOKEN}}

    matchers:
      - type: word
        words:
          - "Logged in"

Result into:-

POST /apps HTTP/1.1
Host: 0.0.0.0:8000
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 YaBrowser/19.6.0.1583 Yowser/2.5 Safari/537.36
Connection: close
Content-Length: 44
Accept: */*
Accept-Language: en
Accept-Encoding: gzip

username=admin&password=admin_token

Activity

  1. added
    Type: Enhancement
    on Mar 23, 2021
  2. changed the title [-][feature] Adding environment variable support[/-] [+][feature] Adding environment variable support using helper functions[/+] on Mar 23, 2021
  3. added and removed
    Type: Enhancement
    on May 26, 2021
  4. Mzack9999 commented on Jun 21, 2021

    @Mzack9999
    Member

    Support for environment variables is already added in #641, the template would look like the following one:

    requests:
      - method: POST
        path:
          - "{{BaseURL}}/apps"
    
        body: username={{ENV_USER}}&password={{ENV_TOKEN}}
    
        matchers:
          - type: word
            words:
              - "Logged in"
    
  5. self-assigned this
    on Jun 21, 2021
  6. linked a pull request that will close this issueAdding support for global env variables #916on Aug 8, 2021
  7. added
    Status: Completed
    on Aug 9, 2021
  8. linked a pull request that will close this issueHotfix release #922on Aug 9, 2021
  9. ehsandeep commented on Aug 10, 2021

    @ehsandeep
    MemberAuthor

    @toufik-airane this is now supported with the release of v2.4.3, you just need to add -env-vars flag, and the template will read defined variable name from a running system.

    Example template:-

    id: env-example
    
    info:
      name: ENV Template
      author: pdteam
      severity: info
    
    requests:
      - method: POST
        path:
          - "{{BaseURL}}/apps"
    
        body: username={{USER}}&password={{TOKEN}}
    
        matchers:
          - type: word
            words:
              - "Logged in"
    nuclei -env-vars -t test.yaml -u https://example.com
    

    Additionally, you can also define these variables via CLI as well using the newly introduced var flag.

    For example:-

    nuclei -t test.yaml -u https://example.com -var ENV_USER=YYY -var ENV_TOKEN=XXX
    
  10. toufik-airane commented on Aug 11, 2021

    @toufik-airane
    Contributor

    Big! 🤩

  11. savushkin-yauheni commented on Aug 17, 2021

    @savushkin-yauheni
    Contributor

    Hi @ehsandeep

    Can we use env vars in matchers ?

    If no, what do you think about it ?

    Thanks!

  12. ehsandeep commented on Aug 17, 2021

    @ehsandeep
    MemberAuthor

    @savushkin-yauheni that is something we intend to support, GH issue for it - #555

  13. added
    Type: Enhancement
    and removed on Oct 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Status: CompletedType: Enhancement

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions