How to decode viewstate

前端 未结 11 1224
终归单人心
终归单人心 2020-11-28 04:45

I need to see the contents of the viewstate of an asp.net page. I looked for a viewstate decoder, found Fridz Onion\'s ViewState Decoder but it asks for the url of a page to

相关标签:
11条回答
  • 2020-11-28 05:19

    Here is the source code for a ViewState visualizer from Scott Mitchell's article on ViewState (25 pages)

    using System;
    using System.Collections;
    using System.Text;
    using System.IO;
    using System.Web.UI;
    
    
    namespace ViewStateArticle.ExtendedPageClasses
    {
        /// <summary>
        /// Parses the view state, constructing a viaully-accessible object graph.
        /// </summary>
        public class ViewStateParser
        {
            // private member variables
            private TextWriter tw;
            private string indentString = "   ";
    
            #region Constructor
            /// <summary>
            /// Creates a new ViewStateParser instance, specifying the TextWriter to emit the output to.
            /// </summary>
            public ViewStateParser(TextWriter writer)
            {
                tw = writer;
            }
            #endregion
    
            #region Methods
            #region ParseViewStateGraph Methods
            /// <summary>
            /// Emits a readable version of the view state to the TextWriter passed into the object's constructor.
            /// </summary>
            /// <param name="viewState">The view state object to start parsing at.</param>
            public virtual void ParseViewStateGraph(object viewState)
            {
                ParseViewStateGraph(viewState, 0, string.Empty);    
            }
    
            /// <summary>
            /// Emits a readable version of the view state to the TextWriter passed into the object's constructor.
            /// </summary>
            /// <param name="viewStateAsString">A base-64 encoded representation of the view state to parse.</param>
            public virtual void ParseViewStateGraph(string viewStateAsString)
            {
                // First, deserialize the string into a Triplet
                LosFormatter los = new LosFormatter();
                object viewState = los.Deserialize(viewStateAsString);
    
                ParseViewStateGraph(viewState, 0, string.Empty);    
            }
    
            /// <summary>
            /// Recursively parses the view state.
            /// </summary>
            /// <param name="node">The current view state node.</param>
            /// <param name="depth">The "depth" of the view state tree.</param>
            /// <param name="label">A label to display in the emitted output next to the current node.</param>
            protected virtual void ParseViewStateGraph(object node, int depth, string label)
            {
                tw.Write(System.Environment.NewLine);
    
                if (node == null)
                {
                    tw.Write(String.Concat(Indent(depth), label, "NODE IS NULL"));
                } 
                else if (node is Triplet)
                {
                    tw.Write(String.Concat(Indent(depth), label, "TRIPLET"));
                    ParseViewStateGraph(((Triplet) node).First, depth+1, "First: ");
                    ParseViewStateGraph(((Triplet) node).Second, depth+1, "Second: ");
                    ParseViewStateGraph(((Triplet) node).Third, depth+1, "Third: ");
                }
                else if (node is Pair)
                {
                    tw.Write(String.Concat(Indent(depth), label, "PAIR"));
                    ParseViewStateGraph(((Pair) node).First, depth+1, "First: ");
                    ParseViewStateGraph(((Pair) node).Second, depth+1, "Second: ");
                }
                else if (node is ArrayList)
                {
                    tw.Write(String.Concat(Indent(depth), label, "ARRAYLIST"));
    
                    // display array values
                    for (int i = 0; i < ((ArrayList) node).Count; i++)
                        ParseViewStateGraph(((ArrayList) node)[i], depth+1, String.Format("({0}) ", i));
                }
                else if (node.GetType().IsArray)
                {
                    tw.Write(String.Concat(Indent(depth), label, "ARRAY "));
                    tw.Write(String.Concat("(", node.GetType().ToString(), ")"));
                    IEnumerator e = ((Array) node).GetEnumerator();
                    int count = 0;
                    while (e.MoveNext())
                        ParseViewStateGraph(e.Current, depth+1, String.Format("({0}) ", count++));
                }
                else if (node.GetType().IsPrimitive || node is string)
                {
                    tw.Write(String.Concat(Indent(depth), label));
                    tw.Write(node.ToString() + " (" + node.GetType().ToString() + ")");
                }
                else
                {
                    tw.Write(String.Concat(Indent(depth), label, "OTHER - "));
                    tw.Write(node.GetType().ToString());
                }
            }
            #endregion
    
            /// <summary>
            /// Returns a string containing the <see cref="IndentString"/> property value a specified number of times.
            /// </summary>
            /// <param name="depth">The number of times to repeat the <see cref="IndentString"/> property.</param>
            /// <returns>A string containing the <see cref="IndentString"/> property value a specified number of times.</returns>
            protected virtual string Indent(int depth)
            {
                StringBuilder sb = new StringBuilder(IndentString.Length * depth);
                for (int i = 0; i < depth; i++)
                    sb.Append(IndentString);
    
                return sb.ToString();
            }
            #endregion
    
            #region Properties
            /// <summary>
            /// Specifies the indentation to use for each level when displaying the object graph.
            /// </summary>
            /// <value>A string value; the default is three blank spaces.</value>
            public string IndentString
            {
                get
                {
                    return indentString;
                }
                set
                {
                    indentString = value;
                }
            }
            #endregion
        }
    }
    

    And here's a simple page to read the viewstate from a textbox and graph it using the above code

    private void btnParse_Click(object sender, System.EventArgs e)
            {
                // parse the viewState
                StringWriter writer = new StringWriter();
                ViewStateParser p = new ViewStateParser(writer);
    
                p.ParseViewStateGraph(txtViewState.Text);
                ltlViewState.Text = writer.ToString();
            }
    
    0 讨论(0)
  • 2020-11-28 05:24

    JavaScript-ViewState-Parser:

    • http://mutantzombie.github.com/JavaScript-ViewState-Parser/
    • https://github.com/mutantzombie/JavaScript-ViewState-Parser/

    The parser should work with most non-encrypted ViewStates. It doesn’t handle the serialization format used by .NET version 1 because that version is sorely outdated and therefore too unlikely to be encountered in any real situation.

    http://deadliestwebattacks.com/2011/05/29/javascript-viewstate-parser/


    Parsing .NET ViewState

    • A Spirited Peek into ViewState, Part I:

      http://deadliestwebattacks.com/2011/05/13/a-spirited-peek-into-viewstate-part-i/

    • A Spirited Peek into ViewState, Part II:

      http://deadliestwebattacks.com/2011/05/25/a-spirited-peek-into-viewstate-part-ii/


    0 讨论(0)
  • 2020-11-28 05:24

    Online Viewstate Viewer made by Lachlan Keown:

    http://lachlankeown.blogspot.com/2008/05/online-viewstate-viewer-decoder.html

    0 讨论(0)
  • 2020-11-28 05:25

    Here's another decoder that works well as of 2014: http://viewstatedecoder.azurewebsites.net/

    This worked on an input on which the Ignatu decoder failed with "The serialized data is invalid" (although it leaves the BinaryFormatter-serialized data undecoded, showing only its length).

    0 讨论(0)
  • 2020-11-28 05:29

    You can ignore the URL field and simply paste the viewstate into the Viewstate string box.

    It does look like you have an old version; the serialisation methods changed in ASP.NET 2.0, so grab the 2.0 version

    0 讨论(0)
  • 2020-11-28 05:30

    Best way in python is use this link.

    A small Python 3.5+ library for decoding ASP.NET viewstate.

    First install that: pip install viewstate

    >>> from viewstate import ViewState
    >>> base64_encoded_viewstate = '/wEPBQVhYmNkZQ9nAgE='
    >>> vs = ViewState(base64_encoded_viewstate)
    >>> vs.decode()
    ('abcde', (True, 1))
    
    0 讨论(0)
提交回复
热议问题