KC7-Foundation / kc7

A cybersecurity game in Azure Data Explorer
https://kc7cyber.com
Apache License 2.0
162 stars 14 forks source link

modified get_links function to improve data generation speed #56

Closed kkneomis closed 2 years ago

kkneomis commented 2 years ago

The get_links function was querying the database to get domains. but this happened EVERYTIME an email was generated - so thousands of time per data generation cycle

def get_link(actor:Actor, return_domain:bool=False) -> str:
    """Get a link containing actor's domain"""

    dns_records = [record for record in actor.dns_records]
    dns_record = random.choice(dns_records)
    dns_record.active = True  # set record to active so we can track which domains have been used
    domain = dns_record.domain

We abstracted this back up to the email generation function. So only one db query is made per email generation cycle. This reduced gen_email function runtime from 5-10s -> .2s

def gen_email(employees: "list[Employee]", actor: Actor, count_emails:int) -> None:
    """
    Make a call to the Azure email function
    to create an email, post to log analytics
    and send a secondary request to generate browsing traffic
    """

    actor_domains = [record.domain for record in actor.dns_records]

    for _ in range(count_emails):
        # time is returned as timestamp (float)
        time = get_time()