DCERPC and Endpoint Mapper - samba.orgasn/2011-sambaxp-dcerpc.pdf · DCERPC Endpoint Mapper Samba3...

31
DCERPC Endpoint Mapper Samba3 RPC Server Why? DCERPC and Endpoint Mapper Andreas Schneider <[email protected]> Red Hat May 11th, 2011 Andreas Schneider <[email protected]> Red Hat DCERPC and Endpoint Mapper

Transcript of DCERPC and Endpoint Mapper - samba.orgasn/2011-sambaxp-dcerpc.pdf · DCERPC Endpoint Mapper Samba3...

Page 1: DCERPC and Endpoint Mapper - samba.orgasn/2011-sambaxp-dcerpc.pdf · DCERPC Endpoint Mapper Samba3 RPC Server Why? DCERPC and Endpoint Mapper 1 DCERPC How does RPC work? 2 Endpoint

DCERPC Endpoint Mapper Samba3 RPC Server Why?

DCERPC and Endpoint Mapper

Andreas Schneider <[email protected]>

Red Hat

May 11th, 2011

Andreas Schneider <[email protected]> Red Hat

DCERPC and Endpoint Mapper

Page 2: DCERPC and Endpoint Mapper - samba.orgasn/2011-sambaxp-dcerpc.pdf · DCERPC Endpoint Mapper Samba3 RPC Server Why? DCERPC and Endpoint Mapper 1 DCERPC How does RPC work? 2 Endpoint

DCERPC Endpoint Mapper Samba3 RPC Server Why?

DCERPC and Endpoint Mapper

1 DCERPCHow does RPC work?

2 Endpoint MapperConceptFunctions and Details

3 Samba3 RPC ServerOverviewRobustnessScalability

4 Why?FrankyFreeIPA

Andreas Schneider <[email protected]> Red Hat

DCERPC and Endpoint Mapper

Page 3: DCERPC and Endpoint Mapper - samba.orgasn/2011-sambaxp-dcerpc.pdf · DCERPC Endpoint Mapper Samba3 RPC Server Why? DCERPC and Endpoint Mapper 1 DCERPC How does RPC work? 2 Endpoint

DCERPC Endpoint Mapper Samba3 RPC Server Why?

How does RPC work?

DCERPC and Endpoint Mapper

1 DCERPCHow does RPC work?

2 Endpoint MapperConceptFunctions and Details

3 Samba3 RPC ServerOverviewRobustnessScalability

4 Why?FrankyFreeIPA

Andreas Schneider <[email protected]> Red Hat

DCERPC and Endpoint Mapper

Page 4: DCERPC and Endpoint Mapper - samba.orgasn/2011-sambaxp-dcerpc.pdf · DCERPC Endpoint Mapper Samba3 RPC Server Why? DCERPC and Endpoint Mapper 1 DCERPC How does RPC work? 2 Endpoint

DCERPC Endpoint Mapper Samba3 RPC Server Why?

How does RPC work?

Abbreviations

DCE: Distributed (Disturbed) Computing Environment

RPC: Remote Procedure Call

NDR: Network Data Representation

IDL: Interface description language

Andreas Schneider <[email protected]> Red Hat

DCERPC and Endpoint Mapper

Page 5: DCERPC and Endpoint Mapper - samba.orgasn/2011-sambaxp-dcerpc.pdf · DCERPC Endpoint Mapper Samba3 RPC Server Why? DCERPC and Endpoint Mapper 1 DCERPC How does RPC work? 2 Endpoint

DCERPC Endpoint Mapper Samba3 RPC Server Why?

How does RPC work?

The RPC process

Application

Client Stub

RPC Library

Transport

Application

Server Stub

RPC Library

Transport

Server

Andreas Schneider <[email protected]> Red Hat

DCERPC and Endpoint Mapper

Page 6: DCERPC and Endpoint Mapper - samba.orgasn/2011-sambaxp-dcerpc.pdf · DCERPC Endpoint Mapper Samba3 RPC Server Why? DCERPC and Endpoint Mapper 1 DCERPC How does RPC work? 2 Endpoint

DCERPC Endpoint Mapper Samba3 RPC Server Why?

How does RPC work?

Application

spoolss: Printing application displaying a list of printers

regedit: Display all values of a key

Application

Client Stub

RPC Library

Transport

Application

Server Stub

RPC Library

Transport

Server

Andreas Schneider <[email protected]> Red Hat

DCERPC and Endpoint Mapper

Page 7: DCERPC and Endpoint Mapper - samba.orgasn/2011-sambaxp-dcerpc.pdf · DCERPC Endpoint Mapper Samba3 RPC Server Why? DCERPC and Endpoint Mapper 1 DCERPC How does RPC work? 2 Endpoint

DCERPC Endpoint Mapper Samba3 RPC Server Why?

How does RPC work?

Client Stubs

spoolss: Your application calling dcerpc spoolss EnumPrinters

regedit: Your application calling dcerpc winreg EnumValues

Application

Client Stub

RPC Library

Transport

Application

Server Stub

RPC Library

Transport

Server

Andreas Schneider <[email protected]> Red Hat

DCERPC and Endpoint Mapper

Page 8: DCERPC and Endpoint Mapper - samba.orgasn/2011-sambaxp-dcerpc.pdf · DCERPC Endpoint Mapper Samba3 RPC Server Why? DCERPC and Endpoint Mapper 1 DCERPC How does RPC work? 2 Endpoint

DCERPC Endpoint Mapper Samba3 RPC Server Why?

How does RPC work?

Run-time Library

RPC client implementation creating a RPC bind

Establishes the connection

Authenticates the user

Application

Client Stub

RPC Library

Transport

Application

Server Stub

RPC Library

Transport

Server

Andreas Schneider <[email protected]> Red Hat

DCERPC and Endpoint Mapper

Page 9: DCERPC and Endpoint Mapper - samba.orgasn/2011-sambaxp-dcerpc.pdf · DCERPC Endpoint Mapper Samba3 RPC Server Why? DCERPC and Endpoint Mapper 1 DCERPC How does RPC work? 2 Endpoint

DCERPC Endpoint Mapper Samba3 RPC Server Why?

How does RPC work?

Transports

ncacn np: SMB Named Pipes transport

ncacn ip tcp: DCE/RPC over TCP/IP

ncalrpc: Local interprocess communication

ncacn http: DCE/RPC over HTTP

ncadg ip udp, ncacn at dsp, ncacn nb ipx, ncacn dnet nsp, ...

Andreas Schneider <[email protected]> Red Hat

DCERPC and Endpoint Mapper

Page 10: DCERPC and Endpoint Mapper - samba.orgasn/2011-sambaxp-dcerpc.pdf · DCERPC Endpoint Mapper Samba3 RPC Server Why? DCERPC and Endpoint Mapper 1 DCERPC How does RPC work? 2 Endpoint

DCERPC Endpoint Mapper Samba3 RPC Server Why?

How does RPC work?

Run-time Library

The RPC Server accepting a connection over a transport andcreating the RPC bind

After successfull authentication it calls the Server Stub

Application

Client Stub

RPC Library

Transport

Application

Server Stub

RPC Library

Transport

Server

Andreas Schneider <[email protected]> Red Hat

DCERPC and Endpoint Mapper

Page 11: DCERPC and Endpoint Mapper - samba.orgasn/2011-sambaxp-dcerpc.pdf · DCERPC Endpoint Mapper Samba3 RPC Server Why? DCERPC and Endpoint Mapper 1 DCERPC How does RPC work? 2 Endpoint

DCERPC Endpoint Mapper Samba3 RPC Server Why?

How does RPC work?

Server Stubs

This unmarshals the packet and calls the applicationimplementation

spoolss: spoolss EnumPrintersregedit: winreg EnumValues

Application

Client Stub

RPC Library

Transport

Application

Server Stub

RPC Library

Transport

Server

Andreas Schneider <[email protected]> Red Hat

DCERPC and Endpoint Mapper

Page 12: DCERPC and Endpoint Mapper - samba.orgasn/2011-sambaxp-dcerpc.pdf · DCERPC Endpoint Mapper Samba3 RPC Server Why? DCERPC and Endpoint Mapper 1 DCERPC How does RPC work? 2 Endpoint

DCERPC Endpoint Mapper Samba3 RPC Server Why?

Concept

DCERPC and Endpoint Mapper

1 DCERPCHow does RPC work?

2 Endpoint MapperConceptFunctions and Details

3 Samba3 RPC ServerOverviewRobustnessScalability

4 Why?FrankyFreeIPA

Andreas Schneider <[email protected]> Red Hat

DCERPC and Endpoint Mapper

Page 13: DCERPC and Endpoint Mapper - samba.orgasn/2011-sambaxp-dcerpc.pdf · DCERPC Endpoint Mapper Samba3 RPC Server Why? DCERPC and Endpoint Mapper 1 DCERPC How does RPC work? 2 Endpoint

DCERPC Endpoint Mapper Samba3 RPC Server Why?

Concept

Abbreviations

EPM: Endpoint Mapper

UUID: Universally Unique Identifier (man uuidgen)

NDR: Network Data Representation

Andreas Schneider <[email protected]> Red Hat

DCERPC and Endpoint Mapper

Page 14: DCERPC and Endpoint Mapper - samba.orgasn/2011-sambaxp-dcerpc.pdf · DCERPC Endpoint Mapper Samba3 RPC Server Why? DCERPC and Endpoint Mapper 1 DCERPC How does RPC work? 2 Endpoint

DCERPC Endpoint Mapper Samba3 RPC Server Why?

Concept

Terminology

Endpoint: An endpoint could be a port or a pipe and provideseveral interfaces

Interface: An interface is a RPC service provided by anendpoint

The named pipe \\PIPE\netlogon can be used for netlogon andlsarpc connections.

Andreas Schneider <[email protected]> Red Hat

DCERPC and Endpoint Mapper

Page 15: DCERPC and Endpoint Mapper - samba.orgasn/2011-sambaxp-dcerpc.pdf · DCERPC Endpoint Mapper Samba3 RPC Server Why? DCERPC and Endpoint Mapper 1 DCERPC How does RPC work? 2 Endpoint

DCERPC Endpoint Mapper Samba3 RPC Server Why?

Concept

Remember: The RPC process

Application

Client Stub

RPC Library

Transport

Application

Server Stub

RPC Library

Transport

Server

Andreas Schneider <[email protected]> Red Hat

DCERPC and Endpoint Mapper

Page 16: DCERPC and Endpoint Mapper - samba.orgasn/2011-sambaxp-dcerpc.pdf · DCERPC Endpoint Mapper Samba3 RPC Server Why? DCERPC and Endpoint Mapper 1 DCERPC How does RPC work? 2 Endpoint

DCERPC Endpoint Mapper Samba3 RPC Server Why?

Concept

Endpoint operations

Each RPC service allocates one or more endpoints dynamicallyon server startup

Endpoint mapper maintains information about thoseendpoints

The Endpoint Mapper listens on port 135 TCP/IP or on\\PIPE\epmapper

Andreas Schneider <[email protected]> Red Hat

DCERPC and Endpoint Mapper

Page 17: DCERPC and Endpoint Mapper - samba.orgasn/2011-sambaxp-dcerpc.pdf · DCERPC Endpoint Mapper Samba3 RPC Server Why? DCERPC and Endpoint Mapper 1 DCERPC How does RPC work? 2 Endpoint

DCERPC Endpoint Mapper Samba3 RPC Server Why?

Functions and Details

DCERPC and Endpoint Mapper

1 DCERPCHow does RPC work?

2 Endpoint MapperConceptFunctions and Details

3 Samba3 RPC ServerOverviewRobustnessScalability

4 Why?FrankyFreeIPA

Andreas Schneider <[email protected]> Red Hat

DCERPC and Endpoint Mapper

Page 18: DCERPC and Endpoint Mapper - samba.orgasn/2011-sambaxp-dcerpc.pdf · DCERPC Endpoint Mapper Samba3 RPC Server Why? DCERPC and Endpoint Mapper 1 DCERPC How does RPC work? 2 Endpoint

DCERPC Endpoint Mapper Samba3 RPC Server Why?

Functions and Details

Function overview

The most important function of the endpoint mapper.

epm Insert Add specified entries to an endpoint map.

epm Delete Delete specified entries from an endpoint map.

epm Lookup Lookup entries in an endpoint map.

epm Map Apply some algorithm to an endpoint map toproduce a list of protocol towers. (Provide an uuid and get anendpoint)

epm LookupHandleFree Free an epm Lookup or epm Mapentry handle.

Andreas Schneider <[email protected]> Red Hat

DCERPC and Endpoint Mapper

Page 19: DCERPC and Endpoint Mapper - samba.orgasn/2011-sambaxp-dcerpc.pdf · DCERPC Endpoint Mapper Samba3 RPC Server Why? DCERPC and Endpoint Mapper 1 DCERPC How does RPC work? 2 Endpoint

DCERPC Endpoint Mapper Samba3 RPC Server Why?

Functions and Details

Example

Wireshark trace ...

Andreas Schneider <[email protected]> Red Hat

DCERPC and Endpoint Mapper

Page 20: DCERPC and Endpoint Mapper - samba.orgasn/2011-sambaxp-dcerpc.pdf · DCERPC Endpoint Mapper Samba3 RPC Server Why? DCERPC and Endpoint Mapper 1 DCERPC How does RPC work? 2 Endpoint

DCERPC Endpoint Mapper Samba3 RPC Server Why?

Functions and Details

An endpoint tower

A tower has up to 6 floors, 4 at least

1 Floor1: Provides the RPC interface identifier (netlogon uuid).

2 Floor2: Transfer syntax (NDR endcoded)

3 Floor3: RPC protocol identifier (ncacn tcp ip, ncacn np, ...)

4 Floor4: Port address (e.g. TCP Port: 49156, PIPE)

5 Floor5: Transport (e.g. IP:192.168.51.10, NB:krikkit)

6 Floor6: Routing

Andreas Schneider <[email protected]> Red Hat

DCERPC and Endpoint Mapper

Page 21: DCERPC and Endpoint Mapper - samba.orgasn/2011-sambaxp-dcerpc.pdf · DCERPC Endpoint Mapper Samba3 RPC Server Why? DCERPC and Endpoint Mapper 1 DCERPC How does RPC work? 2 Endpoint

DCERPC Endpoint Mapper Samba3 RPC Server Why?

Overview

DCERPC and Endpoint Mapper

1 DCERPCHow does RPC work?

2 Endpoint MapperConceptFunctions and Details

3 Samba3 RPC ServerOverviewRobustnessScalability

4 Why?FrankyFreeIPA

Andreas Schneider <[email protected]> Red Hat

DCERPC and Endpoint Mapper

Page 22: DCERPC and Endpoint Mapper - samba.orgasn/2011-sambaxp-dcerpc.pdf · DCERPC Endpoint Mapper Samba3 RPC Server Why? DCERPC and Endpoint Mapper 1 DCERPC How does RPC work? 2 Endpoint

DCERPC Endpoint Mapper Samba3 RPC Server Why?

Overview

RPC Endpoints

Added support for TCP/IP and NCALRPC

Other processes can register at EPM (OpenChange) overNCALRPC

Andreas Schneider <[email protected]> Red Hat

DCERPC and Endpoint Mapper

Page 23: DCERPC and Endpoint Mapper - samba.orgasn/2011-sambaxp-dcerpc.pdf · DCERPC Endpoint Mapper Samba3 RPC Server Why? DCERPC and Endpoint Mapper 1 DCERPC How does RPC work? 2 Endpoint

DCERPC Endpoint Mapper Samba3 RPC Server Why?

Robustness

DCERPC and Endpoint Mapper

1 DCERPCHow does RPC work?

2 Endpoint MapperConceptFunctions and Details

3 Samba3 RPC ServerOverviewRobustnessScalability

4 Why?FrankyFreeIPA

Andreas Schneider <[email protected]> Red Hat

DCERPC and Endpoint Mapper

Page 24: DCERPC and Endpoint Mapper - samba.orgasn/2011-sambaxp-dcerpc.pdf · DCERPC Endpoint Mapper Samba3 RPC Server Why? DCERPC and Endpoint Mapper 1 DCERPC How does RPC work? 2 Endpoint

DCERPC Endpoint Mapper Samba3 RPC Server Why?

Robustness

Robustness

Client

RPC service tries to register serveral times

After successful registration we do connection monitoring

Server

We monitor the client connection

If it goes away, delete the endpoints

Andreas Schneider <[email protected]> Red Hat

DCERPC and Endpoint Mapper

Page 25: DCERPC and Endpoint Mapper - samba.orgasn/2011-sambaxp-dcerpc.pdf · DCERPC Endpoint Mapper Samba3 RPC Server Why? DCERPC and Endpoint Mapper 1 DCERPC How does RPC work? 2 Endpoint

DCERPC Endpoint Mapper Samba3 RPC Server Why?

Scalability

DCERPC and Endpoint Mapper

1 DCERPCHow does RPC work?

2 Endpoint MapperConceptFunctions and Details

3 Samba3 RPC ServerOverviewRobustnessScalability

4 Why?FrankyFreeIPA

Andreas Schneider <[email protected]> Red Hat

DCERPC and Endpoint Mapper

Page 26: DCERPC and Endpoint Mapper - samba.orgasn/2011-sambaxp-dcerpc.pdf · DCERPC Endpoint Mapper Samba3 RPC Server Why? DCERPC and Endpoint Mapper 1 DCERPC How does RPC work? 2 Endpoint

DCERPC Endpoint Mapper Samba3 RPC Server Why?

Scalability

Pre-fork

We started to implement a mutex locking based pre-fork model.

Parent binds all sockets and then forks a number of children

Childs have a lock around the accept(3) call

Prototype working for our spoolss daemon

Andreas Schneider <[email protected]> Red Hat

DCERPC and Endpoint Mapper

Page 27: DCERPC and Endpoint Mapper - samba.orgasn/2011-sambaxp-dcerpc.pdf · DCERPC Endpoint Mapper Samba3 RPC Server Why? DCERPC and Endpoint Mapper 1 DCERPC How does RPC work? 2 Endpoint

DCERPC Endpoint Mapper Samba3 RPC Server Why?

Franky

DCERPC and Endpoint Mapper

1 DCERPCHow does RPC work?

2 Endpoint MapperConceptFunctions and Details

3 Samba3 RPC ServerOverviewRobustnessScalability

4 Why?FrankyFreeIPA

Andreas Schneider <[email protected]> Red Hat

DCERPC and Endpoint Mapper

Page 28: DCERPC and Endpoint Mapper - samba.orgasn/2011-sambaxp-dcerpc.pdf · DCERPC Endpoint Mapper Samba3 RPC Server Why? DCERPC and Endpoint Mapper 1 DCERPC How does RPC work? 2 Endpoint

DCERPC Endpoint Mapper Samba3 RPC Server Why?

Franky

Franky

A lot of infrastructure has been created for Franky

EPM allows us to have multiple daemons

Andreas Schneider <[email protected]> Red Hat

DCERPC and Endpoint Mapper

Page 29: DCERPC and Endpoint Mapper - samba.orgasn/2011-sambaxp-dcerpc.pdf · DCERPC Endpoint Mapper Samba3 RPC Server Why? DCERPC and Endpoint Mapper 1 DCERPC How does RPC work? 2 Endpoint

DCERPC Endpoint Mapper Samba3 RPC Server Why?

FreeIPA

DCERPC and Endpoint Mapper

1 DCERPCHow does RPC work?

2 Endpoint MapperConceptFunctions and Details

3 Samba3 RPC ServerOverviewRobustnessScalability

4 Why?FrankyFreeIPA

Andreas Schneider <[email protected]> Red Hat

DCERPC and Endpoint Mapper

Page 30: DCERPC and Endpoint Mapper - samba.orgasn/2011-sambaxp-dcerpc.pdf · DCERPC Endpoint Mapper Samba3 RPC Server Why? DCERPC and Endpoint Mapper 1 DCERPC How does RPC work? 2 Endpoint

DCERPC Endpoint Mapper Samba3 RPC Server Why?

FreeIPA

FreeIPA

FreeIPA is something like Active Directory but for Linux only.

We want to be able to do forest trusts with Active Directory

For this we need LSA and Netlogon (SAMR)

pdb ipa and ’net rpc trust’

Andreas Schneider <[email protected]> Red Hat

DCERPC and Endpoint Mapper

Page 31: DCERPC and Endpoint Mapper - samba.orgasn/2011-sambaxp-dcerpc.pdf · DCERPC Endpoint Mapper Samba3 RPC Server Why? DCERPC and Endpoint Mapper 1 DCERPC How does RPC work? 2 Endpoint

DCERPC Endpoint Mapper Samba3 RPC Server Why?

FreeIPA

Questions & Answers

Slides http://www.samba.org/~asn/

Andreas Schneider <[email protected]> Red Hat

DCERPC and Endpoint Mapper