Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support to access specific index from the array element #2106

Open
2 tasks
forgedhallpass opened this issue Jun 3, 2022 · 6 comments
Open
2 tasks

Support to access specific index from the array element #2106

forgedhallpass opened this issue Jun 3, 2022 · 6 comments
Assignees
Labels
Type: Enhancement Most issues will probably ask for additions or changes.

Comments

@forgedhallpass
Copy link
Contributor

forgedhallpass commented Jun 3, 2022

Note: confirm if accessing a specific index from the array element is possible. if yes, update the docs, if not we can look into adding support for it.


  • Update existing templates
  • Update the documentation
id: testextractors

info:
  name: test extractors
  author: brenocss
  severity: info

requests:
  - method: GET
    path:
      - "{{BaseURL}}"

    extractors:
      - type: regex
        name: multiple
        regex:
          - 'script src="(.*?)">'
        internal: true

      - type: regex
        name: single
        regex:
          - 'UA-49905813-1'
        internal: true

    matchers:
      - type: dsl
        dsl:
          - "print_debug(multiple)"
          - "print_debug(multiple0)"
          - "contains(multiple, 'test')"
        condition: and
@forgedhallpass forgedhallpass added the Type: Enhancement Most issues will probably ask for additions or changes. label Jun 3, 2022
@ehsandeep ehsandeep added Priority: Medium This issue may be useful, and needs some attention. Priority: High After critical issues are fixed, these should be dealt with before any further issues. and removed Priority: Medium This issue may be useful, and needs some attention. labels Jun 3, 2022
@Mzack9999 Mzack9999 self-assigned this Jun 9, 2022
@Mzack9999 Mzack9999 added the Status: In Progress This issue is being worked on, and has someone assigned. label Jun 9, 2022
@Mzack9999
Copy link
Member

I don't this is possible without implementing a custom parser, since https://github.com/Knetic/govaluate does not support index access syntax. We could eventually add an helper function like array_pick(multiple, 1) or continue #914

@Mzack9999 Mzack9999 added Status: On Hold Similar to blocked, but is assigned to someone Type: Discussion Some ideas need to be planned and disucssed to come to a strategy. and removed Status: In Progress This issue is being worked on, and has someone assigned. labels Jun 9, 2022
@forgedhallpass
Copy link
Contributor Author

Since we have _1 etc suffixes, I assume we are already doing manual parsing. Worst case, changing that to regular array access syntax should not be complicated. It's more straight forward for the users and maybe we'll change the underlying library later on to something that supports more complex evaluations out of the box.

@Mzack9999
Copy link
Member

govaluate uses [] for escaping purposes, a few alternatives supporting array/slice accessors with brackets:

@ehsandeep ehsandeep removed the Status: On Hold Similar to blocked, but is assigned to someone label Jun 2, 2023
@ehsandeep ehsandeep changed the title Change the array element access in DSL functions Support to access specfic index from the array element Jun 2, 2023
@ehsandeep ehsandeep removed the Type: Discussion Some ideas need to be planned and disucssed to come to a strategy. label Jun 2, 2023
@ehsandeep ehsandeep changed the title Support to access specfic index from the array element Support to access specific index from the array element Jun 2, 2023
@Esonhugh
Copy link

Esonhugh commented Aug 4, 2023

May my contribution is help to fix this issue.. ?
It's HelperFunction called index and I updated the len function to support getting len of array slice and even map.
index(stringOrSlice any, index int) string

PR reference: projectdiscovery/dsl#50
And it merged
Docs reference: projectdiscovery/nuclei-docs#155
And it merged as well
Now it's available on official website and nuclei binary.

@ehsandeep
Copy link
Member

@Esonhugh index function doesn't work for items in the array like the example shared in the issue template, or let me know if you have an example to share?

@Esonhugh
Copy link

Esonhugh commented Aug 9, 2023

@Esonhugh index function doesn't work for items in the array like the example shared in the issue template, or let me know if you have an example to share?

Such kind of template in question may need more support. Such as supporting the array for regex multi results.

But it helps solving the condition in #2106 (comment).

index() can get the index of strings slice (more common type of a string array).

refer: https://github.com/projectdiscovery/dsl/blob/156ef2a49eb95f2f9c5757f161c21033a2221a61/dsl.go#L98 :type assert

doc: https://nuclei.projectdiscovery.io/templating-guide/helper-functions/

And I enhanced the len() func to help people to get the whole length of strings slice or other type make something like getting last 2 line in []line possible.

@tarunKoyalwar tarunKoyalwar removed the Priority: High After critical issues are fixed, these should be dealt with before any further issues. label Feb 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Enhancement Most issues will probably ask for additions or changes.
Projects
None yet
Development

No branches or pull requests

5 participants