Query Details

Device Command Line Public I Ps

Query

# Function: DeviceCommandLinePublicIPs()

## Query Information

#### Description
This function returns all public IPv4 addresses that have been seen on the commandline of the searched device. If you also want to include the remote calls that are initiated by the system account ensure that IncludeSystemExecutions is set to *true*.

#### References
- https://lolbas-project.github.io/lolbas/Binaries/Rundll32/
- https://lolbas-project.github.io/lolbas/Binaries/Rundll32/
- https://andreafortuna.org/2017/11/27/how-a-malware-can-download-a-remote-payload-and-execute-malicious-code-in-one-line/

## Defender For Endpoint
```
let IPRegex = '[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}';
// Returns all commandlines that contain a public IP addres from a specific device
let DeviceCommandLinePublicIPs = (DeviceName: string, IncludeSystemExecutions: bool){
DeviceProcessEvents
| where DeviceName == DeviceName
| extend IPAddress = extract(IPRegex, 0, ProcessCommandLine)
| where not(ipv4_is_private(IPAddress))
| where not(InitiatingProcessAccountSid == "S-1-5-18" and IncludeSystemExecutions == false)
| project Timestamp, ProcessCommandLine, IPAddress
| sort by Timestamp
};
// Example
DeviceCommandLinePublicIPs("devicename.tld", false)
```
## Sentinel
```
let IPRegex = '[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}';
// Returns all commandlines that contain a public IP addres from a specific device
let DeviceCommandLinePublicIPs = (DeviceName: string, IncludeSystemExecutions: bool){
DeviceProcessEvents
| where DeviceName == DeviceName
| extend IPAddress = extract(IPRegex, 0, ProcessCommandLine)
| where not(ipv4_is_private(IPAddress))
| where not(InitiatingProcessAccountSid == "S-1-5-18" and IncludeSystemExecutions == false)
| project TimeGenerated, ProcessCommandLine, IPAddress
| sort by TimeGenerated
};
// Example
DeviceCommandLinePublicIPs("devicename.tld", false)
```

Explanation

The query is a function called "DeviceCommandLinePublicIPs" that returns all public IPv4 addresses that have been seen on the commandline of a specific device. It can also include remote calls initiated by the system account if the "IncludeSystemExecutions" parameter is set to true. The query uses regular expressions to extract IP addresses from the commandline and filters out private IP addresses and system executions. The results include the timestamp, process commandline, and IP address, sorted by timestamp or time generated.

Details

Bert-Jan Pals profile picture

Bert-Jan Pals

Released: September 11, 2023

Tables

DeviceProcessEvents

Keywords

DeviceCommandLinePublicIPs,DeviceName,IncludeSystemExecutions,DeviceProcessEvents,IPAddress,ProcessCommandLine,Timestamp,TimeGenerated

Operators

extendwherenotipv4_is_privateprojectsort by

Actions