forked from tlsnotary/pagesigner-oracles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
aws_query.py
73 lines (64 loc) · 2.26 KB
/
aws_query.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
66
67
68
69
70
71
72
73
import sys
import hmac
import base64
import hashlib
from urllib import parse
if len(sys.argv) != 5:
print ('Output HTTPS GET links to be used to check the oracle status')
print ('The default availability zone is ec2.us-east-1.amazonaws.com')
print ('Usage: instance-id volume-id AWS-ID AWS-secret')
print ('Where instance-id is the oracle instance and volume-id is the volume attached to it')
exit(0)
common_args = [('Expires=2025-01-01'), ('SignatureMethod=HmacSHA256'), ('SignatureVersion=2')]
availability_zone = 'ec2.us-east-1.amazonaws.com'
instance_id = sys.argv[1]
volume_id = sys.argv[2]
key = sys.argv[3]
secret = sys.argv[4]
def makeurl(args, endpoint, abbr):
args.sort()
argstr = ''
for arg in args:
argstr += parse.quote_plus(arg, '=')+'&'
argstr = argstr[:-1]
secret_bytes = bytes(secret , 'latin-1')
mhmac = hmac.new(secret_bytes, ('GET\n'+endpoint+'\n/\n'+argstr).encode('utf-8'),hashlib.sha256)
base64str = base64.b64encode(mhmac.digest()).strip().decode('utf-8')
urlenc_sig = parse.quote_plus(base64str)
final_string='https://'+endpoint+'/?'+argstr+'&Signature='+urlenc_sig
print ("'" + abbr + "':'" + final_string + "',")
args = []
args.extend(common_args)
args.append('Action=DescribeInstances')
args.append('InstanceId='+instance_id)
args.append('AWSAccessKeyId='+key)
args.append('Version=2014-10-01')
makeurl(args, availability_zone, 'DI')
args = []
args.extend(common_args)
args.append('Action=DescribeVolumes')
args.append('VolumeId='+volume_id)
args.append('AWSAccessKeyId='+key)
args.append('Version=2014-10-01')
makeurl(args, availability_zone, 'DV')
args = []
args.extend(common_args)
args.append('Action=GetConsoleOutput')
args.append('InstanceId='+instance_id)
args.append('AWSAccessKeyId='+key)
args.append('Version=2014-10-01')
makeurl(args, availability_zone, 'GCO')
args = []
args.extend(common_args)
args.append('Action=GetUser')
args.append('AWSAccessKeyId='+key)
args.append('Version=2010-05-08')
makeurl(args, 'iam.amazonaws.com', 'GU')
args = []
args.extend(common_args)
args.append('Action=DescribeInstanceAttribute')
args.append('InstanceId='+instance_id)
args.append('Attribute=userData')
args.append('AWSAccessKeyId='+key)
args.append('Version=2014-10-01')
makeurl(args, availability_zone, 'DIA')