Skip to content

Commit 653b8b5

Browse files
authoredAug 28, 2024··
Merge pull request #82 from tlansec/bugfix/cidr_notation_ips
Avoid parsing CIDR notation IPs
2 parents b737020 + a2dcb43 commit 653b8b5

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed
 

‎iocextract.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ def ipv4_len(ip_len=3):
245245
[\[\(\\]*?\.[\]\)]*?
246246
){3}
247247
(?:[1-9]?\d|1\d\d|2[0-4]\d|25[0-5])
248-
(?:(?=[^\d\.])|$)
248+
(?:(?=[^\d\.])|$)(?!\/\d{1,2}(?!\d))
249249
""",
250250
re.VERBOSE,
251251
)
@@ -262,7 +262,7 @@ def ipv4_len(ip_len=3):
262262
){4}
263263
([01]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])
264264
(?:[1-9]?\d|1\d\d|2[0-4]\d|25[0-5])
265-
(?:(?=[^\d\.])|$)
265+
(?:(?=[^\d\.])|$)(?!\/\d{1,2}(?!\d))
266266
""",
267267
re.VERBOSE,
268268
)
@@ -611,7 +611,6 @@ def ipv4_str(data):
611611
# Iterates over any ip address with 4 numbers after the final (3rd) octet
612612
for ip_address in ipv4_len(4).finditer(data):
613613
pass
614-
615614
if refang:
616615
yield refang_ipv4(ip_address.group(0))
617616
else:

‎test_data/invalid.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ x.x.x.x
88
tooshor.t
99
tooshor.
1010
adc83b191b1c6ea0fd8b46cd9f32e592fc
11+
100.20.30.0/24

0 commit comments

Comments
 (0)
Please sign in to comment.