From 2509c3ef4d0472e7fd8c7cf93570100ec2159142 Mon Sep 17 00:00:00 2001 From: Mzack9999 Date: Mon, 2 Oct 2023 10:18:50 +0200 Subject: [PATCH 1/2] moving py smb to runtime --- .github/docker/server/Dockerfile | 1 - pkg/server/smb_server.go | 43 ++++++++++++++++++++++++++------ 2 files changed, 36 insertions(+), 8 deletions(-) diff --git a/.github/docker/server/Dockerfile b/.github/docker/server/Dockerfile index d534cb2c..14c0f872 100644 --- a/.github/docker/server/Dockerfile +++ b/.github/docker/server/Dockerfile @@ -15,7 +15,6 @@ RUN apk -U upgrade --no-cache \ && python3 -m pip install impacket \ && python3 -m pip cache purge \ && apk del .build-deps -RUN curl -o /usr/local/bin/smb_server.py https://raw.githubusercontent.com/projectdiscovery/interactsh/main/cmd/interactsh-server/smb_server.py WORKDIR "/usr/local/bin" COPY --from=builder /app/interactsh-server /usr/local/bin/ diff --git a/pkg/server/smb_server.go b/pkg/server/smb_server.go index ba97d889..ad3fad86 100644 --- a/pkg/server/smb_server.go +++ b/pkg/server/smb_server.go @@ -46,16 +46,26 @@ func (h *SMBServer) ListenAndServe(smbAlive chan bool) error { defer func() { smbAlive <- false }() - tmpFile, err := os.CreateTemp("", "") + + var err error + h.tmpFile, err = fileutil.GetTempFileName() + if err != nil { + return err + } + + pyFileName, err := fileutil.GetTempFileName() if err != nil { return err } - h.tmpFile = tmpFile.Name() - tmpFile.Close() - // execute smb_server.py - only works with ./interactsh-server - cmdLine := fmt.Sprintf("python3 smb_server.py %s %d", h.tmpFile, h.options.SmbPort) - args := strings.Fields(cmdLine) - h.cmd = exec.Command(args[0], args[1:]...) + pyFileName += ".py" + + if err := os.WriteFile(pyFileName, []byte(pySmbServer), os.ModePerm); err != nil { + return err + } + + // args := strings.Fields(cmdLine) + smbPort := fmt.Sprint(h.options.SmbPort) + h.cmd = exec.Command("python3", pyFileName, h.tmpFile, smbPort) err = h.cmd.Start() if err != nil { return err @@ -121,3 +131,22 @@ func (h *SMBServer) Close() { os.RemoveAll(h.tmpFile) } } + +var pySmbServer = ` +import sys +from impacket import smbserver + +log_filename = "log.txt" +if len(sys.argv) >= 2: + log_filename = sys.argv[1] +port = 445 +if len(sys.argv) >= 3: + port = int(sys.argv[2]) + +server = smbserver.SimpleSMBServer(listenAddress="0.0.0.0", listenPort=port) +server.setSMB2Support(True) +server.addShare("interactsh", "/interactsh") +server.setSMBChallenge('') +server.setLogFile(log_filename) +server.start() +` From 2de317d7f799d8bd8299c371403f42832d8333e1 Mon Sep 17 00:00:00 2001 From: Mzack9999 Date: Thu, 5 Oct 2023 11:23:31 +0200 Subject: [PATCH 2/2] lint errors --- pkg/server/smb_server.go | 1 - 1 file changed, 1 deletion(-) diff --git a/pkg/server/smb_server.go b/pkg/server/smb_server.go index ad3fad86..2ae7807c 100644 --- a/pkg/server/smb_server.go +++ b/pkg/server/smb_server.go @@ -63,7 +63,6 @@ func (h *SMBServer) ListenAndServe(smbAlive chan bool) error { return err } - // args := strings.Fields(cmdLine) smbPort := fmt.Sprint(h.options.SmbPort) h.cmd = exec.Command("python3", pyFileName, h.tmpFile, smbPort) err = h.cmd.Start()