Detection rules › Kusto
Detect presence of private IP addresses in URLs (ASIM Web Session)
'This rule identifies requests made to atypical URLs, as malware can exploit IP addresses for communication with command-and-control (C2) servers. The detection identifies network requests that contain either plain text or Base64 encoded IP addresses. Alerts are triggered when a private IP address is observed as plain text or base64 encoded in an outbound web request. This method of concealing the IP address was observed in the utilization of the RunningRAT tool by POLONIUM.'
MITRE ATT&CK coverage
| Tactic | Techniques |
|---|---|
| Command & Control | |
| Exfiltration |
Rule body
id: e3a7722a-e099-45a9-9afb-6618e8f05405
name: Detect presence of private IP addresses in URLs (ASIM Web Session)
description: |
'This rule identifies requests made to atypical URLs, as malware can exploit IP addresses for communication with command-and-control (C2) servers. The detection identifies network requests that contain either plain text or Base64 encoded IP addresses. Alerts are triggered when a private IP address is observed as plain text or base64 encoded in an outbound web request. This method of concealing the IP address was observed in the utilization of the RunningRAT tool by POLONIUM.'
severity: Medium
status: Available
tags:
- Schema: WebSession
SchemaVersion: 0.2.6
requiredDataConnectors: []
queryFrequency: 1h
queryPeriod: 1h
triggerOperator: gt
triggerThreshold: 0
tactics:
- Exfiltration
- CommandAndControl
relevantTechniques:
- T1041
- T1071.001
- T1001
query: |
let lookback = 1h;
// Identified base64 encoded IPv4 addresses
let ipv4_encoded_identification_regex = @"\=([a-zA-Z0-9\/\+]*(?:(?:MC|Au|wL|MS|Eu|xL|Mi|Iu|yL|My|Mu|zL|NC|Qu|0L|NS|Uu|1L|Ni|Yu|2L|Ny|cu|3L|OC|gu|4L|OS|ku|5L){1}[a-zA-Z0-9\/\+]{2,4}){3}[a-zA-Z0-9\/\+\=]*)";
// Extractes IPv4 addresses as hex values
let ipv4_decoded_hex_extract = @"((?:(?:61|62|63|64|65|66|67|68|69|6a|6b|6c|6d|6e|6f|70|71|72|73|74|75|76|77|78|79|7a|41|42|43|44|45|46|47|48|49|4a|4b|4c|4d|4e|4f|50|51|52|53|54|55|56|57|58|59|5a|2f|2b|3d),){6,14}(?:61|62|63|64|65|66|67|68|69|6a|6b|6c|6d|6e|6f|70|71|72|73|74|75|76|77|78|79|7a|41|42|43|44|45|46|47|48|49|4a|4b|4c|4d|4e|4f|50|51|52|53|54|55|56|57|58|59|5a|2f|2b|3d))";
let ipV4_Private_FromPlainString = _Im_WebSession(starttime=ago(lookback), eventresult='Success')
| where isnotempty(Url)
| extend ip_inURL = extract(@"\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b", 0, Url)
| where ipv4_is_private(ip_inURL)
| where not(ipv4_is_private(DstIpAddr)) // only take traffic going to internet
| summarize
EventCount=count(),
EventEndTime = max(TimeGenerated),
EventStartTime = min(TimeGenerated),
Urls=tostring(make_set(Url, 100))
by SrcIpAddr, SrcUsername, SrcHostname, ip_inURL;
let ipV4_Private_FromEncodedString =
_Im_WebSession(starttime=ago(lookback), eventresult='Success')
| where isnotempty(Url)
// Identify requests with encoded IPv4 addresses
| where Url matches regex ipv4_encoded_identification_regex
| where not(ipv4_is_private(DstIpAddr)) // only take traffic going to internet
| project TimeGenerated, Url, SrcIpAddr, SrcUsername, SrcHostname
// Extract IP candidates in their base64 encoded format, significantly reducing the dataset
| extend extracted_encoded_ip_inURL = extract_all(ipv4_encoded_identification_regex, Url)
// We could have more than one ip, expand them out
| mv-expand extracted_encoded_ip_inURL to typeof(string)
| summarize
EventStartTime=min(TimeGenerated),
EventEndTime=max(TimeGenerated),
make_set(Url, 100),
EventCount=count()
by extracted_encoded_ip_inURL, SrcIpAddr, SrcUsername, SrcHostname
// Pad if we need to
| extend extracted_encoded_ip_inURL = iff(strlen(extracted_encoded_ip_inURL) % 2 == 0, extracted_encoded_ip_inURL, strcat(extracted_encoded_ip_inURL, "="))
// Now decode the candidate to a long array, we cannot go straight to string as it cannot handle non-UTF8, we need to strip that first
| extend extracted_encoded_ip_inURL = tostring(base64_decode_toarray(extracted_encoded_ip_inURL))
// Extract the IP candidates from the array
| extend hex_extracted = extract_all(ipv4_decoded_hex_extract, extracted_encoded_ip_inURL)
// Expand, it's still possible that we might have more than 1 IP
| mv-expand hex_extracted
// Now we should have a clean string. We need to put it back into a dynamic array to convert back to a string.
| extend hex_extracted = trim_end(",", tostring(hex_extracted))
| extend hex_extracted = strcat("[", hex_extracted, "]")
| extend hex_extracted = todynamic(hex_extracted)
// Convert the array back into a string
| extend decoded_ip_inURL = unicode_codepoints_to_string(hex_extracted)
| where ipv4_is_private(decoded_ip_inURL)
| project
ip_inURL=decoded_ip_inURL,
Urls=tostring(set_Url),
EventStartTime,
EventEndTime,
EventCount,
SrcIpAddr,
SrcUsername,
SrcHostname;
union ipV4_Private_FromPlainString, ipV4_Private_FromEncodedString
| extend Name = iif(SrcUsername contains "@", tostring(split(SrcUsername,'@',0)[0]),SrcUsername), UPNSuffix = iif(SrcUsername contains "@",tostring(split(SrcUsername,'@',1)[0]),"")
entityMappings:
- entityType: IP
fieldMappings:
- identifier: Address
columnName: ip_inURL
- entityType: IP
fieldMappings:
- identifier: Address
columnName: SrcIpAddr
- entityType: Account
fieldMappings:
- identifier: Name
columnName: Name
- identifier: UPNSuffix
columnName: UPNSuffix
- entityType: Host
fieldMappings:
- identifier: HostName
columnName: SrcHostname
eventGroupingSettings:
aggregationKind: AlertPerResult
customDetails:
EventCount: EventCount
Urls: Urls
EventStartTime: EventStartTime
EventEndTime: EventEndTime
alertDetailsOverride:
alertDisplayNameFormat: "Detected a private ip address '{{ip_inURL}}' carved in URL"
alertDescriptionFormat: "User '{{SrcUsername}}' has been detected requesting URL '{{Urls}}' that contains private IP address '{{ip_inURL}}'. Encoding private IP addresses in a URL can be a method used by attackers to exfiltrate data from a compromised system"
version: 1.0.1
kind: Scheduled
Stages and Predicates
Stage 0: let
let lookback = 1h;
let ipv4_encoded_identification_regex = @"\=([a-zA-Z0-9\/\+]*(?:(?:MC|Au|wL|MS|Eu|xL|Mi|Iu|yL|My|Mu|zL|NC|Qu|0L|NS|Uu|1L|Ni|Yu|2L|Ny|cu|3L|OC|gu|4L|OS|ku|5L){1}[a-zA-Z0-9\/\+]{2,4}){3}[a-zA-Z0-9\/\+\=]*)";
let ipv4_decoded_hex_extract = @"((?:(?:61|62|63|64|65|66|67|68|69|6a|6b|6c|6d|6e|6f|70|71|72|73|74|75|76|77|78|79|7a|41|42|43|44|45|46|47|48|49|4a|4b|4c|4d|4e|4f|50|51|52|53|54|55|56|57|58|59|5a|2f|2b|3d),){6,14}(?:61|62|63|64|65|66|67|68|69|6a|6b|6c|6d|6e|6f|70|71|72|73|74|75|76|77|78|79|7a|41|42|43|44|45|46|47|48|49|4a|4b|4c|4d|4e|4f|50|51|52|53|54|55|56|57|58|59|5a|2f|2b|3d))";
let ipV4_Private_FromPlainString = _Im_WebSession(<inlined as stages below>);
let ipV4_Private_FromEncodedString = _Im_WebSession(<inlined as stages below>);
Stage 1: union
union of 2 branches
Stage 2: source
_Im_WebSession(starttime=ago(lookback), eventresult='Success')
Stage 3: where
| where isnotempty(Url)
Stage 4: extend
| extend ip_inURL = extract(@"\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b", 0, Url)
Stage 5: where
| where ipv4_is_private(ip_inURL)
Stage 6: where
| where not(ipv4_is_private(DstIpAddr))
Stage 7: summarize
| summarize
EventCount=count(),
EventEndTime = max(TimeGenerated),
EventStartTime = min(TimeGenerated),
Urls=tostring(make_set(Url, 100))
by SrcIpAddr, SrcUsername, SrcHostname, ip_inURL
Stage 8: source
_Im_WebSession(starttime=ago(lookback), eventresult='Success')
Stage 9: where
| where isnotempty(Url)
Stage 10: where
| where Url matches regex ipv4_encoded_identification_regex
Stage 11: where
| where not(ipv4_is_private(DstIpAddr))
Stage 12: project
| project TimeGenerated, Url, SrcIpAddr, SrcUsername, SrcHostname
Stage 13: extend
| extend extracted_encoded_ip_inURL = extract_all(ipv4_encoded_identification_regex, Url)
Stage 14: mv-expand
| mv-expand extracted_encoded_ip_inURL to typeof(string)
Stage 15: summarize
| summarize
EventStartTime=min(TimeGenerated),
EventEndTime=max(TimeGenerated),
make_set(Url, 100),
EventCount=count()
by extracted_encoded_ip_inURL, SrcIpAddr, SrcUsername, SrcHostname
Stage 16: extend (3 consecutive steps)
| extend extracted_encoded_ip_inURL = iff(strlen(extracted_encoded_ip_inURL) % 2 == 0, extracted_encoded_ip_inURL, strcat(extracted_encoded_ip_inURL, "="))
| extend extracted_encoded_ip_inURL = tostring(base64_decode_toarray(extracted_encoded_ip_inURL))
| extend hex_extracted = extract_all(ipv4_decoded_hex_extract, extracted_encoded_ip_inURL)
extracted_encoded_ip_inURL =if
/* macro: ((strlen(extracted_encoded_ip_inURL) % 2) == 0) */extracted_encoded_ip_inURLelse
strcat(extracted_encoded_ip_inURL, "=")Stage 17: mv-expand
| mv-expand hex_extracted
Stage 18: extend (4 consecutive steps)
| extend hex_extracted = trim_end(",", tostring(hex_extracted))
| extend hex_extracted = strcat("[", hex_extracted, "]")
| extend hex_extracted = todynamic(hex_extracted)
| extend decoded_ip_inURL = unicode_codepoints_to_string(hex_extracted)
Stage 19: where
| where ipv4_is_private(decoded_ip_inURL)
Stage 20: project
| project
ip_inURL=decoded_ip_inURL,
Urls=tostring(set_Url),
EventStartTime,
EventEndTime,
EventCount,
SrcIpAddr,
SrcUsername,
SrcHostname
Stage 21: extend
extend Name, UPNSuffix
Indicators
These rows show field, operator, and value matches.
| Field | Kind | Values | Search |
|---|---|---|---|
Url | is_not_null | field:"Url" kind:is_not_null | |
Url | regex_match |
| field:"Url" kind:regex_match value:"\=([a-zA-Z0-9\/+]*(?:(?:MC|Au|wL|MS|Eu|xL|Mi|Iu|yL|My|Mu|zL|NC|Qu|0L|NS|Uu|1L|Ni|Yu|2L|Ny|cu|3L|OC|gu|4L|OS|ku|5L){1}[a-zA-Z0-9\/+]{2,4}){3}[a-zA-Z0-9\/+\=]*)" |
decoded_ip_inURL | cidr_match |
| field:"decoded_ip_inURL" kind:cidr_match |
ip_inURL | cidr_match |
| field:"ip_inURL" kind:cidr_match |
Exclusions
The rule actively suppresses these predicates.
| Field | Kind | Excluded values | Search |
|---|---|---|---|
DstIpAddr | cidr_match | 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16, 169.254.0.0/16, 127.0.0.0/8 | excludes:DstIpAddr |
Output fields
These fields are emitted when the rule matches.
| Field | Source |
|---|---|
EventCount | project |
EventEndTime | project |
EventStartTime | project |
SrcHostname | project |
SrcIpAddr | project |
SrcUsername | project |
Urls | project |
ip_inURL | project |
Name | extend |
UPNSuffix | extend |