mirror of
https://github.com/haad/proxychains.git
synced 2026-09-14 11:05:48 +05:00
Compare commits
No commits in common. "master" and "proxychains-4.0" have entirely different histories.
master
...
proxychain
24
.github/ISSUE_TEMPLATE/bug_report.md
vendored
24
.github/ISSUE_TEMPLATE/bug_report.md
vendored
@ -1,24 +0,0 @@
|
|||||||
---
|
|
||||||
name: Bug report
|
|
||||||
about: Create a report to help us improve
|
|
||||||
title: ''
|
|
||||||
labels: ''
|
|
||||||
assignees: ''
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
**Describe the bug**
|
|
||||||
A clear and concise description of what the bug is.
|
|
||||||
|
|
||||||
**To Reproduce**
|
|
||||||
Steps to reproduce the behavior:
|
|
||||||
1. Run command
|
|
||||||
|
|
||||||
**Expected behavior**
|
|
||||||
A clear and concise description of what you expected to happen.
|
|
||||||
|
|
||||||
**Screenshots**
|
|
||||||
If applicable, add screenshots to help explain your problem.
|
|
||||||
|
|
||||||
**Additional context**
|
|
||||||
Add any other context about the problem here.
|
|
||||||
20
.github/ISSUE_TEMPLATE/feature_request.md
vendored
20
.github/ISSUE_TEMPLATE/feature_request.md
vendored
@ -1,20 +0,0 @@
|
|||||||
---
|
|
||||||
name: Feature request
|
|
||||||
about: Suggest an idea for this project
|
|
||||||
title: ''
|
|
||||||
labels: ''
|
|
||||||
assignees: ''
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
**Is your feature request related to a problem? Please describe.**
|
|
||||||
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
|
|
||||||
|
|
||||||
**Describe the solution you'd like**
|
|
||||||
A clear and concise description of what you want to happen.
|
|
||||||
|
|
||||||
**Describe alternatives you've considered**
|
|
||||||
A clear and concise description of any alternative solutions or features you've considered.
|
|
||||||
|
|
||||||
**Additional context**
|
|
||||||
Add any other context or screenshots about the feature request here.
|
|
||||||
55
.github/workflows/buildci.yml
vendored
55
.github/workflows/buildci.yml
vendored
@ -1,55 +0,0 @@
|
|||||||
name: Makefile CI
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches: [ "master" ]
|
|
||||||
pull_request:
|
|
||||||
branches: [ "master" ]
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
build-linux-ubuntu:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v3
|
|
||||||
|
|
||||||
- name: configure
|
|
||||||
run: ./configure
|
|
||||||
|
|
||||||
- name: Build Proxychains
|
|
||||||
run: make
|
|
||||||
|
|
||||||
- name: Run Proxychains
|
|
||||||
run: ./proxychains4 -v
|
|
||||||
|
|
||||||
- name: Run tests
|
|
||||||
run: ./src/proxychains -f dist/proxychains.conf on
|
|
||||||
|
|
||||||
# - name: Run tests
|
|
||||||
# run: ./src/proxychains -f dist/proxychains.conf curl -o /dev/null -v https://sme.sk
|
|
||||||
|
|
||||||
# - name: Run tests
|
|
||||||
# run: ./src/proxychains -f dist/proxychains.conf ping -c 1 sme.sk
|
|
||||||
build-macos:
|
|
||||||
runs-on: macos-latest
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v3
|
|
||||||
|
|
||||||
- name: configure
|
|
||||||
run: ./configure
|
|
||||||
|
|
||||||
- name: Build Proxychains
|
|
||||||
run: make
|
|
||||||
|
|
||||||
- name: Run Proxychains
|
|
||||||
run: ./proxychains4 -v
|
|
||||||
|
|
||||||
- name: Run tests
|
|
||||||
run: ./src/proxychains -f dist/proxychains.conf on
|
|
||||||
|
|
||||||
# - name: Run tests
|
|
||||||
# run: ./src/proxychains -f dist/proxychains.conf curl -o /dev/null -v https://sme.sk
|
|
||||||
|
|
||||||
# - name: Run tests
|
|
||||||
# run: ./src/proxychains -f dist/proxychains.conf ping -t 1 sme.sk
|
|
||||||
|
|
||||||
|
|
||||||
31
.github/workflows/stale.yml
vendored
31
.github/workflows/stale.yml
vendored
@ -1,31 +0,0 @@
|
|||||||
# This workflow warns and then closes issues and PRs that have had no activity for a specified amount of time.
|
|
||||||
#
|
|
||||||
# You can adjust the behavior by modifying this file.
|
|
||||||
# For more information, see:
|
|
||||||
# https://github.com/actions/stale
|
|
||||||
name: Mark stale issues and pull requests
|
|
||||||
|
|
||||||
on:
|
|
||||||
schedule:
|
|
||||||
- cron: '24 3 * * *'
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
stale:
|
|
||||||
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
permissions:
|
|
||||||
issues: write
|
|
||||||
pull-requests: write
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- uses: actions/stale@v5
|
|
||||||
with:
|
|
||||||
days-before-stale: 90
|
|
||||||
days-before-close: 120
|
|
||||||
repo-token: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
stale-issue-message: 'Stale issue message'
|
|
||||||
stale-pr-message: 'Stale pull request message'
|
|
||||||
stale-issue-label: 'no-issue-activity'
|
|
||||||
exempt-issue-labels: 'docu,roadmap,bug,possible-feature'
|
|
||||||
stale-pr-label: 'no-pr-activity'
|
|
||||||
exempt-pr-labels: 'feature'
|
|
||||||
29
.github/workflows/super-linter.yml
vendored
29
.github/workflows/super-linter.yml
vendored
@ -1,29 +0,0 @@
|
|||||||
# This workflow executes several linters on changed files based on languages used in your code base whenever
|
|
||||||
# you push a code or open a pull request.
|
|
||||||
#
|
|
||||||
# You can adjust the behavior by modifying this file.
|
|
||||||
# For more information, see:
|
|
||||||
# https://github.com/github/super-linter
|
|
||||||
name: Lint Code Base
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches: [ "master" ]
|
|
||||||
pull_request:
|
|
||||||
branches: [ "master" ]
|
|
||||||
jobs:
|
|
||||||
run-lint:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- name: Checkout code
|
|
||||||
uses: actions/checkout@v3
|
|
||||||
with:
|
|
||||||
# Full git history is needed to get a proper list of changed files within `super-linter`
|
|
||||||
fetch-depth: 0
|
|
||||||
|
|
||||||
- name: Lint Code Base
|
|
||||||
uses: github/super-linter@v4
|
|
||||||
env:
|
|
||||||
VALIDATE_ALL_CODEBASE: false
|
|
||||||
DEFAULT_BRANCH: "master"
|
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
5
.gitignore
vendored
5
.gitignore
vendored
@ -4,11 +4,8 @@
|
|||||||
*.lo
|
*.lo
|
||||||
.deps/
|
.deps/
|
||||||
.libs/
|
.libs/
|
||||||
.*
|
|
||||||
src/*.d
|
|
||||||
# Autoconf stuff
|
# Autoconf stuff
|
||||||
libtool
|
libtool
|
||||||
config.*
|
config.*
|
||||||
stamp-h
|
stamp-h
|
||||||
proxychains4
|
|
||||||
*.dylib
|
|
||||||
|
|||||||
15
AUTHORS
15
AUTHORS
@ -1,16 +1,5 @@
|
|||||||
original code
|
|
||||||
N3E7CR34TUR3.
|
N3E7CR34TUR3.
|
||||||
http://proxychains.sourceforge.net
|
|
||||||
netcreature@users.sourceforge.net
|
|
||||||
|
|
||||||
main.c, remote-dns, thread safety, bugfixes, build system, cleanups
|
web site: proxychains.sourceforge.net
|
||||||
rofl0r.
|
email: netcreature@users.sourceforge.net
|
||||||
https://github.com/rofl0r/proxychains
|
|
||||||
|
|
||||||
localnet, bugfixes, macos x support, bsd support, packaging
|
|
||||||
haad.
|
|
||||||
https://github.com/haad/proxychains
|
|
||||||
|
|
||||||
localnet-port, bugfixes
|
|
||||||
jianing yang.
|
|
||||||
https://github.com/jianingy/proxychains
|
|
||||||
|
|||||||
21
ChangeLog
21
ChangeLog
@ -1,27 +1,6 @@
|
|||||||
ProxyChains version history (public releases)
|
ProxyChains version history (public releases)
|
||||||
====================
|
====================
|
||||||
|
|
||||||
ver 4.2
|
|
||||||
* Introduce BSD support make proxychains available on (NetBSD, FreeBSD ,OpenBSD and DragonFlyBSD)
|
|
||||||
* Update pkgsrc-wip proxychains package to 4.2.0 release and make easy to install and use
|
|
||||||
proxychains
|
|
||||||
-------------------------------------------------------------------------
|
|
||||||
|
|
||||||
ver 4.1
|
|
||||||
* Mac OS X support, create install script.
|
|
||||||
* thread-safe fixes by @rofl0r
|
|
||||||
|
|
||||||
-------------------------------------------------------------------------
|
|
||||||
|
|
||||||
ver 4.0
|
|
||||||
|
|
||||||
changed:
|
|
||||||
* Add a lot of fixes
|
|
||||||
* localnet-patch
|
|
||||||
* remote-dns
|
|
||||||
* thread-safe
|
|
||||||
-------------------------------------------------------------------------
|
|
||||||
|
|
||||||
ver 3.1
|
ver 3.1
|
||||||
|
|
||||||
changed:
|
changed:
|
||||||
|
|||||||
13
INSTALL
Normal file
13
INSTALL
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
ProxyChains ver 3.1 Installation
|
||||||
|
=======================
|
||||||
|
|
||||||
|
If you have installed other ver of proxychains "make uninstall" before installing this distribution
|
||||||
|
|
||||||
|
unpack the .tar.gz , 'cd' to distribution directory and
|
||||||
|
run following commands (as root)
|
||||||
|
-------------------------------------
|
||||||
|
./configure
|
||||||
|
make
|
||||||
|
make install
|
||||||
|
-------------------------------------
|
||||||
|
that's all
|
||||||
59
Makefile
59
Makefile
@ -8,84 +8,55 @@
|
|||||||
prefix = /usr/local
|
prefix = /usr/local
|
||||||
includedir = $(prefix)/include
|
includedir = $(prefix)/include
|
||||||
libdir = $(prefix)/lib
|
libdir = $(prefix)/lib
|
||||||
confdir = $(prefix)/etc
|
|
||||||
datadir = $(prefix)/share
|
|
||||||
|
|
||||||
exec_prefix = $(prefix)
|
exec_prefix = $(prefix)
|
||||||
bindir = $(exec_prefix)/bin
|
bindir = $(exec_prefix)/bin
|
||||||
zshcompdir = $(datadir)/zsh/site-functions
|
|
||||||
|
|
||||||
SRCS = $(sort $(wildcard src/*.c))
|
SRCS = $(sort $(wildcard src/*.c))
|
||||||
OBJS = $(SRCS:.c=.o)
|
OBJS = $(SRCS:.c=.o)
|
||||||
LOBJS = src/core.o src/common.o src/libproxychains.o
|
LOBJS = src/core.o src/libproxychains.o
|
||||||
DEPS = $(OBJS:.o=.d)
|
|
||||||
|
|
||||||
CCFLAGS = -MD -Wall -O2 -g -std=c99 -D_GNU_SOURCE -pipe -DTHREAD_SAFE -Werror
|
CFLAGS += -Wall -O0 -g -std=c99 -D_GNU_SOURCE -pipe -DTHREAD_SAFE
|
||||||
LDFLAGS = -shared -fPIC
|
LDFLAGS = -shared -fPIC -ldl -lpthread
|
||||||
INC =
|
INC =
|
||||||
PIC = -fPIC
|
PIC = -fPIC
|
||||||
AR = $(CROSS_COMPILE)ar
|
AR = $(CROSS_COMPILE)ar
|
||||||
RANLIB = $(CROSS_COMPILE)ranlib
|
RANLIB = $(CROSS_COMPILE)ranlib
|
||||||
|
|
||||||
LD_SET_SONAME = -Wl
|
LDSO_PATHNAME = libproxychains4.so
|
||||||
INSTALL_FLAGS = -D -m
|
|
||||||
|
|
||||||
-include config.mak
|
|
||||||
|
|
||||||
SHARED_LIBS = $(LDSO_PATHNAME)
|
SHARED_LIBS = $(LDSO_PATHNAME)
|
||||||
ALL_LIBS = $(SHARED_LIBS)
|
ALL_LIBS = $(SHARED_LIBS)
|
||||||
PXCHAINS = proxychains4
|
PXCHAINS = proxychains4
|
||||||
ALL_TOOLS = $(PXCHAINS)
|
ALL_TOOLS = $(PXCHAINS)
|
||||||
|
|
||||||
CCFLAGS+=$(USER_CFLAGS) $(OS_CFLAGS)
|
-include config.mak
|
||||||
LDFLAGS+=$(USER_LDFLAGS) $(OS_LDFLAGS)
|
|
||||||
CXXFLAGS+=$(CCFLAGS) $(USER_CFLAGS) $(OS_CFLAGS)
|
|
||||||
CFLAGS_MAIN=-DLIB_DIR=\"$(libdir)\" -DINSTALL_PREFIX=\"$(prefix)\" -DDLL_NAME=\"$(LDSO_PATHNAME)\" -DSYSCONFDIR=\"$(confdir)\"
|
|
||||||
|
|
||||||
UNAME_S := $(shell uname -s)
|
CFLAGS+=$(USER_CFLAGS)
|
||||||
ifeq ($(UNAME_S),Linux)
|
CFLAGS_MAIN=-DLIB_DIR=\"$(libdir)\"
|
||||||
LDSO_PATHNAME = libproxychains.$(LDSO_SUFFIX)
|
|
||||||
LDSO_SUFFIX = so.4
|
|
||||||
endif
|
|
||||||
ifeq ($(UNAME_S),Darwin)
|
|
||||||
LDSO_PATHNAME = libproxychains4.$(LDSO_SUFFIX)
|
|
||||||
LDSO_SUFFIX = dylib
|
|
||||||
endif
|
|
||||||
|
|
||||||
|
|
||||||
all: $(ALL_LIBS) $(ALL_TOOLS)
|
all: $(ALL_LIBS) $(ALL_TOOLS)
|
||||||
|
|
||||||
#install: $(ALL_LIBS:lib/%=$(DESTDIR)$(libdir)/%) $(DESTDIR)$(LDSO_PATHNAME)
|
#install: $(ALL_LIBS:lib/%=$(DESTDIR)$(libdir)/%) $(DESTDIR)$(LDSO_PATHNAME)
|
||||||
install: install-exec install-config install-zsh-completion
|
install:
|
||||||
|
install -D -m 755 $(ALL_TOOLS) $(bindir)/
|
||||||
install-exec:
|
install -D -m 644 $(ALL_LIBS) $(libdir)/
|
||||||
install -d $(DESTDIR)/$(bindir) $(DESTDIR)/$(libdir) $(DESTDIR)/$(confdir) $(DESTDIR)/$(includedir)
|
install -D -m 644 src/proxychains.conf $(prefix)/etc/
|
||||||
install $(INSTALL_FLAGS) 755 $(ALL_TOOLS) src/proxychains src/proxyresolv $(DESTDIR)/$(bindir)/
|
|
||||||
install $(INSTALL_FLAGS) 644 $(ALL_LIBS) $(DESTDIR)/$(libdir)/
|
|
||||||
|
|
||||||
install-config:
|
|
||||||
install -d $(DESTDIR)/$(confdir)
|
|
||||||
install $(INSTALL_FLAGS) 644 src/proxychains.conf $(DESTDIR)/$(confdir)/
|
|
||||||
|
|
||||||
install-zsh-completion:
|
|
||||||
install -d $(DESTDIR)/$(zshcompdir)
|
|
||||||
install $(INSTALL_FLAGS) 644 completions/zsh/_proxychains4 -t $(DESTDIR)/$(zshcompdir)
|
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f $(ALL_LIBS)
|
rm -f $(ALL_LIBS)
|
||||||
rm -f $(ALL_TOOLS)
|
rm -f $(ALL_TOOLS)
|
||||||
rm -f $(OBJS)
|
rm -f $(OBJS)
|
||||||
rm -f $(DEPS)
|
|
||||||
|
|
||||||
%.o: %.c
|
%.o: %.c
|
||||||
$(CC) $(CCFLAGS) $(CFLAGS_MAIN) $(INC) $(PIC) -c -o $@ $<
|
$(CC) $(CFLAGS) $(CFLAGS_MAIN) $(INC) $(PIC) -c -o $@ $<
|
||||||
|
|
||||||
$(LDSO_PATHNAME): $(LOBJS)
|
$(LDSO_PATHNAME): $(LOBJS)
|
||||||
$(CC) $(LDFLAGS) $(LD_SET_SONAME)$(LDSO_PATHNAME) -o $@ $(LOBJS)
|
$(CC) $(LDFLAGS) -Wl,-soname=$(LDSO_PATHNAME) -o $@ $(LOBJS)
|
||||||
|
|
||||||
$(ALL_TOOLS): $(OBJS)
|
$(ALL_TOOLS): $(OBJS)
|
||||||
$(CC) src/main.o src/common.o -o $(PXCHAINS)
|
$(CC) src/main.o -o $(PXCHAINS)
|
||||||
|
|
||||||
.PHONY: all clean install install-exec install-config install-zsh-completion
|
|
||||||
|
|
||||||
-include $(DEPS)
|
.PHONY: all clean install
|
||||||
|
|||||||
95
README
Normal file
95
README
Normal file
@ -0,0 +1,95 @@
|
|||||||
|
ProxyChains ver 4.0 README
|
||||||
|
==========================
|
||||||
|
|
||||||
|
*********** ATTENTION ***********
|
||||||
|
|
||||||
|
this program works only on dynamically linked programs.
|
||||||
|
also both proxychains and the program to call must use
|
||||||
|
the same dynamic linker (i.e. same libc)
|
||||||
|
|
||||||
|
*********************************
|
||||||
|
|
||||||
|
|
||||||
|
This is Unix version only.
|
||||||
|
|
||||||
|
How to mess with sources - How to Install : read INSTALL !!!!!!
|
||||||
|
|
||||||
|
This program forces any tcp connection made by any given tcp client
|
||||||
|
to follow through proxy (or proxy chain). It is a kind of proxifier.
|
||||||
|
It acts like sockscap / permeo / eborder driver ( intercepts TCP calls )
|
||||||
|
It is FREE.
|
||||||
|
|
||||||
|
Changelog:
|
||||||
|
----------
|
||||||
|
|
||||||
|
Version (4.x) removes the dnsresolver script which required a dynamically
|
||||||
|
linked "dig" binary to be present with remote DNS lookup.
|
||||||
|
this speeds up any operation involving DNS, as the old script had to use TCP.
|
||||||
|
additionally it allows to use .onion urls when used with TOR.
|
||||||
|
also it removed the broken autoconf build system with a simple Makefile.
|
||||||
|
there's a ./configure script though for convenience.
|
||||||
|
it also adds support for a config file passed via command line switches/
|
||||||
|
environment variables.
|
||||||
|
|
||||||
|
Version (3.x) introduces support for DNS resolving through proxy
|
||||||
|
it supports SOCKS4, SOCKS5 and HTTP CONNECT proxy servers.
|
||||||
|
Auth-types: socks - "user/pass" , http - "basic".
|
||||||
|
|
||||||
|
When to use it ?
|
||||||
|
1) When the only way to get "outside" from your LAN is through proxy server.
|
||||||
|
2) To get out from behind restrictive firewall which filters outgoing ports.
|
||||||
|
3) To use two (or more) proxies in chain:
|
||||||
|
like: your_host <--> proxy1 <--> proxy2 <--> target_host
|
||||||
|
4) To "proxify" some program with no proxy support built-in (like telnet)
|
||||||
|
5) Access intranet from outside via proxy.
|
||||||
|
5) To use DNS behind proxy.
|
||||||
|
|
||||||
|
Some cool features:
|
||||||
|
|
||||||
|
* This program can mix different proxy types in the same chain
|
||||||
|
like: your_host <-->socks5 <--> http <--> socks4 <--> target_host
|
||||||
|
* Different chaining options supported
|
||||||
|
random order from the list ( user defined length of chain ).
|
||||||
|
exact order (as they appear in the list )
|
||||||
|
dynamic order (smart exclude dead proxies from chain)
|
||||||
|
* You can use it with any TCP client application, even network scanners
|
||||||
|
yes, yes - you can make portscan via proxy (or chained proxies)
|
||||||
|
for example with Nmap scanner by fyodor (www.insecire.org/nmap).
|
||||||
|
proxychains nmap -sT -PO -p 80 -iR (find some webservers through proxy)
|
||||||
|
* You can use it with servers, like squid, sendmail, or whatever.
|
||||||
|
* DNS resolving through proxy.
|
||||||
|
|
||||||
|
|
||||||
|
Configuration:
|
||||||
|
--------------
|
||||||
|
|
||||||
|
proxychains looks for config file in following order:
|
||||||
|
1) file listed in environment variable ${PROXYCHAINS_CONF_FILE} or
|
||||||
|
provided as a -f argument to proxychains script or binary.
|
||||||
|
2) ./proxychains.conf
|
||||||
|
3) $(HOME)/.proxychains/proxychains.conf
|
||||||
|
4) /etc/proxychains.conf **
|
||||||
|
|
||||||
|
**see more in /etc/proxychains.conf
|
||||||
|
|
||||||
|
Usage Example:
|
||||||
|
|
||||||
|
bash$ proxychains telnet targethost.com
|
||||||
|
|
||||||
|
in this example it will run telnet through proxy(or chained proxies)
|
||||||
|
specified by proxychains.conf
|
||||||
|
|
||||||
|
Usage Example:
|
||||||
|
|
||||||
|
bash$ proxychains -f /etc/proxychains-other.conf targethost2.com
|
||||||
|
|
||||||
|
in this example it will use different configuration file then proxychains.conf
|
||||||
|
to connect to targethost2.com host.
|
||||||
|
|
||||||
|
Usage Example:
|
||||||
|
|
||||||
|
bash$ proxyresolv targethost.com
|
||||||
|
|
||||||
|
in this example it will resolve targethost.com through proxy(or chained proxies)
|
||||||
|
specified by proxychains.conf
|
||||||
|
|
||||||
179
README.md
179
README.md
@ -1,179 +0,0 @@
|
|||||||
# ProxyChains ver. 4.3.0 README
|
|
||||||
|
|
||||||

|
|
||||||
|
|
||||||
|
|
||||||
ProxyChains is a UNIX program, that hooks network-related libc functions
|
|
||||||
in dynamically linked programs via a preloaded DLL and redirects the
|
|
||||||
connections through SOCKS4a/5 or HTTP proxies.
|
|
||||||
|
|
||||||
WARNING: this program works only on dynamically linked programs.
|
|
||||||
also both proxychains and the program to call must use
|
|
||||||
the same dynamic linker (i.e. same libc)
|
|
||||||
|
|
||||||
## Known limitations of the current version
|
|
||||||
|
|
||||||
when a process forks, does a DNS lookup in the child, and then uses
|
|
||||||
the ip in the parent, the corresponding ip mapping will not be found,
|
|
||||||
this is because the fork can't write back into the parents mapping table.
|
|
||||||
IRSSI shows this behavior, so you have to pass the resolved ip address
|
|
||||||
to it. (you can use the proxyresolv script (requires "dig") to do so)
|
|
||||||
|
|
||||||
this means that you can't currently use tor onion urls for irssi.
|
|
||||||
to solve this issue, an external data store (file, pipe, ...) has to
|
|
||||||
manage the dns <-> ip mapping. of course there has to be proper locking.
|
|
||||||
shm_open, mkstemp, are possible candidates for a file based approach,
|
|
||||||
the other option is to spawn some kind of server process that manages the
|
|
||||||
map lookups. since connect() etc are hooked, this must not be a TCP server.
|
|
||||||
|
|
||||||
I am reluctant on doing this change, because the described behavior
|
|
||||||
seems pretty idiotic (doing a fork only for a DNS lookup), and irssi
|
|
||||||
is currently the only known affected program.
|
|
||||||
|
|
||||||
## Installation
|
|
||||||
|
|
||||||
### Using release version
|
|
||||||
|
|
||||||
*Proxychains-4.3.0* are available with pkgsrc to everyone using it on _Linux_,
|
|
||||||
_NetBSD_, _FreeBSD_, _OpenBSD_, _DragonFlyBSD_ or _Mac OS X_. You just need to install
|
|
||||||
pkgsrc-wip repository and run
|
|
||||||
make install
|
|
||||||
in a wip/proxychains directory.
|
|
||||||
|
|
||||||
You can find out more about pkgsrc on link:http://www.pkgsrc.org[pkgsrc] and about pkgsrc-wip on
|
|
||||||
link:https://pkgsrc.org/wip[Pkgsrc-wip homepage]
|
|
||||||
|
|
||||||
### Installing on Mac OS X with homebrew
|
|
||||||
|
|
||||||
You can install current proxychains on Mac OS X with an homebrew. You have to
|
|
||||||
download unofficial link:https://gist.github.com/3792521[homebrew formula] from
|
|
||||||
to your BREW_HOME by default /usr/local/Library/Formula/ and run
|
|
||||||
|
|
||||||
```
|
|
||||||
$ brew install proxychains
|
|
||||||
```
|
|
||||||
|
|
||||||
### Running Current Source code version
|
|
||||||
|
|
||||||
```
|
|
||||||
# needs a working C compiler, preferably gcc
|
|
||||||
./configure
|
|
||||||
make
|
|
||||||
sudo make install
|
|
||||||
```
|
|
||||||
|
|
||||||
## Changelog
|
|
||||||
|
|
||||||
*Version (4.x)* removes the dnsresolver script which required a dynamically
|
|
||||||
linked "dig" binary to be present with remote DNS lookup.
|
|
||||||
this speeds up any operation involving DNS, as the old script had to use TCP.
|
|
||||||
additionally it allows to use .onion urls when used with TOR.
|
|
||||||
also it removed the broken autoconf build system with a simple Makefile.
|
|
||||||
there's a ./configure script though for convenience.
|
|
||||||
it also adds support for a config file passed via command line switches/
|
|
||||||
environment variables.
|
|
||||||
|
|
||||||
*Version (3.x)* introduces support for DNS resolving through proxy
|
|
||||||
it supports SOCKS4, SOCKS5 and HTTP CONNECT proxy servers.
|
|
||||||
|
|
||||||
* Auth-types
|
|
||||||
** socks - "user/pass",
|
|
||||||
** http - "basic"
|
|
||||||
|
|
||||||
## When to use it
|
|
||||||
|
|
||||||
* When the only way to get "outside" from your LAN is through proxy server.
|
|
||||||
* To get out from behind restrictive firewall which filters outgoing ports.
|
|
||||||
* To use two (or more) proxies in chain:
|
|
||||||
|
|
||||||
```
|
|
||||||
like: your_host <--> proxy1 <--> proxy2 <--> target_host
|
|
||||||
```
|
|
||||||
|
|
||||||
* To "proxify" some program with no proxy support built-in (like telnet)
|
|
||||||
* Access intranet from outside via proxy.
|
|
||||||
* To use DNS behind proxy.
|
|
||||||
|
|
||||||
### Some cool features
|
|
||||||
|
|
||||||
* This program can mix different proxy types in the same chain
|
|
||||||
|
|
||||||
```
|
|
||||||
like: your_host <-->socks5 <--> http <--> socks4 <--> target_host
|
|
||||||
```
|
|
||||||
|
|
||||||
* Different chaining options supported
|
|
||||||
random order from the list ( user defined length of chain ).
|
|
||||||
exact order (as they appear in the list )
|
|
||||||
dynamic order (smart exclude dead proxies from chain)
|
|
||||||
* You can use it with any TCP client application, even network scanners
|
|
||||||
yes, yes - you can make portscan via proxy (or chained proxies)
|
|
||||||
for example with Nmap scanner by fyodor (www.insecure.org/nmap).
|
|
||||||
|
|
||||||
```
|
|
||||||
proxychains nmap -sT -PO -p 80 -iR (find some webservers through proxy)
|
|
||||||
```
|
|
||||||
|
|
||||||
* You can use it with servers, like squid, sendmail, or whatever.
|
|
||||||
* DNS resolving through proxy.
|
|
||||||
|
|
||||||
## Configuration
|
|
||||||
|
|
||||||
proxychains looks for configuration in the following order:
|
|
||||||
|
|
||||||
* SOCKS5 proxy host ip and port in environment variable ${PROXYCHAINS_SOCKS5_HOST} ${PROXYCHAINS_SOCKS5_PORT}
|
|
||||||
(if ${PROXYCHAINS_SOCKS5_PORT} is set, no further configuration will be searched. if ${PROXYCHAINS_SOCKS5_HOST} isn't set, host ip will become "127.0.0.1")
|
|
||||||
* file listed in environment variable ${PROXYCHAINS_CONF_FILE} or
|
|
||||||
provided as a -f argument to proxychains script or binary.
|
|
||||||
* ./proxychains.conf
|
|
||||||
* $(HOME)/.proxychains/proxychains.conf
|
|
||||||
* /etc/proxychains.conf
|
|
||||||
|
|
||||||
see more in */etc/proxychains.conf*
|
|
||||||
|
|
||||||
### Usage Example
|
|
||||||
|
|
||||||
```
|
|
||||||
$ proxychains4 telnet targethost.com
|
|
||||||
```
|
|
||||||
|
|
||||||
in this example it will run telnet through proxy(or chained proxies)
|
|
||||||
specified by *proxychains.conf*
|
|
||||||
|
|
||||||
### Usage Example
|
|
||||||
|
|
||||||
```
|
|
||||||
$ proxychains4 -f /etc/proxychains-other.conf targethost2.com
|
|
||||||
```
|
|
||||||
|
|
||||||
in this example it will use different configuration file then *proxychains.conf*
|
|
||||||
to connect to targethost2.com host.
|
|
||||||
|
|
||||||
### Usage Example
|
|
||||||
|
|
||||||
```
|
|
||||||
$ proxyresolv targethost.com
|
|
||||||
```
|
|
||||||
|
|
||||||
in this example it will resolve targethost.com through proxy(or chained proxies)
|
|
||||||
specified by *proxychains.conf*
|
|
||||||
|
|
||||||
### Usage Example:
|
|
||||||
|
|
||||||
```
|
|
||||||
$ ssh -fN -D 4321 some.example.com
|
|
||||||
$ PROXYCHAINS_SOCKS5_HOST=127.0.0.1 PROXYCHAINS_SOCKS5_PORT=4321 proxychains zsh
|
|
||||||
```
|
|
||||||
|
|
||||||
in this example, it will run a shell with all traffic proxied through
|
|
||||||
OpenSSH's "dynamic proxy" (SOCKS5 proxy) on localhost port 4321.
|
|
||||||
|
|
||||||
### Usage Example:
|
|
||||||
|
|
||||||
```
|
|
||||||
$ export PROXY_DNS_SERVER=8.8.8.8
|
|
||||||
$ proxychains4 telnet targethost.com
|
|
||||||
```
|
|
||||||
|
|
||||||
in this example, it will telnet to targethost.com using the 8.8.8.8
|
|
||||||
nameserver supplied by the user through the PROXY_DNS_SERVER
|
|
||||||
12
TODO
12
TODO
@ -1,11 +1,9 @@
|
|||||||
ProxyChains ver 4.0 TODO
|
ProxyChains ver 3.1 TODO
|
||||||
===================
|
===================
|
||||||
|
|
||||||
- hooks for reentrant dns functions, i.e. gethostbyaddr_r
|
stable DNS resolver .... currently gnu dig is used, which is an ugly hack
|
||||||
- shadowsocks support #133
|
also it is required to link it with the same libc as proxychains
|
||||||
- proxy change according to attempts #156
|
|
||||||
|
hooks for reentrant dns functions, i.e. gethostbyaddr_r
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -1,3 +0,0 @@
|
|||||||
#compdef proxychains4
|
|
||||||
|
|
||||||
_arguments -s -S '1: :{_command_names -e}' '*:: :_normal'
|
|
||||||
76
configure
vendored
76
configure
vendored
@ -1,20 +1,6 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
prefix=/usr/local
|
prefix=/usr/local
|
||||||
develflg=0
|
|
||||||
|
|
||||||
usage() {
|
|
||||||
echo "supported arguments"
|
|
||||||
echo "--prefix=/path default: $prefix"
|
|
||||||
echo "--exec_prefix=/path default: $prefix/bin"
|
|
||||||
echo "--bindir=/path default: $prefix/bin"
|
|
||||||
echo "--libdir=/path default: $prefix/lib"
|
|
||||||
echo "--includedir=/path default: $prefix/include"
|
|
||||||
echo "--sysconfdir=/path default: $prefix/etc"
|
|
||||||
echo "--devel default:no (set development mode)"
|
|
||||||
echo "--help : show this text"
|
|
||||||
exit 1
|
|
||||||
}
|
|
||||||
|
|
||||||
spliteq() {
|
spliteq() {
|
||||||
arg=$1
|
arg=$1
|
||||||
@ -25,29 +11,14 @@ spliteq() {
|
|||||||
|
|
||||||
parsearg() {
|
parsearg() {
|
||||||
case "$1" in
|
case "$1" in
|
||||||
--prefix=*) prefix=`spliteq $1`;;
|
--prefix=*) prefix=$(spliteq "$1");;
|
||||||
--exec_prefix=*) exec_prefix=`spliteq $1`;;
|
--exec_prefix=*) exec_prefix=`spliteq $1`;;
|
||||||
--bindir=*) bindir=`spliteq $1`;;
|
--bindir=*) bindir=`spliteq $1`;;
|
||||||
--libdir=*) libdir=`spliteq $1`;;
|
--libdir=*) libdir=`spliteq $1`;;
|
||||||
--includedir=*) includedir=`spliteq $1`;;
|
--includedir=*) includedir=`spliteq $1`;;
|
||||||
--sysconfdir=*) sysconfdir=`spliteq $1`;;
|
|
||||||
--devel) develflg=1;;
|
|
||||||
--help) usage;;
|
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
ismac() {
|
|
||||||
uname -s | grep Darwin
|
|
||||||
}
|
|
||||||
|
|
||||||
isbsd() {
|
|
||||||
uname -s | grep BSD
|
|
||||||
}
|
|
||||||
|
|
||||||
islinux() {
|
|
||||||
uname -s | grep Linux
|
|
||||||
}
|
|
||||||
|
|
||||||
while true ; do
|
while true ; do
|
||||||
case $1 in
|
case $1 in
|
||||||
-*) parsearg "$1"; shift;;
|
-*) parsearg "$1"; shift;;
|
||||||
@ -55,69 +26,34 @@ while true ; do
|
|||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
if [ -z "$exec_prefix" ] ; then
|
if [ ! $exec_prefix ] ; then
|
||||||
exec_prefix=$prefix
|
exec_prefix=$prefix
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -z "$libdir" ] ; then
|
if [ ! $libdir ] ; then
|
||||||
libdir=$prefix/lib
|
libdir=$prefix/lib
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -z "$includedir" ] ; then
|
if [ ! $includedir ] ; then
|
||||||
includedir=$prefix/include
|
includedir=$prefix/include
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -z "$sysconfdir" ] ; then
|
if [ ! $bindir ] ; then
|
||||||
sysconfdir=$prefix/etc
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -z "$bindir" ] ; then
|
|
||||||
bindir=$exec_prefix/bin
|
bindir=$exec_prefix/bin
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -z "$CC" ] ; then
|
if [ ! $CC ] ; then
|
||||||
CC=cc
|
CC=cc
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ $develflg -eq 1 ]; then
|
|
||||||
CFLAGS="-Wextra -Wunused -Wuninitialized -Wconversion -fno-common -g -O0 -DDEBUG"
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo CC?=$CC>config.mak
|
echo CC?=$CC>config.mak
|
||||||
[ -z "$CPPFLAGS" ] || echo CPPFLAGS?=$CPPFLAGS>>config.mak
|
[ -z "$CPPFLAGS" ] || echo CPPFLAGS?=$CPPFLAGS>>config.mak
|
||||||
[ -z "$CFLAGS" ] || echo USER_CFLAGS?=$CFLAGS>>config.mak
|
[ -z "$CFLAGS" ] || echo USER_CFLAGS?=$CFLAGS>>config.mak
|
||||||
[ -z "$LDFLAGS" ] || echo USER_LDFLAGS?=$LDFLAGS>>config.mak
|
|
||||||
|
|
||||||
echo prefix=$prefix>>config.mak
|
echo prefix=$prefix>>config.mak
|
||||||
echo exec_prefix=$exec_prefix>>config.mak
|
echo exec_prefix=$exec_prefix>>config.mak
|
||||||
echo bindir=$bindir>>config.mak
|
echo bindir=$bindir>>config.mak
|
||||||
echo libdir=$libdir>>config.mak
|
echo libdir=$libdir>>config.mak
|
||||||
echo includedir=$includedir>>config.mak
|
echo includedir=$includedir>>config.mak
|
||||||
echo sysconfdir=$sysconfdir>>config.mak
|
|
||||||
|
|
||||||
if ismac ; then
|
|
||||||
arch=`uname -m`
|
|
||||||
|
|
||||||
echo LDSO_SUFFIX=dylib>>config.mak
|
|
||||||
echo OS_CFLAGS+=-DIS_MAC=1 -arch $arch >>config.mak
|
|
||||||
echo OS_LDFLAGS+=-arch $arch -lpthread -ldl -Wl,>>config.mak
|
|
||||||
echo LD_SET_SONAME=-Wl,-install_name,>>config.mak
|
|
||||||
echo LDSO_SUFFIX=dylib>>config.mak
|
|
||||||
echo INSTALL_FLAGS=-m>>config.mak
|
|
||||||
fi
|
|
||||||
|
|
||||||
if islinux ; then
|
|
||||||
echo OS_LDFLAGS=-pthread -ldl -Wl,--no-as-needed>>config.mak
|
|
||||||
echo LD_SET_SONAME=-Wl,-soname= >>config.mak
|
|
||||||
fi
|
|
||||||
|
|
||||||
if isbsd ; then
|
|
||||||
#echo OS_LDFLAGS=
|
|
||||||
#echo OS_CFLAGS
|
|
||||||
echo INSTALL_FLAGS=-m>>config.mak
|
|
||||||
echo LD_SET_SONAME=-Wl,-rpath,$libdir -install_name,>>config.mak
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo done, now run make \&\& make install
|
echo done, now run make \&\& make install
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
13
dist/proxychains.conf
vendored
13
dist/proxychains.conf
vendored
@ -1,13 +0,0 @@
|
|||||||
strict_chain
|
|
||||||
#proxy_dns
|
|
||||||
#remote_dns_subnet 224
|
|
||||||
tcp_read_time_out 15000
|
|
||||||
tcp_connect_time_out 8000
|
|
||||||
|
|
||||||
localnet 127.0.0.0/255.0.0.0
|
|
||||||
|
|
||||||
|
|
||||||
[ProxyList]
|
|
||||||
http 162.243.184.252 8585
|
|
||||||
#socks4 184.170.245.148 4145
|
|
||||||
#raw 162.243.184.252 8585
|
|
||||||
@ -1,13 +1,13 @@
|
|||||||
Begin3
|
Begin3
|
||||||
Title: ProxyChains
|
Title: ProxyChains
|
||||||
Version: 4.3
|
Version: 3.0
|
||||||
Entered-date:
|
Entered-date:
|
||||||
Description:
|
Description:
|
||||||
Keywords:
|
Keywords:
|
||||||
Author: <N37CR347UR3>
|
Author: <N37CR347UR3>
|
||||||
Maintained-by: <haad@netbsd.org>
|
Maintained-by: <NetCreature>
|
||||||
Primary-site:
|
Primary-site:
|
||||||
Home-page: https://github.com/haad/proxychains
|
Home-page: http://proxychains.sourceforge.net
|
||||||
Original-site:
|
Original-site:
|
||||||
Platforms: Linux and other Unices
|
Platforms: Linux and other Unices
|
||||||
Copying-policy: GNU Public License
|
Copying-policy: GNU Public License
|
||||||
|
|||||||
54
src/common.c
54
src/common.c
@ -1,54 +0,0 @@
|
|||||||
#include "common.h"
|
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
static int check_path(char *path) {
|
|
||||||
if(!path)
|
|
||||||
return 0;
|
|
||||||
return access(path, R_OK) != -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
char *get_config_path(char* default_path, char* pbuf, size_t bufsize) {
|
|
||||||
char buf[512];
|
|
||||||
// top priority: user defined path
|
|
||||||
char *path = default_path;
|
|
||||||
if(check_path(path))
|
|
||||||
return path;
|
|
||||||
if (!pbuf)
|
|
||||||
goto err;
|
|
||||||
|
|
||||||
// priority 1: env var PROXYCHAINS_CONF_FILE
|
|
||||||
path = getenv(PROXYCHAINS_CONF_FILE_ENV_VAR);
|
|
||||||
if(check_path(path))
|
|
||||||
return path;
|
|
||||||
|
|
||||||
// priority 2; proxychains conf in actual dir
|
|
||||||
path = getcwd(buf, sizeof(buf));
|
|
||||||
snprintf(pbuf, bufsize, "%s/%s", path, PROXYCHAINS_CONF_FILE);
|
|
||||||
path = pbuf;
|
|
||||||
if(check_path(path))
|
|
||||||
return path;
|
|
||||||
|
|
||||||
// priority 3; $HOME/.proxychains/proxychains.conf
|
|
||||||
path = getenv("HOME");
|
|
||||||
snprintf(pbuf, bufsize, "%s/.proxychains/%s", path, PROXYCHAINS_CONF_FILE);
|
|
||||||
path = pbuf;
|
|
||||||
if(check_path(path))
|
|
||||||
return path;
|
|
||||||
|
|
||||||
// priority 4: $SYSCONFDIR/proxychains.conf
|
|
||||||
path = SYSCONFDIR "/" PROXYCHAINS_CONF_FILE;
|
|
||||||
if(check_path(path))
|
|
||||||
return path;
|
|
||||||
|
|
||||||
// priority 5: /etc/proxychains.conf
|
|
||||||
path = "/etc/" PROXYCHAINS_CONF_FILE;
|
|
||||||
if(check_path(path))
|
|
||||||
return path;
|
|
||||||
|
|
||||||
err:
|
|
||||||
perror("couldn't find configuration file");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
11
src/common.h
11
src/common.h
@ -1,15 +1,4 @@
|
|||||||
#define PROXYCHAINS_CONF_FILE_ENV_VAR "PROXYCHAINS_CONF_FILE"
|
#define PROXYCHAINS_CONF_FILE_ENV_VAR "PROXYCHAINS_CONF_FILE"
|
||||||
#define PROXYCHAINS_QUIET_MODE_ENV_VAR "PROXYCHAINS_QUIET_MODE"
|
#define PROXYCHAINS_QUIET_MODE_ENV_VAR "PROXYCHAINS_QUIET_MODE"
|
||||||
#define PROXYCHAINS_CONF_FILE "proxychains.conf"
|
#define PROXYCHAINS_CONF_FILE "proxychains.conf"
|
||||||
#define PROXYCHAINS_SOCKS5_PORT_ENV_VAR "PROXYCHAINS_SOCKS5_PORT"
|
|
||||||
#define PROXYCHAINS_SOCKS5_HOST_ENV_VAR "PROXYCHAINS_SOCKS5_HOST"
|
|
||||||
#define PROXYCHAINS_DNS_ENV_VAR "PROXYCHAINS_DNS"
|
|
||||||
#define LOG_PREFIX "[proxychains] "
|
#define LOG_PREFIX "[proxychains] "
|
||||||
|
|
||||||
#define PROXYCHAINS_VERSION_MAJOR 4
|
|
||||||
#define PROXYCHAINS_VERSION_MINOR 3
|
|
||||||
#define PROXYCHAINS_VERSION_BUGFIX 0
|
|
||||||
|
|
||||||
#include <stddef.h>
|
|
||||||
|
|
||||||
char *get_config_path(char* default_path, char* pbuf, size_t bufsize);
|
|
||||||
|
|||||||
466
src/core.c
466
src/core.c
@ -14,8 +14,6 @@
|
|||||||
* (at your option) any later version. *
|
* (at your option) any later version. *
|
||||||
* *
|
* *
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
#include <sys/types.h>
|
|
||||||
#include <sys/cdefs.h>
|
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
@ -27,6 +25,7 @@
|
|||||||
#include <sys/utsname.h>
|
#include <sys/utsname.h>
|
||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
|
#include <sys/types.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <sys/poll.h>
|
#include <sys/poll.h>
|
||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
@ -34,16 +33,10 @@
|
|||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <assert.h>
|
|
||||||
|
|
||||||
#ifdef THREAD_SAFE
|
#ifdef THREAD_SAFE
|
||||||
|
#include <pthread.h>
|
||||||
pthread_mutex_t internal_ips_lock;
|
pthread_mutex_t internal_ips_lock;
|
||||||
|
#endif
|
||||||
#ifdef __APPLE__
|
|
||||||
pthread_mutex_t internal_getsrvbyname_lock;
|
|
||||||
#endif /* __APPLE__ */
|
|
||||||
|
|
||||||
#endif /* THREAD_SAFE */
|
|
||||||
|
|
||||||
#include "core.h"
|
#include "core.h"
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
@ -51,10 +44,10 @@ pthread_mutex_t internal_getsrvbyname_lock;
|
|||||||
extern int tcp_read_time_out;
|
extern int tcp_read_time_out;
|
||||||
extern int tcp_connect_time_out;
|
extern int tcp_connect_time_out;
|
||||||
extern int proxychains_quiet_mode;
|
extern int proxychains_quiet_mode;
|
||||||
extern unsigned int remote_dns_subnet;
|
|
||||||
|
|
||||||
internal_ip_lookup_table internal_ips = {0, 0, NULL};
|
internal_ip_lookup_table internal_ips = {0, 0, NULL};
|
||||||
|
|
||||||
|
|
||||||
uint32_t dalias_hash(char* s0) {
|
uint32_t dalias_hash(char* s0) {
|
||||||
unsigned char* s = (void*) s0;
|
unsigned char* s = (void*) s0;
|
||||||
uint_fast32_t h = 0;
|
uint_fast32_t h = 0;
|
||||||
@ -68,27 +61,30 @@ uint32_t dalias_hash(char *s0) {
|
|||||||
uint32_t index_from_internal_ip(ip_type internalip) {
|
uint32_t index_from_internal_ip(ip_type internalip) {
|
||||||
ip_type tmp = internalip;
|
ip_type tmp = internalip;
|
||||||
uint32_t ret;
|
uint32_t ret;
|
||||||
ret = (uint32_t) (tmp.octet[3] + (tmp.octet[2] << 8) + (tmp.octet[1] << 16));
|
ret = tmp.octet[3] + (tmp.octet[2] << 8) + (tmp.octet[1] << 16);
|
||||||
ret -= 1;
|
ret -= 1;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
char* string_from_internal_ip(ip_type internalip) {
|
char* string_from_internal_ip(ip_type internalip) {
|
||||||
char* res = NULL;
|
char* res = NULL;
|
||||||
|
#ifdef THREAD_SAFE
|
||||||
|
pthread_mutex_lock(&internal_ips_lock);
|
||||||
|
#endif
|
||||||
uint32_t index = index_from_internal_ip(internalip);
|
uint32_t index = index_from_internal_ip(internalip);
|
||||||
MUTEX_LOCK(&internal_ips_lock);
|
|
||||||
if(index < internal_ips.counter)
|
if(index < internal_ips.counter)
|
||||||
res = internal_ips.list[index]->string;
|
res = internal_ips.list[index]->string;
|
||||||
MUTEX_UNLOCK(&internal_ips_lock);
|
#ifdef THREAD_SAFE
|
||||||
|
pthread_mutex_unlock(&internal_ips_lock);
|
||||||
|
#endif
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
in_addr_t make_internal_ip(uint32_t index) {
|
in_addr_t make_internal_ip(uint32_t index) {
|
||||||
ip_type ret;
|
ip_type ret;
|
||||||
index++; // so we can start at .0.0.1
|
index++; // so we can start at .0.0.1
|
||||||
if(index > 0xFFFFFF)
|
if(index > 0xFFFFFF) return (in_addr_t) -1;
|
||||||
return (in_addr_t) - 1;
|
ret.octet[0] = 224;
|
||||||
ret.octet[0] = remote_dns_subnet & 0xFF;
|
|
||||||
ret.octet[1] = (index & 0xFF0000) >> 16;
|
ret.octet[1] = (index & 0xFF0000) >> 16;
|
||||||
ret.octet[2] = (index & 0xFF00) >> 8;
|
ret.octet[2] = (index & 0xFF00) >> 8;
|
||||||
ret.octet[3] = index & 0xFF;
|
ret.octet[3] = index & 0xFF;
|
||||||
@ -112,7 +108,7 @@ static int poll_retry(struct pollfd *fds, nfds_t nfsd, int timeout)
|
|||||||
//printf("Retry %d\n", time_remain);
|
//printf("Retry %d\n", time_remain);
|
||||||
ret = poll(fds, nfsd, time_remain);
|
ret = poll(fds, nfsd, time_remain);
|
||||||
gettimeofday(&tv, NULL);
|
gettimeofday(&tv, NULL);
|
||||||
time_elapsed = ((int)(tv.tv_sec - start_time.tv_sec) * 1000 + (int)(tv.tv_usec - start_time.tv_usec) / 1000);
|
time_elapsed = ((tv.tv_sec - start_time.tv_sec) * 1000 + (tv.tv_usec - start_time.tv_usec) / 1000);
|
||||||
//printf("Time elapsed %d\n", time_elapsed);
|
//printf("Time elapsed %d\n", time_elapsed);
|
||||||
time_remain = timeout - time_elapsed;
|
time_remain = timeout - time_elapsed;
|
||||||
} while (ret == -1 && errno == EINTR && time_remain > 0);
|
} while (ret == -1 && errno == EINTR && time_remain > 0);
|
||||||
@ -123,13 +119,13 @@ static int poll_retry(struct pollfd *fds, nfds_t nfsd, int timeout)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void encode_base_64(char *src, char *dest, int max_len) {
|
static void encode_base_64(char* src,char* dest,int max_len)
|
||||||
int n, i;
|
{
|
||||||
size_t l;
|
int n,l,i;
|
||||||
|
|
||||||
l=strlen(src);
|
l=strlen(src);
|
||||||
max_len=(max_len-1)/4;
|
max_len=(max_len-1)/4;
|
||||||
for(i = 0; i < max_len; i++, src += 3, l -= 3) {
|
for ( i=0;i<max_len;i++,src+=3,l-=3)
|
||||||
|
{
|
||||||
switch (l) {
|
switch (l) {
|
||||||
case 0:
|
case 0:
|
||||||
break;
|
break;
|
||||||
@ -154,29 +150,35 @@ static void encode_base_64(char *src, char *dest, int max_len) {
|
|||||||
*dest++=base64[(n >> 6) & 077];
|
*dest++=base64[(n >> 6) & 077];
|
||||||
*dest++=base64[n & 077];
|
*dest++=base64[n & 077];
|
||||||
}
|
}
|
||||||
if(l < 3)
|
if (l<3) break;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
*dest++=0;
|
*dest++=0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void proxychains_write_log(char *str, ...) {
|
#define LOG_BUFF 1024*20
|
||||||
char buff[1024*20];
|
|
||||||
|
int proxychains_write_log(char *str,...)
|
||||||
|
{
|
||||||
|
char buff[LOG_BUFF];
|
||||||
va_list arglist;
|
va_list arglist;
|
||||||
|
FILE * log_file;
|
||||||
|
log_file=stderr;
|
||||||
if (!proxychains_quiet_mode) {
|
if (!proxychains_quiet_mode) {
|
||||||
va_start(arglist,str);
|
va_start(arglist,str);
|
||||||
vsnprintf(buff, sizeof(buff), str, arglist);
|
vsprintf(buff,str,arglist);
|
||||||
va_end(arglist);
|
va_end(arglist);
|
||||||
fprintf(stderr, "%s", buff);
|
fprintf(log_file,"%s",buff);
|
||||||
fflush(stderr);
|
fflush(log_file);
|
||||||
}
|
}
|
||||||
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static size_t write_n_bytes(int fd, char *buff, size_t size) {
|
static int write_n_bytes(int fd,char *buff,size_t size)
|
||||||
size_t i = 0;
|
{
|
||||||
|
int i=0;
|
||||||
size_t wrote=0;
|
size_t wrote=0;
|
||||||
for(;;) {
|
for(;;) {
|
||||||
i = (size_t) write(fd, &buff[wrote], size - wrote);
|
i = write(fd,&buff[wrote],size-wrote);
|
||||||
if(i<=0)
|
if(i<=0)
|
||||||
return i;
|
return i;
|
||||||
wrote += i;
|
wrote += i;
|
||||||
@ -185,7 +187,8 @@ static size_t write_n_bytes(int fd, char *buff, size_t size) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static size_t read_n_bytes(int fd, char *buff, size_t size) {
|
static int read_n_bytes(int fd,char *buff, size_t size)
|
||||||
|
{
|
||||||
int ready;
|
int ready;
|
||||||
size_t i;
|
size_t i;
|
||||||
struct pollfd pfd[1];
|
struct pollfd pfd[1];
|
||||||
@ -196,12 +199,13 @@ static size_t read_n_bytes(int fd, char *buff, size_t size) {
|
|||||||
pfd[0].revents = 0;
|
pfd[0].revents = 0;
|
||||||
ready = poll_retry(pfd, 1, tcp_read_time_out);
|
ready = poll_retry(pfd, 1, tcp_read_time_out);
|
||||||
if(ready != 1 || !(pfd[0].revents&POLLIN) || 1 != read(fd,&buff[i],1))
|
if(ready != 1 || !(pfd[0].revents&POLLIN) || 1 != read(fd,&buff[i],1))
|
||||||
return 0;
|
return -1;
|
||||||
}
|
}
|
||||||
return size;
|
return (int) size;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int timed_connect(int sock, const struct sockaddr *addr, socklen_t len) {
|
static int timed_connect(int sock, const struct sockaddr *addr, socklen_t len)
|
||||||
|
{
|
||||||
int ret, value;
|
int ret, value;
|
||||||
socklen_t value_len;
|
socklen_t value_len;
|
||||||
struct pollfd pfd[1];
|
struct pollfd pfd[1];
|
||||||
@ -210,15 +214,23 @@ static int timed_connect(int sock, const struct sockaddr *addr, socklen_t len) {
|
|||||||
pfd[0].events=POLLOUT;
|
pfd[0].events=POLLOUT;
|
||||||
fcntl(sock, F_SETFL, O_NONBLOCK);
|
fcntl(sock, F_SETFL, O_NONBLOCK);
|
||||||
ret = true_connect(sock, addr, len);
|
ret = true_connect(sock, addr, len);
|
||||||
PDEBUG("\nconnect ret=%d\n", ret);
|
#ifdef DEBUG
|
||||||
|
if(ret == -1) perror("true_connect");
|
||||||
|
printf("\nconnect ret=%d\n",ret);
|
||||||
|
|
||||||
|
fflush(stdout);
|
||||||
|
#endif
|
||||||
if(ret==-1 && errno==EINPROGRESS) {
|
if(ret==-1 && errno==EINPROGRESS) {
|
||||||
ret=poll_retry(pfd,1,tcp_connect_time_out);
|
ret=poll_retry(pfd,1,tcp_connect_time_out);
|
||||||
PDEBUG("\npoll ret=%d\n", ret);
|
#ifdef DEBUG
|
||||||
|
printf("\npoll ret=%d\n",ret);fflush(stdout);
|
||||||
|
#endif
|
||||||
if(ret == 1) {
|
if(ret == 1) {
|
||||||
value_len=sizeof(socklen_t);
|
value_len=sizeof(socklen_t);
|
||||||
getsockopt(sock,SOL_SOCKET,SO_ERROR,&value,&value_len) ;
|
getsockopt(sock,SOL_SOCKET,SO_ERROR,&value,&value_len) ;
|
||||||
PDEBUG("\nvalue=%d\n", value);
|
#ifdef DEBUG
|
||||||
|
printf("\nvalue=%d\n",value);fflush(stdout);
|
||||||
|
#endif
|
||||||
if(!value)
|
if(!value)
|
||||||
ret=0;
|
ret=0;
|
||||||
else
|
else
|
||||||
@ -227,10 +239,6 @@ static int timed_connect(int sock, const struct sockaddr *addr, socklen_t len) {
|
|||||||
ret=-1;
|
ret=-1;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
#ifdef DEBUG
|
|
||||||
if(ret == -1)
|
|
||||||
perror("true_connect");
|
|
||||||
#endif
|
|
||||||
if (ret != 0)
|
if (ret != 0)
|
||||||
ret=-1;
|
ret=-1;
|
||||||
}
|
}
|
||||||
@ -241,29 +249,24 @@ static int timed_connect(int sock, const struct sockaddr *addr, socklen_t len) {
|
|||||||
|
|
||||||
|
|
||||||
#define INVALID_INDEX 0xFFFFFFFFU
|
#define INVALID_INDEX 0xFFFFFFFFU
|
||||||
#define HTTP_AUTH_MAX ((0xFF * 2) + 1 + 1)
|
static int tunnel_to(int sock, ip_type ip, unsigned short port, proxy_type pt,char *user,char *pass)
|
||||||
|
{
|
||||||
static int tunnel_to(int sock, ip_type ip, unsigned short port, proxy_type pt, char *user, char *pass) {
|
#ifdef DEBUG
|
||||||
|
PDEBUG("tunnel_to()\n");
|
||||||
|
#endif
|
||||||
char* dns_name = NULL;
|
char* dns_name = NULL;
|
||||||
size_t dns_len = 0;
|
size_t dns_len = 0;
|
||||||
|
|
||||||
PDEBUG("tunnel_to()\n");
|
|
||||||
|
|
||||||
// we use ip addresses with 224.* to lookup their dns name in our table, to allow remote DNS resolution
|
// we use ip addresses with 224.* to lookup their dns name in our table, to allow remote DNS resolution
|
||||||
// the range 224-255.* is reserved, and it won't go outside (unless the app does some other stuff with
|
// the range 224-255.* is reserved, and it won't go outside (unless the app does some other stuff with
|
||||||
// the results returned from gethostbyname et al.)
|
// the results returned from gethostbyname et al.)
|
||||||
// the hardcoded number 224 can now be changed using the config option remote_dns_subnet to i.e. 127
|
if(ip.octet[0] == 224) {
|
||||||
if(ip.octet[0] == remote_dns_subnet) {
|
|
||||||
dns_name = string_from_internal_ip(ip);
|
dns_name = string_from_internal_ip(ip);
|
||||||
if(!dns_name)
|
if(!dns_name) goto err;
|
||||||
goto err;
|
|
||||||
dns_len = strlen(dns_name);
|
dns_len = strlen(dns_name);
|
||||||
if(!dns_len)
|
if(!dns_len) goto err;
|
||||||
goto err;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PDEBUG("host dns %s\n", dns_name ? dns_name : "<NULL>");
|
|
||||||
|
|
||||||
size_t ulen = strlen(user);
|
size_t ulen = strlen(user);
|
||||||
size_t passlen = strlen(pass);
|
size_t passlen = strlen(pass);
|
||||||
|
|
||||||
@ -272,26 +275,20 @@ static int tunnel_to(int sock, ip_type ip, unsigned short port, proxy_type pt, c
|
|||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t len;
|
int len;
|
||||||
unsigned char buff[BUFF_SIZE];
|
unsigned char buff[BUFF_SIZE];
|
||||||
char ip_buf[16];
|
|
||||||
//memset (buff, 0, sizeof(buff));
|
//memset (buff, 0, sizeof(buff));
|
||||||
|
|
||||||
switch(pt) {
|
switch(pt) {
|
||||||
case RAW_TYPE: {
|
|
||||||
return SUCCESS;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case HTTP_TYPE: {
|
case HTTP_TYPE: {
|
||||||
if(!dns_len) {
|
if(!dns_len)
|
||||||
inet_ntop(AF_INET, &ip.octet[0], ip_buf, sizeof(ip_buf));
|
dns_name = inet_ntoa( * (struct in_addr *) &ip.as_int);
|
||||||
dns_name = ip_buf;
|
|
||||||
}
|
|
||||||
|
|
||||||
snprintf((char *) buff, sizeof(buff), "CONNECT %s:%d HTTP/1.0\r\n", dns_name,
|
snprintf((char*)buff, sizeof(buff), "CONNECT %s:%d HTTP/1.0\r\n", dns_name, ntohs(port));
|
||||||
ntohs(port));
|
|
||||||
|
|
||||||
if(user[0]) {
|
if (user[0])
|
||||||
|
{
|
||||||
|
#define HTTP_AUTH_MAX ((0xFF * 2) + 1 + 1)
|
||||||
// 2 * 0xff: username and pass, plus 1 for ':' and 1 for zero terminator.
|
// 2 * 0xff: username and pass, plus 1 for ':' and 1 for zero terminator.
|
||||||
char src[HTTP_AUTH_MAX];
|
char src[HTTP_AUTH_MAX];
|
||||||
char dst[(4 * HTTP_AUTH_MAX)];
|
char dst[(4 * HTTP_AUTH_MAX)];
|
||||||
@ -305,12 +302,13 @@ static int tunnel_to(int sock, ip_type ip, unsigned short port, proxy_type pt, c
|
|||||||
strcat((char*)buff,"Proxy-Authorization: Basic ");
|
strcat((char*)buff,"Proxy-Authorization: Basic ");
|
||||||
strcat((char*)buff, dst);
|
strcat((char*)buff, dst);
|
||||||
strcat((char*)buff, "\r\n\r\n");
|
strcat((char*)buff, "\r\n\r\n");
|
||||||
} else
|
}
|
||||||
|
else
|
||||||
strcat((char*)buff, "\r\n");
|
strcat((char*)buff, "\r\n");
|
||||||
|
|
||||||
len = strlen((char*)buff);
|
len = strlen((char*)buff);
|
||||||
|
|
||||||
if(len != (size_t) send(sock, buff, len, 0))
|
if(len != send(sock, buff, len, 0))
|
||||||
goto err;
|
goto err;
|
||||||
|
|
||||||
len = 0 ;
|
len = 0 ;
|
||||||
@ -322,12 +320,17 @@ static int tunnel_to(int sock, ip_type ip, unsigned short port, proxy_type pt, c
|
|||||||
goto err;
|
goto err;
|
||||||
if (len > 4 &&
|
if (len > 4 &&
|
||||||
buff[len-1]=='\n' &&
|
buff[len-1]=='\n' &&
|
||||||
buff[len - 2] == '\r' && buff[len - 3] == '\n' && buff[len - 4] == '\r')
|
buff[len-2]=='\r' &&
|
||||||
|
buff[len-3]=='\n' &&
|
||||||
|
buff[len-4]=='\r' )
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// if not ok (200) or response greather than BUFF_SIZE return BLOCKED;
|
// if not ok (200) or response greather than BUFF_SIZE return BLOCKED;
|
||||||
if(len == BUFF_SIZE || !(buff[9] == '2' && buff[10] == '0' && buff[11] == '0'))
|
if (len == BUFF_SIZE ||
|
||||||
|
!( buff[9] =='2' &&
|
||||||
|
buff[10]=='0' &&
|
||||||
|
buff[11]=='0' ))
|
||||||
return BLOCKED;
|
return BLOCKED;
|
||||||
|
|
||||||
return SUCCESS;
|
return SUCCESS;
|
||||||
@ -378,7 +381,8 @@ static int tunnel_to(int sock, ip_type ip, unsigned short port, proxy_type pt, c
|
|||||||
buff[3]=2; /// auth method -> username / password
|
buff[3]=2; /// auth method -> username / password
|
||||||
if(4!=write_n_bytes(sock, (char*)buff, 4))
|
if(4!=write_n_bytes(sock, (char*)buff, 4))
|
||||||
goto err;
|
goto err;
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
buff[0]=5; //version
|
buff[0]=5; //version
|
||||||
buff[1]=1; //nomber of methods
|
buff[1]=1; //nomber of methods
|
||||||
buff[2]=0; // no auth method
|
buff[2]=0; // no auth method
|
||||||
@ -399,20 +403,19 @@ static int tunnel_to(int sock, ip_type ip, unsigned short port, proxy_type pt, c
|
|||||||
if (buff[1] == 2) {
|
if (buff[1] == 2) {
|
||||||
// authentication
|
// authentication
|
||||||
char in[2];
|
char in[2];
|
||||||
char out[515];
|
char out[515]; char* cur=out;
|
||||||
char *cur = out;
|
|
||||||
int c;
|
int c;
|
||||||
*cur++=1; // version
|
*cur++=1; // version
|
||||||
c = ulen & 0xFF;
|
c = ulen & 0xFF;
|
||||||
*cur++ = (char)c;
|
*cur++ = c;
|
||||||
memcpy(cur, user, (size_t)c);
|
memcpy(cur, user, c);
|
||||||
cur += c;
|
cur += c;
|
||||||
c = passlen & 0xFF;
|
c = passlen & 0xFF;
|
||||||
*cur++ = (char)c;
|
*cur++ = c;
|
||||||
memcpy(cur, pass, (size_t)c);
|
memcpy(cur, pass, c);
|
||||||
cur += c;
|
cur += c;
|
||||||
|
|
||||||
if((size_t)(cur - out) != write_n_bytes(sock, out, (size_t) (cur - out)))
|
if((cur-out) != write_n_bytes(sock, out, cur-out))
|
||||||
goto err;
|
goto err;
|
||||||
|
|
||||||
|
|
||||||
@ -425,7 +428,7 @@ static int tunnel_to(int sock, ip_type ip, unsigned short port, proxy_type pt, c
|
|||||||
return BLOCKED;
|
return BLOCKED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
size_t buff_iter = 0;
|
int buff_iter = 0;
|
||||||
buff[buff_iter++] = 5; // version
|
buff[buff_iter++] = 5; // version
|
||||||
buff[buff_iter++] = 1; // connect
|
buff[buff_iter++] = 1; // connect
|
||||||
buff[buff_iter++] = 0; // reserved
|
buff[buff_iter++] = 0; // reserved
|
||||||
@ -456,14 +459,9 @@ static int tunnel_to(int sock, ip_type ip, unsigned short port, proxy_type pt, c
|
|||||||
|
|
||||||
switch (buff[3]) {
|
switch (buff[3]) {
|
||||||
|
|
||||||
case 1:
|
case 1: len = 4; break;
|
||||||
len = 4;
|
case 4: len = 16; break;
|
||||||
break;
|
case 3: len = 0;
|
||||||
case 4:
|
|
||||||
len = 16;
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
len = 0;
|
|
||||||
if(1 != read_n_bytes(sock, (char*) &len, 1))
|
if(1 != read_n_bytes(sock, (char*) &len, 1))
|
||||||
goto err;
|
goto err;
|
||||||
break;
|
break;
|
||||||
@ -488,17 +486,18 @@ static int tunnel_to(int sock, ip_type ip, unsigned short port, proxy_type pt, c
|
|||||||
#define ST "Strict chain"
|
#define ST "Strict chain"
|
||||||
#define RT "Random chain"
|
#define RT "Random chain"
|
||||||
|
|
||||||
static int start_chain(int *fd, proxy_data * pd, char *begin_mark) {
|
static int start_chain(int *fd, proxy_data *pd, char* begin_mark)
|
||||||
|
{
|
||||||
struct sockaddr_in addr;
|
struct sockaddr_in addr;
|
||||||
char ip_buf[16];
|
|
||||||
|
|
||||||
*fd=socket(PF_INET,SOCK_STREAM,0);
|
*fd=socket(PF_INET,SOCK_STREAM,0);
|
||||||
if(*fd==-1)
|
if(*fd==-1)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
inet_ntop(AF_INET, &pd->ip.octet[0], ip_buf, sizeof(ip_buf));
|
|
||||||
proxychains_write_log(LOG_PREFIX "%s "TP" %s:%d ",
|
proxychains_write_log(LOG_PREFIX "%s "TP" %s:%d ",
|
||||||
begin_mark, ip_buf, htons(pd->port));
|
begin_mark,
|
||||||
|
inet_ntoa(*(struct in_addr*)&pd->ip),
|
||||||
|
htons(pd->port));
|
||||||
pd->ps=PLAY_STATE;
|
pd->ps=PLAY_STATE;
|
||||||
memset(&addr, 0, sizeof(addr));
|
memset(&addr, 0, sizeof(addr));
|
||||||
addr.sin_family = AF_INET;
|
addr.sin_family = AF_INET;
|
||||||
@ -518,31 +517,19 @@ static int start_chain(int *fd, proxy_data * pd, char *begin_mark) {
|
|||||||
return SOCKET_ERROR;
|
return SOCKET_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int get_rand_int(unsigned int range){
|
static proxy_data * select_proxy(select_type how,
|
||||||
static FILE *fp;
|
proxy_data *pd, unsigned int proxy_count, unsigned int *offset)
|
||||||
unsigned int randval;
|
{
|
||||||
if (!fp) {
|
|
||||||
fp = fopen("/dev/urandom", "r");
|
|
||||||
}
|
|
||||||
if(fread(&randval, sizeof(randval), 1, fp)) {
|
|
||||||
return (randval % range);
|
|
||||||
} else {
|
|
||||||
srand((unsigned int)time(NULL));
|
|
||||||
return ((unsigned int)rand() % range);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static proxy_data *select_proxy(select_type how, proxy_data * pd, unsigned int proxy_count, unsigned int *offset) {
|
|
||||||
unsigned int i=0, k=0;
|
unsigned int i=0, k=0;
|
||||||
|
|
||||||
if(*offset >= proxy_count)
|
if(*offset >= proxy_count)
|
||||||
return NULL;
|
return NULL;
|
||||||
switch(how) {
|
switch(how) {
|
||||||
case RANDOMLY:
|
case RANDOMLY:
|
||||||
|
srand(time(NULL));
|
||||||
do {
|
do {
|
||||||
k++;
|
k++;
|
||||||
i = 0 + get_rand_int(proxy_count);
|
i = 0 + (unsigned int) (proxy_count * 1.0 * rand()/
|
||||||
|
(RAND_MAX + 1.0));
|
||||||
} while (pd[i].ps != PLAY_STATE && k < proxy_count*100 );
|
} while (pd[i].ps != PLAY_STATE && k < proxy_count*100 );
|
||||||
break;
|
break;
|
||||||
case FIFOLY:
|
case FIFOLY:
|
||||||
@ -561,14 +548,16 @@ static proxy_data *select_proxy(select_type how, proxy_data * pd, unsigned int p
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void release_all(proxy_data * pd, unsigned int proxy_count) {
|
static void release_all(proxy_data *pd, unsigned int proxy_count)
|
||||||
|
{
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
for(i=0; i<proxy_count; i++)
|
for(i=0; i<proxy_count; i++)
|
||||||
pd[i].ps = PLAY_STATE;
|
pd[i].ps = PLAY_STATE;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void release_busy(proxy_data * pd, unsigned int proxy_count) {
|
static void release_busy(proxy_data *pd, unsigned int proxy_count)
|
||||||
|
{
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
for(i=0; i<proxy_count; i++)
|
for(i=0; i<proxy_count; i++)
|
||||||
if(pd[i].ps == BUSY_STATE)
|
if(pd[i].ps == BUSY_STATE)
|
||||||
@ -576,8 +565,10 @@ static void release_busy(proxy_data * pd, unsigned int proxy_count) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
static unsigned int calc_alive(proxy_data * pd, unsigned int proxy_count) {
|
static unsigned int calc_alive(proxy_data *pd, unsigned int proxy_count)
|
||||||
unsigned int i, alive_count = 0;
|
{
|
||||||
|
unsigned int i;
|
||||||
|
int alive_count=0;
|
||||||
release_busy(pd, proxy_count);
|
release_busy(pd, proxy_count);
|
||||||
for(i=0; i<proxy_count; i++)
|
for(i=0; i<proxy_count; i++)
|
||||||
if(pd[i].ps == PLAY_STATE)
|
if(pd[i].ps == PLAY_STATE)
|
||||||
@ -585,25 +576,28 @@ static unsigned int calc_alive(proxy_data * pd, unsigned int proxy_count) {
|
|||||||
return alive_count;
|
return alive_count;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int chain_step(int ns, proxy_data * pfrom, proxy_data * pto) {
|
|
||||||
|
static int chain_step(int ns, proxy_data *pfrom, proxy_data *pto)
|
||||||
|
{
|
||||||
int retcode=-1;
|
int retcode=-1;
|
||||||
char* hostname;
|
char* hostname;
|
||||||
char ip_buf[16];
|
#ifdef DEBUG
|
||||||
|
|
||||||
PDEBUG("chain_step()\n");
|
PDEBUG("chain_step()\n");
|
||||||
|
#endif
|
||||||
if(pto->ip.octet[0] == remote_dns_subnet) {
|
if(pto->ip.octet[0] == 224) {
|
||||||
hostname = string_from_internal_ip(pto->ip);
|
hostname = string_from_internal_ip(pto->ip);
|
||||||
if(!hostname)
|
if(!hostname) goto usenumericip;
|
||||||
goto usenumericip;
|
|
||||||
} else {
|
} else {
|
||||||
usenumericip:
|
usenumericip:
|
||||||
inet_ntop(AF_INET, &pto->ip.octet[0], ip_buf, sizeof(ip_buf));
|
hostname = inet_ntoa(*(struct in_addr*)&pto->ip);
|
||||||
hostname = ip_buf;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
proxychains_write_log(TP " %s:%d ", hostname, htons(pto->port));
|
proxychains_write_log(TP" %s:%d ",
|
||||||
retcode = tunnel_to(ns, pto->ip, pto->port, pfrom->pt, pfrom->user, pfrom->pass);
|
hostname,
|
||||||
|
htons(pto->port));
|
||||||
|
retcode =
|
||||||
|
tunnel_to(ns, pto->ip, pto->port, pfrom->pt, pfrom->user,
|
||||||
|
pfrom->pass);
|
||||||
switch(retcode) {
|
switch(retcode) {
|
||||||
case SUCCESS:
|
case SUCCESS:
|
||||||
pto->ps=BUSY_STATE;
|
pto->ps=BUSY_STATE;
|
||||||
@ -615,7 +609,7 @@ static int chain_step(int ns, proxy_data * pfrom, proxy_data * pto) {
|
|||||||
break;
|
break;
|
||||||
case SOCKET_ERROR:
|
case SOCKET_ERROR:
|
||||||
pto->ps=DOWN_STATE;
|
pto->ps=DOWN_STATE;
|
||||||
proxychains_write_log("<--socket error or timeout!\n");
|
proxychains_write_log("<--timeout\n");
|
||||||
close(ns);
|
close(ns);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -624,7 +618,8 @@ static int chain_step(int ns, proxy_data * pfrom, proxy_data * pto) {
|
|||||||
|
|
||||||
int connect_proxy_chain( int sock, ip_type target_ip,
|
int connect_proxy_chain( int sock, ip_type target_ip,
|
||||||
unsigned short target_port, proxy_data *pd,
|
unsigned short target_port, proxy_data *pd,
|
||||||
unsigned int proxy_count, chain_type ct, unsigned int max_chain) {
|
unsigned int proxy_count, chain_type ct, unsigned int max_chain )
|
||||||
|
{
|
||||||
proxy_data p4;
|
proxy_data p4;
|
||||||
proxy_data *p1,*p2,*p3;
|
proxy_data *p1,*p2,*p3;
|
||||||
int ns=-1;
|
int ns=-1;
|
||||||
@ -633,14 +628,15 @@ int connect_proxy_chain(int sock, ip_type target_ip,
|
|||||||
unsigned int curr_len=0;
|
unsigned int curr_len=0;
|
||||||
|
|
||||||
p3=&p4;
|
p3=&p4;
|
||||||
|
#ifdef DEBUG
|
||||||
PDEBUG("connect_proxy_chain\n");
|
PDEBUG("connect_proxy_chain\n");
|
||||||
|
#endif
|
||||||
|
|
||||||
again:
|
again:
|
||||||
|
|
||||||
switch(ct) {
|
switch(ct) {
|
||||||
case DYNAMIC_TYPE:
|
case DYNAMIC_TYPE:
|
||||||
calc_alive(pd, proxy_count);
|
alive_count = calc_alive(pd,proxy_count);
|
||||||
offset = 0;
|
offset = 0;
|
||||||
do {
|
do {
|
||||||
if(!(p1=select_proxy(FIFOLY,pd,proxy_count,&offset)))
|
if(!(p1=select_proxy(FIFOLY,pd,proxy_count,&offset)))
|
||||||
@ -651,7 +647,9 @@ int connect_proxy_chain(int sock, ip_type target_ip,
|
|||||||
if(!p2)
|
if(!p2)
|
||||||
break;
|
break;
|
||||||
if(SUCCESS!=chain_step(ns,p1,p2)) {
|
if(SUCCESS!=chain_step(ns,p1,p2)) {
|
||||||
|
#ifdef DEBUG
|
||||||
PDEBUG("GOTO AGAIN 1\n");
|
PDEBUG("GOTO AGAIN 1\n");
|
||||||
|
#endif
|
||||||
goto again;
|
goto again;
|
||||||
}
|
}
|
||||||
p1=p2;
|
p1=p2;
|
||||||
@ -664,21 +662,27 @@ int connect_proxy_chain(int sock, ip_type target_ip,
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case STRICT_TYPE:
|
case STRICT_TYPE:
|
||||||
calc_alive(pd, proxy_count);
|
alive_count = calc_alive(pd, proxy_count);
|
||||||
offset = 0;
|
offset = 0;
|
||||||
if(!(p1=select_proxy(FIFOLY, pd, proxy_count, &offset))) {
|
if(!(p1=select_proxy(FIFOLY, pd, proxy_count, &offset))) {
|
||||||
|
#ifdef DEBUG
|
||||||
PDEBUG("select_proxy failed\n");
|
PDEBUG("select_proxy failed\n");
|
||||||
|
#endif
|
||||||
goto error_strict;
|
goto error_strict;
|
||||||
}
|
}
|
||||||
if(SUCCESS!=start_chain(&ns, p1, ST)) {
|
if(SUCCESS!=start_chain(&ns, p1, ST)) {
|
||||||
|
#ifdef DEBUG
|
||||||
PDEBUG("start_chain failed\n");
|
PDEBUG("start_chain failed\n");
|
||||||
|
#endif
|
||||||
goto error_strict;
|
goto error_strict;
|
||||||
}
|
}
|
||||||
while(offset < proxy_count) {
|
while(offset < proxy_count) {
|
||||||
if(!(p2 = select_proxy(FIFOLY, pd, proxy_count, &offset)))
|
if(!(p2 = select_proxy(FIFOLY, pd, proxy_count, &offset)))
|
||||||
break;
|
break;
|
||||||
if(SUCCESS!=chain_step(ns, p1, p2)) {
|
if(SUCCESS!=chain_step(ns, p1, p2)) {
|
||||||
|
#ifdef DEBUG
|
||||||
PDEBUG("chain_step failed\n");
|
PDEBUG("chain_step failed\n");
|
||||||
|
#endif
|
||||||
goto error_strict;
|
goto error_strict;
|
||||||
}
|
}
|
||||||
p1 = p2;
|
p1 = p2;
|
||||||
@ -703,7 +707,9 @@ int connect_proxy_chain(int sock, ip_type target_ip,
|
|||||||
if(!(p2=select_proxy(RANDOMLY,pd,proxy_count,&offset)))
|
if(!(p2=select_proxy(RANDOMLY,pd,proxy_count,&offset)))
|
||||||
goto error_more;
|
goto error_more;
|
||||||
if(SUCCESS!=chain_step(ns, p1, p2)) {
|
if(SUCCESS!=chain_step(ns, p1, p2)) {
|
||||||
|
#ifdef DEBUG
|
||||||
PDEBUG("GOTO AGAIN 2\n");
|
PDEBUG("GOTO AGAIN 2\n");
|
||||||
|
#endif
|
||||||
goto again;
|
goto again;
|
||||||
}
|
}
|
||||||
p1 = p2;
|
p1 = p2;
|
||||||
@ -713,6 +719,7 @@ int connect_proxy_chain(int sock, ip_type target_ip,
|
|||||||
p3->port = target_port;
|
p3->port = target_port;
|
||||||
if(SUCCESS!=chain_step(ns,p1,p3))
|
if(SUCCESS!=chain_step(ns,p1,p3))
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
proxychains_write_log(TP" OK\n");
|
proxychains_write_log(TP" OK\n");
|
||||||
@ -728,8 +735,9 @@ int connect_proxy_chain(int sock, ip_type target_ip,
|
|||||||
error_more:
|
error_more:
|
||||||
proxychains_write_log("\n!!!need more proxies!!!\n");
|
proxychains_write_log("\n!!!need more proxies!!!\n");
|
||||||
error_strict:
|
error_strict:
|
||||||
|
#ifdef DEBUG
|
||||||
PDEBUG("error\n");
|
PDEBUG("error\n");
|
||||||
|
#endif
|
||||||
release_all(pd,proxy_count);
|
release_all(pd,proxy_count);
|
||||||
if(ns!=-1)
|
if(ns!=-1)
|
||||||
close(ns);
|
close(ns);
|
||||||
@ -737,37 +745,36 @@ int connect_proxy_chain(int sock, ip_type target_ip,
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: all those buffers aren't threadsafe, but since no memory allocation happens there shouldnt be any segfaults
|
||||||
|
static struct hostent hostent_space;
|
||||||
|
static in_addr_t resolved_addr;
|
||||||
|
static char* resolved_addr_p[2];
|
||||||
|
static char addr_name[1024*8];
|
||||||
static const ip_type local_host = {{127, 0, 0, 1}};
|
static const ip_type local_host = {{127, 0, 0, 1}};
|
||||||
|
struct hostent* proxy_gethostbyname(const char *name)
|
||||||
char hostname[256]; // default maximum length of hostname in linux
|
{
|
||||||
struct hostent *proxy_gethostbyname(const char *name, struct gethostbyname_data* data) {
|
|
||||||
char buff[256];
|
char buff[256];
|
||||||
uint32_t i, hash;
|
uint32_t i, hash;
|
||||||
// yep, new_mem never gets freed. once you passed a fake ip to the client, you can't "retreat" it
|
// yep, new_mem never gets freed. once you passed a fake ip to the client, you can't "retreat" it
|
||||||
void* new_mem;
|
void* new_mem;
|
||||||
size_t l;
|
size_t l;
|
||||||
|
|
||||||
struct hostent* hp;
|
struct hostent* hp;
|
||||||
|
|
||||||
data->resolved_addr_p[0] = (char *) &data->resolved_addr;
|
resolved_addr_p[0] = (char*) &resolved_addr;
|
||||||
data->resolved_addr_p[1] = NULL;
|
resolved_addr_p[1] = NULL;
|
||||||
|
|
||||||
data->hostent_space.h_addr_list = data->resolved_addr_p;
|
hostent_space.h_addr_list = resolved_addr_p;
|
||||||
|
|
||||||
data->resolved_addr = 0;
|
resolved_addr = 0;
|
||||||
|
|
||||||
gethostname(buff,sizeof(buff));
|
gethostname(buff,sizeof(buff));
|
||||||
|
|
||||||
if(!strcmp(buff, name)) {
|
if(!strcmp(buff, name)) {
|
||||||
data->resolved_addr = inet_addr(buff);
|
resolved_addr = inet_addr(buff);
|
||||||
if(data->resolved_addr == (in_addr_t) (-1))
|
if (resolved_addr == (in_addr_t) (-1))
|
||||||
data->resolved_addr = (in_addr_t) (local_host.as_int);
|
resolved_addr = (in_addr_t) (local_host.as_int);
|
||||||
|
return &hostent_space;
|
||||||
snprintf(hostname,sizeof hostname, "%s", name);
|
|
||||||
data->hostent_space.h_name = hostname;
|
|
||||||
data->hostent_space.h_length = sizeof (in_addr_t);
|
|
||||||
data->hostent_space.h_addrtype = AF_INET;
|
|
||||||
|
|
||||||
return &data->hostent_space;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
memset(buff, 0, sizeof(buff));
|
memset(buff, 0, sizeof(buff));
|
||||||
@ -776,15 +783,18 @@ struct hostent *proxy_gethostbyname(const char *name, struct gethostbyname_data*
|
|||||||
if (!strcmp(hp->h_name,name))
|
if (!strcmp(hp->h_name,name))
|
||||||
return hp;
|
return hp;
|
||||||
|
|
||||||
|
|
||||||
hash = dalias_hash((char*) name);
|
hash = dalias_hash((char*) name);
|
||||||
|
|
||||||
MUTEX_LOCK(&internal_ips_lock);
|
#ifdef THREAD_SAFE
|
||||||
|
pthread_mutex_lock(&internal_ips_lock);
|
||||||
|
#endif
|
||||||
|
|
||||||
// see if we already have this dns entry saved.
|
// see if we already have this dns entry saved.
|
||||||
if(internal_ips.counter) {
|
if(internal_ips.counter) {
|
||||||
for( i = 0; i < internal_ips.counter; i++) {
|
for( i = 0; i < internal_ips.counter; i++) {
|
||||||
if(internal_ips.list[i]->hash == hash && !strcmp(name, internal_ips.list[i]->string)) {
|
if(internal_ips.list[i]->hash == hash && !strcmp(name, internal_ips.list[i]->string)) {
|
||||||
data->resolved_addr = make_internal_ip(i);
|
resolved_addr = make_internal_ip(i);
|
||||||
PDEBUG("got cached ip for %s\n", name);
|
PDEBUG("got cached ip for %s\n", name);
|
||||||
goto have_ip;
|
goto have_ip;
|
||||||
}
|
}
|
||||||
@ -805,9 +815,8 @@ struct hostent *proxy_gethostbyname(const char *name, struct gethostbyname_data*
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
data->resolved_addr = make_internal_ip(internal_ips.counter);
|
resolved_addr = make_internal_ip(internal_ips.counter);
|
||||||
if(data->resolved_addr == (in_addr_t) - 1)
|
if(resolved_addr == (in_addr_t) -1) goto err_plus_unlock;
|
||||||
goto err_plus_unlock;
|
|
||||||
|
|
||||||
l = strlen(name);
|
l = strlen(name);
|
||||||
new_mem = malloc(sizeof(string_hash_tuple) + l + 1);
|
new_mem = malloc(sizeof(string_hash_tuple) + l + 1);
|
||||||
@ -818,7 +827,6 @@ struct hostent *proxy_gethostbyname(const char *name, struct gethostbyname_data*
|
|||||||
|
|
||||||
internal_ips.list[internal_ips.counter] = new_mem;
|
internal_ips.list[internal_ips.counter] = new_mem;
|
||||||
internal_ips.list[internal_ips.counter]->hash = hash;
|
internal_ips.list[internal_ips.counter]->hash = hash;
|
||||||
|
|
||||||
internal_ips.list[internal_ips.counter]->string = (char*) new_mem + sizeof(string_hash_tuple);
|
internal_ips.list[internal_ips.counter]->string = (char*) new_mem + sizeof(string_hash_tuple);
|
||||||
|
|
||||||
memcpy(internal_ips.list[internal_ips.counter]->string, name, l + 1);
|
memcpy(internal_ips.list[internal_ips.counter]->string, name, l + 1);
|
||||||
@ -827,110 +835,78 @@ struct hostent *proxy_gethostbyname(const char *name, struct gethostbyname_data*
|
|||||||
|
|
||||||
have_ip:
|
have_ip:
|
||||||
|
|
||||||
MUTEX_UNLOCK(&internal_ips_lock);
|
#ifdef THREAD_SAFE
|
||||||
|
pthread_mutex_unlock(&internal_ips_lock);
|
||||||
|
#endif
|
||||||
|
|
||||||
strncpy(data->addr_name, name, sizeof(data->addr_name) - 1);
|
|
||||||
|
|
||||||
data->hostent_space.h_name = data->addr_name;
|
strncpy(addr_name, name, sizeof(addr_name));
|
||||||
data->hostent_space.h_length = sizeof(in_addr_t);
|
|
||||||
data->hostent_space.h_addrtype = AF_INET;
|
|
||||||
|
|
||||||
return &data->hostent_space;
|
hostent_space.h_name = addr_name;
|
||||||
|
hostent_space.h_length = sizeof (in_addr_t);
|
||||||
|
return &hostent_space;
|
||||||
|
|
||||||
err_plus_unlock:
|
err_plus_unlock:
|
||||||
MUTEX_UNLOCK(&internal_ips_lock);
|
#ifdef THREAD_SAFE
|
||||||
|
pthread_mutex_unlock(&internal_ips_lock);
|
||||||
|
#endif
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
int proxy_getaddrinfo(const char *node, const char *service,
|
||||||
struct addrinfo_data {
|
const struct addrinfo *hints,
|
||||||
struct addrinfo addrinfo_space;
|
struct addrinfo **res)
|
||||||
struct sockaddr sockaddr_space;
|
|
||||||
char addr_name[256];
|
|
||||||
};
|
|
||||||
|
|
||||||
void proxy_freeaddrinfo(struct addrinfo *res) {
|
|
||||||
free(res);
|
|
||||||
}
|
|
||||||
|
|
||||||
void proxy_getservbyname(const char * service, struct servent *se_buf,
|
|
||||||
char * buf, size_t buf_len, struct servent **se_result)
|
|
||||||
{
|
{
|
||||||
|
|
||||||
#ifdef __linux__
|
|
||||||
getservbyname_r(service, NULL, se_buf, buf, buf_len, se_result);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef __APPLE__
|
|
||||||
struct servent *se;
|
|
||||||
|
|
||||||
MUTEX_LOCK(&internal_getsrvbyname_lock);
|
|
||||||
if(service) {
|
|
||||||
se = getservbyname(service, NULL);
|
|
||||||
|
|
||||||
if ( se != NULL ) {
|
|
||||||
memcpy(se_buf, se, buf_len);
|
|
||||||
*se_result = se_buf;
|
|
||||||
} else {
|
|
||||||
*se_result = NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
MUTEX_UNLOCK(&internal_getsrvbyname_lock);
|
|
||||||
#endif /* __APPLE__ */
|
|
||||||
}
|
|
||||||
|
|
||||||
int proxy_getaddrinfo(const char *node, const char *service, const struct addrinfo *hints, struct addrinfo **res) {
|
|
||||||
struct gethostbyname_data ghdata;
|
|
||||||
struct addrinfo_data *space;
|
|
||||||
struct servent *se = NULL;
|
struct servent *se = NULL;
|
||||||
struct hostent *hp = NULL;
|
struct hostent *hp = NULL;
|
||||||
struct servent se_buf;
|
struct sockaddr* sockaddr_space = NULL;
|
||||||
struct addrinfo *p;
|
struct addrinfo* addrinfo_space = NULL;
|
||||||
char buf[1024];
|
|
||||||
int port;
|
|
||||||
|
|
||||||
// printf("proxy_getaddrinfo node %s service %s\n",node,service);
|
// printf("proxy_getaddrinfo node %s service %s\n",node,service);
|
||||||
space = calloc(1, sizeof(struct addrinfo_data));
|
addrinfo_space = malloc(sizeof(struct addrinfo));
|
||||||
if(!space)
|
if(!addrinfo_space)
|
||||||
return 1;
|
goto err1;
|
||||||
|
sockaddr_space = malloc(sizeof(struct sockaddr));
|
||||||
if(node && !inet_aton(node, &((struct sockaddr_in *) &space->sockaddr_space)->sin_addr)) {
|
if(!sockaddr_space)
|
||||||
hp = proxy_gethostbyname(node, &ghdata);
|
goto err2;
|
||||||
if(hp) {
|
memset(sockaddr_space, 0, sizeof(*sockaddr_space));
|
||||||
memcpy(&((struct sockaddr_in *) &space->sockaddr_space)->sin_addr,
|
memset(addrinfo_space, 0, sizeof(*addrinfo_space));
|
||||||
*(hp->h_addr_list), sizeof(in_addr_t));
|
if (node &&
|
||||||
} else {
|
!inet_aton(node,&((struct sockaddr_in*)sockaddr_space)->sin_addr)) {
|
||||||
free(space);
|
hp = proxy_gethostbyname(node);
|
||||||
return 1;
|
if (hp)
|
||||||
}
|
memcpy(&((struct sockaddr_in*)sockaddr_space)->sin_addr,
|
||||||
|
*(hp->h_addr_list),
|
||||||
|
sizeof(in_addr_t));
|
||||||
|
else
|
||||||
|
goto err3;
|
||||||
}
|
}
|
||||||
if (service)
|
if (service)
|
||||||
proxy_getservbyname(service, &se_buf, buf, sizeof(buf), &se);
|
se = getservbyname(service, NULL);
|
||||||
|
|
||||||
port = se ? se->s_port : htons((uint16_t)atoi(service ? service : "0"));
|
if (!se) {
|
||||||
((struct sockaddr_in *) &space->sockaddr_space)->sin_port = (in_port_t)port;
|
((struct sockaddr_in*)sockaddr_space)->sin_port =
|
||||||
|
htons(atoi(service?:"0"));
|
||||||
|
} else
|
||||||
|
((struct sockaddr_in*)sockaddr_space)->sin_port = se->s_port;
|
||||||
|
|
||||||
*res = p = &space->addrinfo_space;
|
*res = addrinfo_space;
|
||||||
assert((size_t)p == (size_t) space);
|
(*res)->ai_addr = sockaddr_space;
|
||||||
|
|
||||||
p->ai_addr = &space->sockaddr_space;
|
|
||||||
if (node)
|
if (node)
|
||||||
strncpy(space->addr_name, node, sizeof(space->addr_name) - 1);
|
strcpy(addr_name, node);
|
||||||
p->ai_canonname = space->addr_name;
|
(*res)->ai_canonname = addr_name;
|
||||||
p->ai_next = NULL;
|
(*res)->ai_next = NULL;
|
||||||
p->ai_family = space->sockaddr_space.sa_family = AF_INET;
|
(*res)->ai_family = sockaddr_space->sa_family = AF_INET;
|
||||||
p->ai_addrlen = sizeof(space->sockaddr_space);
|
(*res)->ai_socktype = hints->ai_socktype;
|
||||||
|
(*res)->ai_flags = hints->ai_flags;
|
||||||
if(hints) {
|
(*res)->ai_protocol = hints->ai_protocol;
|
||||||
p->ai_socktype = hints->ai_socktype;
|
(*res)->ai_addrlen = sizeof(*sockaddr_space);
|
||||||
p->ai_flags = hints->ai_flags;
|
goto out;
|
||||||
p->ai_protocol = hints->ai_protocol;
|
err3:
|
||||||
} else {
|
free(sockaddr_space);
|
||||||
#ifdef BSD
|
err2:
|
||||||
p->ai_flags = (AI_V4MAPPED | AI_ADDRCONFIG);
|
free(addrinfo_space);
|
||||||
#else
|
err1:
|
||||||
p->ai_flags = (AI_ADDRCONFIG);
|
return 1;
|
||||||
#endif
|
out:
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
103
src/core.h
103
src/core.h
@ -4,8 +4,10 @@
|
|||||||
begin : Tue May 14 2002
|
begin : Tue May 14 2002
|
||||||
copyright : netcreature (C) 2002
|
copyright : netcreature (C) 2002
|
||||||
email : netcreature@users.sourceforge.net
|
email : netcreature@users.sourceforge.net
|
||||||
***************************************************************************
|
***************************************************************************/
|
||||||
***************************************************************************
|
#include <stdint.h>
|
||||||
|
/* GPL */
|
||||||
|
/***************************************************************************
|
||||||
* *
|
* *
|
||||||
* This program is free software; you can redistribute it and/or modify *
|
* 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 *
|
* it under the terms of the GNU General Public License as published by *
|
||||||
@ -13,14 +15,10 @@
|
|||||||
* (at your option) any later version. *
|
* (at your option) any later version. *
|
||||||
* *
|
* *
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
|
|
||||||
#include <stdint.h>
|
|
||||||
|
|
||||||
#ifndef __CORE_HEADER
|
#ifndef __CORE_HEADER
|
||||||
#define __CORE_HEADER
|
#define __CORE_HEADER
|
||||||
#define BUFF_SIZE 8*1024 // used to read responses from proxies.
|
#define BUFF_SIZE 8*1024 // used to read responses from proxies.
|
||||||
#define MAX_LOCALNET 64
|
#define MAX_LOCALNET 1024
|
||||||
#define MAX_DNAT 64
|
|
||||||
|
|
||||||
typedef union {
|
typedef union {
|
||||||
unsigned char octet[4];
|
unsigned char octet[4];
|
||||||
@ -39,20 +37,9 @@ typedef struct {
|
|||||||
} internal_ip_lookup_table;
|
} internal_ip_lookup_table;
|
||||||
|
|
||||||
extern internal_ip_lookup_table internal_ips;
|
extern internal_ip_lookup_table internal_ips;
|
||||||
|
|
||||||
#ifdef THREAD_SAFE
|
#ifdef THREAD_SAFE
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
|
|
||||||
extern pthread_mutex_t internal_ips_lock;
|
extern pthread_mutex_t internal_ips_lock;
|
||||||
extern pthread_mutex_t internal_getsrvbyname_lock;
|
|
||||||
|
|
||||||
# define MUTEX_LOCK(x) pthread_mutex_lock(x)
|
|
||||||
# define MUTEX_UNLOCK(x) pthread_mutex_unlock(x)
|
|
||||||
# define MUTEX_INIT(x,y) pthread_mutex_init(x, y)
|
|
||||||
#else
|
|
||||||
# define MUTEX_LOCK(x)
|
|
||||||
# define MUTEX_UNLOCK(x)
|
|
||||||
# define MUTEX_INIT(x,y)
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*error codes*/
|
/*error codes*/
|
||||||
@ -65,9 +52,9 @@ typedef enum {
|
|||||||
BLOCKED // target's port blocked on last proxy in the chain
|
BLOCKED // target's port blocked on last proxy in the chain
|
||||||
} ERR_CODE;
|
} ERR_CODE;
|
||||||
|
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
HTTP_TYPE,
|
HTTP_TYPE,
|
||||||
RAW_TYPE,
|
|
||||||
SOCKS4_TYPE,
|
SOCKS4_TYPE,
|
||||||
SOCKS5_TYPE
|
SOCKS5_TYPE
|
||||||
} proxy_type;
|
} proxy_type;
|
||||||
@ -95,11 +82,6 @@ typedef struct {
|
|||||||
unsigned short port;
|
unsigned short port;
|
||||||
} localaddr_arg;
|
} localaddr_arg;
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
struct in_addr orig_dst, new_dst;
|
|
||||||
unsigned short orig_port, new_port;
|
|
||||||
} dnat_arg;
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
ip_type ip;
|
ip_type ip;
|
||||||
unsigned short port;
|
unsigned short port;
|
||||||
@ -109,50 +91,61 @@ typedef struct {
|
|||||||
char pass[256];
|
char pass[256];
|
||||||
} proxy_data;
|
} proxy_data;
|
||||||
|
|
||||||
int connect_proxy_chain (int, ip_type, unsigned short, proxy_data *, unsigned int,
|
typedef struct {
|
||||||
chain_type, unsigned int);
|
proxy_data *pd;
|
||||||
|
chain_type ct;
|
||||||
|
unsigned int proxy_count;
|
||||||
|
int sock;
|
||||||
|
struct sockaddr addr;
|
||||||
|
int flags;
|
||||||
|
} thread_arg;
|
||||||
|
|
||||||
|
int connect_proxy_chain (
|
||||||
|
int sock,
|
||||||
|
ip_type target_ip,
|
||||||
|
unsigned short target_port,
|
||||||
|
proxy_data * pd,
|
||||||
|
unsigned int proxy_count,
|
||||||
|
chain_type ct,
|
||||||
|
unsigned int max_chain );
|
||||||
|
|
||||||
|
int proxychains_write_log(char *str,...);
|
||||||
|
struct hostent* proxy_gethostbyname(const char *name);
|
||||||
|
|
||||||
void proxychains_write_log(char *, ...);
|
|
||||||
|
|
||||||
typedef int (*connect_t)(int, const struct sockaddr *, socklen_t);
|
typedef int (*connect_t)(int, const struct sockaddr *, socklen_t);
|
||||||
|
connect_t true_connect;
|
||||||
|
|
||||||
typedef struct hostent* (*gethostbyname_t)(const char *);
|
typedef struct hostent* (*gethostbyname_t)(const char *);
|
||||||
typedef int (*freeaddrinfo_t)(struct addrinfo *);
|
gethostbyname_t true_gethostbyname;
|
||||||
|
|
||||||
#if (defined __linux__) || (defined __APPLE__)
|
typedef int (*getaddrinfo_t)(const char *, const char *,
|
||||||
typedef struct hostent *(*gethostbyaddr_t) (const void *, socklen_t, int);
|
const struct addrinfo *,
|
||||||
#else
|
|
||||||
typedef struct hostent *(*gethostbyaddr_t) (const char *, socklen_t, int);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
typedef int (*getaddrinfo_t)(const char *, const char *, const struct addrinfo *,
|
|
||||||
struct addrinfo **);
|
struct addrinfo **);
|
||||||
typedef int (*getnameinfo_t) (const struct sockaddr *, socklen_t, char *,
|
getaddrinfo_t true_getaddrinfo;
|
||||||
socklen_t, char *, socklen_t, int);
|
|
||||||
|
|
||||||
|
typedef int (*freeaddrinfo_t)(struct addrinfo *);
|
||||||
|
freeaddrinfo_t true_freeaddrinfo;
|
||||||
|
|
||||||
extern connect_t true_connect;
|
typedef int (*getnameinfo_t) (const struct sockaddr *,
|
||||||
extern gethostbyname_t true_gethostbyname;
|
socklen_t, char *,
|
||||||
extern getaddrinfo_t true_getaddrinfo;
|
socklen_t, char *,
|
||||||
extern freeaddrinfo_t true_freeaddrinfo;
|
socklen_t, unsigned int);
|
||||||
extern getnameinfo_t true_getnameinfo;
|
getnameinfo_t true_getnameinfo;
|
||||||
extern gethostbyaddr_t true_gethostbyaddr;
|
|
||||||
|
|
||||||
struct gethostbyname_data {
|
typedef struct hostent *(*gethostbyaddr_t) (const void *, socklen_t, int);
|
||||||
struct hostent hostent_space;
|
gethostbyaddr_t true_gethostbyaddr;
|
||||||
in_addr_t resolved_addr;
|
|
||||||
char *resolved_addr_p[2];
|
|
||||||
char addr_name[1024 * 8];
|
|
||||||
};
|
|
||||||
|
|
||||||
struct hostent* proxy_gethostbyname(const char *, struct gethostbyname_data *);
|
int proxy_getaddrinfo(const char *node, const char *service,
|
||||||
void proxy_getservbyname(const char *, struct servent *, char *, size_t, struct servent **);
|
const struct addrinfo *hints,
|
||||||
int proxy_getaddrinfo(const char *, const char *, const struct addrinfo *, struct addrinfo **);
|
struct addrinfo **res);
|
||||||
void proxy_freeaddrinfo(struct addrinfo *);
|
|
||||||
|
struct hostent* proxy_gethostbyname(const char *name);
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
# define PDEBUG(fmt, args...) do { fprintf(stderr,"DEBUG:"fmt, ## args); fflush(stderr); } while(0)
|
# define PDEBUG(fmt, args...) fprintf(stderr,"DEBUG:"fmt, ## args)
|
||||||
#else
|
#else
|
||||||
# define PDEBUG(fmt, args...) do {} while (0)
|
# define PDEBUG(fmt, args...)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -18,21 +18,20 @@
|
|||||||
#undef _GNU_SOURCE
|
#undef _GNU_SOURCE
|
||||||
#define _GNU_SOURCE
|
#define _GNU_SOURCE
|
||||||
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <sys/param.h>
|
|
||||||
|
|
||||||
#include <dlfcn.h>
|
|
||||||
#include <errno.h>
|
|
||||||
#include <fcntl.h>
|
|
||||||
#include <netdb.h>
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <unistd.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <errno.h>
|
||||||
|
#include <netdb.h>
|
||||||
|
|
||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
|
#include <sys/types.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <dlfcn.h>
|
||||||
|
|
||||||
|
|
||||||
#include "core.h"
|
#include "core.h"
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
@ -42,187 +41,183 @@
|
|||||||
#define SOCKADDR_2(x) (satosin(x)->sin_addr)
|
#define SOCKADDR_2(x) (satosin(x)->sin_addr)
|
||||||
#define SOCKPORT(x) (satosin(x)->sin_port)
|
#define SOCKPORT(x) (satosin(x)->sin_port)
|
||||||
#define SOCKFAMILY(x) (satosin(x)->sin_family)
|
#define SOCKFAMILY(x) (satosin(x)->sin_family)
|
||||||
#define MAX_CHAIN 512
|
#define MAX_CHAIN 30*1024
|
||||||
|
|
||||||
connect_t true_connect;
|
|
||||||
gethostbyname_t true_gethostbyname;
|
|
||||||
getaddrinfo_t true_getaddrinfo;
|
|
||||||
freeaddrinfo_t true_freeaddrinfo;
|
|
||||||
getnameinfo_t true_getnameinfo;
|
|
||||||
gethostbyaddr_t true_gethostbyaddr;
|
|
||||||
|
|
||||||
int tcp_read_time_out;
|
int tcp_read_time_out;
|
||||||
int tcp_connect_time_out;
|
int tcp_connect_time_out;
|
||||||
int proxychains_got_chain_data = 0;
|
|
||||||
int proxychains_quiet_mode = 0;
|
|
||||||
int proxychains_resolver = 0;
|
|
||||||
|
|
||||||
unsigned int proxychains_proxy_count = 0;
|
|
||||||
unsigned int proxychains_max_chain = 1;
|
|
||||||
unsigned int remote_dns_subnet = 224;
|
|
||||||
|
|
||||||
localaddr_arg localnet_addr[MAX_LOCALNET];
|
|
||||||
chain_type proxychains_ct;
|
chain_type proxychains_ct;
|
||||||
proxy_data proxychains_pd[MAX_CHAIN];
|
proxy_data proxychains_pd[MAX_CHAIN];
|
||||||
|
unsigned int proxychains_proxy_count = 0;
|
||||||
size_t num_localnet_addr = 0;
|
int proxychains_got_chain_data = 0;
|
||||||
dnat_arg dnats[MAX_DNAT];
|
unsigned int proxychains_max_chain = 1;
|
||||||
size_t num_dnats = 0;
|
int proxychains_quiet_mode = 0;
|
||||||
|
int proxychains_resolver = 0;
|
||||||
#ifdef THREAD_SAFE
|
|
||||||
pthread_once_t init_once = PTHREAD_ONCE_INIT;
|
|
||||||
#endif
|
|
||||||
static int init_l = 0;
|
static int init_l = 0;
|
||||||
|
localaddr_arg localnet_addr[MAX_LOCALNET];
|
||||||
|
size_t num_localnet_addr = 0;
|
||||||
|
|
||||||
static void load_default_settings(chain_type *ct);
|
static inline void get_chain_data(proxy_data *pd, unsigned int *proxy_count,
|
||||||
static inline void get_chain_data(proxy_data * pd, unsigned int *proxy_count, chain_type * ct);
|
chain_type *ct);
|
||||||
static void simple_socks5_env(proxy_data * pd, unsigned int *proxy_count, chain_type * ct);
|
static void init_lib(void);
|
||||||
|
|
||||||
static void* load_sym(char* symname, void* proxyfunc) {
|
static void init_lib(void)
|
||||||
|
{
|
||||||
void *funcptr = dlsym(RTLD_NEXT, symname);
|
#ifdef THREAD_SAFE
|
||||||
if(!funcptr) {
|
pthread_mutex_init(&internal_ips_lock, NULL);
|
||||||
fprintf(stderr, "Cannot load symbol '%s' %s\n", symname, dlerror());
|
|
||||||
exit(1);
|
|
||||||
} else {
|
|
||||||
PDEBUG("loaded symbol '%s'" " real addr %p wrapped addr %p\n", symname, funcptr, proxyfunc);
|
|
||||||
}
|
|
||||||
if(funcptr == proxyfunc) {
|
|
||||||
PDEBUG("circular reference detected, aborting!\n");
|
|
||||||
abort();
|
|
||||||
}
|
|
||||||
return funcptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
#define INIT() init_lib_wrapper(__FUNCTION__)
|
|
||||||
|
|
||||||
#define SETUP_SYM(X) do { true_ ## X = load_sym( # X, X ); } while(0)
|
|
||||||
|
|
||||||
static void do_init(void) {
|
|
||||||
MUTEX_INIT(&internal_ips_lock, NULL);
|
|
||||||
|
|
||||||
#ifdef __APPLE__
|
|
||||||
MUTEX_INIT(&internal_getsrvbyname_lock, NULL);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* check for simple SOCKS5 proxy setup */
|
|
||||||
simple_socks5_env(proxychains_pd, &proxychains_proxy_count, &proxychains_ct);
|
|
||||||
|
|
||||||
/* read the config file */
|
/* read the config file */
|
||||||
get_chain_data(proxychains_pd, &proxychains_proxy_count, &proxychains_ct);
|
get_chain_data(proxychains_pd, &proxychains_proxy_count, &proxychains_ct);
|
||||||
|
|
||||||
proxychains_write_log(LOG_PREFIX "DLL init\n");
|
proxychains_write_log(LOG_PREFIX "DLL init\n");
|
||||||
SETUP_SYM(connect);
|
|
||||||
SETUP_SYM(gethostbyname);
|
true_connect = (connect_t) dlsym(RTLD_NEXT, "connect");
|
||||||
SETUP_SYM(getaddrinfo);
|
|
||||||
SETUP_SYM(freeaddrinfo);
|
if (!true_connect) {
|
||||||
SETUP_SYM(gethostbyaddr);
|
fprintf(stderr, "Cannot load symbol 'connect' %s\n", dlerror());
|
||||||
SETUP_SYM(getnameinfo);
|
exit(1);
|
||||||
|
} else {
|
||||||
|
#ifdef DEBUG
|
||||||
|
PDEBUG( "loaded symbol 'connect'"
|
||||||
|
" real addr %p wrapped addr %p\n",
|
||||||
|
true_connect, connect);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
if(connect==true_connect) {
|
||||||
|
#ifdef DEBUG
|
||||||
|
PDEBUG("circular reference detected, aborting!\n");
|
||||||
|
#endif
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
|
||||||
|
true_gethostbyname = (gethostbyname_t)
|
||||||
|
dlsym(RTLD_NEXT, "gethostbyname");
|
||||||
|
|
||||||
|
if (!true_gethostbyname) {
|
||||||
|
fprintf(stderr, "Cannot load symbol 'gethostbyname' %s\n",
|
||||||
|
dlerror());
|
||||||
|
exit(1);
|
||||||
|
} else {
|
||||||
|
#ifdef DEBUG
|
||||||
|
PDEBUG( "loaded symbol 'gethostbyname'"
|
||||||
|
" real addr %p wrapped addr %p\n",
|
||||||
|
true_gethostbyname, gethostbyname);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
true_getaddrinfo = (getaddrinfo_t)
|
||||||
|
dlsym(RTLD_NEXT, "getaddrinfo");
|
||||||
|
|
||||||
|
if (!true_getaddrinfo) {
|
||||||
|
fprintf(stderr, "Cannot load symbol 'getaddrinfo' %s\n",
|
||||||
|
dlerror());
|
||||||
|
exit(1);
|
||||||
|
} else {
|
||||||
|
#ifdef DEBUG
|
||||||
|
PDEBUG( "loaded symbol 'getaddrinfo'"
|
||||||
|
" real addr %p wrapped addr %p\n",
|
||||||
|
true_getaddrinfo, getaddrinfo);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
true_freeaddrinfo = (freeaddrinfo_t)
|
||||||
|
dlsym(RTLD_NEXT, "freeaddrinfo");
|
||||||
|
|
||||||
|
if (!true_freeaddrinfo) {
|
||||||
|
fprintf(stderr, "Cannot load symbol 'freeaddrinfo' %s\n",
|
||||||
|
dlerror());
|
||||||
|
exit(1);
|
||||||
|
} else {
|
||||||
|
#ifdef DEBUG
|
||||||
|
PDEBUG( "loaded symbol 'freeaddrinfo'"
|
||||||
|
" real addr %p wrapped addr %p\n",
|
||||||
|
true_freeaddrinfo, freeaddrinfo);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
true_gethostbyaddr = (gethostbyaddr_t)
|
||||||
|
dlsym(RTLD_NEXT, "gethostbyaddr");
|
||||||
|
|
||||||
|
if (!true_gethostbyaddr) {
|
||||||
|
fprintf(stderr, "Cannot load symbol 'gethostbyaddr' %s\n",
|
||||||
|
dlerror());
|
||||||
|
exit(1);
|
||||||
|
} else {
|
||||||
|
#ifdef DEBUG
|
||||||
|
PDEBUG( "loaded symbol 'gethostbyaddr'"
|
||||||
|
" real addr %p wrapped addr %p\n",
|
||||||
|
true_gethostbyaddr, gethostbyaddr);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
true_getnameinfo = (getnameinfo_t)
|
||||||
|
dlsym(RTLD_NEXT, "getnameinfo");
|
||||||
|
|
||||||
|
if (!true_getnameinfo) {
|
||||||
|
fprintf(stderr, "Cannot load symbol 'getnameinfo' %s\n",
|
||||||
|
dlerror());
|
||||||
|
exit(1);
|
||||||
|
} else {
|
||||||
|
#ifdef DEBUG
|
||||||
|
PDEBUG( "loaded symbol 'getnameinfo'"
|
||||||
|
" real addr %p wrapped addr %p\n",
|
||||||
|
true_getnameinfo, getnameinfo);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
init_l = 1;
|
init_l = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void init_lib_wrapper(const char* caller) {
|
static inline void get_chain_data(
|
||||||
#ifndef DEBUG
|
proxy_data *pd,
|
||||||
(void) caller;
|
unsigned int *proxy_count,
|
||||||
#endif
|
chain_type *ct)
|
||||||
#ifndef THREAD_SAFE
|
{
|
||||||
if(init_l) return;
|
int count=0,port_n=0,list=0;
|
||||||
PDEBUG("%s called from %s\n", __FUNCTION__, caller);
|
|
||||||
do_init();
|
|
||||||
#else
|
|
||||||
if(!init_l) PDEBUG("%s called from %s\n", __FUNCTION__, caller);
|
|
||||||
pthread_once(&init_once, do_init);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
/* if we use gcc >= 3, we can instruct the dynamic loader
|
|
||||||
* to call init_lib at link time. otherwise it gets loaded
|
|
||||||
* lazily, which has the disadvantage that there's a potential
|
|
||||||
* race condition if 2 threads call it before init_l is set
|
|
||||||
* and PTHREAD support was disabled */
|
|
||||||
#if __GNUC__ > 2
|
|
||||||
__attribute__((constructor))
|
|
||||||
static void gcc_init(void) {
|
|
||||||
INIT();
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
FILE *
|
|
||||||
open_config_file() {
|
|
||||||
char home_conf[MAXPATHLEN], prefix_conf[MAXPATHLEN];
|
|
||||||
FILE *file;
|
|
||||||
|
|
||||||
snprintf(home_conf, 256, "%s/.proxychains/proxychains.conf", getenv("HOME"));
|
|
||||||
snprintf(prefix_conf, 256, "%s/etc/proxychains.conf", INSTALL_PREFIX);
|
|
||||||
|
|
||||||
if(!(file = fopen("./proxychains.conf", "r"))) {
|
|
||||||
if(!(file = fopen(home_conf, "r"))) {
|
|
||||||
if(!(file = fopen(prefix_conf, "r"))) {
|
|
||||||
if(!(file = fopen("/etc/proxychains.conf", "r"))) {
|
|
||||||
perror("Can't locate proxychains.conf");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return file;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* default settings common to get_chain_data and simple_socks5_env */
|
|
||||||
static void load_default_settings(chain_type *ct) {
|
|
||||||
char *env;
|
|
||||||
|
|
||||||
tcp_read_time_out = 4 * 1000;
|
|
||||||
tcp_connect_time_out = 10 * 1000;
|
|
||||||
*ct = DYNAMIC_TYPE;
|
|
||||||
|
|
||||||
env = getenv(PROXYCHAINS_QUIET_MODE_ENV_VAR);
|
|
||||||
if(env && *env == '1')
|
|
||||||
proxychains_quiet_mode = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* get configuration from config file */
|
|
||||||
static void get_chain_data(proxy_data * pd, unsigned int *proxy_count, chain_type * ct) {
|
|
||||||
unsigned int count = 0;
|
|
||||||
int port_n = 0, list = 0;
|
|
||||||
char buff[1024],type[1024],host[1024],user[1024];
|
char buff[1024],type[1024],host[1024],user[1024];
|
||||||
char *env;
|
char *env;
|
||||||
char local_in_addr_port[32];
|
char local_in_addr_port[32];
|
||||||
char local_in_addr[32], local_in_port[32], local_netmask[32];
|
char local_in_addr[32], local_in_port[32], local_netmask[32];
|
||||||
char dnat_orig_addr_port[32], dnat_new_addr_port[32];
|
FILE* file;
|
||||||
char dnat_orig_addr[32], dnat_orig_port[32], dnat_new_addr[32], dnat_new_port[32];
|
|
||||||
FILE *file = NULL;
|
|
||||||
|
|
||||||
if(proxychains_got_chain_data)
|
if(proxychains_got_chain_data)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
load_default_settings(ct);
|
//Some defaults
|
||||||
|
tcp_read_time_out = 4*1000;
|
||||||
|
tcp_connect_time_out = 10*1000;
|
||||||
|
*ct = DYNAMIC_TYPE;
|
||||||
|
|
||||||
env = get_config_path(getenv(PROXYCHAINS_CONF_FILE_ENV_VAR), buff, sizeof(buff));
|
/*
|
||||||
file = fopen(env, "r");
|
* Get path to configuration file from env this file has priority
|
||||||
|
* if it's defined.
|
||||||
|
*/
|
||||||
|
env = getenv(PROXYCHAINS_CONF_FILE_ENV_VAR);
|
||||||
|
|
||||||
|
snprintf(buff,256,"%s/.proxychains/proxychains.conf",getenv("HOME"));
|
||||||
|
|
||||||
|
if(!env || (!(file=fopen(env,"r"))))
|
||||||
|
if(!(file=fopen("./proxychains.conf","r")))
|
||||||
|
if(!(file=fopen(buff,"r")))
|
||||||
|
if(!(file=fopen("/etc/proxychains.conf","r")))
|
||||||
|
{
|
||||||
|
perror("Can't locate proxychains.conf");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
env = getenv(PROXYCHAINS_QUIET_MODE_ENV_VAR);
|
||||||
|
if(env && *env == '1') proxychains_quiet_mode = 1;
|
||||||
|
|
||||||
while(fgets(buff,sizeof(buff),file)) {
|
while(fgets(buff,sizeof(buff),file)) {
|
||||||
if(buff[0] != '\n' && buff[strspn(buff," ")]!='#') {
|
if(buff[0] != '\n' && buff[strspn(buff," ")]!='#') {
|
||||||
/* proxylist has to come last */
|
|
||||||
if(list) {
|
if(list) {
|
||||||
if(count >= MAX_CHAIN)
|
|
||||||
break;
|
|
||||||
|
|
||||||
memset(&pd[count], 0, sizeof(proxy_data));
|
memset(&pd[count], 0, sizeof(proxy_data));
|
||||||
|
|
||||||
pd[count].ps = PLAY_STATE;
|
pd[count].ps = PLAY_STATE;
|
||||||
port_n = 0;
|
port_n = 0;
|
||||||
|
|
||||||
sscanf(buff, "%s %s %d %s %s", type, host, &port_n, pd[count].user, pd[count].pass);
|
sscanf(buff,"%s %s %d %s %s", type, host, &port_n,
|
||||||
|
pd[count].user, pd[count].pass);
|
||||||
|
|
||||||
pd[count].ip.as_int = (uint32_t) inet_addr(host);
|
pd[count].ip.as_int = (uint32_t) inet_addr(host);
|
||||||
pd[count].port = htons((unsigned short)port_n);
|
pd[count].port = htons((unsigned short)port_n);
|
||||||
|
|
||||||
if(!strcmp(type,"http")) {
|
if(!strcmp(type,"http")) {
|
||||||
pd[count].pt = HTTP_TYPE;
|
pd[count].pt = HTTP_TYPE;
|
||||||
} else if(!strcmp(type, "raw")) {
|
|
||||||
pd[count].pt = RAW_TYPE;
|
|
||||||
} else if(!strcmp(type,"socks4")) {
|
} else if(!strcmp(type,"socks4")) {
|
||||||
pd[count].pt = SOCKS4_TYPE;
|
pd[count].pt = SOCKS4_TYPE;
|
||||||
} else if(!strcmp(type,"socks5")) {
|
} else if(!strcmp(type,"socks5")) {
|
||||||
@ -230,8 +225,10 @@ static void get_chain_data(proxy_data * pd, unsigned int *proxy_count, chain_typ
|
|||||||
} else
|
} else
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if(pd[count].ip.as_int && port_n && pd[count].ip.as_int != (uint32_t) - 1)
|
if(pd[count].ip.as_int && port_n &&
|
||||||
count++;
|
pd[count].ip.as_int != (uint32_t) -1)
|
||||||
|
if(++count==MAX_CHAIN)
|
||||||
|
break;
|
||||||
} else {
|
} else {
|
||||||
if(strstr(buff,"[ProxyList]")) {
|
if(strstr(buff,"[ProxyList]")) {
|
||||||
list=1;
|
list=1;
|
||||||
@ -245,113 +242,59 @@ static void get_chain_data(proxy_data * pd, unsigned int *proxy_count, chain_typ
|
|||||||
sscanf(buff,"%s %d",user,&tcp_read_time_out) ;
|
sscanf(buff,"%s %d",user,&tcp_read_time_out) ;
|
||||||
} else if(strstr(buff,"tcp_connect_time_out")){
|
} else if(strstr(buff,"tcp_connect_time_out")){
|
||||||
sscanf(buff,"%s %d",user,&tcp_connect_time_out) ;
|
sscanf(buff,"%s %d",user,&tcp_connect_time_out) ;
|
||||||
} else if(strstr(buff, "remote_dns_subnet")) {
|
|
||||||
sscanf(buff, "%s %d", user, &remote_dns_subnet);
|
|
||||||
if(remote_dns_subnet >= 256) {
|
|
||||||
fprintf(stderr,
|
|
||||||
"remote_dns_subnet: invalid value. requires a number between 0 and 255.\n");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
} else if(strstr(buff,"localnet")) {
|
} else if(strstr(buff,"localnet")) {
|
||||||
if(sscanf(buff, "%s %21[^/]/%15s", user, local_in_addr_port, local_netmask) < 3) {
|
if (sscanf(buff,"%s %21[^/]/%15s", user,
|
||||||
|
local_in_addr_port, local_netmask) < 3) {
|
||||||
fprintf(stderr, "localnet format error");
|
fprintf(stderr, "localnet format error");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
/* clean previously used buffer */
|
/* clean previously used buffer */
|
||||||
memset(local_in_port, 0, sizeof(local_in_port) / sizeof(local_in_port[0]));
|
memset(local_in_port, 0,
|
||||||
|
sizeof(local_in_port) / sizeof(local_in_port[0]));
|
||||||
|
|
||||||
if(sscanf(local_in_addr_port, "%15[^:]:%5s", local_in_addr, local_in_port) < 2) {
|
if (sscanf(local_in_addr_port, "%15[^:]:%5s",
|
||||||
PDEBUG("added localnet: netaddr=%s, netmask=%s\n",
|
local_in_addr, local_in_port) < 2) {
|
||||||
|
PDEBUG("added localnet: netaddr=%s, port=%s\n",
|
||||||
local_in_addr, local_netmask);
|
local_in_addr, local_netmask);
|
||||||
} else {
|
} else {
|
||||||
PDEBUG("added localnet: netaddr=%s, port=%s, netmask=%s\n",
|
PDEBUG("added localnet: netaddr=%s, port=%s, netmask=%s\n",
|
||||||
local_in_addr, local_in_port, local_netmask);
|
local_in_addr, local_in_port, local_netmask);
|
||||||
}
|
}
|
||||||
if(num_localnet_addr < MAX_LOCALNET) {
|
if (num_localnet_addr < MAX_LOCALNET)
|
||||||
|
{
|
||||||
int error;
|
int error;
|
||||||
error =
|
error = inet_pton(AF_INET, local_in_addr, &localnet_addr[num_localnet_addr].in_addr);
|
||||||
inet_pton(AF_INET, local_in_addr,
|
if (error <= 0)
|
||||||
&localnet_addr[num_localnet_addr].in_addr);
|
{
|
||||||
if(error <= 0) {
|
|
||||||
fprintf(stderr, "localnet address error\n");
|
fprintf(stderr, "localnet address error\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
error =
|
error = inet_pton(AF_INET, local_netmask, &localnet_addr[num_localnet_addr].netmask);
|
||||||
inet_pton(AF_INET, local_netmask,
|
if (error <= 0)
|
||||||
&localnet_addr[num_localnet_addr].netmask);
|
{
|
||||||
if(error <= 0) {
|
|
||||||
fprintf(stderr, "localnet netmask error\n");
|
fprintf(stderr, "localnet netmask error\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
if (local_in_port[0]) {
|
if (local_in_port[0]) {
|
||||||
localnet_addr[num_localnet_addr].port =
|
localnet_addr[num_localnet_addr].port = (short)atoi(local_in_port);
|
||||||
(unsigned short) atoi(local_in_port);
|
|
||||||
} else {
|
} else {
|
||||||
localnet_addr[num_localnet_addr].port = 0;
|
localnet_addr[num_localnet_addr].port = 0;
|
||||||
}
|
}
|
||||||
++num_localnet_addr;
|
++num_localnet_addr;
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
fprintf(stderr, "# of localnet exceed %d.\n", MAX_LOCALNET);
|
fprintf(stderr, "# of localnet exceed %d.\n", MAX_LOCALNET);
|
||||||
}
|
}
|
||||||
} else if(strstr(buff,"chain_len")){
|
} else if(strstr(buff,"chain_len")){
|
||||||
char *pc;
|
char *pc;int len;
|
||||||
int len;
|
|
||||||
pc=strchr(buff,'=');
|
pc=strchr(buff,'=');
|
||||||
len=atoi(++pc);
|
len=atoi(++pc);
|
||||||
proxychains_max_chain = (unsigned int) (len ? len : 1);
|
proxychains_max_chain=(len?len:1);
|
||||||
} else if(strstr(buff,"quiet_mode")){
|
} else if(strstr(buff,"quiet_mode")){
|
||||||
proxychains_quiet_mode=1;
|
proxychains_quiet_mode=1;
|
||||||
} else if(strstr(buff,"proxy_dns")){
|
} else if(strstr(buff,"proxy_dns")){
|
||||||
proxychains_resolver=1;
|
proxychains_resolver=1;
|
||||||
} else if(strstr(buff, "dnat")) {
|
|
||||||
if(sscanf(buff, "%s %21[^ ] %21s\n", user, dnat_orig_addr_port, dnat_new_addr_port) < 3) {
|
|
||||||
fprintf(stderr, "dnat format error");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
/* clean previously used buffer */
|
|
||||||
memset(dnat_orig_port, 0, sizeof(dnat_orig_port) / sizeof(dnat_orig_port[0]));
|
|
||||||
memset(dnat_new_port, 0, sizeof(dnat_new_port) / sizeof(dnat_new_port[0]));
|
|
||||||
|
|
||||||
(void)sscanf(dnat_orig_addr_port, "%15[^:]:%5s", dnat_orig_addr, dnat_orig_port);
|
|
||||||
(void)sscanf(dnat_new_addr_port, "%15[^:]:%5s", dnat_new_addr, dnat_new_port);
|
|
||||||
|
|
||||||
if(num_dnats < MAX_DNAT) {
|
|
||||||
int error;
|
|
||||||
error =
|
|
||||||
inet_pton(AF_INET, dnat_orig_addr,
|
|
||||||
&dnats[num_dnats].orig_dst);
|
|
||||||
if(error <= 0) {
|
|
||||||
fprintf(stderr, "dnat original destination address error\n");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
error =
|
|
||||||
inet_pton(AF_INET, dnat_new_addr,
|
|
||||||
&dnats[num_dnats].new_dst);
|
|
||||||
if(error <= 0) {
|
|
||||||
fprintf(stderr, "dnat effective destination address error\n");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(dnat_orig_port[0]) {
|
|
||||||
dnats[num_dnats].orig_port =
|
|
||||||
(unsigned short) atoi(dnat_orig_port);
|
|
||||||
} else {
|
|
||||||
dnats[num_dnats].orig_port = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(dnat_new_port[0]) {
|
|
||||||
dnats[num_dnats].new_port =
|
|
||||||
(unsigned short) atoi(dnat_new_port);
|
|
||||||
} else {
|
|
||||||
dnats[num_dnats].new_port = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
PDEBUG("added dnat: orig-dst=%s orig-port=%d new-dst=%s new-port=%d\n", dnat_orig_addr, dnats[num_dnats].orig_port, dnat_new_addr, dnats[num_dnats].new_port);
|
|
||||||
++num_dnats;
|
|
||||||
} else {
|
|
||||||
fprintf(stderr, "# of dnat exceed %d.\n", MAX_DNAT);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -361,43 +304,10 @@ static void get_chain_data(proxy_data * pd, unsigned int *proxy_count, chain_typ
|
|||||||
proxychains_got_chain_data = 1;
|
proxychains_got_chain_data = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void simple_socks5_env(proxy_data *pd, unsigned int *proxy_count, chain_type *ct) {
|
|
||||||
char *port_string;
|
|
||||||
char *host_string;
|
|
||||||
|
|
||||||
if(proxychains_got_chain_data)
|
|
||||||
return;
|
|
||||||
|
|
||||||
load_default_settings(ct);
|
int connect (int sock, const struct sockaddr *addr, unsigned int len)
|
||||||
|
{
|
||||||
port_string = getenv(PROXYCHAINS_SOCKS5_PORT_ENV_VAR);
|
|
||||||
|
|
||||||
if(!port_string)
|
|
||||||
return;
|
|
||||||
|
|
||||||
host_string = getenv(PROXYCHAINS_SOCKS5_HOST_ENV_VAR);
|
|
||||||
|
|
||||||
if(!host_string)
|
|
||||||
host_string = "127.0.0.1";
|
|
||||||
|
|
||||||
memset(pd, 0, sizeof(proxy_data));
|
|
||||||
|
|
||||||
pd[0].ps = PLAY_STATE;
|
|
||||||
pd[0].ip.as_int = (uint32_t) inet_addr(host_string);
|
|
||||||
pd[0].port = htons((unsigned short) strtol(port_string, NULL, 0));
|
|
||||||
pd[0].pt = SOCKS5_TYPE;
|
|
||||||
proxychains_max_chain = 1;
|
|
||||||
|
|
||||||
if(getenv(PROXYCHAINS_DNS_ENV_VAR))
|
|
||||||
proxychains_resolver = 1;
|
|
||||||
|
|
||||||
*proxy_count = 1;
|
|
||||||
proxychains_got_chain_data = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/******* HOOK FUNCTIONS *******/
|
|
||||||
|
|
||||||
int connect(int sock, const struct sockaddr *addr, socklen_t len) {
|
|
||||||
int socktype=0, flags=0, ret=0;
|
int socktype=0, flags=0, ret=0;
|
||||||
socklen_t optlen = 0;
|
socklen_t optlen = 0;
|
||||||
ip_type dest_ip;
|
ip_type dest_ip;
|
||||||
@ -405,13 +315,11 @@ int connect(int sock, const struct sockaddr *addr, socklen_t len) {
|
|||||||
char str[256];
|
char str[256];
|
||||||
#endif
|
#endif
|
||||||
struct in_addr *p_addr_in;
|
struct in_addr *p_addr_in;
|
||||||
struct sockaddr_in new_addr;
|
|
||||||
dnat_arg *dnat = NULL;
|
|
||||||
unsigned short port;
|
unsigned short port;
|
||||||
size_t i;
|
size_t i;
|
||||||
int remote_dns_connect = 0;
|
|
||||||
|
|
||||||
INIT();
|
if(!init_l)
|
||||||
|
init_lib();
|
||||||
optlen=sizeof(socktype);
|
optlen=sizeof(socktype);
|
||||||
getsockopt(sock,SOL_SOCKET,SO_TYPE,&socktype,&optlen);
|
getsockopt(sock,SOL_SOCKET,SO_TYPE,&socktype,&optlen);
|
||||||
if (! (SOCKFAMILY(*addr)==AF_INET && socktype==SOCK_STREAM))
|
if (! (SOCKFAMILY(*addr)==AF_INET && socktype==SOCK_STREAM))
|
||||||
@ -426,37 +334,11 @@ int connect(int sock, const struct sockaddr *addr, socklen_t len) {
|
|||||||
PDEBUG("target: %s\n", inet_ntop(AF_INET, p_addr_in, str, sizeof(str)));
|
PDEBUG("target: %s\n", inet_ntop(AF_INET, p_addr_in, str, sizeof(str)));
|
||||||
PDEBUG("port: %d\n", port);
|
PDEBUG("port: %d\n", port);
|
||||||
#endif
|
#endif
|
||||||
|
for (i = 0; i < num_localnet_addr; i++) {
|
||||||
// check if connect called from proxydns
|
|
||||||
remote_dns_connect = (ntohl(p_addr_in->s_addr) >> 24 == remote_dns_subnet);
|
|
||||||
|
|
||||||
// more specific first
|
|
||||||
for(i = 0; i < num_dnats && !remote_dns_connect && !dnat; i++)
|
|
||||||
if(dnats[i].orig_dst.s_addr == p_addr_in->s_addr)
|
|
||||||
if(dnats[i].orig_port && (dnats[i].orig_port == port))
|
|
||||||
dnat = &dnats[i];
|
|
||||||
|
|
||||||
for(i = 0; i < num_dnats && !remote_dns_connect && !dnat; i++)
|
|
||||||
if(dnats[i].orig_dst.s_addr == p_addr_in->s_addr)
|
|
||||||
if(!dnats[i].orig_port)
|
|
||||||
dnat = &dnats[i];
|
|
||||||
|
|
||||||
if (dnat) {
|
|
||||||
if (dnat->new_port)
|
|
||||||
new_addr.sin_port = htons(dnat->new_port);
|
|
||||||
else
|
|
||||||
new_addr.sin_port = htons(port);
|
|
||||||
new_addr.sin_addr = dnat->new_dst;
|
|
||||||
|
|
||||||
addr = (struct sockaddr *)&new_addr;
|
|
||||||
p_addr_in = &((struct sockaddr_in *) addr)->sin_addr;
|
|
||||||
port = ntohs(((struct sockaddr_in *) addr)->sin_port);
|
|
||||||
}
|
|
||||||
|
|
||||||
for(i = 0; i < num_localnet_addr && !remote_dns_connect; i++) {
|
|
||||||
if ((localnet_addr[i].in_addr.s_addr & localnet_addr[i].netmask.s_addr)
|
if ((localnet_addr[i].in_addr.s_addr & localnet_addr[i].netmask.s_addr)
|
||||||
== (p_addr_in->s_addr & localnet_addr[i].netmask.s_addr)) {
|
== (p_addr_in->s_addr & localnet_addr[i].netmask.s_addr))
|
||||||
if(!localnet_addr[i].port || localnet_addr[i].port == port) {
|
{
|
||||||
|
if (localnet_addr[i].port || localnet_addr[i].port == port) {
|
||||||
PDEBUG("accessing localnet using true_connect\n");
|
PDEBUG("accessing localnet using true_connect\n");
|
||||||
return true_connect(sock,addr,len);
|
return true_connect(sock,addr,len);
|
||||||
}
|
}
|
||||||
@ -469,10 +351,14 @@ int connect(int sock, const struct sockaddr *addr, socklen_t len) {
|
|||||||
|
|
||||||
dest_ip.as_int = SOCKADDR(*addr);
|
dest_ip.as_int = SOCKADDR(*addr);
|
||||||
|
|
||||||
ret = connect_proxy_chain(sock,
|
ret = connect_proxy_chain(
|
||||||
|
sock,
|
||||||
dest_ip,
|
dest_ip,
|
||||||
SOCKPORT(*addr),
|
SOCKPORT(*addr),
|
||||||
proxychains_pd, proxychains_proxy_count, proxychains_ct, proxychains_max_chain);
|
proxychains_pd,
|
||||||
|
proxychains_proxy_count,
|
||||||
|
proxychains_ct,
|
||||||
|
proxychains_max_chain );
|
||||||
|
|
||||||
fcntl(sock, F_SETFL, flags);
|
fcntl(sock, F_SETFL, flags);
|
||||||
if(ret != SUCCESS)
|
if(ret != SUCCESS)
|
||||||
@ -480,24 +366,29 @@ int connect(int sock, const struct sockaddr *addr, socklen_t len) {
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct gethostbyname_data ghbndata;
|
struct hostent *gethostbyname(const char *name)
|
||||||
struct hostent *gethostbyname(const char *name) {
|
{
|
||||||
INIT();
|
if(!init_l)
|
||||||
|
init_lib();
|
||||||
|
|
||||||
PDEBUG("gethostbyname: %s\n",name);
|
PDEBUG("gethostbyname: %s\n",name);
|
||||||
|
|
||||||
if(proxychains_resolver)
|
if(proxychains_resolver)
|
||||||
return proxy_gethostbyname(name, &ghbndata);
|
return proxy_gethostbyname(name);
|
||||||
else
|
else
|
||||||
return true_gethostbyname(name);
|
return true_gethostbyname(name);
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
int getaddrinfo(const char *node, const char *service, const struct addrinfo *hints, struct addrinfo **res) {
|
int getaddrinfo(const char *node, const char *service,
|
||||||
|
const struct addrinfo *hints,
|
||||||
|
struct addrinfo **res)
|
||||||
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
INIT();
|
if(!init_l)
|
||||||
|
init_lib();
|
||||||
|
|
||||||
PDEBUG("getaddrinfo: %s %s\n",node ,service);
|
PDEBUG("getaddrinfo: %s %s\n",node ,service);
|
||||||
|
|
||||||
@ -509,59 +400,85 @@ int getaddrinfo(const char *node, const char *service, const struct addrinfo *hi
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void freeaddrinfo(struct addrinfo *res) {
|
void freeaddrinfo(struct addrinfo *res)
|
||||||
INIT();
|
{
|
||||||
|
if(!init_l)
|
||||||
|
init_lib();
|
||||||
|
|
||||||
PDEBUG("freeaddrinfo %p \n",res);
|
PDEBUG("freeaddrinfo %p \n",res);
|
||||||
|
|
||||||
if(!proxychains_resolver)
|
if(!proxychains_resolver)
|
||||||
true_freeaddrinfo(res);
|
true_freeaddrinfo(res);
|
||||||
else
|
else {
|
||||||
proxy_freeaddrinfo(res);
|
free(res->ai_addr);
|
||||||
|
free(res);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// work around a buggy prototype in GLIBC. according to the bugtracker it has been fixed in git at 02 May 2011.
|
// work around a buggy prototype in GLIBC. according to the bugtracker it has been fixed in git at 02 May 2011.
|
||||||
// 2.14 came out in June 2011 so that should be the first fixed version
|
// 2.14 came out in June 2011 so that should be the first fixed version
|
||||||
#if defined(__GLIBC__) && (__GLIBC__ < 3) && (__GLIBC_MINOR__ < 14)
|
#if defined(__GLIBC__) && (__GLIBC__ < 3) && (__GLIBC_MINOR__ < 14)
|
||||||
int getnameinfo (const struct sockaddr * sa,
|
int getnameinfo (const struct sockaddr * sa,
|
||||||
socklen_t salen, char *host, socklen_t hostlen, char *serv, socklen_t servlen, unsigned int flags)
|
socklen_t salen, char * host,
|
||||||
|
socklen_t hostlen, char * serv,
|
||||||
|
socklen_t servlen, unsigned int flags)
|
||||||
#else
|
#else
|
||||||
int getnameinfo (const struct sockaddr * sa,
|
int getnameinfo (const struct sockaddr * sa,
|
||||||
socklen_t salen, char *host, socklen_t hostlen, char *serv, socklen_t servlen, int flags)
|
socklen_t salen, char * host,
|
||||||
|
socklen_t hostlen, char * serv,
|
||||||
|
socklen_t servlen, int flags)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
char ip_buf[16];
|
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
INIT();
|
if(!init_l)
|
||||||
|
init_lib();
|
||||||
|
|
||||||
PDEBUG("getnameinfo: %s %s\n", host, serv);
|
PDEBUG("getnameinfo: %s %s\n", host, serv);
|
||||||
|
|
||||||
if(!proxychains_resolver) {
|
if(!proxychains_resolver) {
|
||||||
ret = true_getnameinfo(sa, salen, host, hostlen, serv, servlen, flags);
|
ret = true_getnameinfo(sa,salen,host,hostlen,
|
||||||
|
serv,servlen,flags);
|
||||||
} else {
|
} else {
|
||||||
if(hostlen) {
|
if(hostlen)
|
||||||
inet_ntop(AF_INET, (unsigned char*) &(SOCKADDR_2(*sa)), ip_buf, sizeof(ip_buf));
|
strncpy(host, inet_ntoa(SOCKADDR_2(*sa)),hostlen);
|
||||||
strncpy(host, ip_buf, hostlen);
|
|
||||||
}
|
|
||||||
if(servlen)
|
if(servlen)
|
||||||
snprintf(serv, servlen,"%d",ntohs(SOCKPORT(*sa)));
|
snprintf(serv, servlen,"%d",ntohs(SOCKPORT(*sa)));
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if (defined __linux__) || (defined __APPLE__)
|
// stolen from libulz (C) rofl0r
|
||||||
struct hostent *gethostbyaddr(const void *addr, socklen_t len, int type) {
|
static void pc_stringfromipv4(unsigned char* ip_buf_4_bytes, char* outbuf_16_bytes) {
|
||||||
#else
|
unsigned char* p;
|
||||||
struct hostent *gethostbyaddr(const char *addr, socklen_t len, int type) {
|
char *o = outbuf_16_bytes;
|
||||||
#endif
|
unsigned char n;
|
||||||
|
for(p = ip_buf_4_bytes; p < ip_buf_4_bytes + 4; p++) {
|
||||||
|
n = *p;
|
||||||
|
if(*p >= 100) {
|
||||||
|
if(*p >= 200) *(o++) = '2';
|
||||||
|
else *(o++) = '1';
|
||||||
|
n %= 100;
|
||||||
|
}
|
||||||
|
if(*p >= 10) {
|
||||||
|
*(o++) = (n / 10) + '0';
|
||||||
|
n %= 10;
|
||||||
|
}
|
||||||
|
*(o++) = n + '0';
|
||||||
|
*(o++) = '.';
|
||||||
|
}
|
||||||
|
o[-1] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct hostent *gethostbyaddr (const void *addr, socklen_t len, int type)
|
||||||
|
{
|
||||||
static char buf[16];
|
static char buf[16];
|
||||||
static char ipv4[4];
|
static char ipv4[4];
|
||||||
static char* list[2];
|
static char* list[2];
|
||||||
static struct hostent he;
|
static struct hostent he;
|
||||||
|
|
||||||
INIT();
|
if(!init_l)
|
||||||
|
init_lib();
|
||||||
|
|
||||||
PDEBUG("TODO: proper gethostbyaddr hook\n");
|
PDEBUG("TODO: proper gethostbyaddr hook\n");
|
||||||
|
|
||||||
@ -570,8 +487,7 @@ struct hostent *gethostbyaddr(const char *addr, socklen_t len, int type) {
|
|||||||
else {
|
else {
|
||||||
|
|
||||||
PDEBUG("len %u\n", len);
|
PDEBUG("len %u\n", len);
|
||||||
if(len != 4)
|
if(len != 4) return NULL;
|
||||||
return NULL;
|
|
||||||
he.h_name = buf;
|
he.h_name = buf;
|
||||||
memcpy(ipv4, addr, 4);
|
memcpy(ipv4, addr, 4);
|
||||||
list[0] = ipv4;
|
list[0] = ipv4;
|
||||||
@ -580,8 +496,9 @@ struct hostent *gethostbyaddr(const char *addr, socklen_t len, int type) {
|
|||||||
he.h_addrtype = AF_INET;
|
he.h_addrtype = AF_INET;
|
||||||
he.h_aliases = NULL;
|
he.h_aliases = NULL;
|
||||||
he.h_length = 4;
|
he.h_length = 4;
|
||||||
inet_ntop(AF_INET, addr, buf, sizeof(buf));
|
pc_stringfromipv4((unsigned char*)addr, buf);
|
||||||
return &he;
|
return &he;
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
147
src/main.c
147
src/main.c
@ -1,4 +1,12 @@
|
|||||||
/* (C) 2011, 2012 rofl0r
|
/***************************************************************************
|
||||||
|
main.c - description
|
||||||
|
|
||||||
|
begin : Tue May 14 2002
|
||||||
|
copyright : netcreature (C) 2002
|
||||||
|
email : netcreature@users.sourceforge.net
|
||||||
|
***************************************************************************/
|
||||||
|
/* GPL */
|
||||||
|
/***************************************************************************
|
||||||
* *
|
* *
|
||||||
* This program is free software; you can redistribute it and/or modify *
|
* 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 *
|
* it under the terms of the GNU General Public License as published by *
|
||||||
@ -6,42 +14,42 @@
|
|||||||
* (at your option) any later version. *
|
* (at your option) any later version. *
|
||||||
* *
|
* *
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
|
|
||||||
#undef _POSIX_C_SOURCE
|
#undef _POSIX_C_SOURCE
|
||||||
#define _POSIX_C_SOURCE 200809L
|
#define _POSIX_C_SOURCE 200809L
|
||||||
#undef _XOPEN_SOURCE
|
#undef _XOPEN_SOURCE
|
||||||
#define _XOPEN_SOURCE 700
|
#define _XOPEN_SOURCE 700
|
||||||
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <sys/param.h>
|
|
||||||
|
|
||||||
#include <errno.h>
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <unistd.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <errno.h>
|
||||||
|
#include <sys/types.h>
|
||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
|
|
||||||
|
extern char *optarg;
|
||||||
|
extern int optind, opterr, optopt;
|
||||||
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
|
||||||
static int usage(char** argv) {
|
static int usage(char** argv) {
|
||||||
printf( "\nProxychains4: %d.%d.%d\n"
|
printf( "\nUsage:\t%s -q -f config_file program_name [arguments]\n"
|
||||||
"Usage:\t%s -q -f config_file program_name [arguments]\n"
|
|
||||||
"\t-v print version and exit\n"
|
|
||||||
"\t-q makes proxychains quiet - this overrides the config setting\n"
|
"\t-q makes proxychains quiet - this overrides the config setting\n"
|
||||||
"\t-f allows to manually specify a configfile to use\n"
|
"\t-t allows to manually specify a configfile to use\n"
|
||||||
"\n\tfor example : proxychains telnet somehost.com\n"
|
"\tfor example : proxychains telnet somehost.com\n"
|
||||||
"\n\tMore help in README file\n\n", PROXYCHAINS_VERSION_MAJOR,
|
"More help in README file\n\n", argv[0]);
|
||||||
PROXYCHAINS_VERSION_MINOR, PROXYCHAINS_VERSION_BUGFIX, argv[0]);
|
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char *dll_name = DLL_NAME;
|
int check_path(char* path) {
|
||||||
|
if(!path) return 0;
|
||||||
|
return access(path, R_OK) != -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static const char* dll_name = "libproxychains4.so";
|
||||||
|
|
||||||
static char own_dir[256];
|
static char own_dir[256];
|
||||||
static const char* dll_dirs[] = {
|
static const char* dll_dirs[] = {
|
||||||
//".",
|
".",
|
||||||
own_dir,
|
own_dir,
|
||||||
LIB_DIR,
|
LIB_DIR,
|
||||||
"/lib",
|
"/lib",
|
||||||
@ -53,69 +61,87 @@ static const char *dll_dirs[] = {
|
|||||||
|
|
||||||
static void set_own_dir(const char* argv0) {
|
static void set_own_dir(const char* argv0) {
|
||||||
size_t l = strlen(argv0);
|
size_t l = strlen(argv0);
|
||||||
while(l && argv0[l - 1] != '/')
|
while(l && argv0[l - 1] != '/') l--;
|
||||||
l--;
|
|
||||||
if(l == 0)
|
if(l == 0)
|
||||||
//memcpy(own_dir, ".", 2);
|
memcpy(own_dir, ".", 2);
|
||||||
memcpy(own_dir, "/dev/null/", 2);
|
|
||||||
else {
|
else {
|
||||||
memcpy(own_dir, argv0, l - 1);
|
memcpy(own_dir, argv0, l - 1);
|
||||||
own_dir[l] = 0;
|
own_dir[l] = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#define MAX_COMMANDLINE_FLAGS 2
|
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
char *path = NULL;
|
char *path = NULL;
|
||||||
char buf[PATH_MAX];
|
char buf[256];
|
||||||
char pbuf[PATH_MAX];
|
char pbuf[256];
|
||||||
|
int opt;
|
||||||
int start_argv = 1;
|
int start_argv = 1;
|
||||||
int quiet = 0;
|
int quiet = 0;
|
||||||
size_t i;
|
|
||||||
|
|
||||||
const char *prefix = NULL;
|
if(argc == 1) return usage(argv);
|
||||||
|
|
||||||
for(i = 0; i < MAX_COMMANDLINE_FLAGS; i++) {
|
while ((opt = getopt(argc, argv, "qf:")) != -1) {
|
||||||
if(start_argv < argc && argv[start_argv][0] == '-') {
|
switch (opt) {
|
||||||
if(argv[start_argv][1] == 'q') {
|
case 'q':
|
||||||
quiet = 1;
|
quiet = 1;
|
||||||
start_argv++;
|
start_argv++;
|
||||||
} else if(argv[start_argv][1] == 'v') {
|
|
||||||
printf("Proxychains4 version: %d.%d.%d\n", PROXYCHAINS_VERSION_MAJOR, PROXYCHAINS_VERSION_MINOR, PROXYCHAINS_VERSION_BUGFIX);
|
|
||||||
exit(EXIT_SUCCESS);
|
|
||||||
|
|
||||||
} else if(argv[start_argv][1] == 'f') {
|
|
||||||
|
|
||||||
if(start_argv + 1 < argc)
|
|
||||||
path = argv[start_argv + 1];
|
|
||||||
else
|
|
||||||
return usage(argv);
|
|
||||||
|
|
||||||
start_argv += 2;
|
|
||||||
}
|
|
||||||
} else
|
|
||||||
break;
|
break;
|
||||||
|
case 'f':
|
||||||
|
path = (char *)optarg;
|
||||||
|
if(!path) {
|
||||||
|
fprintf(stderr, "error: no path supplied.\n");
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
start_argv += 2;
|
||||||
|
break;
|
||||||
|
default: /* '?' */
|
||||||
|
return usage(argv);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(start_argv >= argc)
|
if(start_argv >= argc) return usage(argv);
|
||||||
return usage(argv);
|
|
||||||
|
|
||||||
/* check if path of config file has not been passed via command line */
|
/* check if path of config file has not been passed via command line */
|
||||||
path = get_config_path(path, pbuf, sizeof(pbuf));
|
if(!path) {
|
||||||
if(!quiet)
|
// priority 1: env var PROXYCHAINS_CONF_FILE
|
||||||
fprintf(stderr, LOG_PREFIX "config file found: %s\n", path);
|
path = getenv(PROXYCHAINS_CONF_FILE_ENV_VAR);
|
||||||
|
if(check_path(path)) goto have;
|
||||||
|
|
||||||
|
// priority 2; proxychains conf in actual dir
|
||||||
|
path = getcwd(buf, sizeof(buf));
|
||||||
|
snprintf(pbuf, sizeof(pbuf), "%s/%s", path, PROXYCHAINS_CONF_FILE);
|
||||||
|
path = pbuf;
|
||||||
|
if(check_path(path)) goto have;
|
||||||
|
|
||||||
|
// priority 3; $HOME/.proxychains/proxychains.conf
|
||||||
|
path = getenv("HOME");
|
||||||
|
snprintf(pbuf, sizeof(pbuf), "%s/.proxychains/%s", path, PROXYCHAINS_CONF_FILE);
|
||||||
|
path = pbuf;
|
||||||
|
if(check_path(path)) goto have;
|
||||||
|
|
||||||
|
// priority 4: /etc/proxychains.conf
|
||||||
|
path = "/etc/proxychains.conf";
|
||||||
|
if(check_path(path)) goto have;
|
||||||
|
perror("couldnt find configuration file");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
have:
|
||||||
|
|
||||||
|
if(!quiet) fprintf(stderr, LOG_PREFIX "config file found: %s\n", path);
|
||||||
|
|
||||||
/* Set PROXYCHAINS_CONF_FILE to get proxychains lib to use new config file. */
|
/* Set PROXYCHAINS_CONF_FILE to get proxychains lib to use new config file. */
|
||||||
setenv(PROXYCHAINS_CONF_FILE_ENV_VAR, path, 1);
|
setenv(PROXYCHAINS_CONF_FILE_ENV_VAR, path, 1);
|
||||||
|
|
||||||
if(quiet)
|
if(quiet) setenv(PROXYCHAINS_QUIET_MODE_ENV_VAR, "1", 1);
|
||||||
setenv(PROXYCHAINS_QUIET_MODE_ENV_VAR, "1", 1);
|
|
||||||
|
|
||||||
// search DLL
|
// search DLL
|
||||||
|
size_t i = 0;
|
||||||
|
const char* prefix = NULL;
|
||||||
|
|
||||||
set_own_dir(argv[0]);
|
set_own_dir(argv[0]);
|
||||||
|
|
||||||
i = 0;
|
|
||||||
while(dll_dirs[i]) {
|
while(dll_dirs[i]) {
|
||||||
snprintf(buf, sizeof(buf), "%s/%s", dll_dirs[i], dll_name);
|
snprintf(buf, sizeof(buf), "%s/%s", dll_dirs[i], dll_name);
|
||||||
if(access(buf, R_OK) != -1) {
|
if(access(buf, R_OK) != -1) {
|
||||||
@ -126,21 +152,14 @@ int main(int argc, char *argv[]) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(!prefix) {
|
if(!prefix) {
|
||||||
fprintf(stderr, "couldn't locate %s\n", dll_name);
|
fprintf(stderr, "couldnt locate %s\n", dll_name);
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
if(!quiet) fprintf(stderr, LOG_PREFIX "preloading %s/%s\n", prefix, dll_name);
|
||||||
|
|
||||||
if(!quiet)
|
snprintf(buf, sizeof(buf), "LD_PRELOAD=%s/%s", prefix, dll_name);
|
||||||
fprintf(stderr, LOG_PREFIX "preloading %s/%s\n", prefix, dll_name);
|
|
||||||
|
|
||||||
#ifndef IS_MAC
|
putenv(buf);
|
||||||
snprintf(buf, sizeof(buf), "%s/%s", prefix, dll_name);
|
|
||||||
setenv("LD_PRELOAD", buf, 1);
|
|
||||||
#else
|
|
||||||
snprintf(buf, sizeof(buf), "%s/%s", prefix, dll_name);
|
|
||||||
setenv("DYLD_INSERT_LIBRARIES", buf, 1);
|
|
||||||
setenv("DYLD_FORCE_FLAT_NAMESPACE", "1", 1);
|
|
||||||
#endif
|
|
||||||
execvp(argv[start_argv], &argv[start_argv]);
|
execvp(argv[start_argv], &argv[start_argv]);
|
||||||
perror("proxychains can't load process....");
|
perror("proxychains can't load process....");
|
||||||
|
|
||||||
|
|||||||
@ -1,106 +1,26 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
echo "ProxyChains-4.0 (https://github.com/haad/proxychains)"
|
echo "ProxyChains-3.1 (http://proxychains.sf.net)"
|
||||||
|
|
||||||
usage() {
|
usage() {
|
||||||
|
|
||||||
echo " usage:"
|
echo " usage:"
|
||||||
echo " $0 [hqv] [-f config-file] <prog> [args]"
|
echo " $0 [h] [f config-file] <prog> [args]"
|
||||||
echo " -q make proxychains quiet"
|
|
||||||
exit
|
exit
|
||||||
}
|
}
|
||||||
|
|
||||||
find_proxy_conf() {
|
|
||||||
|
|
||||||
show_proxy_env
|
|
||||||
if [ -f "/usr/local/etc/proxychains.conf" ]; then
|
|
||||||
export PROXYCHAINS_CONF_FILE="/usr/local/etc/proxychains.conf"
|
|
||||||
else
|
|
||||||
if [ -f "/etc/proxychains.conf" ];then
|
|
||||||
PROXYCHAINS_CONF_FILE="/etc/proxychains.conf"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
#
|
|
||||||
# XXX We should not overide possible user settings here. Just add libproxychains to it.
|
|
||||||
#
|
|
||||||
setup_proxy_env() {
|
|
||||||
|
|
||||||
if [ -z "$PROXYCHAINS_CONF_FILE" ]; then
|
|
||||||
find_proxy_conf
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ $(uname -s) = "Darwin" ]; then
|
|
||||||
export DYLD_FORCE_FLAT_NAMESPACE=
|
|
||||||
export DYLD_INSERT_LIBRARIES=libproxychains4.dylib
|
|
||||||
else
|
|
||||||
export LD_PRELOAD=libproxychains.so.4
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
disable_proxy_env() {
|
|
||||||
|
|
||||||
if [ $(uname -s) = "Darwin" ]; then
|
|
||||||
unset DYLD_FORCE_FLAT_NAMESPACE
|
|
||||||
export DYLD_INSERT_LIBRARIES=$(echo $DYLD_INSERT_LIBRARIES | sed -e 's/libproxychains4.dylib//g')
|
|
||||||
if [ -z $DYLD_INSERT_LIBRARIES ]; then
|
|
||||||
unset DYLD_INSERT_LIBRARIES
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
export LD_PRELOAD=$(echo $DYLD_INSERT_LIBRARIES | sed -e 's/libproxychains.so.4//g')
|
|
||||||
if [ -z $LD_PRELOAD ]; then
|
|
||||||
unset LD_PRELOAD
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
show_proxy_env() {
|
|
||||||
|
|
||||||
echo "Proxified environment setup"
|
|
||||||
echo "PROXYCHAINS_CONF_FILE = $PROXYCHAINS_CONF_FILE"
|
|
||||||
|
|
||||||
if [ $(uname -s) = "Darwin" ]; then
|
|
||||||
echo "DYLD_FORCE_FLAT_NAMESPACE = $DYLD_FORCE_FLAT_NAMESPACE"
|
|
||||||
echo "DYLD_INSERT_LIBRARIES = $DYLD_INSERT_LIBRARIES"
|
|
||||||
else
|
|
||||||
echo "LD_PRELOAD = $LD_PRELOAD"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
if [ $# = 0 ] ; then
|
if [ $# = 0 ] ; then
|
||||||
usage
|
usage
|
||||||
fi
|
fi
|
||||||
|
|
||||||
case "$1" in
|
if [ $1 = "-h" ]; then
|
||||||
-h)
|
|
||||||
usage
|
usage
|
||||||
;;
|
fi
|
||||||
-f)
|
|
||||||
|
if [ "$1" = "-f" ]; then
|
||||||
export PROXYCHAINS_CONF_FILE=$2;
|
export PROXYCHAINS_CONF_FILE=$2;
|
||||||
shift;
|
shift;
|
||||||
shift;
|
shift;
|
||||||
;;
|
fi
|
||||||
-q)
|
|
||||||
export PROXYCHAINS_QUIET_MODE=1;
|
|
||||||
shift;
|
|
||||||
;;
|
|
||||||
show)
|
|
||||||
show_proxy_env
|
|
||||||
return
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
case "$1" in
|
export LD_PRELOAD=libproxychains.so.3
|
||||||
on)
|
|
||||||
setup_proxy_env
|
|
||||||
show_proxy_env
|
|
||||||
;;
|
|
||||||
off)
|
|
||||||
disable_proxy_env
|
|
||||||
show_proxy_env
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
setup_proxy_env
|
|
||||||
exec "$@"
|
exec "$@"
|
||||||
;;
|
|
||||||
esac
|
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
# proxychains.conf VER 4
|
# proxychains.conf VER 3.1
|
||||||
#
|
#
|
||||||
# HTTP, SOCKS4, SOCKS5 tunneling proxifier with DNS.
|
# HTTP, SOCKS4, SOCKS5 tunneling proxifier with DNS.
|
||||||
#
|
#
|
||||||
@ -37,32 +37,10 @@ strict_chain
|
|||||||
# Proxy DNS requests - no leak for DNS data
|
# Proxy DNS requests - no leak for DNS data
|
||||||
proxy_dns
|
proxy_dns
|
||||||
|
|
||||||
# set the class A subnet number to usefor use of the internal remote DNS mapping
|
|
||||||
# we use the reserved 224.x.x.x range by default,
|
|
||||||
# if the proxified app does a DNS request, we will return an IP from that range.
|
|
||||||
# on further accesses to this ip we will send the saved DNS name to the proxy.
|
|
||||||
# in case some control-freak app checks the returned ip, and denies to
|
|
||||||
# connect, you can use another subnet, e.g. 10.x.x.x or 127.x.x.x.
|
|
||||||
# of course you should make sure that the proxified app does not need
|
|
||||||
# *real* access to this subnet.
|
|
||||||
# i.e. dont use the same subnet then in the localnet section
|
|
||||||
#remote_dns_subnet 127
|
|
||||||
#remote_dns_subnet 10
|
|
||||||
remote_dns_subnet 224
|
|
||||||
|
|
||||||
# Some timeouts in milliseconds
|
# Some timeouts in milliseconds
|
||||||
tcp_read_time_out 15000
|
tcp_read_time_out 15000
|
||||||
tcp_connect_time_out 8000
|
tcp_connect_time_out 8000
|
||||||
|
|
||||||
# By default enable localnet for loopback address ranges
|
|
||||||
# RFC5735 Loopback address range
|
|
||||||
localnet 127.0.0.0/255.0.0.0
|
|
||||||
# RFC1918 Private Address Ranges
|
|
||||||
# localnet 10.0.0.0/255.0.0.0
|
|
||||||
# localnet 172.16.0.0/255.240.0.0
|
|
||||||
# localnet 192.168.0.0/255.255.0.0
|
|
||||||
|
|
||||||
|
|
||||||
# Example for localnet exclusion
|
# Example for localnet exclusion
|
||||||
## Exclude connections to 192.168.1.0/24 with port 80
|
## Exclude connections to 192.168.1.0/24 with port 80
|
||||||
# localnet 192.168.1.0:80/255.255.255.0
|
# localnet 192.168.1.0:80/255.255.255.0
|
||||||
@ -73,24 +51,6 @@ localnet 127.0.0.0/255.0.0.0
|
|||||||
## Exclude connections to ANYwhere with port 80
|
## Exclude connections to ANYwhere with port 80
|
||||||
# localnet 0.0.0.0:80/0.0.0.0
|
# localnet 0.0.0.0:80/0.0.0.0
|
||||||
|
|
||||||
|
|
||||||
### Examples for dnat
|
|
||||||
## Trying to proxy connections to destinations which are dnatted,
|
|
||||||
## will result in proxying connections to the new given destinations.
|
|
||||||
## Whenever I connect to 1.1.1.1 on port 1234 actually connect to 1.1.1.2 on port 443
|
|
||||||
# dnat 1.1.1.1:1234 1.1.1.2:443
|
|
||||||
|
|
||||||
## Whenever I connect to 1.1.1.1 on port 443 actually connect to 1.1.1.2 on port 443
|
|
||||||
## (no need to write :443 again)
|
|
||||||
# dnat 1.1.1.2:443 1.1.1.2
|
|
||||||
|
|
||||||
## No matter what port I connect to on 1.1.1.1 port actually connect to 1.1.1.2 on port 443
|
|
||||||
# dnat 1.1.1.1 1.1.1.2:443
|
|
||||||
|
|
||||||
## Always, instead of connecting to 1.1.1.1, connect to 1.1.1.2
|
|
||||||
# dnat 1.1.1.1 1.1.1.2
|
|
||||||
|
|
||||||
|
|
||||||
# ProxyList format
|
# ProxyList format
|
||||||
# type host port [user pass]
|
# type host port [user pass]
|
||||||
# (values separated by 'tab' or 'blank')
|
# (values separated by 'tab' or 'blank')
|
||||||
@ -104,13 +64,12 @@ localnet 127.0.0.0/255.0.0.0
|
|||||||
# http 192.168.39.93 8080
|
# http 192.168.39.93 8080
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
# proxy types: http, socks4, socks5, raw
|
# proxy types: http, socks4, socks5
|
||||||
# * raw: The traffic is simply forwarded to the proxy without modification.
|
|
||||||
# ( auth types supported: "basic"-http "user/pass"-socks )
|
# ( auth types supported: "basic"-http "user/pass"-socks )
|
||||||
#
|
#
|
||||||
[ProxyList]
|
[ProxyList]
|
||||||
# add proxy here ...
|
# add proxy here ...
|
||||||
# meanwhile
|
# meanwile
|
||||||
# defaults set to "tor"
|
# defaults set to "tor"
|
||||||
socks4 127.0.0.1 9050
|
socks4 127.0.0.1 9050
|
||||||
|
|
||||||
|
|||||||
@ -2,12 +2,8 @@
|
|||||||
# This script is called by proxychains to resolve DNS names
|
# This script is called by proxychains to resolve DNS names
|
||||||
|
|
||||||
# DNS server used to resolve names
|
# DNS server used to resolve names
|
||||||
|
DNS_SERVER=4.2.2.2
|
||||||
|
|
||||||
if [ -z "$PROXY_DNS_SERVER" ] ; then
|
|
||||||
DNS_SERVER=208.67.222.222 # OpenDNS
|
|
||||||
else
|
|
||||||
DNS_SERVER=$PROXY_DNS_SERVER
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ $# = 0 ] ; then
|
if [ $# = 0 ] ; then
|
||||||
echo " usage:"
|
echo " usage:"
|
||||||
@ -15,10 +11,6 @@ if [ $# = 0 ] ; then
|
|||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
|
|
||||||
awk 'BEGIN{ARGC=0} {for(i=2;i<=NF;i++){if($i==ARGV[1] && $1!~":"){print $1;found=1}} } END{exit found?0:1}' "$1" </etc/hosts
|
|
||||||
if [ "$?" -eq "0" ]; then
|
|
||||||
exit
|
|
||||||
fi
|
|
||||||
|
|
||||||
export LD_PRELOAD=libproxychains.so
|
export LD_PRELOAD=libproxychains.so
|
||||||
drill $1 @$DNS_SERVER -t | awk '/A.+[0-9]+\.[0-9]+\.[0-9]/{print $5;}'
|
dig $1 @$DNS_SERVER +tcp | awk '/A.+[0-9]+\.[0-9]+\.[0-9]/{print $5;}'
|
||||||
|
|||||||
@ -1,41 +0,0 @@
|
|||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <netdb.h>
|
|
||||||
#include <netinet/in.h>
|
|
||||||
#include <sys/socket.h>
|
|
||||||
|
|
||||||
#ifndef NI_MAXHOST
|
|
||||||
#define NI_MAXHOST 1025
|
|
||||||
#endif
|
|
||||||
|
|
||||||
int main(void) {
|
|
||||||
struct addrinfo *result;
|
|
||||||
struct addrinfo *res;
|
|
||||||
int error;
|
|
||||||
|
|
||||||
/* resolve the domain name into a list of addresses */
|
|
||||||
error = getaddrinfo("www.example.com", NULL, NULL, &result);
|
|
||||||
if (error != 0)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "error in getaddrinfo: %s\n", gai_strerror(error));
|
|
||||||
return EXIT_FAILURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* loop over all returned results and do inverse lookup */
|
|
||||||
for (res = result; res != NULL; res = res->ai_next)
|
|
||||||
{
|
|
||||||
char hostname[NI_MAXHOST] = "";
|
|
||||||
|
|
||||||
error = getnameinfo(res->ai_addr, res->ai_addrlen, hostname, NI_MAXHOST, NULL, 0, 0);
|
|
||||||
if (error != 0)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "error in getnameinfo: %s\n", gai_strerror(error));
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (*hostname != '\0')
|
|
||||||
printf("hostname: %s\n", hostname);
|
|
||||||
}
|
|
||||||
|
|
||||||
freeaddrinfo(result);
|
|
||||||
return EXIT_SUCCESS;
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue
Block a user