@DAnya78

Почему не работает код и как можно решить?

Делаю авторизацию на сервис steam, и нужно было пароль зашифровать и сделать запрос
Шифрования rsa взял прямо сайта
var RSAPublicKey = function($modulus_hex, $encryptionExponent_hex) {
	this.modulus = new BigInteger( $modulus_hex, 16);
	this.encryptionExponent = new BigInteger( $encryptionExponent_hex, 16);
};
var Base64 = {
	base64: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
	encode: function($input) {
		if (!$input) {
			return false;
		}
		var $output = "";
		var $chr1, $chr2, $chr3;
		var $enc1, $enc2, $enc3, $enc4;
		var $i = 0;
		do {
			$chr1 = $input.charCodeAt($i++);
			$chr2 = $input.charCodeAt($i++);
			$chr3 = $input.charCodeAt($i++);
			$enc1 = $chr1 >> 2;
			$enc2 = (($chr1 & 3) << 4) | ($chr2 >> 4);
			$enc3 = (($chr2 & 15) << 2) | ($chr3 >> 6);
			$enc4 = $chr3 & 63;
			if (isNaN($chr2)) $enc3 = $enc4 = 64;
			else if (isNaN($chr3)) $enc4 = 64;
			$output += this.base64.charAt($enc1) + this.base64.charAt($enc2) + this.base64.charAt($enc3) + this.base64.charAt($enc4);
		} while ($i < $input.length);
		return $output;
	},
	decode: function($input) {
		if(!$input) return false;
		$input = $input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
		var $output = "";
		var $enc1, $enc2, $enc3, $enc4;
		var $i = 0;
		do {
			$enc1 = this.base64.indexOf($input.charAt($i++));
			$enc2 = this.base64.indexOf($input.charAt($i++));
			$enc3 = this.base64.indexOf($input.charAt($i++));
			$enc4 = this.base64.indexOf($input.charAt($i++));
			$output += String.fromCharCode(($enc1 << 2) | ($enc2 >> 4));
			if ($enc3 != 64) $output += String.fromCharCode((($enc2 & 15) << 4) | ($enc3 >> 2));
			if ($enc4 != 64) $output += String.fromCharCode((($enc3 & 3) << 6) | $enc4);
		} while ($i < $input.length);
		return $output;
	}
};

var Hex = {
	hex: "0123456789abcdef",
	encode: function($input) {
		if(!$input) return false;
		var $output = "";
		var $k;
		var $i = 0;
		do {
			$k = $input.charCodeAt($i++);
			$output += this.hex.charAt(($k >> 4) &0xf) + this.hex.charAt($k & 0xf);
		} while ($i < $input.length);
		return $output;
	},
	decode: function($input) {
		if(!$input) return false;
		$input = $input.replace(/[^0-9abcdef]/g, "");
		var $output = "";
		var $i = 0;
		do {
			$output += String.fromCharCode(((this.hex.indexOf($input.charAt($i++)) << 4) & 0xf0) | (this.hex.indexOf($input.charAt($i++)) & 0xf));
		} while ($i < $input.length);
		return $output;
	}
};

var RSA = {
	getPublicKey: function( $modulus_hex, $exponent_hex ) {
		return new RSAPublicKey( $modulus_hex, $exponent_hex );
	},
	encrypt: function($data, $pubkey) {
		if (!$pubkey) return false;
		$data = this.pkcs1pad2($data,($pubkey.modulus.bitLength()+7)>>3);
		if(!$data) return false;
		$data = $data.modPowInt($pubkey.encryptionExponent, $pubkey.modulus);
		if(!$data) return false;
		$data = $data.toString(16);
		if(($data.length & 1) == 1)
			$data = "0" + $data;
		return Base64.encode(Hex.decode($data));
	},
	pkcs1pad2: function($data, $keysize) {
		if($keysize < $data.length + 11)
			return null;
		var $buffer = [];
		var $i = $data.length - 1;
		while($i >= 0 && $keysize > 0)
			$buffer[--$keysize] = $data.charCodeAt($i--);
		$buffer[--$keysize] = 0;
		while($keysize > 2)
			$buffer[--$keysize] = Math.floor(Math.random()*254) + 1;
		$buffer[--$keysize] = 2;
		$buffer[--$keysize] = 0;
		return new BigInteger($buffer);
	}
};

OnAuthCodeResponse = function(PUBLICKEY_MOD,PUBLICKEY_EXP,PASSWORD) {
    var pubKey = RSA.getPublicKey(PUBLICKEY_MOD,PUBLICKEY_EXP);
    var encryptedPassword = RSA.encrypt(PASSWORD, pubKey );
    return encryptedPassword
};

import time
import execjs
import requests
login_url = 'https://store.steampowered.com/login/dologin/'
get_rsa_key_url = 'https://store.steampowered.com/login/getrsakey/'
headers = {'Host': 'store.steampowered.com',
           'Origin': 'https://store.steampowered.com',
           'Referer': 'https://store.steampowered.com/login/?redir=&redir_ssl=1&snr=1_4_4__global-header',
           'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.71 Safari/537.36'}
session = requests.session()
def get_rsa_key(username):
    data = {'donotcache': str(int(time.time() * 1000)),'username':username}
    response = session.post(url=get_rsa_key_url, data=data, headers=headers).json()
    print(response)
    return response
def get_encrypted_password(publickey_mod,publickey_exp,password):
    f = open('steam.js', 'r', encoding='utf-8')
    steampowered_js = f.read()
    f.close()
    encrypted_password = execjs.compile(steampowered_js).call('OnAuthCodeResponse',publickey_mod,publickey_exp,password)
    return encrypted_password
def login(username, encrypted_password, rsa_key_dict):
    data = {
        'donotcache': str(int(time.time() * 1000)),
        'password': encrypted_password,
        'username': username,
        'twofactorcode': '',
        'emailauth': '',
        'loginfriendlyname': '',
        'emailsteamid': '',
        'rsatimestamp': rsa_key_dict['timestamp'],
        'remember_login': False,
        'tokentype': '-1'   }
    print(data)
    response = session.post(url=login_url, data=data, headers=headers)
    print(response.text)
def main():
    username = input(' Please enter your login account : ')
    password = input(' Please enter the login password : ')
    rsa_key_dict = get_rsa_key(username)
    encrypted_password = get_encrypted_password(rsa_key_dict['publickey_mod'],rsa_key_dict['publickey_exp'],password)
    login(username, encrypted_password, rsa_key_dict)
if __name__ == '__main__':    main()

Please enter your login account : bidid74764sadasd
 Please enter the login password : bidid74764
{'success': True, 'publickey_mod': 'c448ae230f0544ac1cff4f4272bea2ec0639bd5988da36241a68d19fd7aec1dbbff66eee90a8e4aa9ae1a4bc3f1d24623f8daa7e53abb203f6b42fc5d283e30caf7a1159f5b55712b76b563e103b80e39c7c63d6b7c945e73278f9e90f686c4b07c47a7a467197f0b760736d01efdff70f2e7ca9ad3579f613ababa91524f09a6186563f37995578e1667048f9ceba862be04c9d528a8d5b8f2ed652cf042ab615e83abc2d8e0cf5fea37259d9c2cbf3cba73dd9b323ff2bb89e055be3a1b987870aa5167ee146a23a3d72feac54435e32dfaa544a2e3e99bcc0d8ec97f4bcb540dd32599a3c128119c3883e4364d9979f607d211b16dc5af7cd9742183bb65d', 'publickey_exp': '010001', 'timestamp': '14415700000', 'token_gid': '29fa0809f780401f'}
Traceback (most recent call last):
  File "C:\Users\dgana\OneDrive\Рабочий стол\Rabota lolz\steamcommunity.com\steam.py", line 46, in <module>
    if __name__ == '__main__':    main()  #bidid74764	bidid74764sadasd
  File "C:\Users\dgana\OneDrive\Рабочий стол\Rabota lolz\steamcommunity.com\steam.py", line 43, in main
    encrypted_password = get_encrypted_password(rsa_key_dict['publickey_mod'],rsa_key_dict['publickey_exp'],password)
  File "C:\Users\dgana\OneDrive\Рабочий стол\Rabota lolz\steamcommunity.com\steam.py", line 20, in get_encrypted_password
    encrypted_password = execjs.compile(steampowered_js).call('OnAuthCodeResponse',publickey_mod,publickey_exp,password)
  File "C:\Users\dgana\AppData\Local\Programs\Python\Python310\lib\site-packages\execjs\_abstract_runtime_context.py", line 37, in call
    return self._call(name, *args)
  File "C:\Users\dgana\AppData\Local\Programs\Python\Python310\lib\site-packages\execjs\_external_runtime.py", line 92, in _call
    return self._eval("{identifier}.apply(this, {args})".format(identifier=identifier, args=args))
  File "C:\Users\dgana\AppData\Local\Programs\Python\Python310\lib\site-packages\execjs\_external_runtime.py", line 78, in _eval
    return self.exec_(code)
  File "C:\Users\dgana\AppData\Local\Programs\Python\Python310\lib\site-packages\execjs\_abstract_runtime_context.py", line 18, in exec_
    return self._exec_(source)
  File "C:\Users\dgana\AppData\Local\Programs\Python\Python310\lib\site-packages\execjs\_external_runtime.py", line 88, in _exec_
    return self._extract_result(output)
  File "C:\Users\dgana\AppData\Local\Programs\Python\Python310\lib\site-packages\execjs\_external_runtime.py", line 167, in _extract_result
    raise ProgramError(value)
execjs._exceptions.ProgramError: TypeError: 'BigInteger' - определение отсутствует

Искал где есть краткое решения шифровки на python без библиотеки pyCrypto но не нашел, только это
Логин и пароль действительные можете использовать
  • Вопрос задан
  • 268 просмотров
Пригласить эксперта
Ответы на вопрос 1
@MaxKozlov
Длинные портянки текста нет сил читать ?
ProgramError: TypeError: 'BigInteger' - определение отсутствует

Найдите там где брали код и реализацию BigInteger
Ответ написан
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы