January 12

Webinar takeaway – Shellcode Execution with Python

0  comments

teaser for this Webcast, which made me attend

Imagine you are pen testing a company and gain access to a Windows application server. You discover the server has application allow listing deployed, and strong EDR/XDR defensive solutions. To your excitement, you find there is a Python interpreter installed. It would be really great if you could use that Python interpreter to execute your favorite C2 framework shellcode and use all of your normal hacking toolsets to continue your work. With a little bit of coding work, you can! In this Black Hills Information Security (BHIS) webcast, you will learn exactly how to achieve your goal of shellcode execution with Python.

My key takeaways

  • Having a python interpreter installed on a Windows Application Server is an additional security risk, as it allows the attacker to create a C2 channel without using any exe (which might be detected by EDR)
    • disable Microsoft Store to avoid LOTL
  • ctypes buildin Python3 lib provides C compatible data types and allows DLL function calling
  • the NTDLL.dll, which is not really documented, might help overcome the barrier between usermode and kernel mode
  • Its easy to crash the interpreter when calling C functions in a DLL if passed incompatible Python-types as arguments
    • using wintypes might help to avoid
  • Remote process injection is often detected by EDR/XDR. Creating a thread within the Python process itself is preferred.
    • Basic steps to follow:
      • Allocate some memory
      • Copy the shellcode to the allocated memory
      • Create the thread with the starting address of the allocated memory
      • Wait on the thread
  • You can reduce the to getting busted by adding english words or NULLs to your script
  • Memory scanners looking for virtual mem not backed by disk image.
    • Use heap in same process
    • Make new thread base address “look” legit.
  • Evaluate if Python3 process is 64 bit or 32 bit: echo(sys.maxsize == 2 ** 63 - 1) or plattform.architecture() (mod import required)

Env

additional links

User comments

Video


Tags

C2, python, shellcode


You may also like

Webinar takeaway – The Ins and Outs of RITA

My key takeaways RITA is made to detect beacons and long connections open source tool Signature based detection of malicious code is outdated Average detect time is over 6 month > 50% of compromised systems are detected by outsiders RITA is behaviour based Needs a bunch of pakets to work on min 1h, default 24h

Read More

Webinar takeaway – Malware of the Day

My key takeaways "Malware of the Day" is about simulating one malware or exploit that was found "in the wild" why? to share with the public so that we can test our security detection abilities in place sharing (safe) PCAPs with identified C2 methods and network traffic patterns smoke detectors are not build to prevent

Read More