SlideShare a Scribd company logo
Bypass AV in Python
by y0nd13.
Quick introduction to Python
• By default exist in every major Linux
Distribution
• Can be install or run as portable tools in
Windows :
How interpreter language work.
Hello World in Python
Easy right!!
So what’s the big deal?
• Python support Foreign Function Instruction
• It supports Ctypes.
• http://docs.python.org/2/library/ctypes.html
• It provides C compatible data types, and allows
calling functions in DLLs or shared libraries. It can
be used to wrap these libraries in pure Python
• Smell profits!!!
• Alternative ways besides using import system
• Good for Post Exploitation
• Bypass AV 
Quick Introduction to Python FFI
A Simple MessageBoxA 
• From MSDN
• Required 4 argument,
How to understand quickly 
• HWND – A handle to the owner window of the message box to be created.
If this parameter is NULL, the message box has no owner window. (SO we
set to Null, in Python Null is None)
• LPCTSR lpText - It’s a string for a Text
• LPCTSR lpCaption – It’s a string for the MessageBox Title
• UINT - Unsigned Integer .
_in_opt_ is a SAL Annotation saying you can put NULL as a value
SAL Annotation shortcut
Parameters are
required
Parameters are
optional
Input to called function _In_ _In_opt_
Input to called function, and output to
caller
_Inout_ _Inout_opt_
Output to caller _Out_ _Out_opt_
Output of pointer to caller _Outptr_ _Outptr_opt_
How easy to pop up a MessageBox in
python?
• Simple
from ctypes import *
ctypes.windll.user32.MessageBoxA(None,"Hello World","Title",None)
How to about WinExec?
• WinExec is a classical function since the age of Windows 16-
bit . Only 2 Args are needed.
• From MSDN
• We know lpCmdLine is a string for the Exectuable path but
what value should we place for uCmdShow?
uCmdShow from MSDN
• http://msdn.microsoft.com/en-
us/library/windows/desktop/ms633548(v=vs.85).aspx
To Spawn a calcfrom ctypes import *
ctypes.windll.kernel32.WinExec(“C:Windowssystem32calc.exe”,1)
Get CurrentProcessID
How about Executing Shellcode?
• Many ways
– File Dropping Technique (BAD)
– Code Injection Technique(BAD)
– InMemory Technique (G000D)
• File Dropping Technique are bad , since antivirus/malware will
immedietely catch it up and trigeger
• Code Injection , affects the integrity of a binary. HIPS might trigger
alert.
• Why Shellcode? Becoz we can!!
InMemory Technique
• We are going to chain 4 API to execute our
shellcode .
– >VirtualAlloc()
– >WriteProcessMemory()
– >CreateThread()
– >WaitForSingleObject()
VirtualAlloc()
• lpAddress = Null
• dwSize = length of shellcode can be use,
• flAllocation = MEM_COMMIT|MEM_RESERVED (0x3000)
• flProtect = PAGE_EXECUTE_READWRITE(0x40)
WriteProcessMemory()
• hProcess = -1 * we writing in the same process
• lpBaseAddress = A Pointer to address return from VirtualALloc()
• lpBuffer = A pointer to our buffer
• nSize = we can use shellcode size and times 2 to be safe
• lpNUmberofBytesWritten = Null it..
CreateThread()
• Everything is 0 except for (go figure it out
yerself)
WaitForSingleObject()
• -1 , -1 !!!
P.O.C
• Inspired by SK Training.. Use xcc !!!
Using OllyDBG
Attached with Olly
Executing native inside us heheheheh
2nd POC is our calc 
Common technique in Bypassing Stuff in Python.
(Optional) Freeze it to exe 
• Using pyinstaller
Simple2
Exercise 
• Create a Reverse Shell is a piece of cake!
Reference
• Understanding Win32Shellcode Skape:
• http://www.hick.org/code/skape/papers/win32-shellcode.pdf
• Advance Windows Shellcode, SK:
• http://www.phrack.org/issues.html?id=7&issue=62
• http://msdn.microsoft.com/en-US/

More Related Content

PPTX
Hacked? Pray that the Attacker used PowerShell
PPTX
Power of linked list
PPTX
[若渴計畫] Black Hat 2017之過去閱讀相關整理
PPTX
Windows Kernel Exploitation : This Time Font hunt you down in 4 bytes
PPTX
Automating Post Exploitation with PowerShell
PPTX
ONOS System Test - ONS2016
PPTX
Pwning with powershell
PPTX
PowerShell for Cyber Warriors - Bsides Knoxville 2016
Hacked? Pray that the Attacker used PowerShell
Power of linked list
[若渴計畫] Black Hat 2017之過去閱讀相關整理
Windows Kernel Exploitation : This Time Font hunt you down in 4 bytes
Automating Post Exploitation with PowerShell
ONOS System Test - ONS2016
Pwning with powershell
PowerShell for Cyber Warriors - Bsides Knoxville 2016

What's hot (20)

PDF
Attack All the Layers: What's Working during Pentests (OWASP NYC)
PDF
PPTX
Vulnerability desing patterns
PPTX
Get-Help: An intro to PowerShell and how to Use it for Evil
PPTX
FreeIPA - Attacking the Active Directory of Linux
PPTX
Defcon - Veil-Pillage
PDF
Derbycon - The Unintended Risks of Trusting Active Directory
PPTX
Vulnerabilities on Various Data Processing Levels
PPTX
Introducing PS>Attack: An offensive PowerShell toolkit
PPTX
Guardians of your CODE
PDF
TriplePlay-WebAppPenTestingTools
PPTX
G rpc lection1
PDF
Practical Malware Analysis Ch12
PPTX
SSL Checklist for Pentesters (BSides MCR 2014)
PPTX
Owning computers without shell access dark
PPTX
You didnt see it’s coming? "Dawn of hardened Windows Kernel"
PDF
Статический анализ кода в контексте SSDL
PDF
CNIT 126: 10: Kernel Debugging with WinDbg
PPTX
Secure360 - Attack All the Layers! Again!
PPTX
Powering up on power shell avengercon - 2018
Attack All the Layers: What's Working during Pentests (OWASP NYC)
Vulnerability desing patterns
Get-Help: An intro to PowerShell and how to Use it for Evil
FreeIPA - Attacking the Active Directory of Linux
Defcon - Veil-Pillage
Derbycon - The Unintended Risks of Trusting Active Directory
Vulnerabilities on Various Data Processing Levels
Introducing PS>Attack: An offensive PowerShell toolkit
Guardians of your CODE
TriplePlay-WebAppPenTestingTools
G rpc lection1
Practical Malware Analysis Ch12
SSL Checklist for Pentesters (BSides MCR 2014)
Owning computers without shell access dark
You didnt see it’s coming? "Dawn of hardened Windows Kernel"
Статический анализ кода в контексте SSDL
CNIT 126: 10: Kernel Debugging with WinDbg
Secure360 - Attack All the Layers! Again!
Powering up on power shell avengercon - 2018
Ad

Similar to Common technique in Bypassing Stuff in Python. (20)

PDF
Bh Usa 07 Butler And Kendall
PPTX
Steelcon 2014 - Process Injection with Python
PPT
Backdoor coding
PDF
Fuzzing - Part 1
PDF
Higher Level Malware
PPTX
Tranning-2
PPTX
Offensive Python for Pentesting
PDF
Unix executable buffer overflow
PDF
How to write a well-behaved Python command line application
PDF
Buffer overflow tutorial
PDF
A Battle Against the Industry - Beating Antivirus for Meterpreter and More
PDF
CNIT 126 7: Analyzing Malicious Windows Programs
PPT
1. Von Neumann + Booting Sequence + System Calls.ppt
PDF
CNIT 126 Ch 7: Analyzing Malicious Windows Programs
PPT
Linux basics
PPT
02 fundamentals
PDF
جلسه اول پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲
PDF
A CTF Hackers Toolbox
PPT
Practical Malware Analysis: Ch 7: Analyzing Malicious Windows Programs
PDF
[若渴計畫] Challenges and Solutions of Window Remote Shellcode
Bh Usa 07 Butler And Kendall
Steelcon 2014 - Process Injection with Python
Backdoor coding
Fuzzing - Part 1
Higher Level Malware
Tranning-2
Offensive Python for Pentesting
Unix executable buffer overflow
How to write a well-behaved Python command line application
Buffer overflow tutorial
A Battle Against the Industry - Beating Antivirus for Meterpreter and More
CNIT 126 7: Analyzing Malicious Windows Programs
1. Von Neumann + Booting Sequence + System Calls.ppt
CNIT 126 Ch 7: Analyzing Malicious Windows Programs
Linux basics
02 fundamentals
جلسه اول پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲
A CTF Hackers Toolbox
Practical Malware Analysis: Ch 7: Analyzing Malicious Windows Programs
[若渴計畫] Challenges and Solutions of Window Remote Shellcode
Ad

Recently uploaded (20)

PDF
Empathic Computing: Creating Shared Understanding
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Encapsulation theory and applications.pdf
PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
NewMind AI Monthly Chronicles - July 2025
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PDF
cuic standard and advanced reporting.pdf
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PPTX
MYSQL Presentation for SQL database connectivity
Empathic Computing: Creating Shared Understanding
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Encapsulation theory and applications.pdf
Network Security Unit 5.pdf for BCA BBA.
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Building Integrated photovoltaic BIPV_UPV.pdf
NewMind AI Monthly Chronicles - July 2025
Reach Out and Touch Someone: Haptics and Empathic Computing
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Understanding_Digital_Forensics_Presentation.pptx
Spectral efficient network and resource selection model in 5G networks
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Advanced methodologies resolving dimensionality complications for autism neur...
CIFDAQ's Market Insight: SEC Turns Pro Crypto
cuic standard and advanced reporting.pdf
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
NewMind AI Weekly Chronicles - August'25 Week I
20250228 LYD VKU AI Blended-Learning.pptx
Chapter 3 Spatial Domain Image Processing.pdf
MYSQL Presentation for SQL database connectivity

Common technique in Bypassing Stuff in Python.

  • 1. Bypass AV in Python by y0nd13.
  • 2. Quick introduction to Python • By default exist in every major Linux Distribution • Can be install or run as portable tools in Windows :
  • 4. Hello World in Python Easy right!!
  • 5. So what’s the big deal? • Python support Foreign Function Instruction • It supports Ctypes. • http://docs.python.org/2/library/ctypes.html • It provides C compatible data types, and allows calling functions in DLLs or shared libraries. It can be used to wrap these libraries in pure Python • Smell profits!!! • Alternative ways besides using import system • Good for Post Exploitation • Bypass AV 
  • 7. A Simple MessageBoxA  • From MSDN • Required 4 argument,
  • 8. How to understand quickly  • HWND – A handle to the owner window of the message box to be created. If this parameter is NULL, the message box has no owner window. (SO we set to Null, in Python Null is None) • LPCTSR lpText - It’s a string for a Text • LPCTSR lpCaption – It’s a string for the MessageBox Title • UINT - Unsigned Integer . _in_opt_ is a SAL Annotation saying you can put NULL as a value
  • 9. SAL Annotation shortcut Parameters are required Parameters are optional Input to called function _In_ _In_opt_ Input to called function, and output to caller _Inout_ _Inout_opt_ Output to caller _Out_ _Out_opt_ Output of pointer to caller _Outptr_ _Outptr_opt_
  • 10. How easy to pop up a MessageBox in python? • Simple from ctypes import * ctypes.windll.user32.MessageBoxA(None,"Hello World","Title",None)
  • 11. How to about WinExec? • WinExec is a classical function since the age of Windows 16- bit . Only 2 Args are needed. • From MSDN • We know lpCmdLine is a string for the Exectuable path but what value should we place for uCmdShow?
  • 12. uCmdShow from MSDN • http://msdn.microsoft.com/en- us/library/windows/desktop/ms633548(v=vs.85).aspx
  • 13. To Spawn a calcfrom ctypes import * ctypes.windll.kernel32.WinExec(“C:Windowssystem32calc.exe”,1)
  • 15. How about Executing Shellcode? • Many ways – File Dropping Technique (BAD) – Code Injection Technique(BAD) – InMemory Technique (G000D) • File Dropping Technique are bad , since antivirus/malware will immedietely catch it up and trigeger • Code Injection , affects the integrity of a binary. HIPS might trigger alert. • Why Shellcode? Becoz we can!!
  • 16. InMemory Technique • We are going to chain 4 API to execute our shellcode . – >VirtualAlloc() – >WriteProcessMemory() – >CreateThread() – >WaitForSingleObject()
  • 17. VirtualAlloc() • lpAddress = Null • dwSize = length of shellcode can be use, • flAllocation = MEM_COMMIT|MEM_RESERVED (0x3000) • flProtect = PAGE_EXECUTE_READWRITE(0x40)
  • 18. WriteProcessMemory() • hProcess = -1 * we writing in the same process • lpBaseAddress = A Pointer to address return from VirtualALloc() • lpBuffer = A pointer to our buffer • nSize = we can use shellcode size and times 2 to be safe • lpNUmberofBytesWritten = Null it..
  • 19. CreateThread() • Everything is 0 except for (go figure it out yerself)
  • 21. P.O.C • Inspired by SK Training.. Use xcc !!!
  • 23. Executing native inside us heheheheh
  • 24. 2nd POC is our calc 
  • 26. (Optional) Freeze it to exe  • Using pyinstaller
  • 28. Exercise  • Create a Reverse Shell is a piece of cake!
  • 29. Reference • Understanding Win32Shellcode Skape: • http://www.hick.org/code/skape/papers/win32-shellcode.pdf • Advance Windows Shellcode, SK: • http://www.phrack.org/issues.html?id=7&issue=62 • http://msdn.microsoft.com/en-US/