Skip to content
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

How to integrate with python requests? #75

Open
Scylla2020 opened this issue Mar 21, 2022 · 6 comments
Open

How to integrate with python requests? #75

Scylla2020 opened this issue Mar 21, 2022 · 6 comments

Comments

@Scylla2020
Copy link

Hi I'm just wondering if this can be integrated with python requests library? What will the steps look like? I'm interested in running tests mimicking a web browser on a site that uses cloudfare. I want to use a library like requests or urllib, not browser emulation. My requests arent going through because of TLS fingerprinting since the requests library cant do this.

Normally I would request a site like this:

import requests

headers = {
    'authority': 'vplates.com.au',
    'sec-ch-ua': '" Not A;Brand";v="99", "Chromium";v="99", "Google Chrome";v="99"',
    'sec-ch-ua-mobile': '?0',
    'sec-ch-ua-platform': '"Windows"',
    'upgrade-insecure-requests': '1',
    'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.74 Safari/537.36',
    'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
    'sec-fetch-site': 'none',
    'sec-fetch-mode': 'navigate',
    'sec-fetch-user': '?1',
    'sec-fetch-dest': 'document',
    'accept-language': 'en-US,en;q=0.9',
}

response = requests.get('https://example.com/', headers=headers)

But the site site uses cloudflare so I get no response. Anyway to use ja3 to get around this?

@Scylla2020
Copy link
Author

Thanks. I had a look at the python github but couldnt get it working as I cant see any clear examples. So using the Go code what would the above request look like? Will be a good reason for me to finally learn a bit of go but I couldnt find any examples there either

@Scylla2020
Copy link
Author

Awesome thanks, will give it a shot

@Scylla2020
Copy link
Author

I tried on a different site but cloudfare error still showed up. Any ideas?

package main

import (
	"net/http"
	"os"
	"github.com/89z/format/crypto"
)

const ja3 = "771,49195-49196-52393-49199-49200-52392-49161-49162-49171-" +
	"49172-156-157-47-53,65281-0-23-35-13-5-16-11-10,29-23-24,0"

func main() {
	req, err := http.NewRequest("GET", "https://vplates.com.au", nil)
	if err != nil {
		panic(err)
	}
	req.Header = http.Header{
		"sec-fetch-dest": {"document"},
		"user-agent":     {"Mozilla/5.0 (Windows NT 10.0; Win64; x64)"},
		"authority":      {"vplates.com.au"},
		"accept":         {"text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9"},
	}
	hello, err := crypto.ParseJA3(ja3)
	if err != nil {
		panic(err)
	}
	res, err := crypto.Transport(hello).RoundTrip(req)
	if err != nil {
		panic(err)
	}
	defer res.Body.Close()
	os.Stdout.ReadFrom(res.Body)
}

@Scylla2020
Copy link
Author

True okay

@Kies8
Copy link

Kies8 commented Aug 31, 2023

Hi @Scylla2020, how did you solve?

@Scylla2020
Copy link
Author

@Kies8 i didnt solve it. It worked for some sites but not all

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants
@Scylla2020 @Kies8 and others