ASP.NET View State Decoder
Project description
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:
<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.
Install
$ 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:
>>> 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:
>>> vs = ViewState(raw=b'\xff\x01....')
Alternatively, the library can be used via command line by directly executing the module:
$ 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:
$ 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.
>>> vs = ViewState(signed_view_state)
>>> vs.decode()
>>> vs.mac
'hmac_sha256'
>>> vs.signature
b'....'
Development
Development packages can be installed with pipenv. Unit tests and code formatting tasks can be run with the builtin scripts:
$ pipenv sync -d
$ pipenv run test
$ pipenv run format
For PyPI releases, follow the build, check and upload scripts.
$ pipenv run build
$ pipenv run check
$ pipenv run upload
Note that for uploading a new package version, a valid PyPI auth token should be defined in ~/.pypirc.
References
Since there is no publically available specification of how .NET viewstate is encoded, reverse engineering was based on prior work:
Any official documents would be gladly accepted to help improve the parsing logic.
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file viewstate-0.6.0.tar.gz
.
File metadata
- Download URL: viewstate-0.6.0.tar.gz
- Upload date:
- Size: 6.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.2 CPython/3.12.3 Linux/6.8.9-arch1-1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 82746f28cc51262f64d0b26e84bfbcaae2b93dfa416d6ae296f779e0957aad9b |
|
MD5 | 77fbd282d9b56e2aa31791a8b66f2277 |
|
BLAKE2b-256 | 4e8cf9cd70a8b5ced38e14e90d449c9bafaf751e362f3ec9c1d5517543fc6acb |
File details
Details for the file viewstate-0.6.0-py3-none-any.whl
.
File metadata
- Download URL: viewstate-0.6.0-py3-none-any.whl
- Upload date:
- Size: 7.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.2 CPython/3.12.3 Linux/6.8.9-arch1-1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 98eb05fd68c41b25d9f3555bca1197ac438168246468e35d6c6f2d1e5f8dcccc |
|
MD5 | bb10a36fd99f26757abaee328ef240cc |
|
BLAKE2b-256 | c54617f57840dd9b0fb09df736adbff94ba1dc43a9ce632c79daa67a03b0765b |