RodDoSanz commited on
Commit
eebdd68
·
1 Parent(s): 331c344

feat: strip inputs

Browse files
tdagent/tools/get_domain_information.py CHANGED
@@ -71,7 +71,7 @@ def get_geolocation(ip: str) -> dict[str, Any] | str:
71
  """
72
  try:
73
  return requests.get(
74
- f"https://geolocation-db.com/json/{ip}",
75
  timeout=1,
76
  ).json()
77
  except Exception as e: # noqa: BLE001
@@ -174,7 +174,7 @@ def enumerate_dns(domain_name: str) -> dict[str, Any] | None:
174
  enumeration = {}
175
  for record_type in _DNS_RECORD_TYPES:
176
  try:
177
- record = _request_dns_record(domain_name, record_type, timeout=1)
178
  if record:
179
  enumeration[record_type] = record
180
  except Exception as e: # noqa: BLE001, PERF203
@@ -242,7 +242,9 @@ def scrap_subdomains_for_domain(domain_name: str) -> list[str]:
242
  except FileNotFoundError:
243
  return []
244
 
245
- potential_subdomains = [f"{subdomain}.{domain_name}" for subdomain in subdomains]
 
 
246
  with ThreadPoolExecutor(max_workers=None) as executor:
247
  results = executor.map(resolve_subdomain_ipv4, potential_subdomains)
248
  return [domain for domain in results if domain]
@@ -311,7 +313,7 @@ def retrieve_ioc_from_threatfox(potentially_ioc: str) -> str:
311
  )
312
  data = {
313
  "query": "search_ioc",
314
- "search_term": potentially_ioc,
315
  }
316
  json_data = json.dumps(data)
317
  try:
 
71
  """
72
  try:
73
  return requests.get(
74
+ f"https://geolocation-db.com/json/{ip.strip()}",
75
  timeout=1,
76
  ).json()
77
  except Exception as e: # noqa: BLE001
 
174
  enumeration = {}
175
  for record_type in _DNS_RECORD_TYPES:
176
  try:
177
+ record = _request_dns_record(domain_name.strip(), record_type, timeout=1)
178
  if record:
179
  enumeration[record_type] = record
180
  except Exception as e: # noqa: BLE001, PERF203
 
242
  except FileNotFoundError:
243
  return []
244
 
245
+ potential_subdomains = [
246
+ f"{subdomain}.{domain_name.strip()}" for subdomain in subdomains
247
+ ]
248
  with ThreadPoolExecutor(max_workers=None) as executor:
249
  results = executor.map(resolve_subdomain_ipv4, potential_subdomains)
250
  return [domain for domain in results if domain]
 
313
  )
314
  data = {
315
  "query": "search_ioc",
316
+ "search_term": potentially_ioc.strip(),
317
  }
318
  json_data = json.dumps(data)
319
  try:
tdagent/tools/retrieve_from_mitre_attack.py CHANGED
@@ -29,12 +29,15 @@ def get_stix_object_of_attack_id(
29
  or as a custom dictionary following the structure defined by the relevant
30
  Pydantic model, depending on the 'stix_format' flag.
31
  """
32
- lift = attack_client()
33
- return lift.get_object_by_attack_id(
34
- object_type=object_type,
35
- attack_id=attack_id,
36
- stix_format=False,
37
- )[0]
 
 
 
38
 
39
 
40
  gr_get_stix_of_attack_id = gr.Interface(
 
29
  or as a custom dictionary following the structure defined by the relevant
30
  Pydantic model, depending on the 'stix_format' flag.
31
  """
32
+ try:
33
+ lift = attack_client()
34
+ return lift.get_object_by_attack_id(
35
+ object_type=object_type.strip(),
36
+ attack_id=attack_id.strip(),
37
+ stix_format=False,
38
+ )[0]
39
+ except Exception as e: # noqa: BLE001
40
+ return {"Exception": str(e)}
41
 
42
 
43
  gr_get_stix_of_attack_id = gr.Interface(