ALERT!
Click here to register with a few steps and explore all our cool stuff we have to offer!

Jump to content



Photo

How to parse a cookie?


  • Please log in to reply
How to parse a cookie?

#1

Prophesied
Prophesied
    Offline
    126
    Rep
    472
    Likes

    $uicide boy$

Posts: 1182
Threads: 170
Joined: Jan 27, 2016
Credits: 5

Eight years registered
#1

I get those cookies and I want to parse only the _xsrf cookie. How do I do that?

 

Thanks for the answer <3

	G_ENABLED_IDPS=google
	cto_lwid=8a611433-fd26-4930-9a5d-d4287cf0d2d9
	notice_preferences=2:
	notice_gdpr_prefs=0,1,2:
	__stripe_mid=c4469ee0-02ec-496b-a40d-73531016c3a1
	__stripe_sid=6fad41df-b2df-42bd-8e1d-0102b6db1f7f
	_xsrf=2|052be4b4|bf48338576f4ad3f0ca5bd16e7293b49|1547583634
	bsid=d4fecffc928e4bbe8e3f03ec6ee06646
	_timezone=1
	SLG_GWPT_Show_Hide_tmp=1
	SLG_wptGlobTipTmp=1

  • 0

:timmy: Contact ExPLiCiT#6288 for Dell Tags/Invoices.  :timmy:


#2

discord
discord
    Offline
    515
    Rep
    627
    Likes

    Veteran

Posts: 446
Threads: 123
Joined: Dec 10, 2017
Credits: 0

Six years registered
#2

This is all in one string?


 

I get those cookies and I want to parse only the _xsrf cookie. How do I do that?

 

Thanks for the answer <3

	G_ENABLED_IDPS=google
	cto_lwid=8a611433-fd26-4930-9a5d-d4287cf0d2d9
	notice_preferences=2:
	notice_gdpr_prefs=0,1,2:
	__stripe_mid=c4469ee0-02ec-496b-a40d-73531016c3a1
	__stripe_sid=6fad41df-b2df-42bd-8e1d-0102b6db1f7f
	_xsrf=2|052be4b4|bf48338576f4ad3f0ca5bd16e7293b49|1547583634
	bsid=d4fecffc928e4bbe8e3f03ec6ee06646
	_timezone=1
	SLG_GWPT_Show_Hide_tmp=1
	SLG_wptGlobTipTmp=1

  • 2

#3

Prophesied
Prophesied
    Offline
    126
    Rep
    472
    Likes

    $uicide boy$

Posts: 1182
Threads: 170
Joined: Jan 27, 2016
Credits: 5

Eight years registered
#3

This is all in one string?

 

Yup it is. Maybe like that is better:

Cookie: G_ENABLED_IDPS=google; cto_lwid=8a611433-fd26-4930-9a5d-d4287cf0d2d9; notice_preferences=2:; notice_gdpr_prefs=0,1,2:; __stripe_mid=c4469ee0-02ec-496b-a40d-73531016c3a1; __stripe_sid=6fad41df-b2df-42bd-8e1d-0102b6db1f7f; _xsrf=2|052be4b4|bf48338576f4ad3f0ca5bd16e7293b49|1547583634; bsid=d4fecffc928e4bbe8e3f03ec6ee06646; _timezone=1; SLG_GWPT_Show_Hide_tmp=1; SLG_wptGlobTipTmp=1

  • 0

:timmy: Contact ExPLiCiT#6288 for Dell Tags/Invoices.  :timmy:


#4

discord
discord
    Offline
    515
    Rep
    627
    Likes

    Veteran

Posts: 446
Threads: 123
Joined: Dec 10, 2017
Credits: 0

Six years registered
#4

 

Yup it is. Maybe like that is better:

Cookie: G_ENABLED_IDPS=google; cto_lwid=8a611433-fd26-4930-9a5d-d4287cf0d2d9; notice_preferences=2:; notice_gdpr_prefs=0,1,2:; __stripe_mid=c4469ee0-02ec-496b-a40d-73531016c3a1; __stripe_sid=6fad41df-b2df-42bd-8e1d-0102b6db1f7f; _xsrf=2|052be4b4|bf48338576f4ad3f0ca5bd16e7293b49|1547583634; bsid=d4fecffc928e4bbe8e3f03ec6ee06646; _timezone=1; SLG_GWPT_Show_Hide_tmp=1; SLG_wptGlobTipTmp=1

 

The you can do smth like that :

string cookies = "Cookie: G_ENABLED_IDPS=google; cto_lwid=8a611433-fd26-4930-9a5d-d4287cf0d2d9; notice_preferences=2:; notice_gdpr_prefs=0,1,2:; __stripe_mid=c4469ee0-02ec-496b-a40d-73531016c3a1; __stripe_sid=6fad41df-b2df-42bd-8e1d-0102b6db1f7f; _xsrf=2|052be4b4|bf48338576f4ad3f0ca5bd16e7293b49|1547583634; bsid=d4fecffc928e4bbe8e3f03ec6ee06646; _timezone=1; SLG_GWPT_Show_Hide_tmp=1; SLG_wptGlobTipTmp=1";
string xsrf = new Regex("_xsrf=([^;]+)").Match(cookies).Groups[1].Value;

Console.WriteLine(xsrf);

// Output: 2|052be4b4|bf48338576f4ad3f0ca5bd16e7293b49|1547583634

  • 0

#5

Prophesied
Prophesied
    Offline
    126
    Rep
    472
    Likes

    $uicide boy$

Posts: 1182
Threads: 170
Joined: Jan 27, 2016
Credits: 5

Eight years registered
#5

 

The you can do smth like that :

string cookies = "Cookie: G_ENABLED_IDPS=google; cto_lwid=8a611433-fd26-4930-9a5d-d4287cf0d2d9; notice_preferences=2:; notice_gdpr_prefs=0,1,2:; __stripe_mid=c4469ee0-02ec-496b-a40d-73531016c3a1; __stripe_sid=6fad41df-b2df-42bd-8e1d-0102b6db1f7f; _xsrf=2|052be4b4|bf48338576f4ad3f0ca5bd16e7293b49|1547583634; bsid=d4fecffc928e4bbe8e3f03ec6ee06646; _timezone=1; SLG_GWPT_Show_Hide_tmp=1; SLG_wptGlobTipTmp=1";
string xsrf = new Regex("_xsrf=([^;]+)").Match(cookies).Groups[1].Value;

Console.WriteLine(xsrf);

// Output: 2|052be4b4|bf48338576f4ad3f0ca5bd16e7293b49|1547583634

 

It worked thanks alot <3


  • 0

:timmy: Contact ExPLiCiT#6288 for Dell Tags/Invoices.  :timmy:


#6

AutoAccounts
AutoAccounts
    Offline
    13
    Rep
    23
    Likes

    Trusted seller ✅

  • PipPipPipPipPipPip
Posts: 283
Threads: 22
Joined: Feb 11, 2016
Credits: 0

Eight years registered
#6

Based on what you've given me this is what I would do.

If that is one string, I would split the cookie lines by "\r\n"

 

Escaped result for your string:
 

"G_ENABLED_IDPS=google\r\n\tcto_lwid=8a611433-fd26-4930-9a5d-d4287cf0d2d9\r\n\tnotice_preferences=2:\r\n\tnotice_gdpr_prefs=0,1,2:\r\n\t__stripe_mid=c4469ee0-02ec-496b-a40d-73531016c3a1\r\n\t__stripe_sid=6fad41df-b2df-42bd-8e1d-0102b6db1f7f\r\n\t_xsrf=2|052be4b4|bf48338576f4ad3f0ca5bd16e7293b49|1547583634\r\n\tbsid=d4fecffc928e4bbe8e3f03ec6ee06646\r\n\t_timezone=1\r\n\tSLG_GWPT_Show_Hide_tmp=1\r\n\tSLG_wptGlobTipTmp=1"

I would rather deal with lists instead of arrays so I just do .ToList();

 

c89948596a3c9d2eec61d9cd4556fd35.png

 

This is one way to do it, I'm sure it could be simplified using LINQ.

        public static List<Cookie> ParseStringToCookie(string cookieString)
        {
            var cookies = new List<Cookie>();

            // FYI: \r = return | \n = new line | \t = tab
            var cookieStringList = cookieString.Split("\r\n\t").ToList(); //Split \r\n\t because I copied from thread, yours might be different

            foreach (var c in cookieStringList)
            {
                var cookieNameValues = c.Split('=');
                cookies.Add(new Cookie(cookieNameValues[0], cookieNameValues[1]));
            }

            return cookies;
        }

Then if you need it in a CookieContainer just add each cookie to it. If you just need the value do, var cookie = cookies.FirstOrDefault(m=>m.Name == "cookieNameYouWant");


  • 0

#7

Prophesied
Prophesied
    Offline
    126
    Rep
    472
    Likes

    $uicide boy$

Posts: 1182
Threads: 170
Joined: Jan 27, 2016
Credits: 5

Eight years registered
#7

Based on what you've given me this is what I would do.

If that is one string, I would split the cookie lines by "\r\n"

 

Escaped result for your string:
 

"G_ENABLED_IDPS=google\r\n\tcto_lwid=8a611433-fd26-4930-9a5d-d4287cf0d2d9\r\n\tnotice_preferences=2:\r\n\tnotice_gdpr_prefs=0,1,2:\r\n\t__stripe_mid=c4469ee0-02ec-496b-a40d-73531016c3a1\r\n\t__stripe_sid=6fad41df-b2df-42bd-8e1d-0102b6db1f7f\r\n\t_xsrf=2|052be4b4|bf48338576f4ad3f0ca5bd16e7293b49|1547583634\r\n\tbsid=d4fecffc928e4bbe8e3f03ec6ee06646\r\n\t_timezone=1\r\n\tSLG_GWPT_Show_Hide_tmp=1\r\n\tSLG_wptGlobTipTmp=1"

I would rather deal with lists instead of arrays so I just do .ToList();

 

c89948596a3c9d2eec61d9cd4556fd35.png

 

This is one way to do it, I'm sure it could be simplified using LINQ.

        public static List<Cookie> ParseStringToCookie(string cookieString)
        {
            var cookies = new List<Cookie>();

            // FYI: \r = return | \n = new line | \t = tab
            var cookieStringList = cookieString.Split("\r\n\t").ToList(); //Split \r\n\t because I copied from thread, yours might be different

            foreach (var c in cookieStringList)
            {
                var cookieNameValues = c.Split('=');
                cookies.Add(new Cookie(cookieNameValues[0], cookieNameValues[1]));
            }

            return cookies;
        }

Then if you need it in a CookieContainer just add each cookie to it. If you just need the value do, var cookie = cookies.FirstOrDefault(m=>m.Name == "cookieNameYouWant");

 

I'm doing an HTTP request and parsing the xsrf token to use it after for the POST request


  • 0

:timmy: Contact ExPLiCiT#6288 for Dell Tags/Invoices.  :timmy:



 Users browsing this thread: