diff --git a/src/HttpProxy.hs b/src/HttpProxy.hs index ada3ebf..d516a15 100644 --- a/src/HttpProxy.hs +++ b/src/HttpProxy.hs @@ -11,14 +11,10 @@ import ClassyPrelude import qualified Data.ByteString.Char8 as BC import Control.Monad.Except -import qualified Data.Conduit.Network.TLS as N import qualified Data.Streaming.Network as N import qualified Data.ByteString.Base64 as B64 import Network.Socket (HostName, PortNumber) -import qualified Network.Socket as N hiding (recv, recvFrom, send, - sendTo) -import qualified Network.Socket.ByteString as N import Logger import Types diff --git a/src/Protocols.hs b/src/Protocols.hs index 653541b..a534716 100644 --- a/src/Protocols.hs +++ b/src/Protocols.hs @@ -6,15 +6,13 @@ module Protocols where import ClassyPrelude import Control.Concurrent (forkFinally, threadDelay) import qualified Data.HashMap.Strict as H -import System.IO hiding (hSetBuffering, hGetBuffering) import qualified Data.ByteString.Char8 as BC import qualified Data.Streaming.Network as N import Network.Socket (HostName, PortNumber) -import qualified Network.Socket as N hiding (recv, recvFrom, send, - sendTo) +import qualified Network.Socket as N import qualified Network.Socket.ByteString as N import Data.Binary (decode, encode) @@ -123,7 +121,7 @@ runSocks5Server :: Socks5.ServerSettings -> TunnelSettings -> (TunnelSettings -> runSocks5Server socksSettings@Socks5.ServerSettings{..} cfg inner = do info $ "Starting socks5 proxy " <> show socksSettings - N.runTCPServer (N.serverSettingsTCP (fromIntegral listenOn) (fromString bindOn)) $ \cnx -> do + _ <- N.runTCPServer (N.serverSettingsTCP (fromIntegral listenOn) (fromString bindOn)) $ \cnx -> do -- Get the auth request and response with a no Auth authRequest <- decode . fromStrict <$> N.appRead cnx :: IO Socks5.RequestAuth debug $ "Socks5 authentification request " <> show authRequest diff --git a/src/Socks5.hs b/src/Socks5.hs index 1db691b..4704ccd 100644 --- a/src/Socks5.hs +++ b/src/Socks5.hs @@ -12,7 +12,6 @@ import ClassyPrelude import Data.Binary import Data.Binary.Get import Data.Binary.Put -import qualified Data.ByteString as BC import qualified Data.ByteString.Char8 as BC8 import Data.Either import qualified Data.Text as T @@ -21,10 +20,6 @@ import qualified Data.Text.Encoding as E import Network.Socket (HostName, PortNumber) import Numeric (showHex) -import Control.Monad.Except (MonadError) -import qualified Data.Streaming.Network as N - - socksVersion :: Word8 socksVersion = 0x05 @@ -145,8 +140,8 @@ instance Binary Request where host <- if opCode == 0x03 then do - length <- fromIntegral <$> getWord8 - fromRight T.empty . E.decodeUtf8' <$> replicateM length getWord8 + nbWords <- fromIntegral <$> getWord8 + fromRight T.empty . E.decodeUtf8' <$> replicateM nbWords getWord8 else do ipv4 <- replicateM 4 getWord8 :: Get [Word8] let ipv4Str = T.intercalate "." $ fmap (tshow . fromEnum) ipv4 @@ -216,13 +211,13 @@ instance Binary Response where version <- fromIntegral <$> getWord8 guard(version == fromIntegral socksVersion) ret <- toEnum . min maxBound . fromIntegral <$> getWord8 - getWord8 -- RESERVED + _ <- getWord8 -- RESERVED opCode <- fromIntegral <$> getWord8 -- Type guard(opCode == 0x03 || opCode == 0x01) host <- if opCode == 0x03 then do - length <- fromIntegral <$> getWord8 - fromRight T.empty . E.decodeUtf8' <$> replicateM length getWord8 + nbWords <- fromIntegral <$> getWord8 + fromRight T.empty . E.decodeUtf8' <$> replicateM nbWords getWord8 else do ipv4 <- replicateM 4 getWord8 :: Get [Word8] let ipv4Str = T.intercalate "." $ fmap (tshow . fromEnum) ipv4 diff --git a/src/Tunnel.hs b/src/Tunnel.hs index 8ff68b7..d6002bb 100644 --- a/src/Tunnel.hs +++ b/src/Tunnel.hs @@ -17,8 +17,7 @@ import qualified Data.Conduit.Network.TLS as N import qualified Data.Streaming.Network as N import Network.Socket (HostName, PortNumber) -import qualified Network.Socket as N hiding (recv, recvFrom, - send, sendTo) +import qualified Network.Socket as N import qualified Network.Socket.ByteString as N import qualified Network.Socket.ByteString.Lazy as NL @@ -28,7 +27,6 @@ import qualified Network.WebSockets.Stream as WS import Control.Monad.Except import qualified Network.Connection as NC -import System.IO (IOMode (ReadWriteMode)) import qualified Data.ByteString.Base64 as B64 @@ -36,7 +34,6 @@ import Types import Protocols import qualified Socks5 import Logger -import qualified Credentials @@ -227,7 +224,7 @@ runTunnelingServer endPoint@(host, port) isAllowed = do serverEventLoop :: N.SockAddr -> ((ByteString, Int) -> Bool) -> WS.PendingConnection -> IO () serverEventLoop sClient isAllowed pendingConn = do let path = fromPath . WS.requestPath $ WS.pendingRequest pendingConn - let forwardedFor = filter (\(header,val) -> header == "x-forwarded-for") $ WS.requestHeaders $ WS.pendingRequest pendingConn + let forwardedFor = filter (\(header, _) -> header == "x-forwarded-for") $ WS.requestHeaders $ WS.pendingRequest pendingConn info $ "NEW incoming connection from " <> show sClient <> " " <> show forwardedFor case path of Nothing -> info "Rejecting connection" >> WS.rejectRequest pendingConn "Invalid tunneling information"