Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
csujedihy committed May 13, 2015
1 parent d6e8934 commit af4c32a
Show file tree
Hide file tree
Showing 33 changed files with 5,701 additions and 0 deletions.
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
CMAKE_MINIMUM_REQUIRED(VERSION 2.7)
PROJECT (proximac)
ADD_SUBDIRECTORY(src bin)
MESSAGE(STATUS "This is BINARY dir " ${proximac_BINARY_DIR})
MESSAGE(STATUS "This is SOURCE dir " ${proximac_SOURCE_DIR})
68 changes: 68 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
##Proximac [![Build Status](https://travis-ci.org/csujedihy/jedisocks.svg?branch=master)](https://travis-ci.org/csujedihy/jedisocks)


####Overview

Proximac is an open-source alternative to Proxifier. With Proximac, users can force App to use SOCKS5 proxy. The current version can only work for a single App. I hope more developers can join this project.

Note: Proximac only works on Mac OSX.

This project is still **under development**.



####How to build:
NOTE: Proximac is based on libuv. So, before compile this project, make sure [libuv](https://github.com/libuv/libuv) was successfully installed:

$ git clone https://github.com/libuv/libuv.git
$ cd libuv
$ sh autogen.sh
$ ./configure
$ make install

Then,

$ git clone https://github.com/csujedihy/jedisocks.git
$ cd build
$ cmake ..
$ make

####Usage
Modify the config file to set your proxy info and the name of process to be hooked
```
sudo chown -R root:wheel tcplognke.kext
sudo kextload tcplognke.kext
sudo ./proximac -c config.conf
```
####Example of configuration file
We use almost the same config file as shadowsocks do but add new arguments.

```
{
"process_name":"Unibox",
"local_port":1080,
"local_address":"127.0.0.1",
"proximac_listen_address":"127.0.0.1",
"proximac_port":8558
}
```
Note:

```process_name``` shoule better be the full name outputed from ```ps -e```.

```local_address``` and ```local_port``` is the ip address and the listen port of your SOCKS5 proxy, respectively.

leave ```proximac_listen_address``` and ```proximac_port``` alone because these are hardcoded in kext source.


####References
This software is partly based on projects below.

1. [Shadowsocks-libev](https://github.com/shadowsocks/shadowsocks-libev).
2. [js0n](https://github.com/quartzjer/js0n).
3. tcplognke (Apple).

####Contact:
csujedi at icloud dot com
Binary file added build/.DS_Store
Binary file not shown.
Empty file added build/.gitkeep
Empty file.
Binary file added build/bin/.DS_Store
Binary file not shown.
Binary file added src/.DS_Store
Binary file not shown.
4 changes: 4 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
SET(CMAKE_C_FLAGS "-std=gnu99 -g -O2")
SET(LOCAL_SRC_LIST local.c js0n.c utils.c jconf.c)
ADD_EXECUTABLE(proximac ${LOCAL_SRC_LIST})
TARGET_LINK_LIBRARIES(proximac uv)
29 changes: 29 additions & 0 deletions src/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleExecutable</key>
<string>tcplognke</string>
<key>CFBundleIdentifier</key>
<string>KEXT_BUNDLE_ID</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundlePackageType</key>
<string>KEXT</string>
<key>CFBundleVersion</key>
<string>KEXT_VERSION</string>
<key>OSBundleLibraries</key>
<dict>
<key>com.apple.kpi.bsd</key>
<string>8.0.0</string>
<key>com.apple.kpi.libkern</key>
<string>8.0.0</string>
#if MACH_ASSERT
<key>com.apple.kpi.unsupported</key>
<string>8.0.0</string>
#endif
</dict>
</dict>
</plist>
135 changes: 135 additions & 0 deletions src/Read Me.rtf
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
{\rtf1\mac\ansicpg10000\cocoartf824\cocoasubrtf420
{\fonttbl\f0\fnil\fcharset77 LucidaGrande-Bold;\f1\fnil\fcharset77 LucidaGrande;\f2\fnil\fcharset77 Monaco;
}
{\colortbl;\red255\green255\blue255;}
\vieww9000\viewh8400\viewkind0
\pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720

\f0\b\fs36 \cf0 Read Me About tcplognke
\fs24 \
\pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\ql\qnatural
\f1\b0 \cf0 1.3 (November 2006)\
This release of the tcplognke sample is updated to provide IPv6 support. \
\
Provided a workaround solution to a problem such that the mbuf_tag_allocate function failed occasionally for outbound mbuf chains in an AFPoverIP IPv6 connection.\
\
Read the "Network Kernel Extensions Programming Guide" for additional information regarding Network Kernel Extensions, \
<http://developer.apple.com/documentation/Darwin/Conceptual/NKEConceptual/>\
\
1.2 (22 September 2005)
\f0\b \
\
\pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\ql\qnatural
\f1\b0 \cf0 tcplognke is an update to the TCPLogger sample originally published in the NKE.pdf (Network Kernel Extension) document. The sample demonstrates the implementation of a TCP Socket filter and a tool for communications with the NKE using the supported NKE API's in Mac OS X 10.4 and greater.\
\
The tcplognke also demonstrates how the filter can swallow incoming and outgoing packets and re-inject them. The re-injection process is demonstrated from a timer routine but can be performed from subsequent calls to process incoming and outgoing packets. See the section "Known Issues" below. When swallowing packet and re-injecting them, the data_in/data_out function must be prepared to see the packet again and to recognize that a packet may have been previously processed. This sample demonstrates a technique for handling this situation.\
\
The sample queues swallowed packets into a common queue. To control access to the queue, the sample demonstrates the new fine grain locking calls now available in OS X 10.4. The network_funnel is no longer used by an NKE.\
\
A queue is also implemented to track socket information. The fine grain lock calls are used to control adding and removing queue elements.\
\pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\ql\qnatural
\cf0 \
The sample by default, builds the socket filter which swallows all incoming and outgoing packets. This behavior is controlled by the setting of the SWALLOW_PACKETS define. Setting this define to 0 will disable the packet swallowing portion of code. The "swallowed" packets are re-injected by the data_timer routine.\
\
\pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\ql\qnatural

\f0\b\fs28 \cf0 Sample Requirements
\f1\b0\fs24 \
\
The supplied Xcode project was created using Xcode v2.2 running under Mac OS X 10.4.x. The project will create a Universal Binary. The project is designed to work with Mac OS X 10.4.x. The API's used in this sample are not compatible with Mac OS X 10.3.x and earlier.\
\

\f0\b\fs28 Considerations
\f1\b0\fs24 \
\
Under OS X 10.4, the Network Kernel Extension API's are such that all filters, including interface filters, socket filters and IP filters, must be prepared to process (see) a specific packet multiple times. When a packet is swallowed by a socket filter and later re-injected, all socket filters will again be called to reprocess the packet on the re-injected path. If there are multiple socket filters, and all of the filters swallow and re-inject packets, then one of the filters will see the re-injected packet for each re-injection.\
\
When a packet is re-injected, the corresponding input or output routine will be called to process the re-injected packet. The sample demonstrates the use of the tag functions to mark a packet which has been previously "processed". The tag process provides a means to allocate a small amount of memory on a per packet basis. When calling
\f2\fs20 \CocoaLigature0 mbuf_tag_id_find
\f1\fs24 \CocoaLigature1 use a unique value, like the reverse DNS name for your company to ensure the uniqueness of the tag ID value.\
\
To conserve memory, do not allocate multiple tags for the same packet to track different events. Instead, use the allocated memory to store packet specific information - for example if your filter process swallows an outbound packet and later re-injects the packet on the inbound path, use the allocated memory to track which paths, the packet has already been processed on. The small amount of memory associated with the tag, is for the use by your code and will not be modified by the system until the mbuf_t reference is freed.\
\

\f0\b\fs28 Using tcplognke
\f1\b0\fs24 \
\
To load a Network Kernel Extension, follow these instructions after building the tcplog command line utility and the tcplognke.kext.\
\
1. Open a Terminal window and copy the kernel extension to the /tmp directory.\
$cp -R ../tcplognke/build/tcplognke.kext /tmp\
\
2. Use the kextload(8) command line utility. Currently, automatic loading is only possible for IOKit extensions and other extensions which IOKit extensions depend on. Admin privileges are required to use the kextload tool.\
$sudo kextload -v /tmp/tcplognke.kext\
\
3. Use the kextunload(8) command line utility to unload the kext when you are finished. Admin privileges are required to use the kextunload tool.\
$sudo kextunload -v /tmp/tcplognke.kext\
\
\
If there are no problems, the tcplognke.kext is loaded. Launch the Console application and set the window to watch the system log. Launch Safari or other web browser to view the tcp activity taking place with the use of the browser. \
\
Use the tcplog command line utility to tell the Kernel Extension to begin logging and to pass the logged information to the tool for display. After loading tcplognke.kext with the kextload utility, use the tcplog terminal tool to communicate with the kernel extension. Use the -h switch with the tcplog tool and it will display a list of options to use with the tool. Note, you will need admin privileges to use the tcplog tool.\
\
Use the -h switch to have tcplog provide a list of recognized switches along with a brief summary of each switch function.\
\
$./tcplog -h\
tcplog is used to control the tcplognke kernel extension\
The command takes the following options that are evaluated in order, \
and several options may be combined:\
-h display this help and exit\
-s get the current logging settings\
-Q max set size of queue for pending log entries\
-q get size of queue for pending log entries\
-L n set log of tcplognke KEXT on (n > 0) or off (n = 0)\
-E n enable log on (n > 0) or off (n = 0)\
-F flush pending log entries\
-b n use banner once (n < 0), never (n = 0), or every n lines\
-m display TCP log entries\
\
The switch settings are discussed below.\
\
-E n Enables/disables connection information logging to the system log file. n > 0 enables logging, n = 0 disables logging. Default setting - logging enabled.\
\
-m Set the tool into a mode to continuously access the Kernel Extension to read connection information as it is accumulated. Use Control-C to stop the tool.\
\
To enable logging and have the Kernel Extension pass logged information to the tool, enter the following command in a terminal window. The following assumes that the current directory is still at the location of the tcplog tool and tcplognke.kext file.\
\
$sudo ./tcplog -E 1 -m\
\
tcplog will display a single line header, then loop on blocking read calls to tcplognke.kext to receive logged information. For example, open a Safari session and navigate to different web sites and watch the information appear in the terminal window. Try enabling File Sharing on the system and accessing a volume on the test machine remotely.\
\
-Q max set size of queue for pending log entries\
-q get size of queue for pending log entries\
\
The default size of the logging queue in the Kernel Extension is 200 entries. For each TCP connection, tcplognke keeps track of the amount of data passed. When the connection is completed, the information is saved to the internal log queue as a single entry. The size of the log queue determines how many such entries will be accumulated. If the number of accumulated entries is greater than the log size, the oldest log entries are deleted first.\
\
Use tcplog to dump the accumulated entries, which will keep the entries from overflowing.\
\
You can specify a larger or smaller log queue using the -Q switch.\
\
-L n set logging in tcplognke KEXT on (n > 0) or off (n = 0)\
\
Use the -L switch to enable/disable the logging of call trace information in tcplognke. For n=1, basic call trace information is provided regarding entry into each routine. For n=2, additional connection information is provided - count of bytes sent/received across a connection, and the lifetime of the connection.\
\
-F Use to flush the internal log buffer of queued entries.\
\
Use the kextunload command line utility to unload the kext sample when finished. You can perform this command even when there is an active tcp dump session between the tcplog tool and the Kernel Extension. \
\

\f0\b\fs28 Known Issues
\f1\b0\fs24 \
\
The following are known issues with Mac OS X and the implementation of Socket NKE API's.\
\
1. The first release of OS X 10.4 ships with a known bug such that the result returned by the data_in function is ignored <rdar://problem/4073228>. This is an issue only when more than one socket filter is present since one filter might return the EJUSTRETURN error, which should cause processing for the packet to stop, but instead, the next filter is called to process the packet. This problem is fixed in System Update OS X 10.4.1.\
\
2. Under OS X 10.4 and 10.4.1, when a swallowed packet is "re-injected" from a data_in/out routine, a potential corruption can occur in the socket structure such that packet data becomes "lost" <rdar://problem/4114887>. When this problem occurs, the following message can be noted in the "system.log", "sbdrop - count not zero". If the socket filter is for HTTP traffic, the browser will appear to hang. This problem is fixed in System Update OS X 10.4.2.\
\

\f0\b\fs28 FeedBack
\f1\b0\fs24 \
\
Please send all feedback about this sample to \
http://developer.apple.com/contact/feedback.html}
80 changes: 80 additions & 0 deletions src/jconf.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
//
// jconf.c
// proximac
//
// Created by jedihy on 15-5-12.
// Copyright (c) 2015年 jedihy. All rights reserved.
//


#include "js0n.h"
#include "utils.h"
#include "jconf.h"

void read_conf(char* configfile, conf_t* conf) {
char* val = NULL;
char* configbuf = NULL;
char localport_buf[6] = {0};
char proximac_port_buf[6] = {0};
int vlen = 0;

FILE *f = fopen(configfile, "rb");
if (f == NULL) {
FATAL("Invalid config path.");
}

fseek(f, 0, SEEK_END);
long pos = ftell(f);
fseek(f, 0, SEEK_SET);

configbuf = malloc(pos + 1);
if (configbuf == NULL) {
FATAL("No enough memory.");
}

int nread = fread(configbuf, pos, 1, f);
if (!nread) {
FATAL("Failed to read the config file.");
}
fclose(f);

configbuf[pos] = '\0'; // end of string

#define JSONPARSE(str) \
val = js0n(str, strlen(str), configbuf, (int)pos, &vlen); \
if (val != NULL)

JSONPARSE("process_name") {
conf->process_name = (char*) malloc(vlen + 1);
memcpy(conf->process_name, val, vlen);
conf->process_name[vlen] = '\0';
}

JSONPARSE("proximac_listen_address") {
conf->proximac_listen_address = (char*) malloc(vlen + 1);
memcpy(conf->proximac_listen_address, val, vlen);
conf->proximac_listen_address[vlen] = '\0';
}

JSONPARSE("proximac_port") {
memcpy(proximac_port_buf, val, vlen);
conf->proximac_port = atoi(proximac_port_buf);
}

JSONPARSE("local_port") {
memcpy(localport_buf, val, vlen);
conf->localport = atoi(localport_buf);
}

JSONPARSE("local_address"){
conf->local_address = (char*)malloc(vlen + 1);
memcpy(conf->local_address, val, vlen);
conf->local_address[vlen] = '\0';
}

#undef JSONPARSE


free(configbuf);

}
27 changes: 27 additions & 0 deletions src/jconf.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//
// jconf.h
// jedisocks
//
// Created by jedihy on 15-2-25.
// Copyright (c) 2015年 jedihy. All rights reserved.
//

#ifndef jedisocks_jconf_h
#define jedisocks_jconf_h
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <strings.h>

typedef struct {
uint16_t localport;
char* local_address;
char* proximac_listen_address;
char* process_name;
uint16_t proximac_port;
int pid;
} conf_t;

extern void read_conf(char* configfile, conf_t* conf);
#endif
Loading

0 comments on commit af4c32a

Please sign in to comment.