Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Moving py smb to runtime #676

Merged
merged 2 commits into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/docker/server/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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/

Expand Down
42 changes: 35 additions & 7 deletions pkg/server/smb_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,25 @@ 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 {
Mzack9999 marked this conversation as resolved.
Show resolved Hide resolved
return err
}

smbPort := fmt.Sprint(h.options.SmbPort)
h.cmd = exec.Command("python3", pyFileName, h.tmpFile, smbPort)
err = h.cmd.Start()
if err != nil {
return err
Expand Down Expand Up @@ -121,3 +130,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()
`