SlideShare a Scribd company logo
The Python in the Apple
BSides Cleveland 2017
Spencer McIntyre
Agenda
• About Me
• Python ctypes Review
• Integration with Meterpreter (Railgun)
• Objective-C from Railgun
• Demonstration Time
About Me
• Spencer McIntyre
• Work at SecureState
• Research, Development, “Special” Projects
• BSOD-inducer
• Avid open source contributor
• Metasploit among others
• Python enthusiast
Railgun
Pew Pew Pew
Why do we care?
• One word: Stealth
• Everything here could be accomplished an “easier” way
• Writing files (often scripts) to disk
• Starting new processes
Meterpreter’s Railgun
• Standard API Extension of Metepreter
• Remote FFI (Foreign Function Interface)
• Only available for Windows (prior to
March 2017)
• Facilitates in-memory loading and calling
of native library code from the target
• Used by many Windows post and a few
local exploit modules
• You’ve probably used it without realizing it
Meterpreter’s Railgun
• Exposed through four basic Meterpreter API functions
• railgun_api
• Core functionality to load an arbitrary function, call it with defined parameters
and return results
• railgun_api_multi
• Execute multiple calls in a single transaction, offers better speed when used
• railgun_memread
• Read data out of the Meterpreter process, useful when pointers are returned
• railgun_memwrite
• Write data to in the Meterpreter process
Python Meterpreter
• First non-Windows implementation of Railgun
• Heavily utilizes ctypes to make all of the native API calls
• memread / memwrite were deceptively difficult
• Linux version backed with process_vm_(read|write)
• ctypes already supported function calls so wrapping that was relatively cross-
platform
• Error code retrieval is the primary difference
• Memory operations on the other hand…
OSX Memory Primitives
• Invalid access (read or write) results in
segmentation fault when not done safely
• Segmentation fault = session closed
• Enter the libc’s mach_vm_*
• Accessible via standard ctypes methods
• Graceful failure will help you have a good
time
• Error codes are returned for invalid
addresses and invalid permissions
OSX APIs From Railgun
Less Pew Pew more Segmentation fault
OSX APIs
• APIs are provided by frameworks
• /System/Library/Frameworks
• Mach-O universal binaries
• Major ones
• Foundation
• Accounts
• Social
• Security
• Loadable by Python’s ctypes
• Not particularly useful, the interfaces exposed are insufficient by themselves
libobjc
• Provides the runtime for Objective-C code
• This is accessible via C, ctypes will work as expected
• Allows initialization and usage of Objective-C classes
• Severe lack of documentation
• Apple doesn’t advertise this method
• Internet is full of reasons why it’s a Bad Idea™
• Repetitive API to use Objective-C objects this way
• objc_getClass objc_msgSend sel_registerName
Bad Idea™
Objective-C Object
• Basically chaining calls to objc_msgSend
• id objc_msgSend(id self, SEL op, …);
• Uses the standard CDECL calling convention
• Accepts a variable number of arguments (this is key)
• First parameter is the class instance, (or the class itself when you’re first
creating an instance)
• Second parameter is the “method selector”
• This is a string passed to sel_registerName
• Contains the method name and parameters by name
Objective-C Object
dlopen(‘Foundation.framework/Foundation’, RTLD_LAZY)
nsstring = objc_msgSend(
objc_msgSend(
objc_getClass(‘NSString’),
sel_registerName(‘alloc’)
),
sel_registerName(‘initWithCString:encoding:’),
‘Hello World’,
NSUTF8StringEncoding
)
Demonstration Time!
• Tying it all together to run an Apple Script in memory
• Uses NSAppleScript
Beware Faults
Code is Public
• https://github.com/zeroSteiner/metasploit-framework
• https://github.com/zeroSteiner/metasploit-payloads
• Both branches are pymet-rg-osx
Further Reading & Resources
• How Meterpreter’s Railgun works
• https://community.rapid7.com/community/metasploit/blog/2017/05/18/recen
t-python-meterpreter-improvements
• https://warroom.securestate.com/inner-workings-railgun/
• Spencer McIntyre
• Twitter: @zeroSteiner
Thank You For Your Time!

More Related Content

What's hot

Funambol C++ API
Funambol C++ APIFunambol C++ API
Funambol C++ APIFunambol
 
.Net programming with C#
.Net programming with C#.Net programming with C#
.Net programming with C#
NguynSang29
 
Functional Programming in PHP
Functional Programming in PHPFunctional Programming in PHP
Functional Programming in PHP
Aurimas Niekis
 
2014 01-21-mpi-community-feedback
2014 01-21-mpi-community-feedback2014 01-21-mpi-community-feedback
2014 01-21-mpi-community-feedback
Jeff Squyres
 
CPAN Curation
CPAN CurationCPAN Curation
CPAN Curation
neilbowers
 
Use notes objects in memory and other useful java tips for xpages development
Use notes objects in memory and other useful java tips for xpages developmentUse notes objects in memory and other useful java tips for xpages development
Use notes objects in memory and other useful java tips for xpages development
Frank van der Linden
 
Coding Standard And Code Review
Coding Standard And Code ReviewCoding Standard And Code Review
Coding Standard And Code Review
Milan Vukoje
 
CNIT 127 Ch 16: Fault Injection and 17: The Art of Fuzzing
CNIT 127 Ch 16: Fault Injection and 17: The Art of FuzzingCNIT 127 Ch 16: Fault Injection and 17: The Art of Fuzzing
CNIT 127 Ch 16: Fault Injection and 17: The Art of Fuzzing
Sam Bowne
 
LogiLogicless UI prototyping with Node.js | SuperSpeaker@CodeCamp Iasi, 2014
LogiLogicless UI prototyping with Node.js | SuperSpeaker@CodeCamp Iasi, 2014LogiLogicless UI prototyping with Node.js | SuperSpeaker@CodeCamp Iasi, 2014
LogiLogicless UI prototyping with Node.js | SuperSpeaker@CodeCamp Iasi, 2014
Endava
 
.NET and C# Introduction
.NET and C# Introduction.NET and C# Introduction
.NET and C# Introduction
Siraj Memon
 
Robotframework
RobotframeworkRobotframework
Robotframework
Ella Sun
 
A Modeling Editor and Code Generator for AsyncAPI
A Modeling Editor and Code Generator for AsyncAPIA Modeling Editor and Code Generator for AsyncAPI
A Modeling Editor and Code Generator for AsyncAPI
abgolla
 
Code Refactoring
Code RefactoringCode Refactoring
Code Refactoring
Milan Vukoje
 
TypeScript for Alfresco and CMIS - Alfresco DevCon 2012 San Jose
TypeScript for Alfresco and CMIS - Alfresco DevCon 2012 San JoseTypeScript for Alfresco and CMIS - Alfresco DevCon 2012 San Jose
TypeScript for Alfresco and CMIS - Alfresco DevCon 2012 San Jose
Steve Reiner
 
Python and web driver
Python and web driverPython and web driver
Python and web driver
Colm Harrington
 
Entity Framework Today (May 2012)
Entity Framework Today (May 2012)Entity Framework Today (May 2012)
Entity Framework Today (May 2012)
Julie Lerman
 
O365Con18 - Working with PowerShell, VS Code and GitHub - Thomas Vochten
O365Con18 - Working with PowerShell, VS Code and GitHub - Thomas VochtenO365Con18 - Working with PowerShell, VS Code and GitHub - Thomas Vochten
O365Con18 - Working with PowerShell, VS Code and GitHub - Thomas Vochten
NCCOMMS
 
Getting Started with ASP.NET Core 1.0 (formerly ASP.NET 5)
Getting Started with ASP.NET Core 1.0 (formerly ASP.NET 5)Getting Started with ASP.NET Core 1.0 (formerly ASP.NET 5)
Getting Started with ASP.NET Core 1.0 (formerly ASP.NET 5)
Arrow Consulting & Design
 
Stealing Chromium: Embedding HTML5 with the Servo Browser Engine (LinuxCon NA...
Stealing Chromium: Embedding HTML5 with the Servo Browser Engine (LinuxCon NA...Stealing Chromium: Embedding HTML5 with the Servo Browser Engine (LinuxCon NA...
Stealing Chromium: Embedding HTML5 with the Servo Browser Engine (LinuxCon NA...
Samsung Open Source Group
 
ASP.NET Core: The best of the new bits
ASP.NET Core: The best of the new bitsASP.NET Core: The best of the new bits
ASP.NET Core: The best of the new bits
Ken Cenerelli
 

What's hot (20)

Funambol C++ API
Funambol C++ APIFunambol C++ API
Funambol C++ API
 
.Net programming with C#
.Net programming with C#.Net programming with C#
.Net programming with C#
 
Functional Programming in PHP
Functional Programming in PHPFunctional Programming in PHP
Functional Programming in PHP
 
2014 01-21-mpi-community-feedback
2014 01-21-mpi-community-feedback2014 01-21-mpi-community-feedback
2014 01-21-mpi-community-feedback
 
CPAN Curation
CPAN CurationCPAN Curation
CPAN Curation
 
Use notes objects in memory and other useful java tips for xpages development
Use notes objects in memory and other useful java tips for xpages developmentUse notes objects in memory and other useful java tips for xpages development
Use notes objects in memory and other useful java tips for xpages development
 
Coding Standard And Code Review
Coding Standard And Code ReviewCoding Standard And Code Review
Coding Standard And Code Review
 
CNIT 127 Ch 16: Fault Injection and 17: The Art of Fuzzing
CNIT 127 Ch 16: Fault Injection and 17: The Art of FuzzingCNIT 127 Ch 16: Fault Injection and 17: The Art of Fuzzing
CNIT 127 Ch 16: Fault Injection and 17: The Art of Fuzzing
 
LogiLogicless UI prototyping with Node.js | SuperSpeaker@CodeCamp Iasi, 2014
LogiLogicless UI prototyping with Node.js | SuperSpeaker@CodeCamp Iasi, 2014LogiLogicless UI prototyping with Node.js | SuperSpeaker@CodeCamp Iasi, 2014
LogiLogicless UI prototyping with Node.js | SuperSpeaker@CodeCamp Iasi, 2014
 
.NET and C# Introduction
.NET and C# Introduction.NET and C# Introduction
.NET and C# Introduction
 
Robotframework
RobotframeworkRobotframework
Robotframework
 
A Modeling Editor and Code Generator for AsyncAPI
A Modeling Editor and Code Generator for AsyncAPIA Modeling Editor and Code Generator for AsyncAPI
A Modeling Editor and Code Generator for AsyncAPI
 
Code Refactoring
Code RefactoringCode Refactoring
Code Refactoring
 
TypeScript for Alfresco and CMIS - Alfresco DevCon 2012 San Jose
TypeScript for Alfresco and CMIS - Alfresco DevCon 2012 San JoseTypeScript for Alfresco and CMIS - Alfresco DevCon 2012 San Jose
TypeScript for Alfresco and CMIS - Alfresco DevCon 2012 San Jose
 
Python and web driver
Python and web driverPython and web driver
Python and web driver
 
Entity Framework Today (May 2012)
Entity Framework Today (May 2012)Entity Framework Today (May 2012)
Entity Framework Today (May 2012)
 
O365Con18 - Working with PowerShell, VS Code and GitHub - Thomas Vochten
O365Con18 - Working with PowerShell, VS Code and GitHub - Thomas VochtenO365Con18 - Working with PowerShell, VS Code and GitHub - Thomas Vochten
O365Con18 - Working with PowerShell, VS Code and GitHub - Thomas Vochten
 
Getting Started with ASP.NET Core 1.0 (formerly ASP.NET 5)
Getting Started with ASP.NET Core 1.0 (formerly ASP.NET 5)Getting Started with ASP.NET Core 1.0 (formerly ASP.NET 5)
Getting Started with ASP.NET Core 1.0 (formerly ASP.NET 5)
 
Stealing Chromium: Embedding HTML5 with the Servo Browser Engine (LinuxCon NA...
Stealing Chromium: Embedding HTML5 with the Servo Browser Engine (LinuxCon NA...Stealing Chromium: Embedding HTML5 with the Servo Browser Engine (LinuxCon NA...
Stealing Chromium: Embedding HTML5 with the Servo Browser Engine (LinuxCon NA...
 
ASP.NET Core: The best of the new bits
ASP.NET Core: The best of the new bitsASP.NET Core: The best of the new bits
ASP.NET Core: The best of the new bits
 

Similar to The Python in the Apple

MEAN Stack WeNode Barcelona Workshop
MEAN Stack WeNode Barcelona WorkshopMEAN Stack WeNode Barcelona Workshop
MEAN Stack WeNode Barcelona WorkshopValeri Karpov
 
Beyond Domino Designer
Beyond Domino DesignerBeyond Domino Designer
Beyond Domino Designer
Paul Withers
 
Tech IT Easy x DevTalk : "Secure Your Coding with OWASP"
Tech IT Easy x DevTalk : "Secure Your Coding with OWASP"Tech IT Easy x DevTalk : "Secure Your Coding with OWASP"
Tech IT Easy x DevTalk : "Secure Your Coding with OWASP"
Andi Rustandi Djunaedi
 
AWS Lambda Function with Kotlin
AWS Lambda Function with KotlinAWS Lambda Function with Kotlin
AWS Lambda Function with Kotlin
Troy Miles
 
Top 10 python ide
Top 10 python ideTop 10 python ide
Top 10 python ide
Saravanakumar viswanathan
 
Native App Development for iOS, Android, and Windows with Visual Studio
Native App Development for iOS, Android, and Windows with Visual StudioNative App Development for iOS, Android, and Windows with Visual Studio
Native App Development for iOS, Android, and Windows with Visual Studio
Xamarin
 
Игорь Фесенко "Direction of C# as a High-Performance Language"
Игорь Фесенко "Direction of C# as a High-Performance Language"Игорь Фесенко "Direction of C# as a High-Performance Language"
Игорь Фесенко "Direction of C# as a High-Performance Language"
Fwdays
 
Logic appsforbeginners
Logic appsforbeginnersLogic appsforbeginners
Logic appsforbeginners
Mandar Dharmadhikari
 
8. Software Development Security
8. Software Development Security8. Software Development Security
8. Software Development Security
Sam Bowne
 
From .NET Core 3, all the rest will be legacy
From .NET Core 3, all the rest will be legacyFrom .NET Core 3, all the rest will be legacy
From .NET Core 3, all the rest will be legacy
Rick van den Bosch
 
An Open Source Workbench for Prototyping Multimodal Interactions Based on Off...
An Open Source Workbench for Prototyping Multimodal Interactions Based on Off...An Open Source Workbench for Prototyping Multimodal Interactions Based on Off...
An Open Source Workbench for Prototyping Multimodal Interactions Based on Off...
Jean Vanderdonckt
 
Ember - introduction
Ember - introductionEmber - introduction
Ember - introduction
Harikrishnan C
 
Build software like a bag of marbles, not a castle of LEGO®
Build software like a bag of marbles, not a castle of LEGO®Build software like a bag of marbles, not a castle of LEGO®
Build software like a bag of marbles, not a castle of LEGO®
Hannes Lowette
 
Finding The Weak Link in Windows Binaries
Finding The Weak Link in Windows BinariesFinding The Weak Link in Windows Binaries
Finding The Weak Link in Windows Binaries
Ollie Whitehouse
 
Recon-Fu @BsidesKyiv 2016
Recon-Fu @BsidesKyiv 2016Recon-Fu @BsidesKyiv 2016
Recon-Fu @BsidesKyiv 2016
Vlad Styran
 
Live Content: Finding new ways to publish
Live Content: Finding new ways to publishLive Content: Finding new ways to publish
Live Content: Finding new ways to publishckimrie
 
APIs distribuidos con alta escalabilidad
APIs distribuidos con alta escalabilidadAPIs distribuidos con alta escalabilidad
APIs distribuidos con alta escalabilidad
Software Guru
 
Finding Needles in Haystacks
Finding Needles in HaystacksFinding Needles in Haystacks
Finding Needles in Haystacks
snyff
 
SOLID Programming with Portable Class Libraries
SOLID Programming with Portable Class LibrariesSOLID Programming with Portable Class Libraries
SOLID Programming with Portable Class Libraries
Vagif Abilov
 
Escaping the yellow bubble - rewriting Domino using MongoDb and Angular
Escaping the yellow bubble - rewriting Domino using MongoDb and AngularEscaping the yellow bubble - rewriting Domino using MongoDb and Angular
Escaping the yellow bubble - rewriting Domino using MongoDb and Angular
Mark Leusink
 

Similar to The Python in the Apple (20)

MEAN Stack WeNode Barcelona Workshop
MEAN Stack WeNode Barcelona WorkshopMEAN Stack WeNode Barcelona Workshop
MEAN Stack WeNode Barcelona Workshop
 
Beyond Domino Designer
Beyond Domino DesignerBeyond Domino Designer
Beyond Domino Designer
 
Tech IT Easy x DevTalk : "Secure Your Coding with OWASP"
Tech IT Easy x DevTalk : "Secure Your Coding with OWASP"Tech IT Easy x DevTalk : "Secure Your Coding with OWASP"
Tech IT Easy x DevTalk : "Secure Your Coding with OWASP"
 
AWS Lambda Function with Kotlin
AWS Lambda Function with KotlinAWS Lambda Function with Kotlin
AWS Lambda Function with Kotlin
 
Top 10 python ide
Top 10 python ideTop 10 python ide
Top 10 python ide
 
Native App Development for iOS, Android, and Windows with Visual Studio
Native App Development for iOS, Android, and Windows with Visual StudioNative App Development for iOS, Android, and Windows with Visual Studio
Native App Development for iOS, Android, and Windows with Visual Studio
 
Игорь Фесенко "Direction of C# as a High-Performance Language"
Игорь Фесенко "Direction of C# as a High-Performance Language"Игорь Фесенко "Direction of C# as a High-Performance Language"
Игорь Фесенко "Direction of C# as a High-Performance Language"
 
Logic appsforbeginners
Logic appsforbeginnersLogic appsforbeginners
Logic appsforbeginners
 
8. Software Development Security
8. Software Development Security8. Software Development Security
8. Software Development Security
 
From .NET Core 3, all the rest will be legacy
From .NET Core 3, all the rest will be legacyFrom .NET Core 3, all the rest will be legacy
From .NET Core 3, all the rest will be legacy
 
An Open Source Workbench for Prototyping Multimodal Interactions Based on Off...
An Open Source Workbench for Prototyping Multimodal Interactions Based on Off...An Open Source Workbench for Prototyping Multimodal Interactions Based on Off...
An Open Source Workbench for Prototyping Multimodal Interactions Based on Off...
 
Ember - introduction
Ember - introductionEmber - introduction
Ember - introduction
 
Build software like a bag of marbles, not a castle of LEGO®
Build software like a bag of marbles, not a castle of LEGO®Build software like a bag of marbles, not a castle of LEGO®
Build software like a bag of marbles, not a castle of LEGO®
 
Finding The Weak Link in Windows Binaries
Finding The Weak Link in Windows BinariesFinding The Weak Link in Windows Binaries
Finding The Weak Link in Windows Binaries
 
Recon-Fu @BsidesKyiv 2016
Recon-Fu @BsidesKyiv 2016Recon-Fu @BsidesKyiv 2016
Recon-Fu @BsidesKyiv 2016
 
Live Content: Finding new ways to publish
Live Content: Finding new ways to publishLive Content: Finding new ways to publish
Live Content: Finding new ways to publish
 
APIs distribuidos con alta escalabilidad
APIs distribuidos con alta escalabilidadAPIs distribuidos con alta escalabilidad
APIs distribuidos con alta escalabilidad
 
Finding Needles in Haystacks
Finding Needles in HaystacksFinding Needles in Haystacks
Finding Needles in Haystacks
 
SOLID Programming with Portable Class Libraries
SOLID Programming with Portable Class LibrariesSOLID Programming with Portable Class Libraries
SOLID Programming with Portable Class Libraries
 
Escaping the yellow bubble - rewriting Domino using MongoDb and Angular
Escaping the yellow bubble - rewriting Domino using MongoDb and AngularEscaping the yellow bubble - rewriting Domino using MongoDb and Angular
Escaping the yellow bubble - rewriting Domino using MongoDb and Angular
 

Recently uploaded

Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
Dorra BARTAGUIZ
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
Product School
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
Elena Simperl
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 
Generating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using SmithyGenerating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using Smithy
g2nightmarescribd
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Albert Hoitingh
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
Cheryl Hung
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
DianaGray10
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
Frank van Harmelen
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Product School
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
Product School
 

Recently uploaded (20)

Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
Generating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using SmithyGenerating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using Smithy
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
 

The Python in the Apple

  • 1. The Python in the Apple BSides Cleveland 2017 Spencer McIntyre
  • 2. Agenda • About Me • Python ctypes Review • Integration with Meterpreter (Railgun) • Objective-C from Railgun • Demonstration Time
  • 3. About Me • Spencer McIntyre • Work at SecureState • Research, Development, “Special” Projects • BSOD-inducer • Avid open source contributor • Metasploit among others • Python enthusiast
  • 5. Why do we care? • One word: Stealth • Everything here could be accomplished an “easier” way • Writing files (often scripts) to disk • Starting new processes
  • 6. Meterpreter’s Railgun • Standard API Extension of Metepreter • Remote FFI (Foreign Function Interface) • Only available for Windows (prior to March 2017) • Facilitates in-memory loading and calling of native library code from the target • Used by many Windows post and a few local exploit modules • You’ve probably used it without realizing it
  • 7. Meterpreter’s Railgun • Exposed through four basic Meterpreter API functions • railgun_api • Core functionality to load an arbitrary function, call it with defined parameters and return results • railgun_api_multi • Execute multiple calls in a single transaction, offers better speed when used • railgun_memread • Read data out of the Meterpreter process, useful when pointers are returned • railgun_memwrite • Write data to in the Meterpreter process
  • 8. Python Meterpreter • First non-Windows implementation of Railgun • Heavily utilizes ctypes to make all of the native API calls • memread / memwrite were deceptively difficult • Linux version backed with process_vm_(read|write) • ctypes already supported function calls so wrapping that was relatively cross- platform • Error code retrieval is the primary difference • Memory operations on the other hand…
  • 9. OSX Memory Primitives • Invalid access (read or write) results in segmentation fault when not done safely • Segmentation fault = session closed • Enter the libc’s mach_vm_* • Accessible via standard ctypes methods • Graceful failure will help you have a good time • Error codes are returned for invalid addresses and invalid permissions
  • 10. OSX APIs From Railgun Less Pew Pew more Segmentation fault
  • 11. OSX APIs • APIs are provided by frameworks • /System/Library/Frameworks • Mach-O universal binaries • Major ones • Foundation • Accounts • Social • Security • Loadable by Python’s ctypes • Not particularly useful, the interfaces exposed are insufficient by themselves
  • 12. libobjc • Provides the runtime for Objective-C code • This is accessible via C, ctypes will work as expected • Allows initialization and usage of Objective-C classes • Severe lack of documentation • Apple doesn’t advertise this method • Internet is full of reasons why it’s a Bad Idea™ • Repetitive API to use Objective-C objects this way • objc_getClass objc_msgSend sel_registerName
  • 14. Objective-C Object • Basically chaining calls to objc_msgSend • id objc_msgSend(id self, SEL op, …); • Uses the standard CDECL calling convention • Accepts a variable number of arguments (this is key) • First parameter is the class instance, (or the class itself when you’re first creating an instance) • Second parameter is the “method selector” • This is a string passed to sel_registerName • Contains the method name and parameters by name
  • 15. Objective-C Object dlopen(‘Foundation.framework/Foundation’, RTLD_LAZY) nsstring = objc_msgSend( objc_msgSend( objc_getClass(‘NSString’), sel_registerName(‘alloc’) ), sel_registerName(‘initWithCString:encoding:’), ‘Hello World’, NSUTF8StringEncoding )
  • 16. Demonstration Time! • Tying it all together to run an Apple Script in memory • Uses NSAppleScript
  • 18. Code is Public • https://github.com/zeroSteiner/metasploit-framework • https://github.com/zeroSteiner/metasploit-payloads • Both branches are pymet-rg-osx
  • 19. Further Reading & Resources • How Meterpreter’s Railgun works • https://community.rapid7.com/community/metasploit/blog/2017/05/18/recen t-python-meterpreter-improvements • https://warroom.securestate.com/inner-workings-railgun/
  • 20. • Spencer McIntyre • Twitter: @zeroSteiner Thank You For Your Time!