Skip to content

Commit

Permalink
Merge pull request #550 from MortezaBashsiz/py-new-fronting-technique
Browse files Browse the repository at this point in the history
implemented jafar method for fronting test
  • Loading branch information
tempookian authored May 10, 2023
2 parents 7df0e9e + e679eec commit 2216f3b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 15 deletions.
4 changes: 3 additions & 1 deletion python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,8 @@ Contributors names and contact info
* Fixed a bug in reading subnets from file with full address in windows
* 1.3.16
* Added no-fronting option
* 1.3.17
* Improved the fronting test method (jafar method)

[python]: https://img.shields.io/badge/-Python-3776AB?logo=python&logoColor=white
[version]: https://img.shields.io/badge/Version-1.3.16-blue
[version]: https://img.shields.io/badge/Version-1.3.17-blue
28 changes: 15 additions & 13 deletions python/cfscanner/speedtest/fronting.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import re

import requests


Expand All @@ -16,28 +18,28 @@ def fronting_test(
"""
s = requests.Session()
s.get_adapter(
'https://').poolmanager.connection_pool_kw['server_hostname'] = "speed.cloudflare.com"
'https://').poolmanager.connection_pool_kw['server_hostname'] = "jafar.mashallah.gq"
s.get_adapter(
'https://').poolmanager.connection_pool_kw['assert_hostname'] = "speed.cloudflare.com"
'https://').poolmanager.connection_pool_kw['assert_hostname'] = "jafar.mashallah.gq"

try:
compatible_ip = f"[{ip}]" if ":" in ip else ip
r = s.get(
f"https://{compatible_ip}/__down?bytes=10",
timeout=timeout,
headers={"Host": "speed.cloudflare.com"}
headers={"Host": "jafar.mashallah.gq"}
)
if r.status_code != 200:
return f"[bold red1]NO[/bold red1] [orange3]{ip:15s}[/orange3][yellow1] fronting error {r.status_code} [/yellow1]"
elif r.content != b"0" * 10:
return f"[bold red1]NO[/bold red1] [orange3]{ip:15s}[/orange3][yellow1] fronting error - unexpected response [/yellow1]"
except requests.exceptions.ConnectTimeout as e:
return f"[bold red1]NO[/bold red1] [orange3]{ip:15s}[/orange3][yellow1] fronting connect timeout[/yellow1]"
except requests.exceptions.ReadTimeout as e:
return f"[bold red1]NO[/bold red1] [orange3]{ip:15s}[/orange3][yellow1] fronting read timeout[/yellow1]"
except requests.exceptions.Timeout as e:
return f"[bold red1]NO[/bold red1] [orange3]{ip:15s}[/orange3][yellow1] fronting timeout[/yellow1]"
except requests.exceptions.ConnectionError as e:
return f"[bold red1]NO[/bold red1] [orange3]{ip:15s}[/orange3][yellow1] fronting connection error[/yellow1]"

try:
regex = r"^<title>(.+)<\/title>$"
re_match = re.findall(regex, r.text, re.MULTILINE)[0]
if "CNAME Cross-User Banned" in re_match:
return "OK"
else:
return f"[bold red1]NO[/bold red1] [orange3]{ip:15s}[/orange3][yellow1] fronting Unknown error[/yellow1]"
except Exception as e:
return f"[bold red1]NO[/bold red1] [orange3]{ip:15s}[/orange3][yellow1] fronting Unknown error[/yellow1]"

return "OK"
2 changes: 1 addition & 1 deletion python/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "hatchling.build"

[project]
name = "cfscanner"
version = "1.3.16"
version = "1.3.17"
authors = [
{ name="tempookian", email="tempookian@gmail.com" },
{ name="Morteza Bashsiz", email="morteza.bashsiz@gmail.com"}
Expand Down

0 comments on commit 2216f3b

Please sign in to comment.