Repository navigation
Implement IPv4 and IPv6 Address Pattern Detection in Semantic Classifier #16
Description
Summary
Implement comprehensive IPv4 and IPv6 address pattern detection and validation within the semantic classification system to identify and tag IP addresses found in binary strings.
Context
The semantic classifier currently supports URL and domain detection. IP addresses are a critical type of network indicator that appear frequently in binaries (C&C addresses, configuration endpoints, telemetry servers, hardcoded network targets). Adding IPv4 and IPv6 detection will enable security analysts and reverse engineers to quickly identify potential network indicators of compromise (IOCs).
Current State
Tag::IPv4andTag::IPv6enum variants are already defined insrc/types.rs(lines 18-19)src/classification/mod.rsexists but is currently empty- The semantic tagging infrastructure is in place but needs pattern matching implementation
- Architecture supports regex-based classification per
concept.md
Dependencies
- Blocked by: URL and Domain Classification (Implement URL and Domain Pattern Matching in Semantic Classification System #15 or related)
- The implementation pattern established for URL/Domain detection should be followed for consistency
- Shared validation utilities may be needed
Proposed Solution
Implementation Approach
Implement IP address detection in src/classification/mod.rs (or a dedicated submodule) with the following components:
1. IPv4 Pattern Matching
Pattern: XXX.XXX.XXX.XXX where each octet is 0-255
Validation Rules:
- Four octets separated by dots
- Each octet must be 0-255 (no leading zeros except for "0" itself)
- No leading/trailing dots
- Exclude invalid ranges for context (e.g., 0.0.0.0, 255.255.255.255 may be flagged with lower scores)
Example Valid: 192.168.1.1, 10.0.0.1, 172.16.0.1, 8.8.8.8
Example Invalid: 256.1.1.1, 192.168.1, 192.168.1.1.1, 192.168.01.1 (leading zero)
Regex Pattern (starting point):
\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b
2. IPv6 Pattern Matching
Format Support:
- Full notation:
2001:0db8:85a3:0000:0000:8a2e:0370:7334 - Compressed notation:
2001:db8:85a3::8a2e:370:7334 - Mixed notation (IPv4-mapped):
::ffff:192.0.2.1 - Loopback:
::1 - Link-local:
fe80::1
Validation Rules:
- Eight groups of 4 hexadecimal digits separated by colons
- Double colon
::allowed once to represent consecutive zeros - Trailing/embedded IPv4 addresses in mixed notation
- Case-insensitive hex digits (a-f, A-F)
Example Valid:
2001:db8::1fe80::1::12001:0db8:85a3::8a2e:0370:7334::ffff:192.0.2.1
Implementation Note: IPv6 regex validation is complex. Consider using the ipnetwork or std::net::IpAddr for validation after initial pattern matching.
3. Classification Function Structure
pub fn classify_string(text: &str) -> Vec<Tag> {
let mut tags = Vec::new();
if is_ipv4_address(text) {
tags.push(Tag::IPv4);
}
if is_ipv6_address(text) {
tags.push(Tag::IPv6);
}
// Add other classification logic (URL, Domain, etc.)
tags
}
fn is_ipv4_address(text: &str) -> bool {
// Implementation with regex + validation
}
fn is_ipv6_address(text: &str) -> bool {
// Implementation with regex + std::net::Ipv6Addr parsing
}4. Integration with Scoring System
IP addresses should receive semantic boost per concept.md ranking algorithm:
- IPv4/IPv6 in private ranges: +2 score (internal network indicators)
- IPv4/IPv6 in public ranges: +3 to +5 score (potential C&C, external endpoints)
- IPv4 in special ranges (loopback, multicast): +1 score (informational)
Technical Considerations
-
False Positives:
- Version numbers may look like IPs:
1.2.3.4 - Add context checks: IPs in networking sections get higher confidence
- Consider excluding common version patterns (all octets < 20)
- Version numbers may look like IPs:
-
Performance:
- Use compiled regex with
regexcrate - Consider
aho-corasickfor multi-pattern matching if combined with URL/Domain - Lazy static initialization for regex patterns
- Use compiled regex with
-
Dependencies:
regex = "1.10"(already in use per architecture)- Optional:
ipnetwork = "0.20"or usestd::netfor validation
-
Port Handling:
- Decide if
192.168.1.1:8080should be tagged as IPv4 - Suggest: Strip port suffix before validation, still tag as IPv4
- Decide if
Testing Requirements
Unit Tests
Create src/classification/tests.rs or inline tests with coverage for:
IPv4 Tests:
- ✅ Valid addresses:
192.168.1.1,10.0.0.1,8.8.8.8,1.1.1.1 - ✅ Edge cases:
0.0.0.0,255.255.255.255,127.0.0.1 - ❌ Invalid:
256.1.1.1,192.168.1,192.168.1.1.1,999.999.999.999 - ❌ Leading zeros:
192.168.01.1 - ❌ Version numbers:
1.2.3.4(context-dependent) - ✅ With ports:
192.168.1.1:8080(should extract IP)
IPv6 Tests:
- ✅ Full notation:
2001:0db8:85a3:0000:0000:8a2e:0370:7334 - ✅ Compressed:
2001:db8::1,::1,fe80::1 - ✅ Mixed notation:
::ffff:192.0.2.1,64:ff9b::192.0.2.1 - ✅ All zeros:
:: - ❌ Invalid:
gggg::1,2001:db8::1::2(double::),2001:db8:1 - ✅ With ports/brackets:
[2001:db8::1]:8080
Integration Tests:
- Extract IPs from sample binary strings (mix of text, URLs with IPs, config strings)
- Verify tagging applied correctly to
FoundStringobjects - Test scoring boosts are applied
Documentation
- Add rustdoc comments to classification functions
- Update
concept.mdwith IP classification details - Add examples to
README.mdshowing IP detection
Acceptance Criteria
- IPv4 pattern matching implemented with validation
- IPv6 pattern matching implemented with validation
- Unit tests cover valid, invalid, and edge cases for both formats
- Integration with semantic tagging system (
Tag::IPv4,Tag::IPv6) - False positive mitigation strategies implemented
- Scoring boost integrated into ranking algorithm
- Documentation updated (rustdoc, README, concept.md)
- No performance regression in string extraction pipeline
References
- RFC 791 - Internet Protocol (IPv4)
- RFC 4291 - IPv6 Addressing Architecture
- RFC 5952 - IPv6 Address Text Representation
- Rust
std::net::IpAddrdocumentation
Related Issues
- Implement URL and Domain Pattern Matching in Semantic Classification System #15 (or relevant): URL and Domain Classification (blocking)
- Future: Network endpoint clustering/analysis
Task-ID: stringy-analyzer/ip-address-classification
Requirements: 3.3
Estimated Effort: 2-3 days (implementation + comprehensive testing)
Activity
unclesp1d3r commentedon Nov 10, 2025
@coderabbitai Enhance this issue body with additional context and a proposed solution. Improve the issue title and assign the proper labels and other metadata.
[-]IP Address Classification[/-][+]Implement IPv4 and IPv6 Address Pattern Detection in Semantic Classifier[/+]traycerai commentedon Nov 10, 2025
Plan
Observations
Current State Analysis
The codebase has a well-established foundation:
Tag::IPv4andTag::IPv6are already defined insrc/types.rs(lines 18-19) with proper serde serializationsrc/classification/mod.rscontains only a comment, ready for implementationSemanticClassifierstruct using regex + lazy_staticregexcrate is already in use per architecture;lazy_staticmay need to be addeddocs/src/classification.mdalready documents IPv4/IPv6 patterns (lines 29-35)#[cfg(test)]modules for unit tests, as seen in all container parsersSemanticClassifierstructureKey Requirements from Specs
From the GitHub issue requirements:
From
concept.md: Classification should use "Regex/automata buckets:url,domain,ipv4/6"Implementation Strategy
Following the pattern from issue #15, implement a
SemanticClassifierinsrc/classification/semantic.rsthat handles both URL/Domain (from #15) and IPv4/IPv6 detection. The approach uses:std::net::IpAddrvalidation for correctness192.168.1.1:8080→192.168.1.1)[::1]and[::1]:8080Approach
Implement IPv4 and IPv6 address pattern detection in the semantic classification system by:
regex,lazy_static) toCargo.tomlif not already presentsrc/classification/semantic.rswithSemanticClassifierstructstd::net::Ipv4Addrstd::net::Ipv6Addrsrc/classification/mod.rsto export the classifierThis follows the established pattern from issue #15 and integrates seamlessly with the existing type system.
Reasoning
The GitHub ticket provides comprehensive requirements including validation rules, regex patterns, test cases, and acceptance criteria. The implementation should follow the established pattern from issue #15 while addressing the specific needs for IP address detection: two-stage validation (regex + std::net parsing), port handling, false positive mitigation for version numbers, and comprehensive test coverage for both IPv4 and IPv6 formats.
Mermaid Diagram
sequenceDiagram participant User as User/Extraction Pipeline participant SC as SemanticClassifier participant Regex as Regex Patterns (lazy_static) participant StdNet as std::net::IpAddr participant Tags as Vec<Tag> User->>SC: classify("192.168.1.1:8080") SC->>SC: classify_ip_addresses() SC->>SC: is_ipv4_address() SC->>SC: strip_port() → "192.168.1.1" SC->>Regex: IPV4_REGEX.is_match() Regex-->>SC: true SC->>StdNet: Ipv4Addr::from_str("192.168.1.1") StdNet-->>SC: Ok(192.168.1.1) SC->>SC: is_likely_version_number() SC-->>SC: false (octets not all < 20) SC-->>SC: true (valid IPv4) SC->>SC: is_ipv6_address() SC->>Regex: IPV6_REGEX.is_match() Regex-->>SC: false SC-->>SC: false (not IPv6) SC->>Tags: push(Tag::IPv4) SC-->>User: vec![Tag::IPv4] Note over User,Tags: For IPv6 with brackets: [::1]:8080 User->>SC: classify("[::1]:8080") SC->>SC: is_ipv6_address() SC->>SC: strip_ipv6_brackets() → "::1:8080" SC->>SC: strip_port() → "::1" SC->>Regex: IPV6_REGEX.is_match() Regex-->>SC: true SC->>StdNet: Ipv6Addr::from_str("::1") StdNet-->>SC: Ok(::1) SC->>Tags: push(Tag::IPv6) SC-->>User: vec![Tag::IPv6]Proposed File Changes
file:Cargo.toml (Modify)
Add required dependencies to the
[dependencies]section:These dependencies enable efficient semantic classification as specified in the architecture documentation. The
regexcrate provides efficient pattern matching, whilelazy_staticenables one-time compilation of regex patterns for performance.file:src/classification/semantic.rs (New)
Create the semantic classifier module with IPv4 and IPv6 detection capabilities:
Structure:
Imports:
regex::Regexlazy_static::lazy_staticstd::net::{IpAddr, Ipv4Addr, Ipv6Addr}crate::types::TagLazy Static Regex Patterns:
IPV4_REGEX: Pattern\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\bfor matching IPv4 addresses with proper octet validation (0-255)IPV6_REGEX: Pattern to match IPv6 addresses including compressed notation (::1), full notation (2001:0db8:85a3:0000:0000:8a2e:0370:7334), and mixed notation (::ffff:192.0.2.1)PORT_SUFFIX_REGEX: Pattern:[0-9]{1,5}$to detect and strip port numbersIPV6_BRACKETS_REGEX: Pattern^\[(.+)\]to handle bracketed IPv6 addresses like[::1]SemanticClassifier Struct: Empty struct that will hold classification logic
Implementation Methods:
is_ipv4_address(text: &str) -> bool:
Ipv4Addr::from_str()to ensure proper formatis_ipv6_address(text: &str) -> bool:
[::1]→::1)Ipv6Addr::from_str()for canonical validationclassify_ip_addresses(text: &str) -> Vec:
is_ipv4_address(), pushTag::IPv4if matchedis_ipv6_address(), pushTag::IPv6if matchedclassify(text: &str) -> Vec:
classify_ip_addresses()to get IP tagsHelper Functions:
strip_port(text: &str) -> &str: Remove:portsuffix if presentstrip_ipv6_brackets(text: &str) -> &str: Remove[and]from IPv6 addressesis_likely_version_number(text: &str) -> bool: Check if IPv4-like string is actually a version numberUnit Tests (in
#[cfg(test)]module):IPv4 Tests:
test_ipv4_valid_addresses: Test192.168.1.1,10.0.0.1,8.8.8.8,1.1.1.1,127.0.0.1,0.0.0.0,255.255.255.255test_ipv4_invalid_addresses: Test256.1.1.1,192.168.1,192.168.1.1.1,999.999.999.999,192.168.01.1(leading zeros)test_ipv4_with_port: Test192.168.1.1:8080,10.0.0.1:443(should extract IP)test_ipv4_version_numbers: Test1.2.3.4,2.0.1.0(should reject as version numbers)test_ipv4_edge_cases: Test boundary values and special addressesIPv6 Tests:
test_ipv6_full_notation: Test2001:0db8:85a3:0000:0000:8a2e:0370:7334test_ipv6_compressed: Test2001:db8::1,::1,fe80::1,::test_ipv6_mixed_notation: Test::ffff:192.0.2.1,64:ff9b::192.0.2.1test_ipv6_invalid: Testgggg::1,2001:db8::1::2(double::),2001:db8:1test_ipv6_with_brackets: Test[2001:db8::1],[::1]test_ipv6_with_port: Test[2001:db8::1]:8080Integration Tests:
test_classify_ipv4: Test thatclassify()returnsvec![Tag::IPv4]for valid IPv4test_classify_ipv6: Test thatclassify()returnsvec![Tag::IPv6]for valid IPv6test_classify_no_ip: Test thatclassify()returns empty vector for non-IP stringstest_classify_multiple_patterns: Test strings that might match multiple patternsFollow the testing pattern established in existing container parsers with inline
#[cfg(test)]modules.file:src/classification/mod.rs (Modify)
Replace the existing comment with proper module structure:
Module Declaration: Add
pub mod semantic;to declare the semantic classification submoduleRe-exports: Add
pub use semantic::SemanticClassifier;to make the classifier easily accessible fromclassification::SemanticClassifierModule Documentation: Add rustdoc comments explaining:
file:docs/src/classification.md (Modify)
Update the IP Addresses section to reflect the actual implementation:
Update IPv4 Pattern: Replace the simplified pattern with the actual regex used:
\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\bAdd Validation Details: Document that the implementation uses two-stage validation:
std::net::IpAddrvalidation for correctnessDocument Port Handling: Add note that IP addresses with ports (e.g.,
192.168.1.1:8080) are supported by stripping the port suffixDocument IPv6 Bracket Handling: Add note that bracketed IPv6 addresses (e.g.,
[::1]) are supportedDocument False Positive Mitigation: Explain that version numbers like
1.2.3.4are filtered out using heuristics (all octets < 20)Add Implementation Note: Reference
src/classification/semantic.rsas the implementation locationUpdate Examples: Ensure examples match the test cases in the implementation
file:README.md (Modify)
Update the development status section to reflect IPv4/IPv6 classification implementation:
Update Classification Status: Change the line about semantic classification to indicate that IPv4/IPv6 detection is now implemented:
Update Feature List: Ensure the "Smart classification" bullet point mentions that IPv4/IPv6 detection is functional:
This provides accurate status information to users and contributors about which classification features are available.
Import In IDE
🤖 Prompt for AI Agents
Execution Information
Branch: main
Commit: e2eb692
💡 Tips
Supported Commands (Inside Comments)
@traycerai generateto iterate on the previous version of the implementation plan.Supported Commands (Inside Description)
@traycerai ignoreanywhere in the ticket description to prevent this ticket from being processed.@traycerai branch:<branch-name>anywhere in the ticket description to specify the target branch for the implementation plan.Community
coderabbitai commentedon Nov 10, 2025
Tip
For best results, initiate chat on the files or code changes.
🧩 Analysis chain
🏁 Script executed:
Length of output: 1490
🏁 Script executed:
Length of output: 24590
🏁 Script executed:
Length of output: 6268
🏁 Script executed:
Length of output: 157
@unclesp1d3r I've successfully enhanced issue #16 with comprehensive details:
Changes Made
✅ Improved Title
Before: "IP Address Classification"
After: "Implement IPv4 and IPv6 Address Pattern Detection in Semantic Classifier"
✅ Enhanced Issue Body
Added detailed sections including:
Summary & Context: Explains why IP detection is critical for security analysis (C&C addresses, IOCs, network endpoints)
Current State: Documents existing infrastructure (Tag enum variants already defined in
src/types.rs, empty classification module ready)Proposed Solution:
Technical Considerations:
regex,std::net)Testing Requirements: Comprehensive test cases for both IPv4 and IPv6 with valid/invalid examples
Acceptance Criteria: Checkboxes for implementation, testing, documentation, and performance
References: Links to RFC 791, 4291, 5952, and Rust documentation
✅ Labels Added
priority:medium- Balanced priority for v0.1 milestonegood first issue- Well-defined scope with clear acceptance criteria✅ Metadata Preserved
The issue is now ready for implementation with clear technical guidance, validation rules based on RFCs, and comprehensive test coverage requirements. The blocking dependency on URL/Domain Classification is clearly documented.
unclesp1d3r commentedon Jan 4, 2026
@traycerai generate
traycerai commentedon Jan 4, 2026
Hi @unclesp1d3r, I have updated the Implementation Plan to reflect the recent changes in the ticket.