WangYihang / Platypus

:hammer: A modern multiple reverse shell sessions manager written in go
http://platypus-reverse-shell.vercel.app
GNU Lesser General Public License v3.0
1.52k stars 226 forks source link

Add timeout to DataDispatcher for Termite clients, add shell_path configuration variable to Platypus server config file #99

Closed TheRemote closed 2 years ago

TheRemote commented 2 years ago

Hello again! I apologize for this being submitted to the main branch but it's a direct fix to the PR I recently submitted. I'll try to get merged into the "dev" branch for future submissions as I noticed some of the other recent ones have been getting pulled into there.

I've been using it further and it turns out if a command gets "stuck" on a Termite client the entire Platypus server gets stuck basically forever. You can still hit Ctrl+C and press "Y" twice to exit but that's about it.

This PR adds a simple go channel timeout and changes the termite DataDispatcher section (the original one is left alone, that seems to have different ways to handle timeouts as the Termite stuff seems more event driven/websocket).

result := client.System(command) <-----Stuck forever if something goes wrong

to this:

// Check for timeout
c1 := make(chan string, 1)
go func() {
    result := client.System(command)
    c1 <- result
}()
select {
case result := <-c1:
    log.Success("%s", result)
case <-time.After(3 * time.Second):
    log.Error("Command timed out %s: %s", client.FullDesc(), command)
}

The PR also adds the ShellPath configuration option. It's completely optional to have in your config file and will default to /bin/bash if it isn't.

You guys are probably better go programmers than me (I'm just copying your style and trying to stay as consistent as I can, literally never used it before but it's getting to the point where the language hardly matters and they seem to change every few years as to what is popular) so feel free to tweak them. I wasn't sure if there was anything I needed to do with the templates but since a lot of them have a mix of /bin/bash and /bin/sh already the templates are probably fine.

Thanks!

vercel[bot] commented 2 years ago

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/wangyihanger/platypus/EurskafRdbbJQ1qt6k1aTeh4pEHR
✅ Preview: https://platypus-git-fork-theremote-master-wangyihanger.vercel.app

TheRemote commented 2 years ago

So I'm not sure how to make the bot completely recheck the PR but I fixed the issue it found a couple of commits ago here (I chose to leave the API alone and keep it simple / leave that to you in case you want to change how some of it works).