Installing MongoDB under sanctions through a proxy

In the current situation, many services block access from the Russian Federation, I will show how you can get around this ban using ProxyChains and Tor on the example of MongoDB.

Installed on Linux Ubuntu 22.04

1. First update your Linux system

sudo apt update && sudo apt upgrade

2. Installation Tor and Proxychains

sudo apt install proxychains tor -y

We are installing the tor service, which is a service that runs locally on your virtual machine or on your operating system and is actually bound to a specific port on the local host. In our case it will be 9050 and this is the default port for the tor service.

3. Setting ProxyChains

Open config

nano /etc/proxychains.conf

3.1 Dynamic chaining must be uncommented

All you have to do is remove the symbol # before dynamic_chain.

# Dynamic - Each connection will be done via chained proxies
# all proxies chained in the order as they appear in the list
# at least one proxy must be online to play in chain
# (dead proxies are skipped)
# otherwise EINTR is returned to the app

3.2 Place a comment before random_chain and strict_chain. Just add # In front of them.

# Random - Each connection will be done via random proxy
# (or proxy chain, see  chain_len) from the list.
# this option is good to test your IDS :)

3.3 In this way, you will avoid DNS leaks that may reveal your true IP address.

# Proxy DNS requests - no leak for DNS data

3.4 Add socks5 9050 in the proxy list as the last line.

# add proxy here ...
# meanwile
# defaults set to "tor"
socks4 9050 
socks5 9050 

Socks4 proxy will already be specified here. You need to add socks5 proxy as shown above. And finally, save the configuration file and exit the terminal.

4 Using ProxyChains

Just in case, basic TOR commands

To check the status of Tor:

service tor status

To start the tor service:

service tor start

To stop the tor service:

service tor stop

4.1 Launch. First, start the TOR service

service tor start

To use ProxyChains, simply enter the ProxyChains command in a terminal followed by the name of the application you wish to use.

The format is the following:

For example to use Nmap, sqlmap, firefox:

proxychains nmap -targetaddress
proxychains python sqlmap -u target
proxychains firefox

For the test, we look at our current external server IP

wget -qO-

then look through the proxy

proxychains wget -qO-

If it changes, then everything is done correctly

5. Finally installing MongoDB

First, import the public GPG key for the latest stable version of MongoDB. You can find the corresponding key file on the MongoDB keyserver. You need to find a file that includes the latest stable version number and ends with .asc. For example, if you want to install MongoDB version 5.0, you should look for a file named server-5.0.asc.

curl -fsSL | sudo apt-key add -

cURL is a command line tool that is available on many operating systems and is used to transfer data. It reads all the data stored in the given URL and outputs the content to the system output. In the following example, cURL outputs the contents of a GPG key file and then injects it into the sudo apt-key add – command, adding the GPG key to your list of trusted keys.

Also note that the curl command uses the -fsSL options, which together tell cURL not to execute the script unconditionally. This means that if for some reason cURL is unable to contact the GPG server, or the GPG server is down, it will not add the received error code to your list of trusted keys by accident.

If you want to double-check that the key was added correctly, you can do so by running the following command:

apt-key list

Run the following command, which creates a file in the sources.list.d directory named mongodb-org-5.0.list. This file contains only one line: deb [ arch=amd64,arm64 ] focal/mongodb-org/5.0 multiverse:

echo "deb [ arch=amd64,arm64 ] focal/mongodb-org/5.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-5.0.list
This single line tells APT everything it needs to know about the source and where to find it:
  • deb: means that the source refers to the regular Debian architecture. In other cases, this part of the line may look like deb-src. This means that the source represents the source code of the Debian distribution.

  • [ arch=amd64,arm64 ]: Specifies which architectures to load APT data into. In this case, these are the amd64 and arm64 architectures.

  • is a URI representing the location of the APT data. In this case, the URI points to the HTTPS address where the official MongoDB repository is located.

  • focal/mongodb-org/5.0: The Ubuntu repositories may contain several different releases. This means that you only need version 5.0 of the mongodb-org package available for the Ubuntu focal release (“Focal Fossa” is the code name for Ubuntu 20.04).

  • multiverse: This part points APT to one of the four main Ubuntu repositories. In this case, to the multiverse repository.

After running this command, update your server’s local package index so APT knows where to find the mongodb-org package: the site and repositories for the Russian Federation are no longer available, we use a proxy

sudo proxychains apt update

After that you can install MongoDB:

sudo proxychains apt install mongodb-org

Run the following systemctl command to start the MongoDB service:

sudo systemctl start mongod.service

Then check the status of the service.

sudo systemctl status mongod

After confirming that the service is running fine, set MongoDB service activation on boot:

sudo systemctl enable mongod

You can now verify that the database is running by connecting to the database server and running a diagnostic command. The following command connects to the database and displays the current version, server address, and port. It also outputs the result of the MongoDB connectionStatus internal command:

mongo --eval 'db.runCommand({ connectionStatus: 1 })'

connectionStatus checks and returns the database connection status. A value of 1 in the ok field in the response means that the server is working normally.

Now you can turn off Tor and continue working

service tor stop

That’s all. The purpose was to show only the installation method.

The MongoDB installation manual is taken from DigitalOcean + my edits and other articles on proxychains, the originals could not be found, because that was a long time ago. If someone tells me some other way, then I will supplement the article.

Thank you for your attention!

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *