forked from myanaloglife/py-kms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rpcRequest.py
65 lines (49 loc) · 1.93 KB
/
rpcRequest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import binascii
import kmsBase
import rpcBase
import struct
import uuid
from dcerpc import MSRPCRequestHeader, MSRPCRespHeader
class handler(rpcBase.rpcBase):
def parseRequest(self):
request = MSRPCRequestHeader(self.data)
if self.config['debug']:
print "RPC Message Request Bytes:", binascii.b2a_hex(self.data)
print "RPC Message Request:", request.dump()
return request
def generateResponse(self):
request = self.requestData
responseData = kmsBase.generateKmsResponseData(request['pduData'], self.config)
envelopeLength = len(responseData)
response = MSRPCRespHeader()
response['ver_major'] = request['ver_major']
response['ver_minor'] = request['ver_minor']
response['type'] = self.packetType['response']
response['flags'] = self.packetFlags['firstFrag'] | self.packetFlags['lastFrag']
response['representation'] = request['representation']
response['call_id'] = request['call_id']
response['alloc_hint'] = envelopeLength
response['ctx_id'] = request['ctx_id']
response['cancel_count'] = 0
response['pduData'] = responseData
if self.config['debug']:
print "RPC Message Response:", response.dump()
print "RPC Message Response Bytes:", binascii.b2a_hex(str(response))
return response
class request(rpcBase.rpcBase):
def generateRequest(self):
request = MSRPCRequestHeader()
request['ver_major'] = 5
request['ver_minor'] = 0
request['type'] = self.packetType['request']
request['flags'] = self.packetFlags['firstFrag'] | self.packetFlags['lastFrag']
request['representation'] = request['representation']
request['call_id'] = self.config['call_id']
request['alloc_hint'] = len(self.data)
request['pduData'] = self.data
if self.config['debug']:
print "RPC Message Request:", request.dump()
print "RPC Message Request Bytes:", binascii.b2a_hex(str(request))
return request
def parseResponse(self):
return response