🙂 İNSANLARIN EN HAYIRLISI INSANLARA FAYDALI OLANDIR 🙂

Ramazan HABER / C# RMOS / açık olan chromenin cokielerini alma sessionslarını alma

1-) C# RMOS - açık olan chrome'nin cokie'lerini alma sessions'larını alma

 

Install-Package Portable.BouncyCastle -Version 1.8.10

Install-Package System.Security.Cryptography.ProtectedData -Version 4.7.0

Install-Package sqlite -Version 3.13.0

Install-Package System.Data.SQLite.Linq -Version 1.0.113

Install-Package System.Data.SQLite.EF6 -Version 1.0.113

 

1-) AŞAĞIDAKİ OPERA İÇİN

 

# KULLANIMI #

 

private void btnEanOlustur_Click(object sender, EventArgs e)

        {

            CookieContainer cookies = new CookieContainer();

            List<CookieModel> cookieModels = getCokiesss("amazon");

            foreach (CookieModel model in cookieModels)

            {

                Cookie cokSessions = new Cookie(model.key, model.value) { Domain = model.domain };

                Console.WriteLine(model.domain + " -- " + model.key + " -- " + model.value);

                cookies.Add(cokSessions);

            }

            HttpClientHandler handler = new HttpClientHandler();

            handler.CookieContainer = cookies;

 

            HttpClient client = new HttpClient(handler);

 

            Console.WriteLine(getEan("B07L7QM28Q", client));

            Console.WriteLine(getEan("B07L7QN8TG", client));

            Console.WriteLine(getEan("B0034ZP4TU", client));

        }

 

public string getEan(string asin, HttpClient client)

        {

 

            string tamlink = "https://sellercentral.amazon.com.tr/productsearch/search?query=" + asin + "&page=1";

 

            var response = client.GetAsync(tamlink).Result;

            var byteArray = response.Content.ReadAsByteArrayAsync().Result;

            string result = Encoding.UTF8.GetString(byteArray, 0, byteArray.Length);

 

            Ean.Root ean = JsonConvert.DeserializeObject<Ean.Root>(result);

            return ean.products[0].ean;

        }

 

 

 public class CookieModel

        {

            public string domain { get; set; }

            public string key { get; set; }

            public string value { get; set; }

        }

 

public List<CookieModel> getCokiesss(string hostName)

        {

            List<CookieModel> cookieModels = new List<CookieModel>();

            var dbPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\Opera Software\Opera Stable\Cookies";

 

            if (!System.IO.File.Exists(dbPath))

            {

                MessageBox.Show("YOL BULUNAMADI! " + dbPath);

                return null;

            }

 

            var connectionString = "Data Source=" + dbPath + ";pooling=false";

 

            var conn = new System.Data.SQLite.SQLiteConnection(connectionString);

            var cmd = conn.CreateCommand();

 

            var prm = cmd.CreateParameter();

            prm.ParameterName = "hostName";

            prm.Value = hostName;

            cmd.Parameters.AddWithValue("@hostName", "%" + hostName + "%");

 

            cmd.CommandText = "SELECT name,encrypted_value,host_key FROM cookies WHERE host_key like @hostName";

 

            conn.Open();

            var reader = cmd.ExecuteReader();

 

            while (reader.Read())

            {

                var encryptedData = (byte[])reader[1];

 

                string encKey = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\Opera Software\Opera Stable\Local State";

                string alltex = File.ReadAllText(encKey);

                var ob = JsonConvert.DeserializeObject(alltex);

                encKey = JObject.Parse(ob.ToString())["os_crypt"]["encrypted_key"].ToString();

 

                var decodedKey = System.Security.Cryptography.ProtectedData.Unprotect(Convert.FromBase64String(encKey).Skip(5).ToArray(), null, System.Security.Cryptography.DataProtectionScope.LocalMachine);

 

                var plainText = _decryptWithKey(encryptedData, decodedKey, 3);

 

                CookieModel model = new CookieModel();

                model.key = reader.GetString(0);

                model.value = plainText;

                model.domain = reader.GetString(2);

 

                cookieModels.Add(model);

            }

 

            conn.Close();

            return cookieModels;

        }

 

private string _decryptWithKey(byte[] message, byte[] key, int nonSecretPayloadLength)

        {

            const int KEY_BIT_SIZE = 256;

            const int MAC_BIT_SIZE = 128;

            const int NONCE_BIT_SIZE = 96;

 

            if (key == null || key.Length != KEY_BIT_SIZE / 8)

                throw new ArgumentException(String.Format("Key needs to be {0} bit!", KEY_BIT_SIZE), "key");

            if (message == null || message.Length == 0)

                throw new ArgumentException("Message required!", "message");

 

            using (var cipherStream = new MemoryStream(message))

            using (var cipherReader = new BinaryReader(cipherStream))

            {

                var nonSecretPayload = cipherReader.ReadBytes(nonSecretPayloadLength);

                var nonce = cipherReader.ReadBytes(NONCE_BIT_SIZE / 8);

                var cipher = new GcmBlockCipher(new AesEngine());

                var parameters = new AeadParameters(new KeyParameter(key), MAC_BIT_SIZE, nonce);

                cipher.Init(false, parameters);

                var cipherText = cipherReader.ReadBytes(message.Length);

                var plainText = new byte[cipher.GetOutputSize(cipherText.Length)];

                try

                {

                    var len = cipher.ProcessBytes(cipherText, 0, cipherText.Length, plainText, 0);

                    cipher.DoFinal(plainText, len);

                }

                catch (InvalidCipherTextException)

                {

                    return null;

                }

                return Encoding.Default.GetString(plainText);

            }

        }

 

 

 

 

 

# DİĞER YOL KULLANIMI #

 

  private void btnEanOlustur_Click(object sender, EventArgs e)

        {

            // 8681529832987

            //string[] hosts = { ".amazon.com.tr", "sellercentral.amazon.com.tr", ".account.amazon.com" };

            string[] hosts = { "amazon.com" };

            string keysler = "", keys = "";

            List<CookieModel> edevlets = new List<CookieModel>();

            foreach (var item in hosts)

            {

                keys = SessionsCek_2(item);

 

                if (keys.Equals(""))

                {

                    keys = SessionsCek(item);

                }

 

                string[] splits = keys.Split(';');

                foreach (var item2 in splits)

                {

                    if (item2.Equals(""))

                    {

                        continue;

                    }

 

                    CookieModel model = new CookieModel();

                    string[] splits2 = item2.Split('=');

                    model.key = splits2[0].Trim();

                    model.value = splits2[1].Trim();

                    model.domain = item;

                    edevlets.Add(model);

                }

 

                keysler = keysler + keys;

                Console.WriteLine("KEYS- " + keys + "\n\n");

            }

 

            CookieContainer cookies = new CookieContainer();

            foreach (CookieModel model in edevlets)

            {

                Cookie cokSessions = new Cookie(model.key, model.value) { Domain = model.domain };

                cookies.Add(cokSessions);

            }

            HttpClientHandler handler = new HttpClientHandler();

            handler.CookieContainer = cookies;

 

            HttpClient client = new HttpClient(handler);

 

        }

 

 

 

 

 

 public string SessionsCek(string firma_webLink)

        {

            string deger2 = "";

            try

            {

                //string hostname = "hotelextranet.odeontours.com";

                IEnumerable<Tuple<string, string>> deger = opera_ReadCookies(firma_webLink);

                try

                {

                    foreach (var item in deger)

                    {

                        deger2 += item.Item1.ToString() + "=";

                        deger2 += item.Item2.ToString() + ";";

                    }

                }

                catch (Exception ex)

                {

                    Console.WriteLine(ex.Message);

                }

                return deger2;

            }

            catch (Exception ex)

            {

                MessageBox.Show("HATA " + ex.Message);

                return deger2;

            }

        }

 

        public string SessionsCek_2(string firma_webLink)

        {

            string deger2 = "";

            try

            {

                //string hostname = "hotelextranet.odeontours.com";

                IEnumerable<Tuple<string, string>> deger = opera_ReadCookies_2(firma_webLink);

                try

                {

                    foreach (var item in deger)

                    {

                        deger2 += item.Item1.ToString() + "=";

                        deger2 += item.Item2.ToString() + ";";

                    }

                }

                catch (Exception ex)

                {

                    Console.WriteLine(ex.Message);

                }

                return deger2;

            }

            catch (Exception ex)

            {

                MessageBox.Show("HATA " + ex.Message);

                return deger2;

            }

        }

 

        public IEnumerable<Tuple<string, string>> opera_ReadCookies(string hostName)

        {

            if (hostName == null) throw new ArgumentNullException("hostName");

 

            //    var dbPath = @"C:\Users\RAMBO\AppData\Roaming\Opera Software\Opera Stable\Cookies";

 

            var dbPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\Opera Software\Opera Stable\Cookies";

            //   var dbPath = "Cookies";

 

            if (!System.IO.File.Exists(dbPath)) throw new System.IO.FileNotFoundException("Cant find cookie store", dbPath); // race condition, but i'll risk it

 

            var connectionString = "Data Source=" + dbPath + ";pooling=false";

 

            using (var conn = new System.Data.SQLite.SQLiteConnection(connectionString))

            using (var cmd = conn.CreateCommand())

            {

                var prm = cmd.CreateParameter();

                prm.ParameterName = "hostName";

                prm.Value = hostName;

                cmd.Parameters.AddWithValue("@hostName", "%"+ hostName + "%");

 

                cmd.CommandText = "SELECT name,encrypted_value FROM cookies WHERE host_key like @hostName";

 

                conn.Open();

                using (var reader = cmd.ExecuteReader())

                {

                    while (reader.Read())

                    {

                        var encryptedData = (byte[])reader[1];

 

                        string encKey = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\Opera Software\Opera Stable\Local State";

                        string alltex = File.ReadAllText(encKey);

                        var ob = JsonConvert.DeserializeObject(alltex);

                        encKey = JObject.Parse(ob.ToString())["os_crypt"]["encrypted_key"].ToString();

 

                        var decodedKey = System.Security.Cryptography.ProtectedData.Unprotect(Convert.FromBase64String(encKey).Skip(5).ToArray(), null, System.Security.Cryptography.DataProtectionScope.LocalMachine);

 

                        var plainText = _decryptWithKey(encryptedData, decodedKey, 3);

                        yield return Tuple.Create(reader.GetString(0), plainText);

                    }

                }

                conn.Close();

            }

 

        }

        public IEnumerable<Tuple<string, string>> opera_ReadCookies_2(string hostName)

        {

            if (hostName == null) throw new ArgumentNullException("hostName");

 

            //    var dbPath = @"C:\Users\RAMBO\AppData\Roaming\Opera Software\Opera Stable\Cookies";

 

            var dbPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\Opera Software\Opera Stable\Cookies";

            //   var dbPath = "Cookies";

 

            if (!System.IO.File.Exists(dbPath)) throw new System.IO.FileNotFoundException("Cant find cookie store", dbPath); // race condition, but i'll risk it

 

            var connectionString = "Data Source=" + dbPath + ";pooling=false";

 

            using (var conn = new System.Data.SQLite.SQLiteConnection(connectionString))

            using (var cmd = conn.CreateCommand())

            {

                var prm = cmd.CreateParameter();

                prm.ParameterName = "hostName";

                prm.Value = hostName;

                cmd.Parameters.AddWithValue("@hostName", "%" + hostName + "%");

 

                cmd.CommandText = "SELECT name,encrypted_value FROM cookies WHERE host_key like @hostName";

 

                conn.Open();

                using (var reader = cmd.ExecuteReader())

                {

                    while (reader.Read())

                    {

 

                        var encryptedData = (byte[])reader[1];

                        var decodedData = System.Security.Cryptography.ProtectedData.Unprotect(encryptedData, null, System.Security.Cryptography.DataProtectionScope.CurrentUser);

                        var plainText = Encoding.ASCII.GetString(decodedData); // Looks like ASCII

 

                        yield return Tuple.Create(reader.GetString(0), plainText);

 

                    }

                }

                conn.Close();

            }

 

        }

        private string _decryptWithKey(byte[] message, byte[] key, int nonSecretPayloadLength)

        {

            const int KEY_BIT_SIZE = 256;

            const int MAC_BIT_SIZE = 128;

            const int NONCE_BIT_SIZE = 96;

 

            if (key == null || key.Length != KEY_BIT_SIZE / 8)

                throw new ArgumentException(String.Format("Key needs to be {0} bit!", KEY_BIT_SIZE), "key");

            if (message == null || message.Length == 0)

                throw new ArgumentException("Message required!", "message");

 

            using (var cipherStream = new MemoryStream(message))

            using (var cipherReader = new BinaryReader(cipherStream))

            {

                var nonSecretPayload = cipherReader.ReadBytes(nonSecretPayloadLength);

                var nonce = cipherReader.ReadBytes(NONCE_BIT_SIZE / 8);

                var cipher = new GcmBlockCipher(new AesEngine());

                var parameters = new AeadParameters(new KeyParameter(key), MAC_BIT_SIZE, nonce);

                cipher.Init(false, parameters);

                var cipherText = cipherReader.ReadBytes(message.Length);

                var plainText = new byte[cipher.GetOutputSize(cipherText.Length)];

                try

                {

                    var len = cipher.ProcessBytes(cipherText, 0, cipherText.Length, plainText, 0);

                    cipher.DoFinal(plainText, len);

                }

                catch (InvalidCipherTextException)

                {

                    return null;

                }

                return Encoding.Default.GetString(plainText);

            }

        }

 

 

DİĞER ÖRNEK KULLANIM

 

 

odeon session alma yeni1

 

KULLANIMI

 

  Uri myUri = new Uri(firma_webLink);

  string firma_webLink = myUri.Host;

  string keys = SessionsCek(firma_webLink);

 

METOTLAR

 

public string SessionsCek(string firma_webLink)

        {

            string deger2 = "";

            try

            {

                //string hostname = "hotelextranet.odeontours.com";

                IEnumerable<Tuple<string, string>> deger = opera_ReadCookies(firma_webLink);

                try

                {

                    foreach (var item in deger)

                    {

                        deger2 += item.Item1.ToString() + "=";

                        deger2 += item.Item2.ToString() + ";";

                    }

                }

                catch (Exception ex)

                {

                    Console.WriteLine(ex.Message);

                }

                return deger2;

            }

            catch (Exception ex)

            {

                RHMesaj.MyMessageError(MyClass, "odeonSessionsCek", "", ex);

                return deger2;

            }

        }

 

 

public IEnumerable<Tuple<string, string>> opera_ReadCookies(string hostName)

        {

            if (hostName == null) throw new ArgumentNullException("hostName");

 

            //    var dbPath = @"C:\Users\RAMBO\AppData\Roaming\Opera Software\Opera Stable\Cookies";

 

            var dbPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\Opera Software\Opera Stable\Cookies";

            //   var dbPath = "Cookies";

 

            if (!System.IO.File.Exists(dbPath)) throw new System.IO.FileNotFoundException("Cant find cookie store", dbPath); // race condition, but i'll risk it

 

            var connectionString = "Data Source=" + dbPath + ";pooling=false";

 

            using (var conn = new System.Data.SQLite.SQLiteConnection(connectionString))

            using (var cmd = conn.CreateCommand())

            {

                var prm = cmd.CreateParameter();

                prm.ParameterName = "hostName";

                prm.Value = hostName;

                cmd.Parameters.Add(prm);

 

                cmd.CommandText = "SELECT name,encrypted_value FROM cookies WHERE host_key = @hostName";

 

                conn.Open();

                using (var reader = cmd.ExecuteReader())

                {

                    while (reader.Read())

                    {

                        var encryptedData = (byte[])reader[1];

 

                        string encKey = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\Opera Software\Opera Stable\Local State";

                        string alltex = File.ReadAllText(encKey);

                        var ob = JsonConvert.DeserializeObject(alltex);

                        encKey = JObject.Parse(ob.ToString())["os_crypt"]["encrypted_key"].ToString();

 

                        var decodedKey = System.Security.Cryptography.ProtectedData.Unprotect(Convert.FromBase64String(encKey).Skip(5).ToArray(), null, System.Security.Cryptography.DataProtectionScope.LocalMachine);

 

                        var plainText = _decryptWithKey(encryptedData, decodedKey, 3);

                        yield return Tuple.Create(reader.GetString(0), plainText);

                    }

                }

                conn.Close();

            }

 

        }

 

 

private string _decryptWithKey(byte[] message, byte[] key, int nonSecretPayloadLength)

        {

            const int KEY_BIT_SIZE = 256;

            const int MAC_BIT_SIZE = 128;

            const int NONCE_BIT_SIZE = 96;

 

            if (key == null || key.Length != KEY_BIT_SIZE / 8)

                throw new ArgumentException(String.Format("Key needs to be {0} bit!", KEY_BIT_SIZE), "key");

            if (message == null || message.Length == 0)

                throw new ArgumentException("Message required!", "message");

 

            using (var cipherStream = new MemoryStream(message))

            using (var cipherReader = new BinaryReader(cipherStream))

            {

                var nonSecretPayload = cipherReader.ReadBytes(nonSecretPayloadLength);

                var nonce = cipherReader.ReadBytes(NONCE_BIT_SIZE / 8);

                var cipher = new GcmBlockCipher(new AesEngine());

                var parameters = new AeadParameters(new KeyParameter(key), MAC_BIT_SIZE, nonce);

                cipher.Init(false, parameters);

                var cipherText = cipherReader.ReadBytes(message.Length);

                var plainText = new byte[cipher.GetOutputSize(cipherText.Length)];

                try

                {

                    var len = cipher.ProcessBytes(cipherText, 0, cipherText.Length, plainText, 0);

                    cipher.DoFinal(plainText, len);

                }

                catch (InvalidCipherTextException)

                {

                    return null;

                }

                return Encoding.Default.GetString(plainText);

            }

        }

 

 

2-) açık olan chrome'nin cokie'lerini alma sessions'larını alma

 

odeon session alma yeni

 

using System;

using System.Collections.Generic;

using System.Text;

using System.Windows.Forms;

 

namespace WindowsFormsApp3

{

    public partial class Form1 : Form

    {

        public Form1()

        {

            InitializeComponent();

        }

        private void Form1_Load(object sender, EventArgs e)

        {

            /*  nugetten yükle vs en az 2017 olacak

             1.   System.Data.SQLite

             2.   System.Security.Cryptography.ProtectedData

             */

        }

        private void button1_Click(object sender, EventArgs e)

        {

            string hostname = @"hotelextranet.odeontours.com";

            IEnumerable<Tuple<string, string>>  deger = ReadCookies(hostname);

 

            foreach (var item in deger)

            {

                Console.WriteLine(item.Item1.ToString());

                Console.WriteLine(item.Item2.ToString());

            }

        }

 

        public IEnumerable<Tuple<string, string>> ReadCookies(string hostName)

        {

            if (hostName == null) throw new ArgumentNullException("hostName");

 

            var dbPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + @"\Google\Chrome\User Data\Default\Cookies";

            if (!System.IO.File.Exists(dbPath)) throw new System.IO.FileNotFoundException("Cant find cookie store", dbPath); // race condition, but i'll risk it

 

            var connectionString = "Data Source=" + dbPath + ";pooling=false";

 

            using (var conn = new System.Data.SQLite.SQLiteConnection(connectionString))

            using (var cmd = conn.CreateCommand())

            {

                var prm = cmd.CreateParameter();

                prm.ParameterName = "hostName";

                prm.Value = hostName;

                cmd.Parameters.Add(prm);

 

                cmd.CommandText = "SELECT name,encrypted_value FROM cookies WHERE host_key = @hostName";

 

                conn.Open();

                using (var reader = cmd.ExecuteReader())

                {

                    while (reader.Read())

                    {

                        var encryptedData = (byte[])reader[1];

                        var decodedData = System.Security.Cryptography.ProtectedData.Unprotect(encryptedData, null, System.Security.Cryptography.DataProtectionScope.CurrentUser);

                        var plainText = Encoding.ASCII.GetString(decodedData); // Looks like ASCII

 

                        yield return Tuple.Create(reader.GetString(0), plainText);

                    }

                }

                conn.Close();

            }        }    }}

 

 

2-) açık olan opera'dan cokie'lerini alma sessions'larını alma

 

nugetten şunları indir

 

1- System.Data.SQLite

2- System.Security.Cryptography.ProtectedData

 

using System;

using System.Collections.Generic;

using System.Text;

using System.Windows.Forms;

namespace WindowsFormsApp1

{

    public partial class Form1 : Form

    {

        public Form1()

        {

            InitializeComponent();

        }

        public IEnumerable<Tuple<string, string>> ReadCookies(string hostName)

        {

            if (hostName == null) throw new ArgumentNullException("hostName");

 

            //    var dbPath = @"C:\Users\RAMBO\AppData\Roaming\Opera Software\Opera Stable\Cookies";

 

            var dbPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\Opera Software\Opera Stable\Cookies";

 

            if (!System.IO.File.Exists(dbPath)) throw new System.IO.FileNotFoundException("Cant find cookie store", dbPath); // race condition, but i'll risk it

 

            var connectionString = "Data Source=" + dbPath + ";pooling=false";

 

            using (var conn = new System.Data.SQLite.SQLiteConnection(connectionString))

            using (var cmd = conn.CreateCommand())

            {

                var prm = cmd.CreateParameter();

                prm.ParameterName = "hostName";

                prm.Value = hostName;

                cmd.Parameters.Add(prm);

 

                cmd.CommandText = "SELECT name,encrypted_value FROM cookies WHERE host_key = @hostName";

 

                conn.Open();

                using (var reader = cmd.ExecuteReader())

                {

                    while (reader.Read())

                    {

                        var encryptedData = (byte[])reader[1];

                        var decodedData = System.Security.Cryptography.ProtectedData.Unprotect(encryptedData, null, System.Security.Cryptography.DataProtectionScope.CurrentUser);

                        var plainText = Encoding.ASCII.GetString(decodedData); // Looks like ASCII

 

                        yield return Tuple.Create(reader.GetString(0), plainText);

                    }

                }

                conn.Close();

            }

        }

        private void simpleButton1_Click(object sender, EventArgs e)

        {

            string hostname = "hotelextranet.odeontours.com";

            IEnumerable<Tuple<string, string>> deger = ReadCookies(hostname);

 

            foreach (var item in deger)

            {

                Console.WriteLine(item.Item1.ToString());

                Console.WriteLine(item.Item2.ToString());

            }

        }

    }}

 

 

// diğer bakmasanda olur

 

 //var encryptedData = (byte[])reader[1];

                        //var decodedData = System.Security.Cryptography.ProtectedData.Unprotect(encryptedData, null, System.Security.Cryptography.DataProtectionScope.CurrentUser);

                        //var plainText = Encoding.ASCII.GetString(decodedData); // Looks like ASCII

 

                        //yield return Tuple.Create(reader.GetString(0), plainText);

 

 

                        var encryptedData = (byte[])reader[1];

                        string encKey = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + @"\Google\Chrome\User Data\Local State";

                        string alltex = File.ReadAllText(dbPath);

                        //string alltex = File.ReadAllText(encKey);

                        var ob = JsonConvert.DeserializeObject(alltex);

                        

                        encKey = JObject.Parse(ob.ToString())["os_crypt"]["encrypted_key"].ToString();

                        var decodedKey = System.Security.Cryptography.ProtectedData.Unprotect(Convert.FromBase64String(encKey).Skip(5).ToArray(), null, System.Security.Cryptography.DataProtectionScope.LocalMachine);

                        var plainText = _decryptWithKey(encryptedData, decodedKey, 3);

 

                        yield return Tuple.Create(reader.GetString(0), plainText);

 2021 Mart 23 Salı
 544