Giter Club home page Giter Club logo

nimsocks's Introduction

nimSocks

a filtering (standalone) SOCKS proxy server and client library for nim.

Features client and server

  • (SOCKS4, SOCKS4a server only), SOCKS5
  • password auth / no auth
  • ipv4, ipv6, domain.
  • SOCKS CONNECT (no bind, no udp atm)
  • domain target white/black-listing
  • static hosts

SOCKS Compatibility Table

Socks Version TCP UDP IPv4 IPv6 Hostname
SOCKS v4
SOCKS v4a
SOCKS v5

nimSocks implementation

lib TCP connect TCP accociate UDP bind
server
client
lib SOCKS v4 SOCKS v4a SOCKS v5
server
client
auth no auth user/password
server
client

server

usage

  import nimSocks/server
  var proxy = newSocksServer()
  echo "SOCKS Proxy listens on: ", proxy.listenPort
  proxy.allowedSocksVersions = {SOCKS_V4, SOCKS_V5}
  proxy.allowedAuthMethods = {USERNAME_PASSWORD, NO_AUTHENTICATION_REQUIRED}

  ## Add a valid user / password combination
  proxy.addUser("hans", "peter")

  ## For a static host replacement:
  proxy.staticHosts.add("peter.peter", "example.org")

  asyncCheck proxy.serve()
  asyncCheck proxy.dumpThroughput()
  runForever()

black and whitelisting example filter file

(full domain match only)

for a good blacklist file use https://raw.githubusercontent.com/notracking/hosts-blocklists/master/dnscrypt-proxy/dnscrypt-proxy.blacklist.txt

files

  • whitelist.txt
  • blacklist.txt
nim-lang.org
forum.nim-lang.org

example "fancy" filter

files

  • whitelistFancy.txt
  • blacklistFancy.txt

# '#' is a comment

# all domains containing nim
con nim

# ending with
end nim-lang.org
end wikipedia.org

# exact match
eql github.org

# startswith
sta foo.baa

if there are whitelist* entries the blacklist* gets skipped!

static hosts

fill the staticHosts table to always resolve to given ip/dns

#...
proxy.staticHosts.add("foo.loc", "example.org")
proxy.staticHosts.add("baa.loc", "192.168.1.1")
#...

client

the client can "upgrade" your socket.

var sock = waitFor asyncnet.dial("127.0.0.1", Port 1080 ) # dial to the socks server 
assert true == waitFor sock.doSocksHandshake(
    username="username", 
    password="password", 
    methods={NO_AUTHENTICATION_REQUIRED, USERNAME_PASSWORD} # the "best" auth supported gets choosen by the server!
    ) 
assert true == waitFor sock.doSocksConnect("example.org", Port 80) # instruct the proxy to connect to target host (by tcp)

# Then do normal socket operations
sock.send("FOO")

proxy hopping

you could easily do "proxy hopping", by letting the first SOCKS server connect to the next, then do handshake, connect, etc.

var sock = waitFor asyncnet.dial("firstSocks.loc", Port 1080 )
assert true == waitFor sock.doSocksHandshake(methods={NO_AUTHENTICATION_REQUIRED})
assert true == waitFor sock.doSocksConnect("secondSocks.loc", Port 1080) 

assert true == waitFor sock.doSocksHandshake(methods={NO_AUTHENTICATION_REQUIRED})
assert true == waitFor sock.doSocksConnect("mytarget.loc", Port 80) 

sock.send("FOO") # from here we speak to "mytarget.loc"
sock.close() # will destroy the whole tunnel

random examples

$ ncat --proxy 127.0.0.1:1080 --proxy-type socks5 --proxy-auth hans:peter  2a02:bbb:aaa:9daa:ff11:a4ff:aaaa:bbbb 9090
$ curl --socks5-basic --socks5 hans:[email protected]:1080 google.de

nimsocks's People

Contributors

enthus1ast avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

nimsocks's Issues

Client.nim type mismatch

Any thoughts/solutions to this?

/nimSocks/client.nim(34, 19) template/generic instantiation of `async` from here
/nimSocks/client.nim(53, 41) Error: type mismatch: got <UserPasswordStatus, byte>
but expected one of:
proc `==`[Enum: enum](x, y: Enum): bool
  first type mismatch at position: 2
  required type for y: Enum: enum
  but expression 'byte(SUCCEEDED)' is of type: byte
35 other mismatching symbols have been suppressed; compile with --showAllMismatches:on to see them

expression: socksUserPasswordResponse.status == byte(SUCCEEDED)

compile errors

Nim Compiler Version 0.20.2 [MacOSX: amd64]

nim compile --run server.nim
Hint: used config file '/usr/local/Cellar/nim/0.20.2/nim/config/nim.cfg' [Conf]
...
/nim/nimSocks/nimSocks/server.nim(144, 77) template/generic instantiation of async from here
/nim/nimSocks/nimSocks/server.nim(211, 5) Error: invalid else, all cases are already covered

Help the nim novice, please

How to install

This may be weird, but running the command "nimble install nimSocks" gives the "package not found" error.

What is the method of installation?

randomly crashes on send with "File descriptor not registered"

Handling command: succeed
Handling command: succeed
connection from: 127.0.0.1
socks4
host: 0.0.0.1
socks4a
vid.example.com
Handling command: succeed
Traceback (most recent call last)
server.nim(442)          server
asyncdispatch.nim(1010)  runForever
asyncdispatch.nim(1045)  poll
asyncdispatch.nim(179)   processPendingCallbacks
asyncmacro.nim(34)       cb0
server.nim(137)          pumpIter
asyncmacro.nim(393)      send
asyncmacro.nim(34)       cb0
asyncnet.nim(426)        sendIter
asyncdispatch.nim(1274)  send
asyncdispatch.nim(1130)  send
asyncdispatch.nim(982)   addWrite
[[reraised from:
server.nim(442)          server
asyncdispatch.nim(1010)  runForever
asyncdispatch.nim(1045)  poll
asyncdispatch.nim(179)   processPendingCallbacks
asyncmacro.nim(34)       cb0
asyncmacro.nim           pumpIter
asyncfutures.nim(243)    read
]]
[[reraised from:
server.nim(442)          server
asyncdispatch.nim(1010)  runForever
asyncdispatch.nim(1045)  poll
asyncdispatch.nim(179)   processPendingCallbacks
asyncfutures.nim(288)    :anonymous
]]
Error: unhandled exception: File descriptor not registered.
  send's lead up to read of failed Future:
    Traceback (most recent call last)
    server.nim(442)          server
    asyncdispatch.nim(1010)  runForever
    asyncdispatch.nim(1045)  poll
    asyncdispatch.nim(179)   processPendingCallbacks

asyncmacro.nim(34)       cb0
asyncnet.nim(426)        sendIter
asyncdispatch.nim(1274)  send
asyncdispatch.nim(1130)  send
asyncdispatch.nim(982)   addWrite
[[reraised from:
server.nim(442)          server
asyncdispatch.nim(1010)  runForever
asyncdispatch.nim(1045)  poll
asyncdispatch.nim(179)   processPendingCallbacks
asyncmacro.nim(34)       cb0
asyncmacro.nim           pumpIter
asyncfutures.nim(243)    read
]]
[[reraised from:
server.nim(442)          server
asyncdispatch.nim(1010)  runForever
asyncdispatch.nim(1045)  poll
asyncdispatch.nim(179)   processPendingCallbacks
asyncfutures.nim(288)    :anonymous
]]
Error: unhandled exception: File descriptor not registered.
  send's lead up to read of failed Future:
    Traceback (most recent call last)
    server.nim(442)          server
    asyncdispatch.nim(1010)  runForever
    asyncdispatch.nim(1045)  poll
    asyncdispatch.nim(179)   processPendingCallbacks
    asyncmacro.nim(34)       cb0
    server.nim(137)          pumpIter
    asyncmacro.nim(393)      send
    asyncmacro.nim(34)       cb0
    asyncnet.nim(426)        sendIter
    asyncdispatch.nim(1274)  send
    asyncdispatch.nim(1130)  send
    asyncdispatch.nim(982)   addWrite
  pump's lead up to read of failed Future:
    Traceback (most recent call last)
    server.nim(442)          server
    asyncdispatch.nim(1010)  runForever
    asyncdispatch.nim(1045)  poll
    asyncdispatch.nim(179)   processPendingCallbacks
    asyncmacro.nim(34)       cb0
    server.nim(137)          pumpIter
    asyncmacro.nim(393)      send
    asyncmacro.nim(34)       cb0
    asyncnet.nim(426)        sendIter
    asyncdispatch.nim(1274)  send
    asyncdispatch.nim(1130)  send
    asyncdispatch.nim(982)   addWrite
    [[reraised from:
    server.nim(442)          server
    asyncdispatch.nim(1010)  runForever
    asyncdispatch.nim(1045)  poll
    asyncdispatch.nim(179)   processPendingCallbacks
    asyncmacro.nim(34)       cb0
    asyncmacro.nim           pumpIter
    asyncfutures.nim(243)    read
    ]] [ValueError]

Block insecure HTTP using regex on full path

Apple uses insecure (no TLS) OCSP and it'd be great to block only some of those.
Since the whole URL (not just FQDN) is available, a regex would be suitable for such filtering.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.