本文就是写写Keystone咋用的(Python)
不涉及原理层面
地址
官方网站
https://www.keystone-engine.org/
Github
https://github.com/keystone-engine/keystone
介绍
Keystone是一个轻量级的多平台多架构的汇编框架,可以提供不少独特功能:
- 支持多框架:Arm, Arm64 (AArch64/Armv8), Ethereum Virtual Machine, Hexagon, Mips, PowerPC, Sparc, SystemZ & X86 (包括 16/32/64bit)。
- 干净/简单/轻量级/直观的API,同时不依赖任何架构。
- 以C/C++实现,可在众多语言里使用:Java、Masm、C#、PowerShell、Perl、Python、NodeJS、Ruby、Go、Rust、Haskell、VB6 和 OCaml。
- 原生支持Windows和*nix系统(以下系统已确认支持:Mac OSX, Linux, *BSD, Solaris)
- 线程安全的设计。
- 开源,具有双重许可证
使用
编译ShellCode(X86)
Input
from keystone import *
import sys
Shellcode_instruction = '''
xor eax, eax
push eax
push 0x68732f2f
push 0x6e69622f
mov ebx, esp
push eax
push ebx
mov ecx, esp
mov al, 0xb
int 0x80
'''
KS = Ks(KS_ARCH_X86, KS_MODE_64)
code, count = KS.asm(Shellcode_instruction)
print(f"Source\t{code}")
print(f"Bytes\t{b''.join(map(lambda x: x.to_bytes(1, sys.byteorder), code))}")
print(f"Count\t{count}")
Output
Source [49, 192, 80, 104, 47, 47, 115, 104, 104, 47, 98, 105, 110, 137, 227, 80, 83, 137, 225, 176, 11, 205, 128]
Bytes b'1\xc0Ph//shh/bin\x89\xe3PS\x89\xe1\xb0\x0b\xcd\x80'
Count 11
编译ShellCode(X86-64)
Input
from keystone import *
import sys
Shellcode_instruction = '''
xor rdx, rdx
mov rbx, 0x68732f6e69622f2f
shr rbx, 0x8
push rbx
mov rdi, rsp
push rax
push rdi
mov rsi, rsp
mov al, 0x3b
syscall
'''
KS = Ks(KS_ARCH_X86, KS_MODE_64)
code, count = KS.asm(Shellcode_instruction)
print(f"Source\t{code}")
print(f"Bytes\t{b''.join(map(lambda x: x.to_bytes(1, sys.byteorder), code))}")
print(f"Count\t{count}")
Output
Source [72, 49, 210, 72, 187, 47, 47, 98, 105, 110, 47, 115, 104, 72, 193, 235, 8, 83, 72, 137, 231, 80, 87, 72, 137, 230, 176, 59, 15, 5]
Bytes b'H1\xd2H\xbb//bin/shH\xc1\xeb\x08SH\x89\xe7PWH\x89\xe6\xb0;\x0f\x05'
Count 10
ferrous sulfate 100 mg generic order betapace 40mg without prescription betapace 40mg without prescription
buy monograph 600 mg sale oral pletal 100 mg buy pletal medication
where can i buy prasugrel purchase chlorpromazine without prescription tolterodine 1mg pills
order florinef 100mcg online buy generic rabeprazole imodium price
duphaston for sale online order duphaston 10mg generic order jardiance 25mg sale
meloset where to buy meloset buy online order danazol 100mg generic
order dipyridamole 100mg pill dipyridamole price pravachol 20mg canada
aspirin 75 mg brand imiquad usa how to get imiquad without a prescription
order mintop generic cialis pills low cost ed pills
generic acarbose buy generic precose 25mg buy griseofulvin
cialis walmart sildenafil ca buy sildenafil tablets
zaditor 1 mg us ziprasidone where to buy buy imipramine medication
tricor 200mg ca order fenofibrate 160mg without prescription order tricor 200mg generic