-
Notifications
You must be signed in to change notification settings - Fork 1.2k
add proxychains-cli to help using inline config #610
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
0x0a0d
wants to merge
8
commits into
rofl0r:master
Choose a base branch
from
0x0a0d:proxychains-cli
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
3d5acf9
chore: update .gitignore
0x0a0d fbef1d7
feat: add proxychains-cli script that support inline config
0x0a0d 8bc035a
fix: using env value instead of fd
0x0a0d c9d0cb0
fix: pull comments
0x0a0d 487c9cf
Revert "chore: update .gitignore"
0x0a0d 9821870
fix: pull comments
0x0a0d 1ba44c8
feat: cli -P accept URL
0x0a0d 496c479
fix: missing quiet
0x0a0d File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,248 @@ | ||
| #!/bin/sh | ||
| # proxychains4-cli - Dynamic config generation for proxychains4 | ||
|
|
||
| # Static variables | ||
| # sync with proxychains4 version | ||
| PROXYCHAINS_CLI_VERSION="4.17" | ||
|
|
||
| # Defaults | ||
| chain_mode="strict" | ||
| chain_len="" | ||
| quiet="" | ||
| dns_mode="proxy" | ||
| dns_subnet="224" | ||
| read_timeout="15000" | ||
| connect_timeout="8000" | ||
| localnets="" | ||
| dnats="" | ||
| proxies="" | ||
| proxychains_path="proxychains4" | ||
| show_config="" | ||
|
|
||
| show_help() { | ||
| cat <<EOF | ||
| Usage: proxychains4-cli [options] program [args...] | ||
|
|
||
| Chain Options: | ||
| -c, --chain MODE Chain mode (strict/dynamic/random/round_robin) | ||
| -l, --chain-len N Chain length for random/round_robin | ||
|
|
||
| Output: | ||
| -q, --quiet Quiet mode | ||
|
|
||
| DNS Options: | ||
| -d, --dns MODE DNS mode (proxy/old/off/IP:PORT) | ||
| -S, --dns-subnet N Remote DNS subnet (0-255) | ||
|
|
||
| Timeouts: | ||
| -R, --read-timeout MS TCP read timeout in milliseconds | ||
| -T, --connect-timeout MS TCP connect timeout in milliseconds | ||
|
|
||
| Network: | ||
| -n, --localnet CIDR Bypass proxy for CIDR (repeatable) | ||
| --dnat "SRC DST" DNAT mapping (repeatable, quote required) | ||
|
|
||
| Proxy: | ||
| -P, --proxy URL Add proxy to chain (repeatable) | ||
| Format: protocol://[user:pass@]host:port | ||
| Protocols: http, socks4, socks5, raw | ||
| IPv6: socks5://[::1]:1080 | ||
|
|
||
| Debug: | ||
| --config Print generated config and exit | ||
| --proxychains-path PATH Path to proxychains4 (default: proxychains4 in PATH) | ||
|
|
||
| Other: | ||
| -h, --help Show this help | ||
| -v, --version Show version | ||
|
|
||
| Examples: | ||
| proxychains4-cli -P socks5://127.0.0.1:1080 curl example.com | ||
| proxychains4-cli -P socks5://user:[email protected]:1080 wget file.tar.gz | ||
| proxychains4-cli -P "socks5://[::1]:1080" curl -v example.com | ||
| # Special chars in password: use URL encoding (%40=@ %3A=: %25=%) | ||
| proxychains4-cli -P 'socks5://user:p%40ss%[email protected]:1080' curl example.com | ||
| EOF | ||
| } | ||
|
|
||
| show_version() { | ||
| echo "proxychains4-cli ${PROXYCHAINS_CLI_VERSION}" | ||
| } | ||
|
|
||
| # URL decode: %XX -> char | ||
| url_decode() { | ||
| printf '%b' "$(echo "$1" | sed 's/+/ /g; s/%\([0-9A-Fa-f][0-9A-Fa-f]\)/\\x\1/g')" | ||
| } | ||
|
|
||
| # Parse proxy URL: protocol://[user:pass@]host:port | ||
| # Output: protocol\thost\tport[\tuser\tpass] | ||
| # Supports URL-encoded special chars in user/pass | ||
| parse_proxy_url() { | ||
| url="$1" | ||
|
|
||
| # Extract protocol | ||
| proto="${url%%://*}" | ||
| rest="${url#*://}" | ||
|
|
||
| # Validate protocol | ||
| case "$proto" in | ||
| http|socks4|socks5|raw) ;; | ||
| *) echo "Error: Invalid proxy protocol '$proto'. Use http/socks4/socks5/raw" >&2; return 1 ;; | ||
| esac | ||
|
|
||
| # Check for auth (user:pass@) | ||
| if echo "$rest" | grep -q '@'; then | ||
| auth="${rest%%@*}" | ||
| hostport="${rest#*@}" | ||
| user=$(url_decode "${auth%%:*}") | ||
| pass=$(url_decode "${auth#*:}") | ||
| else | ||
| hostport="$rest" | ||
| user="" | ||
| pass="" | ||
| fi | ||
|
|
||
| # Handle IPv6: [::1]:port | ||
| if echo "$hostport" | grep -q '^\['; then | ||
| # IPv6 format: [addr]:port | ||
| host=$(echo "$hostport" | sed 's/^\[\([^]]*\)\].*/\1/') | ||
| port=$(echo "$hostport" | sed 's/.*\]://') | ||
| else | ||
| # IPv4 or hostname: addr:port | ||
| host="${hostport%%:*}" | ||
| port="${hostport##*:}" | ||
| fi | ||
|
|
||
| # Validate port | ||
| if [ -z "$port" ] || ! echo "$port" | grep -qE '^[0-9]+$'; then | ||
| echo "Error: Invalid or missing port in '$url'" >&2 | ||
| return 1 | ||
| fi | ||
|
|
||
| # Output in proxychains.conf format | ||
| if [ -n "$user" ]; then | ||
| printf '%s\t%s\t%s\t%s\t%s\n' "$proto" "$host" "$port" "$user" "$pass" | ||
| else | ||
| printf '%s\t%s\t%s\n' "$proto" "$host" "$port" | ||
| fi | ||
| } | ||
|
|
||
| # Parse arguments | ||
| while [ $# -gt 0 ]; do | ||
| case "$1" in | ||
| -c|--chain) | ||
| chain_mode="$2" | ||
| shift 2 | ||
| ;; | ||
| -l|--chain-len) | ||
| chain_len="$2" | ||
| shift 2 | ||
| ;; | ||
| -q|--quiet) | ||
| quiet=1 | ||
| shift | ||
| ;; | ||
| -d|--dns) | ||
| dns_mode="$2" | ||
| shift 2 | ||
| ;; | ||
| -S|--dns-subnet) | ||
| dns_subnet="$2" | ||
| shift 2 | ||
| ;; | ||
| -R|--read-timeout) | ||
| read_timeout="$2" | ||
| shift 2 | ||
| ;; | ||
| -T|--connect-timeout) | ||
| connect_timeout="$2" | ||
| shift 2 | ||
| ;; | ||
| -n|--localnet) | ||
| localnets="${localnets}${2} | ||
| " | ||
| shift 2 | ||
| ;; | ||
| --dnat) | ||
| dnats="${dnats}${2} | ||
| " | ||
| shift 2 | ||
| ;; | ||
| -P|--proxy) | ||
| entry=$(parse_proxy_url "$2") || exit 1 | ||
| proxies="${proxies}${entry} | ||
| " | ||
| shift 2 | ||
| ;; | ||
| -h|--help) | ||
| show_help | ||
| exit 0 | ||
| ;; | ||
| -v|--version) | ||
| show_version | ||
| exit 0 | ||
| ;; | ||
| --config) | ||
| show_config=1 | ||
| shift | ||
| ;; | ||
| --proxychains-path) | ||
| proxychains_path="$2" | ||
| shift 2 | ||
| ;; | ||
| -*) | ||
| echo "Unknown option: $1" >&2 | ||
| echo "Use -h for help" >&2 | ||
| exit 1 | ||
| ;; | ||
| *) | ||
| # First non-option is program, stop parsing | ||
| break | ||
| ;; | ||
| esac | ||
| done | ||
|
|
||
| # Check if program specified (unless --config) | ||
| if [ $# -eq 0 ] && [ -z "$show_config" ]; then | ||
| echo "Error: No program specified" >&2 | ||
| echo "Use -h for help" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Check if at least one proxy specified | ||
| if [ -z "$proxies" ]; then | ||
| echo "Error: No proxy specified. Use -P to add proxy." >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Build DNS config line | ||
| dns_config="" | ||
| case "$dns_mode" in | ||
| proxy) dns_config="proxy_dns";; | ||
| old) dns_config="proxy_dns_old";; | ||
| off|none|"") ;; | ||
| *) dns_config="proxy_dns_daemon $dns_mode";; | ||
| esac | ||
|
|
||
| # Generate config content | ||
| config_content="${chain_mode}_chain | ||
| ${chain_len:+chain_len = $chain_len} | ||
| ${quiet:+quiet_mode} | ||
| ${dns_config} | ||
| ${dns_subnet:+remote_dns_subnet $dns_subnet} | ||
| ${read_timeout:+tcp_read_time_out $read_timeout} | ||
| ${connect_timeout:+tcp_connect_time_out $connect_timeout} | ||
| $(printf '%s' "$localnets" | while IFS= read -r net; do [ -n "$net" ] && echo "localnet $net"; done) | ||
| $(printf '%s' "$dnats" | while IFS= read -r m; do [ -n "$m" ] && echo "dnat $m"; done) | ||
| [ProxyList] | ||
| $(printf '%s' "$proxies")" | ||
|
|
||
| # If --config, print and exit | ||
| if [ -n "$show_config" ]; then | ||
| printf '%s\n' "$config_content" | ||
| exit 0 | ||
| fi | ||
|
|
||
| # Execute with config via environment variable | ||
| export PROXYCHAINS_CONFIG_DATA="$config_content" | ||
0x0a0d marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| exec "$proxychains_path" ${quiet:+-q} "$@" | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.