问题描述:

In the world of penetration testing with Python, it looks like

one has to generally hook into an API that's OS specific. This makes sense

to me because we're dealing with different architectures and kernels between

OSX, Linux, Windows. But I'm wondering if this isn't the case?

Beyond some of the limited functionality you get out of the OS module, my assumption is that hooking into the OS's API is general going to be specific to *POSIX flavor (maybe they have more in common) than in Windows for example.

In particular I'm thinking of Deviare on Windows. It deals with .DLL files. That's pretty much Windows.

The moment we hear DLL, the mind goes to windows land, .plist OS X and so on.

网友答案:

Hooking is a way to get your own code to execute when another system is running, whether that other system is an OS, a GUI, or whatever. A somewhat silly example in Python:

def Process(records, per_record_hook=None):
    "adds all records to XYZ system"
    for record in records:
        if per_record_hook:
            per_record_hook(record)
        XYZ.append(record)

def print_record(record):
    "print a '.' for each record (primitive counter)"
    print '.'

and then later:

Process(records_from_somewhere, per_record_hook=print_record)
网友答案:

http://en.wikipedia.org/wiki/Hooking

I'm going to assume you're referring to this ^ kind of hooking? I'm completely unfamiliar with the term, but it seems like you're looking for a library that allows interactions with the operating system?

If so, try something like PyWin32 (google it) or follow some of the techniques found here: http://www.rohitab.com/discuss/topic/37018-api-hooking-in-python/

Again, it'd be more helpful if you could put it (the phrase hooking) into more...Python-esque terms, but I hope this helps?

网友答案:

In Python things like this is generally so trivial that it's hard to even provide examples. Hooks are generally callbacks, yes. Callbacks in python are simply done by passing functions around and calling them.

相关阅读:
Top