-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshell.hs
More file actions
41 lines (32 loc) · 1.13 KB
/
shell.hs
File metadata and controls
41 lines (32 loc) · 1.13 KB
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
{-# LANGUAGE OverloadedStrings #-}
import Data.Conduit
import Data.Conduit.Network
import Control.Monad.Trans
import Control.Concurrent.Async
import Data.Streaming.Network.Internal (HostPreference(Host))
import qualified Data.ByteString as BS
import qualified Data.ByteString.Char8 as BS8
import Data.List.Split
import System.Environment
import Crypto
printC :: Sink BS.ByteString IO ()
printC = awaitForever $ \d ->
liftIO $ print d
main = do
args <- getArgs
(addr, port, p) <- return $ case args of
[x, y] ->
if ':' `elem` x
then let [addr, port] = splitOn ":" x
in (addr, read port, y)
else (x, 7001, y)
_ -> error "usage: shell IP:port password"
let pwd = BS8.pack p
BS.putStr "> "
s <- BS.getLine
runTCPClient (clientSettings port $ BS8.pack addr) $ \server -> do
let cmd = BS.concat [s, ";"]
serverSink = encryptAES256CFB pwd =$= appSink server
serverSource = appSource server =$= decryptAES256CFB pwd
concurrently (yield cmd $$ serverSink) (serverSource $$ printC)
main