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

What's hot (20)

PDF
Attack All the Layers: What's Working during Pentests (OWASP NYC)
Scott Sutherland
 
PDF
Nikto
Sorina Chirilă
 
PPTX
Vulnerability desing patterns
Peter Hlavaty
 
PPTX
Get-Help: An intro to PowerShell and how to Use it for Evil
jaredhaight
 
PPTX
FreeIPA - Attacking the Active Directory of Linux
Julian Catrambone
 
PPTX
Defcon - Veil-Pillage
VeilFramework
 
PDF
Derbycon - The Unintended Risks of Trusting Active Directory
Will Schroeder
 
PPTX
Vulnerabilities on Various Data Processing Levels
Positive Hack Days
 
PPTX
Introducing PS>Attack: An offensive PowerShell toolkit
jaredhaight
 
PPTX
Guardians of your CODE
Peter Hlavaty
 
PDF
TriplePlay-WebAppPenTestingTools
Yury Chemerkin
 
PPTX
G rpc lection1
eleksdev
 
PDF
Practical Malware Analysis Ch12
Sam Bowne
 
PPTX
SSL Checklist for Pentesters (BSides MCR 2014)
Jerome Smith
 
PPTX
Owning computers without shell access dark
Royce Davis
 
PPTX
You didnt see it’s coming? "Dawn of hardened Windows Kernel"
Peter Hlavaty
 
PDF
Статический анализ кода в контексте SSDL
Positive Hack Days
 
PDF
CNIT 126: 10: Kernel Debugging with WinDbg
Sam Bowne
 
PPTX
Secure360 - Attack All the Layers! Again!
Scott Sutherland
 
PPTX
Powering up on power shell avengercon - 2018
Fernando Tomlinson, CISSP, MBA
 
Attack All the Layers: What's Working during Pentests (OWASP NYC)
Scott Sutherland
 
Vulnerability desing patterns
Peter Hlavaty
 
Get-Help: An intro to PowerShell and how to Use it for Evil
jaredhaight
 
FreeIPA - Attacking the Active Directory of Linux
Julian Catrambone
 
Defcon - Veil-Pillage
VeilFramework
 
Derbycon - The Unintended Risks of Trusting Active Directory
Will Schroeder
 
Vulnerabilities on Various Data Processing Levels
Positive Hack Days
 
Introducing PS>Attack: An offensive PowerShell toolkit
jaredhaight
 
Guardians of your CODE
Peter Hlavaty
 
TriplePlay-WebAppPenTestingTools
Yury Chemerkin
 
G rpc lection1
eleksdev
 
Practical Malware Analysis Ch12
Sam Bowne
 
SSL Checklist for Pentesters (BSides MCR 2014)
Jerome Smith
 
Owning computers without shell access dark
Royce Davis
 
You didnt see it’s coming? "Dawn of hardened Windows Kernel"
Peter Hlavaty
 
Статический анализ кода в контексте SSDL
Positive Hack Days
 
CNIT 126: 10: Kernel Debugging with WinDbg
Sam Bowne
 
Secure360 - Attack All the Layers! Again!
Scott Sutherland
 
Powering up on power shell avengercon - 2018
Fernando Tomlinson, CISSP, MBA
 

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

PDF
Bh Usa 07 Butler And Kendall
KarlFrank99
 
PPTX
Steelcon 2014 - Process Injection with Python
infodox
 
PPT
Backdoor coding
abdesslem amri
 
PDF
Fuzzing - Part 1
UTD Computer Security Group
 
PDF
Higher Level Malware
CTruncer
 
PPTX
Tranning-2
Ali Hussain
 
PPTX
Offensive Python for Pentesting
Mike Felch
 
PDF
Unix executable buffer overflow
Ammarit Thongthua ,CISSP CISM GXPN CSSLP CCNP
 
PDF
How to write a well-behaved Python command line application
gjcross
 
PDF
Buffer overflow tutorial
hughpearse
 
PDF
A Battle Against the Industry - Beating Antivirus for Meterpreter and More
CTruncer
 
PDF
CNIT 126 7: Analyzing Malicious Windows Programs
Sam Bowne
 
PPT
1. Von Neumann + Booting Sequence + System Calls.ppt
muhammadtaharazzaq
 
PDF
CNIT 126 Ch 7: Analyzing Malicious Windows Programs
Sam Bowne
 
PPT
Linux basics
sirmanohar
 
PPT
02 fundamentals
sirmanohar
 
PDF
جلسه اول پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲
Mohammad Reza Kamalifard
 
PDF
A CTF Hackers Toolbox
Stefan
 
PPT
Practical Malware Analysis: Ch 7: Analyzing Malicious Windows Programs
Sam Bowne
 
PDF
[若渴計畫] Challenges and Solutions of Window Remote Shellcode
Aj MaChInE
 
Bh Usa 07 Butler And Kendall
KarlFrank99
 
Steelcon 2014 - Process Injection with Python
infodox
 
Backdoor coding
abdesslem amri
 
Fuzzing - Part 1
UTD Computer Security Group
 
Higher Level Malware
CTruncer
 
Tranning-2
Ali Hussain
 
Offensive Python for Pentesting
Mike Felch
 
Unix executable buffer overflow
Ammarit Thongthua ,CISSP CISM GXPN CSSLP CCNP
 
How to write a well-behaved Python command line application
gjcross
 
Buffer overflow tutorial
hughpearse
 
A Battle Against the Industry - Beating Antivirus for Meterpreter and More
CTruncer
 
CNIT 126 7: Analyzing Malicious Windows Programs
Sam Bowne
 
1. Von Neumann + Booting Sequence + System Calls.ppt
muhammadtaharazzaq
 
CNIT 126 Ch 7: Analyzing Malicious Windows Programs
Sam Bowne
 
Linux basics
sirmanohar
 
02 fundamentals
sirmanohar
 
جلسه اول پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲
Mohammad Reza Kamalifard
 
A CTF Hackers Toolbox
Stefan
 
Practical Malware Analysis: Ch 7: Analyzing Malicious Windows Programs
Sam Bowne
 
[若渴計畫] Challenges and Solutions of Window Remote Shellcode
Aj MaChInE
 
Ad

Recently uploaded (20)

PPSX
Usergroup - OutSystems Architecture.ppsx
Kurt Vandevelde
 
PDF
GDG Cloud Southlake #44: Eyal Bukchin: Tightening the Kubernetes Feedback Loo...
James Anderson
 
PPTX
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
PDF
Understanding AI Optimization AIO, LLMO, and GEO
CoDigital
 
PPTX
Reimaginando la Ciberdefensa: De Copilots a Redes de Agentes
Cristian Garcia G.
 
PDF
TrustArc Webinar - Navigating APAC Data Privacy Laws: Compliance & Challenges
TrustArc
 
PDF
Proactive Server and System Monitoring with FME: Using HTTP and System Caller...
Safe Software
 
PDF
Hyderabad MuleSoft In-Person Meetup (June 21, 2025) Slides
Ravi Tamada
 
PDF
LLM Search Readiness Audit - Dentsu x SEO Square - June 2025.pdf
Nick Samuel
 
PDF
Optimizing the trajectory of a wheel loader working in short loading cycles
Reno Filla
 
PPTX
MARTSIA: A Tool for Confidential Data Exchange via Public Blockchain - Poster...
Michele Kryston
 
PDF
Plugging AI into everything: Model Context Protocol Simplified.pdf
Abati Adewale
 
PDF
How to Comply With Saudi Arabia’s National Cybersecurity Regulations.pdf
Bluechip Advanced Technologies
 
PDF
DoS Attack vs DDoS Attack_ The Silent Wars of the Internet.pdf
CyberPro Magazine
 
PDF
“Scaling i.MX Applications Processors’ Native Edge AI with Discrete AI Accele...
Edge AI and Vision Alliance
 
PDF
FME as an Orchestration Tool with Principles From Data Gravity
Safe Software
 
PDF
Pipeline Industry IoT - Real Time Data Monitoring
Safe Software
 
PDF
Quantum AI Discoveries: Fractal Patterns Consciousness and Cyclical Universes
Saikat Basu
 
PPTX
Smarter Governance with AI: What Every Board Needs to Know
OnBoard
 
PPTX
Mastering Authorization: Integrating Authentication and Authorization Data in...
Hitachi, Ltd. OSS Solution Center.
 
Usergroup - OutSystems Architecture.ppsx
Kurt Vandevelde
 
GDG Cloud Southlake #44: Eyal Bukchin: Tightening the Kubernetes Feedback Loo...
James Anderson
 
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
Understanding AI Optimization AIO, LLMO, and GEO
CoDigital
 
Reimaginando la Ciberdefensa: De Copilots a Redes de Agentes
Cristian Garcia G.
 
TrustArc Webinar - Navigating APAC Data Privacy Laws: Compliance & Challenges
TrustArc
 
Proactive Server and System Monitoring with FME: Using HTTP and System Caller...
Safe Software
 
Hyderabad MuleSoft In-Person Meetup (June 21, 2025) Slides
Ravi Tamada
 
LLM Search Readiness Audit - Dentsu x SEO Square - June 2025.pdf
Nick Samuel
 
Optimizing the trajectory of a wheel loader working in short loading cycles
Reno Filla
 
MARTSIA: A Tool for Confidential Data Exchange via Public Blockchain - Poster...
Michele Kryston
 
Plugging AI into everything: Model Context Protocol Simplified.pdf
Abati Adewale
 
How to Comply With Saudi Arabia’s National Cybersecurity Regulations.pdf
Bluechip Advanced Technologies
 
DoS Attack vs DDoS Attack_ The Silent Wars of the Internet.pdf
CyberPro Magazine
 
“Scaling i.MX Applications Processors’ Native Edge AI with Discrete AI Accele...
Edge AI and Vision Alliance
 
FME as an Orchestration Tool with Principles From Data Gravity
Safe Software
 
Pipeline Industry IoT - Real Time Data Monitoring
Safe Software
 
Quantum AI Discoveries: Fractal Patterns Consciousness and Cyclical Universes
Saikat Basu
 
Smarter Governance with AI: What Every Board Needs to Know
OnBoard
 
Mastering Authorization: Integrating Authentication and Authorization Data in...
Hitachi, Ltd. OSS Solution Center.
 
Ad

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/