SlideShare a Scribd company logo
Weaponizing the Windows API with Metasploit's Railgun
Weaponizing the Windows API with Metasploit's Railgun
Weaponizing the Windows API with Metasploit's Railgun
“If you don’t think you’re a
newb, then you’re not trying
hard enough”
-   HD Moore
Post-exploitation
Endless Possabilities
Weaponizing the Windows API with Metasploit's Railgun
 Goto Payload for Windows
 DLL, compiled C
 Usually injected into process
  memory
 Enhanced CMD shell
 Provides basic post-exploitation
  API
 Often run with SYSTEM Privs
 Can be migrated into a user’s
 process
Weaponizing the Windows API with Metasploit's Railgun
 Railgun is an extension to
  the Meterpreter STDAPI
 Allows Arbitrary Loading
  of DLLs
 As long as you know the
  path of the DLL, you can
  access it’s functions
 Since Windows API DLLs
  are always at known
  paths, we can always
  load them
 Dynamic access to the
  entirety of the Windows
  API on the system
 By calling APIs from user
  processes, we can
  impersonate users
 Anything becomes
  possible
Weaponizing the Windows API with Metasploit's Railgun
 June 2010 – Railgun submitted
  to Metasploit by Patrick HVE
 Sept 2010 – 64bit support
  added by Stephen Fewer
 Feb 2011 – Chao-mu takes
  over Railgun support, resumes
  new feature work
 Fall 2011 – Chao-mu
  disappears
 Aug 2012 – YOU start
  contributing to Railgun
 Dec 2012 – Mayans predict
  Railgun-related Apocalypse?
 LoadLibrary function opens a
 Handle to the DLL
 GetProcAddress maps a
 function pointer to the
 specified function
 Memread and Memwrite
 functions for manipulating
 memory space
 Ruby code lives in
  lib/rex/post/meterpreter/extensio
  ns/stdapi/railgun
 User/module writer defines the
  DLL and the needed functions
 Functions are then avilable as
  methods
 Can define at runtime or use
  definition files
def self.create_dll(dll_path = 'advapi32')
 dll = DLL.new(dll_path, ApiConstants.manager)



 dll.add_function('CredEnumerateA', 'BOOL', [
  ['PCHAR', 'Filter', 'in'],
  ['DWORD', 'Flags', 'in'],
  ['PDWORD', 'Count', 'out'],
  ['PBLOB', 'Credentials', 'out']])




    A look at Railgun
     Definitions
1. Function Name
2. Function Return Type
3. Array of Parameters
 1. Param type
 2. Param Name
 3. IN/OUT/INOUT Parameter
 Railgun knows about
  Windows constants
 They are defined in
  api_constants.rb in the
  railgun folder
 Easy to add new constants
  as needed there
Weaponizing the Windows API with Metasploit's Railgun
 If it quacks like a duck…
 Pass as a Fixnum or
  Bignum
 String representation of
  constants can also be
  passed in
 Pointer to a DWORD
 Pass a Fixnum
 Pass the Content of the
  DWORD not the pointer
 If it is an OUT only
  paramter, pass a 4 (size
  of a DWORD)
 Pass nil for a NULL
  Pointer
 Pass as Ruby strings.
  Will be converted
  seamlessly
 If OUT only, pass fixnum
  of the size of the buffer
  (including null byte)
Definition                              Usage
dll.add_function(                       ms_enhanced_prov = "Microsoft
                                           Enhanced Cryptographic
    'CryptAcquireContextW',                Provider v1.0"
    'BOOL',[                            prov_rsa_full = 1
['PDWORD', 'phProv', 'out'],            crypt_verify_context =
                                           0xF0000000
['PWCHAR', 'pszContainer',
                                        alg_md5 = 32771
   'in'],
                                        alg_rc4 = 26625
['PWCHAR', 'pszProvider', 'in'],        advapi32 = client.railgun.advapi32
['DWORD', 'dwProvType', 'in'],          acquirecontext =
                                           advapi32.CryptAcquireContext
['DWORD', 'dwflags', 'in']])               W(4, nil, ms_enhanced_prov,
                                           prov_rsa_full,
                                           crypt_verify_context)



Used in the SmartFTP password Recovery Module
 Pass in Ruby True/False
  values exactly as expected
Definition:
dll.add_function( 'IsDebuggerPresent', 'BOOL',[])


Usage:
>> client.railgun.kernel32.IsDebuggerPresent()
=> {"GetLastError"=>0, "return"=>false}
 Handled the same as
  DWORDs but Fixnums
  passed in will be
  truncated to the
  appropriate length
 Anything that’s not a
  string or a DWORD
 Treated as a ruby string
 Railgun will not help you
  parse structures
Definition                             Usage
dll.add_function( 'WlanGetProfile',    profile['name'] =
    'DWORD',[                             @host_process.memory.rea
['DWORD', 'hClientHandle', 'in'],         d(ppointer,512)
['PBLOB', 'pInterfaceGuid', 'in'],     ppointer = (ppointer + 516)
['PBLOB', 'strProfileName', 'in'],
['LPVOID', 'pReserved', 'in'],
['PDWORD', 'pstrProfileXML',           rprofile =
   'out'],                                @wlanapi.WlanGetProfile(wl
['PDWORD', 'pdwFlags', 'inout'],
                                          an_handle,guid,profile['nam
                                          e'],nil,4,4,4)
['PDWORD', 'pdwGrantedAccess',
   'out']])



Used in the wlan_profile post module
 Pointers and Handles of
  any kind are really just
  numbers, so treat them
  as DWORDs
 If it can be treated as a
  number it’s a DWORD
 Otherwise it’s a PBLOB
 If neither works, add
  support for it yourself =)
 The function will return a
  hash
 Hash will always contain at
  least GetLastError
 Hash will return any OUT
  values
 Will return 0 if there was no
  error
 Otherwise will contain the
  windows system Error code
  encountered
 Errors codes can be looked
  up at
  http://msdn.microsoft.com/en
  -
  us/library/windows/desktop/
  ms681381(v=vs.85).aspx
acquirecontext =
  advapi32.CryptAcquireCon
  textW(4, nil,
  ms_enhanced_prov,
  prov_rsa_full,
  crypt_verify_context)


createhash =
  advapi32.CryptCreateHash
  (acquirecontext['phProv']
  , alg_md5, 0, 0, 4)
 Complex structure types that
  you will have to parse
  yourself
 Strings you don’t know the
  length of
 Large number of string reads
  (SLOWWWW)
Weaponizing the Windows API with Metasploit's Railgun
Microsoft will help
 you own things
Seriously…
They even give you
      tools!
Weaponizing the Windows API with Metasploit's Railgun
 Anything you can do with the
  windows API is available
 Without increasing the size of
  the payload
 Get the OS to Decrypt
  stored SmartFTP Passwords
 Enumerate and decrypt
  stored RDP passwords
 Scan for Wireless APs
 Enumerates Domain
  controllers on the victim’s
  network
 Enough of these ugly slides
 Let’s see it in action

More Related Content

PDF
Functional Programming with Groovy
PPT
bluespec talk
PDF
Querydsl overview 2014
PDF
The art of readable code (ch1~ch4)
PDF
What do you mean, Backwards Compatibility?
PDF
The Art Of Readable Code
PDF
Querydsl fin jug - june 2012
PPSX
Spring has got me under it’s SpEL
Functional Programming with Groovy
bluespec talk
Querydsl overview 2014
The art of readable code (ch1~ch4)
What do you mean, Backwards Compatibility?
The Art Of Readable Code
Querydsl fin jug - june 2012
Spring has got me under it’s SpEL

What's hot (20)

PDF
Groovy.pptx
PDF
Cassandra summit 2013 - DataStax Java Driver Unleashed!
PDF
ChtiJUG - Cassandra 2.0
PPTX
concurrency gpars
PDF
[grcpp] Refactoring for testability c++
PDF
Fun Teaching MongoDB New Tricks
PDF
Silicon Valley JUG: JVM Mechanics
PDF
Designing with Groovy Traits - Gr8Conf India
PDF
Ice mini guide
PPTX
Hack ASP.NET website
PDF
T3chFest2016 - Uso del API JavaScript de Photoshop para obtener fotos HDTR
PDF
Semantic code transformations in MetaJS
PDF
groovy rules
PDF
CIS14: Developing with OAuth and OIDC Connect
PPTX
Oleksandr Valetskyy - DI vs. IoC
PPTX
Jafka guide
PDF
MySQL Proxy tutorial
PDF
Geneva JUG - Cassandra for Java Developers
PPTX
Zero-Overhead Metaprogramming: Reflection and Metaobject Protocols Fast and w...
Groovy.pptx
Cassandra summit 2013 - DataStax Java Driver Unleashed!
ChtiJUG - Cassandra 2.0
concurrency gpars
[grcpp] Refactoring for testability c++
Fun Teaching MongoDB New Tricks
Silicon Valley JUG: JVM Mechanics
Designing with Groovy Traits - Gr8Conf India
Ice mini guide
Hack ASP.NET website
T3chFest2016 - Uso del API JavaScript de Photoshop para obtener fotos HDTR
Semantic code transformations in MetaJS
groovy rules
CIS14: Developing with OAuth and OIDC Connect
Oleksandr Valetskyy - DI vs. IoC
Jafka guide
MySQL Proxy tutorial
Geneva JUG - Cassandra for Java Developers
Zero-Overhead Metaprogramming: Reflection and Metaobject Protocols Fast and w...
Ad

Viewers also liked (6)

PPTX
Electromagnetic railgun (emrg)
PPTX
Railgun
PPT
Railgun akr
DOCX
Electromagnetic Railgun Internship Abstract
PPTX
PPTX
Railguns
Electromagnetic railgun (emrg)
Railgun
Railgun akr
Electromagnetic Railgun Internship Abstract
Railguns
Ad

Similar to Weaponizing the Windows API with Metasploit's Railgun (20)

PDF
A CTF Hackers Toolbox
PDF
Marat-Slides
PPTX
A New Framework for Detection
PPTX
Ropython-windbg-python-extensions
PPTX
Using Static Binary Analysis To Find Vulnerabilities And Backdoors in Firmware
PDF
0 to 31337 Real Quick: Lessons Learned by Reversing the Flare-On Challenge
PDF
My old security advisories on HMI/SCADA and industrial software released betw...
PDF
Sourcefire Vulnerability Research Team Labs
PPTX
Metasploit Railguns presentation @ tcs hyderabad
PDF
BERserk: New RSA Signature Forgery Attack
PDF
Fuzzing - Part 2
PDF
DEF CON 23 - COLIN O'FLYNN - dont whisper my chips
PDF
Penetration Testing for Easy RM to MP3 Converter Application and Post Exploit
PDF
Rainbow Over the Windows: More Colors Than You Could Expect
PPTX
NTUSTxTDOH 資訊安全基礎工作坊 基礎逆向教育訓練
PDF
Tilting at Windmills with ctypes and cygwinreg
PDF
Efficient Bytecode Analysis: Linespeed Shellcode Detection
PPTX
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
PDF
What the Fax!?
A CTF Hackers Toolbox
Marat-Slides
A New Framework for Detection
Ropython-windbg-python-extensions
Using Static Binary Analysis To Find Vulnerabilities And Backdoors in Firmware
0 to 31337 Real Quick: Lessons Learned by Reversing the Flare-On Challenge
My old security advisories on HMI/SCADA and industrial software released betw...
Sourcefire Vulnerability Research Team Labs
Metasploit Railguns presentation @ tcs hyderabad
BERserk: New RSA Signature Forgery Attack
Fuzzing - Part 2
DEF CON 23 - COLIN O'FLYNN - dont whisper my chips
Penetration Testing for Easy RM to MP3 Converter Application and Post Exploit
Rainbow Over the Windows: More Colors Than You Could Expect
NTUSTxTDOH 資訊安全基礎工作坊 基礎逆向教育訓練
Tilting at Windmills with ctypes and cygwinreg
Efficient Bytecode Analysis: Linespeed Shellcode Detection
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
What the Fax!?

Recently uploaded (20)

PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
NewMind AI Weekly Chronicles - August'25-Week II
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
Unlocking AI with Model Context Protocol (MCP)
PPT
Teaching material agriculture food technology
PPTX
sap open course for s4hana steps from ECC to s4
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Review of recent advances in non-invasive hemoglobin estimation
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PPTX
MYSQL Presentation for SQL database connectivity
PDF
cuic standard and advanced reporting.pdf
PDF
A comparative analysis of optical character recognition models for extracting...
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Approach and Philosophy of On baking technology
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
NewMind AI Weekly Chronicles - August'25-Week II
Mobile App Security Testing_ A Comprehensive Guide.pdf
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Unlocking AI with Model Context Protocol (MCP)
Teaching material agriculture food technology
sap open course for s4hana steps from ECC to s4
Per capita expenditure prediction using model stacking based on satellite ima...
Review of recent advances in non-invasive hemoglobin estimation
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
MYSQL Presentation for SQL database connectivity
cuic standard and advanced reporting.pdf
A comparative analysis of optical character recognition models for extracting...
Advanced methodologies resolving dimensionality complications for autism neur...
gpt5_lecture_notes_comprehensive_20250812015547.pdf
Assigned Numbers - 2025 - Bluetooth® Document
Digital-Transformation-Roadmap-for-Companies.pptx
Approach and Philosophy of On baking technology
Reach Out and Touch Someone: Haptics and Empathic Computing

Weaponizing the Windows API with Metasploit's Railgun

  • 4. “If you don’t think you’re a newb, then you’re not trying hard enough” - HD Moore
  • 8.  Goto Payload for Windows  DLL, compiled C  Usually injected into process memory  Enhanced CMD shell  Provides basic post-exploitation API
  • 9.  Often run with SYSTEM Privs  Can be migrated into a user’s process
  • 11.  Railgun is an extension to the Meterpreter STDAPI  Allows Arbitrary Loading of DLLs  As long as you know the path of the DLL, you can access it’s functions
  • 12.  Since Windows API DLLs are always at known paths, we can always load them
  • 13.  Dynamic access to the entirety of the Windows API on the system  By calling APIs from user processes, we can impersonate users  Anything becomes possible
  • 15.  June 2010 – Railgun submitted to Metasploit by Patrick HVE  Sept 2010 – 64bit support added by Stephen Fewer  Feb 2011 – Chao-mu takes over Railgun support, resumes new feature work  Fall 2011 – Chao-mu disappears  Aug 2012 – YOU start contributing to Railgun  Dec 2012 – Mayans predict Railgun-related Apocalypse?
  • 16.  LoadLibrary function opens a Handle to the DLL  GetProcAddress maps a function pointer to the specified function  Memread and Memwrite functions for manipulating memory space
  • 17.  Ruby code lives in lib/rex/post/meterpreter/extensio ns/stdapi/railgun  User/module writer defines the DLL and the needed functions  Functions are then avilable as methods  Can define at runtime or use definition files
  • 18. def self.create_dll(dll_path = 'advapi32') dll = DLL.new(dll_path, ApiConstants.manager) dll.add_function('CredEnumerateA', 'BOOL', [ ['PCHAR', 'Filter', 'in'], ['DWORD', 'Flags', 'in'], ['PDWORD', 'Count', 'out'], ['PBLOB', 'Credentials', 'out']])  A look at Railgun Definitions
  • 19. 1. Function Name 2. Function Return Type 3. Array of Parameters 1. Param type 2. Param Name 3. IN/OUT/INOUT Parameter
  • 20.  Railgun knows about Windows constants  They are defined in api_constants.rb in the railgun folder  Easy to add new constants as needed there
  • 22.  If it quacks like a duck…  Pass as a Fixnum or Bignum  String representation of constants can also be passed in
  • 23.  Pointer to a DWORD  Pass a Fixnum  Pass the Content of the DWORD not the pointer  If it is an OUT only paramter, pass a 4 (size of a DWORD)  Pass nil for a NULL Pointer
  • 24.  Pass as Ruby strings. Will be converted seamlessly  If OUT only, pass fixnum of the size of the buffer (including null byte)
  • 25. Definition Usage dll.add_function( ms_enhanced_prov = "Microsoft Enhanced Cryptographic 'CryptAcquireContextW', Provider v1.0" 'BOOL',[ prov_rsa_full = 1 ['PDWORD', 'phProv', 'out'], crypt_verify_context = 0xF0000000 ['PWCHAR', 'pszContainer', alg_md5 = 32771 'in'], alg_rc4 = 26625 ['PWCHAR', 'pszProvider', 'in'], advapi32 = client.railgun.advapi32 ['DWORD', 'dwProvType', 'in'], acquirecontext = advapi32.CryptAcquireContext ['DWORD', 'dwflags', 'in']]) W(4, nil, ms_enhanced_prov, prov_rsa_full, crypt_verify_context) Used in the SmartFTP password Recovery Module
  • 26.  Pass in Ruby True/False values exactly as expected
  • 27. Definition: dll.add_function( 'IsDebuggerPresent', 'BOOL',[]) Usage: >> client.railgun.kernel32.IsDebuggerPresent() => {"GetLastError"=>0, "return"=>false}
  • 28.  Handled the same as DWORDs but Fixnums passed in will be truncated to the appropriate length
  • 29.  Anything that’s not a string or a DWORD  Treated as a ruby string  Railgun will not help you parse structures
  • 30. Definition Usage dll.add_function( 'WlanGetProfile', profile['name'] = 'DWORD',[ @host_process.memory.rea ['DWORD', 'hClientHandle', 'in'], d(ppointer,512) ['PBLOB', 'pInterfaceGuid', 'in'], ppointer = (ppointer + 516) ['PBLOB', 'strProfileName', 'in'], ['LPVOID', 'pReserved', 'in'], ['PDWORD', 'pstrProfileXML', rprofile = 'out'], @wlanapi.WlanGetProfile(wl ['PDWORD', 'pdwFlags', 'inout'], an_handle,guid,profile['nam e'],nil,4,4,4) ['PDWORD', 'pdwGrantedAccess', 'out']]) Used in the wlan_profile post module
  • 31.  Pointers and Handles of any kind are really just numbers, so treat them as DWORDs  If it can be treated as a number it’s a DWORD  Otherwise it’s a PBLOB  If neither works, add support for it yourself =)
  • 32.  The function will return a hash  Hash will always contain at least GetLastError  Hash will return any OUT values
  • 33.  Will return 0 if there was no error  Otherwise will contain the windows system Error code encountered  Errors codes can be looked up at http://msdn.microsoft.com/en - us/library/windows/desktop/ ms681381(v=vs.85).aspx
  • 34. acquirecontext = advapi32.CryptAcquireCon textW(4, nil, ms_enhanced_prov, prov_rsa_full, crypt_verify_context) createhash = advapi32.CryptCreateHash (acquirecontext['phProv'] , alg_md5, 0, 0, 4)
  • 35.  Complex structure types that you will have to parse yourself  Strings you don’t know the length of  Large number of string reads (SLOWWWW)
  • 37. Microsoft will help you own things
  • 39. They even give you tools!
  • 41.  Anything you can do with the windows API is available  Without increasing the size of the payload
  • 42.  Get the OS to Decrypt stored SmartFTP Passwords  Enumerate and decrypt stored RDP passwords  Scan for Wireless APs  Enumerates Domain controllers on the victim’s network
  • 43.  Enough of these ugly slides  Let’s see it in action