Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
lparam committed Apr 2, 2015
1 parent 68818f6 commit e4d4319
Show file tree
Hide file tree
Showing 55 changed files with 8,975 additions and 161 deletions.
7 changes: 7 additions & 0 deletions .gitignore
Expand Up @@ -30,3 +30,10 @@

# Debug files
*.dSYM/

*.swp
/xsocksd
/xsocks
/xtproxy
/xforwarder
/xtunnel
9 changes: 9 additions & 0 deletions .gitmodules
@@ -0,0 +1,9 @@
[submodule "3rd/libuv"]
path = 3rd/libuv
url = https://github.com/libuv/libuv
[submodule "3rd/libsodium"]
path = 3rd/libsodium
url = https://github.com/jedisct1/libsodium
[submodule "3rd/c-ares"]
path = 3rd/c-ares
url = https://github.com/bagder/c-ares
1 change: 1 addition & 0 deletions 3rd/c-ares
Submodule c-ares added at bba4dc
1 change: 1 addition & 0 deletions 3rd/libsodium
Submodule libsodium added at f379ab
1 change: 1 addition & 0 deletions 3rd/libuv
Submodule libuv added at 334608
774 changes: 615 additions & 159 deletions LICENSE

Large diffs are not rendered by default.

186 changes: 186 additions & 0 deletions Makefile
@@ -0,0 +1,186 @@
#
# (C) Copyright 2000-2015
# Ken <ken.i18n@gmail.com>
#

MAJOR = 0
MINOR = 1
PATCH = 0
NAME = xsocks

ifdef O
ifeq ("$(origin O)", "command line")
BUILD_DIR := $(O)
endif
endif

ifneq ($(BUILD_DIR),)
saved-output := $(BUILD_DIR)

# Attempt to create a output directory.
$(shell [ -d ${BUILD_DIR} ] || mkdir -p ${BUILD_DIR})

# Verify if it was successful.
BUILD_DIR := $(shell cd $(BUILD_DIR) && /bin/pwd)
$(if $(BUILD_DIR),,$(error output directory "$(saved-output)" does not exist))
endif # ifneq ($(BUILD_DIR),)

OBJTREE := $(if $(BUILD_DIR),$(BUILD_DIR),$(CURDIR))
SRCTREE := $(CURDIR)
TOPDIR := $(SRCTREE)
export TOPDIR SRCTREE OBJTREE

#########################################################################

# CROSS_COMPILE = mips-openwrt-linux-

ifdef CROSS
CROSS_COMPILE = $(CROSS)
endif

ifdef CROSS_COMPILE
CPPFLAGS += -DCROSS_COMPILE
endif

CFLAGS = \
-Os \
-std=gnu99 \
-Wall \
$(PLATFORM_CFLAGS)

CFLAGS += -ffunction-sections -fdata-sections
#CFLAGS += -g

EXTRA_CFLAGS =

#########################################################################

CPPFLAGS += -Isrc
CPPFLAGS += -I3rd/libuv/include -I3rd/libsodium/src/libsodium/include -I3rd/c-ares/

LDFLAGS = -Wl,--gc-sections
LDFLAGS += -pthread -ldl -lrt
LDFLAGS += 3rd/libuv/.libs/libuv.a 3rd/libsodium/src/libsodium/.libs/libsodium.a

#########################################################################
include $(TOPDIR)/config.mk
#########################################################################

all: libuv libsodium c-ares xsocksd xsocks xtproxy xforwarder xtunnel

3rd/libuv/autogen.sh:
$(Q)git submodule update --init

3rd/libuv/Makefile: | 3rd/libuv/autogen.sh
$(Q)cd 3rd/libuv && ./autogen.sh && ./configure --host=$(patsubst %-,%,$(CROSS_COMPILE)) && $(MAKE)

libuv: 3rd/libuv/Makefile

3rd/libsodium/autogen.sh:
$(Q)git submodule update --init

3rd/libsodium/Makefile: | 3rd/libsodium/autogen.sh
$(Q)cd 3rd/libsodium && ./autogen.sh && ./configure --host=$(patsubst %-,%,$(CROSS_COMPILE)) && $(MAKE)

libsodium: 3rd/libsodium/Makefile

3rd/c-ares/configure:
$(Q)git submodule update --init

3rd/c-ares/Makefile: | 3rd/c-ares/configure
$(Q)cd 3rd/c-ares && ./buildconf && ./configure --host=$(patsubst %-,%,$(CROSS_COMPILE)) && $(MAKE)

c-ares: 3rd/c-ares/Makefile

xsocksd: \
src/util.o \
src/logger.o \
src/crypto.o \
src/resolver.o \
src/daemon.o \
src/signal.o \
src/consumer.o \
src/cache.o \
src/packet.o \
src/xsocksd_udprelay.o \
src/xsocksd_client.o \
src/xsocksd_remote.o \
src/xsocksd.o
$(LINK) $^ -o $(OBJTREE)/$@ $(LDFLAGS) 3rd/c-ares/.libs/libcares.a

xsocks: \
src/util.o \
src/logger.o \
src/crypto.o \
src/daemon.o \
src/signal.o \
src/consumer.o \
src/cache.o \
src/packet.o \
src/xsocks_udprelay.o \
src/xsocks_client.o \
src/xsocks_remote.o \
src/xsocks.o
$(LINK) $^ -o $(OBJTREE)/$@ $(LDFLAGS)

xtproxy: \
src/util.o \
src/logger.o \
src/crypto.o \
src/packet.o \
src/cache.o \
src/daemon.o \
src/signal.o \
src/consumer.o \
src/xtproxy_udprelay.o \
src/xtproxy_client.o \
src/xtproxy_remote.o \
src/xtproxy.o
$(LINK) $^ -o $(OBJTREE)/$@ $(LDFLAGS)

xforwarder: \
src/util.o \
src/logger.o \
src/crypto.o \
src/packet.o \
src/daemon.o \
src/signal.o \
src/consumer.o \
src/cache.o \
src/xforwarder_udprelay.o \
src/xforwarder_client.o \
src/xforwarder_remote.o \
src/xforwarder.o
$(LINK) $^ -o $(OBJTREE)/$@ $(LDFLAGS)

xtunnel: \
src/util.o \
src/logger.o \
src/crypto.o \
src/packet.o \
src/daemon.o \
src/signal.o \
src/consumer.o \
src/xtunnel_source.o \
src/xtunnel_target.o \
src/xtunnel.o
$(LINK) $^ -o $(OBJTREE)/$@ $(LDFLAGS)

clean:
@find $(OBJTREE) -type f \
\( -name '*.bak' -o -name '*~' \
-o -name '*.o' -o -name '*.tmp' \) -print \
| xargs rm -f
@rm -f xsocksd xsocks xtproxy xforwarder xtunnel

distclean: clean
$(Q)cd 3rd/libsodium && make distclean
$(Q)cd 3rd/libuv && make distclean
$(Q)cd 3rd/c-ares && make distclean

install:
$(Q)cp xsocksd /usr/local/bin
$(Q)cp xsocks /usr/local/bin
$(Q)cp xtproxy /usr/local/bin
$(Q)cp xforwarder /usr/local/bin
$(Q)cp xtunnel /usr/local/bin
129 changes: 127 additions & 2 deletions README.md
@@ -1,2 +1,127 @@
# xsocks
A secure and fast proxy for protect your network traffic
xsocks
=================
A secure and fast proxy for protect your network traffic

Features
------------
* Transparent Proxy for all tcp traffic and udp packet
* Multithreading

Installation
------------

### Linux

```bash
make && sudo make install
```

### OpenWRT

```bash
# At OpenWRT build root
cd package
git clone https://github.com/xsocks/xsocks.git

# Build the package
make package/xsocks/openwrt/compile
```

Usage
------------

### Server

```bash
xsocksd -k PASSWORD
xtunnel -m server -k PASSWORD -t TARGET:PORT
```

Multithreading:
```bash
xsocksd -k PASSWORD -c THREADS
```

Stop:
```bash
xsocksd --signal stop
```

### Client

```bash
xsocks -s SERVER:PORT -k PASSWORD
xforwarder -s SERVER:PORT -k PASSWORD -t TARGET:PORT
xtunnel -m client -k PASSWORD
```

### Transparent Proxy

Proxy all tcp traffic and udp packet transparently on gateway.

```bash
root@OpenWrt:~# xtproxy -s SERVER:PORT -k PASSWORD
```

tproxy.sh
```bash
#!/bin/sh

LISTEN_PORT=1070
IP_ROUTE_TABLE_NUMBER=100
FWMARK="0x01/0x01"
SETNAME=wall

iptables -t nat -F XSOCKS
iptables -t nat -X XSOCKS

iptables -t mangle -F XSOCKS
iptables -t mangle -X XSOCKS

iptables -t nat -N XSOCKS
iptables -t mangle -N XSOCKS

ipset -F $SETNAME
ipset -X $SETNAME
ipset -N $SETNAME iphash

### TCP
iptables -t nat -A XSOCKS -p tcp -m set --match-set $SETNAME dst -j REDIRECT --to-port $LISTEN_PORT
iptables -t nat -A PREROUTING -p tcp -j XSOCKS

### UDP
ip rule del fwmark $FWMARK table $IP_ROUTE_TABLE_NUMBER
ip route del local 0.0.0.0/0 dev lo table $IP_ROUTE_TABLE_NUMBER

ip rule add fwmark $FWMARK table $IP_ROUTE_TABLE_NUMBER
ip route add local 0.0.0.0/0 dev lo table $IP_ROUTE_TABLE_NUMBER

iptables -t mangle -A XSOCKS -p udp -m set --match-set $SETNAME dst -j TPROXY \
--on-port $LISTEN_PORT --tproxy-mark $FWMARK
iptables -t mangle -A PREROUTING -j XSOCKS
```

```bash
root@OpenWrt:~# tproxy.sh
```

```bash
root@OpenWrt:~# ipset add SETNAME IP
```

## License

Copyright (C) 2014 Ken <ken.i18n@gmail.com>

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.

0 comments on commit e4d4319

Please sign in to comment.