Skip to content

Instantly share code, notes, and snippets.

@pich4ya
Created March 6, 2023 03:25
Show Gist options
  • Select an option

  • Save pich4ya/f4ae0b04f30653b2bcc2f2246bb564af to your computer and use it in GitHub Desktop.

Select an option

Save pich4ya/f4ae0b04f30653b2bcc2f2246bb564af to your computer and use it in GitHub Desktop.
Install proxychains-ng on macOS m1/m2 arm64e natively without Rosetta 2 (2023)
# @author Pichaya Morimoto ([email protected])
Problem:
```bash
brew install proxychains-ng
proxychains4 ncat 1.2.3.4 # not working
```
There are public workarounds like https://benobi.one/posts/running_brew_on_m1_for_x86/
which suggests to use brew's x86_64 version or run the proxychains4 binary with `arch -x86_64`.
This seems to be working, but it hurts performance (with Rosetta 2 emulator).
Here we can find the proxychains4 binary, in which, it runs natively on our beloved M1/M2 chips <3
Solution:
# M1/M2 supports arm64e, but we need to enable it.
# https://developer.apple.com/documentation/driverkit/debugging_and_testing_system_extensions#3626024
# Tested on macOS 13.2.1 (2023)
# shutdown & long press Power button to recovery mode -> Terminal
csrutil disable
# reboot to normal mode
# enable arm64e support
sudo nvram boot-args=-arm64e_preview_abi
# reboot
Then,
```bash
git clone https://github.com/rofl0r/proxychains-ng
cd proxychains-ng
CFLAGS="-arch arm64e" LDFLAGS="-arch arm64e" ./configure --prefix=/usr/local --bindir=/usr/local/bin --libdir=/usr/local/lib --fat-binary-m1
make
$ file ./proxychains4
./proxychains4: Mach-O universal binary with 3 architectures: [x86_64:Mach-O 64-bit executable x86_64] [arm64:Mach-O 64-bit executable arm64] [arm64e:Mach-O 64-bit executable arm64e]
./proxychains4 (for architecture x86_64): Mach-O 64-bit executable x86_64
./proxychains4 (for architecture arm64): Mach-O 64-bit executable arm64
./proxychains4 (for architecture arm64e): Mach-O 64-bit executable arm64e
$ ./proxychains4 -f /opt/homebrew/etc/proxychains.conf ncat 127.0.0.1 22 -v
[proxychains] config file found: /opt/homebrew/etc/proxychains.conf
[proxychains] preloading /xxx/proxychains-ng/libproxychains4.dylib
[proxychains] DLL init: proxychains-ng 4.16-git-10-g199d03d
Ncat: Version 7.93 ( https://nmap.org/ncat )
[proxychains] Strict chain ... 127.0.0.1:1080 ... 127.0.0.1:22 ... OK
Ncat: Connected to 127.0.0.1:22.
SSH-2.0-OpenSSH_8.9p1 Ubuntu-3ubuntu0.1
```
@sorryyyy
Copy link

sorryyyy commented Aug 16, 2023

Proxychains-ng MacOS M1 - killed Issue Fix

NOTE: All credit to pich4ya for the above solution and crypt0nX's comment. I wrote this to save someone else out there from a trial-by-fire for 2 days trying to find and combine many solutions. I came up with nothing new, and the below guide is just my combination of several solutions.

I will note that the above guide brought me the closest to anything out there, so thank you very much pich4ya.

I was, however, still having the following killed issue:

$ ./proxychains4
[1]    7951 killed     ./proxychains4

No matter how I ran it - with sudo, with applications, without applications - nothing worked and it was always being killed.

Fix Instructions:

Before performing ANY of pich4ya's above solution, perform the below steps. Pich4ya's steps are integrated into the below solution.

Step 0) Prerequisite - Remove/Uninstall/Delete Previous proxychains Files.

  • This might not be necessary, but to prevent any possible issues, I did this.
  • Delete any previously downloaded or installedproxychains/proxychains-ng files, especially if installed with brew or if you installed manually and ran make install.
  • There might be a better way to do this, but I just ran a find command and deleted any file containing the roxychai substring:
$ find / -name "*roxychai*" 2>/dev/null
/some/directory/proxychains.conf
/some/other/directory/proxychains4

$ sudo rm /some/directory/proxychains.conf
$ sudo rm /some/other/directory/proxychains4

Step 1)

# a) Download proxychains-ng with git and cd into the folder:
    $ git clone https://github.com/rofl0r/proxychains-ng 
    
    $ cd proxychains-ng

# b) Set the CFLAGS to the following (different to above solution) and run ./configure (one-liner):
    $ CFLAGS="-arch arm64" LDFLAGS="-arch arm64" ./configure

# c) Run 'make', but do NOT run 'install' or 'make install'. Just 'make':
    $ make

# d) Rename the 'proxychains-ng' folder downloaded with the 'git' command in step a) (prevents issues in later step):
    $ cd ../
    $ mv proxychains-ng proxychains-ng-temp

Step 2)

  • Perform pich4ya's solution to enable arm64e, as outlined below:
    # a) Shutdown the device.

    # b) Press and hold (long-press) the Power button to turn the device on and boot into Recovery mode.
    #    Hold the power button until it says 'Loading Recovery Mode' (or something similar).

    # c) Click on Settings/Options.

    # d) Click your user and enter password.

    # e) Open a Terminal session with ⌘CMD+SHIFT+T.

    # f) Disable csrutil with below command. You will need to type 'y' and hit enter, as well as entering your password.
    #    NOTE: This takes about a minute to execute, be patient.
        $ csrutil disable

    # g) Reboot the device into normal mode (can use the same terminal session):
        $ reboot

    # h) Once rebooted into normal mode and logged in, open a Terminal session and enable arm64e support:
        $ sudo nvram boot-args=-arm64e_preview_abi

    # i) Once again, reboot into normal mode (can use terminal session):
        $ sudo reboot

Step 3)

  • Similar to Step 1), but with a twist on the CFLAGS:
    # a) Download proxychains-ng with git again (this is why we renamed the folder of the previous install) and cd into the folder:
        $ git clone https://github.com/rofl0r/proxychains-ng 
        
        $ cd proxychains-ng

    # b) Set the CFLAGS and run ./configure (as outlined in pich4ya's solution):
        $ CFLAGS="-arch arm64e" LDFLAGS="-arch arm64e" ./configure --prefix=/usr/local --bindir=/usr/local/bin --libdir=/usr/local/lib --fat-binary-m1

    # c) Run 'make', but do NOT run 'install' or 'make install'. Just 'make':
        $ make

Step 4) THE FIX

  • Remember in Step 1) how we installed proxychains-ng, renamed the folder to proxychains-ng-temp and left it?
  • We basically need to replace the proxychains4 binary file we just compiled, with the binary we compiled earlier (in the proxychains-ng-temp folder).
    a) Delete the newly-compiled proxychains4 file in the newly-downloaded `proxychains-ng` folder:
        $ ls -l | grep proxychains
        proxychains-ng
        proxychains-ng-test
        
        $ cd proxychains-ng
        
        $ rm proxychains4

    b) Move the proxychains4 binary compiled earlier from the proxychains-ng-temp folder into the proxychains-ng folder:
        $ ls -l | grep proxychains
        proxychains-ng
        proxychains-ng-test
        
        $ mv proxychains-ng-test/proxychains4 proxychains-ng

IMPORTANT NOTES:

  • This should now work. You can delete the old proxychains-ng-test folder.
  • We disabled csrutil in an earlier step, which provides some critical system security.
    • I can confirm that you CAN now re-enable it and have proxychains work without issues.
    • Disabling csrutil is only required to run the command in Step 2) d), so we can re-enable it now.
    • Re-enable steps:
    # a) Shutdown the device.

    # b) Press and hold (long-press) the Power button to turn the device on and boot into Recovery mode.
    #    Hold the power button until it says 'Loading Recovery Mode' (or something similar).

    # c) Click on Settings/Options.

    # d) Click your user and enter password.

    # e) Open a Terminal session with ⌘CMD+SHIFT+T.

    # f) Enable csrutil with below command. You will need to type 'y' and hit enter, as well as entering your password.
    #    NOTE: This takes about a minute to execute, be patient.
        $ csrutil enable

    # g) Reboot the device into normal mode (can use the same terminal session):
        $ reboot
  • You need to specify the proxychains.conf configuration file every time you run proxychains.
    • We can specify this using the -f switch.
    • The proxychains.conf file is stored in the src folder of the proxychains-ng folder downloaded with git:
        $ pwd
        /Users/sorryyyy/path-to-proxychains-folder/proxychains-ng
        
        $ ./proxychains -f src/proxychains.conf [COMMAND]

@cornradio
Copy link

can any one compile a m1 version for every one to download that?

@troman29
Copy link

troman29 commented Oct 2, 2025

@sorryyyy Your process is being killed because SIP (csrutil) is enabled, and there is no way to bypass this. A binary built under arm64e will work ONLY with SIP disabled.

In your instructions, you replace the proxychain4 built for arm64e with one for arm64, which makes all the effort pointless (the same arm64 binary can simply be installed via brew).

As for me, I just decided not to proxy binaries provided by the system (for example, ssh) but to install them through brew. This way, they are properly proxied through proxychains from brew.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment