Transform: Convert data
Exploits need to manipulate data easily: encode it into base64, compute its hash, HTML-decode it, etc. That's what transform
is for.
Each category of transformation is available as a submodule of transform
.
When you do from ten import *
, transform
is imported as tf
, and the most used modules, such as json
or base64
, are included as root modules.
Each category of transformation is available as a submodule of transform
.
>>> from tenlib.transform import base64, html
>>> base64.decode('dGVzdA==')
b'test'
>>> html.decode('<div>test</div>')
'<div>test</div>'
Methods support both bytes
and str
as input, as well as lists and dicts. Refer to Multiform for more details.
Here are a few examples for the most common transformations.
JSON
python | output |
---|---|
|
|
|
|
Base 64 encoding (base64)
python | output |
---|---|
|
|
|
|
Query string (qs)
Parse query string and URL-encode/decode.
python | output |
---|---|
|
|
|
|
|
|
|
|
|
|
Table
Convert data formatted into a table (such as CSV) to a list (of list), and back. This example converts an array of colon separated lines into a table.
python | output |
---|---|
|
|
|
|
Hashing
python | output |
---|---|
|
|
|
|
Others
Lots of other transforms are available. Refer to the documentation for more details.
Multiform
As you may have seen, you can feed either bytes or strings to the conversion
functions, and they will handle the convertion into the proper type. This
behaviour also works with dict
s and list
s:
python | output |
---|---|
|
|
|
|
|
|
|
|
CLI: the tf
program
The tf
program makes transforms available from the CLI as well:
$ echo 'dGVzdA==' | tf base64.decode
test
The filters can be chained. Here, we convert JSON into an URL-encoded string:
$ echo '{"a":"b","c":"d"}' | tf json.decode qs.unparse
a=b&c=d
Check the --help
for further details.