1

I tried to use pymem in order to process inject into a subprocess I spawned. The code is below:

from pymem import Pymem
import os
import subprocess

svc = subprocess.Popen(['svchost.exe'])
pid = svc.pid
print("process id is: ", pid)

pm = Pymem(pid)
pm.inject_python_interpreter()
shellcode = """
import tkinter as tk
mn = tk.Tk()
mn.mainloop()
"""
pm.inject_python_shellcode(shellcode)

I tried running the code referenced above ^, it did not work. error I got is as follows:

process id is:  7300
Traceback (most recent call last):
  File "C:\Users\yallah\Documents\shel.py", line 28, in <module>
    pm.inject_python_interpreter()
  File "C:\Users\yallah\AppData\Local\Programs\Python\Python311\Lib\site-packages\pymem\__init__.py", line 124, in inject_python_interpreter
    self.start_thread(py_initialize_ex, param_addr)
  File "C:\Users\yallah\AppData\Local\Programs\Python\Python311\Lib\site-packages\pymem\__init__.py", line 191, in start_thread
    pymem.logger.debug('New thread_id: 0x%08x' % thread_h)
                       ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~
TypeError: %x format: an integer is required, not NoneType

Without the use of the integer it works fine. I need to reference the process ID of the spawned process though, Any suggestions?

ysfsun
  • 11
  • 2

0 Answers0