Hunting ngrok Activity

Ngrok is a genuine software and mainly used by developers to expose local web servers or any other TCP service to the internet. However, ngrok is now widely abused by threat actors and abused in multiple ways including persistence & data exfiltration purposes.

ngrok exposes local services to the internet by wrapping TCP connections under HTTPS, which means that the Workstation that has ngrok agent software installed will be connected with ngrok proxy-servers, on the other side; inside the ngrok website control panel, the user is given a public URL for accessing the exposed services.

ngrok tunneling

Based on my previous investigations, the ngrok is mostly used for persistence by exposing the RDP service TCP-3389. Usually, with a Windows scheduled task to run the ngrok agent.

Hunting ngrok Network Connections

before the ngrok agent establishes it’s tunnel, it will first fetch the ngrok tunneling servers domains & IP addresses list from this URL:

Using these artifacts, we can query the firewall or DNS logs for any of the ngrok domain names or IP addresses and find which endpoint is communicating with ngrok servers.

Sample Splunk Search Query:

index=dns ("" OR "" OR "" OR "" OR "" OR "" OR "" OR "*")
index=firewall ("" OR "" OR "" OR "" OR "" OR "" OR "" OR "" OR "" OR "" OR "" OR "" OR "" OR "" OR "" OR "" OR "" OR "" OR "" OR "" OR "" OR "" OR "" OR "" OR "" OR "" OR "" OR "" OR "" OR "" OR "" OR "" OR "" OR "" OR "")

Hunting ngrok Windows Processes

I’ve seen multiple APTs placing ngrok under “c:\windows\” directory or sub-directories C:\windows\*\*

Examples command line parameters for launching ngrok:

c:\windows\abc.exe tcp -config=help.txt 3389
c:\windows\abc.exe tcp -config=svc19.dll 3389
c:\windows\abc.exe tcp -config=HELP 3389


  • abc.exe: the ngrok binary
  • tcp: protocol type of the service will be exposed
  • -config=: the config file contain ngrok config, usually contain user access token
  • 3389: the port will be exposed

You read more on the ngrok documentation page:

To find ngrok running process, you can use process explorer and inspect processes Command Line column, or if you have SIEM in place you can use the following Splunk search query or SIGMA rule:

Sample Splunk Search query

index=windows dest_port=4040 dest_ip= transport=TCP
index=windows CommandLine="*.exe tcp -config=*"

Sigma Rule


title: Ngrok Usage
id: ee37eb7c-a4e7-4cd5-8fa4-efa27f1c3f31
description: Detects the use of Ngrok, a utility used for port forwarding and tunneling, often used by threat actors to make local protected services publicly available. Involved domains are for download and * for connections.
status: experimental
author: Florian Roth
date: 2021/05/14
modified: 2021/06/07
    - attack.command_and_control
    - attack.t1572
    category: process_creation
    product: windows
            - ' tcp 139'
            - ' tcp 445'
            - ' tcp 3389'
            - ' tcp 5985'
            - ' tcp 5986'
            - ' start '
            - '--all'
            - '--config'
            - '.yml'
            - 'ngrok.exe'
            - ' tcp '
            - ' http '
            - ' authtoken '
    condition: 1 of them
    - Another tool that uses the command line switches of Ngrok
    - ngrok http 3978 (
level: high

Hunting ngrok binaries on-disk

Ngrok agent executable can be detected on disk using several ways, including hash compassion & imphash and YARA rules. We will use YARA rules as the hashes are regularly changed.

The following YARA rules can find ngrok binaries on Windows systems.

import "pe"

rule ngrok_binaries {
    author      = "Moath Maharmeh"
    date        = "2021/Sep/28"
    description = "Find NGROK agent binaries"
    filetype    = "exe"
    $s1 = "ngrok" fullword
    $s2 = ""
    $s3 = ""
    $s4 = "ngrokService"
    $s5 = "HTTPRoundTrip_KeyVal"
      uint16(0) == 0x5a4d
    ) and
    (3 of ($s*))

Either yara-scanner or Loki tool can be used to run a YARA scan

If using yara-scanner, save the code above in a new file with the extension “.yar” and place it in the directory “yara-rules-src”

python -r --scan-dir "c:\\windows" --gen-report
yara-scan tool using the rule “ngrok_binaries”
yara-scan HTML report

1 Comment Hunting ngrok Activity

  1. calf

    Nice article ! i made a tool like this. To my experience NGROK is used more for SSH and then for RDP. Sometimes some i find some MSSQL or some empire/metasploit/nc listener lmao. I made also a script (not listed on github) to list every active host on NGROK using certain service. The problem is you can’t do the same for http/https sites, if i remember correct the random generated string is too long to brute


Leave a Reply

Your email address will not be published. Required fields are marked *