|
| 1 | +# Description # |
| 2 | +# This scanner is looking for iqy files used with excel. |
| 3 | +# |
| 4 | +# author: Tasha Taylor |
| 5 | +# date: 10/30/2023 |
| 6 | + |
| 7 | +import re |
| 8 | + |
| 9 | +from strelka import strelka |
| 10 | + |
| 11 | + |
| 12 | +class ScanIqy(strelka.Scanner): |
| 13 | + """ |
| 14 | + Extract URLs from IQY files. |
| 15 | +
|
| 16 | + IQY files, or Excel Web Query Internet Inquire files, are typically created from a VBA Web Query output. |
| 17 | + The following is a typical format: |
| 18 | + WEB |
| 19 | + 1 |
| 20 | + [URL] |
| 21 | + [optional parameters] |
| 22 | + Additional properties can be found at: https://learn.microsoft.com/en-us/office/vba/api/excel.querytable |
| 23 | + """ |
| 24 | + |
| 25 | + def scan(self, data, file, options, expire_at): |
| 26 | + try: |
| 27 | + # Regular expression for detecting a URL-like pattern |
| 28 | + address_pattern = re.compile( |
| 29 | + r"\b(?:http|https|ftp|ftps|file|smb)://\S+|" |
| 30 | + r"\\{2}\w+\\(?:[\w$]+\\)*[\w$]+", |
| 31 | + re.IGNORECASE, |
| 32 | + ) |
| 33 | + |
| 34 | + # Attempt UTF-8 decoding first, fall back to latin-1 if necessary |
| 35 | + try: |
| 36 | + data = data.decode("utf-8") |
| 37 | + except UnicodeDecodeError: |
| 38 | + data = data.decode("latin-1") |
| 39 | + |
| 40 | + # Split lines to review each record separately |
| 41 | + data_lines = data.splitlines() |
| 42 | + |
| 43 | + addresses = set() |
| 44 | + # For each line, check if the line matches the address pattern. |
| 45 | + # In a typical IQY file, the "WEB" keyword is at the beginning of the file, |
| 46 | + # and what follows is usually just one URL with optional additional parameters. |
| 47 | + # However, because we are iterating lines anyway, lets check for additional addresses anyway. |
| 48 | + for entry in data_lines[1:]: |
| 49 | + match = address_pattern.search(entry) |
| 50 | + if match: |
| 51 | + address = match.group().strip() |
| 52 | + if address: |
| 53 | + addresses.add(address) |
| 54 | + |
| 55 | + # Evaluate if any addresses were found and assign the boolean result. |
| 56 | + self.event["address_found"] = bool(addresses) |
| 57 | + |
| 58 | + # Send all addresses to the IOC parser. |
| 59 | + self.add_iocs(list(addresses), self.type.url) |
| 60 | + |
| 61 | + except UnicodeDecodeError as e: |
| 62 | + self.flags.append(f"Unicode decoding error: {e}") |
| 63 | + except Exception as e: |
| 64 | + self.flags.append(f"Unexpected exception: {e}") |
0 commit comments