jm33-m0 / emp3r0r

Linux/Windows post-exploitation framework made by linux user
https://infosec.exchange/@jm33
MIT License
1.26k stars 232 forks source link

reverse shell: local terminal is messed up when re-run `bash` #1

Closed jm33-m0 closed 4 years ago

jm33-m0 commented 4 years ago

https://github.com/jm33-m0/emp3r0r/blob/4ede2fd73ee933a1ceb3499a6d7274e0ffc41fd0/core/internal/cc/rshell.go#L18 On the first run, bash works mostly good, the terminal is functional. However, if we exit current bash session, and re-run bash on whatever target, the terminal is totally unusable as all characters are scambled

jm33-m0 commented 4 years ago

My solution is to restart emp3r0r, the reason why it works is still unknown

jm33-m0 commented 4 years ago

The culprit: In https://github.com/jm33-m0/emp3r0r/blob/4ede2fd73ee933a1ceb3499a6d7274e0ffc41fd0/core/internal/cc/rshell.go#L18 there are several goroutines started with reverseBash(), who are left running the background even after reverseBash has exited.

One of the goroutines that's responsible for receiving data and displaying them on os.Stdout https://github.com/jm33-m0/emp3r0r/blob/4ede2fd73ee933a1ceb3499a6d7274e0ffc41fd0/core/internal/cc/rshell.go#L70 keeps running and writing to os.Stdout, while the new bash session also has a goroutine writing to os.Stdout, making the stdout a mess eventually