Exemple #1
0
        public string DecodeAndSaveFile(string retornoFilePath)
        {
            var key      = this.GetCryptKey();
            var fileName = Path.GetFileName(retornoFilePath);

            try
            {
                var wis = new br.com.bradesco.webta.security.crypto.WEBTAInputStream(
                    fileName,
                    Path.GetDirectoryName(retornoFilePath),
                    key);

                int    readBytes = 0;
                byte[] aux       = new byte[512];
                var    baos      = new java.io.ByteArrayOutputStream();
                while ((readBytes = wis.read(aux, 0, aux.Length)) > 0)
                {
                    baos.write(aux, 0, readBytes);
                }

                var outputFile = string.Concat(Path.Combine(Path.GetDirectoryName(retornoFilePath), Path.GetFileNameWithoutExtension(fileName)), ".out.RET");
                File.WriteAllText(outputFile, baos.toString());

                wis.close();

                return(outputFile);
            }
            catch (Exception ex)
            {
                throw new Exception(string.Format("Falha ao descriptografar o arquivo '{0}'.", fileName), ex);
            }
        }
Exemple #2
0
        /// <summary>Returns a byte[] containing the remainder of 'in'.</summary>
        /// <remarks>Returns a byte[] containing the remainder of 'in'.</remarks>
        /// <exception cref="System.IO.IOException"></exception>
        public static byte[] readFullyNoClose(java.io.InputStream @in)
        {
            java.io.ByteArrayOutputStream bytes = new java.io.ByteArrayOutputStream();
            byte[] buffer = new byte[1024];
            int    count;

            while ((count = @in.read(buffer)) != -1)
            {
                bytes.write(buffer, 0, count);
            }
            return(bytes.toByteArray());
        }
Exemple #3
0
 /// <param name="convertPlus">true to convert '+' to ' '.</param>
 public static string decode(string s, bool convertPlus, java.nio.charset.Charset
                             charset)
 {
     if (s.IndexOf('%') == -1 && (!convertPlus || s.IndexOf('+') == -1))
     {
         return(s);
     }
     java.lang.StringBuilder       result = new java.lang.StringBuilder(s.Length);
     java.io.ByteArrayOutputStream @out   = new java.io.ByteArrayOutputStream();
     {
         for (int i = 0; i < s.Length;)
         {
             char c = s[i];
             if (c == '%')
             {
                 do
                 {
                     if (i + 2 >= s.Length)
                     {
                         throw new System.ArgumentException("Incomplete % sequence at: " + i);
                     }
                     int d1 = hexToInt(s[i + 1]);
                     int d2 = hexToInt(s[i + 2]);
                     if (d1 == -1 || d2 == -1)
                     {
                         throw new System.ArgumentException("Invalid % sequence " + Sharpen.StringHelper.Substring
                                                                (s, i, i + 3) + " at " + i);
                     }
                     @out.write(unchecked ((byte)((d1 << 4) + d2)));
                     i += 3;
                 }while (i < s.Length && s[i] == '%');
                 result.append(XobotOS.Runtime.Util.GetStringForBytes(@out.toByteArray(), charset)
                               );
                 @out.reset();
             }
             else
             {
                 if (convertPlus && c == '+')
                 {
                     c = ' ';
                 }
                 result.append(c);
                 i++;
             }
         }
     }
     return(result.ToString());
 }
Exemple #4
0
		/// <param name="convertPlus">true to convert '+' to ' '.</param>
		public static string decode(string s, bool convertPlus, java.nio.charset.Charset 
			charset)
		{
			if (s.IndexOf('%') == -1 && (!convertPlus || s.IndexOf('+') == -1))
			{
				return s;
			}
			java.lang.StringBuilder result = new java.lang.StringBuilder(s.Length);
			java.io.ByteArrayOutputStream @out = new java.io.ByteArrayOutputStream();
			{
				for (int i = 0; i < s.Length; )
				{
					char c = s[i];
					if (c == '%')
					{
						do
						{
							if (i + 2 >= s.Length)
							{
								throw new System.ArgumentException("Incomplete % sequence at: " + i);
							}
							int d1 = hexToInt(s[i + 1]);
							int d2 = hexToInt(s[i + 2]);
							if (d1 == -1 || d2 == -1)
							{
								throw new System.ArgumentException("Invalid % sequence " + Sharpen.StringHelper.Substring
									(s, i, i + 3) + " at " + i);
							}
							@out.write(unchecked((byte)((d1 << 4) + d2)));
							i += 3;
						}
						while (i < s.Length && s[i] == '%');
						result.append(XobotOS.Runtime.Util.GetStringForBytes(@out.toByteArray(), charset)
							);
						@out.reset();
					}
					else
					{
						if (convertPlus && c == '+')
						{
							c = ' ';
						}
						result.append(c);
						i++;
					}
				}
			}
			return result.ToString();
		}
Exemple #5
0
 public override void write(int i)
 {
     _out.write(i);
 }
Exemple #6
0
        public static string check(string proxy, string combo)
        {
            try
            {
                HttpRequest vlient = new HttpRequest();
                JArray      lol    =
                    JArray.Parse(
                        JObject.Parse(vlient.Get("http://apresolve.spotify.com/?type=accesspoint").ToString())[
                            "accesspoint"].ToString());
                TcpClient clinet = null;
                Random    random = new Random();

                string host = lol[random.Next(0, lol.Count)].ToString();

                if (proxy == "null")
                {
                    clinet = new TcpClient(host.Split(':')[0], int.Parse(host.Split(':')[1]));
                }
                else
                {
                    clinet = ProxyTcpClient(host.Split(':')[0], int.Parse(host.Split(':')[1]), proxy.Split(':')[0], int.Parse(proxy.Split(':')[1]));
                }
                //clinet = new TcpClient(host.Split(':')[0], int.Parse(host.Split(':')[1]));
                if (clinet == null)
                {
                    return("error");
                }

                clinet.ReceiveTimeout = 4000;
                clinet.SendTimeout    = 4000;
                com.JB.crypto.DiffieHellman keys = new com.JB.crypto.DiffieHellman(new java.util.Random());
                byte[]      clientHello          = com.JB.core.Session.clientHello(keys);
                Accumulator acc = new Accumulator();

                var a = clinet.GetStream();
                a.WriteByte(0x00);
                a.WriteByte(0x04);
                a.WriteByte(0x00);
                a.WriteByte(0x00);
                a.WriteByte(0x00);
                a.Flush();
                int    lenght = 2 + 4 + clientHello.Length;
                byte[] bytes  = BitConverter.GetBytes(lenght);
                a.WriteByte(bytes[0]);
                a.Write(clientHello, 0, clientHello.Length);
                a.Flush();
                Byte[] buffer = new byte[1000];
                int    len    = int.Parse(a.Read(buffer, 0, buffer.Length).ToString());
                byte[] tmp    = new byte[len];
                Array.Copy(buffer, tmp, len);

                tmp = tmp.Skip(4).ToArray();

                acc.writeByte(0x00);
                acc.writeByte(0x04);
                acc.writeInt(lenght);
                acc.write(clientHello);
                acc.writeInt(len);
                acc.write(tmp);
                acc.dump();

                com.spotify.Keyexchange.APResponseMessage apResponseMessage =
                    com.spotify.Keyexchange.APResponseMessage.parseFrom(tmp);
                byte[] sharedKey = com.JB.common.Utils.toByteArray(keys.computeSharedKey(apResponseMessage
                                                                                         .getChallenge().getLoginCryptoChallenge().getDiffieHellman().getGs().toByteArray()));

                java.security.KeyFactory factory   = java.security.KeyFactory.getInstance("RSA");
                java.security.PublicKey  publicKey = factory.generatePublic(
                    new java.security.spec.RSAPublicKeySpec(new java.math.BigInteger(1, serverKey),
                                                            java.math.BigInteger.valueOf(65537)));
                java.security.Signature sig = java.security.Signature.getInstance("SHA1withRSA");
                sig.initVerify(publicKey);
                sig.update(apResponseMessage.getChallenge().getLoginCryptoChallenge().getDiffieHellman().getGs()
                           .toByteArray());
                sig.verify(apResponseMessage.getChallenge().getLoginCryptoChallenge().getDiffieHellman()
                           .getGsSignature().toByteArray());

                java.io.ByteArrayOutputStream data = new java.io.ByteArrayOutputStream(100);

                javax.crypto.Mac mac = javax.crypto.Mac.getInstance("HmacSHA1");
                mac.init(new javax.crypto.spec.SecretKeySpec(sharedKey, "HmacSHA1"));
                for (int i = 1; i < 6; i++)
                {
                    mac.update(acc.array());
                    mac.update(new byte[] { (byte)i });
                    data.write(mac.doFinal());
                    mac.reset();
                }

                byte[] dataArray = data.toByteArray();
                mac = javax.crypto.Mac.getInstance("HmacSHA1");
                mac.init(new javax.crypto.spec.SecretKeySpec(java.util.Arrays.copyOfRange(dataArray, 0, 0x14),
                                                             "HmacSHA1"));
                mac.update(acc.array());
                byte[] challenge = mac.doFinal();

                com.spotify.Keyexchange.ClientResponsePlaintext clientResponsePlaintext = com.spotify.Keyexchange
                                                                                          .ClientResponsePlaintext.newBuilder()
                                                                                          .setLoginCryptoResponse(com.spotify.Keyexchange.LoginCryptoResponseUnion.newBuilder()
                                                                                                                  .setDiffieHellman(com.spotify.Keyexchange.LoginCryptoDiffieHellmanResponse.newBuilder()
                                                                                                                                    .setHmac(com.google.protobuf.ByteString.copyFrom(challenge)).build())
                                                                                                                  .build())
                                                                                          .setPowResponse(com.spotify.Keyexchange.PoWResponseUnion.newBuilder().build())
                                                                                          .setCryptoResponse(com.spotify.Keyexchange.CryptoResponseUnion.newBuilder().build())
                                                                                          .build();

                byte[] clientResponsePlaintextBytes = clientResponsePlaintext.toByteArray();
                len = 4 + clientResponsePlaintextBytes.Length;
                a.WriteByte(0x00);
                a.WriteByte(0x00);
                a.WriteByte(0x00);
                byte[] bytesb = BitConverter.GetBytes(len);
                a.WriteByte(bytesb[0]);
                a.Write(clientResponsePlaintextBytes, 0, clientResponsePlaintextBytes.Length);
                a.Flush();

                com.spotify.Authentication.LoginCredentials loginCredentials = com.spotify.Authentication
                                                                               .LoginCredentials.newBuilder()
                                                                               .setUsername(combo.Split(':')[0])
                                                                               .setTyp(com.spotify.Authentication.AuthenticationType.AUTHENTICATION_USER_PASS)
                                                                               .setAuthData(com.google.protobuf.ByteString.copyFromUtf8(combo.Split(':')[1]))
                                                                               .build();

                com.spotify.Authentication.ClientResponseEncrypted clientResponseEncrypted = com.spotify.Authentication
                                                                                             .ClientResponseEncrypted.newBuilder()
                                                                                             .setLoginCredentials(loginCredentials)
                                                                                             .setSystemInfo(com.spotify.Authentication.SystemInfo.newBuilder()
                                                                                                            .setOs(com.spotify.Authentication.Os.OS_UNKNOWN)
                                                                                                            .setCpuFamily(com.spotify.Authentication.CpuFamily.CPU_UNKNOWN)
                                                                                                            .setSystemInformationString(com.JB.Version.systemInfoString())
                                                                                                            .setDeviceId(com.JB.common.Utils.randomHexString(new java.util.Random(), 30))
                                                                                                            .build())
                                                                                             .setVersionString(com.JB.Version.versionString())
                                                                                             .build();

                com.JB.crypto.Shannon sendCipher = new com.JB.crypto.Shannon();
                sendCipher.key(java.util.Arrays.copyOfRange(data.toByteArray(), 0x14, 0x34));
                AtomicInteger sendNonce = new AtomicInteger(0);

                com.JB.crypto.Shannon recvCipher = new com.JB.crypto.Shannon();
                recvCipher.key(java.util.Arrays.copyOfRange(data.toByteArray(), 0x34, 0x54));
                AtomicInteger recvNonce = new AtomicInteger(0);
                sendCipher.nonce(com.JB.common.Utils.toByteArray(sendNonce.getAndIncrement()));

                java.nio.ByteBuffer buffer2 =
                    java.nio.ByteBuffer.allocate(1 + 2 + clientResponseEncrypted.toByteArray().Length);
                buffer2.put(com.JB.crypto.Packet.Type.Login.val)
                .putShort((short)clientResponseEncrypted.toByteArray().Length)
                .put(clientResponseEncrypted.toByteArray());

                byte[] bytess = buffer2.array();
                sendCipher.encrypt(bytess);
                byte[] macc = new byte[4];
                sendCipher.finish(macc);
                a.Write(bytess, 0, bytess.Length);
                a.Write(macc, 0, macc.Length);
                a.Flush();
                recvCipher.nonce(com.JB.common.Utils.toByteArray(recvNonce.getAndIncrement()));

                byte[] headerBytes = new byte[3];
                a.Read(headerBytes, 0, 3);
                recvCipher.decrypt(headerBytes);

                short  payloadLength = (short)((headerBytes[1] << 8) | (headerBytes[2] & 0xFF));
                byte[] payloadBytes  = new byte[payloadLength];
                a.Read(payloadBytes, 0, payloadBytes.Length);
                recvCipher.decrypt(payloadBytes);

                byte[] maccc = new byte[4];
                a.Read(maccc, 0, maccc.Length);
                if (headerBytes[0] == 172)
                {
                    com.spotify.Authentication.APWelcome apWelcome = com.spotify.Authentication.APWelcome.parseFrom(payloadBytes);

                    int    i    = 0;
                    string lel  = "";
                    string lel2 = "";
                    while (true)
                    {
                        recvCipher.nonce(com.JB.common.Utils.toByteArray(recvNonce.getAndIncrement()));

                        headerBytes = new byte[3];
                        a.Read(headerBytes, 0, 3);
                        recvCipher.decrypt(headerBytes);

                        payloadLength = (short)((headerBytes[1] << 8) | (headerBytes[2] & 0xFF));
                        payloadBytes  = new byte[payloadLength];
                        a.Read(payloadBytes, 0, payloadBytes.Length);
                        Thread.Sleep(10);
                        recvCipher.decrypt(payloadBytes);
                        maccc = new byte[4];
                        a.Read(maccc, 0, maccc.Length);

                        //File.WriteAllBytes(headerBytes[0]+".txt",payloadBytes);
                        if (headerBytes[0] == 27)
                        {
                            System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding();
                            lel2 = enc.GetString(payloadBytes);
                            i++;
                        }
                        if (headerBytes[0] == 80)
                        {
                            Console.WriteLine(com.JB.core.Session.parse(payloadBytes).get("financial-product").ToString());
                            lel = com.JB.core.Session.parse(payloadBytes).get("financial-product").ToString();
                            i++;
                        }

                        if (i >= 2)
                        {
                            return(lel + "-lol-" + apWelcome + "-lol-" + lel2);
                        }
                    }
                }
                else if (headerBytes[0] == 173)
                {
                    return("invalid");
                }
            }
            catch (Exception ex)
            {
                return("error");
            }

            return("error");
        }
Exemple #7
0
		/// <summary>Returns a byte[] containing the remainder of 'in'.</summary>
		/// <remarks>Returns a byte[] containing the remainder of 'in'.</remarks>
		/// <exception cref="System.IO.IOException"></exception>
		public static byte[] readFullyNoClose(java.io.InputStream @in)
		{
			java.io.ByteArrayOutputStream bytes = new java.io.ByteArrayOutputStream();
			byte[] buffer = new byte[1024];
			int count;
			while ((count = @in.read(buffer)) != -1)
			{
				bytes.write(buffer, 0, count);
			}
			return bytes.toByteArray();
		}