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

Create self-delete-using-alternate-data-streams.yml #895

Merged
merged 5 commits into from
Apr 29, 2024
Merged

Create self-delete-using-alternate-data-streams.yml #895

merged 5 commits into from
Apr 29, 2024

Conversation

dstepanic
Copy link
Contributor

Reference: #894
Test data: mandiant/capa-testfiles#231

Adding capa rule for self-deletion technique. I tried to capture the main behaviors in the rule across two implementations. I am open for suggestions or improvements to the rule. Thanks in advance!

Copy link
Collaborator

@mr-tz mr-tz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice, this may be a bit detailed and specific to the example compilation. can we relax the counts and instructions or do you think those are already focused on the core?

@dstepanic
Copy link
Contributor Author

nice, this may be a bit detailed and specific to the example compilation. can we relax the counts and instructions or do you think those are already focused on the core?

It's a good question, I would lean towards those as being part of the core. FWIW, the rule also triggers on the x86/x64 PoC compiled versions. I am happy to adjust it though, I was mainly trying to make sure it wouldn't generate FP's as well.

- and:
- instruction:
- mnemonic: lea
- offset: -0x1D
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add a description detailing this offset value?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeh, for sure. Feel free to adjust it as well.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is too specific here so would remove this instruction.
image

Copy link
Collaborator

@mr-tz mr-tz Apr 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FileRenameInfo = 3 and FileDispositionInfo = 4 are already covered, so that should be fine

@mr-tz
Copy link
Collaborator

mr-tz commented Apr 24, 2024

Gotcha, it's definitely better to avoid FPs.

@dstepanic dstepanic requested a review from mr-tz April 24, 2024 19:04
@mr-tz
Copy link
Collaborator

mr-tz commented Apr 25, 2024

What do you think of this simplification?

  features:
    - and:
      - count(api(kernel32.SetFileInformationByHandle)): 2
      - basic block:
        - and:
          - api: kernel32.SetFileInformationByHandle
          - optional:
            - number: 3 = FileRenameInfo
      - basic block:
        - and:
          - api: kernel32.SetFileInformationByHandle
          - number: 4 = FileDispositionInfo
          - number: 1 = TRUE // fDelete.DeleteFile = TRUE;
      - and:
        - count(api(kernel32.CreateFile)): 2
        - number: 0x10000 = DELETE

@dstepanic
Copy link
Contributor Author

What do you think of this simplification?

  features:
    - and:
      - count(api(kernel32.SetFileInformationByHandle)): 2
      - basic block:
        - and:
          - api: kernel32.SetFileInformationByHandle
          - optional:
            - number: 3 = FileRenameInfo
      - basic block:
        - and:
          - api: kernel32.SetFileInformationByHandle
          - number: 4 = FileDispositionInfo
          - number: 1 = TRUE // fDelete.DeleteFile = TRUE;
      - and:
        - count(api(kernel32.CreateFile)): 2
        - number: 0x10000 = DELETE

Yeh, that's much better and cleaner. Thanks for the recommendation, I will adjust and send it back. Thanks!

Comment on lines 22 to 31
- basic block:
- and:
- api: kernel32.SetFileInformationByHandle
- optional:
- number: 3 = FileRenameInfo
- basic block:
- and:
- api: kernel32.SetFileInformationByHandle
- number: 4 = FileDispositionInfo
- number: 1 = TRUE // fDelete.DeleteFile = TRUE;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

last thing while we're at it, let's add an or block each and add a call subscope so this works in the dynamic flavor
so, e.g.:

      - or:
        - basic block:
          - and:
            - api: kernel32.SetFileInformationByHandle
            - optional:
              - number: 3 = FileRenameInfo
        - call:
          - and:
            - api: SetFileInformationByHandle
            - number: 3 = FileRenameInfo

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, thanks. I tried to implement this, let me know if I missed something.

Copy link
Collaborator

@mr-tz mr-tz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fantastic, thank you very much!

@mr-tz mr-tz merged commit 0171241 into mandiant:master Apr 29, 2024
3 checks passed
@williballenthin
Copy link
Collaborator

thanks @dstepanic!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants