Skip to content

Commit

Permalink
start wrapper in nim instead shell
Browse files Browse the repository at this point in the history
  • Loading branch information
ariary committed Oct 3, 2022
1 parent dccacd1 commit 3e3baaa
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 1 deletion.
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,7 @@ build.tacos.image:
docker build -f ./Dockerfiles/Dockerfile-tacos -t ariary/tacos ./Dockerfiles

build.tacos-reverse.image:
docker build -f ./Dockerfiles/Dockerfile-reverse -t ariary/tacos-reverse .
docker build -f ./Dockerfiles/Dockerfile-reverse -t ariary/tacos-reverse .

build.wrap:
nim -o:wrap/bin/wrap c wrap/src/wrap.nim
Binary file added wrap/bin/wrap
Binary file not shown.
Binary file added wrap/src/wrap
Binary file not shown.
89 changes: 89 additions & 0 deletions wrap/src/wrap.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import os
import osproc
import terminal

const TACOS_DIRPATH: string = getHomeDir()&".tacos/"
const PTY4ALL: string = TACOS_DIRPATH&"light-pty4all/"

proc Wrap(
bore = false,
ngrok = false,
lhost ="",
lport = 4444,
webport=9292,
gitar = true,
windows=false,
tmp=false,
noShortcut=false
): void =
## Ease the launch of socat listener waiting for tacos interactive reverse shell
#Flag consistency
if ngrok and bore:
styledEcho("Conflicting flags ",fgRed,"--ngrok and --bore")
quit(QuitFailure)

if lport==webport:
styledEcho("Conflicting flags ",fgRed,"--lport and --webport are equals")
quit(QuitFailure)

if tmp and windows:
styledEcho("Conflicting flags ",fgRed,"--tmp and --windows")
quit(QuitFailure)

if (bore or ngrok) and lhost!="":
styledEcho("鈿狅笍 ",fgYellow,"--lhost has been filled but will not be used with --ngrok or --bore flags")
quit(QuitFailure)

## Tmux
if not existsEnv("TMUX"):
# Launch Tmux
let tmuxSession = startProcess("tmux",args=["new-session", "-s", "test","-d"], options={poUsePath})
# TODO: error handle (errorHandle?)
styledEcho(fgGreen,"[+] ",fgDefault,"Launch Tmux session")
tmuxSession.close()
else:
styledEcho(fgYellow,"[+] ",fgDefault,"Tmux is already running")

var binary: string
var script: string

## Windows
if windows:
binary ="tacos.exe"
script="socat-forker-windows.sh"
else:
binary = "tacos"
script="socat-forker.sh"

## TLS
if fileExists("server.pem"):
styledEcho(fgYellow,"[+] ",fgDefault,"server.pem already exist, do not generate certificates")
else:
styledEcho(fgGreen,"[+] ",fgDefault,"Generate certificates")
removeFile("server.key")
removeFile("server.crt")
let errOpenssl = execCmdEx("yes \"\" | openssl req -newkey rsa:2048 -nodes -keyout server.key -x509 -days 30 -out server.crt").exitCode
if errOpenssl != 0:
styledEcho(fgRed,"failed creating certificates with openssl")
quit(QuitFailure)
let errPem = execCmdEx("cat server.key server.crt >server.pem").exitCode
if errPem != 0:
styledEcho(fgRed,"failed creating server.pem")
quit(QuitFailure)

try:
copyFile(PTY4ALL&script,getCurrentDir()&"/"&script)
except OSError:
styledEcho(fgRed,"failed copying",PTY4ALL&script,"in",getCurrentDir()&"/"&script)
quit(QuitFailure)

when isMainModule:
import cligen; dispatch Wrap, help={"ngrok": "use ngrok to expose listener (can't be used with bore)",
"bore": "use bore to expose listener",
"lport": "socat listener local port",
"webport": "webport",
"gitar": "use gitar as web server (also enable gitar shortcut on remote). Python server is used otherwise",
"windows": "target windows machine",
"tmp": "if RCE is not in a writable repository, store tacos in /tmp/tacos (only for linux)",
"no-shortcut": "disable /sh endpoint of gitar (use longer command)",
}
14 changes: 14 additions & 0 deletions wrap/wrap.nimble
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Package

version = "0.0.1"
author = "ariary"
description = "Wrapper for tacos launching"
license = "Unlicense"
srcDir = "src"
bin = @["wrap"]


# Dependencies

requires "nim >= 1.6.6"
requires "cligen >= 1.5.25"

0 comments on commit 3e3baaa

Please sign in to comment.