-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdrone-hashdump.py
73 lines (58 loc) · 1.96 KB
/
drone-hashdump.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
#!/usr/bin/env python
"""drone-hashdump
Usage:
drone-hashdump [options] <id> <file>
drone-hashdump --version
Options:
-h --help Show usage.
--version Show version.
-k Allow insecure SSL connections.
"""
import os
from sys import exit
from urlparse import urlparse
from netaddr import IPAddress, AddrFormatError
from docopt import docopt
from pylair import models
from pylair import client
def main():
arguments = docopt(__doc__, version='drone-hashdump 1.0.0')
lair_url = ''
try:
lair_url = os.environ['LAIR_API_SERVER']
except KeyError:
print "Fatal: Missing LAIR_API_SERVER environment variable"
exit(1)
u = urlparse(lair_url)
if u.username is None or u.password is None:
print "Fatal: Missing username and/or password"
exit(1)
project_id = arguments['<id>']
project = dict(models.project)
project['id'] = project_id
project['commands'] = [{'command': 'iphashdump', 'tool': 'iphashdump'}]
project['tool'] = 'drone-hashdump'
opts = client.Options(u.username, u.password, u.hostname + ":" + str(u.port), project_id, scheme=u.scheme,
insecure_skip_verify=arguments['-k'])
lines = []
cidrs = set()
try:
lines = [line.rstrip('\n') for line in open(arguments['<file>'])]
except IOError as e:
print "Fatal: Could not open file. Error: {0}".format(e)
exit(1)
for line in lines:
entry = line.split(":")
print entry
credential = dict(models.credential)
credential['projectId'] = project_id
credential['username'] = entry[0]
credential['hash'] = entry[2]+":"+entry[3]
project['credentials'].append(credential)
res = client.import_project(project, opts)
if res['status'] == 'Error':
print "Fatal: " + res['message']
exit(1)
print "Success: Operation completed successfully"
if __name__ == '__main__':
main()