Skip to main content
ASP.NET View State Decoder
======================

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

Viewstate is a method used in the ASP.NET framework to persist changes to a web form across postbacks. It is usually saved on a hidden form field:

.. code-block:: html

<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEP...">

Decoding the view state can be useful in penetration testing on ASP.NET applications, as well as revealing more information that can be used to efficiently scrape web pages.

.. image:: https://travis-ci.org/yuvadm/viewstate.svg?branch=master
:target: https://travis-ci.org/yuvadm/viewstate

Install
-------

.. code-block:: shell

$ pip install viewstate

Usage
-----

The Viewstate decoder accepts Base64 encoded .NET viewstate data and returns the decoded output in the form of plain Python objects.

There are two main ways to use this package. First, it can be used as an imported library with the following typical use case:

.. code-block:: python

>>> from viewstate import ViewState
>>> base64_encoded_viewstate = '/wEPBQVhYmNkZQ9nAgE='
>>> vs = ViewState(base64_encoded_viewstate)
>>> vs.decode()
('abcde', (True, 1))

It is also possible to feed the raw bytes directly:

.. code-block:: python

>>> vs = ViewState(raw=b'\xff\x01....')

Alternatively, the library can be used via command line by directly executing the module:

.. code-block:: shell

$ cat data.base64 | python -m viewstate

Which will pretty-print the decoded data structure.

The command line usage can also accept raw bytes with the ``-r`` flag:

.. code-block:: shell

$ cat data.base64 | base64 -d | python -m viewstate -r

Viewstate HMAC signatures are also supported. In case there are any remaining bytes after parsing, they are assumed to be HMAC signatures, with the types estimated according to signature length.

.. code-block:: python

>>> vs = ViewState(signed_view_state)
>>> vs.decode()
>>> vs.mac
'hmac_sha256'
>>> vs.signature
b'....'

Development
-----------

.. code-block:: shell

$ pytest

References
----------

Since there is no publically available specification of how .NET viewstate is encoded, reverse engineering was based on prior work:

- https://github.com/mutantzombie/JavaScript-ViewState-Parser
- http://viewstatedecoder.azurewebsites.net/

Any official documents would be gladly accepted to help improve the parsing logic.

License
-------
MIT


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

viewstate-0.4.1.tar.gz (5.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

viewstate-0.4.1-py2.py3-none-any.whl (8.2 kB view details)

Uploaded Python 2Python 3

File details

Details for the file viewstate-0.4.1.tar.gz.

File metadata

  • Download URL: viewstate-0.4.1.tar.gz
  • Upload date:
  • Size: 5.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for viewstate-0.4.1.tar.gz
Algorithm Hash digest
SHA256 7a34e4b9a64fd05d8af61fbec5b36575e790e75b27da716bdb35c105dc9788ef
MD5 7dbf7a2efa1696e8332aa979cddbdf5c
BLAKE2b-256 e701445b8626409505ef9ef4897cb727f3b89c11853440dd5ac3376c70eedab4

See more details on using hashes here.

File details

Details for the file viewstate-0.4.1-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for viewstate-0.4.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 21d1a81f74be071bda40f6f5955603f98bb152c96cff41d0c99ed35f2964538f
MD5 116f6863fce3d3aaee6fa9f154723096
BLAKE2b-256 4343119921497a9509fd6355beed2baed95c376be2f198f88e4e874bf35f0244

See more details on using hashes here.

Release history Release notifications | RSS feed

0.7.0

2 files

0.6.0

2 files

0.5.3

1 file

0.5.2

1 file

0.5.1

1 file

0.4.3

2 files

0.4.2

2 files

This release

0.4.1 This release

2 files

0.4.0

2 files

0.3.1

2 files

0.3.0

2 files

0.2.1

1 file

0.2.0

1 file

0.1.2

1 file

0.1.1

1 file

0.1.0

1 file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page