From fe1c17bac1075763d3fa37e361db203656781d56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Romain=20G=C3=89RARD?= Date: Wed, 6 Jun 2018 00:46:02 +0200 Subject: [PATCH] Sock5 proxy: Add support for IPV4 connection method Former-commit-id: 2b786bdfca8f7c4f13be5d3f2fbffabb3bb6c1ff Former-commit-id: 79521d28ef7ec78f037a39d345d0b7caa6a21aad [formerly 4f529c3bf32ec3d058f0437a4ed56cd530bb0380] [formerly 5fe75721d4197c31274853956429750a8a6bae34 [formerly b985c09e33290e80db92edd3a6688d56df463ab4 [formerly d19a7a5290bd4676d018052c1ba82ff0a2f7c53c] [formerly d19a7a5290bd4676d018052c1ba82ff0a2f7c53c [formerly d19a7a5290bd4676d018052c1ba82ff0a2f7c53c [formerly 2a811ddc94f163f29e7b13c5c0209edaa0ba94dd]]]]] Former-commit-id: ac4e18a935137eac85d7a1fcb03aff223ce9a413 [formerly c6a4d21c51709b03cab6c6de9934188da49028e7] Former-commit-id: 736cb733cf4083f0d6e98f4bd4315119b65ac994 Former-commit-id: 3639f8c1a181eed16f4d642745cbe19725834784 Former-commit-id: d0d2d9ea134579057a321900564f210e35e85a42 Former-commit-id: afc68a28fd773821f36742d9c561f1df8c43f66b [formerly 441a3c84970aba955d980519a74178e4dbe64ec1] Former-commit-id: 08598a77acb35f6e71f6c5b8aabd905348ec9ea8 --- src/Socks5.hs | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/Socks5.hs b/src/Socks5.hs index 21cd282..933ff22 100644 --- a/src/Socks5.hs +++ b/src/Socks5.hs @@ -128,13 +128,20 @@ instance Binary Request where cmd <- get :: Get Command _ <- getWord8 -- RESERVED - opCode <- fromIntegral <$> getWord8 -- DOMAINNAME - guard (opCode == 0x03) + opCode <- fromIntegral <$> getWord8 -- Addr type, we support only ipv4 and domainame + guard (opCode == 0x03 || opCode == 0x01) -- DOMAINNAME OR IPV4 + + host <- if opCode == 0x03 + then do + length <- fromIntegral <$> getWord8 + host <- either (const T.empty) id . E.decodeUtf8' <$> replicateM length getWord8 + return host + else do + ipv4 <- replicateM 4 getWord8 :: Get [Word8] + let ipv4Str = T.intercalate "." $ fmap (tshow . fromEnum) ipv4 + return ipv4Str - length <- fromIntegral <$> getWord8 - host <- either (const T.empty) id . E.decodeUtf8' <$> replicateM length getWord8 guard (not $ null host) - port <- fromIntegral <$> getWord16be return Request