Explore Enterprise Education Gitee Premium Gitee AI AI teammates
Fetch the repository succeeded.
Donate
Please sign in before you donate.
Scan WeChat QR to Pay
Cancel
Complete
Prompt
Switch to Alipay.
OK
Cancel
1 Star 0 Fork 3

github-mysync/qiling

forked from qiling/qiling
Create your Gitee Account
Explore and code with more than 14 million developers,Free private repositories !:)
Sign up
Already have an account? Sign in
文件
dev
Branches (17)
Tags (10)
dev
master
ida_plugin_enhance
fix_pipe
uc2afl
old_dev
fix-windows-ci
mcu
dev_before_mcu
dev_old
revert-734-fix-new-thread-id
refactor
revert-639-dev
revert-612-dev
dev_official
revert-544-x64_partial_regs
demigod
1.4.1
1.4.0
1.3.0
1.2.4.1
1.2.4
1.2.3
1.2.2
1.2.1
1.2
1.1.3
dev
Branches (17)
Tags (10)
dev
master
ida_plugin_enhance
fix_pipe
uc2afl
old_dev
fix-windows-ci
mcu
dev_before_mcu
dev_old
revert-734-fix-new-thread-id
refactor
revert-639-dev
revert-612-dev
dev_official
revert-544-x64_partial_regs
demigod
1.4.1
1.4.0
1.3.0
1.2.4.1
1.2.4
1.2.3
1.2.2
1.2.1
1.2
1.1.3
Clone or Download
Clone/Download
Prompt
To download the code, please copy the following command and execute it in the terminal
To ensure that your submitted code identity is correctly recognized by Gitee, please execute the following command.
When using the SSH protocol for the first time to clone or push code, follow the prompts below to complete the SSH configuration.
1 Generate RSA keys.
2 Obtain the content of the RSA public key and configure it in SSH Public Keys
To use SVN on Gitee, please visit the usage guide
When using the HTTPS protocol, the command line will prompt for account and password verification as follows. For security reasons, Gitee recommends configure and use personal access tokens instead of login passwords for cloning, pushing, and other operations.
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # Private Token
dev
Branches (17)
Tags (10)
dev
master
ida_plugin_enhance
fix_pipe
uc2afl
old_dev
fix-windows-ci
mcu
dev_before_mcu
dev_old
revert-734-fix-new-thread-id
refactor
revert-639-dev
revert-612-dev
dev_official
revert-544-x64_partial_regs
demigod
1.4.1
1.4.0
1.3.0
1.2.4.1
1.2.4
1.2.3
1.2.2
1.2.1
1.2
1.1.3
qiling
/
examples
/
sality.py
qiling
/
examples
/
sality.py
sality.py 7.06 KB
Copy Edit Raw Blame History
elicn authored 2021年08月22日 19:07 +08:00 . Move io_Write to Windos utils, where it belongs
#!/usr/bin/env python3
#
# Cross Platform and Multi Architecture Advanced Binary Emulation Framework
#
from unicorn import UcError
import sys
sys.path.append("..")
from qiling import Qiling
from qiling.const import QL_VERBOSE
from qiling.os.const import POINTER, DWORD, STRING, HANDLE
from qiling.os.windows import utils
from qiling.os.windows.api import *
from qiling.os.windows.fncc import *
from qiling.os.windows.dlls.kernel32.fileapi import _CreateFile
def init_unseen_symbols(ql: Qiling, address: int, name: str, ordinal: int, dll_name: str):
ql.loader.import_symbols[address] = {
"name": name,
"ordinal": ordinal,
"dll": dll_name.partition('.')[0]
}
ql.loader.import_address_table[dll_name][name] = address
if ordinal != 0:
ql.loader.import_address_table[dll_name][ordinal] = address
# HANDLE CreateThread(
# LPSECURITY_ATTRIBUTES lpThreadAttributes,
# SIZE_T dwStackSize,
# LPTHREAD_START_ROUTINE lpStartAddress,
# __drv_aliasesMem LPVOID lpParameter,
# DWORD dwCreationFlags,
# LPDWORD lpThreadId
# );
@winsdkapi(cc=STDCALL, params={
'lpThreadAttributes' : LPSECURITY_ATTRIBUTES,
'dwStackSize' : SIZE_T,
'lpStartAddress' : LPTHREAD_START_ROUTINE,
'lpParameter' : LPVOID,
'dwCreationFlags' : DWORD,
'lpThreadId' : LPDWORD
})
def hook_CreateThread(ql: Qiling, address: int, params):
# set thread handle
return 1
# HANDLE CreateFileA(
# LPCSTR lpFileName,
# DWORD dwDesiredAccess,
# DWORD dwShareMode,
# LPSECURITY_ATTRIBUTES lpSecurityAttributes,
# DWORD dwCreationDisposition,
# DWORD dwFlagsAndAttributes,
# HANDLE hTemplateFile
# );
@winsdkapi(cc=STDCALL, params={
'lpFileName' : LPCSTR,
'dwDesiredAccess' : DWORD,
'dwShareMode' : DWORD,
'lpSecurityAttributes' : LPSECURITY_ATTRIBUTES,
'dwCreationDisposition' : DWORD,
'dwFlagsAndAttributes' : DWORD,
'hTemplateFile' : HANDLE
})
def hook_CreateFileA(ql: Qiling, address: int, params):
lpFileName = params["lpFileName"]
if lpFileName.startswith("\\\\.\\"):
if ql.amsint32_driver:
return 0x13371337
else:
return (-1)
else:
ret = _CreateFile(ql, address, params, "CreateFileA")
return ret
def _WriteFile(ql: Qiling, address: int, params):
ret = 1
hFile = params["hFile"]
lpBuffer = params["lpBuffer"]
nNumberOfBytesToWrite = params["nNumberOfBytesToWrite"]
lpNumberOfBytesWritten = params["lpNumberOfBytesWritten"]
#lpOverlapped = params["lpOverlapped"]
if hFile == 0xfffffff5:
s = ql.mem.read(lpBuffer, nNumberOfBytesToWrite)
ql.os.stdout.write(s)
ql.os.utils.string_appearance(s.decode())
ql.mem.write(lpNumberOfBytesWritten, ql.pack(nNumberOfBytesToWrite))
else:
f = ql.os.handle_manager.get(hFile)
if f is None:
# Invalid handle
ql.os.last_error = 0xffffffff
return 0
else:
f = f.obj
buffer = ql.mem.read(lpBuffer, nNumberOfBytesToWrite)
f.write(bytes(buffer))
ql.mem.write(lpNumberOfBytesWritten, ql.pack32(nNumberOfBytesToWrite))
return ret
@winsdkapi(cc=STDCALL, params={
'hFile' : HANDLE,
'lpBuffer' : LPCVOID,
'nNumberOfBytesToWrite' : DWORD,
'lpNumberOfBytesWritten' : LPDWORD,
'lpOverlapped' : LPOVERLAPPED
})
def hook_WriteFile(ql: Qiling, address: int, params):
hFile = params["hFile"]
lpBuffer = params["lpBuffer"]
nNumberOfBytesToWrite = params["nNumberOfBytesToWrite"]
lpNumberOfBytesWritten = params["lpNumberOfBytesWritten"]
if hFile == 0x13371337:
buffer = ql.mem.read(lpBuffer, nNumberOfBytesToWrite)
try:
r, nNumberOfBytesToWrite = utils.io_Write(ql.amsint32_driver, buffer)
ql.mem.write(lpNumberOfBytesWritten, ql.pack32(nNumberOfBytesToWrite))
except Exception as e:
ql.log.exception("")
print("Exception = %s" % str(e))
r = 1
if r:
return 1
else:
return 0
else:
return _WriteFile(ql, address, params)
# BOOL StartServiceA(
# SC_HANDLE hService,
# DWORD dwNumServiceArgs,
# LPCSTR *lpServiceArgVectors
# );
@winsdkapi(cc=STDCALL, params={
'hService' : SC_HANDLE,
'dwNumServiceArgs' : DWORD,
'lpServiceArgVectors' : POINTER
})
def hook_StartServiceA(ql: Qiling, address: int, params):
try:
hService = params["hService"]
service_handle = ql.os.handle_manager.get(hService)
if service_handle.name == "amsint32":
if service_handle.name in ql.os.services:
service_path = ql.os.services[service_handle.name]
service_path = ql.os.path.transform_to_real_path(service_path)
ql.amsint32_driver = Qiling([service_path], ql.rootfs, verbose=QL_VERBOSE.DEBUG)
init_unseen_symbols(ql.amsint32_driver, ql.amsint32_driver.loader.dlls["ntoskrnl.exe"]+0xb7695, b"NtTerminateProcess", 0, "ntoskrnl.exe")
#ql.amsint32_driver.debugger= ":9999"
try:
ql.amsint32_driver.load()
return 1
except UcError as e:
print("Load driver error: ", e)
return 0
else:
return 0
else:
return 1
except Exception as e:
ql.log.exception("")
print (e)
def hook_stop_address(ql):
print(" >>>> Stop address: 0x%08x" % ql.reg.arch_pc)
ql.emu_stop()
if __name__ == "__main__":
ql = Qiling(["../examples/rootfs/x86_windows/bin/sality.dll"], "../examples/rootfs/x86_windows", verbose=QL_VERBOSE.DEBUG, libcache=True)
# for this module
ql.amsint32_driver = None
# emulate some Windows API
ql.set_api("CreateThread", hook_CreateThread)
ql.set_api("CreateFileA", hook_CreateFileA)
ql.set_api("WriteFile", hook_WriteFile)
ql.set_api("StartServiceA", hook_StartServiceA)
#init sality
ql.hook_address(hook_stop_address, 0x40EFFB)
ql.run()
# run driver thread
# execution is about to resume from 0x4053B2, which essentially jumps to ExitThread (kernel32.dll).
# Set ExitThread exit code to 0
ql.os.fcall = ql.os.fcall_select(STDCALL)
ql.os.fcall.writeParams(((DWORD, 0),))
ql.hook_address(hook_stop_address, 0x4055FA)
ql.run(0x4053B2)
ql.log.info("test kill thread")
if ql.amsint32_driver:
utils.io_Write(ql.amsint32_driver, ql.pack32(0xdeadbeef))
# TODO: Should stop at 0x10423, but for now just stop at 0x0001066a
ql.amsint32_driver.hook_address(hook_stop_address, 0x0001066a)
# TODO: not sure whether this one is really STDCALL
ql.amsint32_driver.os.fcall = ql.amsint32_driver.os.fcall_select(STDCALL)
ql.amsint32_driver.os.fcall.writeParams(((DWORD, 0),))
ql.amsint32_driver.run(begin=0x102D0)
Loading...
Report
Report success
We will send you the feedback within 2 working days through the letter!
Please fill in the reason for the report carefully. Provide as detailed a description as possible.
Please select a report type
Cancel
Send
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

About

Qiling Advanced Binary Emulation Framework
Cancel

Releases

No release

Contributors

All

Activities

can not load any more
Edit
About
Homepage
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/github-mysync/qiling.git
git@gitee.com:github-mysync/qiling.git
github-mysync
qiling
qiling
dev
Going to Help Center

Search

Repository Report
Back to the top
Login prompt
This operation requires login to the code cloud account. Please log in before operating.
Go to login
No account. Register

AltStyle によって変換されたページ (->オリジナル) /