Unprotected SELFDESTRUCT Instruction (SWC-106)

Description
SWC-106 refers to the vulnerability where a contract is vulnerable to a malicious self-destruct attack due to missing or insufficient access controls. This means that a malicious party can destroy the contract by calling the selfdestruct function with their own address as the recipient.
In Solidity, the selfdestruct function can be called by any account, and it allows the owner of the contract to transfer the contract’s remaining balance to an arbitrary address before destroying the contract. If the contract does not have proper access controls in place, any account can call this function and destroy the contract, which could result in a complete loss of funds.
To mitigate this vulnerability, access controls should be implemented to restrict the use of the selfdestruct function to only authorized accounts. This can be done by implementing checks in the contract to ensure that only specific accounts are allowed to call this function, or by using the onlyOwner modifier in the contract to ensure that only the owner of the contract can call it. Additionally, contracts that do not require the use of the selfdestruct function should not include it at all, to minimize the potential attack surface.
Восстановление
The self-destruct function in Solidity allows a contract to be removed from the blockchain, freeing up storage and preventing it from consuming gas in the future. However, this function can be misused by malicious actors to destroy a contract without permission, causing permanent loss of data and assets.
To mitigate this vulnerability, one solution is to remove the self-destruct function entirely unless it is absolutely necessary for the intended functionality of the contract. If it is necessary, a multisig scheme can be implemented to require multiple parties to approve the self-destruct action. This would prevent a single malicious actor from executing the self-destruct function and destroying the contract.
A multisig scheme involves creating a contract that requires a specified number of signatures from different parties before a transaction can be executed. In the case of a self-destruct function, the multisig contract would require a predetermined number of signatures from authorized parties before allowing the self-destruct to be executed. This adds an extra layer of security and makes it more difficult for malicious actors to execute the self-destruct function without authorization.
Overall, it is important for developers to carefully consider the necessity of the self-destruct function in their contracts and implement appropriate access controls and security measures to prevent unauthorized access to this functionality.
Contract Samples
Code with a vulnerability
pragma solidity ^0.4.23;
contract SuicideMultiTxFeasible {
uint256 private initialized = 0;
uint256 public count = 1;
function init() public {
initialized = 1;
}
function run(uint256 input) {
if (initialized == 0) {
return;
}
selfdestruct(msg.sender);
}
}
Code without a vulnerability
pragma solidity ^0.4.23;
contract SuicideMultiTxFeasible {
uint256 private initialized = 0;
uint256 public count = 1;
function init() public {
initialized = 1;
}
function run(uint256 input) {
if (initialized != 2) {
return;
}
selfdestruct(msg.sender);
}
}
Tools for scaning SWC-106
1. Mythril: It is a popular open-source tool that can analyze Solidity code to detect various vulnerabilities, including SWC-106.
2. SmartCheck: It is a smart contract security analysis tool that uses symbolic execution to identify vulnerabilities, including SWC-106.
3. Slither: It is another open-source tool that can detect various security issues in Solidity code, including the SWC-106 vulnerability.
4. Securify: It is a security scanner that uses a combination of static and dynamic analysis to identify vulnerabilities in smart contracts, including SWC-106.
Общее перечисление слабых мест (CWE)
CWE-284: Неправильный контроль доступа
Mitigation for SWC-106
To mitigate SWC-106, it is recommended to remove the self-destruct functionality unless it is absolutely required. If self-destruct is necessary, it is recommended to implement a multi-signature scheme, where multiple parties must approve the self-destruct action.
Additionally, it is important to implement proper access controls to ensure that only authorized parties can call the self-destruct function. This can be done by using modifiers such as onlyOwner or onlyAuthorized. It is also recommended to limit the scope of the self-destruct function by only allowing it to be called under certain conditions or within a specific time period.
Furthermore, it is important to thoroughly test the smart contract for vulnerabilities and to conduct regular security audits to identify and fix any potential vulnerabilities. Using tools such as automated vulnerability scanners and manual code reviews can also help to identify potential vulnerabilities.
Заключение
As a result of missing or inadequate access controls, SWC-106 is a vulnerability that enables hostile parties to self-destruct a contract. It is advised to disable the self-destruct capability unless it is absolutely necessary in order to prevent this issue. A multisig scheme should be deployed if there is a legitimate use-case such that many parties must consent to the self-destruct operation.
When including self-destruct capability in their contracts, developers should carefully evaluate the access restrictions and possible repercussions and put in place the necessary safeguards to avoid unauthorised access or misuse. Code reviews and security audits can also be beneficial in locating and resolving vulnerabilities like SWC-106.
Другие Услуги
Insomnia Security Scanner
AI-powered web application security scanner by CQR. Automated vulnerability discovery, exploit verification, and detailed reporting for modern applications.
Узнать большеЗащита Инфраструктуры CRYEYE
Аудит безопасности с помощью CryEye обеспечивает информационную безопасность предприятия, защищая всю инфраструктуру.
Узнать большеТестирование на проникновение
Найдите уязвимости во всей инфраструктуре вашего бизнеса раньше, чем это сделают хакеры! В рамках консалтинга по тестированию на проникновение мы подберем методы пентестов.
Узнать большеСоциальная инженерия
Simulate real-world phishing, vishing, and pretexting attacks to measure and improve your team's security awareness and response capabilities.
Узнать большеНагрузочное Тестирование
All kinds of load and performance testing of your system from the CQR online security company.
Узнать большеAI-Powered Vulnerability Assessment
Leverage artificial intelligence to discover, prioritize, and remediate vulnerabilities across your digital assets faster and more accurately than traditional scanners.
Узнать большеCloud Security Audit (AWS / GCP / Azure)
Comprehensive security review of your cloud environments — IAM policies, network controls, data exposure, and misconfigurations across all major cloud platforms.
Узнать большеDevSecOps Integration
Embed security into every stage of your CI/CD pipeline. Automated SAST, DAST, SCA, and secret scanning so vulnerabilities are caught before they reach production.
Узнать большеAPI Security Testing
In-depth testing of REST, GraphQL, and SOAP APIs for authentication flaws, authorization bypasses, injection vulnerabilities, and data leakage risks.
Узнать большеMobile Application Penetration Testing
Manual and automated security testing for iOS and Android applications — reverse engineering, runtime analysis, traffic interception, and backend API assessment.
Узнать большеIoT Security Assessment
Evaluate firmware, communication protocols, cloud backends, and physical interfaces of IoT devices to identify vulnerabilities before attackers do.
Узнать большеBlockchain & Smart Contract Audit
Formal verification and manual code review of smart contracts on Ethereum, Solana, and other chains. Detect reentrancy, overflow, and logic flaws before deployment.
Узнать большеRed Team Operations
Advanced adversary simulation using real attacker TTPs (MITRE ATT&CK) to test your detection, response, and overall security posture under realistic conditions.
Узнать большеThreat Intelligence & Monitoring
Continuous monitoring of threat feeds, dark web, and attacker infrastructure to provide actionable intelligence specific to your organization and industry.
Узнать большеZero Trust Architecture Review
Assess and design your Zero Trust security model — identity verification, micro-segmentation, least-privilege access, and continuous validation controls.
Узнать большеCompliance Consulting (PCI DSS / SOC 2 / GDPR)
Expert guidance to achieve and maintain compliance with major security frameworks. Gap analysis, remediation roadmaps, and audit-readiness support.
Узнать большеDark Web Monitoring
Continuous surveillance of dark web forums, marketplaces, and breach databases for leaked credentials, sensitive data, or mentions of your organization.
Узнать большеPhishing Simulation & Awareness Training
Controlled phishing campaigns combined with interactive security awareness training to build a human firewall across your entire organization.
Узнать большеSupply Chain Security Audit
Assess third-party vendor risks, open-source dependencies, and software supply chain integrity to prevent attacks like SolarWinds and Log4Shell.
Узнать большеContainer & Kubernetes Security
Security review of Docker images, Kubernetes clusters, RBAC policies, network policies, and runtime configurations to harden your container infrastructure.
Узнать большеWeb Application Firewall (WAF) Deployment
Professional WAF setup, rule tuning, and ongoing management to block SQL injection, XSS, CSRF, and other OWASP Top 10 threats in real time.
Узнать большеBug Bounty Program Management
Full lifecycle management of your bug bounty program — scope definition, researcher coordination, triage, validation, and remediation tracking.
Узнать большеOSINT Investigation Services
Open-source intelligence gathering on individuals, organizations, and infrastructure. Ideal for pre-engagement recon, fraud investigation, and competitive analysis.
Узнать большеDigital Forensics & Incident Response
Rapid response to security breaches — evidence collection, malware analysis, attacker timeline reconstruction, and actionable remediation recommendations.
Узнать больше