-
Notifications
You must be signed in to change notification settings - Fork 783
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from wh0am1i/dev
Dev
- Loading branch information
Showing
8 changed files
with
222 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
__title__ = 'pocsuite3' | ||
__version__ = '2.0.5' | ||
__version__ = '2.0.6' | ||
__author__ = 'Knownsec 404 Team' | ||
__author_email__ = '[email protected]' | ||
__license__ = 'GPLv2' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
from io import BytesIO | ||
from docker import client | ||
from docker import errors | ||
|
||
|
||
from pocsuite3.lib.core.data import logger | ||
|
||
|
||
class DockerEnv: | ||
|
||
def __init__(self): | ||
self.client = client.from_env() | ||
|
||
def build(self, name, docker_file): | ||
file_obj = BytesIO(docker_file.encode()) | ||
try: | ||
logger.info("Building image...") | ||
build_info = self.client.images.build(fileobj=file_obj, tag=name) | ||
return build_info | ||
except errors.BuildError as e: | ||
logger.error(e) | ||
|
||
def run(self, tag_name, docker_file, ports, envs, volumes): | ||
try: | ||
# if image exists run | ||
self.client.images.get(tag_name) | ||
logger.info("Image {} exists".format(tag_name)) | ||
run_info = self.client.containers.run( | ||
tag_name, | ||
detach=True, | ||
ports=ports, | ||
environment=envs, | ||
volumes=volumes | ||
) | ||
return run_info | ||
except errors.ImageNotFound: | ||
# if image not exists, build image first | ||
logger.info("Image {} does not exist".format(tag_name)) | ||
build_info = self.build(tag_name, docker_file) | ||
if build_info[0].tags: | ||
run_info = self.client.containers.run( | ||
tag_name, | ||
detach=True, | ||
ports=ports, | ||
environment=envs, | ||
volumes=volumes | ||
) | ||
return run_info | ||
|
||
|
||
if __name__ == "__main__": | ||
docker_env = DockerEnv() | ||
ports = {"8080/tcp": '8899', '8090/tcp': ("127.0.0.1", 8890)} | ||
env = ["PORT=8899", "PORT=8890"] | ||
volumes = ["/tmp:/home"] | ||
dockerfile = "FROM ubuntu:latest" | ||
image_tag = "ubuntu:pocsuite" | ||
docker_env.run( | ||
image_tag, | ||
docker_file=dockerfile, | ||
ports=ports, | ||
envs=env, | ||
volumes=volumes | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import re | ||
from pocsuite3.lib.core.data import conf | ||
from pocsuite3.lib.core.data import logger | ||
from pocsuite3.lib.core.common import get_file_text | ||
|
||
|
||
def parse_dockerfile(file): | ||
regx_rules = [ | ||
"name = '(.*)'", | ||
"vulID = '(.*)'", | ||
r"dockerfile = '''([\s\S]*?)'''", | ||
] | ||
result = { | ||
"name": 0, | ||
"vulID": 1, | ||
"dockerfile": 2, | ||
} | ||
st = get_file_text(file) | ||
for k, v in result.items(): | ||
pattern = re.compile(regx_rules[v]) | ||
match = pattern.findall(st) | ||
if match is not None: | ||
result[k] = match[0] | ||
|
||
return result | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,3 +15,4 @@ dacite >= 1.6.0 | |
PyYAML >= 6.0 | ||
lxml >= 4.6.0 | ||
mmh3 >= 3.0.0 | ||
docker >= 6.1.3 |