LoFP LoFP / administration, ci jobs and authorized testing can use literal ips, public hosting, temporary destinations or chained execution. review the script and its ancestry before tuning the filter macro. invocation and url checks reduce literal code-search matches but cannot distinguish all quoted examples from executed powershell code.

Techniques

Sample rules

PowerShell Start-BitsTransfer

Description

The following analytic detects PowerShell command lines initiating a BITS transfer with and additional behavioral indicator such as literal IP URL host, file-sharing or hosted-content domain, executable or script in a staging destination, or a chained execution command.

Detection logic


| tstats `security_content_summariesonly`
  count min(_time) as firstTime
        max(_time) as lastTime

FROM datamodel=Endpoint.Processes WHERE

`process_powershell`
Processes.process="*Start-BitsTransfer*"

BY Processes.action Processes.dest Processes.original_file_name
   Processes.parent_process Processes.parent_process_exec Processes.parent_process_guid
   Processes.parent_process_id Processes.parent_process_name Processes.parent_process_path
   Processes.process Processes.process_exec Processes.process_guid
   Processes.process_hash Processes.process_id Processes.process_integrity_level
   Processes.process_name Processes.process_path Processes.user
   Processes.user_id Processes.vendor_product


| `drop_dm_object_name(Processes)`


| where match(process, "(?i)(?:^
|[\\s;
|&({\"\\x27])(?:BitsTransfer\\\\)?Start-BitsTransfer\\s+(?:-[A-Za-z]+\\s+
|[\"\\x27]?https?://)")
    AND NOT match(process, "(?i)-TransferType\\s+[\"\\x27]?Upload(?:Reply)?(?:[\"\\x27\\s;]
|$)")


| rex max_match=0 field=process "(?i)https?://(?:[^/\\s@]+@)?(?<bits_remote_host>\\[[0-9a-f:]+\\]
|[^/:\\s\"\\x27]+)"

| rex max_match=0 field=process "(?i)https?://[^\\s\"']+[\"']?\\s+(?<bits_positional_path>\"[^\"]+\"
|'[^']+'
|\\S+)"

| rex field=process "(?i)-Destination\\s+(?:\"(?<bits_destination_double>[^\"]+)\"
|'(?<bits_destination_single>[^']+)'
|(?<bits_destination_bare>[^\\s;
|]+))"


| eval bits_direct_ip=if(mvfind(bits_remote_host, "(?i)^(?:25[0-5]
|2[0-4][0-9]
|1?[0-9]?[0-9])(?:\\.(?:25[0-5]
|2[0-4][0-9]
|1?[0-9]?[0-9])){3}$
|^\\[[0-9a-f]*:[0-9a-f:]+\\]$")>=0, 1, 0),
       bits_file_hosting=if(mvfind(bits_remote_host, "(?i)(^
|\\.)(?:github\\.com
|githubusercontent\\.com
|discordapp\\.com
|discordapp\\.net
|dropboxusercontent\\.com
|gofile\\.io
|mega\\.nz
|mediafire\\.com
|pastebin\\.com
|paste\\.ee
|transfer\\.sh
|temp\\.sh
|anonfiles\\.com
|storage\\.googleapis\\.com
|trycloudflare\\.com
|workers\\.dev
|pages\\.dev
|onrender\\.com
|supabase\\.co
|ddns\\.net
|ngrok-free\\.app)$")>=0, 1, 0),
       bits_local_path=coalesce(bits_destination_double, bits_destination_single, bits_destination_bare, bits_positional_path)


| where isnotnull(bits_remote_host)
        AND
        (
            bits_direct_ip=1
            OR
            bits_file_hosting=1
            OR
            mvcount(
                mvfilter(
                    match(bits_local_path, "(?i)(?:\\\\(?:AppData\\\\(?:Local
|Roaming)
|Users\\\\Public
|ProgramData
|PerfLogs
|Temp
|Windows\\\\(?:Temp
|Tasks
|debug)
|\\$Recycle\\.Bin
|inetpub\\\\wwwroot)\\\\
|\\\\Start Menu\\\\Programs\\\\Startup\\\\
|%(?:temp
|tmp
|appdata
|localappdata
|programdata
|public)%\\\\
|\\$env:(?:temp
|tmp
|appdata
|localappdata
|programdata
|public)\\\\)")
                    AND
                    match(bits_local_path, "(?i)\\.(?:exe
|dll
|com
|pif
|scr
|cpl
|msi
|msp
|ps1
|psm1
|bat
|cmd
|vbs
|vbe
|js
|jse
|wsf
|wsh
|sct
|hta
|chm
|xll
|aspx?
|ashx
|asmx
|jsp
|jspx
|war)[\"\\x27]?$")
                )
            )>0
            OR
            match(process, "(?i)[;
|]\\s*(?:Start-Process
|Invoke-Item
|Invoke-Expression
|iex
|&)(?:\\s
|\\()")
        )


| `security_content_ctime(firstTime)`

| `security_content_ctime(lastTime)`

| `powershell_start_bitstransfer_filter`