Coder Social home page Coder Social logo

sasukefreestyle / xtls-iran-tls Goto Github PK

View Code? Open in Web Editor NEW
72.0 4.0 16.0 138 KB

How to make a V2ray (XTLS) Server for bypassing internet censorship in Iran.

License: GNU Affero General Public License v3.0

Shell 100.00%
anticensorship iran proxy trojan tunnel v2fly v2ray vmess vpn xray vless shadowsocks iranian persian xray-core xtls

xtls-iran-tls's Introduction

This Guide is outdated.

For an updated guide using reality protocol click on this link


XTLS-Iran-TLS

How to make a V2ray (XTLS) Server for bypassing internet censorship in Iran with TLS encryption and Fallback (Anti-probe) to Nginx webserver.

  • The main goal of this guide is to spread awereness on how to make one correctly.
  • I see many guides/videos online and v2ray servers in public Telegram groups that are missconfigured for Iranian users. Some are not even encrypted...
  • The configuration file (config.json) is the main key here that includes a correct CIDR-IP block so the server does not initiate a connection back to Iran as this is not "normal" behaviour for a (web)server.
  • The use of encryption, in this case TLS and a fallback to Nginx to prevent active-probing.
  • The use of uTLS fingerprint is also important. This is configured in the clients/apps.

This will not work CDNs like cloudflare e.t.c


Notes

  • This is a noob-friendly guide but if you are an experienced linux user you should make a new user without sudo-access to run xray and give right permissions to files.
  • I wanted to make it easy for anyone non-technical to make a server without changing/creating users or editing permissions of files.
  • I will also teach on how to use your Iranian IP for direct communication to Iranian websites/services without disconnecting the "VPN".

This guide is written for Ubuntu 22.04 LTS but any Debian based distro should also work.

What you need before starting this guide. Prerequisites

  • VPS or any other computer / Virtual-Machine running Ubuntu 22.04 LTS or a Debian based distro
  • SSH or terminal/console access to your server.
  • You need to know your username (the username when you log into Ubuntu)
  • A Domain name, You can get a free domain name from https://freedns.afraid.org/ or https://www.noip.com/
  • Domain name must be pointed to your IP hosting the server.
  • Port 80 and 443 open in your router or/and firewall.

First we need to do some kernel settings for performance and raise ulimits.

sudo nano /etc/sysctl.conf

Copy this at end of then file and save and close.

net.ipv4.tcp_keepalive_time = 90
net.ipv4.ip_local_port_range = 1024 65535
net.ipv4.tcp_fastopen = 3
net.core.default_qdisc=fq
net.ipv4.tcp_congestion_control=bbr
fs.file-max = 65535000

Then run this command to edit limits.conf

sudo nano /etc/security/limits.conf

Copy this at end of the file and save and close.

* soft     nproc          655350
* hard     nproc          655350
* soft     nofile         655350
* hard     nofile         655350
root soft     nproc          655350
root hard     nproc          655350
root soft     nofile         655350
root hard     nofile         655350

Run this to apply settings.

sudo sysctl -p

Install Xray (XTLS)

Create two folders in your username home folder. You should be in this folder when you log in.

mkdir xray
mkdir cert 

Update Ubuntu package list and install unzip.

sudo apt-get update
sudo apt-get install unzip

Change directory to the newly created xray folder.

cd xray/

Download the latest geoasset file for blocking Iranian websites.

wget https://github.com/bootmortis/iran-hosted-domains/releases/latest/download/iran.dat

Download the latest version of XTLS-Xray-Core.

At the time of writing this its 1.7.5.

Link to release page.

https://github.com/XTLS/Xray-core/releases

To download the zip file, we can use the wget command. Then we will unzip the file.

wget https://github.com/XTLS/Xray-core/releases/download/v1.8.3/Xray-linux-64.zip
unzip Xray-linux-64.zip

Remove the Xray-linux-64.zip for easier future updates. See updates

rm Xray-linux-64.zip

Generate UUID for config.json save this for later.

./xray uuid -i Secret

It should look something like this.

92c96807-e627-5328-8d85-XXXXXXXXX

Install xray to boot at startup (Systemd-Service) create file or copy paste xray.service file from this repository

Create service file.

sudo nano /etc/systemd/system/xray.service
[Unit]
Description=XTLS Xray-Core a VMESS/VLESS Server
After=network.target nss-lookup.target
[Service]
# Change to your username <---
User=USERNAME
Group=USERNAME
CapabilityBoundingSet=CAP_NET_ADMIN CAP_NET_BIND_SERVICE
AmbientCapabilities=CAP_NET_ADMIN CAP_NET_BIND_SERVICE
NoNewPrivileges=true
#                       --->  Change to your username  <---
ExecStart=/home/USERNAME/xray/xray run -config /home/USERNAME/xray/config.json
Restart=on-failure
RestartPreventExitStatus=23
StandardOutput=journal
LimitNPROC=100000
LimitNOFILE=1000000
[Install]
WantedBy=multi-user.target

Remember to edit this file to your own USERNAME! The parts to edit are.

User=USERNAME
Group=USERNAME
ExecStart=/home/USERNAME/xray/xray run -config /home/USERNAME/xray/config.json

Example

User=SasukeFreestyle
Group=SasukeFreestyle
ExecStart=/home/SasukeFreestyle/xray/xray run -config /home/SasukeFreestyle/xray/config.json

Reload services and enable auto-start.

sudo systemctl daemon-reload && sudo systemctl enable xray

Install Certbot and generate certificates

sudo snap install core; sudo snap refresh core
sudo snap install --classic certbot
sudo ln -s /snap/bin/certbot /usr/bin/certbot

Now we are going to get SSL/TLS certificates from Certbot for secure communication to the server.

We will make Certbot use a standalone webserver for certificate authorization.

For this you need port 80 open.

sudo certbot certonly --standalone --preferred-challenge http --agree-tos --register-unsafely-without-email
  • At this part enter your domain name (replace EXAMPLE.COM)
Please enter the domain name(s) you would like on your certificate (comma and/or
space separated) (Enter 'c' to cancel): EXAMPLE.COM

If no errors occurred you should now have SSL/TLS Certificates inside /etc/letsencrypt/live/EXAMPLE.COM/

Install Nginx from mainline

sudo apt-get install curl gnupg2 ca-certificates lsb-release ubuntu-keyring
curl https://nginx.org/keys/nginx_signing.key | gpg --dearmor | sudo tee /usr/share/keyrings/nginx-archive-keyring.gpg >/dev/null
echo "deb [signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg] \
http://nginx.org/packages/mainline/ubuntu `lsb_release -cs` nginx" \
    | sudo tee /etc/apt/sources.list.d/nginx.list
sudo apt-get update
sudo apt-get install nginx

Next we will remove server tokens from Nginx.

sudo nano /etc/nginx/nginx.conf

Add under sendfile on; in http block and save file.

server_tokens off;

Remove the Nginx default virtualhost configuration.

sudo rm /etc/nginx/conf.d/default.conf

Create a new default.conf and copy contents from default.conf from this repository.

sudo nano /etc/nginx/conf.d/default.conf

Edit the two first server_name EXAMPLE.COM; to your domain name.

server_name EXAMPLE.COM;

Do NOT edit server_name _; in the last server block (at the end of file)

Test Nginx configuration.

sudo nginx -t

If configuration is successful you will see this.

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

Reload services and enable Nginx auto-start and restart Nginx.

sudo systemctl daemon-reload
sudo systemctl enable nginx
sudo systemctl restart nginx

Xray Configuration

Create a new file called config.json inside xray folder. Copy contents of config.json from this repository to the file.

nano /home/USERNAME/xray/config.json
  • Enter your UUID inside "YOUR UUID HERE" Example: "id":"92c96807-e627-5328-8d85-XXXXXXXXX",
  • Change your path to your USERNAME
  • My recommendation is to use Vision without ,none. Most popular clients today support vision.
  • If your clients/apps does not support xtls-rprx-vision add ,none in flow.
  • If your client/app does support vision, do not add ,none to flow.

Example

"flow":"xtls-rprx-vision,none"

Or (recommended)

"flow":"xtls-rprx-vision"

The parts to edit are.

   "inbounds":[
      {
         "listen":"0.0.0.0",
         "port":443,
         "protocol":"vless",
         "settings":{
            "clients":[
               {
                  "id":"YOUR UUID HERE", // Edit to your own UUID
                  "flow":"xtls-rprx-vision" // add ,none if your apps/clients does not support vision.
               // "flow":"xtls-rprx-vision,none"
               }
            ],
            "decryption":"none",
            "fallbacks":[
               {
                  "dest":"/dev/shm/h1.sock",
                  "xver":2
               }
            ]
         },
         "streamSettings":{
            "network":"tcp",
            "security":"tls",
            "tlsSettings":{
               "MinVersion":"1.2",
               "MaxVersion":"1.3",
               "cipherSuites":"TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256:TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256:TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384:TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384:TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256:TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256",
               "alpn":[
                  "http/1.1"
               ],
               "certificates":[
                  {
                     "ocspStapling":3600,
                     "certificateFile":"/home/USERNAME/cert/fullchain.pem", //Edit USERNAME to your username
                     "keyFile":"/home/USERNAME/cert/privkey.pem"  //Edit USERNAME to your username
                  }
               ]
            }
         },

Example

"id":"92c96807-e627-5328-8d85-XXXXXXXXX",
"certificateFile":"/home/SasukeFreestyle/cert/fullchain.pem",
"keyFile":"/home/SasukeFreestyle/cert/privkey.pem"

Configure Certbot renewal script for certificate updates

Create a stop script, this script stops xray when certificates updates.

sudo nano /etc/letsencrypt/renewal-hooks/pre/stop.sh

Copy paste this text to file then save.

#!/bin/sh
systemctl stop xray

Make script executable.

sudo chmod +x /etc/letsencrypt/renewal-hooks/pre/stop.sh

Create a start script

sudo nano /etc/letsencrypt/renewal-hooks/post/start.sh

Edit EXAMPLE.COM and USERNAME to your domain and username. Copy paste this text to file then save.

#!/bin/sh
cp /etc/letsencrypt/live/EXAMPLE.COM/fullchain.pem /home/USERNAME/cert/fullchain.pem
cp /etc/letsencrypt/live/EXAMPLE.COM/privkey.pem /home/USERNAME/cert/privkey.pem
chown USERNAME:USERNAME /home/USERNAME/cert/fullchain.pem
chown USERNAME:USERNAME /home/USERNAME/cert/privkey.pem
systemctl start xray

Make script executable.

sudo chmod +x /etc/letsencrypt/renewal-hooks/post/start.sh

Run a Certbot dry-run, This will copy certificates to your cert folder in your home directory and start xray.

sudo certbot renew --dry-run

Check if xray is running it should now say Active: active (running).

sudo systemctl status xray
● xray.service - XTLS Xray-Core a VMESS/VLESS Server
     Loaded: loaded (/etc/systemd/system/xray.service; enabled; vendor preset: enabled)
     Active: active (running) since Tue 2023-02-14 18:31:07 CET; 22min ago
   Main PID: 338362 (xray)
      Tasks: 16 (limit: 9365)
     Memory: 279.6M
        CPU: 5min 28.315s

Finished. You now have a XTLS (V2ray) server with real certificates that are valid from all devices!

Visit https://EXAMPLE.COM (Your domain) and see if you can see "Welcome to nginx" website.

Client/Apps (Settings)

To connect to the server using V2rayNG or any other client these are the settings.

In V2rayNG press + then pick "Type manually[VLESS]"

Settings also apply to V2rayN (Windows).

Remember to set (uTLS) Fingerprint to Chrome.

  • Remarks/Alias
    • Name of the server, choose whatever name you want.
  • Address
    • Domain name of your server. (EXAMPLE.COM)
  • Port: 443
  • id:
    • Your UUID in config.json
  • Flow: xtls-rprx-vision
    • If your software does not have vision, leave flow empty. ,none in flow required.
  • Encryption: None
  • Network: TCP
  • TLS: TLS
  • uTLS/Fingerprint: Chrome
  • alpn: http/1.1
  • allowinsecure: False

photo_2023-02-26_04-49-03

If you want to be able to visit Iranians websites without disconnecting the VPN follow the instructions in the video below.

This will also make it harder for government to see that you are using a VPN.

  • Connect to your server then go to Settings -> Geo asset files -> press download cloud to download new Geo asset files.

  • Go to Settings -> Custom Rules -> Direct URL or IP.

Enter

geoip:private,
geosite:private,
geoip:ir,
geosite:category-ir
  • Then save and reconnect to your server. Try browsing to youtube and tci.ir both will now work at the same time.

Video Instructions:

Untitled.mp4

  • Settings for V2rayN.

Capt1ure

Optional (But recommended)

You should make a fake website with random contents and put your HTML files inside /usr/share/nginx/html/ This will make it harder to detect the server and will mask the server better.

How to update to latest version

If a new version of Xray is published and you want to update to the latest version do this easy steps.

  • Log into your machine with SSH.

Change directory to your xray folder.

cd xray/

wget the latest release, we will use this example link since latest version is still 1.7.5

wget https://github.com/XTLS/Xray-core/releases/download/v1.8.3/Xray-linux-64.zip

This command will stop the xray service and remove old files and start xray service again.

sudo systemctl stop xray && rm geo* && rm LICENSE && rm README.md && rm xray && unzip Xray-linux-64.zip && sudo systemctl start xray

Make sure xray is running by entering this command.

sudo systemctl status xray

Remove the zipfile.

rm Xray-linux-64.zip

Done!

Roadmap

  • Initial release of Instructions
  • Create or link to fake website for anti-probe
  • Create Dockerfile
  • Create install script

xtls-iran-tls's People

Contributors

sasukefreestyle avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

xtls-iran-tls's Issues

bind() to unix:/dev/shm fails on OpenVZ VPS

Hello and thanks for your comprehensive guide.
I am having a problem starting nginx with your provided config file in my OpenVZ VPS. I get the following error when I run systemctl restart nginx:

Mar 14 19:40:14 vps97472.hostsailor.com nginx[11319]: nginx: [emerg] bind() to unix:/dev/shm/h1.sock failed (98: Address already in use)
Mar 14 19:40:14 vps97472.hostsailor.com nginx[11319]: nginx: [emerg] bind() to unix:/dev/shm/h2c.sock failed (98: Address already in use)
Mar 14 19:40:15 vps97472.hostsailor.com nginx[11319]: nginx: [emerg] bind() to unix:/dev/shm/h1.sock failed (98: Address already in use)
Mar 14 19:40:15 vps97472.hostsailor.com nginx[11319]: nginx: [emerg] bind() to unix:/dev/shm/h2c.sock failed (98: Address already in use)
Mar 14 19:40:15 vps97472.hostsailor.com nginx[11319]: nginx: [emerg] bind() to unix:/dev/shm/h1.sock failed (98: Address already in use)
Mar 14 19:40:15 vps97472.hostsailor.com nginx[11319]: nginx: [emerg] bind() to unix:/dev/shm/h2c.sock failed (98: Address already in use)
Mar 14 19:40:16 vps97472.hostsailor.com nginx[11319]: nginx: [emerg] still could not bind()
Mar 14 19:40:16 vps97472.hostsailor.com systemd[1]: nginx.service: Control process exited, code=exited status=1
Mar 14 19:40:16 vps97472.hostsailor.com systemd[1]: nginx.service: Failed with result 'exit-code'.
Mar 14 19:40:16 vps97472.hostsailor.com systemd[1]: Failed to start A high performance web server and a reverse proxy server.

I'm not sure what this unix:/dev/shm listen address is but I Googled it and it seems it's some kind of memory sharing technique and I suspect maybe it's because I am using OpenVZ that I get this error because OpenVZ itself uses shared memory and is different from a real machine or KVM machines.

Xray service not starting

× xray.service - XTLS Xray-Core a VMESS/VLESS Server
Loaded: loaded (/etc/systemd/system/xray.service; enabled; preset: enabled)
Active: failed (Result: exit-code) since Sun 2023-03-05 18:06:12 UTC; 757ms ago
Duration: 2ms
Process: 982 ExecStart=/home/aniskhanak/xray/xray run -config /home/aniskhanak/xray/config.json (code=exited, status=2>
Main PID: 982 (code=exited, status=217/USER)
CPU: 1ms

Mar 05 18:06:12 ubuntu-1vcpu-2gb-lon1 systemd[1]: xray.service: Scheduled restart job, restart counter is at 5.
Mar 05 18:06:12 ubuntu-1vcpu-2gb-lon1 systemd[1]: Stopped XTLS Xray-Core a VMESS/VLESS Server.
Mar 05 18:06:12 ubuntu-1vcpu-2gb-lon1 systemd[1]: xray.service: Start request repeated too quickly.
Mar 05 18:06:12 ubuntu-1vcpu-2gb-lon1 systemd[1]: xray.service: Failed with result 'exit-code'.
Mar 05 18:06:12 ubuntu-1vcpu-2gb-lon1 systemd[1]: Failed to start XTLS Xray-Core a VMESS/VLESS Server.

v2ray client for IOS

Can You please recommend free v2ray client for IOS as v2rayNG is available only for Android?

hi, can you please help me with xtls vision?

Hi. I'm an Iranian. Have a USA vps. The ip is unfiltered and ports are accessable from Iran. But tls configs (ws tls, tcp tls, trojan ,etc) are having a lot of problems! It connects but the ping is very high, like 2000 when it should be 800 at most, and it's very unstable, it disconnects randomly and gives "tls handshake timeout" and has awful speed and ping. It only happens when I'm using tls. This is probably sth to do with government blocking. I have heard that xtls vision can solve this "tls handshake timeout" error. I installed x-ui. X-ui only has tls with vision flow, not xtls with vision flow. Is it okay or does it have to be xtls?? + I saw you mentioned something about fall back to fake ngingx website. How exactly can I do it? For example, I wanna make a vless xtls vision config with fall back to ngnix website. So steps are like this ?

1: setting up an ngninx server on port 443 or 8443.
2: making the config and putting the nginx hostname in the SNI field?

Please help a bother out. I'm confused , and frustrated. I'm also willing to give you the vps credentials to set up whatever you want, because I only know how to use x-ui.

use your config with xui

Hello,
i have installed x-ui panel already, and i want use your config and then use private CDN to hide ip, its possible?
so if possible, what configs i should set on x-ui panel ?
note: in x-ui panel i think i cant add vision

screenshot:
https://prnt.sc/L5-0h-BTie1R

Thanks for your help

No such authorization

Command entered:

sudo certbot certonly

Expected result:

Spin up a temporary webserver (standalone)

Actual result:

Saving debug log to /var/log/letsencrypt/letsencrypt.log

How would you like to authenticate with the ACME CA?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: Runs an HTTP server locally which serves the necessary validation files under
the /.well-known/acme-challenge/ request path. Suitable if there is no HTTP
server already running. HTTP challenge only (wildcards not supported).
(standalone)
2: Saves the necessary validation files to a .well-known/acme-challenge/
directory within the nominated webroot path. A seperate HTTP server must be
running and serving files from the webroot path. HTTP challenge only (wildcards
not supported). (webroot)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 1
Enter email address (used for urgent renewal and security notices)
 (Enter 'c' to cancel): [email protected]

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.3-September-21-2022.pdf. You must
agree in order to register with the ACME server. Do you agree?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: y

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Would you be willing, once your first certificate is successfully issued, to
share your email address with the Electronic Frontier Foundation, a founding
partner of the Let's Encrypt project and the non-profit organization that
develops Certbot? We'd like to send you email about our work encrypting the web,
EFF news, campaigns, and ways to support digital freedom.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: n
Account registered.
Please enter the domain name(s) you would like on your certificate (comma and/or
space separated) (Enter 'c' to cancel): xxxxx.xxxxx.xxx
Requesting a certificate for xxxxx.xxxxx.xxx
An unexpected error occurred:
No such authorization
Ask for help or search for solutions at https://community.letsencrypt.org. See the logfile /var/log/letsencrypt/letsencrypt.log or re-run Certbot with -v for more details.

Not working with TCI, # Update from TCI users needed, please report.

Hi Sasuke
thx for this tutorial.
I followed step by step and done.

but in both android and windows i got test Error on TCI ISP
I tested on TCI, Irancell and Rightel ISP's. just TCI has error.
what is problem? need I more complex configure? I need a configure to working on just TCI.

please help to fix this problem
thank you again.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.